From 20305494f8189994a6dc39cd450837a8f9e58dee Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Sat, 27 Aug 2022 14:26:12 +0200 Subject: refactor: remove redundant casts --- src/nvim/decoration.c | 4 +- src/nvim/ex_docmd.c | 2 +- src/nvim/extmark.c | 4 +- src/nvim/highlight.c | 4 +- src/nvim/keycodes.c | 144 +++++++++++++++++++++++++------------------------- src/nvim/mouse.c | 4 +- 6 files changed, 81 insertions(+), 81 deletions(-) (limited to 'src') diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c index a93fb599c4..9f3e5a8638 100644 --- a/src/nvim/decoration.c +++ b/src/nvim/decoration.c @@ -547,7 +547,7 @@ int decor_virt_lines(win_T *wp, linenr_T lnum, VirtLines *lines) } int virt_lines = 0; - int row = (int)MAX(lnum - 2, 0); + int row = MAX(lnum - 2, 0); int end_row = (int)lnum; MarkTreeIter itr[1] = { 0 }; marktree_itr_get(buf->b_marktree, row, 0, itr); @@ -558,7 +558,7 @@ int decor_virt_lines(win_T *wp, linenr_T lnum, VirtLines *lines) } else if (marktree_decor_level(mark) < kDecorLevelVirtLine) { goto next_mark; } - bool above = mark.pos.row > (int)(lnum - 2); + bool above = mark.pos.row > (lnum - 2); Decoration *decor = mark.decor_full; if (decor && decor->virt_lines_above == above) { virt_lines += (int)kv_size(decor->virt_lines); diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index eadde7a725..0d74ff6574 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -3088,7 +3088,7 @@ cmdidx_T excmd_get_cmdidx(const char *cmd, size_t len) { cmdidx_T idx; - for (idx = (cmdidx_T)0; (int)idx < (int)CMD_SIZE; idx = (cmdidx_T)((int)idx + 1)) { + for (idx = (cmdidx_T)0; (int)idx < CMD_SIZE; idx = (cmdidx_T)((int)idx + 1)) { if (strncmp(cmdnames[(int)idx].cmd_name, cmd, len) == 0) { break; } diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index 1639f72990..8e780f4aaa 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -510,11 +510,11 @@ void extmark_adjust(buf_T *buf, linenr_T line1, linenr_T line2, linenr_T amount, bcount_t old_byte = 0, new_byte = 0; int old_row, new_row; if (amount == MAXLNUM) { - old_row = (int)(line2 - line1 + 1); + old_row = line2 - line1 + 1; // TODO(bfredl): ej kasta? old_byte = (bcount_t)buf->deleted_bytes2; - new_row = (int)(amount_after + old_row); + new_row = amount_after + old_row; } else { // A region is either deleted (amount == MAXLNUM) or // added (line2 == MAXLNUM). The only other case is :move diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index c5a84c731d..4848668351 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -223,7 +223,7 @@ int ns_get_hl(NS *ns_hl, int hl_id, bool link, bool nodefault) } } - it.attr_id = fallback ? -1 : hl_get_syn_attr((int)ns_id, hl_id, attrs); + it.attr_id = fallback ? -1 : hl_get_syn_attr(ns_id, hl_id, attrs); it.version = p->hl_valid - tmp; it.is_default = attrs.rgb_ae_attr & HL_DEFAULT; it.link_global = attrs.rgb_ae_attr & HL_GLOBAL; @@ -406,7 +406,7 @@ void update_ns_hl(int ns_id) } int *hl_attrs = **alloc; - for (int hlf = 0; hlf < (int)HLF_COUNT; hlf++) { + for (int hlf = 0; hlf < HLF_COUNT; hlf++) { int id = syn_check_group(hlf_names[hlf], STRLEN(hlf_names[hlf])); bool optional = (hlf == HLF_INACTIVE || hlf == HLF_NFLOAT); hl_attrs[hlf] = hl_get_ui_attr(ns_id, hlf, id, optional); diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index 5a5257efb2..2b00d371f0 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -57,15 +57,15 @@ static char_u modifier_keys_table[] = MOD_MASK_SHIFT, '*', '4', 'k', 'D', // delete char MOD_MASK_SHIFT, '*', '5', 'k', 'L', // delete line MOD_MASK_SHIFT, '*', '7', '@', '7', // end - MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_END, '@', '7', // end + MOD_MASK_CTRL, KS_EXTRA, KE_C_END, '@', '7', // end MOD_MASK_SHIFT, '*', '9', '@', '9', // exit MOD_MASK_SHIFT, '*', '0', '@', '0', // find MOD_MASK_SHIFT, '#', '1', '%', '1', // help MOD_MASK_SHIFT, '#', '2', 'k', 'h', // home - MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_HOME, 'k', 'h', // home + MOD_MASK_CTRL, KS_EXTRA, KE_C_HOME, 'k', 'h', // home MOD_MASK_SHIFT, '#', '3', 'k', 'I', // insert MOD_MASK_SHIFT, '#', '4', 'k', 'l', // left arrow - MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_LEFT, 'k', 'l', // left arrow + MOD_MASK_CTRL, KS_EXTRA, KE_C_LEFT, 'k', 'l', // left arrow MOD_MASK_SHIFT, '%', 'a', '%', '3', // message MOD_MASK_SHIFT, '%', 'b', '%', '4', // move MOD_MASK_SHIFT, '%', 'c', '%', '5', // next @@ -75,63 +75,63 @@ static char_u modifier_keys_table[] = MOD_MASK_SHIFT, '%', 'g', '%', '0', // redo MOD_MASK_SHIFT, '%', 'h', '&', '3', // replace MOD_MASK_SHIFT, '%', 'i', 'k', 'r', // right arr. - MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_RIGHT, 'k', 'r', // right arr. + MOD_MASK_CTRL, KS_EXTRA, KE_C_RIGHT, 'k', 'r', // right arr. MOD_MASK_SHIFT, '%', 'j', '&', '5', // resume MOD_MASK_SHIFT, '!', '1', '&', '6', // save MOD_MASK_SHIFT, '!', '2', '&', '7', // suspend MOD_MASK_SHIFT, '!', '3', '&', '8', // undo - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_UP, 'k', 'u', // up arrow - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_DOWN, 'k', 'd', // down arrow + MOD_MASK_SHIFT, KS_EXTRA, KE_S_UP, 'k', 'u', // up arrow + MOD_MASK_SHIFT, KS_EXTRA, KE_S_DOWN, 'k', 'd', // down arrow // vt100 F1 - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF1, KS_EXTRA, (int)KE_XF1, - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF2, KS_EXTRA, (int)KE_XF2, - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF3, KS_EXTRA, (int)KE_XF3, - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF4, KS_EXTRA, (int)KE_XF4, - - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F1, 'k', '1', // F1 - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F2, 'k', '2', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F3, 'k', '3', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F4, 'k', '4', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F5, 'k', '5', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F6, 'k', '6', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F7, 'k', '7', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F8, 'k', '8', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F9, 'k', '9', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F10, 'k', ';', // F10 - - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F11, 'F', '1', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F12, 'F', '2', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F13, 'F', '3', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F14, 'F', '4', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F15, 'F', '5', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F16, 'F', '6', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F17, 'F', '7', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F18, 'F', '8', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F19, 'F', '9', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F20, 'F', 'A', - - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F21, 'F', 'B', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F22, 'F', 'C', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F23, 'F', 'D', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F24, 'F', 'E', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F25, 'F', 'F', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F26, 'F', 'G', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F27, 'F', 'H', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F28, 'F', 'I', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F29, 'F', 'J', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F30, 'F', 'K', - - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F31, 'F', 'L', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F32, 'F', 'M', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F33, 'F', 'N', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F34, 'F', 'O', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F35, 'F', 'P', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F36, 'F', 'Q', - MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F37, 'F', 'R', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_XF1, KS_EXTRA, KE_XF1, + MOD_MASK_SHIFT, KS_EXTRA, KE_S_XF2, KS_EXTRA, KE_XF2, + MOD_MASK_SHIFT, KS_EXTRA, KE_S_XF3, KS_EXTRA, KE_XF3, + MOD_MASK_SHIFT, KS_EXTRA, KE_S_XF4, KS_EXTRA, KE_XF4, + + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F1, 'k', '1', // F1 + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F2, 'k', '2', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F3, 'k', '3', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F4, 'k', '4', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F5, 'k', '5', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F6, 'k', '6', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F7, 'k', '7', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F8, 'k', '8', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F9, 'k', '9', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F10, 'k', ';', // F10 + + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F11, 'F', '1', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F12, 'F', '2', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F13, 'F', '3', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F14, 'F', '4', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F15, 'F', '5', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F16, 'F', '6', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F17, 'F', '7', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F18, 'F', '8', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F19, 'F', '9', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F20, 'F', 'A', + + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F21, 'F', 'B', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F22, 'F', 'C', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F23, 'F', 'D', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F24, 'F', 'E', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F25, 'F', 'F', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F26, 'F', 'G', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F27, 'F', 'H', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F28, 'F', 'I', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F29, 'F', 'J', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F30, 'F', 'K', + + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F31, 'F', 'L', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F32, 'F', 'M', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F33, 'F', 'N', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F34, 'F', 'O', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F35, 'F', 'P', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F36, 'F', 'Q', + MOD_MASK_SHIFT, KS_EXTRA, KE_S_F37, 'F', 'R', // TAB pseudo code - MOD_MASK_SHIFT, 'k', 'B', KS_EXTRA, (int)KE_TAB, + MOD_MASK_SHIFT, 'k', 'B', KS_EXTRA, KE_TAB, NUL }; @@ -349,26 +349,26 @@ static struct mousetable { bool is_drag; // Is it a mouse drag event? } mouse_table[] = { - { (int)KE_LEFTMOUSE, MOUSE_LEFT, true, false }, - { (int)KE_LEFTDRAG, MOUSE_LEFT, false, true }, - { (int)KE_LEFTRELEASE, MOUSE_LEFT, false, false }, - { (int)KE_MIDDLEMOUSE, MOUSE_MIDDLE, true, false }, - { (int)KE_MIDDLEDRAG, MOUSE_MIDDLE, false, true }, - { (int)KE_MIDDLERELEASE, MOUSE_MIDDLE, false, false }, - { (int)KE_RIGHTMOUSE, MOUSE_RIGHT, true, false }, - { (int)KE_RIGHTDRAG, MOUSE_RIGHT, false, true }, - { (int)KE_RIGHTRELEASE, MOUSE_RIGHT, false, false }, - { (int)KE_X1MOUSE, MOUSE_X1, true, false }, - { (int)KE_X1DRAG, MOUSE_X1, false, true }, - { (int)KE_X1RELEASE, MOUSE_X1, false, false }, - { (int)KE_X2MOUSE, MOUSE_X2, true, false }, - { (int)KE_X2DRAG, MOUSE_X2, false, true }, - { (int)KE_X2RELEASE, MOUSE_X2, false, false }, + { KE_LEFTMOUSE, MOUSE_LEFT, true, false }, + { KE_LEFTDRAG, MOUSE_LEFT, false, true }, + { KE_LEFTRELEASE, MOUSE_LEFT, false, false }, + { KE_MIDDLEMOUSE, MOUSE_MIDDLE, true, false }, + { KE_MIDDLEDRAG, MOUSE_MIDDLE, false, true }, + { KE_MIDDLERELEASE, MOUSE_MIDDLE, false, false }, + { KE_RIGHTMOUSE, MOUSE_RIGHT, true, false }, + { KE_RIGHTDRAG, MOUSE_RIGHT, false, true }, + { KE_RIGHTRELEASE, MOUSE_RIGHT, false, false }, + { KE_X1MOUSE, MOUSE_X1, true, false }, + { KE_X1DRAG, MOUSE_X1, false, true }, + { KE_X1RELEASE, MOUSE_X1, false, false }, + { KE_X2MOUSE, MOUSE_X2, true, false }, + { KE_X2DRAG, MOUSE_X2, false, true }, + { KE_X2RELEASE, MOUSE_X2, false, false }, // DRAG without CLICK - { (int)KE_MOUSEMOVE, MOUSE_RELEASE, false, true }, + { KE_MOUSEMOVE, MOUSE_RELEASE, false, true }, // RELEASE without CLICK - { (int)KE_IGNORE, MOUSE_RELEASE, false, false }, - { 0, 0, 0, 0 }, + { KE_IGNORE, MOUSE_RELEASE, false, false }, + { 0, 0, 0, 0 }, }; /// Return the modifier mask bit (#MOD_MASK_*) corresponding to mod name @@ -926,8 +926,8 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co } else { src += 5; result[dlen++] = K_SPECIAL; - result[dlen++] = (int)KS_EXTRA; - result[dlen++] = (int)KE_SNR; + result[dlen++] = KS_EXTRA; + result[dlen++] = KE_SNR; snprintf((char *)result + dlen, buf_len - dlen, "%" PRId64, (int64_t)current_sctx.sc_sid); dlen += STRLEN(result + dlen); diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 3dfbeec048..cc833dc3c0 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -702,8 +702,8 @@ static linenr_T find_longest_lnum(void) max = len; ret = lnum; } else if (len == (colnr_T)max - && abs((int)(lnum - curwin->w_cursor.lnum)) - < abs((int)(ret - curwin->w_cursor.lnum))) { + && abs(lnum - curwin->w_cursor.lnum) + < abs(ret - curwin->w_cursor.lnum)) { ret = lnum; } } -- cgit From 691f4715c0cf4bc11ea2280db8777e6dd174a8ac Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/buffer.c | 2 +- src/nvim/charset.c | 2 +- src/nvim/cmdexpand.c | 2 +- src/nvim/debugger.c | 2 +- src/nvim/diff.c | 2 +- src/nvim/edit.c | 6 +- src/nvim/eval/funcs.c | 6 +- src/nvim/ex_cmds.c | 4 +- src/nvim/ex_docmd.c | 16 +-- src/nvim/ex_getln.c | 2 +- src/nvim/file_search.c | 12 +-- src/nvim/fileio.c | 12 +-- src/nvim/garray.h | 2 +- src/nvim/getchar.c | 4 +- src/nvim/globals.h | 16 +-- src/nvim/help.c | 2 +- src/nvim/highlight.c | 2 +- src/nvim/indent.c | 13 +-- src/nvim/insexpand.c | 29 +++--- src/nvim/lua/stdlib.c | 4 +- src/nvim/main.c | 2 +- src/nvim/mark.c | 4 +- src/nvim/mbyte.c | 22 ++--- src/nvim/memfile.c | 10 +- src/nvim/memline.c | 20 ++-- src/nvim/message.c | 2 +- src/nvim/normal.c | 4 +- src/nvim/normal.h | 4 +- src/nvim/ops.c | 12 +-- src/nvim/option.c | 264 +++++++++++++++++++++++-------------------------- src/nvim/option_defs.h | 86 ++++++++-------- src/nvim/optionstr.c | 230 +++++++++++++++++++++--------------------- src/nvim/quickfix.c | 8 +- src/nvim/runtime.c | 2 +- src/nvim/screen.c | 30 +++--- src/nvim/shada.c | 2 +- src/nvim/spell.c | 12 +-- src/nvim/spellfile.c | 42 ++++---- src/nvim/statusline.c | 4 +- src/nvim/syntax.c | 65 ++++++------ src/nvim/tag.c | 52 +++++----- 41 files changed, 497 insertions(+), 520 deletions(-) (limited to 'src') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 514be4c56b..5dc7083a01 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2701,7 +2701,7 @@ void buflist_list(exarg_T *eap) home_replace(buf, buf->b_fname, (char *)NameBuff, MAXPATHL, true); } - if (message_filtered(NameBuff)) { + if (message_filtered((char_u *)NameBuff)) { continue; } diff --git a/src/nvim/charset.c b/src/nvim/charset.c index dc62b85716..df951854e0 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -246,7 +246,7 @@ int buf_init_chartab(buf_T *buf, int global) } c = *p; - p = skip_to_option_part(p); + p = (char_u *)skip_to_option_part((char *)p); if ((c == ',') && (*p == NUL)) { // Trailing comma is not allowed. diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index b55e885235..7f9a8b2a5c 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -705,7 +705,7 @@ int showmatches(expand_T *xp, int wildmenu) p = (char_u *)L_SHOWFILE(k); } else { home_replace(NULL, files_found[k], (char *)NameBuff, MAXPATHL, true); - p = NameBuff; + p = (char_u *)NameBuff; } } else { j = false; diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index d2f4910e14..9aee023f0c 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -703,7 +703,7 @@ void ex_breaklist(exarg_T *eap) smsg(_("%3d %s %s line %" PRId64), bp->dbg_nr, bp->dbg_type == DBG_FUNC ? "func" : "file", - bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff, + bp->dbg_type == DBG_FUNC ? bp->dbg_name : (char_u *)NameBuff, (int64_t)bp->dbg_lnum); } else { smsg(_("%3d expr %s"), bp->dbg_nr, bp->dbg_name); diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 8107b64c83..23fdc728f3 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1148,7 +1148,7 @@ static int diff_file(diffio_T *dio) (diff_flags & DIFF_IBLANK) ? "-B " : "", (diff_flags & DIFF_ICASE) ? "-i " : "", tmp_orig, tmp_new); - append_redir(cmd, len, (char *)p_srr, tmp_diff); + append_redir(cmd, len, p_srr, tmp_diff); block_autocmds(); // Avoid ShellCmdPost stuff (void)call_shell((char_u *)cmd, kShellOptFilter | kShellOptSilent | kShellOptDoOut, diff --git a/src/nvim/edit.c b/src/nvim/edit.c index ed625e1d6e..adcf9cd075 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3282,10 +3282,8 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) } } - /* - * Skip over ", ". - */ - look = skip_to_option_part(look); + // Skip over ", ". + look = (char_u *)skip_to_option_part((char *)look); } return false; } diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 581f187140..22447b933a 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -3895,9 +3895,11 @@ static void f_iconv(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const char *const str = tv_get_string(&argvars[0]); char buf1[NUMBUFLEN]; - char_u *const from = enc_canonize(enc_skip((char_u *)tv_get_string_buf(&argvars[1], buf1))); + char_u *const from = + (char_u *)enc_canonize((char *)enc_skip((char_u *)tv_get_string_buf(&argvars[1], buf1))); char buf2[NUMBUFLEN]; - char_u *const to = enc_canonize(enc_skip((char_u *)tv_get_string_buf(&argvars[2], buf2))); + char_u *const to = + (char_u *)enc_canonize((char *)enc_skip((char_u *)tv_get_string_buf(&argvars[2], buf2))); vimconv.vc_type = CONV_NONE; convert_setup(&vimconv, from, to); diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a72cddc0a9..4a1cdb0fc5 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -743,7 +743,7 @@ void ex_retab(exarg_T *eap) curwin->w_p_list = 0; // don't want list mode here new_ts_str = eap->arg; - if (!tabstop_set((char_u *)eap->arg, &new_vts_array)) { + if (!tabstop_set(eap->arg, &new_vts_array)) { return; } while (ascii_isdigit(*(eap->arg)) || *(eap->arg) == ',') { @@ -1656,7 +1656,7 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp) } #endif if (otmp != NULL) { - append_redir(buf, len, (char *)p_srr, otmp); + append_redir(buf, len, p_srr, otmp); } return buf; } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index eadde7a725..8ecc1e266b 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -531,7 +531,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) if (flags & DOCMD_KEEPLINE) { xfree(repeat_cmdline); if (count == 0) { - repeat_cmdline = vim_strsave((char_u *)next_cmdline); + repeat_cmdline = (char *)vim_strsave((char_u *)next_cmdline); } else { repeat_cmdline = NULL; } @@ -3788,8 +3788,8 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) // if there are still wildcards present. if (vim_strchr(eap->arg, '$') != NULL || vim_strchr(eap->arg, '~') != NULL) { - expand_env_esc((char_u *)eap->arg, NameBuff, MAXPATHL, true, true, NULL); - has_wildcards = path_has_wildcard(NameBuff); + expand_env_esc((char_u *)eap->arg, (char_u *)NameBuff, MAXPATHL, true, true, NULL); + has_wildcards = path_has_wildcard((char_u *)NameBuff); p = (char *)NameBuff; } else { p = NULL; @@ -4058,7 +4058,7 @@ static int getargopt(exarg_T *eap) *arg = NUL; if (pp == &eap->force_ff) { - if (check_ff_value((char_u *)eap->cmd + eap->force_ff) == FAIL) { + if (check_ff_value(eap->cmd + eap->force_ff) == FAIL) { return FAIL; } eap->force_ff = (char_u)eap->cmd[eap->force_ff]; @@ -5482,8 +5482,8 @@ bool changedir_func(char *new_dir, CdScope scope) new_dir = pdir; } - if (os_dirname(NameBuff, MAXPATHL) == OK) { - pdir = (char *)vim_strsave(NameBuff); + if (os_dirname((char_u *)NameBuff, MAXPATHL) == OK) { + pdir = xstrdup(NameBuff); } else { pdir = NULL; } @@ -5496,7 +5496,7 @@ bool changedir_func(char *new_dir, CdScope scope) if (*new_dir == NUL && p_cdh) { #endif // Use NameBuff for home directory name. - expand_env((char_u *)"$HOME", NameBuff, MAXPATHL); + expand_env((char_u *)"$HOME", (char_u *)NameBuff, MAXPATHL); new_dir = (char *)NameBuff; } @@ -5565,7 +5565,7 @@ void ex_cd(exarg_T *eap) /// ":pwd". static void ex_pwd(exarg_T *eap) { - if (os_dirname(NameBuff, MAXPATHL) == OK) { + if (os_dirname((char_u *)NameBuff, MAXPATHL) == OK) { #ifdef BACKSLASH_IN_FILENAME slash_adjust(NameBuff); #endif diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 081aa80778..c509205a6c 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -854,7 +854,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init s->histype == HIST_SEARCH ? s->firstc : NUL); if (s->firstc == ':') { xfree(new_last_cmdline); - new_last_cmdline = vim_strsave(ccline.cmdbuff); + new_last_cmdline = (char *)vim_strsave(ccline.cmdbuff); } } diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 273fe12d31..a990043017 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1409,11 +1409,11 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first // copy file name into NameBuff, expanding environment variables save_char = ptr[len]; ptr[len] = NUL; - expand_env_esc(ptr, NameBuff, MAXPATHL, false, true, NULL); + expand_env_esc(ptr, (char_u *)NameBuff, MAXPATHL, false, true, NULL); ptr[len] = save_char; xfree(ff_file_to_find); - ff_file_to_find = vim_strsave(NameBuff); + ff_file_to_find = vim_strsave((char_u *)NameBuff); if (options & FNAME_UNESC) { // Change all "\ " to " ". for (ptr = ff_file_to_find; *ptr != NUL; ptr++) { @@ -1473,11 +1473,11 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first buf = (char *)suffixes; for (;;) { if ( - (os_path_exists(NameBuff) + (os_path_exists((char_u *)NameBuff) && (find_what == FINDFILE_BOTH || ((find_what == FINDFILE_DIR) - == os_isdir(NameBuff))))) { - file_name = vim_strsave(NameBuff); + == os_isdir((char_u *)NameBuff))))) { + file_name = vim_strsave((char_u *)NameBuff); goto theend; } if (*buf == NUL) { @@ -1641,7 +1641,7 @@ int vim_chdirfile(char *fname, CdCause cause) STRLCPY(dir, fname, MAXPATHL); *path_tail_with_sep(dir) = NUL; - if (os_dirname(NameBuff, sizeof(NameBuff)) != OK) { + if (os_dirname((char_u *)NameBuff, sizeof(NameBuff)) != OK) { NameBuff[0] = NUL; } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 39b4eb4376..b873388473 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -699,7 +699,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, * Decide which 'encoding' to use or use first. */ if (eap != NULL && eap->force_enc != 0) { - fenc = (char *)enc_canonize((char_u *)eap->cmd + eap->force_enc); + fenc = enc_canonize(eap->cmd + eap->force_enc); fenc_alloced = true; keep_dest_enc = true; } else if (curbuf->b_p_bin) { @@ -2056,8 +2056,8 @@ void set_file_options(int set_options, exarg_T *eap) void set_forced_fenc(exarg_T *eap) { if (eap->force_enc != 0) { - char_u *fenc = enc_canonize((char_u *)eap->cmd + eap->force_enc); - set_string_option_direct("fenc", -1, (char *)fenc, OPT_FREE|OPT_LOCAL, 0); + char *fenc = enc_canonize(eap->cmd + eap->force_enc); + set_string_option_direct("fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0); xfree(fenc); } } @@ -2081,12 +2081,12 @@ static char_u *next_fenc(char **pp, bool *alloced) } p = (char_u *)vim_strchr((*pp), ','); if (p == NULL) { - r = enc_canonize((char_u *)(*pp)); + r = (char_u *)enc_canonize(*pp); *pp += STRLEN(*pp); } else { r = vim_strnsave((char_u *)(*pp), (size_t)(p - (char_u *)(*pp))); *pp = (char *)p + 1; - p = enc_canonize(r); + p = (char_u *)enc_canonize((char *)r); xfree(r); r = p; } @@ -3055,7 +3055,7 @@ nobackup: // Check for forced 'fileencoding' from "++opt=val" argument. if (eap != NULL && eap->force_enc != 0) { fenc = eap->cmd + eap->force_enc; - fenc = (char *)enc_canonize((char_u *)fenc); + fenc = enc_canonize(fenc); fenc_tofree = fenc; } else { fenc = buf->b_p_fenc; diff --git a/src/nvim/garray.h b/src/nvim/garray.h index 56bd5c9130..0281678925 100644 --- a/src/nvim/garray.h +++ b/src/nvim/garray.h @@ -4,7 +4,7 @@ #include // for size_t #include "nvim/log.h" -#include "nvim/types.h" // for char_u +#include "nvim/types.h" /// Structure used for growing arrays. /// This is used to store information that only grows, is deleted all at diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index c1c5680cb0..ebea4b7a9b 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1302,7 +1302,7 @@ void openscript(char_u *name, bool directly) curscript++; } // use NameBuff for expanded name - expand_env(name, NameBuff, MAXPATHL); + expand_env(name, (char_u *)NameBuff, MAXPATHL); int error; if ((scriptin[curscript] = file_open_new(&error, (char *)NameBuff, kFileReadOnly, 0)) == NULL) { @@ -2120,7 +2120,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) // Check for match with 'pastetoggle' if (*p_pt != NUL && mp == NULL && (State & (MODE_INSERT | MODE_NORMAL))) { - bool match = typebuf_match_len(p_pt, &mlen); + bool match = typebuf_match_len((char_u *)p_pt, &mlen); if (match) { // write chars to script file(s) if (mlen > typebuf.tb_maplen) { diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 7b93fbc852..8d62674a22 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -159,10 +159,10 @@ EXTERN colnr_T dollar_vcol INIT(= -1); // Variables for Insert mode completion. -EXTERN char_u *edit_submode INIT(= NULL); // msg for CTRL-X submode -EXTERN char_u *edit_submode_pre INIT(= NULL); // prepended to edit_submode -EXTERN char_u *edit_submode_extra INIT(= NULL); // appended to edit_submode -EXTERN hlf_T edit_submode_highl; // highl. method for extra info +EXTERN char *edit_submode INIT(= NULL); // msg for CTRL-X submode +EXTERN char *edit_submode_pre INIT(= NULL); // prepended to edit_submode +EXTERN char *edit_submode_extra INIT(= NULL); // appended to edit_submode +EXTERN hlf_T edit_submode_highl; // highl. method for extra info // state for putting characters in the message area EXTERN int cmdmsg_rl INIT(= false); // cmdline is drawn right to left @@ -667,7 +667,7 @@ EXTERN int swap_exists_action INIT(= SEA_NONE); ///< For dialog when swap file EXTERN bool swap_exists_did_quit INIT(= false); ///< Selected "quit" at the dialog. EXTERN char_u IObuff[IOSIZE]; ///< Buffer for sprintf, I/O, etc. -EXTERN char_u NameBuff[MAXPATHL]; ///< Buffer for expanding file names +EXTERN char NameBuff[MAXPATHL]; ///< Buffer for expanding file names EXTERN char msg_buf[MSG_BUF_LEN]; ///< Small buffer for messages EXTERN char os_buf[ ///< Buffer for the os/ layer #if MAXPATHL > IOSIZE @@ -731,9 +731,9 @@ EXTERN bool need_start_insertmode INIT(= false); ///< start insert mode soon // including the terminating NUL EXTERN char last_mode[MODE_MAX_LENGTH] INIT(= "n"); -EXTERN char_u *last_cmdline INIT(= NULL); // last command line (for ":) -EXTERN char_u *repeat_cmdline INIT(= NULL); // command line for "." -EXTERN char_u *new_last_cmdline INIT(= NULL); // new value for last_cmdline +EXTERN char *last_cmdline INIT(= NULL); // last command line (for ":) +EXTERN char *repeat_cmdline INIT(= NULL); // command line for "." +EXTERN char *new_last_cmdline INIT(= NULL); // new value for last_cmdline EXTERN char *autocmd_fname INIT(= NULL); // fname for on cmdline EXTERN int autocmd_bufnr INIT(= 0); // fnum for on cmdline EXTERN char *autocmd_match INIT(= NULL); // name for on cmdline diff --git a/src/nvim/help.c b/src/nvim/help.c index 19bf67c890..4b2b113437 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -537,7 +537,7 @@ int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep if (keep_lang) { flags |= TAG_KEEP_LANG; } - if (find_tags(IObuff, num_matches, matches, flags, MAXCOL, NULL) == OK + if (find_tags((char *)IObuff, num_matches, matches, flags, MAXCOL, NULL) == OK && *num_matches > 0) { // Sort the matches found on the heuristic number that is after the // tag name. diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index c5a84c731d..3e3d03fa9c 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -729,7 +729,7 @@ static int hl_cterm2rgb_color(int nr) 0x08, 0x12, 0x1C, 0x26, 0x30, 0x3A, 0x44, 0x4E, 0x58, 0x62, 0x6C, 0x76, 0x80, 0x8A, 0x94, 0x9E, 0xA8, 0xB2, 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE }; - static char_u ansi_table[16][4] = { + static uint8_t ansi_table[16][4] = { // R G B idx { 0, 0, 0, 1 }, // black { 224, 0, 0, 2 }, // dark red diff --git a/src/nvim/indent.c b/src/nvim/indent.c index c4805283c2..7c5f291837 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -34,12 +34,13 @@ /// Set the integer values corresponding to the string setting of 'vartabstop'. /// "array" will be set, caller must free it if needed. -/// Return false for an error. -bool tabstop_set(char_u *var, long **array) +/// +/// @return false for an error. +bool tabstop_set(char *var, long **array) { long valcount = 1; int t; - char_u *cp; + char *cp; if (var[0] == NUL || (var[0] == '0' && var[1] == NUL)) { *array = NULL; @@ -50,8 +51,8 @@ bool tabstop_set(char_u *var, long **array) if (cp == var || cp[-1] == ',') { char *end; - if (strtol((char *)cp, &end, 10) <= 0) { - if (cp != (char_u *)end) { + if (strtol(cp, &end, 10) <= 0) { + if (cp != end) { emsg(_(e_positive)); } else { semsg(_(e_invarg2), cp); @@ -76,7 +77,7 @@ bool tabstop_set(char_u *var, long **array) t = 1; for (cp = var; *cp != NUL;) { - int n = atoi((char *)cp); + int n = atoi(cp); // Catch negative values, overflow and ridiculous big values. if (n <= 0 || n > TABSTOP_MAX) { diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index e6c13f315e..981a8d42a6 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -268,7 +268,7 @@ void ins_ctrl_x(void) } // We're not sure which CTRL-X mode it will be yet ctrl_x_mode = CTRL_X_NOT_DEFINED_YET; - edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode)); + edit_submode = _(CTRL_X_MSG(ctrl_x_mode)); edit_submode_pre = NULL; showmode(); } else { @@ -1830,9 +1830,9 @@ static bool set_ctrl_x_mode(const int c) // scroll the window one line up or down ctrl_x_mode = CTRL_X_SCROLL; if (!(State & REPLACE_FLAG)) { - edit_submode = (char_u *)_(" (insert) Scroll (^E/^Y)"); + edit_submode = _(" (insert) Scroll (^E/^Y)"); } else { - edit_submode = (char_u *)_(" (replace) Scroll (^E/^Y)"); + edit_submode = _(" (replace) Scroll (^E/^Y)"); } edit_submode_pre = NULL; showmode(); @@ -2845,10 +2845,10 @@ static void get_next_tag_completion(void) g_tag_at_cursor = true; char **matches; int num_matches; - if (find_tags((char_u *)compl_pattern, &num_matches, &matches, + if (find_tags(compl_pattern, &num_matches, &matches, TAG_REGEXP | TAG_NAMES | TAG_NOIC | TAG_INS_COMP | (ctrl_x_mode_not_default() ? TAG_VERBOSE : 0), - TAG_MANY, (char_u *)curbuf->b_ffname) == OK && num_matches > 0) { + TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0) { ins_compl_add_matches(num_matches, matches, p_ic); } g_tag_at_cursor = false; @@ -4078,7 +4078,7 @@ static int ins_compl_start(void) } if (compl_status_adding()) { - edit_submode_pre = (char_u *)_(" Adding"); + edit_submode_pre = _(" Adding"); if (ctrl_x_mode_line_or_eval()) { // Insert a new line, keep indentation but ignore 'comments'. char *old = curbuf->b_p_com; @@ -4097,9 +4097,9 @@ static int ins_compl_start(void) } if (compl_cont_status & CONT_LOCAL) { - edit_submode = (char_u *)_(ctrl_x_msgs[CTRL_X_LOCAL_MSG]); + edit_submode = _(ctrl_x_msgs[CTRL_X_LOCAL_MSG]); } else { - edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode)); + edit_submode = _(CTRL_X_MSG(ctrl_x_mode)); } // If any of the original typed text has been changed we need to fix @@ -4123,7 +4123,7 @@ static int ins_compl_start(void) // showmode might reset the internal line pointers, so it must // be called before line = ml_get(), or when this address is no // longer needed. -- Acevedo. - edit_submode_extra = (char_u *)_("-- Searching..."); + edit_submode_extra = _("-- Searching..."); edit_submode_highl = HLF_COUNT; showmode(); edit_submode_extra = NULL; @@ -4137,20 +4137,19 @@ static void ins_compl_show_statusmsg(void) { // we found no match if the list has only the "compl_orig_text"-entry if (is_first_match(compl_first_match->cp_next)) { - edit_submode_extra = compl_status_adding() && compl_length > 1 - ? (char_u *)_(e_hitend) : (char_u *)_(e_patnotf); + edit_submode_extra = compl_status_adding() && compl_length > 1 ? _(e_hitend) : _(e_patnotf); edit_submode_highl = HLF_E; } if (edit_submode_extra == NULL) { if (match_at_original_text(compl_curr_match)) { - edit_submode_extra = (char_u *)_("Back at original"); + edit_submode_extra = _("Back at original"); edit_submode_highl = HLF_W; } else if (compl_cont_status & CONT_S_IPOS) { - edit_submode_extra = (char_u *)_("Word from other line"); + edit_submode_extra = _("Word from other line"); edit_submode_highl = HLF_COUNT; } else if (compl_curr_match->cp_next == compl_curr_match->cp_prev) { - edit_submode_extra = (char_u *)_("The only match"); + edit_submode_extra = _("The only match"); edit_submode_highl = HLF_COUNT; compl_curr_match->cp_number = 1; } else { @@ -4175,7 +4174,7 @@ static void ins_compl_show_statusmsg(void) _("match %d"), compl_curr_match->cp_number); } - edit_submode_extra = match_ref; + edit_submode_extra = (char *)match_ref; edit_submode_highl = HLF_R; if (dollar_vcol >= 0) { curs_columns(curwin, false); diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 64e9abe0c9..0d08817285 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -494,8 +494,8 @@ static int nlua_iconv(lua_State *lstate) size_t str_len = 0; const char *str = lua_tolstring(lstate, 1, &str_len); - char_u *from = enc_canonize(enc_skip((char_u *)lua_tolstring(lstate, 2, NULL))); - char_u *to = enc_canonize(enc_skip((char_u *)lua_tolstring(lstate, 3, NULL))); + char_u *from = (char_u *)enc_canonize((char *)enc_skip((char_u *)lua_tolstring(lstate, 2, NULL))); + char_u *to = (char_u *)enc_canonize((char *)enc_skip((char_u *)lua_tolstring(lstate, 3, NULL))); vimconv_T vimconv; vimconv.vc_type = CONV_NONE; diff --git a/src/nvim/main.c b/src/nvim/main.c index e2e150a892..09a387262c 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1490,7 +1490,7 @@ static void handle_quickfix(mparm_T *paramp) set_string_option_direct("ef", -1, paramp->use_ef, OPT_FREE, SID_CARG); } vim_snprintf((char *)IObuff, IOSIZE, "cfile %s", p_ef); - if (qf_init(NULL, (char *)p_ef, p_efm, true, (char *)IObuff, (char *)p_menc) < 0) { + if (qf_init(NULL, (char *)p_ef, p_efm, true, (char *)IObuff, p_menc) < 0) { msg_putchar('\n'); os_exit(3); } diff --git a/src/nvim/mark.c b/src/nvim/mark.c index c4b30ae600..883371c5fb 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -674,7 +674,7 @@ static void fname2fnum(xfmark_T *fm) )) { int len; - expand_env((char_u *)"~/", NameBuff, MAXPATHL); + expand_env((char_u *)"~/", (char_u *)NameBuff, MAXPATHL); len = (int)STRLEN(NameBuff); STRLCPY(NameBuff + len, fm->fname + 2, MAXPATHL - len); } else { @@ -683,7 +683,7 @@ static void fname2fnum(xfmark_T *fm) // Try to shorten the file name. os_dirname(IObuff, IOSIZE); - p = path_shorten_fname(NameBuff, IObuff); + p = path_shorten_fname((char_u *)NameBuff, IObuff); // buflist_new() will call fmarks_check_names() (void)buflist_new((char *)NameBuff, (char *)p, (linenr_T)1, 0); diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 9213457608..dab6c8fbd3 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -2160,27 +2160,27 @@ char_u *enc_skip(char_u *p) return p; } -/* - * Find the canonical name for encoding "enc". - * When the name isn't recognized, returns "enc" itself, but with all lower - * case characters and '_' replaced with '-'. - * Returns an allocated string. - */ -char_u *enc_canonize(char_u *enc) FUNC_ATTR_NONNULL_RET +/// Find the canonical name for encoding "enc". +/// When the name isn't recognized, returns "enc" itself, but with all lower +/// case characters and '_' replaced with '-'. +/// +/// @return an allocated string. +char *enc_canonize(char *enc) + FUNC_ATTR_NONNULL_RET { char_u *p, *s; int i; if (STRCMP(enc, "default") == 0) { // Use the default encoding as found by set_init_1(). - return vim_strsave(fenc_default); + return (char *)vim_strsave(fenc_default); } // copy "enc" to allocated memory, with room for two '-' char_u *r = xmalloc(STRLEN(enc) + 3); // Make it all lower case and replace '_' with '-'. p = r; - for (s = enc; *s != NUL; s++) { + for (s = (char_u *)enc; *s != NUL; s++) { if (*s == '_') { *p++ = '-'; } else { @@ -2224,7 +2224,7 @@ char_u *enc_canonize(char_u *enc) FUNC_ATTR_NONNULL_RET xfree(r); r = vim_strsave((char_u *)enc_canon_table[i].name); } - return r; + return (char *)r; } /// Search for an encoding alias of "name". @@ -2309,7 +2309,7 @@ enc_locale_copy_enc: buf[i] = NUL; } - return enc_canonize((char_u *)buf); + return (char_u *)enc_canonize(buf); } #if defined(HAVE_ICONV) diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 216ee26620..9446aaee4f 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -77,7 +77,7 @@ /// /// @return - The open memory file, on success. /// - NULL, on failure (e.g. file does not exist). -memfile_T *mf_open(char_u *fname, int flags) +memfile_T *mf_open(char *fname, int flags) { memfile_T *mfp = xmalloc(sizeof(memfile_T)); @@ -148,7 +148,7 @@ memfile_T *mf_open(char_u *fname, int flags) /// /// @return OK On success. /// FAIL If file could not be opened. -int mf_open_file(memfile_T *mfp, char_u *fname) +int mf_open_file(memfile_T *mfp, char *fname) { if (mf_do_open(mfp, fname, O_RDWR | O_CREAT | O_EXCL)) { mfp->mf_dirty = true; @@ -749,9 +749,9 @@ void mf_free_fnames(memfile_T *mfp) /// /// Only called when creating or renaming the swapfile. Either way it's a new /// name so we must work out the full path name. -void mf_set_fnames(memfile_T *mfp, char_u *fname) +void mf_set_fnames(memfile_T *mfp, char *fname) { - mfp->mf_fname = fname; + mfp->mf_fname = (char_u *)fname; mfp->mf_ffname = (char_u *)FullName_save((char *)mfp->mf_fname, false); } @@ -779,7 +779,7 @@ bool mf_need_trans(memfile_T *mfp) /// /// @param flags Flags for open(). /// @return A bool indicating success of the `open` call. -static bool mf_do_open(memfile_T *mfp, char_u *fname, int flags) +static bool mf_do_open(memfile_T *mfp, char *fname, int flags) { // fname cannot be NameBuff, because it must have been allocated. mf_set_fnames(mfp, fname); diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 2913d0d271..ee90ae6b15 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -430,7 +430,7 @@ void ml_setname(buf_T *buf) if (vim_rename(mfp->mf_fname, fname) == 0) { success = true; mf_free_fnames(mfp); - mf_set_fnames(mfp, fname); + mf_set_fnames(mfp, (char *)fname); ml_upd_block0(buf, UB_SAME_DIR); break; } @@ -483,7 +483,7 @@ void ml_open_file(buf_T *buf) if (buf->b_spell) { fname = vim_tempname(); if (fname != NULL) { - (void)mf_open_file(mfp, fname); // consumes fname! + (void)mf_open_file(mfp, (char *)fname); // consumes fname! } buf->b_may_swap = false; return; @@ -506,7 +506,7 @@ void ml_open_file(buf_T *buf) if (fname == NULL) { continue; } - if (mf_open_file(mfp, fname) == OK) { // consumes fname! + if (mf_open_file(mfp, (char *)fname) == OK) { // consumes fname! ml_upd_block0(buf, UB_SAME_DIR); // Flush block zero, so others can read it @@ -835,7 +835,7 @@ void ml_recover(bool checkext) */ p = vim_strsave(fname_used); // save "fname_used" for the message: // mf_open() will consume "fname_used"! - mfp = mf_open(fname_used, O_RDONLY); + mfp = mf_open((char *)fname_used, O_RDONLY); fname_used = p; if (mfp == NULL || mfp->mf_fd < 0) { semsg(_("E306: Cannot open %s"), fname_used); @@ -926,7 +926,7 @@ void ml_recover(bool checkext) * If .swp file name given directly, use name from swap file for buffer. */ if (directly) { - expand_env(b0p->b0_fname, NameBuff, MAXPATHL); + expand_env(b0p->b0_fname, (char_u *)NameBuff, MAXPATHL); if (setfname(curbuf, (char *)NameBuff, NULL, true) == FAIL) { goto theend; } @@ -1873,7 +1873,7 @@ errorret: // when the GUI redraws part of the text. recursive++; get_trans_bufname(buf); - shorten_dir(NameBuff); + shorten_dir((char_u *)NameBuff); siemsg(_("E316: ml_get: cannot find line %" PRId64 " in buffer %d %s"), (int64_t)lnum, buf->b_fnum, NameBuff); recursive--; @@ -3472,8 +3472,8 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ // Symlinks may point to the same file even // when the name differs, need to check the // inode too. - expand_env(b0.b0_fname, NameBuff, MAXPATHL); - if (fnamecmp_ino((char_u *)buf->b_ffname, NameBuff, + expand_env(b0.b0_fname, (char_u *)NameBuff, MAXPATHL); + if (fnamecmp_ino((char_u *)buf->b_ffname, (char_u *)NameBuff, char_to_long(b0.b0_ino))) { differ = true; } @@ -3481,8 +3481,8 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ } else { // The name in the swap file may be // "~user/path/file". Expand it first. - expand_env(b0.b0_fname, NameBuff, MAXPATHL); - if (fnamecmp_ino((char_u *)buf->b_ffname, NameBuff, + expand_env(b0.b0_fname, (char_u *)NameBuff, MAXPATHL); + if (fnamecmp_ino((char_u *)buf->b_ffname, (char_u *)NameBuff, char_to_long(b0.b0_ino))) { differ = true; } diff --git a/src/nvim/message.c b/src/nvim/message.c index 40de8a2bc6..fbf9c9b603 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -3426,7 +3426,7 @@ int verbose_open(void) // Only give the error message once. verbose_did_open = true; - verbose_fd = os_fopen((char *)p_vfile, "a"); + verbose_fd = os_fopen(p_vfile, "a"); if (verbose_fd == NULL) { semsg(_(e_notopen), p_vfile); return FAIL; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 31646f686d..5dd6742e2f 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -4807,14 +4807,14 @@ static void nv_search(cmdarg_T *cap) // When using 'incsearch' the cursor may be moved to set a different search // start position. - cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0, true); + cap->searchbuf = (char *)getcmdline(cap->cmdchar, cap->count1, 0, true); if (cap->searchbuf == NULL) { clearop(oap); return; } - (void)normal_search(cap, cap->cmdchar, cap->searchbuf, + (void)normal_search(cap, cap->cmdchar, (char_u *)cap->searchbuf, (cap->arg || !equalpos(save_cursor, curwin->w_cursor)) ? 0 : SEARCH_MARK, NULL); } diff --git a/src/nvim/normal.h b/src/nvim/normal.h index 9bda70eacd..13ea233658 100644 --- a/src/nvim/normal.h +++ b/src/nvim/normal.h @@ -57,7 +57,7 @@ typedef struct oparg_S { * Arguments for Normal mode commands. */ typedef struct cmdarg_S { - oparg_T *oap; // Operator arguments + oparg_T *oap; // Operator arguments int prechar; // prefix character (optional, always 'g') int cmdchar; // command character int nchar; // next command character (optional) @@ -69,7 +69,7 @@ typedef struct cmdarg_S { long count1; // count before command, default 1 int arg; // extra argument from nv_cmds[] int retval; // return: CA_* values - char_u *searchbuf; // return: pointer to search pattern or NULL + char *searchbuf; // return: pointer to search pattern or NULL } cmdarg_T; // values for retval: diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 0fc15b9382..1bf4c00633 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1111,7 +1111,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) // don't keep the cmdline containing @: XFREE_CLEAR(new_last_cmdline); // Escape all control characters with a CTRL-V - p = vim_strsave_escaped_ext(last_cmdline, + p = vim_strsave_escaped_ext((char_u *)last_cmdline, (char_u *)"\001\002\003\004\005\006\007" "\010\011\012\013\014\015\016\017" "\020\021\022\023\024\025\026\027" @@ -1346,7 +1346,7 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg) if (last_cmdline == NULL && errmsg) { emsg(_(e_nolastcmd)); } - *argp = (char *)last_cmdline; + *argp = last_cmdline; return true; case '/': // last search-pattern @@ -3854,9 +3854,9 @@ void ex_display(exarg_T *eap) // display last command line if (last_cmdline != NULL && (arg == NULL || vim_strchr((char *)arg, ':') != NULL) - && !got_int && !message_filtered(last_cmdline)) { + && !got_int && !message_filtered((char_u *)last_cmdline)) { msg_puts("\n c \": "); - dis_msg(last_cmdline, false); + dis_msg((char_u *)last_cmdline, false); } // display current file name @@ -5799,7 +5799,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) // If 'cpoptions' does not contain 'r', insert the search // pattern to really repeat the same command. if (vim_strchr(p_cpo, CPO_REDO) == NULL) { - AppendToRedobuffLit((char *)cap->searchbuf, -1); + AppendToRedobuffLit(cap->searchbuf, -1); } AppendToRedobuff(NL_STR); } else if (cap->cmdchar == ':' || cap->cmdchar == K_COMMAND) { @@ -5809,7 +5809,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if (repeat_cmdline == NULL) { ResetRedobuff(); } else { - AppendToRedobuffLit((char *)repeat_cmdline, -1); + AppendToRedobuffLit(repeat_cmdline, -1); AppendToRedobuff(NL_STR); XFREE_CLEAR(repeat_cmdline); } diff --git a/src/nvim/option.c b/src/nvim/option.c index 4bf978d2f6..c3f803e543 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -149,7 +149,7 @@ static int p_et_nopaste; static long p_sts_nopaste; static long p_tw_nopaste; static long p_wm_nopaste; -static char_u *p_vsts_nopaste; +static char *p_vsts_nopaste; typedef struct vimoption { char *fullname; // full option name @@ -455,7 +455,7 @@ static void set_option_default(int opt_idx, int opt_flags) char_u *varp; // pointer to variable for current option int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; - varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); + varp = (char_u *)get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); uint32_t flags = options[opt_idx].flags; if (varp != NULL) { // skip hidden option, nothing to do for it if (flags & P_STRING) { @@ -675,12 +675,12 @@ void set_init_3(void) if (FNAMECMP(p, "csh") == 0 || FNAMECMP(p, "tcsh") == 0) { if (do_sp) { - p_sp = (char_u *)"|& tee"; - options[idx_sp].def_val = p_sp; + p_sp = "|& tee"; + options[idx_sp].def_val = (char_u *)p_sp; } if (do_srr) { - p_srr = (char_u *)">&"; - options[idx_srr].def_val = p_srr; + p_srr = ">&"; + options[idx_srr].def_val = (char_u *)p_srr; } } else if (FNAMECMP(p, "sh") == 0 || FNAMECMP(p, "ksh") == 0 @@ -694,12 +694,12 @@ void set_init_3(void) || FNAMECMP(p, "dash") == 0) { // Always use POSIX shell style redirection if we reach this if (do_sp) { - p_sp = (char_u *)"2>&1| tee"; - options[idx_sp].def_val = p_sp; + p_sp = "2>&1| tee"; + options[idx_sp].def_val = (char_u *)p_sp; } if (do_srr) { - p_srr = (char_u *)">%s 2>&1"; - options[idx_srr].def_val = p_srr; + p_srr = ">%s 2>&1"; + options[idx_srr].def_val = (char_u *)p_srr; } } xfree(p); @@ -810,7 +810,7 @@ int do_set(char *arg, int opt_flags) int opt_idx; char *errmsg; char errbuf[80]; - char_u *startarg; + char *startarg; int prefix; // 1: nothing, 0: "no", 2: "inv" in front of name char_u nextchar; // next non-white char after option name int afterchar; // character just after option name @@ -833,7 +833,7 @@ int do_set(char *arg, int opt_flags) while (*arg != NUL) { // loop to process all options errmsg = NULL; - startarg = (char_u *)arg; // remember for error message + startarg = arg; // remember for error message if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]) && !(opt_flags & OPT_MODELINE)) { @@ -947,7 +947,7 @@ int do_set(char *arg, int opt_flags) } flags = options[opt_idx].flags; - varp = (char *)get_varp_scope(&(options[opt_idx]), opt_flags); + varp = get_varp_scope(&(options[opt_idx]), opt_flags); } else { flags = P_STRING; } @@ -1543,12 +1543,12 @@ skip: if (errmsg != NULL) { STRLCPY(IObuff, _(errmsg), IOSIZE); i = (int)STRLEN(IObuff) + 2; - if (i + ((char_u *)arg - startarg) < IOSIZE) { + if (i + (arg - startarg) < IOSIZE) { // append the argument with the error STRCAT(IObuff, ": "); - assert((char_u *)arg >= startarg); - memmove(IObuff + i, startarg, (size_t)((char_u *)arg - startarg)); - IObuff[i + ((char_u *)arg - startarg)] = NUL; + assert(arg >= startarg); + memmove(IObuff + i, startarg, (size_t)(arg - startarg)); + IObuff[i + (arg - startarg)] = NUL; } // make sure all characters are printable trans_characters((char *)IObuff, IOSIZE); @@ -1741,7 +1741,7 @@ static char_u *option_expand(int opt_idx, char_u *val) * names. * For 'spellsuggest' expand after "file:". */ - expand_env_esc(val, NameBuff, MAXPATHL, + expand_env_esc(val, (char_u *)NameBuff, MAXPATHL, (char_u **)options[opt_idx].var == &p_tags, false, (char_u **)options[opt_idx].var == (char_u **)&p_sps ? (char_u *)"file:" : NULL); @@ -1749,7 +1749,7 @@ static char_u *option_expand(int opt_idx, char_u *val) return NULL; } - return NameBuff; + return (char_u *)NameBuff; } /// After setting various option values: recompute variables that depend on @@ -1779,17 +1779,17 @@ static void didset_options2(void) highlight_changed(); // Parse default for 'fillchars'. - (void)set_chars_option(curwin, (char_u **)&curwin->w_p_fcs, true); + (void)set_chars_option(curwin, &curwin->w_p_fcs, true); // Parse default for 'listchars'. - (void)set_chars_option(curwin, (char_u **)&curwin->w_p_lcs, true); + (void)set_chars_option(curwin, &curwin->w_p_lcs, true); // Parse default for 'wildmode'. check_opt_wim(); xfree(curbuf->b_p_vsts_array); - (void)tabstop_set((char_u *)curbuf->b_p_vsts, &curbuf->b_p_vsts_array); + (void)tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array); xfree(curbuf->b_p_vts_array); - (void)tabstop_set((char_u *)curbuf->b_p_vts, &curbuf->b_p_vts_array); + (void)tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array); } /// Check for string options that are NULL (normally only termcap options). @@ -1858,10 +1858,10 @@ void redraw_titles(void) /// Return true if "val" is a valid name: only consists of alphanumeric ASCII /// characters or characters in "allowed". -bool valid_name(const char_u *val, const char *allowed) +bool valid_name(const char *val, const char *allowed) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - for (const char_u *s = val; *s != NUL; s++) { + for (const char_u *s = (char_u *)val; *s != NUL; s++) { if (!ASCII_ISALNUM(*s) && vim_strchr(allowed, *s) == NULL) { return false; @@ -2930,14 +2930,14 @@ getoption_T get_option_value(const char *name, long *numval, char **stringval, i return gov_unknown; } - char_u *varp = get_varp_scope(&(options[opt_idx]), opt_flags); + char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags); if (options[opt_idx].flags & P_STRING) { if (varp == NULL) { // hidden option return gov_hidden_string; } if (stringval != NULL) { - if ((char_u **)varp == &p_pt) { // 'pastetoggle' + if ((char **)varp == &p_pt) { // 'pastetoggle' *stringval = str2special_save(*(char **)(varp), false, false); } else { *stringval = xstrdup(*(char **)(varp)); @@ -3056,7 +3056,7 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o // only getting a pointer, no need to use aucmd_prepbuf() curbuf = (buf_T *)from; curwin->w_buffer = curbuf; - varp = get_varp_scope(p, OPT_LOCAL); + varp = (char_u *)get_varp_scope(p, OPT_LOCAL); curbuf = save_curbuf; curwin->w_buffer = curbuf; } @@ -3064,7 +3064,7 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o win_T *save_curwin = curwin; curwin = (win_T *)from; curbuf = curwin->w_buffer; - varp = get_varp_scope(p, OPT_LOCAL); + varp = (char_u *)get_varp_scope(p, OPT_LOCAL); curwin = save_curwin; curbuf = curwin->w_buffer; } @@ -3170,7 +3170,7 @@ char *set_option_value(const char *const name, const long number, const char *co return set_string_option(opt_idx, s, opt_flags); } - varp = get_varp_scope(&(options[opt_idx]), opt_flags); + varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags); if (varp != NULL) { // hidden option is not changed if (number == 0 && string != NULL) { int idx; @@ -3306,7 +3306,7 @@ static void showoptions(int all, int opt_flags) varp = NULL; if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) != 0) { if (p->indir != PV_NONE) { - varp = get_varp_scope(p, opt_flags); + varp = (char_u *)get_varp_scope(p, opt_flags); } } else { varp = get_varp(p); @@ -3410,13 +3410,12 @@ void ui_refresh_options(void) /// @param opt_flags OPT_LOCAL or OPT_GLOBAL static void showoneopt(vimoption_T *p, int opt_flags) { - char_u *varp; int save_silent = silent_mode; silent_mode = false; info_message = true; // use mch_msg(), not mch_errmsg() - varp = get_varp_scope(p, opt_flags); + char_u *varp = (char_u *)get_varp_scope(p, opt_flags); // for 'modified' we also need to check if 'ff' or 'fenc' changed. if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed @@ -3462,7 +3461,7 @@ static void showoneopt(vimoption_T *p, int opt_flags) int makeset(FILE *fd, int opt_flags, int local_only) { vimoption_T *p; - char_u *varp; // currently used value + char *varp; // currently used value char_u *varp_fresh; // local value char_u *varp_local = NULL; // fresh value char *cmd; @@ -3499,7 +3498,7 @@ int makeset(FILE *fd, int opt_flags, int local_only) continue; } // Global values are only written when not at the default value. - if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp)) { + if ((opt_flags & OPT_GLOBAL) && optval_default(p, (char_u *)varp)) { continue; } @@ -3518,11 +3517,11 @@ int makeset(FILE *fd, int opt_flags, int local_only) // When fresh value of window-local option is not at the // default, need to write it too. if (!(opt_flags & OPT_GLOBAL) && !local_only) { - varp_fresh = get_varp_scope(p, OPT_GLOBAL); + varp_fresh = (char_u *)get_varp_scope(p, OPT_GLOBAL); if (!optval_default(p, varp_fresh)) { round = 1; - varp_local = varp; - varp = varp_fresh; + varp_local = (char_u *)varp; + varp = (char *)varp_fresh; } } } @@ -3530,7 +3529,7 @@ int makeset(FILE *fd, int opt_flags, int local_only) // Round 1: fresh value for window-local options. // Round 2: other values - for (; round <= 2; varp = varp_local, round++) { + for (; round <= 2; varp = (char *)varp_local, round++) { if (round == 1 || (opt_flags & OPT_GLOBAL)) { cmd = "set"; } else { @@ -3558,8 +3557,7 @@ int makeset(FILE *fd, int opt_flags, int local_only) } do_endif = true; } - if (put_setstring(fd, cmd, p->fullname, (char_u **)varp, - p->flags) == FAIL) { + if (put_setstring(fd, cmd, p->fullname, (char **)varp, p->flags) == FAIL) { return FAIL; } if (do_endif) { @@ -3579,25 +3577,21 @@ int makeset(FILE *fd, int opt_flags, int local_only) /// 'sessionoptions' or 'viewoptions' contains "folds" but not "options". int makefoldset(FILE *fd) { - if (put_setstring(fd, "setlocal", "fdm", (char_u **)&curwin->w_p_fdm, 0) == FAIL - || put_setstring(fd, "setlocal", "fde", (char_u **)&curwin->w_p_fde, 0) - == FAIL - || put_setstring(fd, "setlocal", "fmr", (char_u **)&curwin->w_p_fmr, 0) - == FAIL - || put_setstring(fd, "setlocal", "fdi", (char_u **)&curwin->w_p_fdi, 0) - == FAIL + if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL + || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0) == FAIL + || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0) == FAIL + || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0) == FAIL || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL - || put_setbool(fd, "setlocal", "fen", - curwin->w_p_fen) == FAIL) { + || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL) { return FAIL; } return OK; } -static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, uint64_t flags) +static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_t flags) { char_u *s; char_u *buf = NULL; @@ -3612,7 +3606,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, uint6 // options some characters have to be escaped with // CTRL-V or backslash if (valuep == &p_pt) { - s = *valuep; + s = (char_u *)(*valuep); while (*s != NUL) { if (put_escstr(fd, (char_u *)str2special((const char **)&s, false, false), 2) @@ -3625,13 +3619,13 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, uint6 // replace home directory in the whole option value into "buf" buf = xmalloc(size); - home_replace(NULL, (char *)(*valuep), (char *)buf, size, false); + home_replace(NULL, *valuep, (char *)buf, size, false); // If the option value is longer than MAXPATHL, we need to append // each comma separated part of the option separately, so that it // can be expanded when read back. if (size >= MAXPATHL && (flags & P_COMMA) != 0 - && vim_strchr((char *)(*valuep), ',') != NULL) { + && vim_strchr(*valuep, ',') != NULL) { part = xmalloc(size); // write line break to clear the option, e.g. ':set rtp=' @@ -3659,7 +3653,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, uint6 return FAIL; } xfree(buf); - } else if (put_escstr(fd, *valuep, 2) == FAIL) { + } else if (put_escstr(fd, (char_u *)(*valuep), 2) == FAIL) { return FAIL; } } @@ -3798,12 +3792,12 @@ void unset_global_local_option(char *name, void *from) break; case PV_LCS: clear_string_option(&((win_T *)from)->w_p_lcs); - set_chars_option((win_T *)from, (char_u **)&((win_T *)from)->w_p_lcs, true); + set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs, true); redraw_later((win_T *)from, UPD_NOT_VALID); break; case PV_FCS: clear_string_option(&((win_T *)from)->w_p_fcs); - set_chars_option((win_T *)from, (char_u **)&((win_T *)from)->w_p_fcs, true); + set_chars_option((win_T *)from, &((win_T *)from)->w_p_fcs, true); redraw_later((win_T *)from, UPD_NOT_VALID); break; case PV_VE: @@ -3814,81 +3808,81 @@ void unset_global_local_option(char *name, void *from) } /// Get pointer to option variable, depending on local or global scope. -static char_u *get_varp_scope(vimoption_T *p, int opt_flags) +static char *get_varp_scope(vimoption_T *p, int opt_flags) { if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE) { if (p->var == VAR_WIN) { - return (char_u *)GLOBAL_WO(get_varp(p)); + return GLOBAL_WO(get_varp(p)); } - return p->var; + return (char *)p->var; } if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) { switch ((int)p->indir) { case PV_FP: - return (char_u *)&(curbuf->b_p_fp); + return (char *)&(curbuf->b_p_fp); case PV_EFM: - return (char_u *)&(curbuf->b_p_efm); + return (char *)&(curbuf->b_p_efm); case PV_GP: - return (char_u *)&(curbuf->b_p_gp); + return (char *)&(curbuf->b_p_gp); case PV_MP: - return (char_u *)&(curbuf->b_p_mp); + return (char *)&(curbuf->b_p_mp); case PV_EP: - return (char_u *)&(curbuf->b_p_ep); + return (char *)&(curbuf->b_p_ep); case PV_KP: - return (char_u *)&(curbuf->b_p_kp); + return (char *)&(curbuf->b_p_kp); case PV_PATH: - return (char_u *)&(curbuf->b_p_path); + return (char *)&(curbuf->b_p_path); case PV_AR: - return (char_u *)&(curbuf->b_p_ar); + return (char *)&(curbuf->b_p_ar); case PV_TAGS: - return (char_u *)&(curbuf->b_p_tags); + return (char *)&(curbuf->b_p_tags); case PV_TC: - return (char_u *)&(curbuf->b_p_tc); + return (char *)&(curbuf->b_p_tc); case PV_SISO: - return (char_u *)&(curwin->w_p_siso); + return (char *)&(curwin->w_p_siso); case PV_SO: - return (char_u *)&(curwin->w_p_so); + return (char *)&(curwin->w_p_so); case PV_DEF: - return (char_u *)&(curbuf->b_p_def); + return (char *)&(curbuf->b_p_def); case PV_INC: - return (char_u *)&(curbuf->b_p_inc); + return (char *)&(curbuf->b_p_inc); case PV_DICT: - return (char_u *)&(curbuf->b_p_dict); + return (char *)&(curbuf->b_p_dict); case PV_TSR: - return (char_u *)&(curbuf->b_p_tsr); + return (char *)&(curbuf->b_p_tsr); case PV_TSRFU: - return (char_u *)&(curbuf->b_p_tsrfu); + return (char *)&(curbuf->b_p_tsrfu); case PV_TFU: - return (char_u *)&(curbuf->b_p_tfu); + return (char *)&(curbuf->b_p_tfu); case PV_SBR: - return (char_u *)&(curwin->w_p_sbr); + return (char *)&(curwin->w_p_sbr); case PV_STL: - return (char_u *)&(curwin->w_p_stl); + return (char *)&(curwin->w_p_stl); case PV_WBR: - return (char_u *)&(curwin->w_p_wbr); + return (char *)&(curwin->w_p_wbr); case PV_UL: - return (char_u *)&(curbuf->b_p_ul); + return (char *)&(curbuf->b_p_ul); case PV_LW: - return (char_u *)&(curbuf->b_p_lw); + return (char *)&(curbuf->b_p_lw); case PV_BKC: - return (char_u *)&(curbuf->b_p_bkc); + return (char *)&(curbuf->b_p_bkc); case PV_MENC: - return (char_u *)&(curbuf->b_p_menc); + return (char *)&(curbuf->b_p_menc); case PV_FCS: - return (char_u *)&(curwin->w_p_fcs); + return (char *)&(curwin->w_p_fcs); case PV_LCS: - return (char_u *)&(curwin->w_p_lcs); + return (char *)&(curwin->w_p_lcs); case PV_VE: - return (char_u *)&(curwin->w_p_ve); + return (char *)&(curwin->w_p_ve); } return NULL; // "cannot happen" } - return get_varp(p); + return (char *)get_varp(p); } /// Get pointer to option variable at 'opt_idx', depending on local or global /// scope. -char_u *get_option_varp_scope(int opt_idx, int opt_flags) +char *get_option_varp_scope(int opt_idx, int opt_flags) { return get_varp_scope(&(options[opt_idx]), opt_flags); } @@ -4365,8 +4359,8 @@ void didset_window_options(win_T *wp, bool valid_cursor) check_colorcolumn(wp); briopt_check(wp); fill_culopt_flags(NULL, wp); - set_chars_option(wp, (char_u **)&wp->w_p_fcs, true); - set_chars_option(wp, (char_u **)&wp->w_p_lcs, true); + set_chars_option(wp, &wp->w_p_fcs, true); + set_chars_option(wp, &wp->w_p_lcs, true); parse_winhl_opt(wp); // sets w_hl_needs_update also for w_p_winbl check_blending(wp); set_winbar_win(wp, false, valid_cursor); @@ -4504,7 +4498,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_swf = p_swf; COPY_OPT_SCTX(buf, BV_SWF); } - buf->b_p_cpt = (char *)vim_strsave(p_cpt); + buf->b_p_cpt = xstrdup(p_cpt); COPY_OPT_SCTX(buf, BV_CPT); #ifdef BACKSLASH_IN_FILENAME buf->b_p_csl = vim_strsave(p_csl); @@ -4514,32 +4508,30 @@ void buf_copy_options(buf_T *buf, int flags) COPY_OPT_SCTX(buf, BV_CFU); buf->b_p_ofu = xstrdup(p_ofu); COPY_OPT_SCTX(buf, BV_OFU); - buf->b_p_tfu = (char *)vim_strsave(p_tfu); + buf->b_p_tfu = xstrdup(p_tfu); COPY_OPT_SCTX(buf, BV_TFU); buf->b_p_sts = p_sts; COPY_OPT_SCTX(buf, BV_STS); buf->b_p_sts_nopaste = p_sts_nopaste; - buf->b_p_vsts = (char *)vim_strsave(p_vsts); + buf->b_p_vsts = xstrdup(p_vsts); COPY_OPT_SCTX(buf, BV_VSTS); - if (p_vsts && p_vsts != (char_u *)empty_option) { + if (p_vsts && p_vsts != empty_option) { (void)tabstop_set(p_vsts, &buf->b_p_vsts_array); } else { buf->b_p_vsts_array = NULL; } - buf->b_p_vsts_nopaste = p_vsts_nopaste - ? (char *)vim_strsave(p_vsts_nopaste) - : NULL; + buf->b_p_vsts_nopaste = p_vsts_nopaste ? xstrdup(p_vsts_nopaste) : NULL; buf->b_p_com = xstrdup(p_com); COPY_OPT_SCTX(buf, BV_COM); - buf->b_p_cms = (char *)vim_strsave(p_cms); + buf->b_p_cms = xstrdup(p_cms); COPY_OPT_SCTX(buf, BV_CMS); - buf->b_p_fo = (char *)vim_strsave(p_fo); + buf->b_p_fo = xstrdup(p_fo); COPY_OPT_SCTX(buf, BV_FO); - buf->b_p_flp = (char *)vim_strsave(p_flp); + buf->b_p_flp = xstrdup(p_flp); COPY_OPT_SCTX(buf, BV_FLP); - buf->b_p_nf = (char *)vim_strsave(p_nf); + buf->b_p_nf = xstrdup(p_nf); COPY_OPT_SCTX(buf, BV_NF); - buf->b_p_mps = (char *)vim_strsave(p_mps); + buf->b_p_mps = xstrdup(p_mps); COPY_OPT_SCTX(buf, BV_MPS); buf->b_p_si = p_si; COPY_OPT_SCTX(buf, BV_SI); @@ -4569,25 +4561,25 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_smc = p_smc; COPY_OPT_SCTX(buf, BV_SMC); buf->b_s.b_syn_isk = empty_option; - buf->b_s.b_p_spc = (char *)vim_strsave(p_spc); + buf->b_s.b_p_spc = xstrdup(p_spc); COPY_OPT_SCTX(buf, BV_SPC); (void)compile_cap_prog(&buf->b_s); - buf->b_s.b_p_spf = (char *)vim_strsave(p_spf); + buf->b_s.b_p_spf = xstrdup(p_spf); COPY_OPT_SCTX(buf, BV_SPF); - buf->b_s.b_p_spl = (char *)vim_strsave(p_spl); + buf->b_s.b_p_spl = xstrdup(p_spl); COPY_OPT_SCTX(buf, BV_SPL); - buf->b_s.b_p_spo = (char *)vim_strsave(p_spo); + buf->b_s.b_p_spo = xstrdup(p_spo); COPY_OPT_SCTX(buf, BV_SPO); - buf->b_p_inde = (char *)vim_strsave(p_inde); + buf->b_p_inde = xstrdup(p_inde); COPY_OPT_SCTX(buf, BV_INDE); - buf->b_p_indk = (char *)vim_strsave(p_indk); + buf->b_p_indk = xstrdup(p_indk); COPY_OPT_SCTX(buf, BV_INDK); buf->b_p_fp = empty_option; - buf->b_p_fex = (char *)vim_strsave(p_fex); + buf->b_p_fex = xstrdup(p_fex); COPY_OPT_SCTX(buf, BV_FEX); buf->b_p_sua = xstrdup(p_sua); COPY_OPT_SCTX(buf, BV_SUA); - buf->b_p_keymap = (char *)vim_strsave(p_keymap); + buf->b_p_keymap = xstrdup(p_keymap); COPY_OPT_SCTX(buf, BV_KMAP); buf->b_kmap_state |= KEYMAP_INIT; // This isn't really an option, but copying the langmap and IME @@ -4614,12 +4606,12 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_tc_flags = 0; buf->b_p_def = empty_option; buf->b_p_inc = empty_option; - buf->b_p_inex = (char *)vim_strsave(p_inex); + buf->b_p_inex = xstrdup(p_inex); COPY_OPT_SCTX(buf, BV_INEX); buf->b_p_dict = empty_option; buf->b_p_tsr = empty_option; buf->b_p_tsrfu = empty_option; - buf->b_p_qe = (char *)vim_strsave(p_qe); + buf->b_p_qe = xstrdup(p_qe); COPY_OPT_SCTX(buf, BV_QE); buf->b_p_udf = p_udf; COPY_OPT_SCTX(buf, BV_UDF); @@ -4634,7 +4626,7 @@ void buf_copy_options(buf_T *buf, int flags) */ if (dont_do_help) { buf->b_p_isk = (char *)save_p_isk; - if (p_vts && p_vts != (char_u *)empty_option && !buf->b_p_vts_array) { + if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { (void)tabstop_set(p_vts, &buf->b_p_vts_array); } else { buf->b_p_vts_array = NULL; @@ -4645,9 +4637,9 @@ void buf_copy_options(buf_T *buf, int flags) did_isk = true; buf->b_p_ts = p_ts; COPY_OPT_SCTX(buf, BV_TS); - buf->b_p_vts = (char *)vim_strsave(p_vts); + buf->b_p_vts = xstrdup(p_vts); COPY_OPT_SCTX(buf, BV_VTS); - if (p_vts && p_vts != (char_u *)empty_option && !buf->b_p_vts_array) { + if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { (void)tabstop_set(p_vts, &buf->b_p_vts_array); } else { buf->b_p_vts_array = NULL; @@ -4966,7 +4958,7 @@ void ExpandOldSetting(int *num_file, char ***file) if (expand_option_idx >= 0) { // Put string of option value in NameBuff. option_value2string(&options[expand_option_idx], expand_option_flags); - var = NameBuff; + var = (char_u *)NameBuff; } else { var = (char_u *)""; } @@ -4999,9 +4991,7 @@ void ExpandOldSetting(int *num_file, char ***file) /// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL static void option_value2string(vimoption_T *opp, int opt_flags) { - char_u *varp; - - varp = get_varp_scope(opp, opt_flags); + char_u *varp = (char_u *)get_varp_scope(opp, opt_flags); if (opp->flags & P_NUM) { long wc = 0; @@ -5023,7 +5013,7 @@ static void option_value2string(vimoption_T *opp, int opt_flags) } else if (opp->flags & P_EXPAND) { home_replace(NULL, (char *)varp, (char *)NameBuff, MAXPATHL, false); // Translate 'pastetoggle' into special key names. - } else if ((char_u **)opp->var == &p_pt) { + } else if ((char **)opp->var == &p_pt) { str2specialbuf((const char *)p_pt, (char *)NameBuff, MAXPATHL); } else { STRLCPY(NameBuff, varp, MAXPATHL); @@ -5052,7 +5042,7 @@ bool shortmess(int x) return (p_shm != NULL && (vim_strchr(p_shm, x) != NULL || (vim_strchr(p_shm, 'a') != NULL - && vim_strchr((char *)SHM_ALL_ABBREVIATIONS, x) != NULL))); + && vim_strchr(SHM_ALL_ABBREVIATIONS, x) != NULL))); } /// paste_option_changed() - Called after p_paste was set or reset. @@ -5101,9 +5091,7 @@ static void paste_option_changed(void) if (p_vsts_nopaste) { xfree(p_vsts_nopaste); } - p_vsts_nopaste = p_vsts && p_vsts != (char_u *)empty_option - ? vim_strsave(p_vsts) - : NULL; + p_vsts_nopaste = p_vsts && p_vsts != empty_option ? xstrdup(p_vsts) : NULL; } // Always set the option values, also when 'paste' is set when it is @@ -5137,9 +5125,9 @@ static void paste_option_changed(void) p_sts = 0; p_ai = 0; if (p_vsts) { - free_string_option((char *)p_vsts); + free_string_option(p_vsts); } - p_vsts = (char_u *)empty_option; + p_vsts = empty_option; } else if (old_p_paste) { // Paste switched from on to off: Restore saved values. @@ -5156,7 +5144,7 @@ static void paste_option_changed(void) buf->b_p_vsts = buf->b_p_vsts_nopaste ? xstrdup(buf->b_p_vsts_nopaste) : empty_option; xfree(buf->b_p_vsts_array); if (buf->b_p_vsts && buf->b_p_vsts != empty_option) { - (void)tabstop_set((char_u *)buf->b_p_vsts, &buf->b_p_vsts_array); + (void)tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array); } else { buf->b_p_vsts_array = NULL; } @@ -5178,9 +5166,9 @@ static void paste_option_changed(void) p_tw = p_tw_nopaste; p_wm = p_wm_nopaste; if (p_vsts) { - free_string_option((char *)p_vsts); + free_string_option(p_vsts); } - p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : (char_u *)empty_option; + p_vsts = p_vsts_nopaste ? xstrdup(p_vsts_nopaste) : empty_option; } old_p_paste = p_paste; @@ -5248,20 +5236,20 @@ void fill_breakat_flags(void) } if (p_breakat != NULL) { - for (p = p_breakat; *p; p++) { + for (p = (char_u *)p_breakat; *p; p++) { breakat_flags[*p] = true; } } } /// fill_culopt_flags() -- called when 'culopt' changes value -int fill_culopt_flags(char_u *val, win_T *wp) +int fill_culopt_flags(char *val, win_T *wp) { - char_u *p; + char *p; char_u culopt_flags_new = 0; if (val == NULL) { - p = (char_u *)wp->w_p_culopt; + p = wp->w_p_culopt; } else { p = val; } @@ -5473,7 +5461,7 @@ void set_fileformat(int eol_style, int opt_flags) } /// Skip to next part of an option argument: skip space and comma -char_u *skip_to_option_part(const char_u *p) +char *skip_to_option_part(const char *p) { if (*p == ',') { p++; @@ -5481,7 +5469,7 @@ char_u *skip_to_option_part(const char_u *p) while (*p == ' ') { p++; } - return (char_u *)p; + return (char *)p; } /// Isolate one part of a string option separated by `sep_chars`. @@ -5516,7 +5504,7 @@ size_t copy_option_part(char **option, char *buf, size_t maxlen, char *sep_chars if (*p != NUL && *p != ',') { // skip non-standard separator p++; } - p = (char *)skip_to_option_part((char_u *)p); // p points to next file name + p = skip_to_option_part(p); // p points to next file name *option = p; return len; diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 59b8485272..6af6b16e86 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -258,7 +258,7 @@ enum { SHM_SEARCHCOUNT = 'S', ///< Search sats: '[1/10]' }; /// Represented by 'a' flag. -#define SHM_ALL_ABBREVIATIONS ((char_u[]) { \ +#define SHM_ALL_ABBREVIATIONS ((char[]) { \ SHM_RO, SHM_MOD, SHM_FILE, SHM_LAST, SHM_TEXT, SHM_LINES, SHM_NEW, SHM_WRI, \ 0, \ }) @@ -440,9 +440,9 @@ EXTERN unsigned bo_flags; #define BO_WILD 0x40000 EXTERN char_u *p_bsk; // 'backupskip' -EXTERN char_u *p_breakat; // 'breakat' -EXTERN char_u *p_bh; ///< 'bufhidden' -EXTERN char_u *p_bt; ///< 'buftype' +EXTERN char *p_breakat; // 'breakat' +EXTERN char *p_bh; ///< 'bufhidden' +EXTERN char *p_bt; ///< 'buftype' EXTERN char *p_cmp; // 'casemap' EXTERN unsigned cmp_flags; #define CMP_INTERNAL 0x001 @@ -459,8 +459,8 @@ EXTERN unsigned cb_flags; #define CB_UNNAMEDMASK (CB_UNNAMED | CB_UNNAMEDPLUS) EXTERN long p_cwh; // 'cmdwinheight' EXTERN long p_ch; // 'cmdheight' -EXTERN char_u *p_cms; ///< 'commentstring' -EXTERN char_u *p_cpt; ///< 'complete' +EXTERN char *p_cms; ///< 'commentstring' +EXTERN char *p_cpt; ///< 'complete' EXTERN long p_columns; // 'columns' EXTERN int p_confirm; // 'confirm' EXTERN char *p_cot; // 'completeopt' @@ -533,9 +533,9 @@ EXTERN unsigned fdo_flags; #define FDO_INSERT 0x100 #define FDO_UNDO 0x200 #define FDO_JUMP 0x400 -EXTERN char_u *p_fex; ///< 'formatexpr' -EXTERN char_u *p_flp; ///< 'formatlistpat' -EXTERN char_u *p_fo; ///< 'formatoptions' +EXTERN char *p_fex; ///< 'formatexpr' +EXTERN char *p_flp; ///< 'formatlistpat' +EXTERN char *p_fo; ///< 'formatoptions' EXTERN char_u *p_fp; // 'formatprg' EXTERN int p_fs; // 'fsync' EXTERN int p_gd; // 'gdefault' @@ -566,10 +566,10 @@ EXTERN int p_ic; // 'ignorecase' EXTERN long p_iminsert; ///< 'iminsert' EXTERN long p_imsearch; ///< 'imsearch' EXTERN int p_inf; ///< 'infercase' -EXTERN char_u *p_inex; ///< 'includeexpr' +EXTERN char *p_inex; ///< 'includeexpr' EXTERN int p_is; // 'incsearch' -EXTERN char_u *p_inde; ///< 'indentexpr' -EXTERN char_u *p_indk; ///< 'indentkeys' +EXTERN char *p_inde; ///< 'indentexpr' +EXTERN char *p_indk; ///< 'indentkeys' EXTERN char *p_icm; // 'inccommand' EXTERN char *p_isf; // 'isfname' EXTERN char *p_isi; // 'isident' @@ -580,7 +580,7 @@ EXTERN char *p_jop; // 'jumpooptions' EXTERN unsigned jop_flags; #define JOP_STACK 0x01 #define JOP_VIEW 0x02 -EXTERN char_u *p_keymap; ///< 'keymap' +EXTERN char *p_keymap; ///< 'keymap' EXTERN char_u *p_kp; // 'keywordprg' EXTERN char *p_km; // 'keymodel' EXTERN char *p_langmap; // 'langmap' @@ -598,11 +598,11 @@ EXTERN char *p_lcs; // 'listchars' EXTERN int p_lz; // 'lazyredraw' EXTERN int p_lpl; // 'loadplugins' EXTERN int p_magic; // 'magic' -EXTERN char_u *p_menc; // 'makeencoding' -EXTERN char *p_mef; // 'makeef' -EXTERN char_u *p_mp; // 'makeprg' -EXTERN char_u *p_mps; ///< 'matchpairs' -EXTERN char_u *p_cc; // 'colorcolumn' +EXTERN char *p_menc; // 'makeencoding' +EXTERN char *p_mef; // 'makeef' +EXTERN char_u *p_mp; // 'makeprg' +EXTERN char *p_mps; ///< 'matchpairs' +EXTERN char_u *p_cc; // 'colorcolumn' EXTERN int p_cc_cols[256]; // array for 'colorcolumn' columns EXTERN long p_mat; // 'matchtime' EXTERN long p_mco; // 'maxcombine' @@ -624,18 +624,18 @@ EXTERN long p_mousescroll_vert INIT(= MOUSESCROLL_VERT_DFLT); EXTERN long p_mousescroll_hor INIT(= MOUSESCROLL_HOR_DFLT); EXTERN long p_mouset; // 'mousetime' EXTERN int p_more; // 'more' -EXTERN char_u *p_nf; ///< 'nrformats' +EXTERN char *p_nf; ///< 'nrformats' EXTERN char *p_opfunc; // 'operatorfunc' -EXTERN char_u *p_para; // 'paragraphs' +EXTERN char_u *p_para; // 'paragraphs' EXTERN int p_paste; // 'paste' -EXTERN char_u *p_pt; // 'pastetoggle' -EXTERN char_u *p_pex; // 'patchexpr' -EXTERN char *p_pm; // 'patchmode' -EXTERN char_u *p_path; // 'path' -EXTERN char_u *p_cdpath; // 'cdpath' +EXTERN char *p_pt; // 'pastetoggle' +EXTERN char_u *p_pex; // 'patchexpr' +EXTERN char *p_pm; // 'patchmode' +EXTERN char_u *p_path; // 'path' +EXTERN char_u *p_cdpath; // 'cdpath' EXTERN int p_pi; ///< 'preserveindent' EXTERN long p_pyx; // 'pyxversion' -EXTERN char_u *p_qe; ///< 'quoteescape' +EXTERN char *p_qe; ///< 'quoteescape' EXTERN int p_ro; ///< 'readonly' EXTERN char *p_rdb; // 'redrawdebug' EXTERN unsigned rdb_flags; @@ -685,13 +685,13 @@ EXTERN unsigned ssop_flags; #define SSOP_TERMINAL 0x10000 #define SSOP_SKIP_RTP 0x20000 -EXTERN char_u *p_sh; // 'shell' -EXTERN char_u *p_shcf; // 'shellcmdflag' -EXTERN char_u *p_sp; // 'shellpipe' -EXTERN char_u *p_shq; // 'shellquote' -EXTERN char_u *p_sxq; // 'shellxquote' -EXTERN char_u *p_sxe; // 'shellxescape' -EXTERN char_u *p_srr; // 'shellredir' +EXTERN char_u *p_sh; // 'shell' +EXTERN char_u *p_shcf; // 'shellcmdflag' +EXTERN char *p_sp; // 'shellpipe' +EXTERN char_u *p_shq; // 'shellquote' +EXTERN char_u *p_sxq; // 'shellxquote' +EXTERN char_u *p_sxe; // 'shellxescape' +EXTERN char *p_srr; // 'shellredir' EXTERN int p_stmp; // 'shelltemp' #ifdef BACKSLASH_IN_FILENAME EXTERN int p_ssl; // 'shellslash' @@ -727,11 +727,11 @@ EXTERN unsigned int tpf_flags; ///< flags from 'termpastefilter' #define TPF_DEL 0x010 #define TPF_C0 0x020 #define TPF_C1 0x040 -EXTERN char_u *p_tfu; ///< 'tagfunc' -EXTERN char_u *p_spc; ///< 'spellcapcheck' -EXTERN char_u *p_spf; ///< 'spellfile' -EXTERN char_u *p_spl; ///< 'spelllang' -EXTERN char_u *p_spo; // 'spelloptions' +EXTERN char *p_tfu; ///< 'tagfunc' +EXTERN char *p_spc; ///< 'spellcapcheck' +EXTERN char *p_spf; ///< 'spellfile' +EXTERN char *p_spl; ///< 'spelllang' +EXTERN char *p_spo; // 'spelloptions' EXTERN char *p_sps; // 'spellsuggest' EXTERN int p_spr; // 'splitright' EXTERN int p_sol; // 'startofline' @@ -745,7 +745,7 @@ EXTERN unsigned swb_flags; #define SWB_NEWTAB 0x008 #define SWB_VSPLIT 0x010 #define SWB_USELAST 0x020 -EXTERN char_u *p_syn; ///< 'syntax' +EXTERN char *p_syn; ///< 'syntax' EXTERN long p_ts; ///< 'tabstop' EXTERN int p_tbs; ///< 'tagbsearch' EXTERN char *p_tc; ///< 'tagcase' @@ -780,13 +780,13 @@ EXTERN long p_uc; ///< 'updatecount' EXTERN long p_ut; ///< 'updatetime' EXTERN char *p_shada; ///< 'shada' EXTERN char *p_shadafile; ///< 'shadafile' -EXTERN char_u *p_vsts; ///< 'varsofttabstop' -EXTERN char_u *p_vts; ///< 'vartabstop' +EXTERN char *p_vsts; ///< 'varsofttabstop' +EXTERN char *p_vts; ///< 'vartabstop' EXTERN char_u *p_vdir; ///< 'viewdir' EXTERN char *p_vop; ///< 'viewoptions' EXTERN unsigned vop_flags; ///< uses SSOP_ flags EXTERN int p_vb; ///< 'visualbell' -EXTERN char_u *p_ve; ///< 'virtualedit' +EXTERN char *p_ve; ///< 'virtualedit' EXTERN unsigned ve_flags; #define VE_BLOCK 5U // includes "all" #define VE_INSERT 6U // includes "all" @@ -798,7 +798,7 @@ EXTERN long p_verbose; // 'verbose' #ifdef IN_OPTION_C char_u *p_vfile = (char_u *)""; // used before options are initialized #else -extern char_u *p_vfile; // 'verbosefile' +extern char *p_vfile; // 'verbosefile' #endif EXTERN int p_warn; // 'warn' EXTERN char *p_wop; // 'wildoptions' diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 808a70c8cb..1bdfcbecb9 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -113,30 +113,30 @@ static char *(p_tpf_values[]) = { "BS", "HT", "FF", "ESC", "DEL", "C0", "C1", NU static char *(p_rdb_values[]) = { "compositor", "nothrottle", "invalid", "nodelta", NULL }; /// All possible flags for 'shm'. -static char_u SHM_ALL[] = { SHM_RO, SHM_MOD, SHM_FILE, SHM_LAST, SHM_TEXT, SHM_LINES, SHM_NEW, - SHM_WRI, SHM_ABBREVIATIONS, SHM_WRITE, SHM_TRUNC, SHM_TRUNCALL, - SHM_OVER, SHM_OVERALL, SHM_SEARCH, SHM_ATTENTION, SHM_INTRO, - SHM_COMPLETIONMENU, SHM_RECORDING, SHM_FILEINFO, SHM_SEARCHCOUNT, 0, }; +static char SHM_ALL[] = { SHM_RO, SHM_MOD, SHM_FILE, SHM_LAST, SHM_TEXT, SHM_LINES, SHM_NEW, + SHM_WRI, SHM_ABBREVIATIONS, SHM_WRITE, SHM_TRUNC, SHM_TRUNCALL, + SHM_OVER, SHM_OVERALL, SHM_SEARCH, SHM_ATTENTION, SHM_INTRO, + SHM_COMPLETIONMENU, SHM_RECORDING, SHM_FILEINFO, SHM_SEARCHCOUNT, 0, }; /// After setting various option values: recompute variables that depend on /// option values. void didset_string_options(void) { - (void)opt_strings_flags((char_u *)p_cmp, p_cmp_values, &cmp_flags, true); - (void)opt_strings_flags((char_u *)p_bkc, p_bkc_values, &bkc_flags, true); - (void)opt_strings_flags((char_u *)p_bo, p_bo_values, &bo_flags, true); - (void)opt_strings_flags((char_u *)p_ssop, p_ssop_values, &ssop_flags, true); - (void)opt_strings_flags((char_u *)p_vop, p_ssop_values, &vop_flags, true); - (void)opt_strings_flags((char_u *)p_fdo, p_fdo_values, &fdo_flags, true); - (void)opt_strings_flags((char_u *)p_dy, p_dy_values, &dy_flags, true); - (void)opt_strings_flags((char_u *)p_rdb, p_rdb_values, &rdb_flags, true); - (void)opt_strings_flags((char_u *)p_tc, p_tc_values, &tc_flags, false); - (void)opt_strings_flags((char_u *)p_tpf, p_tpf_values, &tpf_flags, true); + (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, true); + (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, true); + (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, true); + (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, true); + (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, true); + (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, true); + (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, true); + (void)opt_strings_flags(p_rdb, p_rdb_values, &rdb_flags, true); + (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, false); + (void)opt_strings_flags(p_tpf, p_tpf_values, &tpf_flags, true); (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, true); - (void)opt_strings_flags((char_u *)p_swb, p_swb_values, &swb_flags, true); - (void)opt_strings_flags((char_u *)p_wop, p_wop_values, &wop_flags, true); - (void)opt_strings_flags((char_u *)p_jop, p_jop_values, &jop_flags, true); - (void)opt_strings_flags((char_u *)p_cb, p_cb_values, &cb_flags, true); + (void)opt_strings_flags(p_swb, p_swb_values, &swb_flags, true); + (void)opt_strings_flags(p_wop, p_wop_values, &wop_flags, true); + (void)opt_strings_flags(p_jop, p_jop_values, &jop_flags, true); + (void)opt_strings_flags(p_cb, p_cb_values, &cb_flags, true); } /// Trigger the OptionSet autocommand. @@ -448,7 +448,7 @@ char *set_string_option(const int opt_idx, const char *const value, const int op /// Return true if "val" is a valid 'filetype' name. /// Also used for 'syntax' and 'keymap'. -static bool valid_filetype(const char_u *val) +static bool valid_filetype(const char *val) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { return valid_name(val, ".-_"); @@ -520,7 +520,7 @@ static char *check_mousescroll(char *string) /// Handle setting 'signcolumn' for value 'val' /// /// @return OK when the value is valid, FAIL otherwise -static int check_signcolumn(char_u *val) +static int check_signcolumn(char *val) { if (*val == NUL) { return FAIL; @@ -637,13 +637,12 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf char *errmsg = NULL; char *s, *p; int did_chartab = false; - char_u **gvarp; bool free_oldval = (get_option_flags(opt_idx) & P_ALLOCED); bool value_changed = false; // Get the global option to compare with, otherwise we would have to check // two values for all local options. - gvarp = (char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL); + char **gvarp = (char **)get_option_varp_scope(opt_idx, OPT_GLOBAL); // Disallow changing some options from secure mode if ((secure || sandbox != 0) @@ -657,7 +656,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf // path separator (slash and/or backslash), wildcards and characters that // are often illegal in a file name. Be more permissive if "secure" is off. errmsg = e_invarg; - } else if (gvarp == (char_u **)&p_bkc) { // 'backupcopy' + } else if (gvarp == &p_bkc) { // 'backupcopy' char *bkc = p_bkc; unsigned int *flags = &bkc_flags; @@ -670,7 +669,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf // make the local value empty: use the global value *flags = 0; } else { - if (opt_strings_flags((char_u *)bkc, p_bkc_values, flags, true) != OK) { + if (opt_strings_flags(bkc, p_bkc_values, flags, true) != OK) { errmsg = e_invarg; } @@ -678,7 +677,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf + ((*flags & BKC_YES) != 0) + ((*flags & BKC_NO) != 0) != 1) { // Must have exactly one of "auto", "yes" and "no". - (void)opt_strings_flags((char_u *)oldval, p_bkc_values, flags, true); + (void)opt_strings_flags(oldval, p_bkc_values, flags, true); errmsg = e_invarg; } } @@ -713,8 +712,8 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } else if (varp == &p_rtp || varp == &p_pp) { // 'runtimepath' 'packpath' runtime_search_path_invalidate(); } else if (varp == &curwin->w_p_culopt - || gvarp == (char_u **)&curwin->w_allbuf_opt.wo_culopt) { // 'cursorlineopt' - if (**varp == NUL || fill_culopt_flags((char_u *)(*varp), curwin) != OK) { + || gvarp == &curwin->w_allbuf_opt.wo_culopt) { // 'cursorlineopt' + if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK) { errmsg = e_invarg; } } else if (varp == &curwin->w_p_cc) { // 'colorcolumn' @@ -735,42 +734,42 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf errmsg = e_unsupportedoption; } } else if (varp == &p_jop) { // 'jumpoptions' - if (opt_strings_flags((char_u *)p_jop, p_jop_values, &jop_flags, true) != OK) { + if (opt_strings_flags(p_jop, p_jop_values, &jop_flags, true) != OK) { errmsg = e_invarg; } } else if (gvarp == &p_nf) { // 'nrformats' - if (check_opt_strings((char_u *)(*varp), p_nf_values, true) != OK) { + if (check_opt_strings(*varp, p_nf_values, true) != OK) { errmsg = e_invarg; } } else if (varp == &p_ssop) { // 'sessionoptions' - if (opt_strings_flags((char_u *)p_ssop, p_ssop_values, &ssop_flags, true) != OK) { + if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, true) != OK) { errmsg = e_invarg; } if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR)) { // Don't allow both "sesdir" and "curdir". - (void)opt_strings_flags((char_u *)oldval, p_ssop_values, &ssop_flags, true); + (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, true); errmsg = e_invarg; } } else if (varp == &p_vop) { // 'viewoptions' - if (opt_strings_flags((char_u *)p_vop, p_ssop_values, &vop_flags, true) != OK) { + if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, true) != OK) { errmsg = e_invarg; } } else if (varp == &p_rdb) { // 'redrawdebug' - if (opt_strings_flags((char_u *)p_rdb, p_rdb_values, &rdb_flags, true) != OK) { + if (opt_strings_flags(p_rdb, p_rdb_values, &rdb_flags, true) != OK) { errmsg = e_invarg; } } else if (varp == &p_sbo) { // 'scrollopt' - if (check_opt_strings((char_u *)p_sbo, p_scbopt_values, true) != OK) { + if (check_opt_strings(p_sbo, p_scbopt_values, true) != OK) { errmsg = e_invarg; } } else if (varp == &p_ambw || (int *)varp == &p_emoji) { // 'ambiwidth' - if (check_opt_strings((char_u *)p_ambw, p_ambw_values, false) != OK) { + if (check_opt_strings(p_ambw, p_ambw_values, false) != OK) { errmsg = e_invarg; } else { errmsg = check_chars_options(); } } else if (varp == &p_bg) { // 'background' - if (check_opt_strings((char_u *)p_bg, p_bg_values, false) == OK) { + if (check_opt_strings(p_bg, p_bg_values, false) == OK) { int dark = (*p_bg == 'd'); init_highlight(false, false); @@ -793,21 +792,21 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf errmsg = e_invarg; } } else if (varp == &p_wop) { // 'wildoptions' - if (opt_strings_flags((char_u *)p_wop, p_wop_values, &wop_flags, true) != OK) { + if (opt_strings_flags(p_wop, p_wop_values, &wop_flags, true) != OK) { errmsg = e_invarg; } } else if (varp == &p_wak) { // 'winaltkeys' if (*p_wak == NUL - || check_opt_strings((char_u *)p_wak, p_wak_values, false) != OK) { + || check_opt_strings(p_wak, p_wak_values, false) != OK) { errmsg = e_invarg; } } else if (varp == &p_ei) { // 'eventignore' if (check_ei() == FAIL) { errmsg = e_invarg; } - } else if (varp == &p_enc || gvarp == (char_u **)&p_fenc || gvarp == &p_menc) { + } else if (varp == &p_enc || gvarp == &p_fenc || gvarp == &p_menc) { // 'encoding', 'fileencoding' and 'makeencoding' - if (gvarp == (char_u **)&p_fenc) { + if (gvarp == &p_fenc) { if (!MODIFIABLE(curbuf) && opt_flags != OPT_GLOBAL) { errmsg = e_modifiable; } else if (vim_strchr(*varp, ',') != NULL) { @@ -824,7 +823,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf if (errmsg == NULL) { // canonize the value, so that STRCMP() can be used on it - p = (char *)enc_canonize((char_u *)(*varp)); + p = enc_canonize(*varp); xfree(*varp); *varp = p; if (varp == &p_enc) { @@ -838,11 +837,11 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } } else if (varp == &p_penc) { // Canonize printencoding if VIM standard one - p = (char *)enc_canonize((char_u *)p_penc); + p = enc_canonize(p_penc); xfree(p_penc); p_penc = p; } else if (varp == &curbuf->b_p_keymap) { - if (!valid_filetype((char_u *)(*varp))) { + if (!valid_filetype(*varp)) { errmsg = e_invarg; } else { int secure_save = secure; @@ -883,10 +882,10 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } status_redraw_curbuf(); } - } else if (gvarp == (char_u **)&p_ff) { // 'fileformat' + } else if (gvarp == &p_ff) { // 'fileformat' if (!MODIFIABLE(curbuf) && !(opt_flags & OPT_GLOBAL)) { errmsg = e_modifiable; - } else if (check_opt_strings((char_u *)(*varp), p_ff_values, false) != OK) { + } else if (check_opt_strings(*varp, p_ff_values, false) != OK) { errmsg = e_invarg; } else { redraw_titles(); @@ -899,7 +898,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } } } else if (varp == &p_ffs) { // 'fileformats' - if (check_opt_strings((char_u *)p_ffs, p_ff_values, true) != OK) { + if (check_opt_strings(p_ffs, p_ff_values, true) != OK) { errmsg = e_invarg; } } else if (gvarp == &p_mps) { // 'matchpairs' @@ -923,7 +922,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf break; } } - } else if (gvarp == (char_u **)&p_com) { // 'comments' + } else if (gvarp == &p_com) { // 'comments' for (s = *varp; *s;) { while (*s && *s != ':') { if (vim_strchr(COM_ALL, *s) == NULL @@ -947,13 +946,13 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } s++; } - s = (char *)skip_to_option_part((char_u *)s); + s = skip_to_option_part(s); } } else if (varp == &p_lcs || varp == &p_fcs) { // global 'listchars' or 'fillchars' char **local_ptr = varp == &p_lcs ? &curwin->w_p_lcs : &curwin->w_p_fcs; // only apply the global value to "curwin" when it does not have a local value errmsg = - set_chars_option(curwin, (char_u **)varp, **local_ptr == NUL || !(opt_flags & OPT_GLOBAL)); + set_chars_option(curwin, varp, **local_ptr == NUL || !(opt_flags & OPT_GLOBAL)); if (errmsg == NULL) { // If the current window is set to use the global // 'listchars'/'fillchars' value, clear the window-local value. @@ -967,18 +966,18 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf // here, so ignore the return value. local_ptr = varp == &p_lcs ? &wp->w_p_lcs : &wp->w_p_fcs; if (**local_ptr == NUL) { - (void)set_chars_option(wp, (char_u **)local_ptr, true); + (void)set_chars_option(wp, local_ptr, true); } } redraw_all_later(UPD_NOT_VALID); } } else if (varp == &curwin->w_p_lcs) { // local 'listchars' - errmsg = set_chars_option(curwin, (char_u **)varp, true); + errmsg = set_chars_option(curwin, varp, true); } else if (varp == &curwin->w_p_fcs) { // local 'fillchars' - errmsg = set_chars_option(curwin, (char_u **)varp, true); + errmsg = set_chars_option(curwin, varp, true); } else if (varp == &p_cedit) { // 'cedit' errmsg = check_cedit(); - } else if (varp == (char **)&p_vfile) { // 'verbosefile' + } else if (varp == &p_vfile) { // 'verbosefile' verbose_stop(); if (*p_vfile != NUL && verbose_open() == FAIL) { errmsg = e_invarg; @@ -1037,7 +1036,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf if (*p_shada && errmsg == NULL && get_shada_parameter('\'') < 0) { errmsg = N_("E528: Must specify a ' value"); } - } else if (gvarp == (char_u **)&p_sbr) { // 'showbreak' + } else if (gvarp == &p_sbr) { // 'showbreak' for (s = *varp; *s;) { if (ptr2cells(s) != 1) { errmsg = e_showbreak_contains_unprintable_or_wide_character; @@ -1052,7 +1051,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf errmsg = parse_printmbfont(); } else if (varp == &p_langmap) { // 'langmap' langmap_set(); - } else if (varp == (char **)&p_breakat) { // 'breakat' + } else if (varp == &p_breakat) { // 'breakat' fill_breakat_flags(); } else if (varp == &p_titlestring || varp == &p_iconstring) { // 'titlestring' and 'iconstring' @@ -1067,47 +1066,47 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf did_set_title(); } else if (varp == &p_sel) { // 'selection' if (*p_sel == NUL - || check_opt_strings((char_u *)p_sel, p_sel_values, false) != OK) { + || check_opt_strings(p_sel, p_sel_values, false) != OK) { errmsg = e_invarg; } } else if (varp == &p_slm) { // 'selectmode' - if (check_opt_strings((char_u *)p_slm, p_slm_values, true) != OK) { + if (check_opt_strings(p_slm, p_slm_values, true) != OK) { errmsg = e_invarg; } } else if (varp == &p_km) { // 'keymodel' - if (check_opt_strings((char_u *)p_km, p_km_values, true) != OK) { + if (check_opt_strings(p_km, p_km_values, true) != OK) { errmsg = e_invarg; } else { km_stopsel = (vim_strchr(p_km, 'o') != NULL); km_startsel = (vim_strchr(p_km, 'a') != NULL); } } else if (varp == &p_mousem) { // 'mousemodel' - if (check_opt_strings((char_u *)p_mousem, p_mousem_values, false) != OK) { + if (check_opt_strings(p_mousem, p_mousem_values, false) != OK) { errmsg = e_invarg; } } else if (varp == &p_mousescroll) { // 'mousescroll' errmsg = check_mousescroll(p_mousescroll); } else if (varp == &p_swb) { // 'switchbuf' - if (opt_strings_flags((char_u *)p_swb, p_swb_values, &swb_flags, true) != OK) { + if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, true) != OK) { errmsg = e_invarg; } } else if (varp == &p_debug) { // 'debug' - if (check_opt_strings((char_u *)p_debug, p_debug_values, true) != OK) { + if (check_opt_strings(p_debug, p_debug_values, true) != OK) { errmsg = e_invarg; } } else if (varp == &p_dy) { // 'display' - if (opt_strings_flags((char_u *)p_dy, p_dy_values, &dy_flags, true) != OK) { + if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, true) != OK) { errmsg = e_invarg; } else { (void)init_chartab(); msg_grid_validate(); } } else if (varp == &p_ead) { // 'eadirection' - if (check_opt_strings((char_u *)p_ead, p_ead_values, false) != OK) { + if (check_opt_strings(p_ead, p_ead_values, false) != OK) { errmsg = e_invarg; } } else if (varp == &p_cb) { // 'clipboard' - if (opt_strings_flags((char_u *)p_cb, p_cb_values, &cb_flags, true) != OK) { + if (opt_strings_flags(p_cb, p_cb_values, &cb_flags, true) != OK) { errmsg = e_invarg; } } else if (varp == &(curwin->w_s->b_p_spl) // 'spell' @@ -1116,8 +1115,8 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf // buffer in which 'spell' is set load the wordlists. const bool is_spellfile = varp == &(curwin->w_s->b_p_spf); - if ((is_spellfile && !valid_spellfile((char_u *)(*varp))) - || (!is_spellfile && !valid_spelllang((char_u *)(*varp)))) { + if ((is_spellfile && !valid_spellfile(*varp)) + || (!is_spellfile && !valid_spelllang(*varp))) { errmsg = e_invarg; } else { errmsg = did_set_spell_option(is_spellfile); @@ -1139,14 +1138,14 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } } else if (gvarp == &p_bh) { // When 'bufhidden' is set, check for valid value. - if (check_opt_strings((char_u *)curbuf->b_p_bh, p_bufhidden_values, false) != OK) { + if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, false) != OK) { errmsg = e_invarg; } } else if (gvarp == &p_bt) { // When 'buftype' is set, check for valid value. if ((curbuf->terminal && curbuf->b_p_bt[0] != 't') || (!curbuf->terminal && curbuf->b_p_bt[0] == 't') - || check_opt_strings((char_u *)curbuf->b_p_bt, p_buftype_values, false) != OK) { + || check_opt_strings(curbuf->b_p_bt, p_buftype_values, false) != OK) { errmsg = e_invarg; } else { if (curwin->w_status_height || global_stl_height()) { @@ -1156,7 +1155,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf curbuf->b_help = (curbuf->b_p_bt[0] == 'h'); redraw_titles(); } - } else if (gvarp == (char_u **)&p_stl || gvarp == (char_u **)&p_wbr || varp == &p_tal + } else if (gvarp == &p_stl || gvarp == &p_wbr || varp == &p_tal || varp == &p_ruf) { // 'statusline', 'winbar', 'tabline' or 'rulerformat' int wid; @@ -1184,7 +1183,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf comp_col(); } // add / remove window bars for 'winbar' - if (gvarp == (char_u **)&p_wbr) { + if (gvarp == &p_wbr) { set_winbar(true); } } else if (gvarp == &p_cpt) { @@ -1223,7 +1222,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } } } else if (varp == &p_cot) { // 'completeopt' - if (check_opt_strings((char_u *)p_cot, p_cot_values, true) != OK) { + if (check_opt_strings(p_cot, p_cot_values, true) != OK) { errmsg = e_invarg; } else { completeopt_was_set(); @@ -1236,7 +1235,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } #endif } else if (varp == &curwin->w_p_scl) { // 'signcolumn' - if (check_signcolumn((char_u *)(*varp)) != OK) { + if (check_signcolumn(*varp) != OK) { errmsg = e_invarg; } // When changing the 'signcolumn' to or from 'number', recompute the @@ -1249,20 +1248,20 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } else if (varp == &curwin->w_p_fdc || varp == &curwin->w_allbuf_opt.wo_fdc) { // 'foldcolumn' - if (**varp == NUL || check_opt_strings((char_u *)(*varp), p_fdc_values, false) != OK) { + if (**varp == NUL || check_opt_strings(*varp, p_fdc_values, false) != OK) { errmsg = e_invarg; } - } else if (varp == (char **)&p_pt) { + } else if (varp == &p_pt) { // 'pastetoggle': translate key codes like in a mapping if (*p_pt) { p = NULL; - (void)replace_termcodes((char *)p_pt, + (void)replace_termcodes(p_pt, STRLEN(p_pt), &p, REPTERM_FROM_PART | REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); if (p != NULL) { - free_string_option((char *)p_pt); - p_pt = (char_u *)p; + free_string_option(p_pt); + p_pt = p; } } } else if (varp == &p_bs) { // 'backspace' @@ -1270,14 +1269,14 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf if (*p_bs > '3' || p_bs[1] != NUL) { errmsg = e_invarg; } - } else if (check_opt_strings((char_u *)p_bs, p_bs_values, true) != OK) { + } else if (check_opt_strings(p_bs, p_bs_values, true) != OK) { errmsg = e_invarg; } } else if (varp == &p_bo) { - if (opt_strings_flags((char_u *)p_bo, p_bo_values, &bo_flags, true) != OK) { + if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, true) != OK) { errmsg = e_invarg; } - } else if (gvarp == (char_u **)&p_tc) { // 'tagcase' + } else if (gvarp == &p_tc) { // 'tagcase' unsigned int *flags; if (opt_flags & OPT_LOCAL) { @@ -1292,19 +1291,19 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf // make the local value empty: use the global value *flags = 0; } else if (*p == NUL - || opt_strings_flags((char_u *)p, p_tc_values, flags, false) != OK) { + || opt_strings_flags(p, p_tc_values, flags, false) != OK) { errmsg = e_invarg; } } else if (varp == &p_cmp) { // 'casemap' - if (opt_strings_flags((char_u *)p_cmp, p_cmp_values, &cmp_flags, true) != OK) { + if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, true) != OK) { errmsg = e_invarg; } } else if (varp == &p_dip) { // 'diffopt' if (diffopt_changed() == FAIL) { errmsg = e_invarg; } - } else if (gvarp == (char_u **)&curwin->w_allbuf_opt.wo_fdm) { // 'foldmethod' - if (check_opt_strings((char_u *)(*varp), p_fdm_values, false) != OK + } else if (gvarp == &curwin->w_allbuf_opt.wo_fdm) { // 'foldmethod' + if (check_opt_strings(*varp, p_fdm_values, false) != OK || *curwin->w_p_fdm == NUL) { errmsg = e_invarg; } else { @@ -1317,7 +1316,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf if (foldmethodIsExpr(curwin)) { foldUpdateAll(curwin); } - } else if (gvarp == (char_u **)&curwin->w_allbuf_opt.wo_fmr) { // 'foldmarker' + } else if (gvarp == &curwin->w_allbuf_opt.wo_fmr) { // 'foldmarker' p = vim_strchr(*varp, ','); if (p == NULL) { errmsg = N_("E536: comma required"); @@ -1331,23 +1330,23 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf errmsg = N_("E537: 'commentstring' must be empty or contain %s"); } } else if (varp == &p_fdo) { // 'foldopen' - if (opt_strings_flags((char_u *)p_fdo, p_fdo_values, &fdo_flags, true) != OK) { + if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, true) != OK) { errmsg = e_invarg; } } else if (varp == &p_fcl) { // 'foldclose' - if (check_opt_strings((char_u *)p_fcl, p_fcl_values, true) != OK) { + if (check_opt_strings(p_fcl, p_fcl_values, true) != OK) { errmsg = e_invarg; } - } else if (gvarp == (char_u **)&curwin->w_allbuf_opt.wo_fdi) { // 'foldignore' + } else if (gvarp == &curwin->w_allbuf_opt.wo_fdi) { // 'foldignore' if (foldmethodIsIndent(curwin)) { foldUpdateAll(curwin); } } else if (gvarp == &p_ve) { // 'virtualedit' - char_u *ve = p_ve; + char *ve = p_ve; unsigned int *flags = &ve_flags; if (opt_flags & OPT_LOCAL) { - ve = (char_u *)curwin->w_p_ve; + ve = curwin->w_p_ve; flags = &curwin->w_ve_flags; } @@ -1381,15 +1380,15 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } } } - } else if (gvarp == (char_u **)&p_cino) { // 'cinoptions' + } else if (gvarp == &p_cino) { // 'cinoptions' // TODO(vim): recognize errors parse_cino(curbuf); } else if (varp == &p_icm) { // 'inccommand' - if (check_opt_strings((char_u *)p_icm, p_icm_values, false) != OK) { + if (check_opt_strings(p_icm, p_icm_values, false) != OK) { errmsg = e_invarg; } - } else if (gvarp == (char_u **)&p_ft) { - if (!valid_filetype((char_u *)(*varp))) { + } else if (gvarp == &p_ft) { + if (!valid_filetype(*varp)) { errmsg = e_invarg; } else { value_changed = STRCMP(oldval, *varp) != 0; @@ -1399,7 +1398,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf *value_checked = true; } } else if (gvarp == &p_syn) { - if (!valid_filetype((char_u *)(*varp))) { + if (!valid_filetype(*varp)) { errmsg = e_invarg; } else { value_changed = STRCMP(oldval, *varp) != 0; @@ -1413,20 +1412,20 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf errmsg = e_invarg; } } else if (varp == &p_tpf) { - if (opt_strings_flags((char_u *)p_tpf, p_tpf_values, &tpf_flags, true) != OK) { + if (opt_strings_flags(p_tpf, p_tpf_values, &tpf_flags, true) != OK) { errmsg = e_invarg; } } else if (varp == &(curbuf->b_p_vsts)) { // 'varsofttabstop' - char_u *cp; + char *cp; if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) { XFREE_CLEAR(curbuf->b_p_vsts_array); } else { - for (cp = (char_u *)(*varp); *cp; cp++) { + for (cp = *varp; *cp; cp++) { if (ascii_isdigit(*cp)) { continue; } - if (*cp == ',' && cp > (char_u *)(*varp) && *(cp - 1) != ',') { + if (*cp == ',' && cp > *varp && *(cp - 1) != ',') { continue; } errmsg = e_invarg; @@ -1434,7 +1433,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } if (errmsg == NULL) { long *oldarray = curbuf->b_p_vsts_array; - if (tabstop_set((char_u *)(*varp), &(curbuf->b_p_vsts_array))) { + if (tabstop_set(*varp, &(curbuf->b_p_vsts_array))) { xfree(oldarray); } else { errmsg = e_invarg; @@ -1442,16 +1441,16 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } } } else if (varp == &(curbuf->b_p_vts)) { // 'vartabstop' - char_u *cp; + char *cp; if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) { XFREE_CLEAR(curbuf->b_p_vts_array); } else { - for (cp = (char_u *)(*varp); *cp; cp++) { + for (cp = *varp; *cp; cp++) { if (ascii_isdigit(*cp)) { continue; } - if (*cp == ',' && cp > (char_u *)(*varp) && *(cp - 1) != ',') { + if (*cp == ',' && cp > *varp && *(cp - 1) != ',') { continue; } errmsg = e_invarg; @@ -1459,7 +1458,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } if (errmsg == NULL) { long *oldarray = curbuf->b_p_vts_array; - if (tabstop_set((char_u *)(*varp), &(curbuf->b_p_vts_array))) { + if (tabstop_set(*varp, &(curbuf->b_p_vts_array))) { xfree(oldarray); if (foldmethodIsIndent(curwin)) { foldUpdateAll(curwin); @@ -1484,7 +1483,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf p = WW_ALL; } if (varp == &p_shm) { // 'shortmess' - p = (char *)SHM_ALL; + p = SHM_ALL; } else if (varp == &(p_cpo)) { // 'cpoptions' p = CPO_VI; } else if (varp == &(curbuf->b_p_fo)) { // 'formatoptions' @@ -1527,7 +1526,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf && is_global_local_option(opt_idx)) { // global option with local value set to use global value; free // the local value and make it empty - p = (char *)get_option_varp_scope(opt_idx, OPT_LOCAL); + p = get_option_varp_scope(opt_idx, OPT_LOCAL); free_string_option(*(char **)p); *(char **)p = empty_option; } else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL) { @@ -1574,8 +1573,8 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf } } if (varp == &(curwin->w_s->b_p_spl)) { - char_u fname[200]; - char_u *q = (char_u *)curwin->w_s->b_p_spl; + char fname[200]; + char *q = curwin->w_s->b_p_spl; // Skip the first name if it is "cjk". if (STRNCMP(q, "cjk,", 4) == 0) { @@ -1586,15 +1585,14 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf // They could set 'spellcapcheck' depending on the language. // Use the first name in 'spelllang' up to '_region' or // '.encoding'. - for (p = (char *)q; *p != NUL; p++) { + for (p = q; *p != NUL; p++) { if (!ASCII_ISALNUM(*p) && *p != '-') { break; } } - if (p > (char *)q) { - vim_snprintf((char *)fname, sizeof(fname), "spell/%.*s.vim", - (int)(p - (char *)q), q); - source_runtime((char *)fname, DIP_ALL); + if (p > q) { + vim_snprintf(fname, sizeof(fname), "spell/%.*s.vim", (int)(p - q), q); + source_runtime(fname, DIP_ALL); } } } @@ -1618,7 +1616,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf /// @param list when true: accept a list of values /// /// @return OK for correct value, FAIL otherwise. Empty is always OK. -static int check_opt_strings(char_u *val, char **values, int list) +static int check_opt_strings(char *val, char **values, int list) { return opt_strings_flags(val, values, NULL, list); } @@ -1631,7 +1629,7 @@ static int check_opt_strings(char_u *val, char **values, int list) /// @param list when true: accept a list of values /// /// @return OK for correct value, FAIL otherwise. Empty is always OK. -static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, bool list) +static int opt_strings_flags(char *val, char **values, unsigned *flagp, bool list) { unsigned int new_flags = 0; @@ -1659,7 +1657,7 @@ static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, bool l } /// @return OK if "p" is a valid fileformat name, FAIL otherwise. -int check_ff_value(char_u *p) +int check_ff_value(char *p) { return check_opt_strings(p, p_ff_values, false); } diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index f528bc651b..1b548e1f1b 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -607,7 +607,7 @@ static efm_T *parse_efm_option(char *efm) goto parse_efm_error; } // Advance to next part - efm = (char *)skip_to_option_part((char_u *)efm + len); // skip comma and spaces + efm = skip_to_option_part(efm + len); // skip comma and spaces } if (fmt_first == NULL) { // nothing found @@ -4222,7 +4222,7 @@ static char *make_get_fullcmd(const char *makecmd, const char *fname) // If 'shellpipe' empty: don't redirect to 'errorfile'. if (*p_sp != NUL) { - append_redir(cmd, len, (char *)p_sp, (char *)fname); + append_redir(cmd, len, p_sp, (char *)fname); } // Display the fully formed command. Output a newline if there's something @@ -4241,7 +4241,7 @@ static char *make_get_fullcmd(const char *makecmd, const char *fname) // Used for ":make", ":lmake", ":grep", ":lgrep", ":grepadd", and ":lgrepadd" void ex_make(exarg_T *eap) { - char *enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : (char *)p_menc; + char *enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : p_menc; // Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". if (grep_internal(eap->cmdidx)) { @@ -4981,7 +4981,7 @@ void ex_cfile(exarg_T *eap) set_string_option_direct("ef", -1, eap->arg, OPT_FREE, 0); } - char *enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : (char *)p_menc; + char *enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : p_menc; if (is_loclist_cmd(eap->cmdidx)) { wp = curwin; diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 23606fdc77..25f85b6193 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -2432,7 +2432,7 @@ void ex_scriptencoding(exarg_T *eap) } if (*eap->arg != NUL) { - name = (char *)enc_canonize((char_u *)eap->arg); + name = enc_canonize(eap->arg); } else { name = eap->arg; } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 9c1064d608..3258dc11d6 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -734,13 +734,13 @@ int showmode(void) length = (Rows - msg_row) * Columns - 3; } if (edit_submode_extra != NULL) { - length -= vim_strsize((char *)edit_submode_extra); + length -= vim_strsize(edit_submode_extra); } if (length > 0) { if (edit_submode_pre != NULL) { - length -= vim_strsize((char *)edit_submode_pre); + length -= vim_strsize(edit_submode_pre); } - if (length - vim_strsize((char *)edit_submode) > 0) { + if (length - vim_strsize(edit_submode) > 0) { if (edit_submode_pre != NULL) { msg_puts_attr((const char *)edit_submode_pre, attr); } @@ -1026,7 +1026,7 @@ void draw_tabline(void) if (col + len >= Columns - 3) { break; } - grid_puts_len(&default_grid, NameBuff, len, 0, col, + grid_puts_len(&default_grid, (char_u *)NameBuff, len, 0, col, hl_combine_attr(attr, win_hl_attr(cwp, HLF_T))); col += len; } @@ -1040,9 +1040,9 @@ void draw_tabline(void) if (room > 0) { // Get buffer name in NameBuff[] get_trans_bufname(cwp->w_buffer); - shorten_dir(NameBuff); + shorten_dir((char_u *)NameBuff); len = vim_strsize((char *)NameBuff); - p = NameBuff; + p = (char_u *)NameBuff; while (len > room) { len -= ptr2cells((char *)p); MB_PTR_ADV(p); @@ -1295,13 +1295,13 @@ static int get_encoded_char_adv(const char_u **p) /// @param varp either the global or the window-local value. /// @param apply if false, do not store the flags, only check for errors. /// @return error message, NULL if it's OK. -char *set_chars_option(win_T *wp, char_u **varp, bool apply) +char *set_chars_option(win_T *wp, char **varp, bool apply) { const char_u *last_multispace = NULL; // Last occurrence of "multispace:" const char_u *last_lmultispace = NULL; // Last occurrence of "leadmultispace:" int multispace_len = 0; // Length of lcs-multispace string int lead_multispace_len = 0; // Length of lcs-leadmultispace string - const bool is_listchars = (varp == (char_u **)&p_lcs || varp == (char_u **)&wp->w_p_lcs); + const bool is_listchars = (varp == &p_lcs || varp == &wp->w_p_lcs); struct chars_tab { int *cp; ///< char value @@ -1344,17 +1344,17 @@ char *set_chars_option(win_T *wp, char_u **varp, bool apply) struct chars_tab *tab; int entries; - const char_u *value = *varp; + const char_u *value = (char_u *)(*varp); if (is_listchars) { tab = lcs_tab; entries = ARRAY_SIZE(lcs_tab); - if (varp == (char_u **)&wp->w_p_lcs && wp->w_p_lcs[0] == NUL) { + if (varp == &wp->w_p_lcs && wp->w_p_lcs[0] == NUL) { value = (char_u *)p_lcs; // local value is empty, use the global value } } else { tab = fcs_tab; entries = ARRAY_SIZE(fcs_tab); - if (varp == (char_u **)&wp->w_p_fcs && wp->w_p_fcs[0] == NUL) { + if (varp == &wp->w_p_fcs && wp->w_p_fcs[0] == NUL) { value = (char_u *)p_fcs; // local value is empty, use the global value } } @@ -1520,17 +1520,17 @@ char *set_chars_option(win_T *wp, char_u **varp, bool apply) /// @return an untranslated error message if any of them is invalid, NULL otherwise. char *check_chars_options(void) { - if (set_chars_option(curwin, (char_u **)&p_lcs, false) != NULL) { + if (set_chars_option(curwin, &p_lcs, false) != NULL) { return e_conflicts_with_value_of_listchars; } - if (set_chars_option(curwin, (char_u **)&p_fcs, false) != NULL) { + if (set_chars_option(curwin, &p_fcs, false) != NULL) { return e_conflicts_with_value_of_fillchars; } FOR_ALL_TAB_WINDOWS(tp, wp) { - if (set_chars_option(wp, (char_u **)&wp->w_p_lcs, true) != NULL) { + if (set_chars_option(wp, &wp->w_p_lcs, true) != NULL) { return e_conflicts_with_value_of_listchars; } - if (set_chars_option(wp, (char_u **)&wp->w_p_fcs, true) != NULL) { + if (set_chars_option(wp, &wp->w_p_fcs, true) != NULL) { return e_conflicts_with_value_of_fillchars; } } diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 3de16b3e69..b45a041d96 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1477,7 +1477,7 @@ static char *shada_filename(const char *file) // because various expansions must have already be done by the shell. // If shell is not performing them then they should be done in main.c // where arguments are parsed, *not here*. - expand_env((char_u *)file, &(NameBuff[0]), MAXPATHL); + expand_env((char_u *)file, (char_u *)&(NameBuff[0]), MAXPATHL); file = (const char *)&(NameBuff[0]); } } diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 8fcb379bcf..10923829c3 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1848,7 +1848,7 @@ char *did_set_spelllang(win_T *wp) region = NULL; len = (int)STRLEN(lang); - if (!valid_spelllang(lang)) { + if (!valid_spelllang((char *)lang)) { continue; } @@ -3545,18 +3545,18 @@ int expand_spelling(linenr_T lnum, char_u *pat, char ***matchp) return ga.ga_len; } -/// Return true if "val" is a valid 'spelllang' value. -bool valid_spelllang(const char_u *val) +/// @return true if "val" is a valid 'spelllang' value. +bool valid_spelllang(const char *val) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { return valid_name(val, ".-_,@"); } -/// Return true if "val" is a valid 'spellfile' value. -bool valid_spellfile(const char_u *val) +/// @return true if "val" is a valid 'spellfile' value. +bool valid_spellfile(const char *val) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - for (const char_u *s = val; *s != NUL; s++) { + for (const char_u *s = (char_u *)val; *s != NUL; s++) { if (!vim_isfilec(*s) && *s != ',' && *s != ' ') { return false; } diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index c68dbd8e53..8d6307f123 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -2121,7 +2121,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) if (itemcnt > 0) { if (is_aff_rule(items, itemcnt, "SET", 2) && aff->af_enc == NULL) { // Setup for conversion from "ENC" to 'encoding'. - aff->af_enc = enc_canonize(items[1]); + aff->af_enc = (char_u *)enc_canonize((char *)items[1]); if (!spin->si_ascii && convert_setup(&spin->si_conv, aff->af_enc, (char_u *)p_enc) == FAIL) { smsg(_("Conversion in %s not supported: from %s to %s"), @@ -2167,9 +2167,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) STRCAT(p, " "); STRCAT(p, items[1]); spin->si_info = p; - } else if (is_aff_rule(items, itemcnt, "MIDWORD", 2) - && midword == NULL) { - midword = getroom_save(spin, items[1]); + } else if (is_aff_rule(items, itemcnt, "MIDWORD", 2) && midword == NULL) { + midword = (char_u *)getroom_save(spin, items[1]); } else if (is_aff_rule(items, itemcnt, "TRY", 2)) { // ignored, we look in the tree for what chars may appear } @@ -2307,12 +2306,12 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } if (i >= gap->ga_len) { ga_grow(gap, 2); - ((char **)(gap->ga_data))[gap->ga_len++] = (char *)getroom_save(spin, items[1]); - ((char **)(gap->ga_data))[gap->ga_len++] = (char *)getroom_save(spin, items[2]); + ((char **)(gap->ga_data))[gap->ga_len++] = getroom_save(spin, items[1]); + ((char **)(gap->ga_data))[gap->ga_len++] = getroom_save(spin, items[2]); } } else if (is_aff_rule(items, itemcnt, "SYLLABLE", 2) && syllable == NULL) { - syllable = getroom_save(spin, items[1]); + syllable = (char_u *)getroom_save(spin, items[1]); } else if (is_aff_rule(items, itemcnt, "NOBREAK", 1)) { spin->si_nobreak = true; } else if (is_aff_rule(items, itemcnt, "NOSPLITSUGS", 1)) { @@ -2445,10 +2444,10 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) aff_entry = getroom(spin, sizeof(*aff_entry), true); if (STRCMP(items[2], "0") != 0) { - aff_entry->ae_chop = getroom_save(spin, items[2]); + aff_entry->ae_chop = (char_u *)getroom_save(spin, items[2]); } if (STRCMP(items[3], "0") != 0) { - aff_entry->ae_add = getroom_save(spin, items[3]); + aff_entry->ae_add = (char_u *)getroom_save(spin, items[3]); // Recognize flags on the affix: abcd/XYZ aff_entry->ae_flags = (char_u *)vim_strchr((char *)aff_entry->ae_add, '/'); @@ -2468,7 +2467,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) if (STRCMP(items[4], ".") != 0) { char_u buf[MAXLINELEN]; - aff_entry->ae_cond = getroom_save(spin, items[4]); + aff_entry->ae_cond = (char_u *)getroom_save(spin, items[4]); if (*items[0] == 'P') { sprintf((char *)buf, "^%s", items[4]); } else { @@ -2517,7 +2516,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) if (aff_entry->ae_cond != NULL) { char_u buf[MAXLINELEN]; onecap_copy(items[4], buf, true); - aff_entry->ae_cond = getroom_save(spin, buf); + aff_entry->ae_cond = (char_u *)getroom_save(spin, buf); if (aff_entry->ae_cond != NULL) { sprintf((char *)buf, "^%s", aff_entry->ae_cond); @@ -2547,7 +2546,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) idx = spin->si_prefcond.ga_len; pp = GA_APPEND_VIA_PTR(char_u *, &spin->si_prefcond); *pp = (aff_entry->ae_cond == NULL) ? - NULL : getroom_save(spin, aff_entry->ae_cond); + NULL : (char_u *)getroom_save(spin, aff_entry->ae_cond); } // Add the prefix to the prefix tree. @@ -2673,10 +2672,10 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } } else if (is_aff_rule(items, itemcnt, "SOFOFROM", 2) && sofofrom == NULL) { - sofofrom = getroom_save(spin, items[1]); + sofofrom = (char_u *)getroom_save(spin, items[1]); } else if (is_aff_rule(items, itemcnt, "SOFOTO", 2) && sofoto == NULL) { - sofoto = getroom_save(spin, items[1]); + sofoto = (char_u *)getroom_save(spin, items[1]); } else if (STRCMP(items[0], "COMMON") == 0) { int i; @@ -3042,9 +3041,9 @@ static void add_fromto(spellinfo_T *spin, garray_T *gap, char_u *from, char_u *t fromto_T *ftp = GA_APPEND_VIA_PTR(fromto_T, gap); (void)spell_casefold(curwin, from, (int)STRLEN(from), word, MAXWLEN); - ftp->ft_from = getroom_save(spin, word); + ftp->ft_from = (char_u *)getroom_save(spin, word); (void)spell_casefold(curwin, to, (int)STRLEN(to), word, MAXWLEN); - ftp->ft_to = getroom_save(spin, word); + ftp->ft_to = (char_u *)getroom_save(spin, word); } // Converts a boolean argument in a SAL line to true or false; @@ -3207,7 +3206,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) } // Store the word in the hashtable to be able to find duplicates. - dw = getroom_save(spin, w); + dw = (char_u *)getroom_save(spin, w); if (dw == NULL) { retval = FAIL; xfree(pc); @@ -3728,7 +3727,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) // Setup for conversion to 'encoding'. line += 9; - enc = enc_canonize(line); + enc = (char_u *)enc_canonize((char *)line); if (!spin->si_ascii && convert_setup(&spin->si_conv, enc, (char_u *)p_enc) == FAIL) { smsg(_("Conversion in %s not supported: from %s to %s"), @@ -3864,9 +3863,10 @@ static void *getroom(spellinfo_T *spin, size_t len, bool align) return p; } -// Make a copy of a string into memory allocated with getroom(). -// Returns NULL when out of memory. -static char_u *getroom_save(spellinfo_T *spin, char_u *s) +/// Make a copy of a string into memory allocated with getroom(). +/// +/// @return NULL when out of memory. +static char *getroom_save(spellinfo_T *spin, char_u *s) { const size_t s_size = STRLEN(s) + 1; return memcpy(getroom(spin, s_size, false), s, s_size); diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index 8b56eaadf0..b9cddb7b94 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -77,7 +77,7 @@ void win_redr_status(win_T *wp) width = is_stl_global ? Columns : wp->w_width; get_trans_bufname(wp->w_buffer); - p = NameBuff; + p = (char_u *)NameBuff; len = (int)STRLEN(p); if (bt_help(wp->w_buffer) @@ -138,7 +138,7 @@ void win_redr_status(win_T *wp) if (get_keymap_str(wp, "<%s>", (char *)NameBuff, MAXPATHL) && this_ru_col - len > (int)(STRLEN(NameBuff) + 1)) { - grid_puts(&default_grid, NameBuff, row, + grid_puts(&default_grid, (char_u *)NameBuff, row, (int)((size_t)this_ru_col - STRLEN(NameBuff) - 1), attr); } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 20287089f7..187dc4eed4 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -1634,11 +1634,9 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con bool zero_width_next_list = false; garray_T zero_width_next_ga; - /* - * No character, no attributes! Past end of line? - * Do try matching with an empty line (could be the start of a region). - */ - line = syn_getcurline(); + // No character, no attributes! Past end of line? + // Do try matching with an empty line (could be the start of a region). + line = (char_u *)syn_getcurline(); if (line[current_col] == NUL && current_col != 0) { /* * If we found a match after the last column, use it. @@ -1706,12 +1704,10 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con if (syn_block->b_syn_containedin || cur_si == NULL || cur_si->si_cont_list != NULL) { - /* - * 2. Check for keywords, if on a keyword char after a non-keyword - * char. Don't do this when syncing. - */ + // 2. Check for keywords, if on a keyword char after a non-keyword + // char. Don't do this when syncing. if (do_keywords) { - line = syn_getcurline(); + line = (char_u *)syn_getcurline(); const char_u *cur_pos = line + current_col; if (vim_iswordp_buf(cur_pos, syn_buf) && (current_col == 0 @@ -1979,13 +1975,11 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con * Handle searching for nextgroup match. */ if (current_next_list != NULL && !keep_next_list) { - /* - * If a nextgroup was not found, continue looking for one if: - * - this is an empty line and the "skipempty" option was given - * - we are on white space and the "skipwhite" option was given - */ + // If a nextgroup was not found, continue looking for one if: + // - this is an empty line and the "skipempty" option was given + // - we are on white space and the "skipwhite" option was given if (!found_match) { - line = syn_getcurline(); + line = (char_u *)syn_getcurline(); if (((current_next_flags & HL_SKIPWHITE) && ascii_iswhite(line[current_col])) || ((current_next_flags & HL_SKIPEMPTY) @@ -2108,7 +2102,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con // nextgroup ends at end of line, unless "skipnl" or "skipempty" present if (current_next_list != NULL - && (line = syn_getcurline())[current_col] != NUL + && (line = (char_u *)syn_getcurline())[current_col] != NUL && line[current_col + 1] == NUL && !(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))) { current_next_list = NULL; @@ -2874,12 +2868,10 @@ static void syn_add_start_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *s result->col = col; } -/* - * Get current line in syntax buffer. - */ -static char_u *syn_getcurline(void) +/// Get current line in syntax buffer. +static char *syn_getcurline(void) { - return ml_get_buf(syn_buf, current_lnum, false); + return (char *)ml_get_buf(syn_buf, current_lnum, false); } /* @@ -4059,7 +4051,7 @@ static char *get_group_name(char *arg, char **name_end) /// /// @return a pointer to the next argument (which isn't an option). /// Return NULL for any error; -static char_u *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, int skip) +static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, int skip) { char_u *gname_start, *gname; int syn_id; @@ -4205,7 +4197,7 @@ static char_u *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, } } - return (char_u *)arg; + return arg; } /* @@ -4347,7 +4339,7 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing) cnt = 0; p = keyword_copy; for (; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) { - rest = (char *)get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); + rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); if (rest == NULL || ends_excmd(*rest)) { break; } @@ -4442,18 +4434,18 @@ static void syn_cmd_match(exarg_T *eap, int syncing) syn_opt_arg.cont_list = NULL; syn_opt_arg.cont_in_list = NULL; syn_opt_arg.next_list = NULL; - rest = (char *)get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); + rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); // get the pattern. init_syn_patterns(); CLEAR_FIELD(item); - rest = (char *)get_syn_pattern((char_u *)rest, &item); + rest = get_syn_pattern((char_u *)rest, &item); if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) { syn_opt_arg.flags |= HL_HAS_EOL; } // Get options after the pattern - rest = (char *)get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); + rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); if (rest != NULL) { // all arguments are valid /* @@ -4568,7 +4560,7 @@ static void syn_cmd_region(exarg_T *eap, int syncing) // get the options, patterns and matchgroup. while (rest != NULL && !ends_excmd(*rest)) { // Check for option arguments - rest = (char *)get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); + rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); if (rest == NULL || ends_excmd(*rest)) { break; } @@ -4639,7 +4631,7 @@ static void syn_cmd_region(exarg_T *eap, int syncing) assert(item == ITEM_SKIP || item == ITEM_END); reg_do_extmatch = REX_USE; } - rest = (char *)get_syn_pattern((char_u *)rest, ppp->pp_synp); + rest = get_syn_pattern((char_u *)rest, ppp->pp_synp); reg_do_extmatch = 0; if (item == ITEM_END && vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) { @@ -5034,12 +5026,11 @@ static void init_syn_patterns(void) ga_set_growsize(&curwin->w_s->b_syn_patterns, 10); } -/* - * Get one pattern for a ":syntax match" or ":syntax region" command. - * Stores the pattern and program in a synpat_T. - * Returns a pointer to the next argument, or NULL in case of an error. - */ -static char_u *get_syn_pattern(char_u *arg, synpat_T *ci) +/// Get one pattern for a ":syntax match" or ":syntax region" command. +/// Stores the pattern and program in a synpat_T. +/// +/// @return a pointer to the next argument, or NULL in case of an error. +static char *get_syn_pattern(char_u *arg, synpat_T *ci) { char *end; int *p; @@ -5128,7 +5119,7 @@ static char_u *get_syn_pattern(char_u *arg, synpat_T *ci) semsg(_("E402: Garbage after pattern: %s"), arg); return NULL; } - return (char_u *)skipwhite(end); + return skipwhite(end); } /* diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 2e5ce972d8..50121832ba 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -57,6 +57,7 @@ typedef struct tag_pointers { // filled in by parse_tag_line(): char_u *tagname; // start of tag name (skip "file:") + // char_u *tagname_end; // char after tag name char_u *fname; // first char of file name char_u *fname_end; // char after file name @@ -483,8 +484,8 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) flags |= TAG_NO_TAGFUNC; } - if (find_tags(name, &new_num_matches, &new_matches, flags, - max_num_matches, buf_ffname) == OK + if (find_tags((char *)name, &new_num_matches, &new_matches, flags, + max_num_matches, (char *)buf_ffname) == OK && new_num_matches < max_num_matches) { max_num_matches = MAXCOL; // If less than max_num_matches // found: all matches found. @@ -1365,8 +1366,8 @@ static int find_tagfunc_tags(char_u *pat, garray_T *ga, int *match_count, int fl /// @param matchesp return: array of matches found /// @param mincount MAXCOL: find all matches other: minimal number of matches */ /// @param buf_ffname name of buffer for priority -int find_tags(char_u *pat, int *num_matches, char ***matchesp, int flags, int mincount, - char_u *buf_ffname) +int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int mincount, + char *buf_ffname) { FILE *fp; char_u *lbuf; // line buffer @@ -1459,17 +1460,17 @@ int find_tags(char_u *pat, int *num_matches, char ***matchesp, int flags, int mi p_ic = false; break; case TC_FOLLOWSCS: - p_ic = ignorecase(pat); + p_ic = ignorecase((char_u *)pat); break; case TC_SMART: - p_ic = ignorecase_opt(pat, true, true); + p_ic = ignorecase_opt((char_u *)pat, true, true); break; default: abort(); } help_save = curbuf->b_help; - orgpat.pat = pat; + orgpat.pat = (char_u *)pat; orgpat.regmatch.regprog = NULL; vimconv.vc_type = CONV_NONE; @@ -1503,8 +1504,8 @@ int find_tags(char_u *pat, int *num_matches, char ***matchesp, int flags, int mi if (orgpat.len > 3 && pat[orgpat.len - 3] == '@' && ASCII_ISALPHA(pat[orgpat.len - 2]) && ASCII_ISALPHA(pat[orgpat.len - 1])) { - saved_pat = vim_strnsave(pat, (size_t)orgpat.len - 3); - help_lang_find = &pat[orgpat.len - 2]; + saved_pat = vim_strnsave((char_u *)pat, (size_t)orgpat.len - 3); + help_lang_find = (char_u *)&pat[orgpat.len - 2]; orgpat.pat = saved_pat; orgpat.len -= 3; } @@ -1527,8 +1528,8 @@ int find_tags(char_u *pat, int *num_matches, char ***matchesp, int flags, int mi if (*curbuf->b_p_tfu != NUL && use_tfu && !tfu_in_use) { tfu_in_use = true; - retval = find_tagfunc_tags(pat, &ga_match[0], &match_count, - flags, buf_ffname); + retval = find_tagfunc_tags((char_u *)pat, &ga_match[0], &match_count, flags, + (char_u *)buf_ffname); tfu_in_use = false; if (retval != NOTDONE) { goto findtag_end; @@ -2055,7 +2056,7 @@ parse_line: } else { // Decide in which array to store this match. is_current = test_for_current(tagp.fname, tagp.fname_end, tag_fname, - buf_ffname); + (char_u *)buf_ffname); is_static = test_for_static(&tagp); // Decide in which of the sixteen tables to store this match. @@ -3107,13 +3108,13 @@ int expand_tags(int tagnames, char_u *pat, int *num_file, char ***file) extra_flag = 0; } if (pat[0] == '/') { - ret = find_tags(pat + 1, num_file, file, + ret = find_tags((char *)pat + 1, num_file, file, TAG_REGEXP | extra_flag | TAG_VERBOSE | TAG_NO_TAGFUNC, - TAG_MANY, (char_u *)curbuf->b_ffname); + TAG_MANY, curbuf->b_ffname); } else { - ret = find_tags(pat, num_file, file, + ret = find_tags((char *)pat, num_file, file, TAG_REGEXP | extra_flag | TAG_VERBOSE | TAG_NO_TAGFUNC | TAG_NOIC, - TAG_MANY, (char_u *)curbuf->b_ffname); + TAG_MANY, curbuf->b_ffname); } if (ret == OK && !tagnames) { // Reorganize the tags for display and matching as strings of: @@ -3150,8 +3151,7 @@ int expand_tags(int tagnames, char_u *pat, int *num_file, char ***file) /// /// @param start start of the value /// @param end after the value; can be NULL -static int add_tag_field(dict_T *dict, const char *field_name, const char_u *start, - const char_u *end) +static int add_tag_field(dict_T *dict, const char *field_name, const char *start, const char *end) FUNC_ATTR_NONNULL_ARG(1, 2) { int len = 0; @@ -3198,8 +3198,8 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) tagptrs_T tp; bool is_static; - ret = find_tags(pat, &num_matches, &matches, - TAG_REGEXP | TAG_NOIC, MAXCOL, buf_fname); + ret = find_tags((char *)pat, &num_matches, &matches, + TAG_REGEXP | TAG_NOIC, MAXCOL, (char *)buf_fname); if (ret == OK && num_matches > 0) { for (i = 0; i < num_matches; i++) { int parse_result = parse_match((char_u *)matches[i], &tp); @@ -3220,11 +3220,11 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) tv_list_append_dict(list, dict); full_fname = tag_full_fname(&tp); - if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL - || add_tag_field(dict, "filename", full_fname, NULL) == FAIL - || add_tag_field(dict, "cmd", tp.command, tp.command_end) == FAIL - || add_tag_field(dict, "kind", tp.tagkind, - tp.tagkind ? tp.tagkind_end : NULL) == FAIL + if (add_tag_field(dict, "name", (char *)tp.tagname, (char *)tp.tagname_end) == FAIL + || add_tag_field(dict, "filename", (char *)full_fname, NULL) == FAIL + || add_tag_field(dict, "cmd", (char *)tp.command, (char *)tp.command_end) == FAIL + || add_tag_field(dict, "kind", (char *)tp.tagkind, + tp.tagkind ? (char *)tp.tagkind_end : NULL) == FAIL || tv_dict_add_nr(dict, S_LEN("static"), is_static) == FAIL) { ret = FAIL; } @@ -3259,7 +3259,7 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) p++; } n[len] = NUL; - if (add_tag_field(dict, (char *)n, s, p) == FAIL) { + if (add_tag_field(dict, (char *)n, (char *)s, (char *)p) == FAIL) { ret = FAIL; } n[len] = ':'; -- cgit From 88c32b5eba9fa7072bb4a76a8dbb73c6603165be Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 28 Aug 2022 17:07:24 +0800 Subject: fix(l10n): improve zh_CN and zh_TW translations (#19969) --- src/nvim/po/zh_CN.UTF-8.po | 52 +++---- src/nvim/po/zh_TW.UTF-8.po | 360 +++++++++++++++++++++++---------------------- 2 files changed, 211 insertions(+), 201 deletions(-) (limited to 'src') diff --git a/src/nvim/po/zh_CN.UTF-8.po b/src/nvim/po/zh_CN.UTF-8.po index 373833fa80..afa2f29029 100644 --- a/src/nvim/po/zh_CN.UTF-8.po +++ b/src/nvim/po/zh_CN.UTF-8.po @@ -734,9 +734,9 @@ msgid "E120: Using not in a script context: %s" msgstr "E120: 不能在 script 上下文外使用: %s" #: ../eval.c:7391 -#, fuzzy, c-format +#, c-format msgid "E725: Calling dict function without Dictionary: %s" -msgstr "E720: Dictionary 中缺少冒号: %s" +msgstr "E725: 调用字典函数但是没有字典:%s" #: ../eval.c:7453 #, fuzzy @@ -766,19 +766,16 @@ msgid "E737: Key already exists: %s" msgstr "E737: 键已存在: %s" #: ../eval.c:8692 -#, fuzzy msgid "extend() argument" -msgstr "--cmd 参数" +msgstr "extend() 参数" #: ../eval.c:8915 -#, fuzzy msgid "map() argument" -msgstr "-c 参数" +msgstr "map() 参数" #: ../eval.c:8916 -#, fuzzy msgid "filter() argument" -msgstr "-c 参数" +msgstr "filter() 参数" #: ../eval.c:9229 #, c-format @@ -849,9 +846,8 @@ msgid "E702: Sort compare function failed" msgstr "E702: Sort 比较函数失败" #: ../eval.c:13806 -#, fuzzy msgid "E882: Uniq compare function failed" -msgstr "E702: Sort 比较函数失败" +msgstr "E882: Uniq 比较函数失败" #: ../eval.c:14085 msgid "(Invalid)" @@ -864,31 +860,31 @@ msgstr "E677: 写临时文件出错" #: ../eval.c:16159 #, fuzzy msgid "E805: Using a Float as a Number" -msgstr "E745: 将 List 作数字使用" +msgstr "E805: 将浮点数当做数字使用" #: ../eval.c:16162 msgid "E703: Using a Funcref as a Number" -msgstr "E703: 将 Funcref 作数字使用" +msgstr "E703: 将函数当做数字使用" #: ../eval.c:16170 msgid "E745: Using a List as a Number" -msgstr "E745: 将 List 作数字使用" +msgstr "E745: 将列表当做数字使用" #: ../eval.c:16173 msgid "E728: Using a Dictionary as a Number" -msgstr "E728: 将 Dictionary 作数字使用" +msgstr "E728: 将字典当做数字使用" #: ../eval.c:16259 msgid "E729: using Funcref as a String" -msgstr "E729: 将 Funcref 作 String 使用" +msgstr "E729: 将函数当做字符串使用" #: ../eval.c:16262 msgid "E730: using List as a String" -msgstr "E730: 将 List 作 String 使用" +msgstr "E730: 将列表当做字符串使用" #: ../eval.c:16265 msgid "E731: using Dictionary as a String" -msgstr "E731: 将 Dictionary 作 String 使用" +msgstr "E731: 将字典当做字符串使用" #: ../eval.c:16619 #, c-format @@ -3053,11 +3049,11 @@ msgstr "E673: 不兼容的多字节编码和字符集。" #: ../hardcopy.c:2238 msgid "E674: printmbcharset cannot be empty with multi-byte encoding." -msgstr "E674: printmbcharset 在多字节编码下不能为空。" +msgstr "E674: printmbcharset 在多字节编码下不能为空" #: ../hardcopy.c:2254 msgid "E675: No default font specified for multi-byte printing." -msgstr "E675: 没有指定多字节打印的默认字体。" +msgstr "E675: 没有指定多字节打印的默认字体" #: ../hardcopy.c:2426 msgid "E324: Can't open PostScript output file" @@ -4204,9 +4200,8 @@ msgstr "E329: 没有菜单 \"%s\"" #. Only a mnemonic or accelerator is not valid. #: ../menu.c:329 -#, fuzzy msgid "E792: Empty menu name" -msgstr "E749: 空的缓冲区" +msgstr "E792: 空的菜单名称" #: ../menu.c:340 msgid "E330: Menu path must not lead to a sub-menu" @@ -4329,9 +4324,8 @@ msgid "E766: Insufficient arguments for printf()" msgstr "E766: printf() 的参数不足" #: ../message.c:3119 -#, fuzzy msgid "E807: Expected Float argument for printf()" -msgstr "E766: printf() 的参数不足" +msgstr "E807: 期盼浮点数作为printf()参数" #: ../message.c:3873 msgid "E767: Too many arguments to printf()" @@ -5675,9 +5669,9 @@ msgid "E781: .sug file doesn't match .spl file: %s" msgstr "E781: .sug 文件不能匹配 .spl 文件: %s" #: ../spell.c:9305 -#, fuzzy, c-format +#, c-format msgid "E782: error while reading .sug file: %s" -msgstr "E47: 读取错误文件失败" +msgstr "E782: 当读取.sug 文件时错误" #. This should have been checked when generating the .spl #. file. @@ -5867,6 +5861,7 @@ msgstr "E410: 不正确的 :syntax 子命令: %s" msgid "" " TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN" msgstr "" +" 总 计 计 数 匹 配 最 慢 的 平 均 名 字 模 式" #: ../syntax.c:6146 msgid "E679: recursive loop loading syncolor.vim" @@ -6103,14 +6098,13 @@ msgstr "Vim: 读错误,退出中...\n" #. This happens when the FileChangedRO autocommand changes the #. * file in a way it becomes shorter. #: ../undo.c:379 -#, fuzzy msgid "E881: Line count changed unexpectedly" -msgstr "E787: 意外地改变了缓冲区" +msgstr "E881: 行数意外地改变了" #: ../undo.c:627 -#, fuzzy, c-format +#, c-format msgid "E828: Cannot open undo file for writing: %s" -msgstr "E212: 无法打开并写入文件" +msgstr "E828: 无法打开撤销文件去写入" #: ../undo.c:717 #, c-format diff --git a/src/nvim/po/zh_TW.UTF-8.po b/src/nvim/po/zh_TW.UTF-8.po index 5da69dfe69..e95b1e2cad 100644 --- a/src/nvim/po/zh_TW.UTF-8.po +++ b/src/nvim/po/zh_TW.UTF-8.po @@ -59,19 +59,19 @@ msgstr "無法傳送回應訊息" #: ../api/private/helpers.c:204 msgid "internal error: unknown option type" -msgstr "" +msgstr "內部錯誤: 未知的選項類型" #: ../buffer.c:92 msgid "[Location List]" -msgstr "" +msgstr "[Location 列表]" #: ../buffer.c:93 msgid "[Quickfix List]" -msgstr "" +msgstr "[Quickfix 列表]" #: ../buffer.c:94 msgid "E855: Autocommands caused command to abort" -msgstr "" +msgstr "E855: 自動命令導致命令被停止" #: ../buffer.c:135 msgid "E82: Cannot allocate any buffer, exiting..." @@ -349,7 +349,7 @@ msgstr "E103: 緩衝區 \"%s\" 不是在 diff 模式" #: ../diff.c:2193 msgid "E787: Buffer changed unexpectedly" -msgstr "" +msgstr "E787: 意外地改變了緩衝區" #: ../digraph.c:1598 msgid "E104: Escape not allowed in digraph" @@ -365,7 +365,7 @@ msgstr "E105: 使用 :loadkeymap " #: ../digraph.c:1821 msgid "E791: Empty keymap entry" -msgstr "" +msgstr "E791: 空的鍵位映射項" #: ../edit.c:82 msgid " Keyword completion (^N^P)" @@ -434,11 +434,11 @@ msgstr "已到段落結尾" #: ../edit.c:101 msgid "E839: Completion function changed window" -msgstr "" +msgstr "E839: 補全函式更改了窗口" #: ../edit.c:102 msgid "E840: Completion function deleted text" -msgstr "" +msgstr "E840: 補全函式刪除了文本" #: ../edit.c:1847 msgid "'dictionary' option is empty" @@ -556,7 +556,7 @@ msgstr "E118: 函式 %s 的引數過多" #: ../eval.c:148 #, c-format msgid "E716: Key not present in Dictionary: %s" -msgstr "" +msgstr "E716: 鍵在字典中不存在: %s" #: ../eval.c:150 #, c-format @@ -581,7 +581,7 @@ msgstr "E360: 不能用 -f 選項執行 shell" #: ../eval.c:154 #, c-format msgid "E734: Wrong variable type for %s=" -msgstr "" +msgstr "E734: 錯誤的變數類型: %s=" #: ../eval.c:155 #, fuzzy, c-format @@ -595,19 +595,19 @@ msgstr "E461: 不合法的變數名稱: %s" #: ../eval.c:157 msgid "E806: using Float as a String" -msgstr "" +msgstr "E806: 使用浮點數作為字串" #: ../eval.c:1830 msgid "E687: Less targets than List items" -msgstr "" +msgstr "E687: 目標比列表項數少" #: ../eval.c:1834 msgid "E688: More targets than List items" -msgstr "" +msgstr "E688: 目標比列表項數多" #: ../eval.c:1906 msgid "Double ; in list of variables" -msgstr "" +msgstr "變數列表出現兩個 ;" #: ../eval.c:2078 #, fuzzy, c-format @@ -616,23 +616,23 @@ msgstr "E138: 無法寫入 viminfo 檔案 %s !" #: ../eval.c:2391 msgid "E689: Can only index a List or Dictionary" -msgstr "" +msgstr "E689: 只能索引一個列表或者字典" #: ../eval.c:2396 msgid "E708: [:] must come last" -msgstr "" +msgstr "E708: [:] 必須在最後" #: ../eval.c:2439 msgid "E709: [:] requires a List value" -msgstr "" +msgstr "E709: [:] 需要一個列表值" #: ../eval.c:2674 msgid "E710: List value has more items than target" -msgstr "" +msgstr "E710: 列表值的項比目標多" #: ../eval.c:2678 msgid "E711: List value has not enough items" -msgstr "" +msgstr "E711: 列表值沒有足夠多的項" #: ../eval.c:2867 #, fuzzy @@ -651,7 +651,7 @@ msgstr "E108: 無此變數: \"%s\"" #: ../eval.c:3333 msgid "E743: variable nested too deep for (un)lock" -msgstr "" +msgstr "E743: (un)lock 的變數嵌套過深" #: ../eval.c:3630 msgid "E109: Missing ':' after '?'" @@ -659,7 +659,7 @@ msgstr "E109: '?' 後缺少 ':'" #: ../eval.c:3893 msgid "E691: Can only compare List with List" -msgstr "" +msgstr "E691: 只能比較列表和列表" #: ../eval.c:3895 #, fuzzy @@ -668,7 +668,7 @@ msgstr "E449: 收到不正確的運算式" #: ../eval.c:3915 msgid "E735: Can only compare Dictionary with Dictionary" -msgstr "" +msgstr "E735: 只能比較字典和字典" #: ../eval.c:3917 #, fuzzy @@ -677,7 +677,7 @@ msgstr "E116: 函式 %s 的引數不正確" #: ../eval.c:3932 msgid "E693: Can only compare Funcref with Funcref" -msgstr "" +msgstr "E693: 只能比較Funcref 和 Funcref" #: ../eval.c:3934 #, fuzzy @@ -736,7 +736,7 @@ msgstr "E242: 找不到顏色: %s" #: ../eval.c:6499 #, c-format msgid "E721: Duplicate key in Dictionary: \"%s\"" -msgstr "" +msgstr "E721: Dictionary 中出現重複的鍵: \"%s\"" #: ../eval.c:6517 #, fuzzy, c-format @@ -781,7 +781,7 @@ msgstr "E120: 不能在 script 本文外使用: %s" #: ../eval.c:7391 #, c-format msgid "E725: Calling dict function without Dictionary: %s" -msgstr "" +msgstr "E725: 調用字典函式但是沒有字典: %s" #: ../eval.c:7453 #, fuzzy @@ -814,16 +814,15 @@ msgstr "E227: %s 的 mapping 已經存在" #: ../eval.c:8692 msgid "extend() argument" -msgstr "" +msgstr "extend() 參數" #: ../eval.c:8915 -#, fuzzy msgid "map() argument" -msgstr "vim [參數] " +msgstr "map() 參數" #: ../eval.c:8916 msgid "filter() argument" -msgstr "" +msgstr "filter() 參數" #: ../eval.c:9229 #, c-format @@ -857,19 +856,19 @@ msgstr "E596: 不正確的字型" #: ../eval.c:11980 msgid "E726: Stride is zero" -msgstr "" +msgstr "E726: 步長為零" #: ../eval.c:11982 msgid "E727: Start past end" -msgstr "" +msgstr "E727: 起始值在終止值後" #: ../eval.c:12024 ../eval.c:15297 msgid "" -msgstr "" +msgstr "<空>" #: ../eval.c:12282 msgid "remove() argument" -msgstr "" +msgstr "remove() 參數" #: ../eval.c:12466 msgid "E655: Too many symbolic links (cycle?)" @@ -877,11 +876,11 @@ msgstr "E655: 太多層的符號鏈結(symlink) (循環?)" #: ../eval.c:12593 msgid "reverse() argument" -msgstr "" +msgstr "reverse() 參數" #: ../eval.c:13721 msgid "sort() argument" -msgstr "" +msgstr "sort() 參數" #: ../eval.c:13721 #, fuzzy @@ -895,7 +894,7 @@ msgstr "E237: 無法選擇此印表機" #: ../eval.c:13806 msgid "E882: Uniq compare function failed" -msgstr "" +msgstr "E882: Uniq 比較函式失敗" #: ../eval.c:14085 msgid "(Invalid)" @@ -908,32 +907,31 @@ msgstr "E208: 寫入檔案 \"%s\" 錯誤" #: ../eval.c:16159 msgid "E805: Using a Float as a Number" -msgstr "" +msgstr "E805: 將浮點數當做數字使用" #: ../eval.c:16162 msgid "E703: Using a Funcref as a Number" -msgstr "" +msgstr "E703: 將函式當做數字使用" #: ../eval.c:16170 msgid "E745: Using a List as a Number" -msgstr "" +msgstr "E745: 將列表當做數字使用" #: ../eval.c:16173 msgid "E728: Using a Dictionary as a Number" -msgstr "" +msgstr "E728: 將字典當做數字使用" #: ../eval.c:16259 msgid "E729: using Funcref as a String" -msgstr "" +msgstr "E729: 將函式當做字串使用" #: ../eval.c:16262 -#, fuzzy msgid "E730: using List as a String" -msgstr "E374: 格式化字串裡少了 ]" +msgstr "E730: 將列表當做字串使用" #: ../eval.c:16265 msgid "E731: using Dictionary as a String" -msgstr "" +msgstr "E731: 將字典當做字串使用" #: ../eval.c:16619 #, fuzzy, c-format @@ -953,12 +951,12 @@ msgstr "E128: 函式名稱第一個字母必須大寫: %s" #: ../eval.c:16732 #, c-format msgid "E705: Variable name conflicts with existing function: %s" -msgstr "" +msgstr "E705: 變數名與已有函式名衝突: %s" #: ../eval.c:16763 #, c-format msgid "E741: Value is locked: %s" -msgstr "" +msgstr "E741: 值已鎖定: %s" #: ../eval.c:16764 ../eval.c:16769 ../message.c:1839 msgid "Unknown" @@ -971,7 +969,7 @@ msgstr "E284: 不能設定 IC 數值" #: ../eval.c:16838 msgid "E698: variable nested too deep for making a copy" -msgstr "" +msgstr "E698: 變數嵌套過深無法複製" #: ../eval.c:17249 #, c-format @@ -1216,7 +1214,7 @@ msgstr "要覆寫已存在的檔案 \"%.*s\"?" #: ../ex_cmds.c:2317 #, c-format msgid "Swap file \"%s\" exists, overwrite anyway?" -msgstr "" +msgstr "交換文件 \"%s\" 已存在,確實需要覆蓋嗎?" #: ../ex_cmds.c:2326 #, fuzzy, c-format @@ -1456,7 +1454,7 @@ msgstr "%3d %s %s 第 % 行 " #: ../ex_cmds2.c:942 msgid "E750: First use \":profile start {fname}\"" -msgstr "" +msgstr "E750: 請先使用 :profile start " #: ../ex_cmds2.c:1269 #, fuzzy, c-format @@ -1555,7 +1553,7 @@ msgstr "vim [參數] " #: ../ex_cmds2.c:2771 msgid "environment variable" -msgstr "" +msgstr "環境變數" #: ../ex_cmds2.c:2773 #, fuzzy @@ -2047,7 +2045,7 @@ msgstr "E199: 已刪除掉作用中的視窗或暫存區" #: ../file_search.c:203 msgid "E854: path too long for completion" -msgstr "" +msgstr "E854: 補全用的路徑太長了" #: ../file_search.c:446 #, c-format @@ -2099,11 +2097,11 @@ msgstr "[未命名]" #: ../fileio.c:511 msgid "[New DIRECTORY]" -msgstr "" +msgstr "[新目錄]" #: ../fileio.c:529 ../fileio.c:532 msgid "[File too big]" -msgstr "" +msgstr "[文件太大]" #: ../fileio.c:534 msgid "[Permission Denied]" @@ -2265,7 +2263,7 @@ msgstr "E513: 無法寫入 -- 轉換失敗" msgid "" "E513: write error, conversion failed in line % (make 'fenc' empty to " "override)" -msgstr "" +msgstr "E513: 寫入錯誤,轉換失敗 (請將 'fenc' 置空以強制執行)" #: ../fileio.c:3448 msgid "E514: write error (file system full?)" @@ -2720,7 +2718,7 @@ msgstr "E49: 錯誤的捲動大小" #: ../globals.h:1021 msgid "E901: Job table is full" -msgstr "" +msgstr "E901: 任務表已經滿" #: ../globals.h:1024 #, c-format @@ -2877,7 +2875,7 @@ msgstr "E42: 沒有錯誤" #: ../globals.h:1067 msgid "E776: No location list" -msgstr "" +msgstr "E776: 沒有位置列表" #: ../globals.h:1068 msgid "E43: Damaged match string" @@ -2992,7 +2990,7 @@ msgstr "E473: 內部錯誤" #: ../globals.h:1104 msgid "E363: pattern uses more memory than 'maxmempattern'" -msgstr "" +msgstr "E363: 表達式的內存超出 'maxmempattern'" #: ../globals.h:1105 #, fuzzy @@ -3097,15 +3095,15 @@ msgstr "E621: \"%s\" 資源檔版本錯誤" #: ../hardcopy.c:2225 msgid "E673: Incompatible multi-byte encoding and character set." -msgstr "" +msgstr "E673: 不兼容的多字節編碼和字元集" #: ../hardcopy.c:2238 msgid "E674: printmbcharset cannot be empty with multi-byte encoding." -msgstr "" +msgstr "E674: printmbcharset 在多字節編碼下不能為空" #: ../hardcopy.c:2254 msgid "E675: No default font specified for multi-byte printing." -msgstr "" +msgstr "E675: 沒有指定多字節打印的默認字型" #: ../hardcopy.c:2426 msgid "E324: Can't open PostScript output file" @@ -3267,6 +3265,7 @@ msgstr "%-5s: %-30s (用法: %s)" #: ../if_cscope.c:1155 msgid "" "\n" +" a: Find assignments to this symbol\n" " c: Find functions calling this function\n" " d: Find functions called by this function\n" " e: Find this egrep pattern\n" @@ -3276,6 +3275,16 @@ msgid "" " s: Find this C symbol\n" " t: Find this text string\n" msgstr "" +"\n" +" a: 搜索對此符號的賦值\n" +" c: 搜索調用此函式的函式\n" +" d: 搜索此函式調用的函式\n" +" e: 搜索此 egrep 模式\n" +" f: 搜索此文件\n" +" g: 搜索此定義\n" +" i: 搜索包含此文件的文件\n" +" s: 搜索此 C 符号\n" +" t: 搜索此文本字串\n" #: ../if_cscope.c:1226 msgid "E568: duplicate cscope database not added" @@ -3509,7 +3518,7 @@ msgstr "-N\t\t\t'nocompatible' 不完全與傳統 Vi 相容,可使用 Vim 加 #: ../main.c:2215 msgid "-V[N][fname]\t\tBe verbose [level N] [log messages to fname]" -msgstr "" +msgstr "-V[N][fname]\t\t詳細 [level N] [log messages to fname]" #: ../main.c:2216 msgid "-D\t\t\tDebugging mode" @@ -3602,7 +3611,7 @@ msgstr "-W \t對檔案 寫入所有輸入的命令" #: ../main.c:2240 msgid "--startuptime \tWrite startup timing messages to " -msgstr "" +msgstr "--startuptime \t將啟動時間寫入到文件 " #: ../main.c:2242 msgid "-i \t\tUse instead of .viminfo" @@ -3794,7 +3803,7 @@ msgstr "" #: ../memline.c:945 msgid " has been damaged (page size is smaller than minimum value).\n" -msgstr "" +msgstr "已损坏(頁面大小小於最小值)。\n" #: ../memline.c:974 #, c-format @@ -4082,7 +4091,7 @@ msgstr "E317: 指標區塊 id 錯 2" #: ../memline.c:3070 #, c-format msgid "E773: Symlink loop for \"%s\"" -msgstr "" +msgstr "E773: \"%s\" 符號鏈接出現循環" #: ../memline.c:3221 msgid "E325: ATTENTION" @@ -4231,7 +4240,7 @@ msgstr "E329: 沒有那樣的選單" #. Only a mnemonic or accelerator is not valid. #: ../menu.c:329 msgid "E792: Empty menu name" -msgstr "" +msgstr "E792: 空的菜單名稱" #: ../menu.c:340 msgid "E330: Menu path must not lead to a sub-menu" @@ -4312,7 +4321,7 @@ msgstr "-- 尚有 --" #: ../message.c:2398 msgid " SPACE/d/j: screen/page/line down, b/u/k: up, q: quit " -msgstr "" +msgstr " 空格/d/j: 屏幕/頁/行 下翻,b/u/k: 上翻,q: 退出 " #: ../message.c:3021 ../message.c:3031 msgid "Question" @@ -4357,7 +4366,7 @@ msgstr "E116: 函式 %s 的引數不正確" #: ../message.c:3119 msgid "E807: Expected Float argument for printf()" -msgstr "" +msgstr "E807: 期盼浮點數作為printf()參數" #: ../message.c:3873 #, fuzzy @@ -4370,11 +4379,11 @@ msgstr "W10: 注意: 你正在修改一個唯讀檔" #: ../misc1.c:2537 msgid "Type number and or click with mouse (empty cancels): " -msgstr "" +msgstr "請輸入數字並或點擊鼠標(空白取消): " #: ../misc1.c:2539 msgid "Type number and (empty cancels): " -msgstr "" +msgstr "請選擇數字並( 取消): " #: ../misc1.c:2585 msgid "1 more line" @@ -4400,7 +4409,7 @@ msgstr " (已中斷)" #: ../misc1.c:2635 msgid "Beep!" -msgstr "" +msgstr "Beep!" #: ../misc2.c:738 #, c-format @@ -4617,7 +4626,7 @@ msgstr "E520: 不能在 Modeline 裡出現" #: ../option.c:2815 msgid "E846: Key code not set" -msgstr "" +msgstr "E846: 未設置鍵位代碼" #: ../option.c:2924 msgid "E521: Number required after =" @@ -4642,11 +4651,11 @@ msgstr "E589: 'backupext' 跟 'patchmode' 是一樣的" #: ../option.c:3964 msgid "E834: Conflicts with value of 'listchars'" -msgstr "" +msgstr "E834: 與'listchars'中的值發生衝突" #: ../option.c:3966 msgid "E835: Conflicts with value of 'fillchars'" -msgstr "" +msgstr "E835: 與'fillchars'中的值發生衝突" #: ../option.c:4163 msgid "E524: Missing colon" @@ -4884,7 +4893,7 @@ msgstr "E382: 無法寫入,'buftype' 選項已設定" #: ../quickfix.c:2812 msgid "E683: File name missing or invalid pattern" -msgstr "" +msgstr "E683: 缺少文件名或模式無效" #: ../quickfix.c:2911 #, fuzzy, c-format @@ -5022,25 +5031,26 @@ msgid "" "E864: \\%#= can only be followed by 0, 1, or 2. The automatic engine will be " "used " msgstr "" +"E864: \\%#= 後面只能是0,1,或者2。自動引擎將會被使用" #: ../regexp_nfa.c:239 msgid "E865: (NFA) Regexp end encountered prematurely" -msgstr "" +msgstr "E865: (NFA) 過早的遇到了正則表達式的結尾" #: ../regexp_nfa.c:240 #, c-format msgid "E866: (NFA regexp) Misplaced %c" -msgstr "" +msgstr "E866: (NFA regexp) %c 放錯了位置" #: ../regexp_nfa.c:242 #, c-format msgid "E877: (NFA regexp) Invalid character class: %" -msgstr "" +msgstr "E877: (NFA regexp) 不可用的字元類: %" #: ../regexp_nfa.c:1261 #, c-format msgid "E867: (NFA) Unknown operator '\\z%c'" -msgstr "" +msgstr "E867: (NFA) 未知的操作符 '\\z%c'" #: ../regexp_nfa.c:1387 #, c-format @@ -5050,21 +5060,21 @@ msgstr "" #: ../regexp_nfa.c:1802 #, c-format msgid "E869: (NFA) Unknown operator '\\@%c'" -msgstr "" +msgstr "E869: (NFA) 未知的操作符 '\\%%%c'" #: ../regexp_nfa.c:1831 msgid "E870: (NFA regexp) Error reading repetition limits" -msgstr "" +msgstr "E870: (NFA regexp) 读取重复限制时出错" #. Can't have a multi follow a multi. #: ../regexp_nfa.c:1895 msgid "E871: (NFA regexp) Can't have a multi follow a multi !" -msgstr "" +msgstr "E871: (NFA regexp) 不能多个跟多个!" #. Too many `(' #: ../regexp_nfa.c:2037 msgid "E872: (NFA regexp) Too many '('" -msgstr "" +msgstr "E872: (NFA regexp) 太多 '('" #: ../regexp_nfa.c:2042 #, fuzzy @@ -5073,31 +5083,32 @@ msgstr "E50: 太多 \\z(" #: ../regexp_nfa.c:2066 msgid "E873: (NFA regexp) proper termination error" -msgstr "" +msgstr "E873: (NFA regexp) 未適當終止" #: ../regexp_nfa.c:2599 msgid "E874: (NFA) Could not pop the stack !" -msgstr "" +msgstr "E874: (NFA) 無法出棧!" #: ../regexp_nfa.c:3298 msgid "" "E875: (NFA regexp) (While converting from postfix to NFA), too many states " "left on stack" -msgstr "" +msgstr "E875: (NFA regexp) (從後綴轉到 NFA 时),棧上遺留了太多狀態" #: ../regexp_nfa.c:3302 msgid "E876: (NFA regexp) Not enough space to store the whole NFA " -msgstr "" +msgstr "E876: (NFA regexp) 沒有足夠的空間存儲NFA " #: ../regexp_nfa.c:4571 ../regexp_nfa.c:4869 msgid "" "Could not open temporary log file for writing, displaying on stderr ... " msgstr "" +"無法打開臨時日志文件進行寫入,顯示在stderr中..." #: ../regexp_nfa.c:4840 #, c-format msgid "(NFA) COULD NOT OPEN %s !" -msgstr "" +msgstr "(NFA) 不能打开 %s !" #: ../regexp_nfa.c:6049 #, fuzzy @@ -5270,17 +5281,17 @@ msgstr "E297: 暫存檔寫入錯誤" #: ../spell.c:952 msgid "E758: Truncated spell file" -msgstr "" +msgstr "E758: 已截斷的拼寫文件" #: ../spell.c:953 #, c-format msgid "Trailing text in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,多餘的後續文本: %s" #: ../spell.c:954 #, c-format msgid "Affix name too long in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,附加項名字太長: %s" #: ../spell.c:955 #, fuzzy @@ -5289,20 +5300,20 @@ msgstr "E431: Tag 檔 \"%s\" 格式錯誤" #: ../spell.c:957 msgid "E762: Character in FOL, LOW or UPP is out of range" -msgstr "" +msgstr "E762: FOL、LOW 或 UPP 中字元超出範圍" #: ../spell.c:958 msgid "Compressing word tree..." -msgstr "" +msgstr "壓縮單詞樹……" #: ../spell.c:1951 msgid "E756: Spell checking is not enabled" -msgstr "" +msgstr "E756: 拼寫檢查未啟用" #: ../spell.c:2249 #, c-format msgid "Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\"" -msgstr "" +msgstr "警告: 找不到單詞列表 \"%s.%s.spl\" or \"%s.ascii.spl\"" #: ../spell.c:2473 #, fuzzy, c-format @@ -5316,11 +5327,11 @@ msgstr "E307: %s 看起來不像是 Vim 暫存檔" #: ../spell.c:2501 msgid "E771: Old spell file, needs to be updated" -msgstr "" +msgstr "E771: 舊的拼寫文件,需要更新" #: ../spell.c:2504 msgid "E772: Spell file is for newer version of Vim" -msgstr "" +msgstr "E772: 為更高版本的 Vim 所使用的拼寫文件" #: ../spell.c:2602 #, fuzzy @@ -5340,66 +5351,68 @@ msgstr "搜尋 tag 檔案 \"%s\"" #: ../spell.c:4589 ../spell.c:5635 ../spell.c:6140 #, c-format msgid "Conversion failure for word in %s line %d: %s" -msgstr "" +msgstr "單詞 %s 轉換失敗,第 %d 行: %s" #: ../spell.c:4630 ../spell.c:6170 #, c-format msgid "Conversion in %s not supported: from %s to %s" -msgstr "" +msgstr "不支持 %s 中的轉換: 从 %s 到 %s" #: ../spell.c:4642 #, c-format msgid "Invalid value for FLAG in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,FLAG 的值无效: %s" #: ../spell.c:4655 #, c-format msgid "FLAG after using flags in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,在使用標志後出現 FLAG: %s" #: ../spell.c:4723 #, c-format msgid "" "Defining COMPOUNDFORBIDFLAG after PFX item may give wrong results in %s line " "%d" -msgstr "" +msgstr "在 PFX 項之後定義 COMPOUNDFORBIDFLAG (%s 第%d行)可能會給出的錯誤結果" +"%d" #: ../spell.c:4731 #, c-format msgid "" "Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in %s line " "%d" -msgstr "" +msgstr "在 PFX 項之後定義 COMPOUNDFORBIDFLAG (%s 第%d行)可能會給出的錯誤結果" +"%d" #: ../spell.c:4747 #, c-format msgid "Wrong COMPOUNDRULES value in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,错误的 COMPOUNDMIN 值: %s" #: ../spell.c:4771 #, c-format msgid "Wrong COMPOUNDWORDMAX value in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,错误的 COMPOUNDWORDMAX 值: %s" #: ../spell.c:4777 #, c-format msgid "Wrong COMPOUNDMIN value in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,错误的 COMPOUNDMIN 值: %s" #: ../spell.c:4783 #, c-format msgid "Wrong COMPOUNDSYLMAX value in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,错误的 COMPOUNDSYLMAX 值: %s" #: ../spell.c:4795 #, c-format msgid "Wrong CHECKCOMPOUNDPATTERN value in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,错误的 CHECKCOMPOUNDPATTERN 值: %s" #: ../spell.c:4847 #, c-format msgid "Different combining flag in continued affix block in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,在連續的附加塊種出現不同的組合標誌: %s" #: ../spell.c:4850 #, fuzzy, c-format @@ -5412,45 +5425,47 @@ msgid "" "Affix also used for BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST in %s " "line %d: %s" msgstr "" +"%s 第 %d 行,附加項被 BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST 使" +"用: %s" #: ../spell.c:4893 #, c-format msgid "Expected Y or N in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,此處需要 Y 或 N: %s" #: ../spell.c:4968 #, c-format msgid "Broken condition in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,錯誤的條件: %s" #: ../spell.c:5091 #, c-format msgid "Expected REP(SAL) count in %s line %d" -msgstr "" +msgstr "%s 第 %d 行,此處需要 REP(SAL) 計數" #: ../spell.c:5120 #, c-format msgid "Expected MAP count in %s line %d" -msgstr "" +msgstr "%s 第 %d 行,此處需要 MAP 計數" #: ../spell.c:5132 #, c-format msgid "Duplicate character in MAP in %s line %d" -msgstr "" +msgstr "%s 第 %d 行,MAP 中存在重複的字元" #: ../spell.c:5176 #, c-format msgid "Unrecognized or duplicate item in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,無法識別或重複的項: %s" #: ../spell.c:5197 #, c-format msgid "Missing FOL/LOW/UPP line in %s" -msgstr "" +msgstr "%s 中缺少 FOL/LOW/UPP 行" #: ../spell.c:5220 msgid "COMPOUNDSYLMAX used without SYLLABLE" -msgstr "" +msgstr "在没有 SYLLABLE 的情況下使用了 COMPOUNDSYLMAX" #: ../spell.c:5236 #, fuzzy @@ -5464,32 +5479,32 @@ msgstr "太多編輯參數" #: ../spell.c:5240 msgid "Too many postponed prefixes and/or compound flags" -msgstr "" +msgstr "太多延遲前綴和/或組合標誌" #: ../spell.c:5250 #, c-format msgid "Missing SOFO%s line in %s" -msgstr "" +msgstr "%s 中缺少 SOFO%s 行" #: ../spell.c:5253 #, c-format msgid "Both SAL and SOFO lines in %s" -msgstr "" +msgstr "%s 同時出現 SAL 和 SOFO 行" #: ../spell.c:5331 #, c-format msgid "Flag is not a number in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,標誌不是數字: %s" #: ../spell.c:5334 #, c-format msgid "Illegal flag in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,無效的標誌: %s" #: ../spell.c:5493 ../spell.c:5501 #, c-format msgid "%s value differs from what is used in another .aff file" -msgstr "" +msgstr "%s 的值與另一個 .aff 文件中使用的值不相同" #: ../spell.c:5602 #, fuzzy, c-format @@ -5499,12 +5514,12 @@ msgstr "掃瞄字典: %s" #: ../spell.c:5611 #, c-format msgid "E760: No word count in %s" -msgstr "" +msgstr "E760: %s 中没有單詞計數" #: ../spell.c:5669 #, c-format msgid "line %6d, word %6d - %s" -msgstr "" +msgstr "第 %6d 行,第 %6d 个單詞 - %s" #: ../spell.c:5691 #, fuzzy, c-format @@ -5514,17 +5529,17 @@ msgstr "每一行都找不到: %s" #: ../spell.c:5694 #, c-format msgid "First duplicate word in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,首次出現重複的單詞: %s" #: ../spell.c:5746 #, c-format msgid "%d duplicate word(s) in %s" -msgstr "" +msgstr "存在 %d 个重複的單詞,在 %s 中" #: ../spell.c:5748 #, c-format msgid "Ignored %d word(s) with non-ASCII characters in %s" -msgstr "" +msgstr "忽略了含有非 ASCII 字元的 %d 个單詞,在 %s 中" #: ../spell.c:6115 #, fuzzy, c-format @@ -5534,42 +5549,42 @@ msgstr "從標準輸入讀取..." #: ../spell.c:6155 #, c-format msgid "Duplicate /encoding= line ignored in %s line %d: %s" -msgstr "" +msgstr "%s 第 %ld 行,重复的 /encoding= 行已被忽略: %s" #: ../spell.c:6159 #, c-format msgid "/encoding= line after word ignored in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,单词后的 /encoding= 行已被忽略: %s" #: ../spell.c:6180 #, c-format msgid "Duplicate /regions= line ignored in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,重复的 /regions= 行已被忽略: %s" #: ../spell.c:6185 #, c-format msgid "Too many regions in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,太多區域: %s" #: ../spell.c:6198 #, c-format msgid "/ line ignored in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,/ 行已被忽略: %s" #: ../spell.c:6224 #, fuzzy, c-format msgid "Invalid region nr in %s line %d: %s" -msgstr "E573: 不正確的伺服器 id : %s" +msgstr "%s 第 %d 行,無效的區域號: %s" #: ../spell.c:6230 #, c-format msgid "Unrecognized flags in %s line %d: %s" -msgstr "" +msgstr "%s 第 %d 行,不可識別的標誌: %s" #: ../spell.c:6257 #, c-format msgid "Ignored %d words with non-ASCII characters" -msgstr "" +msgstr "忽略了含有非 ASCII 字元的 %d 个單詞" #: ../spell.c:6656 #, c-format @@ -5578,23 +5593,23 @@ msgstr "" #: ../spell.c:7340 msgid "Reading back spell file..." -msgstr "" +msgstr "读取拼寫文件……" #. Go through the trie of good words, soundfold each word and add it to #. the soundfold trie. #: ../spell.c:7357 msgid "Performing soundfolding..." -msgstr "" +msgstr "正在 soundfolding……" #: ../spell.c:7368 #, c-format msgid "Number of words after soundfolding: %" -msgstr "" +msgstr "soundfolding 后的單詞数: %" #: ../spell.c:7476 #, c-format msgid "Total number of words: %d" -msgstr "" +msgstr "單詞总数: %d" #: ../spell.c:7655 #, fuzzy, c-format @@ -5604,11 +5619,11 @@ msgstr "寫入 viminfo 檔案 \"%s\" 中" #: ../spell.c:7707 ../spell.c:7927 #, c-format msgid "Estimated runtime memory use: %d bytes" -msgstr "" +msgstr "估計運行時的內存用量: %d 位元" #: ../spell.c:7820 msgid "E751: Output file name must not have region name" -msgstr "" +msgstr "E751: 輸出文件不能含有區域名" #: ../spell.c:7822 #, fuzzy @@ -5622,7 +5637,7 @@ msgstr "E15: 不正確的運算式: %s" #: ../spell.c:7907 msgid "Warning: both compounding and NOBREAK specified" -msgstr "" +msgstr "警告: 同時指定了 compounding 和 NOBREAK" #: ../spell.c:7920 #, fuzzy, c-format @@ -5631,30 +5646,30 @@ msgstr "寫入 viminfo 檔案 \"%s\" 中" #: ../spell.c:7925 msgid "Done!" -msgstr "" +msgstr "完成!" #: ../spell.c:8034 #, c-format msgid "E765: 'spellfile' does not have % entries" -msgstr "" +msgstr "E765: 'spellfile' 没有 % 項" #: ../spell.c:8074 #, c-format msgid "Word '%.*s' removed from %s" -msgstr "" +msgstr "从 %s 中删除了單詞" #: ../spell.c:8117 #, c-format msgid "Word '%.*s' added to %s" -msgstr "" +msgstr "向 %s 中添加了單詞" #: ../spell.c:8381 msgid "E763: Word characters differ between spell files" -msgstr "" +msgstr "E763: 拼寫文件之間的字元不相同" #: ../spell.c:8684 msgid "Sorry, no suggestions" -msgstr "" +msgstr "抱歉,没有建议" #: ../spell.c:8687 #, fuzzy, c-format @@ -5671,7 +5686,7 @@ msgstr "將變動存儲至 \"%.*s\"?" #: ../spell.c:8737 #, c-format msgid " < \"%.*s\"" -msgstr "" +msgstr " < \"%.*s\"" #: ../spell.c:8882 #, fuzzy @@ -5691,28 +5706,28 @@ msgstr "E307: %s 看起來不像是 Vim 暫存檔" #: ../spell.c:9282 #, c-format msgid "E779: Old .sug file, needs to be updated: %s" -msgstr "" +msgstr "E779: 舊的.sug 文件,需要更新: %s" #: ../spell.c:9286 #, c-format msgid "E780: .sug file is for newer version of Vim: %s" -msgstr "" +msgstr "E780: .sug 文件適用於較新的 Vim 版本: %s" #: ../spell.c:9295 #, c-format msgid "E781: .sug file doesn't match .spl file: %s" -msgstr "" +msgstr "E781: .sug 文件不能匹配 .spl 文件: %s" #: ../spell.c:9305 #, fuzzy, c-format msgid "E782: error while reading .sug file: %s" -msgstr "E47: 讀取錯誤檔案失敗" +msgstr "E782: 當讀取.sug 文件時錯誤" #. This should have been checked when generating the .spl #. file. #: ../spell.c:11575 msgid "E783: duplicate char in MAP entry" -msgstr "" +msgstr "E783: MAP 條目中有重複的字元" #: ../syntax.c:266 msgid "No Syntax items defined for this buffer" @@ -5894,10 +5909,11 @@ msgstr "E410: 不正確的 :syntax 子命令: %s" msgid "" " TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN" msgstr "" +" 總 計 計 數 匹 配 最 慢 的 平 均 名 字 模 式" #: ../syntax.c:6146 msgid "E679: recursive loop loading syncolor.vim" -msgstr "" +msgstr "E679: 加載 syncolor.vim 时出現嵌套循環" #: ../syntax.c:6256 #, c-format @@ -5975,7 +5991,7 @@ msgstr "E5248: 群組名稱中有不正確的字元" #: ../syntax.c:7448 msgid "E849: Too many highlight and syntax groups" -msgstr "" +msgstr "E849: 高亮和語法組過多" #: ../tag.c:104 msgid "E555: at bottom of tag stack" @@ -6083,7 +6099,7 @@ msgstr "E435: 找不到 tag, 用猜的!" #: ../tag.c:2797 #, c-format msgid "Duplicate field name: %s" -msgstr "" +msgstr "重複的字段名: %s" #: ../term.c:1442 msgid "' not known. Available builtin terminals are:" @@ -6131,35 +6147,35 @@ msgstr "Vim: 讀取輸入錯誤,離開中...\n" #. * file in a way it becomes shorter. #: ../undo.c:379 msgid "E881: Line count changed unexpectedly" -msgstr "" +msgstr "E881: 行數意外地改變了" #: ../undo.c:627 -#, fuzzy, c-format +#, c-format msgid "E828: Cannot open undo file for writing: %s" -msgstr "E212: 無法以寫入模式開啟" +msgstr "E828: 無法打開撤銷文件去寫入" #: ../undo.c:717 #, c-format msgid "E825: Corrupted undo file (%s): %s" -msgstr "" +msgstr "E825: 已損壞的撤銷文件 (%s): %s" #: ../undo.c:1039 msgid "Cannot write undo file in any directory in 'undodir'" -msgstr "" +msgstr "不能寫入撤銷文件到 'undodir' 中的任何文件夾" #: ../undo.c:1074 #, c-format msgid "Will not overwrite with undo file, cannot read: %s" -msgstr "" +msgstr "不能寫入撤銷文件,不可讀取: %s" #: ../undo.c:1092 #, c-format msgid "Will not overwrite, this is not an undo file: %s" -msgstr "" +msgstr "不會覆蓋,這不是撤銷文件: %s" #: ../undo.c:1108 msgid "Skipping undo file write, nothing to undo" -msgstr "" +msgstr "跳過撤消文件寫入,沒有可撤消的內容" #: ../undo.c:1121 #, fuzzy, c-format @@ -6174,7 +6190,7 @@ msgstr "E297: 暫存檔寫入錯誤" #: ../undo.c:1280 #, c-format msgid "Not reading undo file, owner differs: %s" -msgstr "" +msgstr "不能讀取撤銷文件,擁有者不同: %s" #: ../undo.c:1292 #, fuzzy, c-format @@ -6198,7 +6214,7 @@ msgstr "E484: 無法開啟檔案 %s" #: ../undo.c:1328 msgid "File contents changed, cannot use undo info" -msgstr "" +msgstr "文件內容已經改變,不能使用撤銷信息" #: ../undo.c:1497 #, fuzzy, c-format @@ -6207,11 +6223,11 @@ msgstr "結束執行 %s" #: ../undo.c:1586 ../undo.c:1812 msgid "Already at oldest change" -msgstr "" +msgstr "已經在最早的改變" #: ../undo.c:1597 ../undo.c:1814 msgid "Already at newest change" -msgstr "" +msgstr "已經在最新的改變" #: ../undo.c:1806 #, fuzzy, c-format @@ -6259,11 +6275,11 @@ msgstr "% 行 %s 過 %d 次" #: ../undo.c:2228 msgid "before" -msgstr "" +msgstr "之前" #: ../undo.c:2228 msgid "after" -msgstr "" +msgstr "之後" #: ../undo.c:2325 #, fuzzy @@ -6272,7 +6288,7 @@ msgstr "沒有這個 mapping 對應" #: ../undo.c:2330 msgid "number changes when saved" -msgstr "" +msgstr " 編號 改變 時間 保存" #: ../undo.c:2360 #, fuzzy, c-format -- cgit From b21980bd607e952fe52957aec3214367bd48527b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 29 Aug 2022 05:58:32 +0800 Subject: fix(keywordprg): default to :help if set to empty string (#19983) --- src/nvim/normal.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 31646f686d..cab380003d 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -4278,13 +4278,12 @@ static void nv_ident(cmdarg_T *cap) // double the length of the word. p_kp / curbuf->b_p_kp could be added // and some numbers. char_u *kp = *curbuf->b_p_kp == NUL ? p_kp : (char_u *)curbuf->b_p_kp; // 'keywordprg' - assert(*kp != NUL); // option.c:do_set() should default to ":help" if empty. - bool kp_ex = (*kp == ':'); // 'keywordprg' is an ex command - bool kp_help = (STRCMP(kp, ":he") == 0 || STRCMP(kp, ":help") == 0); + bool kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 || STRCMP(kp, ":help") == 0); if (kp_help && *skipwhite(ptr) == NUL) { emsg(_(e_noident)); // found white space only return; } + bool kp_ex = (*kp == ':'); // 'keywordprg' is an ex command size_t buf_size = n * 2 + 30 + STRLEN(kp); char *buf = xmalloc(buf_size); buf[0] = NUL; -- cgit From 1dcaa75a6564b8a90e74a96e242803c6aa3f59cf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 29 Aug 2022 06:16:20 +0800 Subject: fix(events): triggered WinScrolled when only skipcol changed (#19972) fix(events): trigger WinScrolled when only skipcol changed vim-patch:9.0.0304: WinScrolled is not triggered when only skipcol changes Problem: WinScrolled is not triggered when only skipcol changes. Solution: Add w_last_skipcol and use it. (closes vim/vim#10998) https://github.com/vim/vim/commit/670ab0334b536e12d84810de88e73b7bcb01346d --- src/nvim/autocmd.c | 1 + src/nvim/buffer_defs.h | 3 ++- src/nvim/testdir/test_autocmd.vim | 33 +++++++++++++++++++++++++++++++++ src/nvim/window.c | 2 ++ 4 files changed, 38 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 2fe9df2206..1c1de214cd 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -1119,6 +1119,7 @@ int autocmd_register(int64_t id, event_T event, char *pat, int patlen, int group if (event == EVENT_WINSCROLLED && !has_event(EVENT_WINSCROLLED)) { curwin->w_last_topline = curwin->w_topline; curwin->w_last_leftcol = curwin->w_leftcol; + curwin->w_last_skipcol = curwin->w_skipcol; curwin->w_last_width = curwin->w_width; curwin->w_last_height = curwin->w_height; } diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 58bdd2c0a8..319c2addba 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -1240,9 +1240,10 @@ struct window_S { colnr_T w_skipcol; // starting column when a single line // doesn't fit in the window - // four fields that are only used when there is a WinScrolled autocommand + // five fields that are only used when there is a WinScrolled autocommand linenr_T w_last_topline; ///< last known value for w_topline colnr_T w_last_leftcol; ///< last known value for w_leftcol + colnr_T w_last_skipcol; ///< last known value for w_skipcol int w_last_width; ///< last known value for w_width int w_last_height; ///< last known value for w_height diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index a249c2bf50..27bc6303cf 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -341,6 +341,39 @@ func Test_WinScrolled_close_curwin() call delete('Xtestout') endfunc +func Test_WinScrolled_long_wrapped() + CheckRunVimInTerminal + + let lines =<< trim END + set scrolloff=0 + let height = winheight(0) + let width = winwidth(0) + let g:scrolled = 0 + au WinScrolled * let g:scrolled += 1 + call setline(1, repeat('foo', height * width)) + call cursor(1, height * width) + END + call writefile(lines, 'Xtest_winscrolled_long_wrapped') + let buf = RunVimInTerminal('-S Xtest_winscrolled_long_wrapped', {'rows': 6}) + + call term_sendkeys(buf, ":echo g:scrolled\") + call WaitForAssert({-> assert_match('^0 ', term_getline(buf, 6))}, 1000) + + call term_sendkeys(buf, 'gj') + call term_sendkeys(buf, ":echo g:scrolled\") + call WaitForAssert({-> assert_match('^1 ', term_getline(buf, 6))}, 1000) + + call term_sendkeys(buf, '0') + call term_sendkeys(buf, ":echo g:scrolled\") + call WaitForAssert({-> assert_match('^2 ', term_getline(buf, 6))}, 1000) + + call term_sendkeys(buf, '$') + call term_sendkeys(buf, ":echo g:scrolled\") + call WaitForAssert({-> assert_match('^3 ', term_getline(buf, 6))}, 1000) + + call delete('Xtest_winscrolled_long_wrapped') +endfunc + func Test_WinClosed() " Test that the pattern is matched against the closed window's ID, and both " and are set to it. diff --git a/src/nvim/window.c b/src/nvim/window.c index ffbb0fa27f..5b8a69f6eb 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5362,6 +5362,7 @@ void may_trigger_winscrolled(void) win_T *wp = curwin; if (wp->w_last_topline != wp->w_topline || wp->w_last_leftcol != wp->w_leftcol + || wp->w_last_skipcol != wp->w_skipcol || wp->w_last_width != wp->w_width || wp->w_last_height != wp->w_height) { char winid[NUMBUFLEN]; @@ -5375,6 +5376,7 @@ void may_trigger_winscrolled(void) if (win_valid_any_tab(wp)) { wp->w_last_topline = wp->w_topline; wp->w_last_leftcol = wp->w_leftcol; + wp->w_last_skipcol = wp->w_skipcol; wp->w_last_width = wp->w_width; wp->w_last_height = wp->w_height; } -- cgit From 253f0ffd8d4784b7fca03f8f6c2455b9ee83ff9b Mon Sep 17 00:00:00 2001 From: Shougo Date: Mon, 29 Aug 2022 14:11:52 +0900 Subject: vim-patch:9.0.0285: it is not easy to change the command line from a plugin (#19979) vim-patch:9.0.0285: it is not easy to change the command line from a plugin Problem: It is not easy to change the command line from a plugin. Solution: Add setcmdline(). (Shougo Matsushita, closes vim/vim#10869) https://github.com/vim/vim/commit/07ea5f1509fe8dafe3262ed2702b4d0fc99e288b --- src/nvim/eval.lua | 1 + src/nvim/eval/funcs.c | 25 ++++++++++++++++++++++++ src/nvim/ex_getln.c | 38 ++++++++++++++++++++++++++++++++++--- src/nvim/testdir/test_cmdline.vim | 40 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 4863d8013d..3e89489459 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -332,6 +332,7 @@ return { setcharpos={args=2, base=2}, setcharsearch={args=1, base=1}, setcmdpos={args=1, base=1}, + setcmdline={args={1, 2}, base=1}, setcursorcharpos={args={1, 3}, base=1}, setenv={args=2, base=2}, setfperm={args=2, base=1}, diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 581f187140..2ed9ed34f4 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -7619,6 +7619,31 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv, EvalFuncData fpt } } +/// "setcmdline()" function +static void f_setcmdline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +{ + if (argvars[0].v_type != VAR_STRING || argvars[0].vval.v_string == NULL) { + emsg(_(e_stringreq)); + return; + } + + int pos = -1; + if (argvars[1].v_type != VAR_UNKNOWN) { + bool error = false; + + pos = (int)tv_get_number_chk(&argvars[1], &error) - 1; + if (error) { + return; + } + if (pos < 0) { + emsg(_(e_positive)); + return; + } + } + + rettv->vval.v_number = set_cmdline_str(argvars[0].vval.v_string, pos); +} + /// "setcmdpos()" function static void f_setcmdpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 081aa80778..84eacf3997 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2373,9 +2373,9 @@ end: return cmdpreview_type != 0; } -static int command_line_changed(CommandLineState *s) +/// Trigger CmdlineChanged autocommands. +static void do_autocmd_cmdlinechanged(int firstc) { - // Trigger CmdlineChanged autocommands. if (has_event(EVENT_CMDLINECHANGED)) { TryState tstate; Error err = ERROR_INIT; @@ -2383,7 +2383,7 @@ static int command_line_changed(CommandLineState *s) dict_T *dict = get_v_event(&save_v_event); char firstcbuf[2]; - firstcbuf[0] = (char)(s->firstc > 0 ? s->firstc : '-'); + firstcbuf[0] = (char)firstc; firstcbuf[1] = 0; // set v:event to a dictionary with information about the commandline @@ -2403,6 +2403,12 @@ static int command_line_changed(CommandLineState *s) redrawcmd(); } } +} + +static int command_line_changed(CommandLineState *s) +{ + // Trigger CmdlineChanged autocommands. + do_autocmd_cmdlinechanged(s->firstc > 0 ? s->firstc : '-'); if (s->firstc == ':' && current_sctx.sc_sid == 0 // only if interactive @@ -3991,6 +3997,32 @@ int get_cmdline_screen_pos(void) return p->cmdspos; } +/// Set the command line str to "str". +/// @return 1 when failed, 0 when OK. +int set_cmdline_str(const char *str, int pos) +{ + CmdlineInfo *p = get_ccline_ptr(); + + if (p == NULL) { + return 1; + } + + int len = (int)STRLEN(str); + realloc_cmdbuff(len + 1); + p->cmdlen = len; + STRCPY(p->cmdbuff, str); + + p->cmdpos = pos < 0 || pos > p->cmdlen ? p->cmdlen : pos; + new_cmdpos = p->cmdpos; + + redrawcmd(); + + // Trigger CmdlineChanged autocommands. + do_autocmd_cmdlinechanged(ccline.cmdfirstc == NUL ? '-' : ccline.cmdfirstc); + + return 0; +} + /* * Set the command line byte position to "pos". Zero is the first position. * Only works when the command line is being edited. diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 517509004a..a5a30b7953 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -2185,4 +2185,44 @@ func Test_wildmenu_pum_disable_while_shown() set wildoptions& wildmenu& endfunc +func Test_setcmdline() + func SetText(text, pos) + call assert_equal(0, setcmdline(a:text)) + call assert_equal(a:text, getcmdline()) + call assert_equal(len(a:text) + 1, getcmdpos()) + + call assert_equal(0, setcmdline(a:text, a:pos)) + call assert_equal(a:text, getcmdline()) + call assert_equal(a:pos, getcmdpos()) + + call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:') + call assert_fails('call setcmdline({}, 0)', 'E928:') + call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E728:') + + return '' + endfunc + + call feedkeys(":\=SetText('set rtp?', 2)\\", 'xt') + call assert_equal('set rtp?', @:) + + " setcmdline() returns 1 when not editing the command line. + call assert_equal(1, 'foo'->setcmdline()) + + " Called in custom function + func CustomComplete(A, L, P) + call assert_equal(0, setcmdline("DoCmd ")) + return "January\nFebruary\nMars\n" + endfunc + + com! -nargs=* -complete=custom,CustomComplete DoCmd : + call feedkeys(":DoCmd \\\"\", 'tx') + call assert_equal('"DoCmd January February Mars', @:) + + " Called in + cnoremap a setcmdline('let foo=') + call feedkeys(":a\", 'tx') + call assert_equal('let foo=0', @:) + cunmap a +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From ea4e9c71ccaf406fe7aa6b47d461cdab2d6c01e9 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 27 Aug 2022 11:28:11 +0200 Subject: refactor(plines): use a struct for chartabsize state This is a refactor extracted from vim-patch 9.0.0067: cannot show virtual text The logic for inline virtual text is going to be different in nvim than text property based text in vim, but this refactor is still useful, as calculation of displayed linesize is going to be stateful in a similar way. --- src/nvim/change.c | 4 +- src/nvim/charset.c | 24 +++++-- src/nvim/cursor.c | 16 +++-- src/nvim/drawline.c | 28 +++++--- src/nvim/edit.c | 80 +++++++++++++--------- src/nvim/eval/funcs.c | 6 +- src/nvim/ex_cmds.c | 2 +- src/nvim/getchar.c | 19 ++++-- src/nvim/indent.c | 52 +++++++++------ src/nvim/mouse.c | 26 ++++---- src/nvim/ops.c | 101 +++++++++++++++++++--------- src/nvim/plines.c | 182 ++++++++++++++++++++++++++++++-------------------- src/nvim/plines.h | 14 ++++ src/nvim/regexp.c | 2 +- src/nvim/regexp_bt.c | 1 + src/nvim/regexp_nfa.c | 2 +- 16 files changed, 354 insertions(+), 205 deletions(-) (limited to 'src') diff --git a/src/nvim/change.c b/src/nvim/change.c index 04dfb20a1b..074700f4df 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -653,9 +653,9 @@ void ins_char_bytes(char_u *buf, size_t charlen) // cells. May result in adding spaces to fill a gap. colnr_T vcol; getvcol(curwin, &curwin->w_cursor, NULL, &vcol, NULL); - colnr_T new_vcol = vcol + win_chartabsize(curwin, buf, vcol); + colnr_T new_vcol = vcol + win_chartabsize(curwin, (char *)buf, vcol); while (oldp[col + oldlen] != NUL && vcol < new_vcol) { - vcol += win_chartabsize(curwin, oldp + col + oldlen, vcol); + vcol += win_chartabsize(curwin, (char *)oldp + col + oldlen, vcol); // Don't need to remove a TAB that takes us to the right // position. if (vcol > new_vcol && oldp[col + oldlen] == TAB) { diff --git a/src/nvim/charset.c b/src/nvim/charset.c index dc62b85716..3632c3d70b 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -930,14 +930,18 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en posptr -= utf_head_off(line, posptr); } + chartabsize_T cts; + init_chartabsize_arg(&cts, wp, pos->lnum, 0, line, line); + // This function is used very often, do some speed optimizations. // When 'list', 'linebreak', 'showbreak' and 'breakindent' are not set - // use a simple loop. + // and there are no virtual text use a simple loop. // Also use this when 'list' is set but tabs take their normal size. if ((!wp->w_p_list || (wp->w_p_lcs_chars.tab1 != NUL)) && !wp->w_p_lbr && *get_showbreak_value(wp) == NUL - && !wp->w_p_bri) { + && !wp->w_p_bri + && !cts.cts_has_virt_text) { for (;;) { head = 0; int c = *ptr; @@ -984,25 +988,29 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en } else { for (;;) { // A tab gets expanded, depending on the current column + // Other things also take up space. head = 0; - incr = win_lbr_chartabsize(wp, line, ptr, vcol, &head); + incr = win_lbr_chartabsize(&cts, &head); // make sure we don't go past the end of the line - if (*ptr == NUL) { + if (*cts.cts_ptr == NUL) { // NUL at end of line only takes one column incr = 1; break; } - if ((posptr != NULL) && (ptr >= posptr)) { + if ((posptr != NULL) && ((char_u *)cts.cts_ptr >= posptr)) { // character at pos->col break; } - vcol += incr; - MB_PTR_ADV(ptr); + cts.cts_vcol += incr; + MB_PTR_ADV(cts.cts_ptr); } + vcol = cts.cts_vcol; + ptr = (char_u *)cts.cts_ptr; } + clear_chartabsize_arg(&cts); if (start != NULL) { *start = vcol + head; @@ -1013,6 +1021,8 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en } if (cursor != NULL) { + // cursor is after inserted text + vcol += cts.cts_cur_text_width; if ((*ptr == TAB) && (State & MODE_NORMAL) && !wp->w_p_list diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 14ebc11cbf..ed0488cf76 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -137,14 +137,18 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a } } - char_u *ptr = line; - while (col <= wcol && *ptr != NUL) { + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, pos->lnum, 0, line, line); + while (cts.cts_vcol <= wcol && *cts.cts_ptr != NUL) { // Count a tab for what it's worth (if list mode not on) - csize = win_lbr_chartabsize(curwin, line, ptr, col, &head); - MB_PTR_ADV(ptr); - col += csize; + csize = win_lbr_chartabsize(&cts, &head); + MB_PTR_ADV(cts.cts_ptr); + cts.cts_vcol += csize; } - idx = (int)(ptr - line); + col = cts.cts_vcol; + idx = (int)(cts.cts_ptr - (char *)line); + clear_chartabsize_arg(&cts); + // Handle all the special cases. The virtual_active() check // is needed to ensure that a virtual position off the end of // a line has the correct indexing. The one_more comparison diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 9132d6666e..4b5f6c6c06 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -940,12 +940,19 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, } if (v > 0 && !number_only) { char_u *prev_ptr = ptr; - while (vcol < v && *ptr != NUL) { - c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL); - vcol += c; - prev_ptr = ptr; - MB_PTR_ADV(ptr); + chartabsize_T cts; + int charsize; + + init_chartabsize_arg(&cts, wp, lnum, (colnr_T)vcol, line, ptr); + while (cts.cts_vcol < v && *cts.cts_ptr != NUL) { + charsize = win_lbr_chartabsize(&cts, NULL); + cts.cts_vcol += charsize; + prev_ptr = (char_u *)cts.cts_ptr; + MB_PTR_ADV(cts.cts_ptr); } + vcol = cts.cts_vcol; + ptr = (char_u *)cts.cts_ptr; + clear_chartabsize_arg(&cts); // When: // - 'cuc' is set, or @@ -963,11 +970,11 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, // Handle a character that's not completely on the screen: Put ptr at // that character but skip the first few screen characters. if (vcol > v) { - vcol -= c; + vcol -= charsize; ptr = prev_ptr; // If the character fits on the screen, don't need to skip it. // Except for a TAB. - if (utf_ptr2cells((char *)ptr) >= c || *ptr == TAB) { + if (utf_ptr2cells((char *)ptr) >= charsize || *ptr == TAB) { n_skip = (int)(v - vcol); } } @@ -1798,8 +1805,10 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, && !vim_isbreak((int)(*ptr))) { int mb_off = utf_head_off(line, ptr - 1); char_u *p = ptr - (mb_off + 1); - // TODO(neovim): is passing p for start of the line OK? - n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, NULL) - 1; + chartabsize_T cts; + + init_chartabsize_arg(&cts, wp, lnum, (colnr_T)vcol, line, p); + n_extra = win_lbr_chartabsize(&cts, NULL) - 1; // We have just drawn the showbreak value, no need to add // space for it again. @@ -1825,6 +1834,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, c = ' '; } } + clear_chartabsize_arg(&cts); } in_multispace = c == ' ' && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' '); diff --git a/src/nvim/edit.c b/src/nvim/edit.c index ed625e1d6e..e785a46dae 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1665,28 +1665,28 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang } else if (!(State & MODE_INSERT)) { new_cursor_col = curwin->w_cursor.col; } else { - /* - * Compute the screen column where the cursor should be. - */ + // Compute the screen column where the cursor should be. vcol = get_indent() - vcol; curwin->w_virtcol = (colnr_T)((vcol < 0) ? 0 : vcol); - /* - * Advance the cursor until we reach the right screen column. - */ - vcol = last_vcol = 0; - new_cursor_col = -1; + // Advance the cursor until we reach the right screen column. + last_vcol = 0; ptr = get_cursor_line_ptr(); - while (vcol <= (int)curwin->w_virtcol) { - last_vcol = vcol; - if (new_cursor_col >= 0) { - new_cursor_col += utfc_ptr2len((char *)ptr + new_cursor_col); - } else { - new_cursor_col++; + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, 0, 0, ptr, ptr); + while (cts.cts_vcol <= (int)curwin->w_virtcol) { + last_vcol = cts.cts_vcol; + if (cts.cts_vcol > 0) { + MB_PTR_ADV(cts.cts_ptr); + } + if (*cts.cts_ptr == NUL) { + break; } - vcol += lbr_chartabsize(ptr, ptr + new_cursor_col, (colnr_T)vcol); + cts.cts_vcol += lbr_chartabsize(&cts); } vcol = last_vcol; + new_cursor_col = (int)(cts.cts_ptr - cts.cts_line); + clear_chartabsize_arg(&cts); /* * May need to insert spaces to be able to position the cursor on @@ -2991,7 +2991,7 @@ static void replace_do_bs(int limit_col) // Get the number of screen cells used by the character we are // going to delete. getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL); - orig_vcols = win_chartabsize(curwin, get_cursor_pos_ptr(), start_vcol); + orig_vcols = win_chartabsize(curwin, (char *)get_cursor_pos_ptr(), start_vcol); } (void)del_char_after_col(limit_col); if (l_State & VREPLACE_FLAG) { @@ -3006,7 +3006,7 @@ static void replace_do_bs(int limit_col) ins_len = (int)STRLEN(p) - orig_len; vcol = start_vcol; for (i = 0; i < ins_len; i++) { - vcol += win_chartabsize(curwin, p + i, vcol); + vcol += win_chartabsize(curwin, (char *)p + i, vcol); i += utfc_ptr2len((char *)p) - 1; } vcol -= start_vcol; @@ -4644,11 +4644,15 @@ static bool ins_tab(void) getvcol(curwin, &fpos, &vcol, NULL, NULL); getvcol(curwin, cursor, &want_vcol, NULL, NULL); + char_u *tab = (char_u *)"\t"; + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, 0, vcol, tab, tab); + // Use as many TABs as possible. Beware of 'breakindent', 'showbreak' // and 'linebreak' adding extra virtual columns. while (ascii_iswhite(*ptr)) { - i = lbr_chartabsize(NULL, (char_u *)"\t", vcol); - if (vcol + i > want_vcol) { + i = lbr_chartabsize(&cts); + if (cts.cts_vcol + i > want_vcol) { break; } if (*ptr != TAB) { @@ -4663,19 +4667,24 @@ static bool ins_tab(void) } fpos.col++; ptr++; - vcol += i; + cts.cts_vcol += i; } + vcol = cts.cts_vcol; + clear_chartabsize_arg(&cts); if (change_col >= 0) { int repl_off = 0; - char_u *line = ptr; - // Skip over the spaces we need. - while (vcol < want_vcol && *ptr == ' ') { - vcol += lbr_chartabsize(line, ptr, vcol); - ptr++; + init_chartabsize_arg(&cts, curwin, 0, vcol, ptr, ptr); + while (cts.cts_vcol < want_vcol && *cts.cts_ptr == ' ') { + cts.cts_vcol += lbr_chartabsize(&cts); + cts.cts_ptr++; repl_off++; } + ptr = (char_u *)cts.cts_ptr; + vcol = cts.cts_vcol; + clear_chartabsize_arg(&cts); + if (vcol > want_vcol) { // Must have a char with 'showbreak' just before it. ptr--; @@ -4855,7 +4864,6 @@ static int ins_digraph(void) int ins_copychar(linenr_T lnum) { int c; - int temp; char_u *ptr, *prev_ptr; char_u *line; @@ -4865,17 +4873,23 @@ int ins_copychar(linenr_T lnum) } // try to advance to the cursor column - temp = 0; - line = ptr = ml_get(lnum); - prev_ptr = ptr; + line = ml_get(lnum); + prev_ptr = line; validate_virtcol(); - while ((colnr_T)temp < curwin->w_virtcol && *ptr != NUL) { - prev_ptr = ptr; - temp += lbr_chartabsize_adv(line, &ptr, (colnr_T)temp); + + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, lnum, 0, line, line); + while (cts.cts_vcol < curwin->w_virtcol && *cts.cts_ptr != NUL) { + prev_ptr = (char_u *)cts.cts_ptr; + cts.cts_vcol += lbr_chartabsize_adv(&cts); } - if ((colnr_T)temp > curwin->w_virtcol) { + + if (cts.cts_vcol > curwin->w_virtcol) { ptr = prev_ptr; + } else { + ptr = (char_u *)cts.cts_ptr; } + clear_chartabsize_arg(&cts); c = utf_ptr2char((char *)ptr); if (c == NUL) { diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 581f187140..f3a00ffeb2 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -849,11 +849,11 @@ static void get_col(typval_T *argvars, typval_T *rettv, bool charcol) // col(".") when the cursor is on the NUL at the end of the line // because of "coladd" can be seen as an extra column. if (virtual_active() && fp == &curwin->w_cursor) { - char_u *p = get_cursor_pos_ptr(); + char *p = (char *)get_cursor_pos_ptr(); if (curwin->w_cursor.coladd >= (colnr_T)win_chartabsize(curwin, p, curwin->w_virtcol - curwin->w_cursor.coladd)) { int l; - if (*p != NUL && p[(l = utfc_ptr2len((char *)p))] == NUL) { + if (*p != NUL && p[(l = utfc_ptr2len(p))] == NUL) { col += l; } } @@ -8512,7 +8512,7 @@ static void f_strdisplaywidth(typval_T *argvars, typval_T *rettv, EvalFuncData f col = (int)tv_get_number(&argvars[1]); } - rettv->vval.v_number = (varnumber_T)(linetabsize_col(col, (char_u *)s) - col); + rettv->vval.v_number = (varnumber_T)(linetabsize_col(col, (char *)s) - col); } /// "strwidth()" function diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a72cddc0a9..3bb900b57f 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -841,7 +841,7 @@ void ex_retab(exarg_T *eap) if (ptr[col] == NUL) { break; } - vcol += win_chartabsize(curwin, (char_u *)ptr + col, (colnr_T)vcol); + vcol += win_chartabsize(curwin, ptr + col, (colnr_T)vcol); if (vcol >= MAXCOL) { emsg(_(e_resulting_text_too_long)); break; diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index c1c5680cb0..f875fda13d 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2547,7 +2547,7 @@ static int vgetorpeek(bool advance) && (State & MODE_INSERT) && (p_timeout || (keylen == KEYLEN_PART_KEY && p_ttimeout)) && (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, 3, 25L)) == 0) { - colnr_T col = 0, vcol; + colnr_T col = 0; char_u *ptr; if (mode_displayed) { @@ -2565,15 +2565,20 @@ static int vgetorpeek(bool advance) // We are expecting to truncate the trailing // white-space, so find the last non-white // character -- webb - col = vcol = curwin->w_wcol = 0; + curwin->w_wcol = 0; ptr = get_cursor_line_ptr(); - while (col < curwin->w_cursor.col) { - if (!ascii_iswhite(ptr[col])) { - curwin->w_wcol = vcol; + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, + curwin->w_cursor.lnum, 0, ptr, ptr); + while ((char_u *)cts.cts_ptr < ptr + curwin->w_cursor.col) { + if (!ascii_iswhite(*cts.cts_ptr)) { + curwin->w_wcol = cts.cts_vcol; } - vcol += lbr_chartabsize(ptr, ptr + col, vcol); - col += utfc_ptr2len((char *)ptr + col); + cts.cts_vcol += lbr_chartabsize(&cts); + cts.cts_ptr += utfc_ptr2len(cts.cts_ptr); } + clear_chartabsize_arg(&cts); + curwin->w_wrow = curwin->w_cline_row + curwin->w_wcol / curwin->w_width_inner; curwin->w_wcol %= curwin->w_width_inner; diff --git a/src/nvim/indent.c b/src/nvim/indent.c index c4805283c2..8aa8492dae 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -1034,13 +1034,15 @@ int get_lisp_indent(void) amount = 2; } else { char_u *line = that; - - amount = 0; - - while (*that && col) { - amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount); + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, pos->lnum, 0, line, line); + while (*cts.cts_ptr != NUL && col > 0) { + cts.cts_vcol += lbr_chartabsize_adv(&cts); col--; } + amount = cts.cts_vcol; + that = (char_u *)cts.cts_ptr; + clear_chartabsize_arg(&cts); // Some keywords require "body" indenting rules (the // non-standard-lisp ones are Scheme special forms): @@ -1056,10 +1058,15 @@ int get_lisp_indent(void) } firsttry = amount; - while (ascii_iswhite(*that)) { - amount += lbr_chartabsize(line, that, (colnr_T)amount); - that++; + init_chartabsize_arg(&cts, curwin, (colnr_T)(that - line), + amount, line, that); + while (ascii_iswhite(*cts.cts_ptr)) { + cts.cts_vcol += lbr_chartabsize(&cts); + cts.cts_ptr++; } + that = (char_u *)cts.cts_ptr; + amount = cts.cts_vcol; + clear_chartabsize_arg(&cts); if (*that && (*that != ';')) { // Not a comment line. @@ -1072,33 +1079,38 @@ int get_lisp_indent(void) parencount = 0; quotecount = 0; + init_chartabsize_arg(&cts, curwin, + (colnr_T)(that - line), amount, line, that); if (vi_lisp || ((*that != '"') && (*that != '\'') && (*that != '#') && ((*that < '0') || (*that > '9')))) { - while (*that - && (!ascii_iswhite(*that) || quotecount || parencount) - && (!((*that == '(' || *that == '[') + while (*cts.cts_ptr + && (!ascii_iswhite(*cts.cts_ptr) || quotecount || parencount) + && (!((*cts.cts_ptr == '(' || *cts.cts_ptr == '[') && !quotecount && !parencount && vi_lisp))) { - if (*that == '"') { + if (*cts.cts_ptr == '"') { quotecount = !quotecount; } - if (((*that == '(') || (*that == '[')) && !quotecount) { + if (((*cts.cts_ptr == '(') || (*cts.cts_ptr == '[')) && !quotecount) { parencount++; } - if (((*that == ')') || (*that == ']')) && !quotecount) { + if (((*cts.cts_ptr == ')') || (*cts.cts_ptr == ']')) && !quotecount) { parencount--; } - if ((*that == '\\') && (*(that + 1) != NUL)) { - amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount); + if ((*cts.cts_ptr == '\\') && (*(cts.cts_ptr + 1) != NUL)) { + cts.cts_vcol += lbr_chartabsize_adv(&cts); } - amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount); + cts.cts_vcol += lbr_chartabsize_adv(&cts); } } - while (ascii_iswhite(*that)) { - amount += lbr_chartabsize(line, that, (colnr_T)amount); - that++; + while (ascii_iswhite(*cts.cts_ptr)) { + cts.cts_vcol += lbr_chartabsize(&cts); + cts.cts_ptr++; } + that = (char_u *)cts.cts_ptr; + amount = cts.cts_vcol; + clear_chartabsize_arg(&cts); if (!*that || (*that == ';')) { amount = firsttry; diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 3dfbeec048..5ebe97aa61 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -631,14 +631,16 @@ colnr_T vcol2col(win_T *const wp, const linenr_T lnum, const colnr_T vcol) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { // try to advance to the specified column - char_u *ptr = ml_get_buf(wp->w_buffer, lnum, false); - char_u *const line = ptr; - colnr_T count = 0; - while (count < vcol && *ptr != NUL) { - count += win_lbr_chartabsize(wp, line, ptr, count, NULL); - MB_PTR_ADV(ptr); - } - return (colnr_T)(ptr - line); + char_u *line = ml_get_buf(wp->w_buffer, lnum, false); + chartabsize_T cts; + init_chartabsize_arg(&cts, wp, lnum, 0, line, line); + while (cts.cts_vcol < vcol && *cts.cts_ptr != NUL) { + cts.cts_vcol += win_lbr_chartabsize(&cts, NULL); + MB_PTR_ADV(cts.cts_ptr); + } + clear_chartabsize_arg(&cts); + + return (colnr_T)((char_u *)cts.cts_ptr - line); } /// Set UI mouse depending on current mode and 'mouse'. @@ -667,7 +669,7 @@ static colnr_T scroll_line_len(linenr_T lnum) char_u *line = ml_get(lnum); if (*line != NUL) { for (;;) { - int numchar = win_chartabsize(curwin, line, col); + int numchar = win_chartabsize(curwin, (char *)line, col); MB_PTR_ADV(line); if (*line == NUL) { // don't count the last character break; @@ -790,7 +792,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col) // checked for concealed characters. vcol = 0; while (vcol < offset && *ptr != NUL) { - vcol += win_chartabsize(curwin, ptr, vcol); + vcol += win_chartabsize(curwin, (char *)ptr, vcol); ptr += utfc_ptr2len((char *)ptr); } @@ -801,7 +803,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col) vcol = offset; ptr_end = ptr_row_offset; while (vcol < col && *ptr_end != NUL) { - vcol += win_chartabsize(curwin, ptr_end, vcol); + vcol += win_chartabsize(curwin, (char *)ptr_end, vcol); ptr_end += utfc_ptr2len((char *)ptr_end); } @@ -816,7 +818,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col) #define DECR() nudge--; ptr_end -= utfc_ptr2len((char *)ptr_end) while (ptr < ptr_end && *ptr != NUL) { - cwidth = win_chartabsize(curwin, ptr, vcol); + cwidth = win_chartabsize(curwin, (char *)ptr, vcol); vcol += cwidth; if (cwidth > 1 && *ptr == '\t' && nudge > 0) { // A tab will "absorb" any previous adjustments. diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 0fc15b9382..896cfa6098 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -378,12 +378,20 @@ static void shift_block(oparg_T *oap, int amount) bd.startspaces = 0; } } - for (; ascii_iswhite(*bd.textstart);) { - // TODO(fmoralesc): is passing bd.textstart for start of the line OK? - incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, bd.start_vcol); + + // TODO(vim): is passing bd.textstart for start of the line OK? + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, + bd.start_vcol, bd.textstart, bd.textstart); + while (ascii_iswhite(*cts.cts_ptr)) { + incr = lbr_chartabsize_adv(&cts); total += incr; - bd.start_vcol += incr; + cts.cts_vcol += incr; } + bd.textstart = (char_u *)cts.cts_ptr; + bd.start_vcol = cts.cts_vcol; + clear_chartabsize_arg(&cts); + // OK, now total=all the VWS reqd, and textstart points at the 1st // non-ws char in the block. if (!curbuf->b_p_et) { @@ -438,10 +446,16 @@ static void shift_block(oparg_T *oap, int amount) // The character's column is in "bd.start_vcol". colnr_T non_white_col = bd.start_vcol; - while (ascii_iswhite(*non_white)) { - incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); - non_white_col += incr; + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, + non_white_col, bd.textstart, non_white); + while (ascii_iswhite(*cts.cts_ptr)) { + incr = lbr_chartabsize_adv(&cts); + cts.cts_vcol += incr; } + non_white_col = cts.cts_vcol; + non_white = (char_u *)cts.cts_ptr; + clear_chartabsize_arg(&cts); const colnr_T block_space_width = non_white_col - oap->start_vcol; // We will shift by "total" or "block_space_width", whichever is less. @@ -462,17 +476,19 @@ static void shift_block(oparg_T *oap, int amount) if (bd.startspaces) { verbatim_copy_width -= bd.start_char_vcols; } - while (verbatim_copy_width < destination_col) { - char_u *line = verbatim_copy_end; - - // TODO: is passing verbatim_copy_end for start of the line OK? - incr = lbr_chartabsize(line, verbatim_copy_end, verbatim_copy_width); - if (verbatim_copy_width + incr > destination_col) { + init_chartabsize_arg(&cts, curwin, 0, verbatim_copy_width, + bd.textstart, verbatim_copy_end); + while (cts.cts_vcol < destination_col) { + incr = lbr_chartabsize(&cts); + if (cts.cts_vcol + incr > destination_col) { break; } - verbatim_copy_width += incr; - MB_PTR_ADV(verbatim_copy_end); + cts.cts_vcol += incr; + MB_PTR_ADV(cts.cts_ptr); } + verbatim_copy_width = cts.cts_vcol; + verbatim_copy_end = (char_u *)cts.cts_ptr; + clear_chartabsize_arg(&cts); // If "destination_col" is different from the width of the initial // part of the line that will be copied, it means we encountered a tab @@ -1550,6 +1566,7 @@ int op_delete(oparg_T *oap) // Put deleted text into register 1 and shift number registers if the // delete contains a line break, or when using a specific operator (Vi // compatible) + if (oap->motion_type == kMTLineWise || oap->line_count > 1 || oap->use_reg_one) { shift_delete_registers(is_append_register(oap->regname)); reg = &y_regs[1]; @@ -3280,12 +3297,19 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // get the old line and advance to the position to insert at oldp = get_cursor_line_ptr(); oldlen = STRLEN(oldp); - for (ptr = oldp; vcol < col && *ptr;) { + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, + oldp, oldp); + + while (cts.cts_vcol < col && *cts.cts_ptr != NUL) { // Count a tab for what it's worth (if list mode not on) - incr = lbr_chartabsize_adv(oldp, &ptr, vcol); - vcol += incr; + incr = lbr_chartabsize_adv(&cts); + cts.cts_vcol += incr; } + vcol = cts.cts_vcol; + ptr = (char_u *)cts.cts_ptr; bd.textcol = (colnr_T)(ptr - oldp); + clear_chartabsize_arg(&cts); shortline = (vcol < col) || (vcol == col && !*ptr); @@ -3312,9 +3336,14 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // calculate number of spaces required to fill right side of // block spaces = y_width + 1; + init_chartabsize_arg(&cts, curwin, 0, 0, + (char_u *)y_array[i], (char_u *)y_array[i]); for (int j = 0; j < yanklen; j++) { - spaces -= lbr_chartabsize(NULL, (char_u *)(&y_array[i][j]), 0); + spaces -= lbr_chartabsize(&cts); + cts.cts_ptr++; + cts.cts_vcol = 0; } + clear_chartabsize_arg(&cts); if (spaces < 0) { spaces = 0; } @@ -4227,22 +4256,28 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool bdp->start_char_vcols = 0; line = ml_get(lnum); - pstart = line; prev_pstart = line; - while (bdp->start_vcol < oap->start_vcol && *pstart) { + + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, lnum, bdp->start_vcol, line, line); + while (cts.cts_vcol < oap->start_vcol && *cts.cts_ptr != NUL) { // Count a tab for what it's worth (if list mode not on) - incr = lbr_chartabsize(line, pstart, bdp->start_vcol); - bdp->start_vcol += incr; - if (ascii_iswhite(*pstart)) { + incr = lbr_chartabsize(&cts); + cts.cts_vcol += incr; + if (ascii_iswhite(*cts.cts_ptr)) { bdp->pre_whitesp += incr; bdp->pre_whitesp_c++; } else { bdp->pre_whitesp = 0; bdp->pre_whitesp_c = 0; } - prev_pstart = pstart; - MB_PTR_ADV(pstart); + prev_pstart = (char_u *)cts.cts_ptr; + MB_PTR_ADV(cts.cts_ptr); } + bdp->start_vcol = cts.cts_vcol; + pstart = (char_u *)cts.cts_ptr; + clear_chartabsize_arg(&cts); + bdp->start_char_vcols = incr; if (bdp->start_vcol < oap->start_vcol) { // line too short bdp->end_vcol = bdp->start_vcol; @@ -4278,13 +4313,19 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool } } } else { + init_chartabsize_arg(&cts, curwin, lnum, bdp->end_vcol, + line, pend); prev_pend = pend; - while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) { + while (cts.cts_vcol <= oap->end_vcol && *cts.cts_ptr != NUL) { // Count a tab for what it's worth (if list mode not on) - prev_pend = pend; - incr = lbr_chartabsize_adv(line, &pend, bdp->end_vcol); - bdp->end_vcol += incr; + prev_pend = (char_u *)cts.cts_ptr; + incr = lbr_chartabsize_adv(&cts); + cts.cts_vcol += incr; } + bdp->end_vcol = cts.cts_vcol; + pend = (char_u *)cts.cts_ptr; + clear_chartabsize_arg(&cts); + if (bdp->end_vcol <= oap->end_vcol && (!is_del || oap->op_type == OP_APPEND diff --git a/src/nvim/plines.c b/src/nvim/plines.c index 70bdbd8b1d..f13e83ca9b 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -98,15 +98,15 @@ int plines_win_nofill(win_T *wp, linenr_T lnum, bool winheight) /// "wp". Does not care about folding, 'wrap' or 'diff'. int plines_win_nofold(win_T *wp, linenr_T lnum) { - char_u *s; + char *s; unsigned int col; int width; - s = ml_get_buf(wp->w_buffer, lnum, false); + s = (char *)ml_get_buf(wp->w_buffer, lnum, false); if (*s == NUL) { // empty line return 1; } - col = win_linetabsize(wp, s, MAXCOL); + col = win_linetabsize(wp, lnum, (char_u *)s, MAXCOL); // If list mode is on, then the '$' at the end of the line may take up one // extra column. @@ -145,23 +145,27 @@ int plines_win_col(win_T *wp, linenr_T lnum, long column) } char_u *line = ml_get_buf(wp->w_buffer, lnum, false); - char_u *s = line; colnr_T col = 0; - while (*s != NUL && --column >= 0) { - col += win_lbr_chartabsize(wp, line, s, col, NULL); - MB_PTR_ADV(s); + chartabsize_T cts; + + init_chartabsize_arg(&cts, wp, lnum, 0, line, line); + while (*cts.cts_ptr != NUL && --column >= 0) { + cts.cts_vcol += win_lbr_chartabsize(&cts, NULL); + MB_PTR_ADV(cts.cts_ptr); } - // If *s is a TAB, and the TAB is not displayed as ^I, and we're not in - // MODE_INSERT state, then col must be adjusted so that it represents the + // If *cts.cts_ptr is a TAB, and the TAB is not displayed as ^I, and we're not + // in MODE_INSERT state, then col must be adjusted so that it represents the // last screen position of the TAB. This only fixes an error when the TAB // wraps from one screen line to the next (when 'columns' is not a multiple // of 'ts') -- webb. - if (*s == TAB && (State & MODE_NORMAL) + col = cts.cts_vcol; + if (*cts.cts_ptr == TAB && (State & MODE_NORMAL) && (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) { - col += win_lbr_chartabsize(wp, line, s, col, NULL) - 1; + col += win_lbr_chartabsize(&cts, NULL) - 1; } + clear_chartabsize_arg(&cts); // Add column offset for 'number', 'relativenumber', 'foldcolumn', etc. int width = wp->w_width_inner - win_col_off(wp); @@ -223,7 +227,7 @@ int plines_m_win(win_T *wp, linenr_T first, linenr_T last) /// @param col /// /// @return Number of characters. -int win_chartabsize(win_T *wp, char_u *p, colnr_T col) +int win_chartabsize(win_T *wp, char *p, colnr_T col) { buf_T *buf = wp->w_buffer; if (*p == TAB && (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) { @@ -241,24 +245,24 @@ int win_chartabsize(win_T *wp, char_u *p, colnr_T col) /// @return Number of characters the string will take on the screen. int linetabsize(char_u *s) { - return linetabsize_col(0, s); + return linetabsize_col(0, (char *)s); } -/// Like linetabsize(), but starting at column "startcol". +/// Like linetabsize(), but "s" starts at column "startcol". /// /// @param startcol /// @param s /// /// @return Number of characters the string will take on the screen. -int linetabsize_col(int startcol, char_u *s) +int linetabsize_col(int startcol, char *s) { - colnr_T col = startcol; - char_u *line = s; // pointer to start of line, for breakindent - - while (*s != NUL) { - col += lbr_chartabsize_adv(line, &s, col); + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, 0, startcol, (char_u *)s, (char_u *)s); + while (*cts.cts_ptr != NUL) { + cts.cts_vcol += lbr_chartabsize_adv(&cts); } - return (int)col; + clear_chartabsize_arg(&cts); + return (int)cts.cts_vcol; } /// Like linetabsize(), but for a given window instead of the current one. @@ -268,19 +272,39 @@ int linetabsize_col(int startcol, char_u *s) /// @param len /// /// @return Number of characters the string will take on the screen. -unsigned int win_linetabsize(win_T *wp, char_u *line, colnr_T len) +unsigned int win_linetabsize(win_T *wp, linenr_T lnum, char_u *line, colnr_T len) { - colnr_T col = 0; - - for (char_u *s = line; - *s != NUL && (len == MAXCOL || s < line + len); - MB_PTR_ADV(s)) { - col += win_lbr_chartabsize(wp, line, s, col, NULL); + chartabsize_T cts; + init_chartabsize_arg(&cts, wp, lnum, 0, line, line); + for (; *cts.cts_ptr != NUL && (len == MAXCOL || cts.cts_ptr < (char *)line + len); + MB_PTR_ADV(cts.cts_ptr)) { + cts.cts_vcol += win_lbr_chartabsize(&cts, NULL); } + clear_chartabsize_arg(&cts); + return (unsigned int)cts.cts_vcol; +} - return (unsigned int)col; +/// Prepare the structure passed to chartabsize functions. +/// +/// "line" is the start of the line, "ptr" is the first relevant character. +/// When "lnum" is zero do not use text properties that insert text. +void init_chartabsize_arg(chartabsize_T *cts, win_T *wp, linenr_T lnum, colnr_T col, char_u *line, + char_u *ptr) +{ + cts->cts_win = wp; + cts->cts_lnum = lnum; + cts->cts_vcol = col; + cts->cts_line = (char *)line; + cts->cts_ptr = (char *)ptr; + cts->cts_cur_text_width = 0; + // TODO(bfredl): actually lookup inline virtual text here + cts->cts_has_virt_text = false; } +/// Free any allocated item in "cts". +void clear_chartabsize_arg(chartabsize_T *cts) +{} + /// like win_chartabsize(), but also check for line breaks on the screen /// /// @param line @@ -288,16 +312,16 @@ unsigned int win_linetabsize(win_T *wp, char_u *line, colnr_T len) /// @param col /// /// @return The number of characters taken up on the screen. -int lbr_chartabsize(char_u *line, unsigned char *s, colnr_T col) +int lbr_chartabsize(chartabsize_T *cts) { if (!curwin->w_p_lbr && *get_showbreak_value(curwin) == NUL - && !curwin->w_p_bri) { + && !curwin->w_p_bri && !cts->cts_has_virt_text) { if (curwin->w_p_wrap) { - return win_nolbr_chartabsize(curwin, s, col, NULL); + return win_nolbr_chartabsize(cts, NULL); } - return win_chartabsize(curwin, s, col); + return win_chartabsize(curwin, cts->cts_ptr, cts->cts_vcol); } - return win_lbr_chartabsize(curwin, line == NULL ? s: line, s, col, NULL); + return win_lbr_chartabsize(cts, NULL); } /// Call lbr_chartabsize() and advance the pointer. @@ -307,12 +331,12 @@ int lbr_chartabsize(char_u *line, unsigned char *s, colnr_T col) /// @param col /// /// @return The number of characters take up on the screen. -int lbr_chartabsize_adv(char_u *line, char_u **s, colnr_T col) +int lbr_chartabsize_adv(chartabsize_T *cts) { int retval; - retval = lbr_chartabsize(line, *s, col); - MB_PTR_ADV(*s); + retval = lbr_chartabsize(cts); + MB_PTR_ADV(cts->cts_ptr); return retval; } @@ -322,17 +346,19 @@ int lbr_chartabsize_adv(char_u *line, char_u **s, colnr_T col) /// string at start of line. Warning: *headp is only set if it's a non-zero /// value, init to 0 before calling. /// -/// @param wp -/// @param line -/// @param s -/// @param col +/// @param cts /// @param headp /// /// @return The number of characters taken up on the screen. -int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *headp) +int win_lbr_chartabsize(chartabsize_T *cts, int *headp) { + win_T *wp = cts->cts_win; + char *line = cts->cts_line; // start of the line + char_u *s = (char_u *)cts->cts_ptr; + colnr_T vcol = cts->cts_vcol; + colnr_T col2; - colnr_T col_adj = 0; // col + screen size of tab + colnr_T col_adj = 0; // vcol + screen size of tab colnr_T colmax; int added; int mb_added = 0; @@ -340,16 +366,23 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he char_u *ps; int n; + cts->cts_cur_text_width = 0; + // No 'linebreak', 'showbreak' and 'breakindent': return quickly. - if (!wp->w_p_lbr && !wp->w_p_bri && *get_showbreak_value(wp) == NUL) { + if (!wp->w_p_lbr && !wp->w_p_bri && *get_showbreak_value(wp) == NUL + && !cts->cts_has_virt_text) { if (wp->w_p_wrap) { - return win_nolbr_chartabsize(wp, s, col, headp); + return win_nolbr_chartabsize(cts, headp); } - return win_chartabsize(wp, s, col); + return win_chartabsize(wp, (char *)s, vcol); + } + + // First get normal size, without 'linebreak' or virtual text + int size = win_chartabsize(wp, (char *)s, vcol); + if (cts->cts_has_virt_text) { + // TODO(bfredl): inline virtual text } - // First get normal size, without 'linebreak' - int size = win_chartabsize(wp, s, col); int c = *s; if (*s == TAB) { col_adj = size - 1; @@ -365,15 +398,15 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he // Count all characters from first non-blank after a blank up to next // non-blank after a blank. numberextra = win_col_off(wp); - col2 = col; + col2 = vcol; colmax = (colnr_T)(wp->w_width_inner - numberextra - col_adj); - if (col >= colmax) { + if (vcol >= colmax) { colmax += col_adj; n = colmax + win_col_off2(wp); if (n > 0) { - colmax += (((col - colmax) / n) + 1) * n - col_adj; + colmax += (((vcol - colmax) / n) + 1) * n - col_adj; } } @@ -383,21 +416,21 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he c = *s; if (!(c != NUL - && (vim_isbreak(c) || col2 == col || !vim_isbreak((int)(*ps))))) { + && (vim_isbreak(c) || col2 == vcol || !vim_isbreak((int)(*ps))))) { break; } - col2 += win_chartabsize(wp, s, col2); + col2 += win_chartabsize(wp, (char *)s, col2); if (col2 >= colmax) { // doesn't fit - size = colmax - col + col_adj; + size = colmax - vcol + col_adj; break; } } } else if ((size == 2) && (MB_BYTE2LEN(*s) > 1) && wp->w_p_wrap - && in_win_border(wp, col)) { + && in_win_border(wp, vcol)) { // Count the ">" in the last column. size++; mb_added = 1; @@ -409,40 +442,40 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he added = 0; char *const sbr = (char *)get_showbreak_value(wp); - if ((*sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && col != 0) { + if ((*sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && vcol != 0) { colnr_T sbrlen = 0; int numberwidth = win_col_off(wp); numberextra = numberwidth; - col += numberextra + mb_added; + vcol += numberextra + mb_added; - if (col >= (colnr_T)wp->w_width_inner) { - col -= wp->w_width_inner; + if (vcol >= (colnr_T)wp->w_width_inner) { + vcol -= wp->w_width_inner; numberextra = wp->w_width_inner - (numberextra - win_col_off2(wp)); - if (col >= numberextra && numberextra > 0) { - col %= numberextra; + if (vcol >= numberextra && numberextra > 0) { + vcol %= numberextra; } if (*sbr != NUL) { sbrlen = (colnr_T)mb_charlen((char_u *)sbr); - if (col >= sbrlen) { - col -= sbrlen; + if (vcol >= sbrlen) { + vcol -= sbrlen; } } - if (col >= numberextra && numberextra > 0) { - col %= numberextra; - } else if (col > 0 && numberextra > 0) { - col += numberwidth - win_col_off2(wp); + if (vcol >= numberextra && numberextra > 0) { + vcol %= numberextra; + } else if (vcol > 0 && numberextra > 0) { + vcol += numberwidth - win_col_off2(wp); } numberwidth -= win_col_off2(wp); } - if (col == 0 || (col + size + sbrlen > (colnr_T)wp->w_width_inner)) { + if (vcol == 0 || (vcol + size + sbrlen > (colnr_T)wp->w_width_inner)) { if (*sbr != NUL) { if (size + sbrlen + numberwidth > (colnr_T)wp->w_width_inner) { // Calculate effective window width. int width = (colnr_T)wp->w_width_inner - sbrlen - numberwidth; - int prev_width = col ? ((colnr_T)wp->w_width_inner - (sbrlen + col)) + int prev_width = vcol ? ((colnr_T)wp->w_width_inner - (sbrlen + vcol)) : 0; if (width <= 0) { @@ -459,11 +492,11 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he } if (wp->w_p_bri) { - added += get_breakindent_win(wp, line); + added += get_breakindent_win(wp, (char_u *)line); } size += added; - if (col != 0) { + if (vcol != 0) { added = 0; } } @@ -485,8 +518,11 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he /// @param headp /// /// @return The number of characters take up on the screen. -static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp) +static int win_nolbr_chartabsize(chartabsize_T *cts, int *headp) { + win_T *wp = cts->cts_win; + char *s = cts->cts_ptr; + colnr_T col = cts->cts_vcol; int n; if ((*s == TAB) && (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) { @@ -498,7 +534,7 @@ static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp) // Add one cell for a double-width character in the last column of the // window, displayed with a ">". - if ((n == 2) && (MB_BYTE2LEN(*s) > 1) && in_win_border(wp, col)) { + if ((n == 2) && (MB_BYTE2LEN((uint8_t)(*s)) > 1) && in_win_border(wp, col)) { if (headp != NULL) { *headp = 1; } diff --git a/src/nvim/plines.h b/src/nvim/plines.h index 32778b69f1..7b228f3e91 100644 --- a/src/nvim/plines.h +++ b/src/nvim/plines.h @@ -3,6 +3,20 @@ #include "nvim/vim.h" +// Argument for lbr_chartabsize(). +typedef struct { + win_T *cts_win; + linenr_T cts_lnum; // zero when not using text properties + char *cts_line; // start of the line + char *cts_ptr; // current position in line + + bool cts_has_virt_text; // true if if a property inserts text + int cts_cur_text_width; // width of current inserted text + // TODO(bfredl): iterator in to the marktree for scanning virt text + + int cts_vcol; // virtual column at current position +} chartabsize_T; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "plines.h.generated.h" #endif diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index b7ec4bf94e..75bd7b4cc1 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1165,7 +1165,7 @@ static bool reg_match_visual(void) rex.line = reg_getline(rex.lnum); rex.input = rex.line + col; - unsigned int cols_u = win_linetabsize(wp, rex.line, col); + unsigned int cols_u = win_linetabsize(wp, rex.reg_firstlnum + rex.lnum, rex.line, col); assert(cols_u <= MAXCOL); colnr_T cols = (colnr_T)cols_u; if (cols < start || cols > end - (*p_sel == 'e')) { diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c index d7a4f40ecf..88f0d781af 100644 --- a/src/nvim/regexp_bt.c +++ b/src/nvim/regexp_bt.c @@ -3764,6 +3764,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) case RE_VCOL: if (!re_num_cmp(win_linetabsize(rex.reg_win == NULL ? curwin : rex.reg_win, + rex.reg_firstlnum + rex.lnum, rex.line, (colnr_T)(rex.input - rex.line)) + 1, scan)) { diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 554def5b8a..d4db710d93 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -6910,7 +6910,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm result = col > t->state->val * ts; } if (!result) { - uintmax_t lts = win_linetabsize(wp, rex.line, col); + uintmax_t lts = win_linetabsize(wp, rex.reg_firstlnum + rex.lnum, rex.line, col); assert(t->state->val >= 0); result = nfa_re_num_cmp((uintmax_t)t->state->val, op, lts + 1); } -- cgit From 92bc11a891538e5c306915bffef437f097572d09 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 29 Aug 2022 20:22:15 +0800 Subject: vim-patch:9.0.0316: screen flickers when 'cmdheight' is zero (#19991) Problem: Screen flickers when 'cmdheight' is zero. Solution: Redraw over existing text instead of clearing. https://github.com/vim/vim/commit/f73e5ba56f4aca1cd6e38f1c8ea24e941bf6b33f --- src/nvim/drawscreen.c | 50 ++++++++++++++++++++++++++------------------------ src/nvim/ex_getln.c | 2 +- 2 files changed, 27 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index cf8178a30f..a601a82495 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -469,35 +469,37 @@ int update_screen(int type) } msg_grid_set_pos(Rows - (int)p_ch, false); msg_grid_invalid = false; - } else if (msg_scrolled > Rows - 5) { // clearing is faster - type = UPD_CLEAR; } else if (type != UPD_CLEAR) { - check_for_delay(false); - grid_ins_lines(&default_grid, 0, msg_scrolled, Rows, 0, Columns); - FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - if (wp->w_floating) { - continue; - } - if (wp->w_winrow < msg_scrolled) { - if (W_ENDROW(wp) > msg_scrolled - && wp->w_redr_type < UPD_REDRAW_TOP - && wp->w_lines_valid > 0 - && wp->w_topline == wp->w_lines[0].wl_lnum) { - wp->w_upd_rows = msg_scrolled - wp->w_winrow; - wp->w_redr_type = UPD_REDRAW_TOP; - } else { - wp->w_redr_type = UPD_NOT_VALID; - if (wp->w_winrow + wp->w_winbar_height <= msg_scrolled) { - wp->w_redr_status = true; + if (msg_scrolled > Rows - 5) { // redrawing is faster + type = UPD_NOT_VALID; + } else { + check_for_delay(false); + grid_ins_lines(&default_grid, 0, msg_scrolled, Rows, 0, Columns); + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { + if (wp->w_floating) { + continue; + } + if (wp->w_winrow < msg_scrolled) { + if (W_ENDROW(wp) > msg_scrolled + && wp->w_redr_type < UPD_REDRAW_TOP + && wp->w_lines_valid > 0 + && wp->w_topline == wp->w_lines[0].wl_lnum) { + wp->w_upd_rows = msg_scrolled - wp->w_winrow; + wp->w_redr_type = UPD_REDRAW_TOP; + } else { + wp->w_redr_type = UPD_NOT_VALID; + if (wp->w_winrow + wp->w_winbar_height <= msg_scrolled) { + wp->w_redr_status = true; + } } } } + if (is_stl_global && Rows - p_ch - 1 <= msg_scrolled) { + curwin->w_redr_status = true; + } + redraw_cmdline = true; + redraw_tabline = true; } - if (is_stl_global && Rows - p_ch - 1 <= msg_scrolled) { - curwin->w_redr_status = true; - } - redraw_cmdline = true; - redraw_tabline = true; } msg_scrolled = 0; msg_scrolled_at_flush = 0; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 3d991996d6..0cca4b69e8 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -918,7 +918,7 @@ theend: // Restore cmdheight set_option_value("ch", 0L, NULL, 0); // Redraw is needed for command line completion - redraw_all_later(UPD_CLEAR); + redraw_all_later(UPD_NOT_VALID); made_cmdheight_nonzero = false; } -- cgit From 58f30a326f34319801e7921f32c83e8320d85f6c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/arglist.c | 2 +- src/nvim/buffer.c | 2 +- src/nvim/buffer_defs.h | 6 +- src/nvim/change.c | 140 ++++++++++++++++++++++----------------------- src/nvim/charset.c | 18 +++--- src/nvim/cmdexpand.c | 9 ++- src/nvim/debugger.c | 10 ++-- src/nvim/diff.c | 78 ++++++++++++------------- src/nvim/drawline.c | 10 ++-- src/nvim/drawscreen.c | 2 +- src/nvim/edit.c | 40 ++++++------- src/nvim/eval.c | 2 +- src/nvim/eval/funcs.c | 24 ++++---- src/nvim/eval/userfunc.c | 4 +- src/nvim/eval/vars.c | 2 +- src/nvim/ex_cmds.c | 14 ++--- src/nvim/ex_docmd.c | 14 ++--- src/nvim/ex_eval.c | 6 +- src/nvim/ex_getln.c | 2 +- src/nvim/fileio.c | 4 +- src/nvim/getchar.c | 2 +- src/nvim/grid.c | 25 ++++---- src/nvim/hardcopy.c | 21 +++---- src/nvim/help.c | 4 +- src/nvim/highlight_group.c | 2 +- src/nvim/if_cscope.c | 8 +-- src/nvim/indent.c | 10 ++-- src/nvim/indent_c.c | 14 ++--- src/nvim/insexpand.c | 4 +- src/nvim/log.c | 2 +- src/nvim/lua/stdlib.c | 4 +- src/nvim/mapping.c | 4 +- src/nvim/mark.c | 6 +- src/nvim/match.c | 4 +- src/nvim/mbyte.c | 48 +++++++--------- src/nvim/memline.c | 12 ++-- src/nvim/message.c | 16 +++--- src/nvim/normal.c | 26 ++++----- src/nvim/ops.c | 16 +++--- src/nvim/option.c | 2 +- src/nvim/os/env.c | 4 +- src/nvim/os/fs.c | 2 +- src/nvim/path.c | 24 ++++---- src/nvim/plines.c | 2 +- src/nvim/popupmenu.c | 9 ++- src/nvim/quickfix.c | 12 ++-- src/nvim/regexp.c | 10 ++-- src/nvim/runtime.c | 30 ++++++---- src/nvim/screen.c | 14 ++--- src/nvim/search.c | 29 +++++----- src/nvim/shada.c | 2 +- src/nvim/spellfile.c | 88 ++++++++++++++-------------- src/nvim/statusline.c | 15 +++-- src/nvim/strings.c | 4 +- src/nvim/syntax.c | 20 +++---- src/nvim/tag.c | 33 ++++++----- src/nvim/textformat.c | 6 +- src/nvim/usercmd.c | 24 ++++---- src/nvim/usercmd.h | 6 +- src/nvim/version.c | 13 ++--- src/nvim/window.c | 12 ++-- 61 files changed, 479 insertions(+), 499 deletions(-) (limited to 'src') diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index 21aa5afbae..70b2e71949 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -202,7 +202,7 @@ static char *do_one_arg(char *str) for (p = str; *str; str++) { // When the backslash is used for escaping the special meaning of a // character we need to keep it until wildcard expansion. - if (rem_backslash((char_u *)str)) { + if (rem_backslash(str)) { *p++ = *str++; *p++ = *str; } else { diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 5dc7083a01..514be4c56b 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2701,7 +2701,7 @@ void buflist_list(exarg_T *eap) home_replace(buf, buf->b_fname, (char *)NameBuff, MAXPATHL, true); } - if (message_filtered((char_u *)NameBuff)) { + if (message_filtered(NameBuff)) { continue; } diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 319c2addba..c1ac20fd98 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -325,7 +325,7 @@ typedef struct argentry { * Used for the typeahead buffer: typebuf. */ typedef struct { - char_u *tb_buf; // buffer for typed characters + uint8_t *tb_buf; // buffer for typed characters uint8_t *tb_noremap; // mapping flags for characters in tb_buf[] int tb_buflen; // size of tb_buf[] int tb_off; // current position in tb_buf[] @@ -353,7 +353,7 @@ typedef struct { typedef struct mapblock mapblock_T; struct mapblock { mapblock_T *m_next; // next mapblock in list - char_u *m_keys; // mapped from, lhs + uint8_t *m_keys; // mapped from, lhs char *m_str; // mapped to, rhs char *m_orig_str; // rhs as entered by the user LuaRef m_luaref; // lua function reference as rhs @@ -703,7 +703,7 @@ struct file_buffer { char *b_p_cms; ///< 'commentstring' char *b_p_cpt; ///< 'complete' #ifdef BACKSLASH_IN_FILENAME - char_u *b_p_csl; ///< 'completeslash' + char *b_p_csl; ///< 'completeslash' #endif char *b_p_cfu; ///< 'completefunc' char *b_p_ofu; ///< 'omnifunc' diff --git a/src/nvim/change.c b/src/nvim/change.c index 074700f4df..fd079f8eef 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -589,17 +589,17 @@ bool file_ff_differs(buf_T *buf, bool ignore_empty) /// Handles Replace mode and multi-byte characters. void ins_bytes(char *p) { - ins_bytes_len((char_u *)p, STRLEN(p)); + ins_bytes_len(p, STRLEN(p)); } /// Insert string "p" with length "len" at the cursor position. /// Handles Replace mode and multi-byte characters. -void ins_bytes_len(char_u *p, size_t len) +void ins_bytes_len(char *p, size_t len) { size_t n; for (size_t i = 0; i < len; i += n) { // avoid reading past p[len] - n = (size_t)utfc_ptr2len_len(p + i, (int)(len - i)); + n = (size_t)utfc_ptr2len_len((char_u *)p + i, (int)(len - i)); ins_char_bytes(p + i, n); } } @@ -611,18 +611,18 @@ void ins_bytes_len(char_u *p, size_t len) /// convert bytes to a character. void ins_char(int c) { - char_u buf[MB_MAXBYTES + 1]; - size_t n = (size_t)utf_char2bytes(c, (char *)buf); + char buf[MB_MAXBYTES + 1]; + size_t n = (size_t)utf_char2bytes(c, buf); // When "c" is 0x100, 0x200, etc. we don't want to insert a NUL byte. // Happens for CTRL-Vu9900. if (buf[0] == 0) { buf[0] = '\n'; } - ins_char_bytes((char_u *)buf, n); + ins_char_bytes(buf, n); } -void ins_char_bytes(char_u *buf, size_t charlen) +void ins_char_bytes(char *buf, size_t charlen) { // Break tabs if needed. if (virtual_active() && curwin->w_cursor.coladd > 0) { @@ -631,7 +631,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) size_t col = (size_t)curwin->w_cursor.col; linenr_T lnum = curwin->w_cursor.lnum; - char_u *oldp = ml_get(lnum); + char *oldp = (char *)ml_get(lnum); size_t linelen = STRLEN(oldp) + 1; // length of old line including NUL // The lengths default to the values for when not replacing. @@ -661,7 +661,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) if (vcol > new_vcol && oldp[col + oldlen] == TAB) { break; } - oldlen += (size_t)utfc_ptr2len((char *)oldp + col + oldlen); + oldlen += (size_t)utfc_ptr2len(oldp + col + oldlen); // Deleted a bit too much, insert spaces. if (vcol > new_vcol) { newlen += (size_t)(vcol - new_vcol); @@ -670,7 +670,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) curwin->w_p_list = old_list; } else if (oldp[col] != NUL) { // normal replace - oldlen = (size_t)utfc_ptr2len((char *)oldp + col); + oldlen = (size_t)utfc_ptr2len(oldp + col); } // Push the replaced bytes onto the replace stack, so that they can be @@ -683,7 +683,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) } } - char_u *newp = xmalloc(linelen + newlen - oldlen); + char *newp = xmalloc(linelen + newlen - oldlen); // Copy bytes before the cursor. if (col > 0) { @@ -691,7 +691,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) } // Copy bytes after the changed character(s). - char_u *p = newp + col; + char *p = newp + col; if (linelen > col + oldlen) { memmove(p + newlen, oldp + col + oldlen, (size_t)(linelen - col - oldlen)); @@ -706,7 +706,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) } // Replace the line in the buffer. - ml_replace(lnum, (char *)newp, false); + ml_replace(lnum, newp, false); // mark the buffer as changed and prepare for displaying inserted_bytes(lnum, (colnr_T)col, (int)oldlen, (int)newlen); @@ -716,7 +716,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) if (p_sm && (State & MODE_INSERT) && msg_silent == 0 && !ins_compl_active()) { - showmatch(utf_ptr2char((char *)buf)); + showmatch(utf_ptr2char(buf)); } if (!p_ri || (State & REPLACE_FLAG)) { @@ -729,7 +729,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) /// Insert a string at the cursor position. /// Note: Does NOT handle Replace mode. /// Caller must have prepared for undo. -void ins_str(char_u *s) +void ins_str(char *s) { int newlen = (int)STRLEN(s); linenr_T lnum = curwin->w_cursor.lnum; @@ -739,10 +739,10 @@ void ins_str(char_u *s) } colnr_T col = curwin->w_cursor.col; - char_u *oldp = ml_get(lnum); + char *oldp = (char *)ml_get(lnum); int oldlen = (int)STRLEN(oldp); - char_u *newp = (char_u *)xmalloc((size_t)oldlen + (size_t)newlen + 1); + char *newp = xmalloc((size_t)oldlen + (size_t)newlen + 1); if (col > 0) { memmove(newp, oldp, (size_t)col); } @@ -750,7 +750,7 @@ void ins_str(char_u *s) int bytes = oldlen - col + 1; assert(bytes >= 0); memmove(newp + col + newlen, oldp + col, (size_t)bytes); - ml_replace(lnum, (char *)newp, false); + ml_replace(lnum, newp, false); inserted_bytes(lnum, col, 0, newlen); curwin->w_cursor.col += newlen; } @@ -774,9 +774,9 @@ int del_char(bool fixpos) int del_chars(long count, int fixpos) { int bytes = 0; - char_u *p = get_cursor_pos_ptr(); + char *p = (char *)get_cursor_pos_ptr(); for (long i = 0; i < count && *p != NUL; i++) { - int l = utfc_ptr2len((char *)p); + int l = utfc_ptr2len(p); bytes += l; p += l; } @@ -797,7 +797,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) linenr_T lnum = curwin->w_cursor.lnum; colnr_T col = curwin->w_cursor.col; bool fixpos = fixpos_arg; - char_u *oldp = ml_get(lnum); + char *oldp = (char *)ml_get(lnum); colnr_T oldlen = (colnr_T)STRLEN(oldp); // Can't do anything when the cursor is on the NUL after the line. @@ -817,7 +817,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) // If 'delcombine' is set and deleting (less than) one character, only // delete the last combining character. if (p_deco && use_delcombine - && utfc_ptr2len((char *)oldp + col) >= count) { + && utfc_ptr2len(oldp + col) >= count) { int cc[MAX_MCO]; (void)utfc_ptr2char(oldp + col, cc); @@ -826,9 +826,9 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) int n = col; do { col = n; - count = utf_ptr2len((char *)oldp + n); + count = utf_ptr2len(oldp + n); n += count; - } while (utf_composinglike(oldp + col, oldp + n)); + } while (utf_composinglike((char_u *)oldp + col, (char_u *)oldp + n)); fixpos = false; } } @@ -843,7 +843,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) && (get_ve_flags() & VE_ONEMORE) == 0) { curwin->w_cursor.col--; curwin->w_cursor.coladd = 0; - curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col); + curwin->w_cursor.col -= utf_head_off((char_u *)oldp, (char_u *)oldp + curwin->w_cursor.col); } count = oldlen - col; movelen = 1; @@ -852,7 +852,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) // If the old line has been allocated the deletion can be done in the // existing line. Otherwise a new line has to be allocated. bool was_alloced = ml_line_alloced(); // check if oldp was allocated - char_u *newp; + char *newp; if (was_alloced) { ml_add_deleted_len(curbuf->b_ml.ml_line_ptr, oldlen); newp = oldp; // use same allocated memory @@ -862,7 +862,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) } memmove(newp + col, oldp + col + count, (size_t)movelen); if (!was_alloced) { - ml_replace(lnum, (char *)newp, false); + ml_replace(lnum, newp, false); } // mark the buffer as changed and prepare for displaying @@ -874,10 +874,10 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) /// Copy the indent from ptr to the current line (and fill to size). /// Leaves the cursor on the first non-blank in the line. /// @return true if the line was changed. -int copy_indent(int size, char_u *src) +int copy_indent(int size, char *src) { - char_u *p = NULL; - char_u *line = NULL; + char *p = NULL; + char *line = NULL; int ind_len; int line_len = 0; int tab_pad; @@ -889,7 +889,7 @@ int copy_indent(int size, char_u *src) ind_len = 0; int ind_done = 0; int ind_col = 0; - char_u *s = src; + char *s = src; // Count/copy the usable portion of the source line. while (todo > 0 && ascii_iswhite(*s)) { @@ -975,7 +975,7 @@ int copy_indent(int size, char_u *src) memmove(p, get_cursor_line_ptr(), (size_t)line_len); // Replace the line - ml_replace(curwin->w_cursor.lnum, (char *)line, false); + ml_replace(curwin->w_cursor.lnum, line, false); // Put the cursor after the indent. curwin->w_cursor.col = ind_len; @@ -1006,8 +1006,8 @@ int copy_indent(int size, char_u *src) /// @return true on success, false on failure int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) { - char_u *next_line = NULL; // copy of the next line - char_u *p_extra = NULL; // what goes to next line + char *next_line = NULL; // copy of the next line + char *p_extra = NULL; // what goes to next line colnr_T less_cols = 0; // less columns for mark in new line colnr_T less_cols_off = 0; // columns to skip for mark adjust pos_T old_cursor; // old cursor position @@ -1020,9 +1020,9 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) int comment_start = 0; // start index of the comment leader char *lead_flags; // position in 'comments' for comment leader char *leader = NULL; // copy of comment leader - char_u *allocated = NULL; // allocated memory + char *allocated = NULL; // allocated memory char *p; - char_u saved_char = NUL; // init for GCC + char saved_char = NUL; // init for GCC pos_T *pos; bool do_si = may_do_si(); bool do_cindent; @@ -1036,7 +1036,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) colnr_T mincol = curwin->w_cursor.col + 1; // make a copy of the current line so we can mess with it - char_u *saved_line = vim_strsave(get_cursor_line_ptr()); + char *saved_line = (char *)vim_strsave(get_cursor_line_ptr()); if (State & VREPLACE_FLAG) { // With MODE_VREPLACE we make a copy of the next line, which we will be @@ -1047,9 +1047,9 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // the line, replacing what was there before and pushing the right // stuff onto the replace stack. -- webb. if (curwin->w_cursor.lnum < orig_line_count) { - next_line = vim_strsave(ml_get(curwin->w_cursor.lnum + 1)); + next_line = (char *)vim_strsave(ml_get(curwin->w_cursor.lnum + 1)); } else { - next_line = vim_strsave((char_u *)""); + next_line = xstrdup(""); } // In MODE_VREPLACE state, a NL replaces the rest of the line, and @@ -1059,9 +1059,9 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // autoindent etc) a bit later. replace_push(NUL); // Call twice because BS over NL expects it replace_push(NUL); - p = (char *)saved_line + curwin->w_cursor.col; + p = saved_line + curwin->w_cursor.col; while (*p != NUL) { - p += replace_push_mb((char_u *)p); + p += replace_push_mb(p); } saved_line[curwin->w_cursor.col] = NUL; } @@ -1069,7 +1069,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0) { p_extra = saved_line + curwin->w_cursor.col; if (do_si) { // need first char after new line break - p = skipwhite((char *)p_extra); + p = skipwhite(p_extra); first_char = (unsigned char)(*p); } extra_len = (int)STRLEN(p_extra); @@ -1109,7 +1109,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) char *ptr; old_cursor = curwin->w_cursor; - ptr = (char *)saved_line; + ptr = saved_line; if (flags & OPENLINE_DO_COM) { lead_len = get_leader_len(ptr, NULL, false, true); } else { @@ -1193,7 +1193,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // Don't do this if the previous line ended in ';' or // '}'. } else if (last_char != ';' && last_char != '}' - && cin_is_cinword((char_u *)ptr)) { + && cin_is_cinword(ptr)) { did_si = true; } } @@ -1243,13 +1243,13 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // This may then be inserted in front of the new line. end_comment_pending = NUL; if (flags & OPENLINE_DO_COM) { - lead_len = get_leader_len((char *)saved_line, &lead_flags, dir == BACKWARD, true); + lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, true); if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD && (!has_format_option(FO_NO_OPEN_COMS) || (flags & OPENLINE_FORMAT))) { // Check for a line comment after code. comment_start = check_linecomment(saved_line); if (comment_start != MAXCOL) { - lead_len = get_leader_len((char *)saved_line + comment_start, &lead_flags, false, true); + lead_len = get_leader_len(saved_line + comment_start, &lead_flags, false, true); if (lead_len != 0) { lead_len += comment_start; if (did_do_comment != NULL) { @@ -1264,13 +1264,13 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (lead_len > 0) { char *lead_repl = NULL; // replaces comment leader int lead_repl_len = 0; // length of *lead_repl - char_u lead_middle[COM_MAX_LEN]; // middle-comment string - char_u lead_end[COM_MAX_LEN]; // end-comment string - char_u *comment_end = NULL; // where lead_end has been found + char lead_middle[COM_MAX_LEN]; // middle-comment string + char lead_end[COM_MAX_LEN]; // end-comment string + char *comment_end = NULL; // where lead_end has been found int extra_space = false; // append extra space int current_flag; int require_blank = false; // requires blank after middle - char_u *p2; + char *p2; // If the comment leader has the start, middle or end flag, it may not // be used or may be replaced with the middle leader. @@ -1312,15 +1312,15 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) size_t n = copy_option_part(&p, (char *)lead_end, COM_MAX_LEN, ","); if (end_comment_pending == -1) { // we can set it now - end_comment_pending = lead_end[n - 1]; + end_comment_pending = (unsigned char)lead_end[n - 1]; } // If the end of the comment is in the same line, don't use // the comment leader. if (dir == FORWARD) { - for (p = (char *)saved_line + lead_len; *p; p++) { + for (p = saved_line + lead_len; *p; p++) { if (STRNCMP(p, lead_end, n) == 0) { - comment_end = (char_u *)p; + comment_end = p; lead_len = 0; break; } @@ -1353,7 +1353,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // Remember where the end is, might want to use it to find the // start (for C-comments). if (dir == FORWARD) { - comment_end = (char_u *)skipwhite((char *)saved_line); + comment_end = skipwhite(saved_line); lead_len = 0; break; } @@ -1372,7 +1372,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) extra_space = true; // Check whether we allow automatic ending of comments - for (p2 = (char_u *)p; *p2 && *p2 != ':'; p2++) { + for (p2 = p; *p2 && *p2 != ':'; p2++) { if (*p2 == COM_AUTO_END) { end_comment_pending = -1; // means we want to set it } @@ -1382,7 +1382,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) while (*p2 && *p2 != ',') { p2++; } - end_comment_pending = p2[-1]; + end_comment_pending = (unsigned char)p2[-1]; } break; } @@ -1408,7 +1408,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) + 1; assert(bytes >= 0); leader = xmalloc((size_t)bytes); - allocated = (char_u *)leader; // remember to free it later + allocated = leader; // remember to free it later STRLCPY(leader, saved_line, lead_len + 1); @@ -1442,7 +1442,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // Compute the length of the replaced characters in // screen characters, not bytes. { - int repl_size = vim_strnsize((char_u *)lead_repl, lead_repl_len); + int repl_size = vim_strnsize(lead_repl, lead_repl_len); int old_size = 0; char *endp = p; int l; @@ -1487,13 +1487,13 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // screen characters, not bytes. Move the part that is // not to be overwritten. { - int repl_size = vim_strnsize((char_u *)lead_repl, lead_repl_len); + int repl_size = vim_strnsize(lead_repl, lead_repl_len); int i; int l; for (i = 0; i < lead_len && p[i] != NUL; i += l) { l = utfc_ptr2len(p + i); - if (vim_strnsize((char_u *)p, i + l) > repl_size) { + if (vim_strnsize(p, i + l) > repl_size) { break; } } @@ -1536,7 +1536,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // Recompute the indent, it may have changed. if (curbuf->b_p_ai || do_si) { - newindent = get_indent_str_vtab((char_u *)leader, + newindent = get_indent_str_vtab(leader, curbuf->b_p_ts, curbuf->b_p_vts_array, false); } @@ -1619,7 +1619,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) { while ((*p_extra == ' ' || *p_extra == '\t') - && !utf_iscomposing(utf_ptr2char((char *)p_extra + 1))) { + && !utf_iscomposing(utf_ptr2char(p_extra + 1))) { if (REPLACE_NORMAL(State)) { replace_push(*p_extra); } @@ -1633,7 +1633,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } if (p_extra == NULL) { - p_extra = (char_u *)""; // append empty line + p_extra = ""; // append empty line } // concatenate leader and p_extra, if there is a leader @@ -1653,7 +1653,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } } STRCAT(leader, p_extra); - p_extra = (char_u *)leader; + p_extra = leader; did_ai = true; // So truncating blanks works with comments less_cols -= lead_len; } else { @@ -1666,7 +1666,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) curwin->w_cursor.lnum--; } if ((State & VREPLACE_FLAG) == 0 || old_cursor.lnum >= orig_line_count) { - if (ml_append(curwin->w_cursor.lnum, (char *)p_extra, (colnr_T)0, false) == FAIL) { + if (ml_append(curwin->w_cursor.lnum, p_extra, (colnr_T)0, false) == FAIL) { goto theend; } // Postpone calling changed_lines(), because it would mess up folding @@ -1688,7 +1688,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) (void)u_save_cursor(); // errors are ignored! vr_lines_changed++; } - ml_replace(curwin->w_cursor.lnum, (char *)p_extra, true); + ml_replace(curwin->w_cursor.lnum, p_extra, true); changed_bytes(curwin->w_cursor.lnum, 0); // TODO(vigoux): extmark_splice_cols here?? curwin->w_cursor.lnum--; @@ -1753,7 +1753,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (trunc_line && !(flags & OPENLINE_KEEPTRAIL)) { truncate_spaces(saved_line); } - ml_replace(curwin->w_cursor.lnum, (char *)saved_line, false); + ml_replace(curwin->w_cursor.lnum, saved_line, false); int new_len = (int)STRLEN(saved_line); @@ -1838,15 +1838,15 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // stuff onto the replace stack (via ins_char()). if (State & VREPLACE_FLAG) { // Put new line in p_extra - p_extra = vim_strsave(get_cursor_line_ptr()); + p_extra = (char *)vim_strsave(get_cursor_line_ptr()); // Put back original line - ml_replace(curwin->w_cursor.lnum, (char *)next_line, false); + ml_replace(curwin->w_cursor.lnum, next_line, false); // Insert new stuff into line again curwin->w_cursor.col = 0; curwin->w_cursor.coladd = 0; - ins_bytes((char *)p_extra); // will call changed_bytes() + ins_bytes(p_extra); // will call changed_bytes() xfree(p_extra); next_line = NULL; } diff --git a/src/nvim/charset.c b/src/nvim/charset.c index e0f798121a..2632279565 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -313,7 +313,7 @@ size_t transstr_len(const char *const s, bool untab) const size_t l = (size_t)utfc_ptr2len(p); if (l > 1) { int pcc[MAX_MCO + 1]; - pcc[0] = utfc_ptr2char((const char_u *)p, &pcc[1]); + pcc[0] = utfc_ptr2char(p, &pcc[1]); if (vim_isprintc(pcc[0])) { len += l; @@ -359,7 +359,7 @@ size_t transstr_buf(const char *const s, char *const buf, const size_t len, bool break; // Exceeded `buf` size. } int pcc[MAX_MCO + 1]; - pcc[0] = utfc_ptr2char((const char_u *)p, &pcc[1]); + pcc[0] = utfc_ptr2char(p, &pcc[1]); if (vim_isprintc(pcc[0])) { memmove(buf_p, p, l); @@ -709,7 +709,7 @@ int ptr2cells(const char *p_in) /// @return number of character cells. int vim_strsize(char *s) { - return vim_strnsize((char_u *)s, MAXCOL); + return vim_strnsize(s, MAXCOL); } /// Return the number of character cells string "s[len]" will take on the @@ -721,13 +721,13 @@ int vim_strsize(char *s) /// @param len /// /// @return Number of character cells. -int vim_strnsize(char_u *s, int len) +int vim_strnsize(char *s, int len) { assert(s != NULL); int size = 0; while (*s != NUL && --len >= 0) { - int l = utfc_ptr2len((char *)s); - size += ptr2cells((char *)s); + int l = utfc_ptr2len(s); + size += ptr2cells(s); s += l; len -= l - 1; } @@ -1687,12 +1687,12 @@ int hexhex2nr(const char_u *p) /// characters. /// /// @param str file path string to check -bool rem_backslash(const char_u *str) +bool rem_backslash(const char *str) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { #ifdef BACKSLASH_IN_FILENAME return str[0] == '\\' - && str[1] < 0x80 + && (uint8_t)str[1] < 0x80 && (str[1] == ' ' || (str[1] != NUL && str[1] != '*' @@ -1710,7 +1710,7 @@ bool rem_backslash(const char_u *str) void backslash_halve(char_u *p) { for (; *p; p++) { - if (rem_backslash(p)) { + if (rem_backslash((char *)p)) { STRMOVE(p, p + 1); } } diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 7f9a8b2a5c..dbf169c801 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -787,7 +787,7 @@ static bool expand_showtail(expand_T *xp) for (s = (char_u *)xp->xp_pattern; s < end; s++) { // Skip escaped wildcards. Only when the backslash is not a path // separator, on DOS the '*' "path\*\file" must not be skipped. - if (rem_backslash(s)) { + if (rem_backslash((char *)s)) { s++; } else if (vim_strchr("*?[", *s) != NULL) { return false; @@ -1242,11 +1242,10 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons arg = (const char *)skipwhite((char *)skiptowhite((const char_u *)arg)); if (*arg != NUL) { xp->xp_context = EXPAND_NOTHING; - arg = (const char *)skip_regexp((char_u *)arg + 1, (uint8_t)(*arg), - p_magic, NULL); + arg = (const char *)skip_regexp((char *)arg + 1, (uint8_t)(*arg), p_magic, NULL); } } - return (const char *)find_nextcmd((char_u *)arg); + return (const char *)find_nextcmd(arg); // All completion for the +cmdline_compl feature goes here. @@ -1282,7 +1281,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons if (delim) { // Skip "from" part. arg++; - arg = (const char *)skip_regexp((char_u *)arg, delim, p_magic, NULL); + arg = (const char *)skip_regexp((char *)arg, delim, p_magic, NULL); } // Skip "to" part. while (arg[0] != NUL && (uint8_t)arg[0] != delim) { diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index 9aee023f0c..9fdeebf68a 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -47,7 +47,7 @@ struct debuggy { /// Debug mode. Repeatedly get Ex commands, until told to continue normal /// execution. -void do_debug(char_u *cmd) +void do_debug(char *cmd) { int save_msg_scroll = msg_scroll; int save_State = State; @@ -239,11 +239,11 @@ void do_debug(char_u *cmd) last_cmd = CMD_STEP; break; case CMD_BACKTRACE: - do_showbacktrace(cmd); + do_showbacktrace((char_u *)cmd); continue; case CMD_FRAME: if (*p == NUL) { - do_showbacktrace(cmd); + do_showbacktrace((char_u *)cmd); } else { p = skipwhite(p); do_setdebugtracelevel((char_u *)p); @@ -414,7 +414,7 @@ void dbg_check_breakpoint(exarg_T *eap) debug_breakpoint_name + (*p == NUL ? 0 : 3), (int64_t)debug_breakpoint_lnum); debug_breakpoint_name = NULL; - do_debug((char_u *)eap->cmd); + do_debug(eap->cmd); } else { debug_skipped = true; debug_skipped_name = debug_breakpoint_name; @@ -422,7 +422,7 @@ void dbg_check_breakpoint(exarg_T *eap) } } else if (ex_nesting_level <= debug_break_level) { if (!eap->skip) { - do_debug((char_u *)eap->cmd); + do_debug(eap->cmd); } else { debug_skipped = true; debug_skipped_name = NULL; diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 23fdc728f3..1cfb535fe8 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -573,9 +573,9 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) if (dir == BACKWARD) { off_org = dp->df_count[i_org] - 1; } - char_u *line_org = vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], - dp->df_lnum[i_org] + off_org, - false)); + char *line_org = (char *)vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], + dp->df_lnum[i_org] + off_org, + false)); int i_new; for (i_new = i_org + 1; i_new < DB_COUNT; i_new++) { @@ -592,9 +592,9 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) break; } - if (diff_cmp(line_org, ml_get_buf(tp->tp_diffbuf[i_new], - dp->df_lnum[i_new] + off_new, - false)) != 0) { + if (diff_cmp((char_u *)line_org, ml_get_buf(tp->tp_diffbuf[i_new], + dp->df_lnum[i_new] + off_new, + false)) != 0) { break; } } @@ -1539,8 +1539,8 @@ static void diff_read(int idx_orig, int idx_new, diffio_T *dio) diff_T *dp = curtab->tp_first_diff; diff_T *dn, *dpl; diffout_T *dout = &dio->dio_diff; - char_u linebuf[LBUFLEN]; // only need to hold the diff line - char_u *line; + char linebuf[LBUFLEN]; // only need to hold the diff line + char *line; linenr_T off; int i; int notset = true; // block "*dp" not set yet @@ -1576,9 +1576,9 @@ static void diff_read(int idx_orig, int idx_new, diffio_T *dio) if (line_idx >= dout->dout_ga.ga_len) { break; // did last line } - line = ((char_u **)dout->dout_ga.ga_data)[line_idx++]; + line = ((char **)dout->dout_ga.ga_data)[line_idx++]; } else { - if (vim_fgets(linebuf, LBUFLEN, fd)) { + if (vim_fgets((char_u *)linebuf, LBUFLEN, fd)) { break; // end of file } line = linebuf; @@ -1600,9 +1600,9 @@ static void diff_read(int idx_orig, int idx_new, diffio_T *dio) } else if ((STRNCMP(line, "@@ ", 3) == 0)) { diffstyle = DIFF_UNIFIED; } else if ((STRNCMP(line, "--- ", 4) == 0) // -V501 - && (vim_fgets(linebuf, LBUFLEN, fd) == 0) // -V501 + && (vim_fgets((char_u *)linebuf, LBUFLEN, fd) == 0) // -V501 && (STRNCMP(line, "+++ ", 4) == 0) - && (vim_fgets(linebuf, LBUFLEN, fd) == 0) // -V501 + && (vim_fgets((char_u *)linebuf, LBUFLEN, fd) == 0) // -V501 && (STRNCMP(line, "@@ ", 3) == 0)) { diffstyle = DIFF_UNIFIED; } else { @@ -1616,7 +1616,7 @@ static void diff_read(int idx_orig, int idx_new, diffio_T *dio) if (!isdigit(*line)) { continue; // not the start of a diff block } - if (parse_diff_ed(line, hunk) == FAIL) { + if (parse_diff_ed((char_u *)line, hunk) == FAIL) { continue; } } else { @@ -1624,7 +1624,7 @@ static void diff_read(int idx_orig, int idx_new, diffio_T *dio) if (STRNCMP(line, "@@ ", 3) != 0) { continue; // not the start of a diff block } - if (parse_diff_unified(line, hunk) == FAIL) { + if (parse_diff_unified((char_u *)line, hunk) == FAIL) { continue; } } @@ -1920,11 +1920,11 @@ static bool diff_equal_entry(diff_T *dp, int idx1, int idx2) } for (int i = 0; i < dp->df_count[idx1]; i++) { - char_u *line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1], - dp->df_lnum[idx1] + i, false)); + char *line = (char *)vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1], + dp->df_lnum[idx1] + i, false)); - int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], - dp->df_lnum[idx2] + i, false)); + int cmp = diff_cmp((char_u *)line, ml_get_buf(curtab->tp_diffbuf[idx2], + dp->df_lnum[idx2] + i, false)); xfree(line); if (cmp != 0) { @@ -2281,7 +2281,7 @@ bool diffopt_filler(void) bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - char_u *line_new; + char *line_new; int si_org; int si_new; int ei_org; @@ -2290,7 +2290,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) int l; // Make a copy of the line, the next ml_get() will invalidate it. - char_u *line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, false)); + char *line_org = (char *)vim_strsave(ml_get_buf(wp->w_buffer, lnum, false)); int idx = diff_buf_idx(wp->w_buffer); if (idx == DB_COUNT) { @@ -2322,8 +2322,8 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) continue; } added = false; - line_new = ml_get_buf(curtab->tp_diffbuf[i], - dp->df_lnum[i] + off, false); + line_new = (char *)ml_get_buf(curtab->tp_diffbuf[i], + dp->df_lnum[i] + off, false); // Search for start of difference si_org = si_new = 0; @@ -2335,10 +2335,10 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) || ((diff_flags & DIFF_IWHITEALL) && (ascii_iswhite(line_org[si_org]) || ascii_iswhite(line_new[si_new])))) { - si_org = (int)((char_u *)skipwhite((char *)line_org + si_org) - line_org); - si_new = (int)((char_u *)skipwhite((char *)line_new + si_new) - line_new); + si_org = (int)(skipwhite(line_org + si_org) - line_org); + si_new = (int)(skipwhite(line_new + si_new) - line_new); } else { - if (!diff_equal_char(line_org + si_org, line_new + si_new, &l)) { + if (!diff_equal_char((char_u *)line_org + si_org, (char_u *)line_new + si_new, &l)) { break; } si_org += l; @@ -2348,8 +2348,8 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) // Move back to first byte of character in both lines (may // have "nn^" in line_org and "n^ in line_new). - si_org -= utf_head_off(line_org, line_org + si_org); - si_new -= utf_head_off(line_new, line_new + si_new); + si_org -= utf_head_off((char_u *)line_org, (char_u *)line_org + si_org); + si_new -= utf_head_off((char_u *)line_new, (char_u *)line_new + si_new); if (*startp > si_org) { *startp = si_org; @@ -2378,11 +2378,11 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) ei_new--; } } else { - const char_u *p1 = line_org + ei_org; - const char_u *p2 = line_new + ei_new; + const char_u *p1 = (char_u *)line_org + ei_org; + const char_u *p2 = (char_u *)line_new + ei_new; - p1 -= utf_head_off(line_org, p1); - p2 -= utf_head_off(line_new, p2); + p1 -= utf_head_off((char_u *)line_org, p1); + p2 -= utf_head_off((char_u *)line_new, p2); if (!diff_equal_char(p1, p2, &l)) { break; @@ -2511,7 +2511,7 @@ void ex_diffgetput(exarg_T *eap) diff_T *dfree; int i; int added; - char_u *p; + char *p; aco_save_T aco; buf_T *buf; linenr_T start_skip; @@ -2565,18 +2565,18 @@ void ex_diffgetput(exarg_T *eap) } } else { // Buffer number or pattern given. Ignore trailing white space. - p = (char_u *)eap->arg + STRLEN(eap->arg); - while (p > (char_u *)eap->arg && ascii_iswhite(p[-1])) { + p = eap->arg + STRLEN(eap->arg); + while (p > eap->arg && ascii_iswhite(p[-1])) { p--; } - for (i = 0; ascii_isdigit(eap->arg[i]) && (char_u *)eap->arg + i < p; i++) {} + for (i = 0; ascii_isdigit(eap->arg[i]) && eap->arg + i < p; i++) {} - if ((char_u *)eap->arg + i == p) { + if (eap->arg + i == p) { // digits only i = (int)atol(eap->arg); } else { - i = buflist_findpat(eap->arg, (char *)p, false, true, false); + i = buflist_findpat(eap->arg, p, false, true, false); if (i < 0) { // error message already given @@ -2718,8 +2718,8 @@ void ex_diffgetput(exarg_T *eap) if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count) { break; } - p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, false)); - ml_append(lnum + i - 1, (char *)p, 0, false); + p = (char *)vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, false)); + ml_append(lnum + i - 1, p, 0, false); xfree(p); added++; if (buf_empty && (curbuf->b_ml.ml_line_count == 2)) { diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 4b5f6c6c06..b6654699d8 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -116,7 +116,7 @@ static int line_putchar(buf_T *buf, LineState *s, schar_T *dest, int maxcells, b if (cells > maxcells) { return -1; } - u8c = utfc_ptr2char(p, u8cc); + u8c = utfc_ptr2char((char *)p, u8cc); if (*p == TAB) { cells = MIN(tabstop_padding(vcol, buf->b_p_ts, buf->b_p_vts_array), maxcells); for (int c = 0; c < cells; c++) { @@ -141,7 +141,7 @@ static int line_putchar(buf_T *buf, LineState *s, schar_T *dest, int maxcells, b nc = utf_ptr2char((char *)p + c_len); s->prev_c1 = u8cc[0]; } else { - pc = utfc_ptr2char(p + c_len, pcc); + pc = utfc_ptr2char((char *)p + c_len, pcc); nc = s->prev_c; pc1 = pcc[0]; } @@ -1489,7 +1489,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (mb_l > n_extra) { mb_l = 1; } else if (mb_l > 1) { - mb_c = utfc_ptr2char(p_extra, u8cc); + mb_c = utfc_ptr2char((char *)p_extra, u8cc); mb_utf8 = true; c = 0xc0; } @@ -1540,7 +1540,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, mb_l = utfc_ptr2len((char *)ptr); mb_utf8 = false; if (mb_l > 1) { - mb_c = utfc_ptr2char(ptr, u8cc); + mb_c = utfc_ptr2char((char *)ptr, u8cc); // Overlong encoded ASCII or ASCII with composing char // is displayed normally, except a NUL. if (mb_c < 0x80) { @@ -1598,7 +1598,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, nc = utf_ptr2char((char *)ptr + mb_l); prev_c1 = u8cc[0]; } else { - pc = utfc_ptr2char(ptr + mb_l, pcc); + pc = utfc_ptr2char((char *)ptr + mb_l, pcc); nc = prev_c; pc1 = pcc[0]; } diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index a601a82495..40dbec8a5b 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -1889,7 +1889,7 @@ win_update_start: int scr_row = wp->w_grid.rows - 1; // Last line isn't finished: Display "@@@" in the last screen line. - grid_puts_len(&wp->w_grid, (char_u *)"@@", MIN(wp->w_grid.cols, 2), scr_row, 0, at_attr); + grid_puts_len(&wp->w_grid, "@@", MIN(wp->w_grid.cols, 2), scr_row, 0, at_attr); grid_fill(&wp->w_grid, scr_row, scr_row + 1, 2, wp->w_grid.cols, '@', ' ', at_attr); diff --git a/src/nvim/edit.c b/src/nvim/edit.c index b9432ca362..b0174de01f 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1523,8 +1523,7 @@ void edit_unputchar(void) if (pc_status == PC_STATUS_RIGHT || pc_status == PC_STATUS_LEFT) { redrawWinline(curwin, curwin->w_cursor.lnum); } else { - grid_puts(&curwin->w_grid, pc_bytes, pc_row - msg_scrolled, pc_col, - pc_attr); + grid_puts(&curwin->w_grid, (char *)pc_bytes, pc_row - msg_scrolled, pc_col, pc_attr); } } } @@ -1698,7 +1697,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang ptr = xmallocz(i); memset(ptr, ' ', i); new_cursor_col += (int)i; - ins_str(ptr); + ins_str((char *)ptr); xfree(ptr); } @@ -1797,7 +1796,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang /// Truncate the space at the end of a line. This is to be used only in an /// insert mode. It handles fixing the replace stack for MODE_REPLACE and /// MODE_VREPLACE modes. -void truncate_spaces(char_u *line) +void truncate_spaces(char *line) { int i; @@ -1989,7 +1988,7 @@ static void insert_special(int c, int allow_modmask, int ctrlv) return; } p[len - 1] = NUL; - ins_str(p); + ins_str((char *)p); AppendToRedobuffLit((char *)p, -1); ctrlv = false; } @@ -2117,7 +2116,7 @@ void insertchar(int c, int flags, int second_indent) // Insert the end-comment string, except for the last // character, which will get inserted as normal later. - ins_bytes_len(lead_end, (size_t)(end_len - 1)); + ins_bytes_len((char *)lead_end, (size_t)(end_len - 1)); } } } @@ -2177,7 +2176,7 @@ void insertchar(int c, int flags, int second_indent) do_digraph(-1); // clear digraphs do_digraph(buf[i - 1]); // may be the start of a digraph buf[i] = NUL; - ins_str(buf); + ins_str((char *)buf); if (flags & INSCHAR_CTRLV) { redo_literal(*buf); i = 1; @@ -2195,7 +2194,7 @@ void insertchar(int c, int flags, int second_indent) utf_char2bytes(c, (char *)buf); buf[cc] = NUL; - ins_char_bytes((char_u *)buf, (size_t)cc); + ins_char_bytes(buf, (size_t)cc); AppendCharToRedobuff(c); } else { ins_char(c); @@ -2848,14 +2847,13 @@ void replace_push(int c) replace_stack_nr++; } -/* - * Push a character onto the replace stack. Handles a multi-byte character in - * reverse byte order, so that the first byte is popped off first. - * Return the number of bytes done (includes composing characters). - */ -int replace_push_mb(char_u *p) +/// Push a character onto the replace stack. Handles a multi-byte character in +/// reverse byte order, so that the first byte is popped off first. +/// +/// @return the number of bytes done (includes composing characters). +int replace_push_mb(char *p) { - int l = utfc_ptr2len((char *)p); + int l = utfc_ptr2len(p); int j; for (j = l - 1; j >= 0; j--) { @@ -2919,7 +2917,7 @@ static void mb_replace_pop_ins(int cc) for (i = 1; i < n; i++) { buf[i] = (char_u)replace_pop(); } - ins_bytes_len(buf, (size_t)n); + ins_bytes_len((char *)buf, (size_t)n); } else { ins_char(cc); } @@ -2942,7 +2940,7 @@ static void mb_replace_pop_ins(int cc) buf[i] = (char_u)replace_pop(); } if (utf_iscomposing(utf_ptr2char((char *)buf))) { - ins_bytes_len(buf, (size_t)n); + ins_bytes_len((char *)buf, (size_t)n); } else { // Not a composing char, put it back. for (i = n - 1; i >= 0; i--) { @@ -4078,7 +4076,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) if (State & VREPLACE_FLAG) { ins_char(' '); } else { - ins_str((char_u *)" "); + ins_str(" "); if ((State & REPLACE_FLAG)) { replace_push(NUL); } @@ -4122,7 +4120,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) } else { const int l_p_deco = p_deco; if (l_p_deco) { - (void)utfc_ptr2char(get_cursor_pos_ptr(), cpc); + (void)utfc_ptr2char((char *)get_cursor_pos_ptr(), cpc); } (void)del_char(false); // If there are combining characters and 'delcombine' is set @@ -4584,7 +4582,7 @@ static bool ins_tab(void) if (State & VREPLACE_FLAG) { ins_char(' '); } else { - ins_str((char_u *)" "); + ins_str(" "); if (State & REPLACE_FLAG) { // no char replaced replace_push(NUL); } @@ -4718,7 +4716,7 @@ static bool ins_tab(void) // Insert each char in saved_line from changed_col to // ptr-cursor - ins_bytes_len(saved_line + change_col, (size_t)(cursor->col - change_col)); + ins_bytes_len((char *)saved_line + change_col, (size_t)(cursor->col - change_col)); } } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index ecac7e75ae..f89b06843a 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -8162,7 +8162,7 @@ repeat: while (src[*usedlen] == ':' && src[*usedlen + 1] == 'h') { valid |= VALID_HEAD; *usedlen += 2; - s = (char *)get_past_head((char_u *)(*fnamep)); + s = get_past_head(*fnamep); while (tail > s && after_pathsep(s, tail)) { MB_PTR_BACK(*fnamep, tail); } diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 0c3d2d6935..0bf3ad6901 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -851,7 +851,8 @@ static void get_col(typval_T *argvars, typval_T *rettv, bool charcol) if (virtual_active() && fp == &curwin->w_cursor) { char *p = (char *)get_cursor_pos_ptr(); if (curwin->w_cursor.coladd >= - (colnr_T)win_chartabsize(curwin, p, curwin->w_virtcol - curwin->w_cursor.coladd)) { + (colnr_T)win_chartabsize(curwin, p, + curwin->w_virtcol - curwin->w_cursor.coladd)) { int l; if (*p != NUL && p[(l = utfc_ptr2len(p))] == NUL) { col += l; @@ -3896,12 +3897,12 @@ static void f_iconv(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const char *const str = tv_get_string(&argvars[0]); char buf1[NUMBUFLEN]; char_u *const from = - (char_u *)enc_canonize((char *)enc_skip((char_u *)tv_get_string_buf(&argvars[1], buf1))); + (char_u *)enc_canonize(enc_skip((char *)tv_get_string_buf(&argvars[1], buf1))); char buf2[NUMBUFLEN]; char_u *const to = - (char_u *)enc_canonize((char *)enc_skip((char_u *)tv_get_string_buf(&argvars[2], buf2))); + (char_u *)enc_canonize(enc_skip((char *)tv_get_string_buf(&argvars[2], buf2))); vimconv.vc_type = CONV_NONE; - convert_setup(&vimconv, from, to); + convert_setup(&vimconv, (char *)from, (char *)to); // If the encodings are equal, no conversion needed. if (vimconv.vc_type == CONV_NONE) { @@ -7072,7 +7073,7 @@ static void f_screenchars(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) return; } int pcc[MAX_MCO]; - int c = utfc_ptr2char(grid->chars[grid->line_offset[row] + (size_t)col], pcc); + int c = utfc_ptr2char((char *)grid->chars[grid->line_offset[row] + (size_t)col], pcc); int composing_len = 0; while (pcc[composing_len] != 0) { composing_len++; @@ -7605,7 +7606,7 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv, EvalFuncData fpt char_u *const csearch = (char_u *)tv_dict_get_string(d, "char", false); if (csearch != NULL) { int pcc[MAX_MCO]; - const int c = utfc_ptr2char(csearch, pcc); + const int c = utfc_ptr2char((char *)csearch, pcc); set_last_csearch(c, csearch, utfc_ptr2len((char *)csearch)); } @@ -8402,11 +8403,10 @@ static void f_strftime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) rettv->vval.v_string = xstrdup(_("(Invalid)")); } else { vimconv_T conv; - char_u *enc; conv.vc_type = CONV_NONE; - enc = enc_locale(); - convert_setup(&conv, (char_u *)p_enc, enc); + char *enc = (char *)enc_locale(); + convert_setup(&conv, p_enc, enc); if (conv.vc_type != CONV_NONE) { p = (char *)string_convert(&conv, (char_u *)p, NULL); } @@ -8420,7 +8420,7 @@ static void f_strftime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (conv.vc_type != CONV_NONE) { xfree(p); } - convert_setup(&conv, enc, (char_u *)p_enc); + convert_setup(&conv, enc, p_enc); if (conv.vc_type != CONV_NONE) { rettv->vval.v_string = (char *)string_convert(&conv, (char_u *)result_buf, NULL); } else { @@ -8665,8 +8665,8 @@ static void f_strptime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) vimconv_T conv = { .vc_type = CONV_NONE, }; - char_u *enc = enc_locale(); - convert_setup(&conv, (char_u *)p_enc, enc); + char *enc = (char *)enc_locale(); + convert_setup(&conv, p_enc, enc); if (conv.vc_type != CONV_NONE) { fmt = (char *)string_convert(&conv, (char_u *)fmt, NULL); } diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 8cb7a075cb..2a48de5e41 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1933,7 +1933,7 @@ void ex_function(exarg_T *eap) if (!HASHITEM_EMPTY(hi)) { todo--; fp = HI2UF(hi); - if (message_filtered(fp->uf_name)) { + if (message_filtered((char *)fp->uf_name)) { continue; } if (!func_name_refcount(fp->uf_name)) { @@ -1950,7 +1950,7 @@ void ex_function(exarg_T *eap) * ":function /pat": list functions matching pattern. */ if (*eap->arg == '/') { - p = skip_regexp((char_u *)eap->arg + 1, '/', true, NULL); + p = (char_u *)skip_regexp(eap->arg + 1, '/', true, NULL); if (!eap->skip) { regmatch_T regmatch; diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index 0086cc41ca..e73bba16e2 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -413,7 +413,7 @@ void list_hashtable_vars(hashtab_T *ht, const char *prefix, int empty, int *firs // apply :filter /pat/ to variable name xstrlcpy(buf, prefix, IOSIZE); xstrlcat(buf, (char *)di->di_key, IOSIZE); - if (message_filtered((char_u *)buf)) { + if (message_filtered(buf)) { continue; } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 6886ce0987..57eb2f526f 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -120,7 +120,7 @@ void do_ascii(const exarg_T *const eap) { char *dig; int cc[MAX_MCO]; - int c = utfc_ptr2char(get_cursor_pos_ptr(), cc); + int c = utfc_ptr2char((char *)get_cursor_pos_ptr(), cc); if (c == NUL) { msg("NUL"); return; @@ -513,7 +513,7 @@ void ex_sort(exarg_T *eap) eap->nextcmd = (char *)check_nextcmd((char_u *)p); break; } else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) { - s = (char *)skip_regexp((char_u *)p + 1, *p, true, NULL); + s = skip_regexp(p + 1, *p, true, NULL); if (*s != *p) { emsg(_(e_invalpat)); goto sortend; @@ -1709,7 +1709,7 @@ void print_line(linenr_T lnum, int use_number, int list) int save_silent = silent_mode; // apply :filter /pat/ - if (message_filtered(ml_get(lnum))) { + if (message_filtered((char *)ml_get(lnum))) { return; } @@ -3546,7 +3546,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T which_pat = RE_LAST; // use last used regexp delimiter = (char_u)(*cmd++); // remember delimiter character pat = cmd; // remember start of search pat - cmd = (char *)skip_regexp((char_u *)cmd, delimiter, p_magic, &eap->arg); + cmd = skip_regexp(cmd, delimiter, p_magic, &eap->arg); if (cmd[0] == delimiter) { // end delimiter found *cmd++ = NUL; // replace it with a NUL has_second_delim = true; @@ -4631,7 +4631,7 @@ void ex_global(exarg_T *eap) delim = *cmd; // get the delimiter cmd++; // skip delimiter if there is one pat = cmd; // remember start of pattern - cmd = (char *)skip_regexp((char_u *)cmd, delim, p_magic, &eap->arg); + cmd = skip_regexp(cmd, delim, p_magic, &eap->arg); if (cmd[0] == delim) { // end delimiter found *cmd++ = NUL; // replace it with a NUL } @@ -4948,7 +4948,7 @@ char *skip_vimgrep_pat(char *p, char **s, int *flags) *s = p + 1; } c = (char_u)(*p); - p = (char *)skip_regexp((char_u *)p + 1, c, true, NULL); + p = skip_regexp(p + 1, c, true, NULL); if (*p != c) { return NULL; } @@ -4993,7 +4993,7 @@ void ex_oldfiles(exarg_T *eap) } nr++; const char *fname = tv_get_string(TV_LIST_ITEM_TV(li)); - if (!message_filtered((char_u *)fname)) { + if (!message_filtered((char *)fname)) { msg_outnum(nr); msg_puts(": "); msg_outtrans((char *)tv_get_string(TV_LIST_ITEM_TV(li))); diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 206fd515e3..3cd4369107 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -851,8 +851,8 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) || getline_equal(fgetline, cookie, get_func_line)) && ex_nesting_level + 1 <= debug_break_level) { do_debug(getline_equal(fgetline, cookie, getsourceline) - ? (char_u *)_("End of sourced file") - : (char_u *)_("End of function")); + ? _("End of sourced file") + : _("End of function")); } } @@ -3310,7 +3310,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int goto error; } if (skip) { // skip "/pat/" - cmd = (char *)skip_regexp((char_u *)cmd, c, p_magic, NULL); + cmd = skip_regexp(cmd, c, p_magic, NULL); if (*cmd == c) { cmd++; } @@ -4295,7 +4295,7 @@ int ends_excmd(int c) FUNC_ATTR_CONST /// @return the next command, after the first '|' or '\n' or, /// NULL if not found. -char_u *find_nextcmd(const char_u *p) +char *find_nextcmd(const char *p) { while (*p != '|' && *p != '\n') { if (*p == NUL) { @@ -4303,7 +4303,7 @@ char_u *find_nextcmd(const char_u *p) } p++; } - return (char_u *)p + 1; + return (char *)p + 1; } /// Check if *p is a separator between Ex commands, skipping over white space. @@ -5499,7 +5499,7 @@ bool changedir_func(char *new_dir, CdScope scope) if (*new_dir == NUL && p_cdh) { #endif // Use NameBuff for home directory name. - expand_env((char_u *)"$HOME", (char_u *)NameBuff, MAXPATHL); + expand_env("$HOME", NameBuff, MAXPATHL); new_dir = (char *)NameBuff; } @@ -6454,7 +6454,7 @@ static void ex_findpat(exarg_T *eap) if (*eap->arg == '/') { // Match regexp, not just whole words whole = false; eap->arg++; - char *p = (char *)skip_regexp((char_u *)eap->arg, '/', p_magic, NULL); + char *p = skip_regexp(eap->arg, '/', p_magic, NULL); if (*p) { *p++ = NUL; p = skipwhite(p); diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 19dcc06825..e2b02929d2 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -1333,10 +1333,10 @@ void ex_catch(exarg_T *eap) if (ends_excmd(*eap->arg)) { // no argument, catch all errors pat = ".*"; end = NULL; - eap->nextcmd = (char *)find_nextcmd((char_u *)eap->arg); + eap->nextcmd = find_nextcmd(eap->arg); } else { pat = eap->arg + 1; - end = (char *)skip_regexp((char_u *)pat, *eap->arg, true, NULL); + end = skip_regexp(pat, *eap->arg, true, NULL); } if (!give_up) { @@ -1439,7 +1439,7 @@ void ex_catch(exarg_T *eap) } if (end != NULL) { - eap->nextcmd = (char *)find_nextcmd((char_u *)end); + eap->nextcmd = find_nextcmd(end); } } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 0cca4b69e8..ec2672c675 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -315,7 +315,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s p = skipwhite(p); delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; *search_delim = delim; - end = (char *)skip_regexp((char_u *)p, delim, p_magic, NULL); + end = skip_regexp(p, delim, p_magic, NULL); use_last_pat = end == p && *end == delim; if (end == p && !use_last_pat) { diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index b873388473..450c608fad 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2024,7 +2024,7 @@ void prep_exarg(exarg_T *eap, const buf_T *buf) snprintf(eap->cmd, cmd_len, "e ++enc=%s", buf->b_p_fenc); eap->force_enc = 8; eap->bad_char = buf->b_bad_char; - eap->force_ff = *buf->b_p_ff; + eap->force_ff = (unsigned char)(*buf->b_p_ff); eap->force_bin = buf->b_p_bin ? FORCE_BIN : FORCE_NOBIN; eap->read_edit = false; @@ -5317,7 +5317,7 @@ static void vim_mktempdir(void) mode_t umask_save = umask(0077); for (size_t i = 0; i < ARRAY_SIZE(temp_dirs); i++) { // Expand environment variables, leave room for "/tmp/nvim./XXXXXX/999999999". - expand_env((char_u *)temp_dirs[i], (char_u *)tmp, TEMP_FILE_PATH_MAXLEN - 64); + expand_env((char *)temp_dirs[i], tmp, TEMP_FILE_PATH_MAXLEN - 64); if (!os_isdir((char_u *)tmp)) { continue; } diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 574eba9bdd..af3895b793 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1302,7 +1302,7 @@ void openscript(char_u *name, bool directly) curscript++; } // use NameBuff for expanded name - expand_env(name, (char_u *)NameBuff, MAXPATHL); + expand_env((char *)name, NameBuff, MAXPATHL); int error; if ((scriptin[curscript] = file_open_new(&error, (char *)NameBuff, kFileReadOnly, 0)) == NULL) { diff --git a/src/nvim/grid.c b/src/nvim/grid.c index c805c238c6..329adfda12 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -125,7 +125,7 @@ void grid_putchar(ScreenGrid *grid, int c, int row, int col, int attr) char buf[MB_MAXBYTES + 1]; buf[utf_char2bytes(c, buf)] = NUL; - grid_puts(grid, (char_u *)buf, row, col, attr); + grid_puts(grid, buf, row, col, attr); } /// get a single character directly from grid.chars into "bytes[]". @@ -148,7 +148,7 @@ void grid_getbytes(ScreenGrid *grid, int row, int col, char_u *bytes, int *attrp /// attributes 'attr', and update chars[] and attrs[]. /// Note: only outputs within one row, message is truncated at grid boundary! /// Note: if grid, row and/or col is invalid, nothing is done. -void grid_puts(ScreenGrid *grid, char_u *text, int row, int col, int attr) +void grid_puts(ScreenGrid *grid, char *text, int row, int col, int attr) { grid_puts_len(grid, text, -1, row, col, attr); } @@ -187,10 +187,10 @@ void grid_put_schar(ScreenGrid *grid, int row, int col, char_u *schar, int attr) /// like grid_puts(), but output "text[len]". When "len" is -1 output up to /// a NUL. -void grid_puts_len(ScreenGrid *grid, char_u *text, int textlen, int row, int col, int attr) +void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, int attr) { size_t off; - char_u *ptr = text; + char *ptr = text; int len = textlen; int c; size_t max_off; @@ -237,13 +237,13 @@ void grid_puts_len(ScreenGrid *grid, char_u *text, int textlen, int row, int col while (col < grid->cols && (len < 0 || (int)(ptr - text) < len) && *ptr != NUL) { - c = *ptr; + c = (unsigned char)(*ptr); // check if this is the first byte of a multibyte mbyte_blen = len > 0 - ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) - : utfc_ptr2len((char *)ptr); + ? utfc_ptr2len_len((char_u *)ptr, (int)((text + len) - ptr)) + : utfc_ptr2len(ptr); u8c = len >= 0 - ? utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr)) + ? utfc_ptr2char_len((char_u *)ptr, u8cc, (int)((text + len) - ptr)) : utfc_ptr2char(ptr, u8cc); mbyte_cells = utf_char2cells(u8c); if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) { @@ -254,7 +254,8 @@ void grid_puts_len(ScreenGrid *grid, char_u *text, int textlen, int row, int col nc1 = NUL; } else { nc = len >= 0 - ? utfc_ptr2char_len(ptr + mbyte_blen, pcc, (int)((text + len) - ptr - mbyte_blen)) + ? utfc_ptr2char_len((char_u *)ptr + mbyte_blen, pcc, + (int)((text + len) - ptr - mbyte_blen)) : utfc_ptr2char(ptr + mbyte_blen, pcc); nc1 = pcc[0]; } @@ -320,7 +321,7 @@ void grid_puts_len(ScreenGrid *grid, char_u *text, int textlen, int row, int col ptr += mbyte_blen; if (clear_next_cell) { // This only happens at the end, display one space next. - ptr = (char_u *)" "; + ptr = " "; len = -1; } } @@ -393,11 +394,11 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int // double wide-char clear out the right half. Only needed in a // terminal. if (start_col > 0 && grid_fix_col(grid, start_col, row) != start_col) { - grid_puts_len(grid, (char_u *)" ", 1, row, start_col - 1, 0); + grid_puts_len(grid, " ", 1, row, start_col - 1, 0); } if (end_col < grid->cols && grid_fix_col(grid, end_col, row) != end_col) { - grid_puts_len(grid, (char_u *)" ", 1, row, end_col, 0); + grid_puts_len(grid, " ", 1, row, end_col, 0); } // if grid was resized (in ext_multigrid mode), the UI has no redraw updates diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 6f98e25f56..6e424f2fd6 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -613,7 +613,7 @@ static void prt_message(char_u *s) { // TODO(bfredl): delete this grid_fill(&default_grid, Rows - 1, Rows, 0, Columns, ' ', ' ', 0); - grid_puts(&default_grid, s, Rows - 1, 0, HL_ATTR(HLF_R)); + grid_puts(&default_grid, (char *)s, Rows - 1, 0, HL_ATTR(HLF_R)); ui_flush(); } @@ -2147,17 +2147,14 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) char_u *p; int props; int cmap = 0; - char_u *p_encoding; struct prt_ps_encoding_S *p_mbenc; struct prt_ps_encoding_S *p_mbenc_first; struct prt_ps_charset_S *p_mbchar = NULL; - /* - * Set up font and encoding. - */ - p_encoding = enc_skip((char_u *)p_penc); + // Set up font and encoding. + char_u *p_encoding = (char_u *)enc_skip(p_penc); if (*p_encoding == NUL) { - p_encoding = enc_skip((char_u *)p_enc); + p_encoding = (char_u *)enc_skip(p_enc); } // Look for a multi-byte font that matches the encoding and character set. @@ -2591,13 +2588,13 @@ bool mch_print_begin(prt_settings_T *psettings) // that cannot be found then default to "latin1". // Note: VIM specific encoding header is always skipped. if (!prt_out_mbyte) { - p_encoding = (char *)enc_skip((char_u *)p_penc); + p_encoding = enc_skip(p_penc); if (*p_encoding == NUL || !prt_find_resource(p_encoding, &res_encoding)) { // 'printencoding' not set or not supported - find alternate int props; - p_encoding = (char *)enc_skip((char_u *)p_enc); + p_encoding = enc_skip(p_enc); props = enc_canon_props((char_u *)p_encoding); if (!(props & ENC_8BIT) || !prt_find_resource(p_encoding, &res_encoding)) { @@ -2617,9 +2614,9 @@ bool mch_print_begin(prt_settings_T *psettings) // For the moment there are no checks on encoding resource files to // perform } else { - p_encoding = (char *)enc_skip((char_u *)p_penc); + p_encoding = enc_skip(p_penc); if (*p_encoding == NUL) { - p_encoding = (char *)enc_skip((char_u *)p_enc); + p_encoding = enc_skip(p_enc); } if (prt_use_courier) { // Include ASCII range encoding vector @@ -2639,7 +2636,7 @@ bool mch_print_begin(prt_settings_T *psettings) prt_conv.vc_type = CONV_NONE; if (!(enc_canon_props((char_u *)p_enc) & enc_canon_props((char_u *)p_encoding) & ENC_8BIT)) { // Set up encoding conversion if required - if (convert_setup(&prt_conv, (char_u *)p_enc, (char_u *)p_encoding) == FAIL) { + if (convert_setup(&prt_conv, p_enc, p_encoding) == FAIL) { semsg(_("E620: Unable to convert to print encoding \"%s\""), p_encoding); return false; diff --git a/src/nvim/help.c b/src/nvim/help.c index 4b2b113437..b25fabca48 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -803,8 +803,8 @@ void fix_help_buffer(void) // 'encoding' may be required. vc.vc_type = CONV_NONE; convert_setup(&vc, - (char_u *)(this_utf == kTrue ? "utf-8" : "latin1"), - (char_u *)p_enc); + (this_utf == kTrue ? "utf-8" : "latin1"), + p_enc); if (vc.vc_type == CONV_NONE) { // No conversion needed. cp = (char *)IObuff; diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index a63768a8e3..e2d4a81345 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -1421,7 +1421,7 @@ static void highlight_list_one(const int id) const HlGroup *sgp = &hl_table[id - 1]; // index is ID minus one bool didh = false; - if (message_filtered(sgp->sg_name)) { + if (message_filtered((char *)sgp->sg_name)) { return; } diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 50ec444d51..975fa0ca92 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -423,7 +423,7 @@ static int cs_add_common(char *arg1, char *arg2, char *flags) // get the filename (arg1), expand it, and try to stat it fname = xmalloc(MAXPATHL + 1); - expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL); + expand_env(arg1, fname, MAXPATHL); size_t len = STRLEN(fname); fbuf = fname; (void)modify_fname(":p", false, &usedlen, &fname, &fbuf, &len); @@ -445,7 +445,7 @@ staterr: // get the prepend path (arg2), expand it, and see if it exists if (arg2 != NULL) { ppath = xmalloc(MAXPATHL + 1); - expand_env((char_u *)arg2, (char_u *)ppath, MAXPATHL); + expand_env(arg2, ppath, MAXPATHL); if (!os_path_exists((char_u *)ppath)) { goto staterr; } @@ -757,14 +757,14 @@ err_closing: #endif // expand the cscope exec for env var's prog = xmalloc(MAXPATHL + 1); - expand_env((char_u *)p_csprg, (char_u *)prog, MAXPATHL); + expand_env(p_csprg, prog, MAXPATHL); // alloc space to hold the cscope command size_t len = strlen(prog) + strlen(csinfo[i].fname) + 32; if (csinfo[i].ppath) { // expand the prepend path for env var's ppath = xmalloc(MAXPATHL + 1); - expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL); + expand_env(csinfo[i].ppath, ppath, MAXPATHL); len += strlen(ppath); } diff --git a/src/nvim/indent.c b/src/nvim/indent.c index c983de6d5e..792f4d93c4 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -343,7 +343,7 @@ int get_sts_value(void) // Count the size (in window cells) of the indent in the current line. int get_indent(void) { - return get_indent_str_vtab(get_cursor_line_ptr(), + return get_indent_str_vtab((char *)get_cursor_line_ptr(), curbuf->b_p_ts, curbuf->b_p_vts_array, false); @@ -352,7 +352,7 @@ int get_indent(void) // Count the size (in window cells) of the indent in line "lnum". int get_indent_lnum(linenr_T lnum) { - return get_indent_str_vtab(ml_get(lnum), + return get_indent_str_vtab((char *)ml_get(lnum), curbuf->b_p_ts, curbuf->b_p_vts_array, false); @@ -362,7 +362,7 @@ int get_indent_lnum(linenr_T lnum) // "buf". int get_indent_buf(buf_T *buf, linenr_T lnum) { - return get_indent_str_vtab(ml_get_buf(buf, lnum, false), + return get_indent_str_vtab((char *)ml_get_buf(buf, lnum, false), curbuf->b_p_ts, buf->b_p_vts_array, false); @@ -400,7 +400,7 @@ int get_indent_str(const char_u *ptr, int ts, bool list) /// Count the size (in window cells) of the indent in line "ptr", using /// variable tabstops. /// if "list" is true, count only screen size for tabs. -int get_indent_str_vtab(const char_u *ptr, long ts, long *vts, bool list) +int get_indent_str_vtab(const char *ptr, long ts, long *vts, bool list) { int count = 0; @@ -800,7 +800,7 @@ int get_breakindent_win(win_T *wp, char_u *line) prev_ts = wp->w_buffer->b_p_ts; prev_tick = buf_get_changedtick(wp->w_buffer); prev_vts = wp->w_buffer->b_p_vts_array; - prev_indent = get_indent_str_vtab(line, + prev_indent = get_indent_str_vtab((char *)line, wp->w_buffer->b_p_ts, wp->w_buffer->b_p_vts_array, wp->w_p_list); diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 128eea915d..8ef6667374 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -212,16 +212,14 @@ int is_pos_in_string(const char_u *line, colnr_T col) * Below "XXX" means that this function may unlock the current line. */ -/* - * Return true if the string "line" starts with a word from 'cinwords'. - */ -bool cin_is_cinword(const char_u *line) +/// @return true if the string "line" starts with a word from 'cinwords'. +bool cin_is_cinword(const char *line) { bool retval = false; size_t cinw_len = STRLEN(curbuf->b_p_cinw) + 1; char_u *cinw_buf = xmalloc(cinw_len); - line = (char_u *)skipwhite((char *)line); + line = skipwhite((char *)line); for (char *cinw = curbuf->b_p_cinw; *cinw;) { size_t len = copy_option_part(&cinw, (char *)cinw_buf, cinw_len, ","); @@ -2021,7 +2019,7 @@ int get_c_indent(void) if (trypos == NULL && curwin->w_cursor.lnum > 1) { // There may be a statement before the comment, search from the end // of the line for a comment start. - linecomment_pos.col = check_linecomment(ml_get(curwin->w_cursor.lnum - 1)); + linecomment_pos.col = check_linecomment((char *)ml_get(curwin->w_cursor.lnum - 1)); if (linecomment_pos.col != MAXCOL) { trypos = &linecomment_pos; trypos->lnum = curwin->w_cursor.lnum - 1; @@ -2854,7 +2852,7 @@ int get_c_indent(void) if (n) { amount = n; l = after_label(get_cursor_line_ptr()); - if (l != NULL && cin_is_cinword(l)) { + if (l != NULL && cin_is_cinword((char *)l)) { if (theline[0] == '{') { amount += curbuf->b_ind_open_extra; } else { @@ -3108,7 +3106,7 @@ int get_c_indent(void) * Check if we are after an "if", "while", etc. * Also allow " } else". */ - if (cin_is_cinword(l) || cin_iselse((char_u *)skipwhite((char *)l))) { + if (cin_is_cinword((char *)l) || cin_iselse((char_u *)skipwhite((char *)l))) { // Found an unterminated line after an if (), line up // with the last one. // if (cond) diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 981a8d42a6..3c32d0755e 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -1732,7 +1732,7 @@ void ins_compl_addleader(int c) utf_char2bytes(c, (char *)buf); buf[cc] = NUL; - ins_char_bytes((char_u *)buf, (size_t)cc); + ins_char_bytes(buf, (size_t)cc); } else { ins_char(c); } @@ -2014,7 +2014,7 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) const int compl_len = get_compl_len(); const int len = (int)STRLEN(p); if (len > compl_len) { - ins_bytes_len(p + compl_len, (size_t)(len - compl_len)); + ins_bytes_len((char *)p + compl_len, (size_t)(len - compl_len)); } } retval = true; diff --git a/src/nvim/log.c b/src/nvim/log.c index 99b17a612b..9f25543be7 100644 --- a/src/nvim/log.c +++ b/src/nvim/log.c @@ -60,7 +60,7 @@ static bool log_try_create(char *fname) static void log_path_init(void) { size_t size = sizeof(log_file_path); - expand_env((char_u *)"$" ENV_LOGFILE, (char_u *)log_file_path, (int)size - 1); + expand_env("$" ENV_LOGFILE, log_file_path, (int)size - 1); if (strequal("$" ENV_LOGFILE, log_file_path) || log_file_path[0] == '\0' || os_isdir((char_u *)log_file_path) diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 0d08817285..7e8dda6ca1 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -494,8 +494,8 @@ static int nlua_iconv(lua_State *lstate) size_t str_len = 0; const char *str = lua_tolstring(lstate, 1, &str_len); - char_u *from = (char_u *)enc_canonize((char *)enc_skip((char_u *)lua_tolstring(lstate, 2, NULL))); - char_u *to = (char_u *)enc_canonize((char *)enc_skip((char_u *)lua_tolstring(lstate, 3, NULL))); + char_u *from = (char_u *)enc_canonize(enc_skip((char *)lua_tolstring(lstate, 2, NULL))); + char_u *to = (char_u *)enc_canonize(enc_skip((char *)lua_tolstring(lstate, 3, NULL))); vimconv_T vimconv; vimconv.vc_type = CONV_NONE; diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 2364a388b3..333fb847f6 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -150,8 +150,8 @@ static void showmap(mapblock_T *mp, bool local) { size_t len = 1; - if (message_filtered(mp->m_keys) && message_filtered((char_u *)mp->m_str) - && (mp->m_desc == NULL || message_filtered((char_u *)mp->m_desc))) { + if (message_filtered((char *)mp->m_keys) && message_filtered(mp->m_str) + && (mp->m_desc == NULL || message_filtered(mp->m_desc))) { return; } diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 883371c5fb..92a7c7c4b0 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -674,7 +674,7 @@ static void fname2fnum(xfmark_T *fm) )) { int len; - expand_env((char_u *)"~/", (char_u *)NameBuff, MAXPATHL); + expand_env("~/", NameBuff, MAXPATHL); len = (int)STRLEN(NameBuff); STRLCPY(NameBuff + len, fm->fname + 2, MAXPATHL - len); } else { @@ -911,7 +911,7 @@ static void show_one_mark(int c, char_u *arg, pos_T *p, char_u *name_arg, int cu name = mark_line(p, 15); mustfree = true; } - if (!message_filtered(name)) { + if (!message_filtered((char *)name)) { if (!did_title) { // Highlight title msg_puts_title(_("\nmark line col file/text")); @@ -1037,7 +1037,7 @@ void ex_jumps(exarg_T *eap) name = vim_strsave((char_u *)"-invalid-"); } // apply :filter /pat/ or file name not available - if (name == NULL || message_filtered(name)) { + if (name == NULL || message_filtered((char *)name)) { xfree(name); continue; } diff --git a/src/nvim/match.c b/src/nvim/match.c index 31fa35d84b..cabd008591 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -1194,7 +1194,7 @@ void ex_match(exarg_T *eap) semsg(_(e_invarg2), eap->arg); return; } - end = skip_regexp(p + 1, *p, true, NULL); + end = (char_u *)skip_regexp((char *)p + 1, *p, true, NULL); if (!eap->skip) { if (*end != NUL && !ends_excmd(*skipwhite((char *)end + 1))) { xfree(g); @@ -1215,5 +1215,5 @@ void ex_match(exarg_T *eap) *end = (char_u)c; } } - eap->nextcmd = (char *)find_nextcmd(end); + eap->nextcmd = find_nextcmd((char *)end); } diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index dab6c8fbd3..e703280032 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -754,21 +754,19 @@ bool utf_composinglike(const char_u *p1, const char_u *p2) /// space at least for #MAX_MCO + 1 elements. /// /// @return leading character. -int utfc_ptr2char(const char_u *p, int *pcc) +int utfc_ptr2char(const char *p_in, int *pcc) { - int len; - int c; - int cc; + uint8_t *p = (uint8_t *)p_in; int i = 0; - c = utf_ptr2char((char *)p); - len = utf_ptr2len((char *)p); + int c = utf_ptr2char((char *)p); + int len = utf_ptr2len((char *)p); // Only accept a composing char when the first char isn't illegal. if ((len > 1 || *p < 0x80) && p[len] >= 0x80 && utf_composinglike(p, p + len)) { - cc = utf_ptr2char((char *)p + len); + int cc = utf_ptr2char((char *)p + len); for (;;) { pcc[i++] = cc; if (i == MAX_MCO) { @@ -1936,7 +1934,7 @@ void utf_find_illegal(void) // 'encoding' is "utf-8" but we are editing a 8-bit encoded file, // possibly a utf-8 file with illegal bytes. Setup for conversion // from utf-8 to 'fileencoding'. - convert_setup(&vimconv, (char_u *)p_enc, (char_u *)curbuf->b_p_fenc); + convert_setup(&vimconv, p_enc, curbuf->b_p_fenc); } curwin->w_cursor.coladd = 0; @@ -2146,10 +2144,8 @@ const char *mb_unescape(const char **const pp) return NULL; } -/* - * Skip the Vim specific head of a 'encoding' name. - */ -char_u *enc_skip(char_u *p) +/// Skip the Vim specific head of a 'encoding' name. +char *enc_skip(char *p) { if (STRNCMP(p, "2byte-", 6) == 0) { return p + 6; @@ -2169,8 +2165,6 @@ char *enc_canonize(char *enc) FUNC_ATTR_NONNULL_RET { char_u *p, *s; - int i; - if (STRCMP(enc, "default") == 0) { // Use the default encoding as found by set_init_1(). return (char *)vim_strsave(fenc_default); @@ -2190,7 +2184,7 @@ char *enc_canonize(char *enc) *p = NUL; // Skip "2byte-" and "8bit-". - p = enc_skip(r); + p = (char_u *)enc_skip((char *)r); // Change "microsoft-cp" to "cp". Used in some spell files. if (STRNCMP(p, "microsoft-cp", 12) == 0) { @@ -2214,6 +2208,7 @@ char *enc_canonize(char *enc) STRMOVE(p + 5, p + 6); } + int i; if (enc_canon_search(p) >= 0) { // canonical name can be used unmodified if (p != r) { @@ -2332,7 +2327,7 @@ void *my_iconv_open(char_u *to, char_u *from) if (iconv_working == kBroken) { return (void *)-1; // detected a broken iconv() previously } - fd = iconv_open((char *)enc_skip(to), (char *)enc_skip(from)); + fd = iconv_open(enc_skip((char *)to), enc_skip((char *)from)); if (fd != (iconv_t)-1 && iconv_working == kUnknown) { /* @@ -2443,18 +2438,17 @@ static char_u *iconv_string(const vimconv_T *const vcp, char_u *str, size_t slen #endif // HAVE_ICONV -/* - * Setup "vcp" for conversion from "from" to "to". - * The names must have been made canonical with enc_canonize(). - * vcp->vc_type must have been initialized to CONV_NONE. - * Note: cannot be used for conversion from/to ucs-2 and ucs-4 (will use utf-8 - * instead). - * Afterwards invoke with "from" and "to" equal to NULL to cleanup. - * Return FAIL when conversion is not supported, OK otherwise. - */ -int convert_setup(vimconv_T *vcp, char_u *from, char_u *to) +/// Setup "vcp" for conversion from "from" to "to". +/// The names must have been made canonical with enc_canonize(). +/// vcp->vc_type must have been initialized to CONV_NONE. +/// Note: cannot be used for conversion from/to ucs-2 and ucs-4 (will use utf-8 +/// instead). +/// Afterwards invoke with "from" and "to" equal to NULL to cleanup. +/// +/// @return FAIL when conversion is not supported, OK otherwise. +int convert_setup(vimconv_T *vcp, char *from, char *to) { - return convert_setup_ext(vcp, from, true, to, true); + return convert_setup_ext(vcp, (char_u *)from, true, (char_u *)to, true); } /// As convert_setup(), but only when from_unicode_is_utf8 is true will all diff --git a/src/nvim/memline.c b/src/nvim/memline.c index ee90ae6b15..b940040c45 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -922,11 +922,9 @@ void ml_recover(bool checkext) b0p = hp->bh_data; } - /* - * If .swp file name given directly, use name from swap file for buffer. - */ + // If .swp file name given directly, use name from swap file for buffer. if (directly) { - expand_env(b0p->b0_fname, (char_u *)NameBuff, MAXPATHL); + expand_env((char *)b0p->b0_fname, NameBuff, MAXPATHL); if (setfname(curbuf, (char *)NameBuff, NULL, true) == FAIL) { goto theend; } @@ -1873,7 +1871,7 @@ errorret: // when the GUI redraws part of the text. recursive++; get_trans_bufname(buf); - shorten_dir((char_u *)NameBuff); + shorten_dir(NameBuff); siemsg(_("E316: ml_get: cannot find line %" PRId64 " in buffer %d %s"), (int64_t)lnum, buf->b_fnum, NameBuff); recursive--; @@ -3472,7 +3470,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ // Symlinks may point to the same file even // when the name differs, need to check the // inode too. - expand_env(b0.b0_fname, (char_u *)NameBuff, MAXPATHL); + expand_env((char *)b0.b0_fname, NameBuff, MAXPATHL); if (fnamecmp_ino((char_u *)buf->b_ffname, (char_u *)NameBuff, char_to_long(b0.b0_ino))) { differ = true; @@ -3481,7 +3479,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ } else { // The name in the swap file may be // "~user/path/file". Expand it first. - expand_env(b0.b0_fname, (char_u *)NameBuff, MAXPATHL); + expand_env((char *)b0.b0_fname, NameBuff, MAXPATHL); if (fnamecmp_ino((char_u *)buf->b_ffname, (char_u *)NameBuff, char_to_long(b0.b0_ino))) { differ = true; diff --git a/src/nvim/message.c b/src/nvim/message.c index fbf9c9b603..7b198371c5 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -305,7 +305,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) // Skip messages not match ":filter pattern". // Don't filter when there is an error. - if (!emsg_on_display && message_filtered((char_u *)s)) { + if (!emsg_on_display && message_filtered((char *)s)) { return true; } @@ -1990,7 +1990,7 @@ static char_u *screen_puts_mbyte(char_u *s, int l, int attr) return s; } - grid_puts_len(&msg_grid_adj, s, l, msg_row, msg_col, attr); + grid_puts_len(&msg_grid_adj, (char *)s, l, msg_row, msg_col, attr); if (cmdmsg_rl) { msg_col -= cw; if (msg_col == 0) { @@ -2353,13 +2353,13 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs /// @return true when ":filter pattern" was used and "msg" does not match /// "pattern". -bool message_filtered(char_u *msg) +bool message_filtered(char *msg) { if (cmdmod.cmod_filter_regmatch.regprog == NULL) { return false; } - bool match = vim_regexec(&cmdmod.cmod_filter_regmatch, (char *)msg, (colnr_T)0); + bool match = vim_regexec(&cmdmod.cmod_filter_regmatch, msg, (colnr_T)0); return cmdmod.cmod_filter_force ? match : !match; } @@ -2703,8 +2703,7 @@ static void t_puts(int *t_col, const char_u *t_s, const char_u *s, int attr) attr = hl_combine_attr(HL_ATTR(HLF_MSG), attr); // Output postponed text. msg_didout = true; // Remember that line is not empty. - grid_puts_len(&msg_grid_adj, (char_u *)t_s, (int)(s - t_s), msg_row, msg_col, - attr); + grid_puts_len(&msg_grid_adj, (char *)t_s, (int)(s - t_s), msg_row, msg_col, attr); msg_col += *t_col; *t_col = 0; // If the string starts with a composing character don't increment the @@ -3083,10 +3082,9 @@ void msg_moremsg(int full) char_u *s = (char_u *)_("-- More --"); attr = hl_combine_attr(HL_ATTR(HLF_MSG), HL_ATTR(HLF_M)); - grid_puts(&msg_grid_adj, s, Rows - 1, 0, attr); + grid_puts(&msg_grid_adj, (char *)s, Rows - 1, 0, attr); if (full) { - grid_puts(&msg_grid_adj, (char_u *) - _(" SPACE/d/j: screen/page/line down, b/u/k: up, q: quit "), + grid_puts(&msg_grid_adj, _(" SPACE/d/j: screen/page/line down, b/u/k: up, q: quit "), Rows - 1, vim_strsize((char *)s), attr); } } diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 8c5b1a033c..6430070f1b 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2718,8 +2718,6 @@ void clear_showcmd(void) /// @return true if output has been written (and setcursor() has been called). bool add_to_showcmd(int c) { - char_u *p; - int i; static int ignore[] = { K_IGNORE, K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, K_MOUSEMOVE, @@ -2742,14 +2740,14 @@ bool add_to_showcmd(int c) // Ignore keys that are scrollbar updates and mouse clicks if (IS_SPECIAL(c)) { - for (i = 0; ignore[i] != 0; i++) { + for (int i = 0; ignore[i] != 0; i++) { if (ignore[i] == c) { return false; } } } - p = transchar(c); + char *p = (char *)transchar(c); if (*p == ' ') { STRCPY(p, "<20>"); } @@ -2845,12 +2843,12 @@ static void display_showcmd(void) grid_puts_line_start(&msg_grid_adj, showcmd_row); if (!showcmd_is_clear) { - grid_puts(&msg_grid_adj, showcmd_buf, showcmd_row, sc_col, + grid_puts(&msg_grid_adj, (char *)showcmd_buf, showcmd_row, sc_col, HL_ATTR(HLF_MSG)); } // clear the rest of an old message by outputting up to SHOWCMD_COLS spaces - grid_puts(&msg_grid_adj, (char_u *)" " + len, showcmd_row, + grid_puts(&msg_grid_adj, (char *)" " + len, showcmd_row, sc_col + len, HL_ATTR(HLF_MSG)); grid_puts_line_flush(false); @@ -4392,8 +4390,7 @@ static void nv_ident(cmdarg_T *cap) init_history(); add_to_history(HIST_SEARCH, (char_u *)buf, true, NUL); - (void)normal_search(cap, cmdchar == '*' ? '/' : '?', (char_u *)buf, 0, - NULL); + (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0, NULL); } else { g_tag_at_cursor = true; do_cmdline_cmd(buf); @@ -4813,7 +4810,7 @@ static void nv_search(cmdarg_T *cap) return; } - (void)normal_search(cap, cap->cmdchar, (char_u *)cap->searchbuf, + (void)normal_search(cap, cap->cmdchar, cap->searchbuf, (cap->arg || !equalpos(save_cursor, curwin->w_cursor)) ? 0 : SEARCH_MARK, NULL); } @@ -4842,9 +4839,8 @@ static void nv_next(cmdarg_T *cap) /// @param opt extra flags for do_search() /// /// @return 0 for failure, 1 for found, 2 for found and line offset added. -static int normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt, int *wrapped) +static int normal_search(cmdarg_T *cap, int dir, char *pat, int opt, int *wrapped) { - int i; searchit_arg_T sia; cap->oap->motion_type = kMTCharWise; @@ -4853,8 +4849,8 @@ static int normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt, int *wrap curwin->w_set_curswant = true; CLEAR_FIELD(sia); - i = do_search(cap->oap, dir, dir, pat, cap->count1, - opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, &sia); + int i = do_search(cap->oap, dir, dir, (char_u *)pat, cap->count1, + opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, &sia); if (wrapped != NULL) { *wrapped = sia.sa_wrapped; } @@ -5625,7 +5621,7 @@ static MarkMoveRes nv_mark_move_to(cmdarg_T *cap, MarkMove flags, fmark_T *fm) /// Handle commands that are operators in Visual mode. static void v_visop(cmdarg_T *cap) { - static char_u trans[] = "YyDdCcxdXdAAIIrr"; + static char trans[] = "YyDdCcxdXdAAIIrr"; // Uppercase means linewise, except in block mode, then "D" deletes till // the end of the line, and "C" replaces till EOL @@ -5637,7 +5633,7 @@ static void v_visop(cmdarg_T *cap) curwin->w_curswant = MAXCOL; } } - cap->cmdchar = (uint8_t)(*(vim_strchr((char *)trans, cap->cmdchar) + 1)); + cap->cmdchar = (uint8_t)(*(vim_strchr(trans, cap->cmdchar) + 1)); nv_operator(cap); } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 092487fd3e..7b6f9e6370 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3839,7 +3839,7 @@ void ex_display(exarg_T *eap) bool do_show = false; for (size_t j = 0; !do_show && j < yb->y_size; j++) { - do_show = !message_filtered((char_u *)yb->y_array[j]); + do_show = !message_filtered(yb->y_array[j]); } if (do_show || yb->y_size == 0) { @@ -3876,14 +3876,14 @@ void ex_display(exarg_T *eap) // display last inserted text if ((p = get_last_insert()) != NULL && (arg == NULL || vim_strchr((char *)arg, '.') != NULL) && !got_int - && !message_filtered(p)) { + && !message_filtered((char *)p)) { msg_puts("\n c \". "); dis_msg(p, true); } // display last command line if (last_cmdline != NULL && (arg == NULL || vim_strchr((char *)arg, ':') != NULL) - && !got_int && !message_filtered((char_u *)last_cmdline)) { + && !got_int && !message_filtered(last_cmdline)) { msg_puts("\n c \": "); dis_msg((char_u *)last_cmdline, false); } @@ -3891,7 +3891,7 @@ void ex_display(exarg_T *eap) // display current file name if (curbuf->b_fname != NULL && (arg == NULL || vim_strchr((char *)arg, '%') != NULL) && !got_int - && !message_filtered((char_u *)curbuf->b_fname)) { + && !message_filtered(curbuf->b_fname)) { msg_puts("\n c \"% "); dis_msg((char_u *)curbuf->b_fname, false); } @@ -3901,7 +3901,7 @@ void ex_display(exarg_T *eap) char *fname; linenr_T dummy; - if (buflist_name_nr(0, &fname, &dummy) != FAIL && !message_filtered((char_u *)fname)) { + if (buflist_name_nr(0, &fname, &dummy) != FAIL && !message_filtered(fname)) { msg_puts("\n c \"# "); dis_msg((char_u *)fname, false); } @@ -3910,14 +3910,14 @@ void ex_display(exarg_T *eap) // display last search pattern if (last_search_pat() != NULL && (arg == NULL || vim_strchr((char *)arg, '/') != NULL) && !got_int - && !message_filtered(last_search_pat())) { + && !message_filtered((char *)last_search_pat())) { msg_puts("\n c \"/ "); dis_msg(last_search_pat(), false); } // display last used expression if (expr_line != NULL && (arg == NULL || vim_strchr((char *)arg, '=') != NULL) - && !got_int && !message_filtered(expr_line)) { + && !got_int && !message_filtered((char *)expr_line)) { msg_puts("\n c \"= "); dis_msg(expr_line, false); } @@ -4802,7 +4802,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } *ptr = NUL; STRCAT(buf1, buf2); - ins_str(buf1); // insert the new number + ins_str((char *)buf1); // insert the new number endpos = curwin->w_cursor; if (curwin->w_cursor.col) { curwin->w_cursor.col--; diff --git a/src/nvim/option.c b/src/nvim/option.c index c3f803e543..f9b32d50af 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3299,7 +3299,7 @@ static void showoptions(int all, int opt_flags) item_count = 0; for (p = &options[0]; p->fullname != NULL; p++) { // apply :filter /pat/ - if (message_filtered((char_u *)p->fullname)) { + if (message_filtered(p->fullname)) { continue; } diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index ea9a803a86..274e13e3c6 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -553,9 +553,9 @@ char_u *expand_env_save_opt(char_u *src, bool one) /// @param src Input string e.g. "$HOME/vim.hlp" /// @param dst[out] Where to put the result /// @param dstlen Maximum length of the result -void expand_env(char_u *src, char_u *dst, int dstlen) +void expand_env(char *src, char *dst, int dstlen) { - expand_env_esc(src, dst, dstlen, false, false, NULL); + expand_env_esc((char_u *)src, (char_u *)dst, dstlen, false, false, NULL); } /// Expand environment variable with path name and escaping. diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 0d62a5f5f9..dc96c39d25 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -911,7 +911,7 @@ int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_di // We're done when it's "/" or "c:/". const size_t dirlen = strlen(dir); char *const curdir = xmemdupz(dir, dirlen); - char *const past_head = (char *)get_past_head((char_u *)curdir); + char *const past_head = get_past_head(curdir); char *e = curdir + dirlen; const char *const real_end = e; const char past_head_save = *past_head; diff --git a/src/nvim/path.c b/src/nvim/path.c index d786ccbf73..e40729b114 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -62,7 +62,7 @@ FileComparison path_full_compare(char *const s1, char *const s2, const bool chec FileID file_id_1, file_id_2; if (expandenv) { - expand_env((char_u *)s1, (char_u *)exp1, MAXPATHL); + expand_env(s1, exp1, MAXPATHL); } else { STRLCPY(exp1, s1, MAXPATHL); } @@ -104,7 +104,7 @@ char *path_tail(const char *fname) return ""; } - const char *tail = (char *)get_past_head((char_u *)fname); + const char *tail = get_past_head(fname); const char *p = tail; // Find last part of path. while (*p != NUL) { @@ -130,7 +130,7 @@ char *path_tail_with_sep(char *fname) assert(fname != NULL); // Don't remove the '/' from "c:/file". - char *past_head = (char *)get_past_head((char_u *)fname); + char *past_head = get_past_head(fname); char *tail = path_tail(fname); while (tail > past_head && after_pathsep(fname, tail)) { tail--; @@ -150,7 +150,7 @@ char *path_tail_with_sep(char *fname) const char_u *invocation_path_tail(const char_u *invocation, size_t *len) FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ARG(1) { - const char_u *tail = get_past_head((char_u *)invocation); + const char_u *tail = (char_u *)get_past_head((char *)invocation); const char_u *p = tail; while (*p != NUL && *p != ' ') { bool was_sep = vim_ispathsep_nocolon(*p); @@ -215,13 +215,13 @@ bool is_path_head(const char_u *path) /// Get a pointer to one character past the head of a path name. /// Unix: after "/"; Win: after "c:\" /// If there is no head, path is returned. -char_u *get_past_head(const char_u *path) +char *get_past_head(const char *path) { - const char_u *retval = path; + const char *retval = path; #ifdef WIN32 // May skip "c:" - if (is_path_head(path)) { + if (is_path_head((char_u *)path)) { retval = path + 2; } #endif @@ -230,7 +230,7 @@ char_u *get_past_head(const char_u *path) retval++; } - return (char_u *)retval; + return (char *)retval; } /// Return true if 'c' is a path separator. @@ -310,9 +310,9 @@ void shorten_dir_len(char_u *str, int trim_len) /// Shorten the path of a file from "~/foo/../.bar/fname" to "~/f/../.b/fname" /// It's done in-place. -void shorten_dir(char_u *str) +void shorten_dir(char *str) { - shorten_dir_len(str, 1); + shorten_dir_len((char_u *)str, 1); } /// Return true if the directory of "fname" exists, false otherwise. @@ -631,7 +631,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, while (*path_end != NUL) { /* May ignore a wildcard that has a backslash before it; it will * be removed by rem_backslash() or file_pat_to_reg_pat() below. */ - if (path_end >= path + wildoff && rem_backslash(path_end)) { + if (path_end >= path + wildoff && rem_backslash((char *)path_end)) { *p++ = *path_end++; } else if (vim_ispathsep_nocolon(*path_end)) { if (e != NULL) { @@ -658,7 +658,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, /* Remove backslashes between "wildoff" and the start of the wildcard * component. */ for (p = buf + wildoff; p < s; p++) { - if (rem_backslash(p)) { + if (rem_backslash((char *)p)) { STRMOVE(p, p + 1); e--; s--; diff --git a/src/nvim/plines.c b/src/nvim/plines.c index f13e83ca9b..11b6951edd 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -233,7 +233,7 @@ int win_chartabsize(win_T *wp, char *p, colnr_T col) if (*p == TAB && (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) { return tabstop_padding(col, buf->b_p_ts, buf->b_p_vts_array); } else { - return ptr2cells((char *)p); + return ptr2cells(p); } } diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 529e351f33..b144348188 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -542,14 +542,13 @@ void pum_redraw(void) size++; } } - grid_puts_len(&pum_grid, (char_u *)rt, (int)STRLEN(rt), row, - grid_col - size + 1, attr); + grid_puts_len(&pum_grid, rt, (int)STRLEN(rt), row, grid_col - size + 1, attr); xfree(rt_start); xfree(st); grid_col -= width; } else { // use grid_puts_len() to truncate the text - grid_puts(&pum_grid, st, row, grid_col, attr); + grid_puts(&pum_grid, (char *)st, row, grid_col, attr); xfree(st); grid_col += width; } @@ -560,11 +559,11 @@ void pum_redraw(void) // Display two spaces for a Tab. if (pum_rl) { - grid_puts_len(&pum_grid, (char_u *)" ", 2, row, grid_col - 1, + grid_puts_len(&pum_grid, " ", 2, row, grid_col - 1, attr); grid_col -= 2; } else { - grid_puts_len(&pum_grid, (char_u *)" ", 2, row, grid_col, attr); + grid_puts_len(&pum_grid, " ", 2, row, grid_col, attr); grid_col += 2; } totwidth += 2; diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 53bb17364e..20e6893ea5 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -1000,7 +1000,7 @@ static int qf_setup_state(qfstate_T *pstate, char *restrict enc, const char *res { pstate->vc.vc_type = CONV_NONE; if (enc != NULL && *enc != NUL) { - convert_setup(&pstate->vc, (char_u *)enc, (char_u *)p_enc); + convert_setup(&pstate->vc, enc, p_enc); } if (efile != NULL @@ -1244,7 +1244,7 @@ static int qf_parse_fmt_f(regmatch_T *rmp, int midx, qffields_T *fields, int pre // Expand ~/file and $HOME/file to full path. char c = (char)(*rmp->endp[midx]); *rmp->endp[midx] = NUL; - expand_env(rmp->startp[midx], (char_u *)fields->namebuf, CMDBUFFSIZE); + expand_env((char *)rmp->startp[midx], fields->namebuf, CMDBUFFSIZE); *rmp->endp[midx] = (char_u)c; // For separate filename patterns (%O, %P and %Q), the specified file @@ -3038,16 +3038,16 @@ static void qf_list_entry(qfline_T *qfp, int qf_idx, bool cursel) // text of the entry. bool filter_entry = true; if (qfp->qf_module != NULL && *qfp->qf_module != NUL) { - filter_entry &= message_filtered((char_u *)qfp->qf_module); + filter_entry &= message_filtered(qfp->qf_module); } if (filter_entry && fname != NULL) { - filter_entry &= message_filtered((char_u *)fname); + filter_entry &= message_filtered(fname); } if (filter_entry && qfp->qf_pattern != NULL) { - filter_entry &= message_filtered((char_u *)qfp->qf_pattern); + filter_entry &= message_filtered(qfp->qf_pattern); } if (filter_entry) { - filter_entry &= message_filtered((char_u *)qfp->qf_text); + filter_entry &= message_filtered(qfp->qf_text); } if (filter_entry) { return; diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 75bd7b4cc1..a52343e28b 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -488,10 +488,10 @@ static char_u *skip_anyof(char *p) /// When "newp" is not NULL and "dirc" is '?', make an allocated copy of the /// expression and change "\?" to "?". If "*newp" is not NULL the expression /// is changed in-place. -char_u *skip_regexp(char_u *startp, int dirc, int magic, char **newp) +char *skip_regexp(char *startp, int dirc, int magic, char **newp) { int mymagic; - char_u *p = startp; + char *p = startp; if (magic) { mymagic = MAGIC_ON; @@ -506,7 +506,7 @@ char_u *skip_regexp(char_u *startp, int dirc, int magic, char **newp) } if ((p[0] == '[' && mymagic >= MAGIC_ON) || (p[0] == '\\' && p[1] == '[' && mymagic <= MAGIC_OFF)) { - p = skip_anyof((char *)p + 1); + p = (char *)skip_anyof(p + 1); if (p[0] == NUL) { break; } @@ -514,8 +514,8 @@ char_u *skip_regexp(char_u *startp, int dirc, int magic, char **newp) if (dirc == '?' && newp != NULL && p[1] == '?') { // change "\?" to "?", make a copy first. if (*newp == NULL) { - *newp = (char *)vim_strsave(startp); - p = (char_u *)(*newp) + (p - startp); + *newp = xstrdup(startp); + p = *newp + (p - startp); } STRMOVE(p, p + 1); } else { diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 25f85b6193..41056a2773 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -815,15 +815,21 @@ static void source_all_matches(char *pat) /// @param is_pack whether the added dir is a "pack/*/start/*/" style package static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) { - char_u *p4, *p3, *p2, *p1, *p; - char_u *buf = NULL; + char *p; + char *buf = NULL; char *afterdir = NULL; int retval = FAIL; - p4 = p3 = p2 = p1 = get_past_head(fname); + char *p1 = get_past_head((char *)fname); + char *p2 = p1; + char *p3 = p1; + char *p4 = p1; for (p = p1; *p; MB_PTR_ADV(p)) { if (vim_ispathsep_nocolon(*p)) { - p4 = p3; p3 = p2; p2 = p1; p1 = p; + p4 = p3; + p3 = p2; + p2 = p1; + p1 = p; } } @@ -833,7 +839,7 @@ static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) // // find the part up to "pack" in 'runtimepath' p4++; // append pathsep in order to expand symlink - char_u c = *p4; + char c = *p4; *p4 = NUL; char *const ffname = fix_fname((char *)fname); *p4 = c; @@ -854,10 +860,10 @@ static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) for (const char *entry = (const char *)p_rtp; *entry != NUL;) { const char *cur_entry = entry; - copy_option_part((char **)&entry, (char *)buf, MAXPATHL, ","); + copy_option_part((char **)&entry, buf, MAXPATHL, ","); if (insp == NULL) { - add_pathsep((char *)buf); - char *const rtp_ffname = fix_fname((char *)buf); + add_pathsep(buf); + char *const rtp_ffname = fix_fname(buf); if (rtp_ffname == NULL) { goto theend; } @@ -869,7 +875,7 @@ static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) } } - if ((p = (char_u *)strstr((char *)buf, "after")) != NULL + if ((p = strstr(buf, "after")) != NULL && p > buf && vim_ispathsep(p[-1]) && (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ',')) { @@ -2018,7 +2024,7 @@ int do_source(char *fname, int check_other, int is_vimrc) if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef && firstline[1] == 0xbb && firstline[2] == 0xbf) { // Found BOM; setup conversion, skip over BOM and recode the line. - convert_setup(&cookie.conv, (char_u *)"utf-8", (char_u *)p_enc); + convert_setup(&cookie.conv, "utf-8", p_enc); p = (char *)string_convert(&cookie.conv, (char_u *)firstline + 3, NULL); if (p == NULL) { p = xstrdup((char *)firstline + 3); @@ -2149,7 +2155,7 @@ void ex_scriptnames(exarg_T *eap) if (SCRIPT_ITEM(i).sn_name != NULL) { home_replace(NULL, (char *)SCRIPT_ITEM(i).sn_name, (char *)NameBuff, MAXPATHL, true); vim_snprintf((char *)IObuff, IOSIZE, "%3d: %s", i, NameBuff); - if (!message_filtered(IObuff)) { + if (!message_filtered((char *)IObuff)) { msg_putchar('\n'); msg_outtrans((char *)IObuff); line_breakcheck(); @@ -2439,7 +2445,7 @@ void ex_scriptencoding(exarg_T *eap) // Setup for conversion from the specified encoding to 'encoding'. sp = (struct source_cookie *)getline_cookie(eap->getline, eap->cookie); - convert_setup(&sp->conv, (char_u *)name, (char_u *)p_enc); + convert_setup(&sp->conv, name, p_enc); if (name != eap->arg) { xfree(name); diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 3258dc11d6..6efaae3725 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -277,7 +277,7 @@ static int wildmenu_match_len(expand_T *xp, char_u *s) /// These are backslashes used for escaping. Do show backslashes in help tags. static int skip_wildmenu_char(expand_T *xp, char_u *s) { - if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) + if ((rem_backslash((char *)s) && xp->xp_context != EXPAND_HELP) || ((xp->xp_context == EXPAND_MENUS || xp->xp_context == EXPAND_MENUNAMES) && (s[0] == '\t' @@ -469,10 +469,10 @@ void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int match, i ScreenGrid *grid = (wild_menu_showing == WM_SCROLLED) ? &msg_grid_adj : &default_grid; - grid_puts(grid, buf, row, 0, attr); + grid_puts(grid, (char *)buf, row, 0, attr); if (selstart != NULL && highlight) { *selend = NUL; - grid_puts(grid, selstart, row, selstart_col, HL_ATTR(HLF_WM)); + grid_puts(grid, (char *)selstart, row, selstart_col, HL_ATTR(HLF_WM)); } grid_fill(grid, row, row + 1, clen, Columns, @@ -1026,12 +1026,12 @@ void draw_tabline(void) if (col + len >= Columns - 3) { break; } - grid_puts_len(&default_grid, (char_u *)NameBuff, len, 0, col, + grid_puts_len(&default_grid, NameBuff, len, 0, col, hl_combine_attr(attr, win_hl_attr(cwp, HLF_T))); col += len; } if (modified) { - grid_puts_len(&default_grid, (char_u *)"+", 1, 0, col++, attr); + grid_puts_len(&default_grid, "+", 1, 0, col++, attr); } grid_putchar(&default_grid, ' ', 0, col++, attr); } @@ -1040,7 +1040,7 @@ void draw_tabline(void) if (room > 0) { // Get buffer name in NameBuff[] get_trans_bufname(cwp->w_buffer); - shorten_dir((char_u *)NameBuff); + shorten_dir(NameBuff); len = vim_strsize((char *)NameBuff); p = (char_u *)NameBuff; while (len > room) { @@ -1051,7 +1051,7 @@ void draw_tabline(void) len = Columns - col - 1; } - grid_puts_len(&default_grid, p, (int)STRLEN(p), 0, col, attr); + grid_puts_len(&default_grid, (char *)p, (int)STRLEN(p), 0, col, attr); col += len; } grid_putchar(&default_grid, ' ', 0, col++, attr); diff --git a/src/nvim/search.c b/src/nvim/search.c index 892d531633..c1c2f0dbe9 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1124,7 +1124,7 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, * If there is a matching '/' or '?', toss it. */ ps = (char_u *)strcopy; - p = skip_regexp(pat, search_delim, p_magic, &strcopy); + p = (char_u *)skip_regexp((char *)pat, search_delim, p_magic, &strcopy); if (strcopy != (char *)ps) { // made a copy of "pat" to change "\?" to "?" searchcmdlen += (int)(STRLEN(pat) - STRLEN(strcopy)); @@ -1977,7 +1977,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) // backward search: Check if this line contains a single-line comment if ((backwards && comment_dir) || lisp) { - comment_col = check_linecomment(linep); + comment_col = check_linecomment((char *)linep); } if (lisp && comment_col != MAXCOL && pos.col > (colnr_T)comment_col) { lispcomm = true; // find match inside this comment @@ -2010,7 +2010,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) // Check if this line contains a single-line comment if (comment_dir || lisp) { - comment_col = check_linecomment(linep); + comment_col = check_linecomment((char *)linep); } // skip comment if (lisp && comment_col != MAXCOL) { @@ -2043,7 +2043,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) do_quotes = -1; line_breakcheck(); if (lisp) { // find comment pos in new line - comment_col = check_linecomment(linep); + comment_col = check_linecomment((char *)linep); } } else { pos.col += utfc_ptr2len((char *)linep + pos.col); @@ -2301,15 +2301,15 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) /// Check if line[] contains a / / comment. /// @returns MAXCOL if not, otherwise return the column. -int check_linecomment(const char_u *line) +int check_linecomment(const char *line) { - const char_u *p = line; // scan from start + const char *p = line; // scan from start // skip Lispish one-line comments if (curbuf->b_p_lisp) { if (vim_strchr((char *)p, ';') != NULL) { // there may be comments bool in_str = false; // inside of string - while ((p = (char_u *)strpbrk((char *)p, "\";")) != NULL) { + while ((p = strpbrk((char *)p, "\";")) != NULL) { if (*p == '"') { if (in_str) { if (*(p - 1) != '\\') { // skip escaped quote @@ -2322,7 +2322,7 @@ int check_linecomment(const char_u *line) } } else if (!in_str && ((p - line) < 2 || (*(p - 1) != '\\' && *(p - 2) != '#')) - && !is_pos_in_string(line, (colnr_T)(p - line))) { + && !is_pos_in_string((char_u *)line, (colnr_T)(p - line))) { break; // found! } p++; @@ -2331,12 +2331,12 @@ int check_linecomment(const char_u *line) p = NULL; } } else { - while ((p = (char_u *)vim_strchr((char *)p, '/')) != NULL) { + while ((p = vim_strchr((char *)p, '/')) != NULL) { // Accept a double /, unless it's preceded with * and followed by *, // because * / / * is an end and start of a C comment. Only // accept the position if it is not inside a string. if (p[1] == '/' && (p == line || p[-1] != '*' || p[2] != '*') - && !is_pos_in_string(line, (colnr_T)(p - line))) { + && !is_pos_in_string((char_u *)line, (colnr_T)(p - line))) { break; } p++; @@ -3536,7 +3536,6 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo int i; char_u *already = NULL; char_u *startp = NULL; - char_u *inc_opt = NULL; win_T *curwin_save = NULL; const int l_g_do_tagpreview = g_do_tagpreview; @@ -3561,9 +3560,9 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo goto fpip_end; } } - inc_opt = (*curbuf->b_p_inc == NUL) ? (char_u *)p_inc : (char_u *)curbuf->b_p_inc; + char *inc_opt = (*curbuf->b_p_inc == NUL) ? p_inc : curbuf->b_p_inc; if (*inc_opt != NUL) { - incl_regmatch.regprog = vim_regcomp((char *)inc_opt, p_magic ? RE_MAGIC : 0); + incl_regmatch.regprog = vim_regcomp(inc_opt, p_magic ? RE_MAGIC : 0); if (incl_regmatch.regprog == NULL) { goto fpip_end; } @@ -3597,7 +3596,7 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo char_u *p_fname = (curr_fname == (char_u *)curbuf->b_fname) ? (char_u *)curbuf->b_ffname : curr_fname; - if (inc_opt != NULL && strstr((char *)inc_opt, "\\zs") != NULL) { + if (inc_opt != NULL && strstr(inc_opt, "\\zs") != NULL) { // Use text from '\zs' to '\ze' (or end) of 'include'. new_fname = find_file_name_in_path(incl_regmatch.startp[0], (size_t)(incl_regmatch.endp[0] @@ -3674,7 +3673,7 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo * Include the surrounding "" or <> if present. */ if (inc_opt != NULL - && strstr((char *)inc_opt, "\\zs") != NULL) { + && strstr(inc_opt, "\\zs") != NULL) { // pattern contains \zs, use the match p = incl_regmatch.startp[0]; i = (int)(incl_regmatch.endp[0] diff --git a/src/nvim/shada.c b/src/nvim/shada.c index b45a041d96..88ad7d519a 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1477,7 +1477,7 @@ static char *shada_filename(const char *file) // because various expansions must have already be done by the shell. // If shell is not performing them then they should be done in main.c // where arguments are parsed, *not here*. - expand_env((char_u *)file, (char_u *)&(NameBuff[0]), MAXPATHL); + expand_env((char *)file, &(NameBuff[0]), MAXPATHL); file = (const char *)&(NameBuff[0]); } } diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 8d6307f123..33e8c5c099 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -2042,7 +2042,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } vim_snprintf((char *)IObuff, IOSIZE, _("Reading affix file %s..."), fname); - spell_message(spin, IObuff); + spell_message(spin, (char *)IObuff); // Only do REP lines when not done in another .aff file already. do_rep = GA_EMPTY(&spin->si_rep); @@ -2123,7 +2123,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // Setup for conversion from "ENC" to 'encoding'. aff->af_enc = (char_u *)enc_canonize((char *)items[1]); if (!spin->si_ascii - && convert_setup(&spin->si_conv, aff->af_enc, (char_u *)p_enc) == FAIL) { + && convert_setup(&spin->si_conv, (char *)aff->af_enc, p_enc) == FAIL) { smsg(_("Conversion in %s not supported: from %s to %s"), fname, aff->af_enc, p_enc); } @@ -3123,7 +3123,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) vim_snprintf((char *)IObuff, IOSIZE, _("Reading dictionary file %s..."), fname); - spell_message(spin, IObuff); + spell_message(spin, (char *)IObuff); // start with a message for the first line spin->si_msg_count = 999999; @@ -3676,7 +3676,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) } vim_snprintf((char *)IObuff, IOSIZE, _("Reading word file %s..."), fname); - spell_message(spin, IObuff); + spell_message(spin, (char *)IObuff); // Read all the lines in the file one by one. while (!vim_fgets(rline, MAXLINELEN, fd) && !got_int) { @@ -3723,13 +3723,13 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) smsg(_("/encoding= line after word ignored in %s line %ld: %s"), fname, lnum, line - 1); } else { - char_u *enc; + char *enc; // Setup for conversion to 'encoding'. line += 9; - enc = (char_u *)enc_canonize((char *)line); + enc = enc_canonize((char *)line); if (!spin->si_ascii - && convert_setup(&spin->si_conv, enc, (char_u *)p_enc) == FAIL) { + && convert_setup(&spin->si_conv, enc, p_enc) == FAIL) { smsg(_("Conversion in %s not supported: from %s to %s"), fname, line, p_enc); } @@ -3820,7 +3820,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) if (spin->si_ascii && non_ascii > 0) { vim_snprintf((char *)IObuff, IOSIZE, _("Ignored %d words with non-ASCII characters"), non_ascii); - spell_message(spin, IObuff); + spell_message(spin, (char *)IObuff); } return retval; @@ -3894,13 +3894,13 @@ static wordnode_T *wordtree_alloc(spellinfo_T *spin) /// Return true if "word" contains valid word characters. /// Control characters and trailing '/' are invalid. Space is OK. -static bool valid_spell_word(const char_u *word, const char_u *end) +static bool valid_spell_word(const char *word, const char *end) { - if (!utf_valid_string(word, end)) { + if (!utf_valid_string((char_u *)word, (char_u *)end)) { return false; } - for (const char_u *p = word; *p != NUL && p < end; p += utfc_ptr2len((const char *)p)) { - if (*p < ' ' || (p[0] == '/' && p[1] == NUL)) { + for (const char *p = word; *p != NUL && p < end; p += utfc_ptr2len(p)) { + if ((uint8_t)(*p) < ' ' || (p[0] == '/' && p[1] == NUL)) { return false; } } @@ -3928,7 +3928,7 @@ static int store_word(spellinfo_T *spin, char_u *word, int flags, int region, co int res = OK; // Avoid adding illegal bytes to the word tree. - if (!valid_spell_word(word, word + len)) { + if (!valid_spell_word((char *)word, (char *)word + len)) { return FAIL; } @@ -4213,7 +4213,7 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n vim_snprintf((char *)IObuff, IOSIZE, _("Compressed %s of %ld nodes; %ld (%ld%%) remaining"), name, tot, tot - n, perc); - spell_message(spin, IObuff); + spell_message(spin, (char *)IObuff); } #ifdef SPELL_PRINTTREE spell_print_tree(root->wn_sibling); @@ -4347,14 +4347,15 @@ static int rep_compare(const void *s1, const void *s2) return STRCMP(p1->ft_from, p2->ft_from); } -// Write the Vim .spl file "fname". -// Return OK/FAIL. -static int write_vim_spell(spellinfo_T *spin, char_u *fname) +/// Write the Vim .spl file "fname". +/// +/// @return OK/FAIL. +static int write_vim_spell(spellinfo_T *spin, char *fname) { int retval = OK; int regionmask; - FILE *fd = os_fopen((char *)fname, "w"); + FILE *fd = os_fopen(fname, "w"); if (fd == NULL) { semsg(_(e_notopen), fname); return FAIL; @@ -4893,7 +4894,7 @@ void ex_mkspell(exarg_T *eap) // Create the .sug file. // Uses the soundfold info in "spin". // Writes the file with the name "wfname", with ".spl" changed to ".sug". -static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname) +static void spell_make_sugfile(spellinfo_T *spin, char *wfname) { char_u *fname = NULL; int len; @@ -4906,14 +4907,14 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname) // of the code for the soundfolding stuff. // It might have been done already by spell_reload_one(). for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare((char *)wfname, (char *)slang->sl_fname, false, true) + if (path_full_compare(wfname, (char *)slang->sl_fname, false, true) == kEqualFiles) { break; } } if (slang == NULL) { - spell_message(spin, (char_u *)_("Reading back spell file...")); - slang = spell_load_file(wfname, NULL, NULL, false); + spell_message(spin, _("Reading back spell file...")); + slang = spell_load_file((char_u *)wfname, NULL, NULL, false); if (slang == NULL) { return; } @@ -4930,7 +4931,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname) // Go through the trie of good words, soundfold each word and add it to // the soundfold trie. - spell_message(spin, (char_u *)_("Performing soundfolding...")); + spell_message(spin, _("Performing soundfolding...")); if (sug_filltree(spin, slang) == FAIL) { goto theend; } @@ -4947,7 +4948,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname) (int64_t)spin->si_spellbuf->b_ml.ml_line_count); // Compress the soundfold trie. - spell_message(spin, (char_u *)_(msg_compressing)); + spell_message(spin, _(msg_compressing)); wordtree_compress(spin, spin->si_foldroot, "case-folded"); // Write the .sug file. @@ -5193,7 +5194,7 @@ static void sug_write(spellinfo_T *spin, char_u *fname) vim_snprintf((char *)IObuff, IOSIZE, _("Writing suggestion file %s..."), fname); - spell_message(spin, IObuff); + spell_message(spin, (char *)IObuff); // : if (fwrite(VIMSUGMAGIC, VIMSUGMAGICL, (size_t)1, fd) != 1) { // @@ -5249,7 +5250,7 @@ static void sug_write(spellinfo_T *spin, char_u *fname) vim_snprintf((char *)IObuff, IOSIZE, _("Estimated runtime memory use: %d bytes"), spin->si_memtot); - spell_message(spin, IObuff); + spell_message(spin, (char *)IObuff); theend: // close the file @@ -5268,7 +5269,6 @@ theend: static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool added_word) { char_u *fname = NULL; - char_u *wfname; char **innames; int incount; afffile_T *(afile[MAXREGIONS]); @@ -5296,7 +5296,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool innames = &fnames[fcount == 1 ? 0 : 1]; incount = fcount - 1; - wfname = xmalloc(MAXPATHL); + char *wfname = xmalloc(MAXPATHL); if (fcount >= 1) { len = (int)STRLEN(fnames[0]); @@ -5304,46 +5304,46 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool // For ":mkspell path/en.latin1.add" output file is // "path/en.latin1.add.spl". incount = 1; - vim_snprintf((char *)wfname, MAXPATHL, "%s.spl", fnames[0]); + vim_snprintf(wfname, MAXPATHL, "%s.spl", fnames[0]); } else if (fcount == 1) { // For ":mkspell path/vim" output file is "path/vim.latin1.spl". incount = 1; - vim_snprintf((char *)wfname, MAXPATHL, SPL_FNAME_TMPL, + vim_snprintf(wfname, MAXPATHL, SPL_FNAME_TMPL, fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); } else if (len > 4 && STRCMP(fnames[0] + len - 4, ".spl") == 0) { // Name ends in ".spl", use as the file name. STRLCPY(wfname, fnames[0], MAXPATHL); } else { // Name should be language, make the file name from it. - vim_snprintf((char *)wfname, MAXPATHL, SPL_FNAME_TMPL, + vim_snprintf(wfname, MAXPATHL, SPL_FNAME_TMPL, fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); } // Check for .ascii.spl. - if (strstr(path_tail((char *)wfname), SPL_FNAME_ASCII) != NULL) { + if (strstr(path_tail(wfname), SPL_FNAME_ASCII) != NULL) { spin.si_ascii = true; } // Check for .add.spl. - if (strstr(path_tail((char *)wfname), SPL_FNAME_ADD) != NULL) { + if (strstr(path_tail(wfname), SPL_FNAME_ADD) != NULL) { spin.si_add = true; } } if (incount <= 0) { emsg(_(e_invarg)); // need at least output and input names - } else if (vim_strchr(path_tail((char *)wfname), '_') != NULL) { + } else if (vim_strchr(path_tail(wfname), '_') != NULL) { emsg(_("E751: Output file name must not have region name")); } else if (incount > MAXREGIONS) { semsg(_("E754: Only up to %d regions supported"), MAXREGIONS); } else { // Check for overwriting before doing things that may take a lot of // time. - if (!over_write && os_path_exists(wfname)) { + if (!over_write && os_path_exists((char_u *)wfname)) { emsg(_(e_exists)); goto theend; } - if (os_isdir(wfname)) { + if (os_isdir((char_u *)wfname)) { semsg(_(e_isadir2), wfname); goto theend; } @@ -5421,7 +5421,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool if (!error && !got_int) { // Combine tails in the tree. - spell_message(&spin, (char_u *)_(msg_compressing)); + spell_message(&spin, _(msg_compressing)); wordtree_compress(&spin, spin.si_foldroot, "case-folded"); wordtree_compress(&spin, spin.si_keeproot, "keep-case"); wordtree_compress(&spin, spin.si_prefroot, "prefixes"); @@ -5431,18 +5431,18 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool // Write the info in the spell file. vim_snprintf((char *)IObuff, IOSIZE, _("Writing spell file %s..."), wfname); - spell_message(&spin, IObuff); + spell_message(&spin, (char *)IObuff); error = write_vim_spell(&spin, wfname) == FAIL; - spell_message(&spin, (char_u *)_("Done!")); + spell_message(&spin, _("Done!")); vim_snprintf((char *)IObuff, IOSIZE, _("Estimated runtime memory use: %d bytes"), spin.si_memtot); - spell_message(&spin, IObuff); + spell_message(&spin, (char *)IObuff); // If the file is loaded need to reload it. if (!error) { - spell_reload_one(wfname, added_word); + spell_reload_one((char_u *)wfname, added_word); } } @@ -5479,14 +5479,14 @@ theend: // Display a message for spell file processing when 'verbose' is set or using // ":mkspell". "str" can be IObuff. -static void spell_message(const spellinfo_T *spin, char_u *str) +static void spell_message(const spellinfo_T *spin, char *str) FUNC_ATTR_NONNULL_ALL { if (spin->si_verbose || p_verbose > 2) { if (!spin->si_verbose) { verbose_enter(); } - msg((char *)str); + msg(str); ui_flush(); if (!spin->si_verbose) { verbose_leave(); @@ -5524,7 +5524,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo int i; char_u *spf; - if (!valid_spell_word(word, word + len)) { + if (!valid_spell_word((char *)word, (char *)word + len)) { emsg(_(e_illegal_character_in_word)); return; } diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index b9cddb7b94..9b441ba0a9 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -132,13 +132,13 @@ void win_redr_status(win_T *wp) row = is_stl_global ? (Rows - (int)p_ch - 1) : W_ENDROW(wp); col = is_stl_global ? 0 : wp->w_wincol; - grid_puts(&default_grid, p, row, col, attr); + grid_puts(&default_grid, (char *)p, row, col, attr); grid_fill(&default_grid, row, row + 1, len + col, this_ru_col + col, fillchar, fillchar, attr); if (get_keymap_str(wp, "<%s>", (char *)NameBuff, MAXPATHL) && this_ru_col - len > (int)(STRLEN(NameBuff) + 1)) { - grid_puts(&default_grid, (char_u *)NameBuff, row, + grid_puts(&default_grid, NameBuff, row, (int)((size_t)this_ru_col - STRLEN(NameBuff) - 1), attr); } @@ -342,7 +342,7 @@ void win_redr_ruler(win_T *wp, bool always) } ScreenGrid *grid = part_of_status ? &default_grid : &msg_grid_adj; - grid_puts(grid, (char_u *)buffer, row, this_ru_col + off, attr); + grid_puts(grid, buffer, row, this_ru_col + off, attr); grid_fill(grid, row, row + 1, this_ru_col + off + (int)STRLEN(buffer), off + width, fillchar, fillchar, attr); @@ -571,8 +571,8 @@ void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) p = buf; for (n = 0; hltab[n].start != NULL; n++) { int textlen = (int)(hltab[n].start - p); - grid_puts_len(grid, (char_u *)p, textlen, row, col, curattr); - col += vim_strnsize((char_u *)p, textlen); + grid_puts_len(grid, p, textlen, row, col, curattr); + col += vim_strnsize(p, textlen); p = hltab[n].start; if (hltab[n].userhl == 0) { @@ -586,8 +586,7 @@ void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) } } // Make sure to use an empty string instead of p, if p is beyond buf + len. - grid_puts(grid, p >= buf + len ? (char_u *)"" : (char_u *)p, row, col, - curattr); + grid_puts(grid, p >= buf + len ? "" : p, row, col, curattr); grid_puts_line_flush(false); @@ -608,7 +607,7 @@ void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) .type = kStlClickDisabled, }; for (n = 0; tabtab[n].start != NULL; n++) { - len += vim_strnsize((char_u *)p, (int)(tabtab[n].start - p)); + len += vim_strnsize(p, (int)(tabtab[n].start - p)); while (col < len) { click_defs[col++] = cur_click_def; } diff --git a/src/nvim/strings.c b/src/nvim/strings.c index ac9d414be2..bd0f122f99 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -104,7 +104,7 @@ char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars, c p += l - 1; continue; } - if (vim_strchr((char *)esc_chars, *p) != NULL || (bsl && rem_backslash(p))) { + if (vim_strchr((char *)esc_chars, *p) != NULL || (bsl && rem_backslash((char *)p))) { length++; // count a backslash } length++; // count an ordinary char @@ -120,7 +120,7 @@ char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars, c p += l - 1; // skip multibyte char continue; } - if (vim_strchr((char *)esc_chars, *p) != NULL || (bsl && rem_backslash(p))) { + if (vim_strchr((char *)esc_chars, *p) != NULL || (bsl && rem_backslash((char *)p))) { *p2++ = cc; } *p2++ = *p; diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 187dc4eed4..e88b1b17f6 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3008,7 +3008,7 @@ static void syn_cmd_conceal(exarg_T *eap, int syncing) char_u *arg = (char_u *)eap->arg; char_u *next; - eap->nextcmd = (char *)find_nextcmd(arg); + eap->nextcmd = find_nextcmd((char *)arg); if (eap->skip) { return; } @@ -3037,7 +3037,7 @@ static void syn_cmd_case(exarg_T *eap, int syncing) char_u *arg = (char_u *)eap->arg; char_u *next; - eap->nextcmd = (char *)find_nextcmd(arg); + eap->nextcmd = find_nextcmd((char *)arg); if (eap->skip) { return; } @@ -3064,7 +3064,7 @@ static void syn_cmd_foldlevel(exarg_T *eap, int syncing) char_u *arg = (char_u *)eap->arg; char_u *arg_end; - eap->nextcmd = (char *)find_nextcmd(arg); + eap->nextcmd = find_nextcmd((char *)arg); if (eap->skip) { return; } @@ -3105,7 +3105,7 @@ static void syn_cmd_spell(exarg_T *eap, int syncing) char_u *arg = (char_u *)eap->arg; char_u *next; - eap->nextcmd = (char *)find_nextcmd(arg); + eap->nextcmd = find_nextcmd((char *)arg); if (eap->skip) { return; } @@ -3312,7 +3312,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing) char_u *arg_end; int id; - eap->nextcmd = (char *)find_nextcmd(arg); + eap->nextcmd = find_nextcmd((char *)arg); if (eap->skip) { return; } @@ -3465,7 +3465,7 @@ static void syn_cmd_list(exarg_T *eap, int syncing) char_u *arg = (char_u *)eap->arg; char_u *arg_end; - eap->nextcmd = (char *)find_nextcmd(arg); + eap->nextcmd = find_nextcmd((char *)arg); if (eap->skip) { return; } @@ -4237,7 +4237,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing) int prev_syn_inc_tag; bool source = false; - eap->nextcmd = (char *)find_nextcmd((char_u *)arg); + eap->nextcmd = find_nextcmd(arg); if (eap->skip) { return; } @@ -4958,7 +4958,7 @@ static void syn_cmd_cluster(exarg_T *eap, int syncing) int opt_len; int list_op; - eap->nextcmd = (char *)find_nextcmd((char_u *)arg); + eap->nextcmd = find_nextcmd(arg); if (eap->skip) { return; } @@ -5042,7 +5042,7 @@ static char *get_syn_pattern(char_u *arg, synpat_T *ci) return NULL; } - end = (char *)skip_regexp(arg + 1, *arg, true, NULL); + end = skip_regexp((char *)arg + 1, *arg, true, NULL); if (*end != (char)(*arg)) { // end delimiter not found semsg(_("E401: Pattern delimiter not found: %s"), arg); return NULL; @@ -5199,7 +5199,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) finished = true; break; } - arg_end = (char *)skip_regexp(next_arg + 1, *next_arg, true, NULL); + arg_end = skip_regexp((char *)next_arg + 1, *next_arg, true, NULL); if (*arg_end != (char)(*next_arg)) { // end delimiter not found illegal = true; break; diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 50121832ba..11825ce1c4 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -1781,7 +1781,7 @@ line_read_in: // encoding to 'encoding'. for (p = lbuf + 20; *p > ' ' && *p < 127; p++) {} *p = NUL; - convert_setup(&vimconv, lbuf + 20, (char_u *)p_enc); + convert_setup(&vimconv, (char *)lbuf + 20, p_enc); } // Read the next line. Unrecognized flags are ignored. @@ -2055,8 +2055,9 @@ parse_line: mtt = MT_GL_OTH; } else { // Decide in which array to store this match. - is_current = test_for_current(tagp.fname, tagp.fname_end, tag_fname, - (char_u *)buf_ffname); + is_current = test_for_current((char *)tagp.fname, (char *)tagp.fname_end, + (char *)tag_fname, + buf_ffname); is_static = test_for_static(&tagp); // Decide in which of the sixteen tables to store this match. @@ -2826,7 +2827,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) */ str = pbuf; if (pbuf[0] == '/' || pbuf[0] == '?') { - str = skip_regexp(pbuf + 1, pbuf[0], false, NULL) + 1; + str = (char_u *)skip_regexp((char *)pbuf + 1, pbuf[0], false, NULL) + 1; } if (str > pbuf_end - 1) { // search command with nothing following save_p_ws = p_ws; @@ -3012,27 +3013,25 @@ static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, const bo return retval; } -/* - * Check if we have a tag for the buffer with name "buf_ffname". - * This is a bit slow, because of the full path compare in path_full_compare(). - * Return true if tag for file "fname" if tag file "tag_fname" is for current - * file. - */ -static int test_for_current(char_u *fname, char_u *fname_end, char_u *tag_fname, char_u *buf_ffname) +/// Check if we have a tag for the buffer with name "buf_ffname". +/// This is a bit slow, because of the full path compare in path_full_compare(). +/// +/// @return true if tag for file "fname" if tag file "tag_fname" is for current +/// file. +static int test_for_current(char *fname, char *fname_end, char *tag_fname, char *buf_ffname) { int c; int retval = false; - char_u *fullname; if (buf_ffname != NULL) { // if the buffer has a name { - c = *fname_end; + c = (unsigned char)(*fname_end); *fname_end = NUL; } - fullname = expand_tag_fname(fname, tag_fname, true); - retval = (path_full_compare((char *)fullname, (char *)buf_ffname, true, true) & kEqualFiles); + char *fullname = (char *)expand_tag_fname((char_u *)fname, (char_u *)tag_fname, true); + retval = (path_full_compare(fullname, buf_ffname, true, true) & kEqualFiles); xfree(fullname); - *fname_end = (char_u)c; + *fname_end = (char)c; } return retval; @@ -3052,7 +3051,7 @@ static int find_extra(char_u **pp) if (ascii_isdigit(*str)) { str = (char_u *)skipdigits((char *)str + 1); } else if (*str == '/' || *str == '?') { - str = skip_regexp(str + 1, *str, false, NULL); + str = (char_u *)skip_regexp((char *)str + 1, *str, false, NULL); if (*str != first_char) { str = NULL; } else { diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index b2bfca08ed..125146f712 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -121,7 +121,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on leader_len = get_leader_len((char *)line, NULL, false, true); if (leader_len == 0 && curbuf->b_p_cin) { // Check for a line comment after code. - int comment_start = check_linecomment(line); + int comment_start = check_linecomment((char *)line); if (comment_start != MAXCOL) { leader_len = get_leader_len((char *)line + comment_start, NULL, false, true); if (leader_len != 0) { @@ -411,7 +411,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on // add the additional whitespace needed after the // comment leader for the numbered list. for (int i = 0; i < padding; i++) { - ins_str((char_u *)" "); + ins_str(" "); } changed_bytes(curwin->w_cursor.lnum, leader_len); } else { @@ -1026,7 +1026,7 @@ void format_lines(linenr_T line_count, bool avoid_fex) // paragraph doesn't really end. if (next_leader_flags == NULL || STRNCMP(next_leader_flags, "://", 3) != 0 - || check_linecomment(get_cursor_line_ptr()) == MAXCOL) { + || check_linecomment((char *)get_cursor_line_ptr()) == MAXCOL) { is_end_par = true; } } diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 834aad2872..ae312de61a 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -127,7 +127,7 @@ char *find_ucmd(exarg_T *eap, char *p, int *full, expand_T *xp, int *complp) for (j = 0; j < gap->ga_len; j++) { uc = USER_CMD_GA(gap, j); cp = eap->cmd; - np = (char *)uc->uc_name; + np = uc->uc_name; k = 0; while (k < len && *np != NUL && *cp++ == *np++) { k++; @@ -167,7 +167,7 @@ char *find_ucmd(exarg_T *eap, char *p, int *full, expand_T *xp, int *complp) } if (xp != NULL) { xp->xp_luaref = uc->uc_compl_luaref; - xp->xp_arg = (char *)uc->uc_compl_arg; + xp->xp_arg = uc->uc_compl_arg; xp->xp_script_ctx = uc->uc_script_ctx; xp->xp_script_ctx.sc_lnum += SOURCING_LNUM; } @@ -272,12 +272,12 @@ char *get_user_commands(expand_T *xp FUNC_ATTR_UNUSED, int idx) const buf_T *const buf = prevwin_curwin()->w_buffer; if (idx < buf->b_ucmds.ga_len) { - return (char *)USER_CMD_GA(&buf->b_ucmds, idx)->uc_name; + return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name; } idx -= buf->b_ucmds.ga_len; if (idx < ucmds.ga_len) { - char *name = (char *)USER_CMD(idx)->uc_name; + char *name = USER_CMD(idx)->uc_name; for (int i = 0; i < buf->b_ucmds.ga_len; i++) { if (STRCMP(name, USER_CMD_GA(&buf->b_ucmds, i)->uc_name) == 0) { @@ -297,14 +297,14 @@ char *get_user_commands(expand_T *xp FUNC_ATTR_UNUSED, int idx) char *get_user_command_name(int idx, int cmdidx) { if (cmdidx == CMD_USER && idx < ucmds.ga_len) { - return (char *)USER_CMD(idx)->uc_name; + return USER_CMD(idx)->uc_name; } if (cmdidx == CMD_USER_BUF) { // In cmdwin, the alternative buffer should be used. const buf_T *const buf = prevwin_curwin()->w_buffer; if (idx < buf->b_ucmds.ga_len) { - return (char *)USER_CMD_GA(&buf->b_ucmds, idx)->uc_name; + return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name; } } return NULL; @@ -434,7 +434,7 @@ static void uc_list(char *name, size_t name_len) msg_putchar(' '); } - msg_outtrans_attr(cmd->uc_name, HL_ATTR(HLF_D)); + msg_outtrans_attr((char_u *)cmd->uc_name, HL_ATTR(HLF_D)); len = (int)STRLEN(cmd->uc_name) + 4; do { @@ -531,7 +531,7 @@ static void uc_list(char *name, size_t name_len) } } - msg_outtrans_special(cmd->uc_rep, false, + msg_outtrans_special((char_u *)cmd->uc_rep, false, name_len == 0 ? Columns - 47 : 0); if (p_verbose > 0) { last_set_msg(cmd->uc_script_ctx); @@ -883,17 +883,17 @@ int uc_add_command(char *name, size_t name_len, const char *rep, uint32_t argt, gap->ga_len++; - cmd->uc_name = (char_u *)p; + cmd->uc_name = p; } - cmd->uc_rep = (char_u *)rep_buf; + cmd->uc_rep = rep_buf; cmd->uc_argt = argt; cmd->uc_def = def; cmd->uc_compl = compl; cmd->uc_script_ctx = current_sctx; cmd->uc_script_ctx.sc_lnum += SOURCING_LNUM; nlua_set_sctx(&cmd->uc_script_ctx); - cmd->uc_compl_arg = (char_u *)compl_arg; + cmd->uc_compl_arg = compl_arg; cmd->uc_compl_luaref = compl_luaref; cmd->uc_preview_luaref = preview_luaref; cmd->uc_addr_type = addr_type; @@ -1569,7 +1569,7 @@ int do_ucmd(exarg_T *eap, bool preview) // Second round: copy result into "buf". buf = NULL; for (;;) { - p = (char *)cmd->uc_rep; // source + p = cmd->uc_rep; // source q = buf; // destination totlen = 0; diff --git a/src/nvim/usercmd.h b/src/nvim/usercmd.h index 637862b216..4d2cf0d9de 100644 --- a/src/nvim/usercmd.h +++ b/src/nvim/usercmd.h @@ -4,14 +4,14 @@ #include "nvim/ex_cmds_defs.h" typedef struct ucmd { - char_u *uc_name; // The command name + char *uc_name; // The command name uint32_t uc_argt; // The argument type - char_u *uc_rep; // The command's replacement string + char *uc_rep; // The command's replacement string long uc_def; // The default value for a range/count int uc_compl; // completion type cmd_addr_T uc_addr_type; // The command's address type sctx_T uc_script_ctx; // SCTX where the command was defined - char_u *uc_compl_arg; // completion argument if any + char *uc_compl_arg; // completion argument if any LuaRef uc_compl_luaref; // Reference to Lua completion function LuaRef uc_preview_luaref; // Reference to Lua preview function LuaRef uc_luaref; // Reference to Lua function diff --git a/src/nvim/version.c b/src/nvim/version.c index 46e3a67388..5888d4614e 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -2274,7 +2274,7 @@ void intro_message(int colon) } if (*p != NUL) { - do_intro_line(row, (char_u *)_(p), 0); + do_intro_line(row, _(p), 0); } row++; } @@ -2287,15 +2287,14 @@ void intro_message(int colon) } } -static void do_intro_line(long row, char_u *mesg, int attr) +static void do_intro_line(long row, char *mesg, int attr) { - long col; - char_u *p; + char *p; int l; int clen; // Center the message horizontally. - col = vim_strsize((char *)mesg); + long col = vim_strsize(mesg); col = (Columns - col) / 2; @@ -2310,8 +2309,8 @@ static void do_intro_line(long row, char_u *mesg, int attr) for (l = 0; p[l] != NUL && (l == 0 || (p[l] != '<' && p[l - 1] != '>')); l++) { - clen += ptr2cells((char *)p + l); - l += utfc_ptr2len((char *)p + l) - 1; + clen += ptr2cells(p + l); + l += utfc_ptr2len(p + l) - 1; } assert(row <= INT_MAX && col <= INT_MAX); grid_puts_len(&default_grid, p, l, (int)row, (int)col, diff --git a/src/nvim/window.c b/src/nvim/window.c index 5b8a69f6eb..29b1b05ade 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -215,7 +215,7 @@ newwindow: case Ctrl_Q: case 'q': reset_VIsual_and_resel(); // stop Visual mode - cmd_with_count("quit", (char_u *)cbuf, sizeof(cbuf), Prenum); + cmd_with_count("quit", cbuf, sizeof(cbuf), Prenum); do_cmdline_cmd(cbuf); break; @@ -223,7 +223,7 @@ newwindow: case Ctrl_C: case 'c': reset_VIsual_and_resel(); // stop Visual mode - cmd_with_count("close", (char_u *)cbuf, sizeof(cbuf), Prenum); + cmd_with_count("close", cbuf, sizeof(cbuf), Prenum); do_cmdline_cmd(cbuf); break; @@ -256,7 +256,7 @@ newwindow: case 'o': CHECK_CMDWIN; reset_VIsual_and_resel(); // stop Visual mode - cmd_with_count("only", (char_u *)cbuf, sizeof(cbuf), Prenum); + cmd_with_count("only", cbuf, sizeof(cbuf), Prenum); do_cmdline_cmd(cbuf); break; @@ -622,12 +622,12 @@ wingotofile: } } -static void cmd_with_count(char *cmd, char_u *bufp, size_t bufsize, int64_t Prenum) +static void cmd_with_count(char *cmd, char *bufp, size_t bufsize, int64_t Prenum) { size_t len = STRLCPY(bufp, cmd, bufsize); if (Prenum > 0 && len < bufsize) { - vim_snprintf((char *)bufp + len, bufsize - len, "%" PRId64, Prenum); + vim_snprintf(bufp + len, bufsize - len, "%" PRId64, Prenum); } } @@ -2082,7 +2082,7 @@ static int get_maximum_wincount(frame_T *fr, int height) void win_equal(win_T *next_curwin, bool current, int dir) { if (dir == 0) { - dir = *p_ead; + dir = (unsigned char)(*p_ead); } win_equal_rec(next_curwin == NULL ? curwin : next_curwin, current, topframe, dir, 0, tabline_height(), -- cgit From 8fd66ff5c57d29a4349c80d3ae769cde12357ac0 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 29 Aug 2022 21:58:07 +0200 Subject: fix(redraw): handle switching to a tabpage with larger p_ch value --- src/nvim/window.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/nvim/window.c b/src/nvim/window.c index 29b1b05ade..832cb82bda 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4343,6 +4343,11 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, bool trigger_enter_a // Use the stored value of p_ch, so that it can be different for each tab page. if (p_ch != curtab->tp_ch_used) { clear_cmdline = true; + if (msg_grid.chars && p_ch < curtab->tp_ch_used) { + // TODO(bfredl): a bit expensive, should be enough to invalidate the + // region between the old and the new p_ch. + grid_invalidate(&msg_grid); + } } p_ch = curtab->tp_ch_used; -- cgit From f58a9795990a3b324f66912e4ae33dae7eb7474d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 30 Aug 2022 06:26:06 +0800 Subject: vim-patch:9.0.0318: clearing screen causes flicker (#19993) Problem: Clearing screen causes flicker. Solution: Do not clear but redraw in more cases. Add () to "wait_return". https://github.com/vim/vim/commit/13608d851a0470ced30921428b3313c023d395d8 Only 2 lines of actual code change. --- src/nvim/ex_cmds.c | 3 ++- src/nvim/ex_cmds2.c | 2 +- src/nvim/ex_docmd.c | 4 ++-- src/nvim/getchar.c | 2 +- src/nvim/if_cscope.c | 2 +- src/nvim/input.c | 2 +- src/nvim/memline.c | 2 +- src/nvim/message.c | 12 ++++++------ src/nvim/option.c | 2 +- src/nvim/os/shell.c | 2 +- 10 files changed, 17 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 57eb2f526f..ba6594fd7a 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1347,7 +1347,8 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b msg_putchar('\n'); // Keep message from buf_write(). no_wait_return--; if (!aborting()) { - semsg(_("E482: Can't create file %s"), itmp); // Will call wait_return. + // will call wait_return() + semsg(_("E482: Can't create file %s"), itmp); } goto filterend; } diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 2ed2b5519b..11280eecbb 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -364,7 +364,7 @@ bool check_changed_any(bool hidden, bool unload) exiting = false; // When ":confirm" used, don't give an error message. if (!(p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM))) { - // There must be a wait_return for this message, do_buffer() + // There must be a wait_return() for this message, do_buffer() // may cause a redraw. But wait_return() is a no-op when vgetc() // is busy (Quit used from window menu), then make sure we don't // cause a scroll up. diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 3cd4369107..08709ec228 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -516,7 +516,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) cstack.cs_idx < 0 ? 0 : (cstack.cs_idx + 1) * 2, true)) == NULL) { - // Don't call wait_return for aborted command line. The NULL + // Don't call wait_return() for aborted command line. The NULL // returned for the end of a sourced file or executed function // doesn't do this. if (KeyTyped && !(flags & DOCMD_REPEAT)) { @@ -888,7 +888,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) need_wait_return = false; msg_didany = false; // don't wait when restarting edit } else if (need_wait_return) { - // The msg_start() above clears msg_didout. The wait_return we do + // The msg_start() above clears msg_didout. The wait_return() we do // here should not overwrite the command that may be shown before // doing that. msg_didout |= msg_didout_before_start; diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index af3895b793..bb8cd5a1eb 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1768,7 +1768,7 @@ static void getchar_common(typval_T *argvars, typval_T *rettv) if (!ui_has_messages()) { // redraw the screen after getchar() - update_screen(UPD_CLEAR); + update_screen(UPD_NOT_VALID); } set_vim_var_nr(VV_MOUSE_WIN, 0); diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 975fa0ca92..2a9d2c357e 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -2035,7 +2035,7 @@ static int cs_show(exarg_T *eap) } } - wait_return(true); + wait_return(false); return CSCOPE_SUCCESS; } diff --git a/src/nvim/input.c b/src/nvim/input.c index 37c2903cfd..0aa9feaca3 100644 --- a/src/nvim/input.c +++ b/src/nvim/input.c @@ -46,7 +46,7 @@ int ask_yesno(const char *const str, const bool direct) int r = ' '; while (r != 'y' && r != 'n') { - // Same highlighting as for wait_return. + // same highlighting as for wait_return() smsg_attr(HL_ATTR(HLF_R), "%s (y/n)?", str); if (direct) { r = get_keystroke(NULL); diff --git a/src/nvim/memline.c b/src/nvim/memline.c index b940040c45..044655ef2b 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -523,7 +523,7 @@ void ml_open_file(buf_T *buf) } if (*p_dir != NUL && mfp->mf_fname == NULL) { - need_wait_return = true; // call wait_return later + need_wait_return = true; // call wait_return() later no_wait_return++; (void)semsg(_("E303: Unable to open swap file for \"%s\", recovery impossible"), buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname); diff --git a/src/nvim/message.c b/src/nvim/message.c index 7b198371c5..4fba78feca 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -215,7 +215,7 @@ void msg_grid_validate(void) /// Displays the string 's' on the status line /// When terminal not initialized (yet) mch_errmsg(..) is used. /// -/// @return true if wait_return not called +/// @return true if wait_return() not called int msg(char *s) { return msg_attr_keep(s, 0, false, false); @@ -745,7 +745,7 @@ static bool emsg_multiline(const char *s, bool multiline) attr = HL_ATTR(HLF_E); // set highlight mode for error messages if (msg_scrolled != 0) { need_wait_return = true; // needed in case emsg() is called after - } // wait_return has reset need_wait_return + } // wait_return() has reset need_wait_return // and a redraw is expected because // msg_scrolled is non-zero if (msg_ext_kind == NULL) { @@ -766,7 +766,7 @@ static bool emsg_multiline(const char *s, bool multiline) /// Rings the bell, if appropriate, and calls message() to do the real work /// When terminal not initialized (yet) mch_errmsg(..) is used. /// -/// @return true if wait_return not called +/// @return true if wait_return() not called bool emsg(const char *s) { return emsg_multiline(s, false); @@ -2243,7 +2243,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs } inc_msg_scrolled(); - need_wait_return = true; // may need wait_return in main() + need_wait_return = true; // may need wait_return() in main() redraw_cmdline = true; if (cmdline_row > 0 && !exmode_active) { cmdline_row--; @@ -3164,9 +3164,9 @@ void msg_clr_cmdline(void) } /// end putting a message on the screen -/// call wait_return if the message does not fit in the available space +/// call wait_return() if the message does not fit in the available space /// -/// @return true if wait_return not called. +/// @return true if wait_return() not called. int msg_end(void) { /* diff --git a/src/nvim/option.c b/src/nvim/option.c index f9b32d50af..455070c742 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1553,7 +1553,7 @@ skip: // make sure all characters are printable trans_characters((char *)IObuff, IOSIZE); - no_wait_return++; // wait_return done later + no_wait_return++; // wait_return() done later emsg((char *)IObuff); // show error highlighted no_wait_return--; diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 574543b1a5..c8267ede14 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -911,7 +911,7 @@ static int do_os_system(char **argv, const char *input, size_t len, char **outpu out_data_ring(NULL, SIZE_MAX); } if (forward_output) { - // caller should decide if wait_return is invoked + // caller should decide if wait_return() is invoked no_wait_return++; msg_end(); no_wait_return--; -- cgit From 2c83d7b2ddf74966777e3bb72230a3605b92ffe2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 29 Aug 2022 15:12:30 +0800 Subject: refactor: move cmdline functions to ex_getln.c --- src/nvim/eval/funcs.c | 69 ------------------------ src/nvim/ex_getln.c | 144 +++++++++++++++++++++++++++++++------------------- 2 files changed, 91 insertions(+), 122 deletions(-) (limited to 'src') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 0bf3ad6901..c442f5c465 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2721,40 +2721,6 @@ static void f_getcharsearch(typval_T *argvars, typval_T *rettv, EvalFuncData fpt tv_dict_add_nr(dict, S_LEN("until"), last_csearch_until()); } -/// "getcmdcompltype()" function -static void f_getcmdcompltype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) -{ - rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char *)get_cmdline_completion(); -} - -/// "getcmdline()" function -static void f_getcmdline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) -{ - rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char *)get_cmdline_str(); -} - -/// "getcmdpos()" function -static void f_getcmdpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) -{ - rettv->vval.v_number = get_cmdline_pos() + 1; -} - -/// "getcmdscreenpos()" function -static void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) -{ - rettv->vval.v_number = get_cmdline_screen_pos() + 1; -} - -/// "getcmdtype()" function -static void f_getcmdtype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) -{ - rettv->v_type = VAR_STRING; - rettv->vval.v_string = xmallocz(1); - rettv->vval.v_string[0] = (char)get_cmdline_type(); -} - /// "getcmdwintype()" function static void f_getcmdwintype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { @@ -7622,41 +7588,6 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv, EvalFuncData fpt } } -/// "setcmdline()" function -static void f_setcmdline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) -{ - if (argvars[0].v_type != VAR_STRING || argvars[0].vval.v_string == NULL) { - emsg(_(e_stringreq)); - return; - } - - int pos = -1; - if (argvars[1].v_type != VAR_UNKNOWN) { - bool error = false; - - pos = (int)tv_get_number_chk(&argvars[1], &error) - 1; - if (error) { - return; - } - if (pos < 0) { - emsg(_(e_positive)); - return; - } - } - - rettv->vval.v_number = set_cmdline_str(argvars[0].vval.v_string, pos); -} - -/// "setcmdpos()" function -static void f_setcmdpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) -{ - const int pos = (int)tv_get_number(&argvars[0]) - 1; - - if (pos >= 0) { - rettv->vval.v_number = set_cmdline_pos(pos); - } -} - /// "setcursorcharpos" function static void f_setcursorcharpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index ec2672c675..7dac5fbe7e 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3933,8 +3933,41 @@ static CmdlineInfo *get_ccline_ptr(void) } } +/// Get the current command-line type. +/// Returns ':' or '/' or '?' or '@' or '>' or '-' +/// Only works when the command line is being edited. +/// Returns NUL when something is wrong. +static int get_cmdline_type(void) +{ + CmdlineInfo *p = get_ccline_ptr(); + + if (p == NULL) { + return NUL; + } + if (p->cmdfirstc == NUL) { + return (p->input_fn) ? '@' : '-'; + } + return p->cmdfirstc; +} + +/// Get the current command line in allocated memory. +/// Only works when the command line is being edited. +/// Returns NULL when something is wrong. +static char_u *get_cmdline_str(void) +{ + if (cmdline_star > 0) { + return NULL; + } + CmdlineInfo *p = get_ccline_ptr(); + + if (p == NULL) { + return NULL; + } + return vim_strnsave(p->cmdbuff, (size_t)p->cmdlen); +} + /// Get the current command-line completion type. -char_u *get_cmdline_completion(void) +static char_u *get_cmdline_completion(void) { if (cmdline_star > 0) { return NULL; @@ -3952,54 +3985,45 @@ char_u *get_cmdline_completion(void) return NULL; } -/* - * Get the current command line in allocated memory. - * Only works when the command line is being edited. - * Returns NULL when something is wrong. - */ -char_u *get_cmdline_str(void) +/// "getcmdcompltype()" function +void f_getcmdcompltype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - if (cmdline_star > 0) { - return NULL; - } - CmdlineInfo *p = get_ccline_ptr(); + rettv->v_type = VAR_STRING; + rettv->vval.v_string = (char *)get_cmdline_completion(); +} - if (p == NULL) { - return NULL; - } - return vim_strnsave(p->cmdbuff, (size_t)p->cmdlen); +/// "getcmdline()" function +void f_getcmdline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +{ + rettv->v_type = VAR_STRING; + rettv->vval.v_string = (char *)get_cmdline_str(); } -/* - * Get the current command line position, counted in bytes. - * Zero is the first position. - * Only works when the command line is being edited. - * Returns -1 when something is wrong. - */ -int get_cmdline_pos(void) +/// "getcmdpos()" function +void f_getcmdpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { CmdlineInfo *p = get_ccline_ptr(); - - if (p == NULL) { - return -1; - } - return p->cmdpos; + rettv->vval.v_number = p != NULL ? p->cmdpos + 1 : 0; } -/// Get the command line cursor screen position. -int get_cmdline_screen_pos(void) +/// "getcmdscreenpos()" function +void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { CmdlineInfo *p = get_ccline_ptr(); + rettv->vval.v_number = p != NULL ? p->cmdspos + 1 : 0; +} - if (p == NULL) { - return -1; - } - return p->cmdspos; +/// "getcmdtype()" function +void f_getcmdtype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +{ + rettv->v_type = VAR_STRING; + rettv->vval.v_string = xmallocz(1); + rettv->vval.v_string[0] = (char)get_cmdline_type(); } /// Set the command line str to "str". /// @return 1 when failed, 0 when OK. -int set_cmdline_str(const char *str, int pos) +static int set_cmdline_str(const char *str, int pos) { CmdlineInfo *p = get_ccline_ptr(); @@ -4023,12 +4047,10 @@ int set_cmdline_str(const char *str, int pos) return 0; } -/* - * Set the command line byte position to "pos". Zero is the first position. - * Only works when the command line is being edited. - * Returns 1 when failed, 0 when OK. - */ -int set_cmdline_pos(int pos) +/// Set the command line byte position to "pos". Zero is the first position. +/// Only works when the command line is being edited. +/// @return 1 when failed, 0 when OK. +static int set_cmdline_pos(int pos) { CmdlineInfo *p = get_ccline_ptr(); @@ -4046,23 +4068,39 @@ int set_cmdline_pos(int pos) return 0; } -/* - * Get the current command-line type. - * Returns ':' or '/' or '?' or '@' or '>' or '-' - * Only works when the command line is being edited. - * Returns NUL when something is wrong. - */ -int get_cmdline_type(void) +/// "setcmdline()" function +void f_setcmdline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - CmdlineInfo *p = get_ccline_ptr(); + if (argvars[0].v_type != VAR_STRING || argvars[0].vval.v_string == NULL) { + emsg(_(e_stringreq)); + return; + } - if (p == NULL) { - return NUL; + int pos = -1; + if (argvars[1].v_type != VAR_UNKNOWN) { + bool error = false; + + pos = (int)tv_get_number_chk(&argvars[1], &error) - 1; + if (error) { + return; + } + if (pos < 0) { + emsg(_(e_positive)); + return; + } } - if (p->cmdfirstc == NUL) { - return (p->input_fn) ? '@' : '-'; + + rettv->vval.v_number = set_cmdline_str(argvars[0].vval.v_string, pos); +} + +/// "setcmdpos()" function +void f_setcmdpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +{ + const int pos = (int)tv_get_number(&argvars[0]) - 1; + + if (pos >= 0) { + rettv->vval.v_number = set_cmdline_pos(pos); } - return p->cmdfirstc; } /// Return the first character of the current command line. -- cgit From e6e9879cb3eecf9d5c3f3964259a89dc36f60d52 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 30 Aug 2022 06:32:14 +0800 Subject: vim-patch:9.0.0320: command line type of CmdlineChange differs from getcmdtype() Problem: Command line type of CmdlineChange differs from getcmdtype(). Solution: Use the same type. (closes vim/vim#11005) https://github.com/vim/vim/commit/54acb90d9e672315e3bd13f8dc71f828df97c868 --- src/nvim/ex_getln.c | 2 +- src/nvim/testdir/test_cmdline.vim | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 7dac5fbe7e..66c3327ce3 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4042,7 +4042,7 @@ static int set_cmdline_str(const char *str, int pos) redrawcmd(); // Trigger CmdlineChanged autocommands. - do_autocmd_cmdlinechanged(ccline.cmdfirstc == NUL ? '-' : ccline.cmdfirstc); + do_autocmd_cmdlinechanged(get_cmdline_type()); return 0; } diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index a5a30b7953..045504b8bf 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -2187,9 +2187,13 @@ endfunc func Test_setcmdline() func SetText(text, pos) + autocmd CmdlineChanged * let g:cmdtype = expand('') call assert_equal(0, setcmdline(a:text)) call assert_equal(a:text, getcmdline()) call assert_equal(len(a:text) + 1, getcmdpos()) + call assert_equal(getcmdtype(), g:cmdtype) + unlet g:cmdtype + autocmd! CmdlineChanged call assert_equal(0, setcmdline(a:text, a:pos)) call assert_equal(a:text, getcmdline()) @@ -2205,6 +2209,13 @@ func Test_setcmdline() call feedkeys(":\=SetText('set rtp?', 2)\\", 'xt') call assert_equal('set rtp?', @:) + call feedkeys(":let g:str = input('? ')\", 't') + call feedkeys("\=SetText('foo', 4)\\", 'xt') + call assert_equal('foo', g:str) + unlet g:str + + delfunc SetText + " setcmdline() returns 1 when not editing the command line. call assert_equal(1, 'foo'->setcmdline()) @@ -2217,6 +2228,8 @@ func Test_setcmdline() com! -nargs=* -complete=custom,CustomComplete DoCmd : call feedkeys(":DoCmd \\\"\", 'tx') call assert_equal('"DoCmd January February Mars', @:) + delcom DoCmd + delfunc CustomComplete " Called in cnoremap a setcmdline('let foo=') -- cgit From 568737d5b39a4b58cab05d4edc2599653979770c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 30 Aug 2022 10:55:00 +0800 Subject: feat(tui): recognize sidescroll events (#19992) Ref https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Other-buttons This works in xterm and kitty. CSI < 66 ; x ; y M sequence is for ScrollWheelLeft. CSI < 67 ; x ; y M sequence is for ScrollWheelRight. --- src/nvim/tui/input.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 03cfb830e6..d269878f46 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -398,6 +398,14 @@ static void forward_mouse_event(TermInput *input, TermKeyKey *key) button = last_pressed_button; } + if (ev == TERMKEY_MOUSE_UNKNOWN && !(key->code.mouse[0] & 0x20)) { + int code = key->code.mouse[0] & ~0x3c; + if (code == 66 || code == 67) { + ev = TERMKEY_MOUSE_PRESS; + button = code - 60; + } + } + if (button == 0 || (ev != TERMKEY_MOUSE_PRESS && ev != TERMKEY_MOUSE_DRAG && ev != TERMKEY_MOUSE_RELEASE)) { return; @@ -431,8 +439,11 @@ static void forward_mouse_event(TermInput *input, TermKeyKey *key) if (button == 4) { len += (size_t)snprintf(buf + len, sizeof(buf) - len, "ScrollWheelUp"); } else if (button == 5) { - len += (size_t)snprintf(buf + len, sizeof(buf) - len, - "ScrollWheelDown"); + len += (size_t)snprintf(buf + len, sizeof(buf) - len, "ScrollWheelDown"); + } else if (button == 6) { + len += (size_t)snprintf(buf + len, sizeof(buf) - len, "ScrollWheelLeft"); + } else if (button == 7) { + len += (size_t)snprintf(buf + len, sizeof(buf) - len, "ScrollWheelRight"); } else { len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Mouse"); last_pressed_button = button; -- cgit From 6ab2bf68196292721b71e096f45bfa3dd0192ee0 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 22 Aug 2022 17:29:26 +0200 Subject: fix(highlight): set the window namespace when redrawing statusline --- src/nvim/drawscreen.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 40dbec8a5b..29ff261461 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -748,6 +748,8 @@ void show_cursor_info(bool always) if (!always && !redrawing()) { return; } + + win_check_ns_hl(curwin); if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && (curwin->w_status_height || global_stl_height())) { redraw_custom_statusline(curwin); @@ -764,6 +766,7 @@ void show_cursor_info(bool always) maketitle(); } + win_check_ns_hl(NULL); // Redraw the tab pages line if needed. if (redraw_tabline) { draw_tabline(); @@ -2119,10 +2122,13 @@ void redraw_statuslines(void) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (wp->w_redr_status) { + win_check_ns_hl(wp); win_redr_winbar(wp); win_redr_status(wp); } } + + win_check_ns_hl(NULL); if (redraw_tabline) { draw_tabline(); } -- cgit From 2828aae7b49921380f229ebf4d7432f39c6c2c2b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 30 Aug 2022 14:52:09 +0200 Subject: refactor: replace char_u with char 4 (#19987) * refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/change.c | 4 +- src/nvim/charset.c | 49 ++++---- src/nvim/cmdexpand.c | 32 ++--- src/nvim/debugger.c | 12 +- src/nvim/digraph.c | 8 +- src/nvim/drawline.c | 4 +- src/nvim/edit.c | 12 +- src/nvim/eval.c | 16 +-- src/nvim/eval/executor.c | 3 +- src/nvim/eval/funcs.c | 28 ++--- src/nvim/eval/typval.c | 2 +- src/nvim/eval/userfunc.c | 39 +++--- src/nvim/eval/vars.c | 9 +- src/nvim/ex_cmds.c | 11 +- src/nvim/ex_docmd.c | 19 ++- src/nvim/ex_eval.c | 4 +- src/nvim/ex_getln.c | 4 +- src/nvim/ex_session.c | 2 +- src/nvim/file_search.c | 12 +- src/nvim/fileio.c | 12 +- src/nvim/getchar.c | 4 +- src/nvim/globals.h | 2 +- src/nvim/hardcopy.c | 3 +- src/nvim/help.c | 10 +- src/nvim/highlight_group.c | 20 +-- src/nvim/if_cscope.c | 4 +- src/nvim/indent_c.c | 4 +- src/nvim/insexpand.c | 4 +- src/nvim/locale.c | 2 +- src/nvim/log.c | 4 +- src/nvim/lua/stdlib.c | 2 +- src/nvim/main.c | 4 +- src/nvim/mark.c | 6 +- src/nvim/match.c | 2 +- src/nvim/mbyte.c | 18 ++- src/nvim/memline.c | 10 +- src/nvim/menu.c | 2 +- src/nvim/message.c | 55 +++++---- src/nvim/normal.c | 8 +- src/nvim/ops.c | 10 +- src/nvim/os/env.c | 6 +- src/nvim/os/fs.c | 8 +- src/nvim/os/shell.c | 4 +- src/nvim/path.c | 32 ++--- src/nvim/plines.c | 4 +- src/nvim/popupmenu.c | 2 +- src/nvim/profile.c | 8 +- src/nvim/quickfix.c | 6 +- src/nvim/runtime.c | 277 +++++++++++++++++++++--------------------- src/nvim/runtime.h | 2 +- src/nvim/screen.c | 2 +- src/nvim/search.c | 8 +- src/nvim/shada.c | 2 +- src/nvim/sign.c | 20 +-- src/nvim/spell.c | 22 ++-- src/nvim/spell_defs.h | 6 +- src/nvim/spellfile.c | 24 ++-- src/nvim/spellsuggest.c | 14 +-- src/nvim/strings.c | 16 ++- src/nvim/syntax.c | 28 ++--- src/nvim/tag.c | 38 +++--- src/nvim/undo.c | 2 +- src/nvim/usercmd.c | 8 +- src/nvim/vim.h | 5 +- src/nvim/viml/parser/parser.h | 4 +- src/nvim/window.c | 4 +- 66 files changed, 499 insertions(+), 509 deletions(-) (limited to 'src') diff --git a/src/nvim/change.c b/src/nvim/change.c index fd079f8eef..85ab92e49b 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -653,9 +653,9 @@ void ins_char_bytes(char *buf, size_t charlen) // cells. May result in adding spaces to fill a gap. colnr_T vcol; getvcol(curwin, &curwin->w_cursor, NULL, &vcol, NULL); - colnr_T new_vcol = vcol + win_chartabsize(curwin, (char *)buf, vcol); + colnr_T new_vcol = vcol + win_chartabsize(curwin, buf, vcol); while (oldp[col + oldlen] != NUL && vcol < new_vcol) { - vcol += win_chartabsize(curwin, (char *)oldp + col + oldlen, vcol); + vcol += win_chartabsize(curwin, oldp + col + oldlen, vcol); // Don't need to remove a TAB that takes us to the right // position. if (vcol > new_vcol && oldp[col + oldlen] == TAB) { diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 2632279565..4efd8a4ad1 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1157,7 +1157,7 @@ char *skipwhite(const char *const p) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { - return (char *)skipwhite_len((char_u *)p, STRLEN(p)); + return skipwhite_len(p, STRLEN(p)); } /// Like `skipwhite`, but skip up to `len` characters. @@ -1168,27 +1168,27 @@ char *skipwhite(const char *const p) /// /// @return Pointer to character after the skipped whitespace, or the `len`-th /// character in the string. -char_u *skipwhite_len(const char_u *p, size_t len) +char *skipwhite_len(const char *p, size_t len) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { for (; len > 0 && ascii_iswhite(*p); len--) { p++; } - return (char_u *)p; + return (char *)p; } // getwhitecols: return the number of whitespace // columns (bytes) at the start of a given line intptr_t getwhitecols_curline(void) { - return getwhitecols(get_cursor_line_ptr()); + return getwhitecols((char *)get_cursor_line_ptr()); } -intptr_t getwhitecols(const char_u *p) +intptr_t getwhitecols(const char *p) FUNC_ATTR_PURE { - return (char_u *)skipwhite((char *)p) - p; + return skipwhite(p) - p; } /// Skip over digits @@ -1232,10 +1232,10 @@ const char *skipbin(const char *q) /// /// @return Pointer to the character after the skipped digits and hex /// characters. -char_u *skiphex(char_u *q) +char *skiphex(char *q) FUNC_ATTR_PURE { - char_u *p = q; + char *p = q; while (ascii_isxdigit(*p)) { // skip to next non-digit p++; @@ -1248,10 +1248,10 @@ char_u *skiphex(char_u *q) /// @param q /// /// @return Pointer to the digit or (NUL after the string). -char_u *skiptodigit(char_u *q) +char *skiptodigit(char *q) FUNC_ATTR_PURE { - char_u *p = q; + char *p = q; while (*p != NUL && !ascii_isdigit(*p)) { // skip to next digit p++; @@ -1282,10 +1282,10 @@ const char *skiptobin(const char *q) /// @param q /// /// @return Pointer to the hex character or (NUL after the string). -char_u *skiptohex(char_u *q) +char *skiptohex(char *q) FUNC_ATTR_PURE { - char_u *p = q; + char *p = q; while (*p != NUL && !ascii_isxdigit(*p)) { // skip to next digit p++; @@ -1298,13 +1298,13 @@ char_u *skiptohex(char_u *q) /// @param[in] p Text to skip over. /// /// @return Pointer to the next whitespace or NUL character. -char_u *skiptowhite(const char_u *p) +char *skiptowhite(const char *p) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE { while (*p != ' ' && *p != '\t' && *p != NUL) { p++; } - return (char_u *)p; + return (char *)p; } /// skiptowhite_esc: Like skiptowhite(), but also skip escaped chars @@ -1329,11 +1329,11 @@ char *skiptowhite_esc(char *p) /// @param[in] p Text to skip over. /// /// @return Pointer to the next '\n' or NUL character. -char_u *skip_to_newline(const char_u *const p) +char *skip_to_newline(const char *const p) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { - return (char_u *)xstrchrnul((const char *)p, NL); + return xstrchrnul(p, NL); } /// Gets a number from a string and skips over it, signalling overflow. @@ -1422,10 +1422,10 @@ int32_t getdigits_int32(char **pp, bool strict, long def) /// Check that "lbuf" is empty or only contains blanks. /// /// @param lbuf line buffer to check -bool vim_isblankline(char_u *lbuf) +bool vim_isblankline(char *lbuf) FUNC_ATTR_PURE { - char_u *p = (char_u *)skipwhite((char *)lbuf); + char *p = skipwhite(lbuf); return *p == NUL || *p == '\r' || *p == '\n'; } @@ -1664,8 +1664,9 @@ int hex2nr(int c) } /// Convert two hex characters to a byte. -/// Return -1 if one of the characters is not hex. -int hexhex2nr(const char_u *p) +/// +/// @return -1 if one of the characters is not hex. +int hexhex2nr(const char *p) FUNC_ATTR_PURE { if (!ascii_isxdigit(p[0]) || !ascii_isxdigit(p[1])) { @@ -1707,10 +1708,10 @@ bool rem_backslash(const char *str) /// Halve the number of backslashes in a file name argument. /// /// @param p -void backslash_halve(char_u *p) +void backslash_halve(char *p) { for (; *p; p++) { - if (rem_backslash((char *)p)) { + if (rem_backslash(p)) { STRMOVE(p, p + 1); } } @@ -1721,11 +1722,11 @@ void backslash_halve(char_u *p) /// @param p /// /// @return String with the number of backslashes halved. -char_u *backslash_halve_save(const char_u *p) +char *backslash_halve_save(const char *p) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { // TODO(philix): simplify and improve backslash_halve_save algorithm - char_u *res = vim_strsave(p); + char *res = xstrdup(p); backslash_halve(res); return res; } diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index dbf169c801..5c54404aab 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -387,7 +387,7 @@ static char_u *ExpandOne_start(int mode, expand_T *xp, char_u *str, int options) } /// Return the longest common part in the list of cmdline completion matches. -static char_u *find_longest_match(expand_T *xp, int options) +static char *find_longest_match(expand_T *xp, int options) { size_t len = 0; @@ -417,7 +417,7 @@ static char_u *find_longest_match(expand_T *xp, int options) } } - return (char_u *)xstrndup(xp->xp_files[0], len); + return xstrndup(xp->xp_files[0], len); } /// Do wildcard expansion on the string 'str'. @@ -500,7 +500,7 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode // Find longest common part if (mode == WILD_LONGEST && xp->xp_numfiles > 0) { - ss = find_longest_match(xp, options); + ss = (char_u *)find_longest_match(xp, options); findex = -1; // next p_wc gets first one } @@ -670,7 +670,7 @@ int showmatches(expand_T *xp, int wildmenu) lastlen = 999; for (k = i; k < num_files; k += lines) { if (xp->xp_context == EXPAND_TAGS_LISTFILES) { - msg_outtrans_attr((char_u *)files_found[k], HL_ATTR(HLF_D)); + msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D)); p = (char_u *)files_found[k] + STRLEN(files_found[k]) + 1; msg_advance(maxlen + 1); msg_puts((const char *)p); @@ -691,15 +691,15 @@ int showmatches(expand_T *xp, int wildmenu) // $HOME has been replaced with ~/. char_u *exp_path = expand_env_save_opt((char_u *)files_found[k], true); char_u *path = exp_path != NULL ? exp_path : (char_u *)files_found[k]; - char_u *halved_slash = backslash_halve_save(path); - j = os_isdir(halved_slash); + char_u *halved_slash = (char_u *)backslash_halve_save((char *)path); + j = os_isdir((char *)halved_slash); xfree(exp_path); if (halved_slash != path) { xfree(halved_slash); } } else { // Expansion was done here, file names are literal. - j = os_isdir((char_u *)files_found[k]); + j = os_isdir(files_found[k]); } if (showtail) { p = (char_u *)L_SHOWFILE(k); @@ -711,7 +711,7 @@ int showmatches(expand_T *xp, int wildmenu) j = false; p = (char_u *)L_SHOWFILE(k); } - lastlen = msg_outtrans_attr(p, j ? attr : 0); + lastlen = msg_outtrans_attr((char *)p, j ? attr : 0); } if (msg_col > 0) { // when not wrapped around msg_clr_eos(); @@ -1239,7 +1239,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons if (*arg == NUL || !ends_excmd(*arg)) { // also complete "None" set_context_in_echohl_cmd(xp, arg); - arg = (const char *)skipwhite((char *)skiptowhite((const char_u *)arg)); + arg = (const char *)skipwhite(skiptowhite(arg)); if (*arg != NUL) { xp->xp_context = EXPAND_NOTHING; arg = (const char *)skip_regexp((char *)arg + 1, (uint8_t)(*arg), p_magic, NULL); @@ -1592,7 +1592,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons #ifdef HAVE_WORKING_LIBINTL case CMD_language: - p = (const char *)skiptowhite((const char_u *)arg); + p = (const char *)skiptowhite(arg); if (*p == NUL) { xp->xp_context = EXPAND_LANGUAGE; xp->xp_pattern = (char *)arg; @@ -2161,19 +2161,19 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char ***f } if (xp->xp_context == EXPAND_COLORS) { char *directories[] = { "colors", NULL }; - return ExpandRTDir(pat, DIP_START + DIP_OPT + DIP_LUA, num_file, file, directories); + return ExpandRTDir((char *)pat, DIP_START + DIP_OPT + DIP_LUA, num_file, file, directories); } if (xp->xp_context == EXPAND_COMPILER) { char *directories[] = { "compiler", NULL }; - return ExpandRTDir(pat, DIP_LUA, num_file, file, directories); + return ExpandRTDir((char *)pat, DIP_LUA, num_file, file, directories); } if (xp->xp_context == EXPAND_OWNSYNTAX) { char *directories[] = { "syntax", NULL }; - return ExpandRTDir(pat, 0, num_file, file, directories); + return ExpandRTDir((char *)pat, 0, num_file, file, directories); } if (xp->xp_context == EXPAND_FILETYPE) { char *directories[] = { "syntax", "indent", "ftplugin", NULL }; - return ExpandRTDir(pat, DIP_LUA, num_file, file, directories); + return ExpandRTDir((char *)pat, DIP_LUA, num_file, file, directories); } if (xp->xp_context == EXPAND_USER_LIST) { return ExpandUserList(xp, num_file, file); @@ -2182,7 +2182,7 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char ***f return ExpandUserLua(xp, num_file, file); } if (xp->xp_context == EXPAND_PACKADD) { - return ExpandPackAddDir(pat, num_file, file); + return ExpandPackAddDir((char *)pat, num_file, file); } // When expanding a function name starting with s:, match the nr_ @@ -2573,7 +2573,7 @@ static int ExpandUserLua(expand_T *xp, int *num_file, char ***file) /// Expand `file` for all comma-separated directories in `path`. /// Adds matches to `ga`. -void globpath(char *path, char_u *file, garray_T *ga, int expand_options) +void globpath(char *path, char *file, garray_T *ga, int expand_options) { expand_T xpc; ExpandInit(&xpc); diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index 9fdeebf68a..36df62b502 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -718,9 +718,9 @@ void ex_breaklist(exarg_T *eap) /// @param file true for a file, false for a function /// @param fname file or function name /// @param after after this line number -linenr_T dbg_find_breakpoint(bool file, char_u *fname, linenr_T after) +linenr_T dbg_find_breakpoint(bool file, char *fname, linenr_T after) { - return debuggy_find(file, fname, after, &dbg_breakp, NULL); + return debuggy_find(file, (char_u *)fname, after, &dbg_breakp, NULL); } /// @param file true for a file, false for a function @@ -728,9 +728,9 @@ linenr_T dbg_find_breakpoint(bool file, char_u *fname, linenr_T after) /// @param fp[out] forceit /// /// @returns true if profiling is on for a function or sourced file. -bool has_profiling(bool file, char_u *fname, bool *fp) +bool has_profiling(bool file, char *fname, bool *fp) { - return debuggy_find(file, fname, (linenr_T)0, &prof_ga, fp) + return debuggy_find(file, (char_u *)fname, (linenr_T)0, &prof_ga, fp) != (linenr_T)0; } @@ -825,9 +825,9 @@ static linenr_T debuggy_find(bool file, char_u *fname, linenr_T after, garray_T } /// Called when a breakpoint was encountered. -void dbg_breakpoint(char_u *name, linenr_T lnum) +void dbg_breakpoint(char *name, linenr_T lnum) { // We need to check if this line is actually executed in do_one_cmd() - debug_breakpoint_name = name; + debug_breakpoint_name = (char_u *)name; debug_breakpoint_lnum = lnum; } diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index de2dd09d1c..e4528f9038 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1695,7 +1695,7 @@ static void digraph_header(const char *msg) if (msg_col > 0) { msg_putchar('\n'); } - msg_outtrans_attr((const char_u *)msg, HL_ATTR(HLF_CM)); + msg_outtrans_attr(msg, HL_ATTR(HLF_CM)); msg_putchar('\n'); } @@ -1856,7 +1856,7 @@ static void printdigraph(const digr_T *dp, result_T *previous) p += utf_char2bytes(dp->result, (char *)p); *p = NUL; - msg_outtrans_attr(buf, HL_ATTR(HLF_8)); + msg_outtrans_attr((char *)buf, HL_ATTR(HLF_8)); p = buf; if (char2cells(dp->result) == 1) { *p++ = ' '; @@ -2096,10 +2096,10 @@ void ex_loadkeymap(exarg_T *eap) if ((*p != '"') && (*p != NUL)) { kmap_T *kp = GA_APPEND_VIA_PTR(kmap_T, &curbuf->b_kmap_ga); - s = skiptowhite(p); + s = (char_u *)skiptowhite((char *)p); kp->from = vim_strnsave(p, (size_t)(s - p)); p = (char_u *)skipwhite((char *)s); - s = skiptowhite(p); + s = (char_u *)skiptowhite((char *)p); kp->to = vim_strnsave(p, (size_t)(s - p)); if ((STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN) diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index b6654699d8..b6c4400c60 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -870,7 +870,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (has_spell && !number_only) { // For checking first word with a capital skip white space. if (cap_col == 0) { - cap_col = (int)getwhitecols(line); + cap_col = (int)getwhitecols((char *)line); } // To be able to spell-check over line boundaries copy the end of the @@ -1171,7 +1171,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (wp->w_p_rl) { // reverse line numbers // like rl_mirror(), but keep the space at the end char_u *p2 = (char_u *)skipwhite((char *)extra); - p2 = skiptowhite(p2) - 1; + p2 = (char_u *)skiptowhite((char *)p2) - 1; for (char_u *p1 = (char_u *)skipwhite((char *)extra); p1 < p2; p1++, p2--) { const char_u t = *p1; *p1 = *p2; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index b0174de01f..aee8389900 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2698,12 +2698,12 @@ int cursor_down(long n, int upd_topline) /// @param no_esc Don't add an ESC at the end int stuff_inserted(int c, long count, int no_esc) { - char_u *esc_ptr; - char_u *ptr; - char_u *last_ptr; - char_u last = NUL; + char *esc_ptr; + char *ptr; + char *last_ptr; + char last = NUL; - ptr = get_last_insert(); + ptr = (char *)get_last_insert(); if (ptr == NULL) { emsg(_(e_noinstext)); return FAIL; @@ -2713,7 +2713,7 @@ int stuff_inserted(int c, long count, int no_esc) if (c != NUL) { stuffcharReadbuff(c); } - if ((esc_ptr = STRRCHR(ptr, ESC)) != NULL) { + if ((esc_ptr = strrchr(ptr, ESC)) != NULL) { // remove the ESC. *esc_ptr = NUL; } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f89b06843a..508d7cf491 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2042,7 +2042,7 @@ void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx) || cmdidx == CMD_echomsg) && xp->xp_context == EXPAND_EXPRESSION) { for (;;) { - char *const n = (char *)skiptowhite((char_u *)arg); + char *const n = skiptowhite(arg); if (n == arg || ascii_iswhite_or_nul(*skipwhite(n))) { break; @@ -2658,7 +2658,7 @@ static int eval5(char **arg, typval_T *rettv, int evaluate) tv_clear(&var2); return FAIL; } - p = (char *)concat_str((const char_u *)s1, (const char_u *)s2); + p = concat_str(s1, s2); tv_clear(rettv); rettv->v_type = VAR_STRING; rettv->vval.v_string = p; @@ -7400,7 +7400,7 @@ hashtab_T *find_var_ht_dict(const char *name, const size_t name_len, const char bool should_free; // should_free is ignored as script_sctx will be resolved to a fnmae // & new_script_item will consume it. - char *sc_name = (char *)get_scriptname(last_set, &should_free); + char *sc_name = get_scriptname(last_set, &should_free); new_script_item(sc_name, ¤t_sctx.sc_sid); } } @@ -7527,9 +7527,9 @@ int var_item_copy(const vimconv_T *const conv, typval_T *const from, typval_T *c } else { to->v_type = VAR_STRING; to->v_lock = VAR_UNLOCKED; - if ((to->vval.v_string = (char *)string_convert((vimconv_T *)conv, - (char_u *)from->vval.v_string, - NULL)) + if ((to->vval.v_string = string_convert((vimconv_T *)conv, + from->vval.v_string, + NULL)) == NULL) { to->vval.v_string = xstrdup(from->vval.v_string); } @@ -7980,7 +7980,7 @@ void option_last_set_msg(LastSet last_set) { if (last_set.script_ctx.sc_sid != 0) { bool should_free; - char *p = (char *)get_scriptname(last_set, &should_free); + char *p = get_scriptname(last_set, &should_free); verbose_enter(); msg_puts(_("\n\tLast set from ")); msg_puts(p); @@ -8077,7 +8077,7 @@ repeat: } // Append a path separator to a directory. - if (os_isdir((char_u *)(*fnamep))) { + if (os_isdir(*fnamep)) { // Make room for one or two extra characters. *fnamep = xstrnsave(*fnamep, STRLEN(*fnamep) + 2); xfree(*bufp); // free any allocated file name diff --git a/src/nvim/eval/executor.c b/src/nvim/eval/executor.c index b461456a3a..0e0d0fe696 100644 --- a/src/nvim/eval/executor.c +++ b/src/nvim/eval/executor.c @@ -108,8 +108,7 @@ int eexe_mod_op(typval_T *const tv1, const typval_T *const tv2, const char *cons const char *tvs = tv_get_string(tv1); char numbuf[NUMBUFLEN]; char *const s = - (char *)concat_str((const char_u *)tvs, (const char_u *)tv_get_string_buf(tv2, - numbuf)); + concat_str(tvs, tv_get_string_buf(tv2, numbuf)); tv_clear(tv1); tv1->v_type = VAR_STRING; tv1->vval.v_string = s; diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index c442f5c465..f21011d22b 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2210,7 +2210,7 @@ static void f_filereadable(typval_T *argvars, typval_T *rettv, EvalFuncData fptr { const char *const p = tv_get_string(&argvars[0]); rettv->vval.v_number = - (*p && !os_isdir((const char_u *)p) && os_file_is_readable(p)); + (*p && !os_isdir(p) && os_file_is_readable(p)); } /// @return 0 for not writable @@ -2888,7 +2888,7 @@ static void f_getfsize(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) FileInfo file_info; if (os_fileinfo(fname, &file_info)) { uint64_t filesize = os_fileinfo_size(&file_info); - if (os_isdir((const char_u *)fname)) { + if (os_isdir(fname)) { rettv->vval.v_number = 0; } else { rettv->vval.v_number = (varnumber_T)filesize; @@ -3491,7 +3491,7 @@ static void f_globpath(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (file != NULL && !error) { garray_T ga; ga_init(&ga, (int)sizeof(char_u *), 10); - globpath((char *)tv_get_string(&argvars[0]), (char_u *)file, &ga, flags); + globpath((char *)tv_get_string(&argvars[0]), (char *)file, &ga, flags); if (rettv->v_type == VAR_STRING) { rettv->vval.v_string = ga_concat_strings_sep(&ga, "\n"); @@ -3874,7 +3874,7 @@ static void f_iconv(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (vimconv.vc_type == CONV_NONE) { rettv->vval.v_string = xstrdup(str); } else { - rettv->vval.v_string = (char *)string_convert(&vimconv, (char_u *)str, NULL); + rettv->vval.v_string = string_convert(&vimconv, (char *)str, NULL); } convert_setup(&vimconv, NULL, NULL); @@ -4131,7 +4131,7 @@ static void f_invert(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "isdirectory()" function static void f_isdirectory(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - rettv->vval.v_number = os_isdir((const char_u *)tv_get_string(&argvars[0])); + rettv->vval.v_number = os_isdir(tv_get_string(&argvars[0])); } /// "islocked()" function @@ -4458,7 +4458,7 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (new_cwd && *new_cwd != NUL) { cwd = new_cwd; // The new cwd must be a directory. - if (!os_isdir((const char_u *)cwd)) { + if (!os_isdir(cwd)) { semsg(_(e_invarg2), "expected valid directory"); shell_free_argv(argv); return; @@ -5891,7 +5891,7 @@ static void f_readfile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) // their own about CR-LF conversion. const char *const fname = tv_get_string(&argvars[0]); - if (os_isdir((const char_u *)fname)) { + if (os_isdir(fname)) { semsg(_(e_isadir2), fname); return; } @@ -6343,7 +6343,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (*q != NUL) { cpy = remain; remain = (remain - ? (char *)concat_str((char_u *)q - 1, (char_u *)remain) + ? concat_str(q - 1, remain) : xstrdup(q - 1)); xfree(cpy); q[-1] = NUL; @@ -6402,7 +6402,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) && (p[2] == NUL || vim_ispathsep(p[2])))))) { // Prepend "./". - cpy = (char *)concat_str((const char_u *)"./", (const char_u *)p); + cpy = concat_str("./", p); xfree(p); p = cpy; } else if (!is_relative_to_current) { @@ -8339,7 +8339,7 @@ static void f_strftime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) char *enc = (char *)enc_locale(); convert_setup(&conv, p_enc, enc); if (conv.vc_type != CONV_NONE) { - p = (char *)string_convert(&conv, (char_u *)p, NULL); + p = string_convert(&conv, p, NULL); } char result_buf[256]; if (p != NULL) { @@ -8353,7 +8353,7 @@ static void f_strftime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } convert_setup(&conv, enc, p_enc); if (conv.vc_type != CONV_NONE) { - rettv->vval.v_string = (char *)string_convert(&conv, (char_u *)result_buf, NULL); + rettv->vval.v_string = string_convert(&conv, result_buf, NULL); } else { rettv->vval.v_string = xstrdup(result_buf); } @@ -8599,7 +8599,7 @@ static void f_strptime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) char *enc = (char *)enc_locale(); convert_setup(&conv, p_enc, enc); if (conv.vc_type != CONV_NONE) { - fmt = (char *)string_convert(&conv, (char_u *)fmt, NULL); + fmt = string_convert(&conv, fmt, NULL); } if (fmt == NULL || os_strptime(str, fmt, &tmval) == NULL @@ -9070,7 +9070,7 @@ static void f_tagfiles(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) bool first = true; tagname_T tn; - while (get_tagfname(&tn, first, (char_u *)fname) == OK) { + while (get_tagfname(&tn, first, fname) == OK) { tv_list_append_string(rettv->vval.v_list, fname, -1); first = false; } @@ -9148,7 +9148,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (new_cwd && *new_cwd != NUL) { cwd = new_cwd; // The new cwd must be a directory. - if (!os_isdir((const char_u *)cwd)) { + if (!os_isdir(cwd)) { semsg(_(e_invarg2), "expected valid directory"); shell_free_argv(argv); return; diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 152c2eff8f..d5b2b1f2ae 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -2533,7 +2533,7 @@ dict_T *tv_dict_copy(const vimconv_T *const conv, dict_T *const orig, const bool new_di = tv_dict_item_alloc((const char *)di->di_key); } else { size_t len = STRLEN(di->di_key); - char *const key = (char *)string_convert(conv, di->di_key, &len); + char *const key = (char *)string_convert(conv, (char *)di->di_key, &len); if (key == NULL) { new_di = tv_dict_item_alloc_len((const char *)di->di_key, len); } else { diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 2a48de5e41..b9a94a971b 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -409,7 +409,7 @@ void emsg_funcname(char *ermsg, const char_u *name) char_u *p; if (*name == K_SPECIAL) { - p = concat_str((char_u *)"", name + 3); + p = (char_u *)concat_str("", (char *)name + 3); } else { p = (char_u *)name; } @@ -863,7 +863,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett fc->rettv = rettv; fc->level = ex_nesting_level; // Check if this function has a breakpoint. - fc->breakpoint = dbg_find_breakpoint(false, fp->uf_name, (linenr_T)0); + fc->breakpoint = dbg_find_breakpoint(false, (char *)fp->uf_name, (linenr_T)0); fc->dbg_tick = debug_tick; // Set up fields for closure. @@ -1058,7 +1058,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett bool func_not_yet_profiling_but_should = do_profiling_yes - && !fp->uf_profiling && has_profiling(false, fp->uf_name, NULL); + && !fp->uf_profiling && has_profiling(false, (char *)fp->uf_name, NULL); if (func_not_yet_profiling_but_should) { started_profiling = true; @@ -2332,7 +2332,7 @@ void ex_function(exarg_T *eap) } // heredoc: Check for ":python <func; - char_u *retval; + char *retval; garray_T *gap; // growarray with function lines // If breakpoints have been added/deleted need to check for it. if (fcp->dbg_tick != debug_tick) { - fcp->breakpoint = dbg_find_breakpoint(false, fp->uf_name, SOURCING_LNUM); + fcp->breakpoint = dbg_find_breakpoint(false, (char *)fp->uf_name, SOURCING_LNUM); fcp->dbg_tick = debug_tick; } if (do_profiling == PROF_YES) { @@ -3159,7 +3160,7 @@ char *get_func_line(int c, void *cookie, int indent, bool do_concat) if (fcp->linenr >= gap->ga_len) { retval = NULL; } else { - retval = (char_u *)xstrdup(((char **)(gap->ga_data))[fcp->linenr++]); + retval = xstrdup(((char **)(gap->ga_data))[fcp->linenr++]); SOURCING_LNUM = fcp->linenr; if (do_profiling == PROF_YES) { func_line_start(cookie); @@ -3169,13 +3170,13 @@ char *get_func_line(int c, void *cookie, int indent, bool do_concat) // Did we encounter a breakpoint? if (fcp->breakpoint != 0 && fcp->breakpoint <= SOURCING_LNUM) { - dbg_breakpoint(fp->uf_name, SOURCING_LNUM); + dbg_breakpoint((char *)fp->uf_name, SOURCING_LNUM); // Find next breakpoint. - fcp->breakpoint = dbg_find_breakpoint(false, fp->uf_name, SOURCING_LNUM); + fcp->breakpoint = dbg_find_breakpoint(false, (char *)fp->uf_name, SOURCING_LNUM); fcp->dbg_tick = debug_tick; } - return (char *)retval; + return retval; } /// @return true if the currently active function should be ended, because a diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index e73bba16e2..75410d40d8 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -81,7 +81,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) // The marker is the next word. if (*cmd != NUL && *cmd != '"') { marker = skipwhite(cmd); - p = (char *)skiptowhite((char_u *)marker); + p = skiptowhite(marker); if (*skipwhite(p) != NUL && *skipwhite(p) != '"') { semsg(_(e_trailing_arg), p); return NULL; @@ -587,7 +587,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo char *s = vim_getenv(name); if (s != NULL) { - tofree = (char *)concat_str((const char_u *)s, (const char_u *)p); + tofree = concat_str(s, p); p = (const char *)tofree; xfree(s); } @@ -663,8 +663,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo } else if (opt_type == gov_string && stringval != NULL && s != NULL) { // string char *const oldstringval = stringval; - stringval = (char *)concat_str((const char_u *)stringval, - (const char_u *)s); + stringval = concat_str(stringval, s); xfree(oldstringval); s = stringval; } @@ -705,7 +704,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo if (p != NULL && op != NULL && *op == '.') { s = get_reg_contents(*arg == '@' ? '"' : *arg, kGRegExprSrc); if (s != NULL) { - ptofree = (char *)concat_str((char_u *)s, (const char_u *)p); + ptofree = concat_str(s, p); p = (const char *)ptofree; xfree(s); } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index ba6594fd7a..fc753cf65c 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -586,11 +586,11 @@ void ex_sort(exarg_T *eap) p = s + start_col; if (sort_nr) { if (sort_what & STR2NR_HEX) { - s = (char *)skiptohex((char_u *)p); + s = skiptohex(p); } else if (sort_what & STR2NR_BIN) { s = (char *)skiptobin(p); } else { - s = (char *)skiptodigit((char_u *)p); + s = skiptodigit(p); } if (s > p && s[-1] == '-') { s--; // include preceding negative sign @@ -2006,7 +2006,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int oth if (!eap->forceit && !eap->append) { #ifdef UNIX // It is possible to open a directory on Unix. - if (os_isdir((char_u *)ffname)) { + if (os_isdir(ffname)) { semsg(_(e_isadir2), ffname); return FAIL; } @@ -3940,8 +3940,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // what matches. Temporarily replace the line // and change it back afterwards. orig_line = (char *)vim_strsave(ml_get(lnum)); - char *new_line = (char *)concat_str((char_u *)new_start, - (char_u *)sub_firstline + copycol); + char *new_line = concat_str(new_start, sub_firstline + copycol); // Position the cursor relative to the end of the line, the // previous substitute may have inserted or deleted characters @@ -4939,7 +4938,7 @@ char *skip_vimgrep_pat(char *p, char **s, int *flags) if (s != NULL) { *s = p; } - p = (char *)skiptowhite((char_u *)p); + p = skiptowhite(p); if (s != NULL && *p != NUL) { *p++ = NUL; } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 08709ec228..1fa14f4e4f 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -462,7 +462,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) if (breakpoint != NULL && dbg_tick != NULL && *dbg_tick != debug_tick) { *breakpoint = dbg_find_breakpoint(getline_equal(fgetline, cookie, getsourceline), - (char_u *)fname, SOURCING_LNUM); + fname, SOURCING_LNUM); *dbg_tick = debug_tick; } @@ -471,10 +471,10 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) // Did we encounter a breakpoint? if (breakpoint != NULL && *breakpoint != 0 && *breakpoint <= SOURCING_LNUM) { - dbg_breakpoint((char_u *)fname, SOURCING_LNUM); + dbg_breakpoint(fname, SOURCING_LNUM); // Find next breakpoint. *breakpoint = dbg_find_breakpoint(getline_equal(fgetline, cookie, getsourceline), - (char_u *)fname, SOURCING_LNUM); + fname, SOURCING_LNUM); *dbg_tick = debug_tick; } if (do_profiling == PROF_YES) { @@ -639,8 +639,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) // Check for the next breakpoint at or after the ":while" // or ":for". if (breakpoint != NULL) { - *breakpoint = dbg_find_breakpoint(getline_equal(fgetline, cookie, getsourceline), - (char_u *)fname, + *breakpoint = dbg_find_breakpoint(getline_equal(fgetline, cookie, getsourceline), fname, ((wcmd_T *)lines_ga.ga_data)[current_line].lnum - 1); *dbg_tick = debug_tick; } @@ -3665,7 +3664,7 @@ char *replace_makeprg(exarg_T *eap, char *arg, char **cmdlinep) STRCAT(new_cmdline, arg); } - msg_make((char_u *)arg); + msg_make(arg); // 'eap->cmd' is not set here, because it is not used at CMD_make xfree(*cmdlinep); @@ -3807,7 +3806,7 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) // done by ExpandOne() below. #ifdef UNIX if (!has_wildcards) { - backslash_halve((char_u *)eap->arg); + backslash_halve(eap->arg); } #else backslash_halve((char_u *)eap->arg); @@ -5032,7 +5031,7 @@ static void ex_tabs(exarg_T *eap) msg_putchar('\n'); vim_snprintf((char *)IObuff, IOSIZE, _("Tab page %d"), tabcount++); - msg_outtrans_attr(IObuff, HL_ATTR(HLF_T)); + msg_outtrans_attr((char *)IObuff, HL_ATTR(HLF_T)); ui_flush(); // output one line at a time os_breakcheck(); @@ -6154,7 +6153,7 @@ FILE *open_exfile(char_u *fname, int forceit, char *mode) { #ifdef UNIX // with Unix it is possible to open a directory - if (os_isdir(fname)) { + if (os_isdir((char *)fname)) { semsg(_(e_isadir2), fname); return NULL; } @@ -6881,7 +6880,7 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum if (src[*usedlen] == '<') { (*usedlen)++; char *s; - if ((s = (char *)STRRCHR(result, '.')) != NULL + if ((s = strrchr(result, '.')) != NULL && s >= path_tail(result)) { resultlen = (size_t)(s - result); } diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index e2b02929d2..11795684cf 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -726,14 +726,14 @@ static void report_pending(int action, int pending, void *value) break; case CSTP_RETURN: // ":return" command producing value, allocated - s = (char *)get_return_cmd(value); + s = get_return_cmd(value); break; default: if (pending & CSTP_THROW) { vim_snprintf((char *)IObuff, IOSIZE, mesg, _("Exception")); - mesg = (char *)concat_str(IObuff, (char_u *)": %s"); + mesg = concat_str((char *)IObuff, ": %s"); s = ((except_T *)value)->value; } else if ((pending & CSTP_ERROR) && (pending & CSTP_INTERRUPT)) { s = _("Error and interrupt"); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 66c3327ce3..0998bdd867 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3198,7 +3198,7 @@ static void draw_cmdline(int start, int len) } } - msg_outtrans_len((char_u *)arshape_buf, newlen); + msg_outtrans_len(arshape_buf, newlen); } else { draw_cmdline_no_arabicshape: if (kv_size(ccline.last_colors.colors)) { @@ -3213,7 +3213,7 @@ draw_cmdline_no_arabicshape: chunk.attr); } } else { - msg_outtrans_len(ccline.cmdbuff + start, len); + msg_outtrans_len((char *)ccline.cmdbuff + start, len); } } } diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index 453de89aea..e907c45e79 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -956,7 +956,7 @@ void ex_mkrc(exarg_T *eap) } // When using 'viewdir' may have to create the directory. - if (using_vdir && !os_isdir(p_vdir)) { + if (using_vdir && !os_isdir((char *)p_vdir)) { vim_mkdir_emsg((const char *)p_vdir, 0755); } diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index a990043017..bbc6e53aa8 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -471,7 +471,7 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le STRCPY(buf, ff_expand_buffer); STRCPY(buf + eb_len, search_ctx->ffsc_fix_path); - if (os_isdir(buf)) { + if (os_isdir((char *)buf)) { STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path); add_pathsep((char *)ff_expand_buffer); } else { @@ -796,7 +796,7 @@ char_u *vim_findfile(void *search_ctx_arg) */ for (int i = stackp->ffs_filearray_cur; i < stackp->ffs_filearray_size; i++) { if (!path_with_url(stackp->ffs_filearray[i]) - && !os_isdir((char_u *)stackp->ffs_filearray[i])) { + && !os_isdir(stackp->ffs_filearray[i])) { continue; // not a directory } // prepare the filename to be checked for existence below @@ -828,7 +828,7 @@ char_u *vim_findfile(void *search_ctx_arg) || (os_path_exists(file_path) && (search_ctx->ffsc_find_what == FINDFILE_BOTH || ((search_ctx->ffsc_find_what == FINDFILE_DIR) - == os_isdir(file_path))))) + == os_isdir((char *)file_path))))) #ifndef FF_VERBOSE && (ff_check_visited(&search_ctx->ffsc_visited_list->ffvl_visited_list, file_path, (char_u *)"") == OK) @@ -885,7 +885,7 @@ char_u *vim_findfile(void *search_ctx_arg) } else { // still wildcards left, push the directories for further search for (int i = stackp->ffs_filearray_cur; i < stackp->ffs_filearray_size; i++) { - if (!os_isdir((char_u *)stackp->ffs_filearray[i])) { + if (!os_isdir(stackp->ffs_filearray[i])) { continue; // not a directory } ff_push(search_ctx, @@ -909,7 +909,7 @@ char_u *vim_findfile(void *search_ctx_arg) stackp->ffs_fix_path) == 0) { continue; // don't repush same directory } - if (!os_isdir((char_u *)stackp->ffs_filearray[i])) { + if (!os_isdir(stackp->ffs_filearray[i])) { continue; // not a directory } ff_push(search_ctx, @@ -1476,7 +1476,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first (os_path_exists((char_u *)NameBuff) && (find_what == FINDFILE_BOTH || ((find_what == FINDFILE_DIR) - == os_isdir((char_u *)NameBuff))))) { + == os_isdir(NameBuff))))) { file_name = vim_strsave((char_u *)NameBuff); goto theend; } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 450c608fad..d67cd36a85 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -143,7 +143,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr) msg_scroll = msg_scroll_save; msg_scrolled_ign = true; // may truncate the message to avoid a hit-return prompt - msg_outtrans_attr(msg_may_trunc(false, IObuff), attr); + msg_outtrans_attr((char *)msg_may_trunc(false, IObuff), attr); msg_clr_eos(); ui_flush(); msg_scrolled_ign = false; @@ -2775,7 +2775,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en if (trailing_pathseps) { IObuff[dir_len - 2] = NUL; } - if (*dirp == NUL && !os_isdir(IObuff)) { + if (*dirp == NUL && !os_isdir((char *)IObuff)) { int ret; char *failed_dir; if ((ret = os_mkdir_recurse((char *)IObuff, 0755, &failed_dir)) != 0) { @@ -2936,7 +2936,7 @@ nobackup: if (trailing_pathseps) { IObuff[dir_len - 2] = NUL; } - if (*dirp == NUL && !os_isdir(IObuff)) { + if (*dirp == NUL && !os_isdir((char *)IObuff)) { int ret; char *failed_dir; if ((ret = os_mkdir_recurse((char *)IObuff, 0755, &failed_dir)) != 0) { @@ -4948,7 +4948,7 @@ int buf_check_timestamp(buf_T *buf) buf_store_file_info(buf, &file_info); } - if (os_isdir((char_u *)buf->b_fname)) { + if (os_isdir(buf->b_fname)) { // Don't do anything for a directory. Might contain the file explorer. } else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar) && !bufIsChanged(buf) && file_info_ok) { @@ -5318,7 +5318,7 @@ static void vim_mktempdir(void) for (size_t i = 0; i < ARRAY_SIZE(temp_dirs); i++) { // Expand environment variables, leave room for "/tmp/nvim./XXXXXX/999999999". expand_env((char *)temp_dirs[i], tmp, TEMP_FILE_PATH_MAXLEN - 64); - if (!os_isdir((char_u *)tmp)) { + if (!os_isdir(tmp)) { continue; } @@ -5328,7 +5328,7 @@ static void vim_mktempdir(void) xstrlcat(tmp, user, sizeof(tmp)); (void)os_mkdir(tmp, 0700); // Always create, to avoid a race. bool owned = os_file_owned(tmp); - bool isdir = os_isdir((char_u *)tmp); + bool isdir = os_isdir(tmp); #ifdef UNIX int perm = os_getperm(tmp); // XDG_RUNTIME_DIR must be owned by the user, mode 0700. bool valid = isdir && owned && 0700 == (perm & 0777); diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index bb8cd5a1eb..0a9457ef35 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1280,7 +1280,7 @@ void restore_typeahead(tasave_T *tp) /// Open a new script file for the ":source!" command. /// /// @param directly when true execute directly -void openscript(char_u *name, bool directly) +void openscript(char *name, bool directly) { if (curscript + 1 == NSCRIPT) { emsg(_(e_nesting)); @@ -1302,7 +1302,7 @@ void openscript(char_u *name, bool directly) curscript++; } // use NameBuff for expanded name - expand_env((char *)name, NameBuff, MAXPATHL); + expand_env(name, NameBuff, MAXPATHL); int error; if ((scriptin[curscript] = file_open_new(&error, (char *)NameBuff, kFileReadOnly, 0)) == NULL) { diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 77784defd1..ddbe727db9 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -177,7 +177,7 @@ EXTERN bool msg_scrolled_ign INIT(= false); // is reset before the screen is redrawn, so we need to keep track of this. EXTERN bool msg_did_scroll INIT(= false); -EXTERN char_u *keep_msg INIT(= NULL); // msg to be shown after redraw +EXTERN char *keep_msg INIT(= NULL); // msg to be shown after redraw EXTERN int keep_msg_attr INIT(= 0); // highlight attr for keep_msg EXTERN bool need_fileinfo INIT(= false); // do fileinfo() after redraw EXTERN int msg_scroll INIT(= false); // msg_start() will scroll diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 6e424f2fd6..602fa8b71d 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -3062,7 +3062,8 @@ int mch_print_text_out(char_u *const textp, size_t len) if (prt_do_conv) { // Convert from multi-byte to 8-bit encoding - tofree = p = string_convert(&prt_conv, p, &len); + p = (char_u *)string_convert(&prt_conv, (char *)p, &len); + tofree = p; if (p == NULL) { p = (char_u *)""; len = 0; diff --git a/src/nvim/help.c b/src/nvim/help.c index b25fabca48..245d80489f 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -741,8 +741,8 @@ void fix_help_buffer(void) const char *const f2 = fnames[i2]; const char *const t1 = path_tail(f1); const char *const t2 = path_tail(f2); - const char *const e1 = (char *)STRRCHR(t1, '.'); - const char *const e2 = (char *)STRRCHR(t2, '.'); + const char *const e1 = strrchr(t1, '.'); + const char *const e2 = strrchr(t2, '.'); if (e1 == NULL || e2 == NULL) { continue; } @@ -811,7 +811,7 @@ void fix_help_buffer(void) } else { // Do the conversion. If it fails // use the unconverted text. - cp = (char *)string_convert(&vc, IObuff, NULL); + cp = string_convert(&vc, (char *)IObuff, NULL); if (cp == NULL) { cp = (char *)IObuff; } @@ -1163,13 +1163,13 @@ void ex_helptags(exarg_T *eap) } if (STRCMP(eap->arg, "ALL") == 0) { - do_in_path((char_u *)p_rtp, "doc", DIP_ALL + DIP_DIR, helptags_cb, &add_help_tags); + do_in_path(p_rtp, "doc", DIP_ALL + DIP_DIR, helptags_cb, &add_help_tags); } else { ExpandInit(&xpc); xpc.xp_context = EXPAND_DIRECTORIES; dirname = (char *)ExpandOne(&xpc, (char_u *)eap->arg, NULL, WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); - if (dirname == NULL || !os_isdir((char_u *)dirname)) { + if (dirname == NULL || !os_isdir(dirname)) { semsg(_("E150: Not a directory: %s"), eap->arg); } else { do_helptags(dirname, add_help_tags, false); diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index e2d4a81345..ed1f0185b7 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -852,14 +852,14 @@ void do_highlight(const char *line, const bool forceit, const bool init) } // Isolate the name. - name_end = (const char *)skiptowhite((const char_u *)line); + name_end = (const char *)skiptowhite(line); linep = (const char *)skipwhite(name_end); // Check for "default" argument. if (strncmp(line, "default", (size_t)(name_end - line)) == 0) { dodefault = true; line = linep; - name_end = (const char *)skiptowhite((const char_u *)line); + name_end = (const char *)skiptowhite(line); linep = (const char *)skipwhite(name_end); } @@ -891,9 +891,9 @@ void do_highlight(const char *line, const bool forceit, const bool init) int to_id; HlGroup *hlgroup = NULL; - from_end = (const char *)skiptowhite((const char_u *)from_start); + from_end = (const char *)skiptowhite(from_start); to_start = (const char *)skipwhite(from_end); - to_end = (const char *)skiptowhite((const char_u *)to_start); + to_end = (const char *)skiptowhite(to_start); if (ends_excmd((uint8_t)(*from_start)) || ends_excmd((uint8_t)(*to_start))) { @@ -969,7 +969,7 @@ void do_highlight(const char *line, const bool forceit, const bool init) redraw_all_later(UPD_NOT_VALID); return; } - name_end = (const char *)skiptowhite((const char_u *)line); + name_end = (const char *)skiptowhite(line); linep = (const char *)skipwhite(name_end); } @@ -1054,7 +1054,7 @@ void do_highlight(const char *line, const bool forceit, const bool init) } } else { arg_start = linep; - linep = (const char *)skiptowhite((const char_u *)linep); + linep = (const char *)skiptowhite(linep); } if (linep == arg_start) { semsg(_("E417: missing argument: %s"), key_start); @@ -2074,13 +2074,13 @@ void set_context_in_highlight_cmd(expand_T *xp, const char *arg) // (part of) subcommand already typed if (*arg != NUL) { - const char *p = (const char *)skiptowhite((const char_u *)arg); + const char *p = (const char *)skiptowhite(arg); if (*p != NUL) { // Past "default" or group name. include_default = 0; if (strncmp("default", arg, (unsigned)(p - arg)) == 0) { arg = (const char *)skipwhite(p); xp->xp_pattern = (char *)arg; - p = (const char *)skiptowhite((const char_u *)arg); + p = (const char *)skiptowhite(arg); } if (*p != NUL) { // past group name include_link = 0; @@ -2090,10 +2090,10 @@ void set_context_in_highlight_cmd(expand_T *xp, const char *arg) if (strncmp("link", arg, (unsigned)(p - arg)) == 0 || strncmp("clear", arg, (unsigned)(p - arg)) == 0) { xp->xp_pattern = skipwhite(p); - p = (const char *)skiptowhite((char_u *)xp->xp_pattern); + p = (const char *)skiptowhite(xp->xp_pattern); if (*p != NUL) { // Past first group name. xp->xp_pattern = skipwhite(p); - p = (const char *)skiptowhite((char_u *)xp->xp_pattern); + p = (const char *)skiptowhite(xp->xp_pattern); } } if (*p != NUL) { // Past group name(s). diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 2a9d2c357e..9413abb2e1 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -153,10 +153,10 @@ void set_context_in_cscope_cmd(expand_T *xp, const char *arg, cmdidx_T cmdidx) // (part of) subcommand already typed if (*arg != NUL) { - const char *p = (const char *)skiptowhite((const char_u *)arg); + const char *p = (const char *)skiptowhite(arg); if (*p != NUL) { // Past first word. xp->xp_pattern = skipwhite(p); - if (*skiptowhite((char_u *)xp->xp_pattern) != NUL) { + if (*skiptowhite(xp->xp_pattern) != NUL) { xp->xp_context = EXPAND_NOTHING; } else if (STRNICMP(arg, "add", p - arg) == 0) { xp->xp_context = EXPAND_FILES; diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 8ef6667374..166695ef5b 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -676,10 +676,10 @@ static int cin_first_id_amount(void) line = get_cursor_line_ptr(); p = (char_u *)skipwhite((char *)line); - len = (int)(skiptowhite(p) - p); + len = (int)((char_u *)skiptowhite((char *)p) - p); if (len == 6 && STRNCMP(p, "static", 6) == 0) { p = (char_u *)skipwhite((char *)p + 6); - len = (int)(skiptowhite(p) - p); + len = (int)((char_u *)skiptowhite((char *)p) - p); } if (len == 6 && STRNCMP(p, "struct", 6) == 0) { p = (char_u *)skipwhite((char *)p + 6); diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 3c32d0755e..ba0a36cafe 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3767,7 +3767,7 @@ static int get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col) /// Sets the global variables: compl_col, compl_length and compl_pattern. static int get_wholeline_compl_info(char_u *line, colnr_T curs_col) { - compl_col = (colnr_T)getwhitecols(line); + compl_col = (colnr_T)getwhitecols((char *)line); compl_length = (int)curs_col - (int)compl_col; if (compl_length < 0) { // cursor in indent: empty pattern compl_length = 0; @@ -3985,7 +3985,7 @@ static void ins_compl_continue_search(char_u *line) // first non_blank in the line, if it is not a wordchar // include it to get a better pattern, but then we don't // want the "\\<" prefix, check it below. - compl_col = (colnr_T)getwhitecols(line); + compl_col = (colnr_T)getwhitecols((char *)line); compl_startpos.col = compl_col; compl_startpos.lnum = curwin->w_cursor.lnum; compl_cont_status &= ~CONT_SOL; // clear SOL if present diff --git a/src/nvim/locale.c b/src/nvim/locale.c index ba0566011c..3e0774c096 100644 --- a/src/nvim/locale.c +++ b/src/nvim/locale.c @@ -188,7 +188,7 @@ void ex_language(exarg_T *eap) // Check for "messages {name}", "ctype {name}" or "time {name}" argument. // Allow abbreviation, but require at least 3 characters to avoid // confusion with a two letter language name "me" or "ct". - p = (char *)skiptowhite((char_u *)eap->arg); + p = skiptowhite(eap->arg); if ((*p == NUL || ascii_iswhite(*p)) && p - eap->arg >= 3) { if (STRNICMP(eap->arg, "messages", p - eap->arg) == 0) { what = VIM_LC_MESSAGES; diff --git a/src/nvim/log.c b/src/nvim/log.c index 9f25543be7..9bdf327430 100644 --- a/src/nvim/log.c +++ b/src/nvim/log.c @@ -63,13 +63,13 @@ static void log_path_init(void) expand_env("$" ENV_LOGFILE, log_file_path, (int)size - 1); if (strequal("$" ENV_LOGFILE, log_file_path) || log_file_path[0] == '\0' - || os_isdir((char_u *)log_file_path) + || os_isdir(log_file_path) || !log_try_create(log_file_path)) { // Make $XDG_STATE_HOME if it does not exist. char *loghome = get_xdg_home(kXDGStateHome); char *failed_dir = NULL; bool log_dir_failure = false; - if (!os_isdir((char_u *)loghome)) { + if (!os_isdir(loghome)) { log_dir_failure = (os_mkdir_recurse(loghome, 0700, &failed_dir) != 0); } XFREE_CLEAR(loghome); diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 7e8dda6ca1..1b874e673a 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -501,7 +501,7 @@ static int nlua_iconv(lua_State *lstate) vimconv.vc_type = CONV_NONE; convert_setup_ext(&vimconv, from, false, to, false); - char_u *ret = string_convert(&vimconv, (char_u *)str, &str_len); + char_u *ret = (char_u *)string_convert(&vimconv, (char *)str, &str_len); convert_setup(&vimconv, NULL, NULL); diff --git a/src/nvim/main.c b/src/nvim/main.c index 09a387262c..883f946cad 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1342,8 +1342,8 @@ scripterror: ga_grow(&global_alist.al_ga, 1); char *p = xstrdup(argv[0]); - if (parmp->diff_mode && os_isdir((char_u *)p) && GARGCOUNT > 0 - && !os_isdir((char_u *)alist_name(&GARGLIST[0]))) { + if (parmp->diff_mode && os_isdir(p) && GARGCOUNT > 0 + && !os_isdir(alist_name(&GARGLIST[0]))) { char *r = concat_fnames(p, path_tail(alist_name(&GARGLIST[0])), true); xfree(p); p = r; diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 92a7c7c4b0..9df4d416ff 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -922,7 +922,7 @@ static void show_one_mark(int c, char_u *arg, pos_T *p, char_u *name_arg, int cu snprintf((char *)IObuff, IOSIZE, " %c %6" PRIdLINENR " %4d ", c, p->lnum, p->col); msg_outtrans((char *)IObuff); if (name != NULL) { - msg_outtrans_attr(name, current ? HL_ATTR(HLF_D) : 0); + msg_outtrans_attr((char *)name, current ? HL_ATTR(HLF_D) : 0); } } ui_flush(); // show one line at a time @@ -1052,7 +1052,7 @@ void ex_jumps(exarg_T *eap) i > curwin->w_jumplistidx ? i - curwin->w_jumplistidx : curwin->w_jumplistidx - i, curwin->w_jumplist[i].fmark.mark.lnum, curwin->w_jumplist[i].fmark.mark.col); msg_outtrans((char *)IObuff); - msg_outtrans_attr(name, + msg_outtrans_attr((char *)name, curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum ? HL_ATTR(HLF_D) : 0); xfree(name); @@ -1097,7 +1097,7 @@ void ex_changes(exarg_T *eap) curbuf->b_changelist[i].mark.col); msg_outtrans((char *)IObuff); name = mark_line(&curbuf->b_changelist[i].mark, 17); - msg_outtrans_attr(name, HL_ATTR(HLF_D)); + msg_outtrans_attr((char *)name, HL_ATTR(HLF_D)); xfree(name); os_breakcheck(); } diff --git a/src/nvim/match.c b/src/nvim/match.c index cabd008591..48f0d0fc05 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -1183,7 +1183,7 @@ void ex_match(exarg_T *eap) && (ascii_iswhite(eap->arg[4]) || ends_excmd(eap->arg[4])))) { end = (char_u *)eap->arg + 4; } else { - p = skiptowhite((char_u *)eap->arg); + p = (char_u *)skiptowhite(eap->arg); if (!eap->skip) { g = vim_strnsave((char_u *)eap->arg, (size_t)(p - (char_u *)eap->arg)); } diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index e703280032..b874f0dc94 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1942,7 +1942,7 @@ void utf_find_illegal(void) p = get_cursor_pos_ptr(); if (vimconv.vc_type != CONV_NONE) { xfree(tofree); - tofree = string_convert(&vimconv, p, NULL); + tofree = (char_u *)string_convert(&vimconv, (char *)p, NULL); if (tofree == NULL) { break; } @@ -2521,16 +2521,14 @@ int convert_setup_ext(vimconv_T *vcp, char_u *from, bool from_unicode_is_utf8, c return OK; } -/* - * Convert text "ptr[*lenp]" according to "vcp". - * Returns the result in allocated memory and sets "*lenp". - * When "lenp" is NULL, use NUL terminated strings. - * Illegal chars are often changed to "?", unless vcp->vc_fail is set. - * When something goes wrong, NULL is returned and "*lenp" is unchanged. - */ -char_u *string_convert(const vimconv_T *const vcp, char_u *ptr, size_t *lenp) +/// Convert text "ptr[*lenp]" according to "vcp". +/// Returns the result in allocated memory and sets "*lenp". +/// When "lenp" is NULL, use NUL terminated strings. +/// Illegal chars are often changed to "?", unless vcp->vc_fail is set. +/// When something goes wrong, NULL is returned and "*lenp" is unchanged. +char *string_convert(const vimconv_T *const vcp, char *ptr, size_t *lenp) { - return string_convert_ext(vcp, ptr, lenp, NULL); + return (char *)string_convert_ext(vcp, (char_u *)ptr, lenp, NULL); } /* diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 044655ef2b..b0b6b675cb 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -857,7 +857,7 @@ void ml_recover(bool checkext) if ((hp = mf_get(mfp, 0, 1)) == NULL) { msg_start(); msg_puts_attr(_("Unable to read block 0 from "), attr | MSG_HIST); - msg_outtrans_attr(mfp->mf_fname, attr | MSG_HIST); + msg_outtrans_attr((char *)mfp->mf_fname, attr | MSG_HIST); msg_puts_attr(_("\nMaybe no changes were made or Vim did not update the swap file."), attr | MSG_HIST); msg_end(); @@ -866,7 +866,7 @@ void ml_recover(bool checkext) b0p = hp->bh_data; if (STRNCMP(b0p->b0_version, "VIM 3.0", 7) == 0) { msg_start(); - msg_outtrans_attr(mfp->mf_fname, MSG_HIST); + msg_outtrans_attr((char *)mfp->mf_fname, MSG_HIST); msg_puts_attr(_(" cannot be used with this version of Vim.\n"), MSG_HIST); msg_puts_attr(_("Use Vim version 3.0.\n"), MSG_HIST); @@ -879,7 +879,7 @@ void ml_recover(bool checkext) } if (b0_magic_wrong(b0p)) { msg_start(); - msg_outtrans_attr(mfp->mf_fname, attr | MSG_HIST); + msg_outtrans_attr((char *)mfp->mf_fname, attr | MSG_HIST); msg_puts_attr(_(" cannot be used on this computer.\n"), attr | MSG_HIST); msg_puts_attr(_("The file was created on "), attr | MSG_HIST); @@ -901,7 +901,7 @@ void ml_recover(bool checkext) mf_new_page_size(mfp, (unsigned)char_to_long(b0p->b0_page_size)); if (mfp->mf_page_size < previous_page_size) { msg_start(); - msg_outtrans_attr(mfp->mf_fname, attr | MSG_HIST); + msg_outtrans_attr((char *)mfp->mf_fname, attr | MSG_HIST); msg_puts_attr(_(" has been damaged (page size is smaller than minimum value).\n"), attr | MSG_HIST); msg_end(); @@ -3614,7 +3614,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ fname[n - 1]--; // ".swo", ".swn", etc. } - if (os_isdir((char_u *)dir_name)) { + if (os_isdir(dir_name)) { *found_existing_dir = true; } else if (!*found_existing_dir && **dirp == NUL) { int ret; diff --git a/src/nvim/menu.c b/src/nvim/menu.c index b1d729f71d..cb6918cd27 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -853,7 +853,7 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth) msg_puts(" "); } // Same highlighting as for directories!? - msg_outtrans_attr((char_u *)menu->name, HL_ATTR(HLF_D)); + msg_outtrans_attr(menu->name, HL_ATTR(HLF_D)); } if (menu != NULL && menu->children == NULL) { diff --git a/src/nvim/message.c b/src/nvim/message.c index 4fba78feca..80b5f53f4e 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -265,7 +265,7 @@ void msg_multiline_attr(const char *s, int attr, bool check_int, bool *need_clea // Print the rest of the message. We know there is no special // character because strpbrk returned NULL if (*s != NUL) { - msg_outtrans_attr((char_u *)s, attr); + msg_outtrans_attr(s, attr); } } @@ -325,7 +325,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) // Add message to history (unless it's a repeated kept message or a // truncated message) - if ((const char_u *)s != keep_msg + if (s != keep_msg || (*s != '<' && last_msg_hist != NULL && last_msg_hist->msg != NULL @@ -344,7 +344,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) if (multiline) { msg_multiline_attr(s, attr, false, &need_clear); } else { - msg_outtrans_attr((char_u *)s, attr); + msg_outtrans_attr(s, attr); } if (need_clear) { msg_clr_eos(); @@ -1307,7 +1307,7 @@ void wait_return(int redraw) emsg_on_display = false; // can delete error message now lines_left = -1; // reset lines_left at next msg_start() reset_last_sourcing(); - if (keep_msg != NULL && vim_strsize((char *)keep_msg) >= + if (keep_msg != NULL && vim_strsize(keep_msg) >= (Rows - cmdline_row - 1) * Columns + sc_col) { XFREE_CLEAR(keep_msg); // don't redisplay message, it's too long } @@ -1350,7 +1350,7 @@ void set_keep_msg(char *s, int attr) { xfree(keep_msg); if (s != NULL && msg_silent == 0) { - keep_msg = vim_strsave((char_u *)s); + keep_msg = xstrdup(s); } else { keep_msg = NULL; } @@ -1510,7 +1510,7 @@ void msg_home_replace_hl(char_u *fname) static void msg_home_replace_attr(char_u *fname, int attr) { char *name = home_replace_save(NULL, (char *)fname); - msg_outtrans_attr((char_u *)name, attr); + msg_outtrans_attr(name, attr); xfree(name); } @@ -1521,29 +1521,29 @@ static void msg_home_replace_attr(char_u *fname, int attr) /// @return the number of characters it takes on the screen. int msg_outtrans(char *str) { - return msg_outtrans_attr((char_u *)str, 0); + return msg_outtrans_attr(str, 0); } -int msg_outtrans_attr(const char_u *str, int attr) +int msg_outtrans_attr(const char *str, int attr) { - return msg_outtrans_len_attr(str, (int)STRLEN(str), attr); + return msg_outtrans_len_attr((char_u *)str, (int)STRLEN(str), attr); } -int msg_outtrans_len(const char_u *str, int len) +int msg_outtrans_len(const char *str, int len) { - return msg_outtrans_len_attr(str, len, 0); + return msg_outtrans_len_attr((char_u *)str, len, 0); } /// Output one character at "p". /// Handles multi-byte characters. /// /// @return pointer to the next character. -char_u *msg_outtrans_one(char_u *p, int attr) +char *msg_outtrans_one(char *p, int attr) { int l; - if ((l = utfc_ptr2len((char *)p)) > 1) { - msg_outtrans_len_attr(p, l, attr); + if ((l = utfc_ptr2len(p)) > 1) { + msg_outtrans_len_attr((char_u *)p, l, attr); return p + l; } msg_puts_attr((const char *)transchar_byte(*p), attr); @@ -1628,12 +1628,13 @@ int msg_outtrans_len_attr(const char_u *msgstr, int len, int attr) return retval; } -void msg_make(char_u *arg) +void msg_make(char *arg) { int i; - static char_u *str = (char_u *)"eeffoc", *rs = (char_u *)"Plon#dqg#vxjduB"; + static char *str = "eeffoc"; + static char *rs = "Plon#dqg#vxjduB"; - arg = (char_u *)skipwhite((char *)arg); + arg = skipwhite(arg); for (i = 5; *arg && i >= 0; i--) { if (*arg++ != str[i]) { break; @@ -1976,13 +1977,13 @@ void msg_prt_line(char_u *s, int list) /// Use grid_puts() to output one multi-byte character. /// /// @return the pointer "s" advanced to the next character. -static char_u *screen_puts_mbyte(char_u *s, int l, int attr) +static char *screen_puts_mbyte(char *s, int l, int attr) { int cw; attr = hl_combine_attr(HL_ATTR(HLF_MSG), attr); msg_didout = true; // remember that line is not empty - cw = utf_ptr2cells((char *)s); + cw = utf_ptr2cells(s); if (cw > 1 && (cmdmsg_rl ? msg_col <= 1 : msg_col == Columns - 1)) { // Doesn't fit, print a highlighted '>' to fill it up. @@ -1990,7 +1991,7 @@ static char_u *screen_puts_mbyte(char_u *s, int l, int attr) return s; } - grid_puts_len(&msg_grid_adj, (char *)s, l, msg_row, msg_col, attr); + grid_puts_len(&msg_grid_adj, s, l, msg_row, msg_col, attr); if (cmdmsg_rl) { msg_col -= cw; if (msg_col == 0) { @@ -2197,7 +2198,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs // ourselves). if (t_col > 0) { // output postponed text - t_puts(&t_col, t_s, s, attr); + t_puts(&t_col, (char *)t_s, (char *)s, attr); } // When no more prompt and no more room, truncate here @@ -2222,7 +2223,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs } else { l = utfc_ptr2len((char *)s); } - s = screen_puts_mbyte((char_u *)s, l, attr); + s = (char_u *)screen_puts_mbyte((char *)s, l, attr); did_last_char = true; } else { did_last_char = false; @@ -2281,7 +2282,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs if (t_col > 0 && (wrap || *s == '\r' || *s == '\b' || *s == '\t' || *s == BELL)) { // Output any postponed text. - t_puts(&t_col, t_s, s, attr); + t_puts(&t_col, (char *)t_s, (char *)s, attr); } if (wrap && p_more && !recurse) { @@ -2324,7 +2325,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs // characters and draw them all at once later. if (cmdmsg_rl || (cw > 1 && msg_col + t_col >= Columns - 1)) { if (l > 1) { - s = screen_puts_mbyte((char_u *)s, l, attr) - 1; + s = (char_u *)screen_puts_mbyte((char *)s, l, attr) - 1; } else { msg_screen_putchar(*s, attr); } @@ -2342,7 +2343,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs // Output any postponed text. if (t_col > 0) { - t_puts(&t_col, t_s, s, attr); + t_puts(&t_col, (char *)t_s, (char *)s, attr); } if (p_more && !recurse) { store_sb_text((char **)&sb_str, (char *)s, attr, &sb_col, false); @@ -2698,7 +2699,7 @@ static msgchunk_T *disp_sb_line(int row, msgchunk_T *smp) } /// Output any postponed text for msg_puts_attr_len(). -static void t_puts(int *t_col, const char_u *t_s, const char_u *s, int attr) +static void t_puts(int *t_col, const char *t_s, const char *s, int attr) { attr = hl_combine_attr(HL_ATTR(HLF_MSG), attr); // Output postponed text. @@ -2708,7 +2709,7 @@ static void t_puts(int *t_col, const char_u *t_s, const char_u *s, int attr) *t_col = 0; // If the string starts with a composing character don't increment the // column position for it. - if (utf_iscomposing(utf_ptr2char((char *)t_s))) { + if (utf_iscomposing(utf_ptr2char(t_s))) { msg_col--; } if (msg_col >= Columns) { diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 6430070f1b..47ad000385 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -631,16 +631,16 @@ static void normal_redraw_mode_message(NormalState *s) if (must_redraw && keep_msg != NULL && !emsg_on_display) { char_u *kmsg; - kmsg = keep_msg; + kmsg = (char_u *)keep_msg; keep_msg = NULL; // Showmode() will clear keep_msg, but we want to use it anyway. // First update w_topline. setcursor(); update_screen(0); // now reset it, otherwise it's put in the history again - keep_msg = kmsg; + keep_msg = (char *)kmsg; - kmsg = vim_strsave(keep_msg); + kmsg = vim_strsave((char_u *)keep_msg); msg_attr((const char *)kmsg, keep_msg_attr); xfree(kmsg); } @@ -1302,7 +1302,7 @@ static void normal_redraw(NormalState *s) // Display message after redraw. If an external message is still visible, // it contains the kept message already. if (keep_msg != NULL && !msg_ext_is_visible()) { - char_u *const p = vim_strsave(keep_msg); + char *const p = xstrdup(keep_msg); // msg_start() will set keep_msg to NULL, make a copy // first. Don't reset keep_msg, msg_attr_keep() uses it to diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 7b6f9e6370..4f2b84d20f 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2500,7 +2500,7 @@ int op_change(oparg_T *oap) } firstline = ml_get(oap->start.lnum); pre_textlen = (long)STRLEN(firstline); - pre_indent = (long)getwhitecols(firstline); + pre_indent = (long)getwhitecols((char *)firstline); bd.textcol = curwin->w_cursor.col; } @@ -2521,7 +2521,7 @@ int op_change(oparg_T *oap) // the indent, exclude that indent change from the inserted text. firstline = ml_get(oap->start.lnum); if (bd.textcol > (colnr_T)pre_indent) { - long new_indent = (long)getwhitecols(firstline); + long new_indent = (long)getwhitecols((char *)firstline); pre_textlen += new_indent - pre_indent; bd.textcol += (colnr_T)(new_indent - pre_indent); @@ -3860,7 +3860,7 @@ void ex_display(exarg_T *eap) for (p = (char_u *)yb->y_array[j]; *p != NUL && (n -= ptr2cells((char *)p)) >= 0; p++) { // -V1019 clen = utfc_ptr2len((char *)p); - msg_outtrans_len(p, clen); + msg_outtrans_len((char *)p, clen); p += clen - 1; } } @@ -3938,10 +3938,10 @@ static void dis_msg(const char_u *p, bool skip_esc) && !(*p == ESC && skip_esc && *(p + 1) == NUL) && (n -= ptr2cells((char *)p)) >= 0) { if ((l = utfc_ptr2len((char *)p)) > 1) { - msg_outtrans_len(p, l); + msg_outtrans_len((char *)p, l); p += l; } else { - msg_outtrans_len(p++, 1); + msg_outtrans_len((char *)p++, 1); } } os_breakcheck(); diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 274e13e3c6..c940c86675 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -765,12 +765,12 @@ static char *vim_version_dir(const char *vimdir) return NULL; } char *p = concat_fnames(vimdir, VIM_VERSION_NODOT, true); - if (os_isdir((char_u *)p)) { + if (os_isdir(p)) { return p; } xfree(p); p = concat_fnames(vimdir, RUNTIME_DIRNAME, true); - if (os_isdir((char_u *)p)) { + if (os_isdir(p)) { return p; } xfree(p); @@ -976,7 +976,7 @@ char *vim_getenv(const char *name) assert(vim_path_end >= vim_path); vim_path = xstrndup(vim_path, (size_t)(vim_path_end - vim_path)); - if (!os_isdir((char_u *)vim_path)) { + if (!os_isdir(vim_path)) { xfree(vim_path); vim_path = NULL; } diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index dc96c39d25..c0d5616666 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -129,10 +129,10 @@ bool os_isrealdir(const char *name) /// Check if the given path exists and is a directory. /// /// @return `true` if `name` is a directory. -bool os_isdir(const char_u *name) +bool os_isdir(const char *name) FUNC_ATTR_NONNULL_ALL { - int32_t mode = os_getperm((const char *)name); + int32_t mode = os_getperm(name); if (mode < 0) { return false; } @@ -865,7 +865,7 @@ int os_file_is_writable(const char *name) int r; RUN_UV_FS_FUNC(r, uv_fs_access, name, W_OK, NULL); if (r == 0) { - return os_isdir((char_u *)name) ? 2 : 1; + return os_isdir(name) ? 2 : 1; } return 0; } @@ -915,7 +915,7 @@ int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_di char *e = curdir + dirlen; const char *const real_end = e; const char past_head_save = *past_head; - while (!os_isdir((char_u *)curdir)) { + while (!os_isdir(curdir)) { e = path_tail_with_sep(curdir); if (e <= past_head) { *past_head = NUL; diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index c8267ede14..461a79c37b 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -55,7 +55,7 @@ static void save_patterns(int num_pat, char **pat, int *num_file, char ***file) char_u *s = vim_strsave((char_u *)pat[i]); // Be compatible with expand_filename(): halve the number of // backslashes. - backslash_halve(s); + backslash_halve((char *)s); (*file)[i] = (char *)s; } *num_file = num_pat; @@ -508,7 +508,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in } // check if this entry should be included - dir = (os_isdir((char_u *)(*file)[i])); + dir = (os_isdir((*file)[i])); if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) { continue; } diff --git a/src/nvim/path.c b/src/nvim/path.c index e40729b114..a5cec6772f 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -326,7 +326,7 @@ bool dir_of_file_exists(char_u *fname) } char c = *p; *p = NUL; - bool retval = os_isdir(fname); + bool retval = os_isdir((char *)fname); *p = c; return retval; } @@ -752,7 +752,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, // no more wildcards, check if there is a match // remove backslashes for the remaining components only if (*path_end != NUL) { - backslash_halve(buf + len + 1); + backslash_halve((char *)buf + len + 1); } // add existing file or symbolic link if ((flags & EW_ALLLINKS) ? os_fileinfo_link((char *)buf, &file_info) @@ -1135,7 +1135,7 @@ static int expand_in_path(garray_T *const gap, char_u *const pattern, const int if (flags & EW_ADDSLASH) { glob_flags |= WILD_ADD_SLASH; } - globpath((char *)paths, pattern, gap, glob_flags); + globpath((char *)paths, (char *)pattern, gap, glob_flags); xfree(paths); return gap->ga_len; @@ -1312,7 +1312,7 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i } if (add_pat == -1 || (add_pat == 0 && (flags & EW_NOTFOUND))) { - char_u *t = backslash_halve_save(p); + char_u *t = (char_u *)backslash_halve_save((char *)p); /* When EW_NOTFOUND is used, always add files and dirs. Makes * "vim c:/" work. */ @@ -1472,7 +1472,7 @@ void addfile(garray_T *gap, char_u *f, int flags) } #endif - isdir = os_isdir(f); + isdir = os_isdir((char *)f); if ((isdir && !(flags & EW_DIR)) || (!isdir && !(flags & EW_FILE))) { return; } @@ -1845,7 +1845,7 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force) return OK; } - int rv = path_to_absolute((char_u *)fname, (char_u *)buf, len, force); + int rv = path_to_absolute(fname, buf, len, force); if (rv == FAIL) { xstrlcpy(buf, fname, len); // something failed; use the filename } @@ -1904,7 +1904,7 @@ void path_fix_case(char *name) } // Open the directory where the file is located. - char *slash = (char *)STRRCHR(name, '/'); + char *slash = strrchr(name, '/'); char *tail; Directory dir; bool ok; @@ -2139,7 +2139,7 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char ***file, int flags) true); emsg_off--; if (eval_pat != NULL) { - exp_pat = (char *)concat_str(eval_pat, (char_u *)exp_pat + usedlen); + exp_pat = concat_str((char *)eval_pat, exp_pat + usedlen); } } @@ -2353,20 +2353,20 @@ int append_path(char *path, const char *to_append, size_t max_len) /// @param force also expand when "fname" is already absolute. /// /// @return FAIL for failure, OK for success. -static int path_to_absolute(const char_u *fname, char_u *buf, size_t len, int force) +static int path_to_absolute(const char *fname, char *buf, size_t len, int force) { - char_u *p; + char *p; *buf = NUL; char *relative_directory = xmalloc(len); char *end_of_path = (char *)fname; // expand it if forced or not an absolute path - if (force || !path_is_absolute(fname)) { - p = STRRCHR(fname, '/'); + if (force || !path_is_absolute((char_u *)fname)) { + p = strrchr(fname, '/'); #ifdef WIN32 if (p == NULL) { - p = STRRCHR(fname, '\\'); + p = strrchr(fname, '\\'); } #endif if (p != NULL) { @@ -2380,19 +2380,19 @@ static int path_to_absolute(const char_u *fname, char_u *buf, size_t len, int fo memcpy(relative_directory, fname, (size_t)(p - fname)); relative_directory[p - fname] = NUL; } - end_of_path = (char *)(p + 1); + end_of_path = p + 1; } else { relative_directory[0] = NUL; end_of_path = (char *)fname; } - if (FAIL == path_full_dir_name(relative_directory, (char *)buf, len)) { + if (FAIL == path_full_dir_name(relative_directory, buf, len)) { xfree(relative_directory); return FAIL; } } xfree(relative_directory); - return append_path((char *)buf, end_of_path, len); + return append_path(buf, end_of_path, len); } /// Check if file `fname` is a full (absolute) path. diff --git a/src/nvim/plines.c b/src/nvim/plines.c index 11b6951edd..cc730ba307 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -262,7 +262,7 @@ int linetabsize_col(int startcol, char *s) cts.cts_vcol += lbr_chartabsize_adv(&cts); } clear_chartabsize_arg(&cts); - return (int)cts.cts_vcol; + return cts.cts_vcol; } /// Like linetabsize(), but for a given window instead of the current one. @@ -530,7 +530,7 @@ static int win_nolbr_chartabsize(chartabsize_T *cts, int *headp) wp->w_buffer->b_p_ts, wp->w_buffer->b_p_vts_array); } - n = ptr2cells((char *)s); + n = ptr2cells(s); // Add one cell for a double-width character in the last column of the // window, displayed with a ">". diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index b144348188..0d9080ceb7 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -524,7 +524,7 @@ void pum_redraw(void) } if (pum_rl) { - char *rt = (char *)reverse_text(st); + char *rt = reverse_text((char *)st); char *rt_start = rt; int size = vim_strsize(rt); diff --git a/src/nvim/profile.c b/src/nvim/profile.c index d4f3756f4d..cded231c85 100644 --- a/src/nvim/profile.c +++ b/src/nvim/profile.c @@ -279,7 +279,7 @@ void ex_profile(exarg_T *eap) char *e; int len; - e = (char *)skiptowhite((char_u *)eap->arg); + e = skiptowhite(eap->arg); len = (int)(e - eap->arg); e = skipwhite(e); @@ -354,7 +354,7 @@ void set_context_in_profile_cmd(expand_T *xp, const char *arg) pexpand_what = PEXP_SUBCMD; xp->xp_pattern = (char *)arg; - char_u *const end_subcmd = skiptowhite((const char_u *)arg); + char_u *const end_subcmd = (char_u *)skiptowhite(arg); if (*end_subcmd == NUL) { return; } @@ -612,7 +612,7 @@ static void func_dump_profile(FILE *fd) .script_ctx = fp->uf_script_ctx, .channel_id = 0, }; - char *p = (char *)get_scriptname(last_set, &should_free); + char *p = get_scriptname(last_set, &should_free); fprintf(fd, " Defined: %s:%" PRIdLINENR "\n", p, fp->uf_script_ctx.sc_lnum); if (should_free) { @@ -721,7 +721,7 @@ static void script_dump_profile(FILE *fd) fprintf(fd, "\n"); fprintf(fd, "count total (s) self (s)\n"); - sfd = os_fopen((char *)si->sn_name, "r"); + sfd = os_fopen(si->sn_name, "r"); if (sfd == NULL) { fprintf(fd, "Cannot open file!\n"); } else { diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 20e6893ea5..f9c4892b91 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -799,7 +799,7 @@ retry: // Convert a line if it contains a non-ASCII character if (state->vc.vc_type != CONV_NONE && has_non_ascii((char_u *)state->linebuf)) { - char *line = (char *)string_convert(&state->vc, (char_u *)state->linebuf, &state->linelen); + char *line = string_convert(&state->vc, state->linebuf, &state->linelen); if (line != NULL) { if (state->linelen < IOSIZE) { STRLCPY(state->linebuf, line, state->linelen + 1); @@ -2129,7 +2129,7 @@ static char *qf_push_dir(char *dirbuf, struct dir_stack_T **stackptr, bool is_fi while (ds_new) { xfree((*stackptr)->dirname); (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf, true); - if (os_isdir((char_u *)(*stackptr)->dirname)) { + if (os_isdir((*stackptr)->dirname)) { break; } @@ -3054,7 +3054,7 @@ static void qf_list_entry(qfline_T *qfp, int qf_idx, bool cursel) } msg_putchar('\n'); - msg_outtrans_attr(IObuff, cursel ? HL_ATTR(HLF_QFL) : qfFileAttr); + msg_outtrans_attr((char *)IObuff, cursel ? HL_ATTR(HLF_QFL) : qfFileAttr); if (qfp->qf_lnum != 0) { msg_puts_attr(":", qfSepAttr); diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 41056a2773..e85167f8fd 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -123,7 +123,7 @@ char *estack_sfile(estack_arg_T which) ? &entry->es_info.ufunc->uf_script_ctx : &entry->es_info.aucmd->script_ctx); return def_ctx->sc_sid > 0 - ? xstrdup((char *)(SCRIPT_ITEM(def_ctx->sc_sid).sn_name)) + ? xstrdup((SCRIPT_ITEM(def_ctx->sc_sid).sn_name)) : NULL; } else if (entry->es_type == ETYPE_SCRIPT) { return xstrdup(entry->es_name); @@ -192,7 +192,7 @@ void runtime_init(void) void ex_runtime(exarg_T *eap) { char *arg = eap->arg; - char *p = (char *)skiptowhite((char_u *)arg); + char *p = skiptowhite(arg); ptrdiff_t len = p - arg; int flags = eap->forceit ? DIP_ALL : 0; @@ -226,9 +226,9 @@ static void source_callback(char *fname, void *cookie) /// When "flags" has DIP_ERR: give an error message if there is no match. /// /// return FAIL when no file could be sourced, OK otherwise. -int do_in_path(char_u *path, char *name, int flags, DoInRuntimepathCB callback, void *cookie) +int do_in_path(char *path, char *name, int flags, DoInRuntimepathCB callback, void *cookie) { - char_u *tail; + char *tail; int num_files; char **files; int i; @@ -236,17 +236,17 @@ int do_in_path(char_u *path, char *name, int flags, DoInRuntimepathCB callback, // Make a copy of 'runtimepath'. Invoking the callback may change the // value. - char_u *rtp_copy = vim_strsave(path); + char *rtp_copy = xstrdup(path); char *buf = xmallocz(MAXPATHL); { if (p_verbose > 10 && name != NULL) { verbose_enter(); - smsg(_("Searching for \"%s\" in \"%s\""), name, (char *)path); + smsg(_("Searching for \"%s\" in \"%s\""), name, path); verbose_leave(); } // Loop over all entries in 'runtimepath'. - char *rtp = (char *)rtp_copy; + char *rtp = rtp_copy; while (*rtp != NUL && ((flags & DIP_ALL) || !did_one)) { // Copy the path from 'runtimepath' to buf[]. copy_option_part(&rtp, buf, MAXPATHL, ","); @@ -267,14 +267,14 @@ int do_in_path(char_u *path, char *name, int flags, DoInRuntimepathCB callback, did_one = true; } else if (buflen + STRLEN(name) + 2 < MAXPATHL) { add_pathsep(buf); - tail = (char_u *)buf + STRLEN(buf); + tail = buf + STRLEN(buf); // Loop over all patterns in "name" char *np = name; while (*np != NUL && ((flags & DIP_ALL) || !did_one)) { // Append the pattern from "name" to buf[]. - assert(MAXPATHL >= (tail - (char_u *)buf)); - copy_option_part(&np, (char *)tail, (size_t)(MAXPATHL - (tail - (char_u *)buf)), "\t "); + assert(MAXPATHL >= (tail - buf)); + copy_option_part(&np, tail, (size_t)(MAXPATHL - (tail - buf)), "\t "); if (p_verbose > 10) { verbose_enter(); @@ -303,7 +303,7 @@ int do_in_path(char_u *path, char *name, int flags, DoInRuntimepathCB callback, xfree(buf); xfree(rtp_copy); if (!did_one && name != NULL) { - char *basepath = path == (char_u *)p_rtp ? "runtimepath" : "packpath"; + char *basepath = path == p_rtp ? "runtimepath" : "packpath"; if (flags & DIP_ERR) { semsg(_(e_dirnotf), basepath, name); @@ -363,19 +363,19 @@ void runtime_search_path_unref(RuntimeSearchPath path, int *ref) /// When "flags" has DIP_ERR: give an error message if there is no match. /// /// return FAIL when no file could be sourced, OK otherwise. -int do_in_cached_path(char_u *name, int flags, DoInRuntimepathCB callback, void *cookie) +int do_in_cached_path(char *name, int flags, DoInRuntimepathCB callback, void *cookie) { - char_u *tail; + char *tail; int num_files; char **files; int i; bool did_one = false; - char_u buf[MAXPATHL]; + char buf[MAXPATHL]; if (p_verbose > 10 && name != NULL) { verbose_enter(); - smsg(_("Searching for \"%s\" in runtime path"), (char *)name); + smsg(_("Searching for \"%s\" in runtime path"), name); verbose_leave(); } @@ -399,15 +399,15 @@ int do_in_cached_path(char_u *name, int flags, DoInRuntimepathCB callback, void (*callback)(item.path, cookie); } else if (buflen + STRLEN(name) + 2 < MAXPATHL) { STRCPY(buf, item.path); - add_pathsep((char *)buf); + add_pathsep(buf); tail = buf + STRLEN(buf); // Loop over all patterns in "name" - char *np = (char *)name; + char *np = name; while (*np != NUL && ((flags & DIP_ALL) || !did_one)) { // Append the pattern from "name" to buf[]. assert(MAXPATHL >= (tail - buf)); - copy_option_part(&np, (char *)tail, (size_t)(MAXPATHL - (tail - buf)), "\t "); + copy_option_part(&np, tail, (size_t)(MAXPATHL - (tail - buf)), "\t "); if (p_verbose > 10) { verbose_enter(); @@ -419,7 +419,7 @@ int do_in_cached_path(char_u *name, int flags, DoInRuntimepathCB callback, void | (flags & DIP_DIRFILE) ? (EW_DIR|EW_FILE) : 0; // Expand wildcards, invoke the callback for each match. - char *(pat[]) = { (char *)buf }; + char *(pat[]) = { buf }; if (gen_expand_wildcards(1, pat, &num_files, &files, ew_flags) == OK) { for (i = 0; i < num_files; i++) { (*callback)(files[i], cookie); @@ -499,7 +499,7 @@ ArrayOf(String) runtime_get_named_common(bool lua, Array pat, bool all, if (lua) { if (item->has_lua == kNone) { size_t size = (size_t)snprintf(buf, buf_len, "%s/lua/", item->path); - item->has_lua = (size < buf_len && os_isdir((char_u *)buf)); + item->has_lua = (size < buf_len && os_isdir(buf)); } if (item->has_lua == kFalse) { continue; @@ -534,13 +534,13 @@ done: /// If "name" is NULL calls callback for each entry in "path". Cookie is /// passed by reference in this case, setting it to NULL indicates that callback /// has done its job. -int do_in_path_and_pp(char_u *path, char_u *name, int flags, DoInRuntimepathCB callback, - void *cookie) +int do_in_path_and_pp(char *path, char *name, int flags, DoInRuntimepathCB callback, void *cookie) { int done = FAIL; if ((flags & DIP_NORTP) == 0) { - done |= do_in_path(path, (char *)((name && !*name) ? NULL : name), flags, callback, cookie); + done |= do_in_path(path, (name && !*name) ? NULL : name, flags, callback, + cookie); } if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START)) { @@ -550,7 +550,7 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, DoInRuntimepathCB c char *suffix = (flags & DIP_AFTER) ? "after/" : ""; vim_snprintf(s, len, start_dir, suffix, name); - done |= do_in_path((char_u *)p_pp, s, flags & ~DIP_AFTER, callback, cookie); + done |= do_in_path(p_pp, s, flags & ~DIP_AFTER, callback, cookie); xfree(s); @@ -560,7 +560,7 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, DoInRuntimepathCB c s = xmallocz(len); vim_snprintf(s, len, start_dir, suffix, name); - done |= do_in_path((char_u *)p_pp, s, flags & ~DIP_AFTER, callback, cookie); + done |= do_in_path(p_pp, s, flags & ~DIP_AFTER, callback, cookie); xfree(s); } @@ -572,7 +572,7 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, DoInRuntimepathCB c char *s = xmallocz(len); vim_snprintf(s, len, opt_dir, name); - done |= do_in_path((char_u *)p_pp, s, flags, callback, cookie); + done |= do_in_path(p_pp, s, flags, callback, cookie); xfree(s); @@ -582,7 +582,7 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, DoInRuntimepathCB c s = xmallocz(len); vim_snprintf(s, len, opt_dir, name); - done |= do_in_path((char_u *)p_pp, s, flags, callback, cookie); + done |= do_in_path(p_pp, s, flags, callback, cookie); xfree(s); } @@ -625,7 +625,7 @@ static void expand_rtp_entry(RuntimeSearchPath *search_path, Map(String, handle_ } static void expand_pack_entry(RuntimeSearchPath *search_path, Map(String, handle_T) *rtp_used, - CharVec *after_path, char_u *pack_entry, size_t pack_entry_len) + CharVec *after_path, char *pack_entry, size_t pack_entry_len) { static char buf[MAXPATHL]; char *(start_pat[]) = { "/pack/*/start/*", "/start/*" }; // NOLINT @@ -664,10 +664,10 @@ RuntimeSearchPath runtime_search_path_build(void) RuntimeSearchPath search_path = KV_INITIAL_VALUE; CharVec after_path = KV_INITIAL_VALUE; - static char_u buf[MAXPATHL]; + static char buf[MAXPATHL]; for (char *entry = p_pp; *entry != NUL;) { char *cur_entry = entry; - copy_option_part(&entry, (char *)buf, MAXPATHL, ","); + copy_option_part(&entry, buf, MAXPATHL, ","); String the_entry = { .data = cur_entry, .size = STRLEN(buf) }; @@ -678,18 +678,18 @@ RuntimeSearchPath runtime_search_path_build(void) char *rtp_entry; for (rtp_entry = p_rtp; *rtp_entry != NUL;) { char *cur_entry = rtp_entry; - copy_option_part(&rtp_entry, (char *)buf, MAXPATHL, ","); + copy_option_part(&rtp_entry, buf, MAXPATHL, ","); size_t buflen = STRLEN(buf); - if (path_is_after((char *)buf, buflen)) { + if (path_is_after(buf, buflen)) { rtp_entry = cur_entry; break; } // fact: &rtp entries can contain wild chars - expand_rtp_entry(&search_path, &rtp_used, (char *)buf, false); + expand_rtp_entry(&search_path, &rtp_used, buf, false); - handle_T *h = map_ref(String, handle_T)(&pack_used, cstr_as_string((char *)buf), false); + handle_T *h = map_ref(String, handle_T)(&pack_used, cstr_as_string(buf), false); if (h) { (*h)++; expand_pack_entry(&search_path, &rtp_used, &after_path, buf, buflen); @@ -700,7 +700,7 @@ RuntimeSearchPath runtime_search_path_build(void) String item = kv_A(pack_entries, i); handle_T h = map_get(String, handle_T)(&pack_used, item); if (h == 0) { - expand_pack_entry(&search_path, &rtp_used, &after_path, (char_u *)item.data, item.size); + expand_pack_entry(&search_path, &rtp_used, &after_path, item.data, item.size); } } @@ -712,8 +712,8 @@ RuntimeSearchPath runtime_search_path_build(void) // "after" dirs in rtp for (; *rtp_entry != NUL;) { - copy_option_part(&rtp_entry, (char *)buf, MAXPATHL, ","); - expand_rtp_entry(&search_path, &rtp_used, (char *)buf, path_is_after((char *)buf, STRLEN(buf))); + copy_option_part(&rtp_entry, buf, MAXPATHL, ","); + expand_rtp_entry(&search_path, &rtp_used, buf, path_is_after(buf, STRLEN(buf))); } // strings are not owned @@ -767,13 +767,13 @@ int do_in_runtimepath(char *name, int flags, DoInRuntimepathCB callback, void *c { int success = FAIL; if (!(flags & DIP_NORTP)) { - success |= do_in_cached_path((name && !*name) ? NULL : (char_u *)name, flags, callback, cookie); + success |= do_in_cached_path((name && !*name) ? NULL : name, flags, callback, cookie); flags = (flags & ~DIP_START) | DIP_NORTP; } // TODO(bfredl): we could integrate disabled OPT dirs into the cached path // which would effectivize ":packadd myoptpack" as well if ((flags & (DIP_START|DIP_OPT)) && (success == FAIL || (flags & DIP_ALL))) { - success |= do_in_path_and_pp((char_u *)p_rtp, (char_u *)name, flags, callback, cookie); + success |= do_in_path_and_pp(p_rtp, name, flags, callback, cookie); } return success; } @@ -789,7 +789,7 @@ int source_runtime(char *name, int flags) } /// Just like source_runtime(), but use "path" instead of 'runtimepath'. -int source_in_path(char_u *path, char_u *name, int flags) +int source_in_path(char *path, char *name, int flags) { return do_in_path_and_pp(path, name, flags, source_callback, NULL); } @@ -813,14 +813,14 @@ static void source_all_matches(char *pat) /// /// @param fname the package path /// @param is_pack whether the added dir is a "pack/*/start/*/" style package -static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) +static int add_pack_dir_to_rtp(char *fname, bool is_pack) { char *p; char *buf = NULL; char *afterdir = NULL; int retval = FAIL; - char *p1 = get_past_head((char *)fname); + char *p1 = get_past_head(fname); char *p2 = p1; char *p3 = p1; char *p4 = p1; @@ -841,7 +841,7 @@ static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) p4++; // append pathsep in order to expand symlink char c = *p4; *p4 = NUL; - char *const ffname = fix_fname((char *)fname); + char *const ffname = fix_fname(fname); *p4 = c; if (ffname == NULL) { @@ -895,9 +895,9 @@ static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) } // check if rtp/pack/name/start/name/after exists - afterdir = concat_fnames((char *)fname, "after", true); + afterdir = concat_fnames(fname, "after", true); size_t afterlen = 0; - if (is_pack ? pack_has_entries((char_u *)afterdir) : os_isdir((char_u *)afterdir)) { + if (is_pack ? pack_has_entries(afterdir) : os_isdir(afterdir)) { afterlen = strlen(afterdir) + 1; // add one for comma } @@ -964,29 +964,29 @@ theend: /// Load scripts in "plugin" directory of the package. /// For opt packages, also load scripts in "ftdetect" (start packages already /// load these from filetype.vim) -static int load_pack_plugin(bool opt, char_u *fname) +static int load_pack_plugin(bool opt, char *fname) { static const char *ftpat = "%s/ftdetect/*.vim"; // NOLINT - char *const ffname = fix_fname((char *)fname); + char *const ffname = fix_fname(fname); size_t len = strlen(ffname) + STRLEN(ftpat); - char_u *pat = xmallocz(len); + char *pat = xmallocz(len); - vim_snprintf((char *)pat, len, "%s/plugin/**/*.vim", ffname); // NOLINT - source_all_matches((char *)pat); - vim_snprintf((char *)pat, len, "%s/plugin/**/*.lua", ffname); // NOLINT - source_all_matches((char *)pat); + vim_snprintf(pat, len, "%s/plugin/**/*.vim", ffname); // NOLINT + source_all_matches(pat); + vim_snprintf(pat, len, "%s/plugin/**/*.lua", ffname); // NOLINT + source_all_matches(pat); - char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes"); + char *cmd = xstrdup("g:did_load_filetypes"); // If runtime/filetype.vim wasn't loaded yet, the scripts will be // found when it loads. - if (opt && eval_to_number((char *)cmd) > 0) { + if (opt && eval_to_number(cmd) > 0) { do_cmdline_cmd("augroup filetypedetect"); - vim_snprintf((char *)pat, len, ftpat, ffname); - source_all_matches((char *)pat); + vim_snprintf(pat, len, ftpat, ffname); + source_all_matches(pat); vim_snprintf((char *)pat, len, "%s/ftdetect/*.lua", ffname); // NOLINT - source_all_matches((char *)pat); + source_all_matches(pat); do_cmdline_cmd("augroup END"); } xfree(cmd); @@ -1001,7 +1001,7 @@ static int APP_ADD_DIR; static int APP_LOAD; static int APP_BOTH; -static void add_pack_plugin(bool opt, char_u *fname, void *cookie) +static void add_pack_plugin(bool opt, char *fname, void *cookie) { if (cookie != &APP_LOAD) { char *buf = xmalloc(MAXPATHL); @@ -1010,7 +1010,7 @@ static void add_pack_plugin(bool opt, char_u *fname, void *cookie) const char *p = (const char *)p_rtp; while (*p != NUL) { copy_option_part((char **)&p, buf, MAXPATHL, ","); - if (path_fnamecmp(buf, (char *)fname) == 0) { + if (path_fnamecmp(buf, fname) == 0) { found = true; break; } @@ -1031,25 +1031,25 @@ static void add_pack_plugin(bool opt, char_u *fname, void *cookie) static void add_start_pack_plugin(char *fname, void *cookie) { - add_pack_plugin(false, (char_u *)fname, cookie); + add_pack_plugin(false, fname, cookie); } static void add_opt_pack_plugin(char *fname, void *cookie) { - add_pack_plugin(true, (char_u *)fname, cookie); + add_pack_plugin(true, fname, cookie); } /// Add all packages in the "start" directory to 'runtimepath'. void add_pack_start_dirs(void) { - do_in_path((char_u *)p_pp, NULL, DIP_ALL + DIP_DIR, add_pack_start_dir, NULL); + do_in_path(p_pp, NULL, DIP_ALL + DIP_DIR, add_pack_start_dir, NULL); } -static bool pack_has_entries(char_u *buf) +static bool pack_has_entries(char *buf) { int num_files; char **files; - char *(pat[]) = { (char *)buf }; + char *(pat[]) = { buf }; if (gen_expand_wildcards(1, pat, &num_files, &files, EW_DIR) == OK) { FreeWild(num_files, files); } @@ -1058,7 +1058,7 @@ static bool pack_has_entries(char_u *buf) static void add_pack_start_dir(char *fname, void *cookie) { - static char_u buf[MAXPATHL]; + static char buf[MAXPATHL]; char *(start_pat[]) = { "/start/*", "/pack/*/start/*" }; // NOLINT for (int i = 0; i < 2; i++) { if (STRLEN(fname) + STRLEN(start_pat[i]) + 1 > MAXPATHL) { @@ -1076,9 +1076,9 @@ static void add_pack_start_dir(char *fname, void *cookie) void load_start_packages(void) { did_source_packages = true; - do_in_path((char_u *)p_pp, "pack/*/start/*", DIP_ALL + DIP_DIR, // NOLINT + do_in_path(p_pp, "pack/*/start/*", DIP_ALL + DIP_DIR, // NOLINT add_start_pack_plugin, &APP_LOAD); - do_in_path((char_u *)p_pp, "start/*", DIP_ALL + DIP_DIR, // NOLINT + do_in_path(p_pp, "start/*", DIP_ALL + DIP_DIR, // NOLINT add_start_pack_plugin, &APP_LOAD); } @@ -1099,12 +1099,12 @@ void ex_packloadall(exarg_T *eap) void load_plugins(void) { if (p_lpl) { - char_u *rtp_copy = (char_u *)p_rtp; - char_u *const plugin_pattern_vim = (char_u *)"plugin/**/*.vim"; // NOLINT - char_u *const plugin_pattern_lua = (char_u *)"plugin/**/*.lua"; // NOLINT + char *rtp_copy = p_rtp; + char *const plugin_pattern_vim = "plugin/**/*.vim"; // NOLINT + char *const plugin_pattern_lua = "plugin/**/*.lua"; // NOLINT if (!did_source_packages) { - rtp_copy = vim_strsave((char_u *)p_rtp); + rtp_copy = xstrdup(p_rtp); add_pack_start_dirs(); } @@ -1121,8 +1121,8 @@ void load_plugins(void) } TIME_MSG("loading packages"); - source_runtime((char *)plugin_pattern_vim, DIP_ALL | DIP_AFTER); - source_runtime((char *)plugin_pattern_lua, DIP_ALL | DIP_AFTER); + source_runtime(plugin_pattern_vim, DIP_ALL | DIP_AFTER); + source_runtime(plugin_pattern_lua, DIP_ALL | DIP_AFTER); TIME_MSG("loading after plugins"); } } @@ -1146,7 +1146,7 @@ void ex_packadd(exarg_T *eap) // The first round don't give a "not found" error, in the second round // only when nothing was found in the first round. res = - do_in_path((char_u *)p_pp, pat, DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0), + do_in_path(p_pp, pat, DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0), round == 1 ? add_start_pack_plugin : add_opt_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH); xfree(pat); @@ -1162,7 +1162,7 @@ void ex_packadd(exarg_T *eap) /// 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim /// When "flags" has DIP_LUA: search also performed for .lua files /// "dirnames" is an array with one or more directory names. -int ExpandRTDir(char_u *pat, int flags, int *num_file, char ***file, char *dirnames[]) +int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirnames[]) { *num_file = 0; *file = NULL; @@ -1174,11 +1174,11 @@ int ExpandRTDir(char_u *pat, int flags, int *num_file, char ***file, char *dirna // TODO(bfredl): this is bullshit, exandpath should not reinvent path logic. for (int i = 0; dirnames[i] != NULL; i++) { size_t size = STRLEN(dirnames[i]) + pat_len + 7; - char_u *s = xmalloc(size); - snprintf((char *)s, size, "%s/%s*.vim", dirnames[i], pat); + char *s = xmalloc(size); + snprintf(s, size, "%s/%s*.vim", dirnames[i], pat); globpath(p_rtp, s, &ga, 0); if (flags & DIP_LUA) { - snprintf((char *)s, size, "%s/%s*.lua", dirnames[i], pat); + snprintf(s, size, "%s/%s*.lua", dirnames[i], pat); globpath(p_rtp, s, &ga, 0); } xfree(s); @@ -1187,11 +1187,11 @@ int ExpandRTDir(char_u *pat, int flags, int *num_file, char ***file, char *dirna if (flags & DIP_START) { for (int i = 0; dirnames[i] != NULL; i++) { size_t size = STRLEN(dirnames[i]) + pat_len + 22; - char_u *s = xmalloc(size); - snprintf((char *)s, size, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT + char *s = xmalloc(size); + snprintf(s, size, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT globpath(p_pp, s, &ga, 0); if (flags & DIP_LUA) { - snprintf((char *)s, size, "pack/*/start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT + snprintf(s, size, "pack/*/start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT globpath(p_pp, s, &ga, 0); } xfree(s); @@ -1199,11 +1199,11 @@ int ExpandRTDir(char_u *pat, int flags, int *num_file, char ***file, char *dirna for (int i = 0; dirnames[i] != NULL; i++) { size_t size = STRLEN(dirnames[i]) + pat_len + 22; - char_u *s = xmalloc(size); - snprintf((char *)s, size, "start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT + char *s = xmalloc(size); + snprintf(s, size, "start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT globpath(p_pp, s, &ga, 0); if (flags & DIP_LUA) { - snprintf((char *)s, size, "start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT + snprintf(s, size, "start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT globpath(p_pp, s, &ga, 0); } xfree(s); @@ -1213,11 +1213,11 @@ int ExpandRTDir(char_u *pat, int flags, int *num_file, char ***file, char *dirna if (flags & DIP_OPT) { for (int i = 0; dirnames[i] != NULL; i++) { size_t size = STRLEN(dirnames[i]) + pat_len + 20; - char_u *s = xmalloc(size); - snprintf((char *)s, size, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT + char *s = xmalloc(size); + snprintf(s, size, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT globpath(p_pp, s, &ga, 0); if (flags & DIP_LUA) { - snprintf((char *)s, size, "pack/*/opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT + snprintf(s, size, "pack/*/opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT globpath(p_pp, s, &ga, 0); } xfree(s); @@ -1225,11 +1225,11 @@ int ExpandRTDir(char_u *pat, int flags, int *num_file, char ***file, char *dirna for (int i = 0; dirnames[i] != NULL; i++) { size_t size = STRLEN(dirnames[i]) + pat_len + 20; - char_u *s = xmalloc(size); - snprintf((char *)s, size, "opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT + char *s = xmalloc(size); + snprintf(s, size, "opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT globpath(p_pp, s, &ga, 0); if (flags & DIP_LUA) { - snprintf((char *)s, size, "opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT + snprintf(s, size, "opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT globpath(p_pp, s, &ga, 0); } xfree(s); @@ -1237,9 +1237,9 @@ int ExpandRTDir(char_u *pat, int flags, int *num_file, char ***file, char *dirna } for (int i = 0; i < ga.ga_len; i++) { - char_u *match = ((char_u **)ga.ga_data)[i]; - char_u *s = match; - char_u *e = s + STRLEN(s); + char *match = ((char **)ga.ga_data)[i]; + char *s = match; + char *e = s + STRLEN(s); if (e - s > 4 && (STRNICMP(e - 4, ".vim", 4) == 0 || ((flags & DIP_LUA) && STRNICMP(e - 4, ".lua", 4) == 0))) { @@ -1271,7 +1271,7 @@ int ExpandRTDir(char_u *pat, int flags, int *num_file, char ***file, char *dirna /// Expand loadplugin names: /// 'packpath'/pack/ * /opt/{pat} -int ExpandPackAddDir(char_u *pat, int *num_file, char ***file) +int ExpandPackAddDir(char *pat, int *num_file, char ***file) { garray_T ga; @@ -1281,16 +1281,16 @@ int ExpandPackAddDir(char_u *pat, int *num_file, char ***file) ga_init(&ga, (int)sizeof(char *), 10); size_t buflen = pat_len + 26; - char_u *s = xmalloc(buflen); - snprintf((char *)s, buflen, "pack/*/opt/%s*", pat); // NOLINT + char *s = xmalloc(buflen); + snprintf(s, buflen, "pack/*/opt/%s*", pat); // NOLINT globpath(p_pp, s, &ga, 0); - snprintf((char *)s, buflen, "opt/%s*", pat); // NOLINT + snprintf(s, buflen, "opt/%s*", pat); // NOLINT globpath(p_pp, s, &ga, 0); xfree(s); for (int i = 0; i < ga.ga_len; i++) { - char_u *match = ((char_u **)ga.ga_data)[i]; - s = (char_u *)path_tail((char *)match); + char *match = ((char **)ga.ga_data)[i]; + s = path_tail(match); memmove(match, s, STRLEN(s) + 1); } @@ -1479,7 +1479,7 @@ char *get_lib_dir(void) // TODO(bfredl): too fragile? Ideally default_lib_dir would be made empty // in an appimage build if (strlen(default_lib_dir) != 0 - && os_isdir((const char_u *)default_lib_dir)) { + && os_isdir(default_lib_dir)) { return xstrdup(default_lib_dir); } @@ -1611,7 +1611,7 @@ static void cmd_source(char *fname, exarg_T *eap) // - after ":argdo", ":windo" or ":bufdo" // - another command follows // - inside a loop - openscript((char_u *)fname, global_busy || listcmd_busy || eap->nextcmd != NULL + openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL || eap->cstack->cs_idx >= 0); // ":source" read ex commands @@ -1691,12 +1691,12 @@ static FILE *fopen_noinh_readbin(char *filename) /// /// @return true if this line did begin with a continuation (the next line /// should also be considered, if it exists); false otherwise -static bool concat_continued_line(garray_T *const ga, const int init_growsize, - const char_u *const p, size_t len) +static bool concat_continued_line(garray_T *const ga, const int init_growsize, const char *const p, + size_t len) FUNC_ATTR_NONNULL_ALL { - const char *const line = (char *)skipwhite_len(p, len); - len -= (size_t)((char_u *)line - p); + const char *const line = skipwhite_len((char *)p, len); + len -= (size_t)(line - p); // Skip lines starting with '\" ', concat lines starting with '\' if (len >= 3 && STRNCMP(line, "\"\\ ", 3) == 0) { return true; @@ -1732,15 +1732,15 @@ static char *get_str_line(int c, void *cookie, int indent, bool do_concat) return NULL; } const char *line = p->buf + p->offset; - const char *eol = (char *)skip_to_newline((char_u *)line); + const char *eol = skip_to_newline(line); garray_T ga; - ga_init(&ga, sizeof(char_u), 400); + ga_init(&ga, sizeof(char), 400); ga_concat_len(&ga, line, (size_t)(eol - line)); if (do_concat && vim_strchr(p_cpo, CPO_CONCAT) == NULL) { while (eol[0] != NUL) { line = eol + 1; - const char_u *const next_eol = skip_to_newline((char_u *)line); - if (!concat_continued_line(&ga, 400, (char_u *)line, (size_t)(next_eol - (char_u *)line))) { + const char *const next_eol = skip_to_newline(line); + if (!concat_continued_line(&ga, 400, line, (size_t)(next_eol - line))) { break; } eol = (char *)next_eol; @@ -1770,7 +1770,7 @@ scriptitem_T *new_script_item(char *const name, scid_T *const sid_out) SCRIPT_ITEM(script_items.ga_len).sn_name = NULL; SCRIPT_ITEM(script_items.ga_len).sn_prof_on = false; } - SCRIPT_ITEM(sid).sn_name = (char_u *)name; + SCRIPT_ITEM(sid).sn_name = name; new_script_vars(sid); // Allocate the local script variables to use for this script. return &SCRIPT_ITEM(sid); } @@ -1814,7 +1814,7 @@ static void cmd_source_buffer(const exarg_T *const eap) return; } garray_T ga; - ga_init(&ga, sizeof(char_u), 400); + ga_init(&ga, sizeof(char), 400); const linenr_T final_lnum = eap->line2; // Copy the contents to be executed. for (linenr_T curr_lnum = eap->line1; curr_lnum <= final_lnum; curr_lnum++) { @@ -1825,7 +1825,7 @@ static void cmd_source_buffer(const exarg_T *const eap) ga_concat(&ga, (char *)ml_get(curr_lnum)); ga_append(&ga, NL); } - ((char_u *)ga.ga_data)[ga.ga_len - 1] = NUL; + ((char *)ga.ga_data)[ga.ga_len - 1] = NUL; const GetStrLineCookie cookie = { .buf = ga.ga_data, .offset = 0, @@ -1886,7 +1886,7 @@ int do_source(char *fname, int check_other, int is_vimrc) if (fname_exp == NULL) { return retval; } - if (os_isdir((char_u *)fname_exp)) { + if (os_isdir(fname_exp)) { smsg(_("Cannot source a directory: \"%s\""), fname); goto theend; } @@ -1963,7 +1963,7 @@ int do_source(char *fname, int check_other, int is_vimrc) cookie.finished = false; // Check if this script has a breakpoint. - cookie.breakpoint = dbg_find_breakpoint(true, (char_u *)fname_exp, (linenr_T)0); + cookie.breakpoint = dbg_find_breakpoint(true, fname_exp, (linenr_T)0); cookie.fname = fname_exp; cookie.dbg_tick = debug_tick; @@ -1992,7 +1992,7 @@ int do_source(char *fname, int check_other, int is_vimrc) si = get_current_script_id(&fname_exp, ¤t_sctx); // Keep the sourcing name/lnum, for recursive calls. - estack_push(ETYPE_SCRIPT, (char *)si->sn_name, 0); + estack_push(ETYPE_SCRIPT, si->sn_name, 0); if (l_do_profiling == PROF_YES) { bool forceit = false; @@ -2025,7 +2025,7 @@ int do_source(char *fname, int check_other, int is_vimrc) && firstline[1] == 0xbb && firstline[2] == 0xbf) { // Found BOM; setup conversion, skip over BOM and recode the line. convert_setup(&cookie.conv, "utf-8", p_enc); - p = (char *)string_convert(&cookie.conv, (char_u *)firstline + 3, NULL); + p = string_convert(&cookie.conv, (char *)firstline + 3, NULL); if (p == NULL) { p = xstrdup((char *)firstline + 3); } @@ -2128,7 +2128,7 @@ scriptitem_T *get_current_script_id(char **fnamep, sctx_T *ret_sctx) } if (script_sctx.sc_sid == 0) { si = new_script_item(*fnamep, &script_sctx.sc_sid); - *fnamep = xstrdup((char *)si->sn_name); + *fnamep = xstrdup(si->sn_name); } if (ret_sctx != NULL) { *ret_sctx = script_sctx; @@ -2145,7 +2145,7 @@ void ex_scriptnames(exarg_T *eap) if (eap->line2 < 1 || eap->line2 > script_items.ga_len) { emsg(_(e_invarg)); } else { - eap->arg = (char *)SCRIPT_ITEM(eap->line2).sn_name; + eap->arg = SCRIPT_ITEM(eap->line2).sn_name; do_exedit(eap, NULL); } return; @@ -2153,7 +2153,7 @@ void ex_scriptnames(exarg_T *eap) for (int i = 1; i <= script_items.ga_len && !got_int; i++) { if (SCRIPT_ITEM(i).sn_name != NULL) { - home_replace(NULL, (char *)SCRIPT_ITEM(i).sn_name, (char *)NameBuff, MAXPATHL, true); + home_replace(NULL, SCRIPT_ITEM(i).sn_name, (char *)NameBuff, MAXPATHL, true); vim_snprintf((char *)IObuff, IOSIZE, "%3d: %s", i, NameBuff); if (!message_filtered((char *)IObuff)) { msg_putchar('\n'); @@ -2179,40 +2179,40 @@ void scriptnames_slash_adjust(void) /// Get a pointer to a script name. Used for ":verbose set". /// Message appended to "Last set from " -char_u *get_scriptname(LastSet last_set, bool *should_free) +char *get_scriptname(LastSet last_set, bool *should_free) { *should_free = false; switch (last_set.script_ctx.sc_sid) { case SID_MODELINE: - return (char_u *)_("modeline"); + return _("modeline"); case SID_CMDARG: - return (char_u *)_("--cmd argument"); + return _("--cmd argument"); case SID_CARG: - return (char_u *)_("-c argument"); + return _("-c argument"); case SID_ENV: - return (char_u *)_("environment variable"); + return _("environment variable"); case SID_ERROR: - return (char_u *)_("error handler"); + return _("error handler"); case SID_WINLAYOUT: - return (char_u *)_("changed window size"); + return _("changed window size"); case SID_LUA: - return (char_u *)_("Lua"); + return _("Lua"); case SID_API_CLIENT: snprintf((char *)IObuff, IOSIZE, _("API client (channel id %" PRIu64 ")"), last_set.channel_id); - return IObuff; + return (char *)IObuff; case SID_STR: - return (char_u *)_("anonymous :source"); + return _("anonymous :source"); default: { - char *const sname = (char *)SCRIPT_ITEM(last_set.script_ctx.sc_sid).sn_name; + char *const sname = SCRIPT_ITEM(last_set.script_ctx.sc_sid).sn_name; if (sname == NULL) { snprintf((char *)IObuff, IOSIZE, _("anonymous :source (script id %d)"), last_set.script_ctx.sc_sid); - return IObuff; + return (char *)IObuff; } *should_free = true; - return (char_u *)home_replace_save(NULL, sname); + return home_replace_save(NULL, sname); } } } @@ -2248,7 +2248,7 @@ char *getsourceline(int c, void *cookie, int indent, bool do_concat) // If breakpoints have been added/deleted need to check for it. if (sp->dbg_tick < debug_tick) { - sp->breakpoint = dbg_find_breakpoint(true, (char_u *)sp->fname, SOURCING_LNUM); + sp->breakpoint = dbg_find_breakpoint(true, sp->fname, SOURCING_LNUM); sp->dbg_tick = debug_tick; } if (do_profiling == PROF_YES) { @@ -2287,11 +2287,10 @@ char *getsourceline(int c, void *cookie, int indent, bool do_concat) || (p[0] == '"' && p[1] == '\\' && p[2] == ' '))) { garray_T ga; - ga_init(&ga, (int)sizeof(char_u), 400); + ga_init(&ga, (int)sizeof(char), 400); ga_concat(&ga, line); while (sp->nextline != NULL - && concat_continued_line(&ga, 400, (char_u *)sp->nextline, - STRLEN(sp->nextline))) { + && concat_continued_line(&ga, 400, sp->nextline, STRLEN(sp->nextline))) { xfree(sp->nextline); sp->nextline = get_one_sourceline(sp); } @@ -2305,7 +2304,7 @@ char *getsourceline(int c, void *cookie, int indent, bool do_concat) char *s; // Convert the encoding of the script line. - s = (char *)string_convert(&sp->conv, (char_u *)line, NULL); + s = string_convert(&sp->conv, line, NULL); if (s != NULL) { xfree(line); line = s; @@ -2314,9 +2313,9 @@ char *getsourceline(int c, void *cookie, int indent, bool do_concat) // Did we encounter a breakpoint? if (sp->breakpoint != 0 && sp->breakpoint <= SOURCING_LNUM) { - dbg_breakpoint((char_u *)sp->fname, SOURCING_LNUM); + dbg_breakpoint(sp->fname, SOURCING_LNUM); // Find next breakpoint. - sp->breakpoint = dbg_find_breakpoint(true, (char_u *)sp->fname, SOURCING_LNUM); + sp->breakpoint = dbg_find_breakpoint(true, sp->fname, SOURCING_LNUM); sp->dbg_tick = debug_tick; } diff --git a/src/nvim/runtime.h b/src/nvim/runtime.h index 03c426c79b..053c71212e 100644 --- a/src/nvim/runtime.h +++ b/src/nvim/runtime.h @@ -51,7 +51,7 @@ typedef enum { } estack_arg_T; typedef struct scriptitem_S { - char_u *sn_name; + char *sn_name; bool sn_prof_on; ///< true when script is/was profiled bool sn_pr_force; ///< forceit: profile functions in this script proftime_T sn_pr_child; ///< time set when going into first child diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 6efaae3725..d268dde845 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1270,7 +1270,7 @@ static int get_encoded_char_adv(const char_u **p) int64_t num = 0; for (int bytes = s[1] == 'x' ? 1 : s[1] == 'u' ? 2 : 4; bytes > 0; bytes--) { *p += 2; - int n = hexhex2nr(*p); + int n = hexhex2nr((char *)(*p)); if (n < 0) { return 0; } diff --git a/src/nvim/search.c b/src/nvim/search.c index c1c2f0dbe9..e995081df8 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -170,7 +170,7 @@ int search_regcomp(char_u *pat, int pat_save, int pat_use, int options, regmmatc } if (curwin->w_p_rl && *curwin->w_p_rlc == 's') { - mr_pattern = reverse_text(pat); + mr_pattern = (char_u *)reverse_text((char *)pat); mr_pattern_alloced = true; } else { mr_pattern = pat; @@ -1261,7 +1261,7 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, // it would be blanked out again very soon. Show it on the // left, but do reverse the text. if (curwin->w_p_rl && *curwin->w_p_rlc == 's') { - char_u *r = reverse_text(trunc != NULL ? trunc : msgbuf); + char_u *r = (char_u *)reverse_text(trunc != NULL ? (char *)trunc : (char *)msgbuf); xfree(msgbuf); msgbuf = r; // move reversed text to beginning of buffer @@ -3666,7 +3666,7 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo if (new_fname != NULL) { // using "new_fname" is more reliable, e.g., when // 'includeexpr' is set. - msg_outtrans_attr(new_fname, HL_ATTR(HLF_D)); + msg_outtrans_attr((char *)new_fname, HL_ATTR(HLF_D)); } else { /* * Isolate the file name. @@ -3702,7 +3702,7 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo } save_char = p[i]; p[i] = NUL; - msg_outtrans_attr(p, HL_ATTR(HLF_D)); + msg_outtrans_attr((char *)p, HL_ATTR(HLF_D)); p[i] = save_char; } diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 88ad7d519a..d2f1b39ca4 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -3023,7 +3023,7 @@ shada_write_file_nomerge: {} if (tail != fname) { const char tail_save = *tail; *tail = NUL; - if (!os_isdir((char_u *)fname)) { + if (!os_isdir(fname)) { int ret; char *failed_dir; if ((ret = os_mkdir_recurse(fname, 0700, &failed_dir)) != 0) { diff --git a/src/nvim/sign.c b/src/nvim/sign.c index a9640eacda..ed7f53d3ba 100644 --- a/src/nvim/sign.c +++ b/src/nvim/sign.c @@ -858,7 +858,7 @@ static void sign_define_init_icon(sign_T *sp, char_u *icon) { xfree(sp->sn_icon); sp->sn_icon = vim_strsave(icon); - backslash_halve(sp->sn_icon); + backslash_halve((char *)sp->sn_icon); } /// Initialize the text for a new sign @@ -1353,7 +1353,7 @@ static int parse_sign_cmd_args(int cmd, char_u *arg, char_u **sign_name, int *si if (STRNCMP(arg, "line=", 5) == 0) { arg += 5; *lnum = atoi((char *)arg); - arg = skiptowhite(arg); + arg = (char_u *)skiptowhite((char *)arg); lnum_arg = true; } else if (STRNCMP(arg, "*", 1) == 0 && cmd == SIGNCMD_UNPLACE) { if (*signid != -1) { @@ -1361,11 +1361,11 @@ static int parse_sign_cmd_args(int cmd, char_u *arg, char_u **sign_name, int *si return FAIL; } *signid = -2; - arg = skiptowhite(arg + 1); + arg = (char_u *)skiptowhite((char *)arg + 1); } else if (STRNCMP(arg, "name=", 5) == 0) { arg += 5; name = arg; - arg = skiptowhite(arg); + arg = (char_u *)skiptowhite((char *)arg); if (*arg != NUL) { *arg++ = NUL; } @@ -1376,14 +1376,14 @@ static int parse_sign_cmd_args(int cmd, char_u *arg, char_u **sign_name, int *si } else if (STRNCMP(arg, "group=", 6) == 0) { arg += 6; *group = arg; - arg = skiptowhite(arg); + arg = (char_u *)skiptowhite((char *)arg); if (*arg != NUL) { *arg++ = NUL; } } else if (STRNCMP(arg, "priority=", 9) == 0) { arg += 9; *prio = atoi((char *)arg); - arg = skiptowhite(arg); + arg = (char_u *)skiptowhite((char *)arg); } else if (STRNCMP(arg, "file=", 5) == 0) { arg += 5; filename = arg; @@ -1427,7 +1427,7 @@ void ex_sign(exarg_T *eap) sign_T *sp; // Parse the subcommand. - p = skiptowhite(arg); + p = (char_u *)skiptowhite((char *)arg); idx = sign_cmd_idx(arg, p); if (idx == SIGNCMD_LAST) { semsg(_("E160: Unknown sign command: %s"), arg); @@ -1449,7 +1449,7 @@ void ex_sign(exarg_T *eap) // Isolate the sign name. If it's a number skip leading zeroes, // so that "099" and "99" are the same sign. But keep "0". - p = skiptowhite(arg); + p = (char_u *)skiptowhite((char *)arg); if (*p != NUL) { *p++ = NUL; } @@ -1789,7 +1789,7 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg) expand_what = EXP_SUBCMD; xp->xp_pattern = (char *)arg; - end_subcmd = skiptowhite(arg); + end_subcmd = (char_u *)skiptowhite((char *)arg); if (*end_subcmd == NUL) { // expand subcmd name // :sign {subcmd} @@ -1814,7 +1814,7 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg) do { p = (char_u *)skipwhite((char *)p); last = p; - p = skiptowhite(p); + p = (char_u *)skiptowhite((char *)p); } while (*p != NUL); p = (char_u *)vim_strchr((char *)last, '='); diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 10923829c3..1259736e0e 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -243,7 +243,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou if (*ptr == '0' && (ptr[1] == 'b' || ptr[1] == 'B')) { mi.mi_end = (char_u *)skipbin((char *)ptr + 2); } else if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) { - mi.mi_end = skiphex(ptr + 2); + mi.mi_end = (char_u *)skiphex((char *)ptr + 2); } else { mi.mi_end = (char_u *)skipdigits((char *)ptr); } @@ -1258,10 +1258,10 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att // For checking first word with a capital skip white space. if (capcol == 0) { - capcol = (int)getwhitecols(line); + capcol = (int)getwhitecols((char *)line); } else if (curline && wp == curwin) { // For spellbadword(): check if first word needs a capital. - col = (int)getwhitecols(line); + col = (int)getwhitecols((char *)line); if (check_need_cap(lnum, col)) { capcol = col; } @@ -1876,7 +1876,7 @@ char *did_set_spelllang(win_T *wp) // Check if we loaded this language before. for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare((char *)lang, (char *)slang->sl_fname, false, true) + if (path_full_compare((char *)lang, slang->sl_fname, false, true) == kEqualFiles) { break; } @@ -1925,7 +1925,7 @@ char *did_set_spelllang(win_T *wp) // Loop over the languages, there can be several files for "lang". for (slang = first_lang; slang != NULL; slang = slang->sl_next) { if (filename - ? path_full_compare((char *)lang, (char *)slang->sl_fname, false, true) == kEqualFiles + ? path_full_compare((char *)lang, slang->sl_fname, false, true) == kEqualFiles : STRICMP(lang, slang->sl_name) == 0) { region_mask = REGION_ALL; if (!filename && region != NULL) { @@ -1981,7 +1981,7 @@ char *did_set_spelllang(win_T *wp) // If it was already found above then skip it. for (c = 0; c < ga.ga_len; c++) { - p = LANGP_ENTRY(ga, c)->lp_slang->sl_fname; + p = (char_u *)LANGP_ENTRY(ga, c)->lp_slang->sl_fname; if (p != NULL && path_full_compare((char *)spf_name, (char *)p, false, true) == kEqualFiles) { break; @@ -1994,7 +1994,7 @@ char *did_set_spelllang(win_T *wp) // Check if it was loaded already. for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare((char *)spf_name, (char *)slang->sl_fname, false, true) + if (path_full_compare((char *)spf_name, slang->sl_fname, false, true) == kEqualFiles) { break; } @@ -2473,7 +2473,7 @@ bool check_need_cap(linenr_T lnum, colnr_T col) char_u *line = get_cursor_line_ptr(); char_u *line_copy = NULL; colnr_T endcol = 0; - if (getwhitecols(line) >= (int)col) { + if (getwhitecols((char *)line) >= (int)col) { // At start of line, check if previous line is empty or sentence // ends there. if (lnum == 1) { @@ -2484,7 +2484,7 @@ bool check_need_cap(linenr_T lnum, colnr_T col) need_cap = true; } else { // Append a space in place of the line break. - line_copy = concat_str(line, (char_u *)" "); + line_copy = (char_u *)concat_str((char *)line, " "); line = line_copy; endcol = (colnr_T)STRLEN(line); } @@ -3599,8 +3599,8 @@ char *compile_cap_prog(synblock_T *synblock) synblock->b_cap_prog = NULL; } else { // Prepend a ^ so that we only match at one column - char_u *re = concat_str((char_u *)"^", (char_u *)synblock->b_p_spc); - synblock->b_cap_prog = vim_regcomp((char *)re, RE_MAGIC); + char *re = concat_str("^", synblock->b_p_spc); + synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC); xfree(re); if (synblock->b_cap_prog == NULL) { synblock->b_cap_prog = rp; // restore the previous program diff --git a/src/nvim/spell_defs.h b/src/nvim/spell_defs.h index 61f722b9ee..27b9777dc2 100644 --- a/src/nvim/spell_defs.h +++ b/src/nvim/spell_defs.h @@ -115,9 +115,9 @@ typedef struct slang_S slang_T; struct slang_S { slang_T *sl_next; // next language - char_u *sl_name; // language name "en", "en.rare", "nl", etc. - char_u *sl_fname; // name of .spl file - bool sl_add; // true if it's a .add file. + char_u *sl_name; // language name "en", "en.rare", "nl", etc. + char *sl_fname; // name of .spl file + bool sl_add; // true if it's a .add file. char_u *sl_fbyts; // case-folded word bytes long sl_fbyts_len; // length of sl_fbyts diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 33e8c5c099..0f8034312e 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -604,7 +604,7 @@ slang_T *spell_load_file(char_u *fname, char_u *lang, slang_T *old_lp, bool sile lp = slang_alloc(lang); // Remember the file name, used to reload the file when it's updated. - lp->sl_fname = vim_strsave(fname); + lp->sl_fname = (char *)vim_strsave(fname); // Check for .add.spl. lp->sl_add = strstr(path_tail((char *)fname), SPL_FNAME_ADD) != NULL; @@ -869,12 +869,12 @@ static void tree_count_words(char_u *byts, idx_T *idxs) } } -// Load the .sug files for languages that have one and weren't loaded yet. +/// Load the .sug files for languages that have one and weren't loaded yet. void suggest_load_files(void) { langp_T *lp; slang_T *slang; - char_u *dotp; + char *dotp; FILE *fd; char_u buf[MAXWLEN]; int i; @@ -894,12 +894,12 @@ void suggest_load_files(void) // don't try again and again. slang->sl_sugloaded = true; - dotp = STRRCHR(slang->sl_fname, '.'); + dotp = strrchr(slang->sl_fname, '.'); if (dotp == NULL || FNAMECMP(dotp, ".spl") != 0) { continue; } STRCPY(dotp, ".sug"); - fd = os_fopen((char *)slang->sl_fname, "r"); + fd = os_fopen(slang->sl_fname, "r"); if (fd == NULL) { goto nextone; } @@ -1822,7 +1822,7 @@ static void spell_reload_one(char_u *fname, bool added_word) bool didit = false; for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare((char *)fname, (char *)slang->sl_fname, false, true) == kEqualFiles) { + if (path_full_compare((char *)fname, slang->sl_fname, false, true) == kEqualFiles) { slang_clear(slang); if (spell_load_file(fname, NULL, slang, false) == NULL) { // reloading failed, clear the language @@ -2075,7 +2075,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // Convert from "SET" to 'encoding' when needed. xfree(pc); if (spin->si_conv.vc_type != CONV_NONE) { - pc = string_convert(&spin->si_conv, rline, NULL); + pc = (char_u *)string_convert(&spin->si_conv, (char *)rline, NULL); if (pc == NULL) { smsg(_("Conversion failure for word in %s line %d: %s"), fname, lnum, rline); @@ -3155,7 +3155,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) // Convert from "SET" to 'encoding' when needed. if (spin->si_conv.vc_type != CONV_NONE) { - pc = string_convert(&spin->si_conv, line, NULL); + pc = (char_u *)string_convert(&spin->si_conv, (char *)line, NULL); if (pc == NULL) { smsg(_("Conversion failure for word in %s line %d: %s"), fname, lnum, line); @@ -3701,7 +3701,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) // Convert from "/encoding={encoding}" to 'encoding' when needed. xfree(pc); if (spin->si_conv.vc_type != CONV_NONE) { - pc = string_convert(&spin->si_conv, rline, NULL); + pc = (char_u *)string_convert(&spin->si_conv, (char *)rline, NULL); if (pc == NULL) { smsg(_("Conversion failure for word in %s line %ld: %s"), fname, lnum, rline); @@ -4907,7 +4907,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char *wfname) // of the code for the soundfolding stuff. // It might have been done already by spell_reload_one(). for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare(wfname, (char *)slang->sl_fname, false, true) + if (path_full_compare(wfname, slang->sl_fname, false, true) == kEqualFiles) { break; } @@ -5343,7 +5343,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool emsg(_(e_exists)); goto theend; } - if (os_isdir((char_u *)wfname)) { + if (os_isdir(wfname)) { semsg(_(e_isadir2), wfname); goto theend; } @@ -5723,7 +5723,7 @@ static void init_spellfile(void) "/%.*s", (int)(lend - lstart), lstart); } l = (int)STRLEN(buf); - fname = LANGP_ENTRY(curwin->w_s->b_langp, 0) + fname = (char_u *)LANGP_ENTRY(curwin->w_s->b_langp, 0) ->lp_slang->sl_fname; vim_snprintf((char *)buf + l, MAXPATHL - (size_t)l, ".%s.add", ((fname != NULL diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index fa46d94342..23c8c621b5 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -972,7 +972,7 @@ static void suggest_try_special(suginfo_T *su) char_u word[MAXWLEN]; // Recognize a word that is repeated: "the the". - char_u *p = skiptowhite(su->su_fbadword); + char_u *p = (char_u *)skiptowhite((char *)su->su_fbadword); size_t len = (size_t)(p - su->su_fbadword); p = (char_u *)skipwhite((char *)p); if (STRLEN(p) == len && STRNCMP(su->su_fbadword, p, len) == 0) { @@ -1369,8 +1369,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (compound_ok) { p = preword; - while (*skiptowhite(p) != NUL) { - p = (char_u *)skipwhite((char *)skiptowhite(p)); + while (*skiptowhite((char *)p) != NUL) { + p = (char_u *)skipwhite(skiptowhite((char *)p)); } if (fword_ends && !can_compound(slang, p, compflags + sp->ts_compsplit)) { @@ -1590,8 +1590,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so break; } p = preword; - while (*skiptowhite(p) != NUL) { - p = (char_u *)skipwhite((char *)skiptowhite(p)); + while (*skiptowhite((char *)p) != NUL) { + p = (char_u *)skipwhite(skiptowhite((char *)p)); } if (sp->ts_complen > sp->ts_compsplit && !can_compound(slang, p, @@ -2636,8 +2636,8 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u * // removing the space. Don't do it when the good word also contains a // space. if (ascii_iswhite(su->su_badptr[su->su_badlen]) - && *skiptowhite(stp->st_word) == NUL) { - for (p = fword; *(p = skiptowhite(p)) != NUL;) { + && *skiptowhite((char *)stp->st_word) == NUL) { + for (p = fword; *(p = (char_u *)skiptowhite((char *)p)) != NUL;) { STRMOVE(p, p + 1); } } diff --git a/src/nvim/strings.c b/src/nvim/strings.c index bd0f122f99..16691d0ded 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -503,7 +503,7 @@ static int sort_compare(const void *s1, const void *s2) void sort_strings(char **files, int count) { - qsort((void *)files, (size_t)count, sizeof(char_u *), sort_compare); + qsort((void *)files, (size_t)count, sizeof(char *), sort_compare); } /* @@ -540,14 +540,12 @@ bool has_non_ascii_len(const char *const s, const size_t len) return false; } -/* - * Concatenate two strings and return the result in allocated memory. - */ -char_u *concat_str(const char_u *restrict str1, const char_u *restrict str2) +/// Concatenate two strings and return the result in allocated memory. +char *concat_str(const char *restrict str1, const char *restrict str2) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { size_t l = STRLEN(str1); - char_u *dest = xmalloc(l + STRLEN(str2) + 1); + char *dest = xmalloc(l + STRLEN(str2) + 1); STRCPY(dest, str1); STRCPY(dest + l, str2); return dest; @@ -1511,15 +1509,15 @@ int kv_do_printf(StringBuilder *str, const char *fmt, ...) /// Reverse text into allocated memory. /// /// @return the allocated string. -char_u *reverse_text(char_u *s) +char *reverse_text(char *s) FUNC_ATTR_NONNULL_RET { // Reverse the pattern. size_t len = STRLEN(s); - char_u *rev = xmalloc(len + 1); + char *rev = xmalloc(len + 1); size_t rev_i = len; for (size_t s_i = 0; s_i < len; s_i++) { - const int mb_len = utfc_ptr2len((char *)s + s_i); + const int mb_len = utfc_ptr2len(s + s_i); rev_i -= (size_t)mb_len; memmove(rev + rev_i, s + s_i, (size_t)mb_len); s_i += (size_t)mb_len - 1; diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index e88b1b17f6..f055cc9b0e 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3013,7 +3013,7 @@ static void syn_cmd_conceal(exarg_T *eap, int syncing) return; } - next = skiptowhite(arg); + next = (char_u *)skiptowhite((char *)arg); if (*arg == NUL) { if (curwin->w_s->b_syn_conceal) { msg("syntax conceal on"); @@ -3042,7 +3042,7 @@ static void syn_cmd_case(exarg_T *eap, int syncing) return; } - next = skiptowhite(arg); + next = (char_u *)skiptowhite((char *)arg); if (*arg == NUL) { if (curwin->w_s->b_syn_ic) { msg("syntax case ignore"); @@ -3081,7 +3081,7 @@ static void syn_cmd_foldlevel(exarg_T *eap, int syncing) return; } - arg_end = skiptowhite(arg); + arg_end = (char_u *)skiptowhite((char *)arg); if (STRNICMP(arg, "start", 5) == 0 && arg_end - arg == 5) { curwin->w_s->b_syn_foldlevel = SYNFLD_START; } else if (STRNICMP(arg, "minimum", 7) == 0 && arg_end - arg == 7) { @@ -3110,7 +3110,7 @@ static void syn_cmd_spell(exarg_T *eap, int syncing) return; } - next = skiptowhite(arg); + next = (char_u *)skiptowhite((char *)arg); if (*arg == NUL) { if (curwin->w_s->b_syn_spell == SYNSPL_TOP) { msg("syntax spell toplevel"); @@ -3345,7 +3345,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing) * Clear the group IDs that are in the argument. */ while (!ends_excmd(*arg)) { - arg_end = skiptowhite(arg); + arg_end = (char_u *)skiptowhite((char *)arg); if (*arg == '@') { id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); if (id == 0) { @@ -3522,7 +3522,7 @@ static void syn_cmd_list(exarg_T *eap, int syncing) * List the group IDs and syntax clusters that are in the argument. */ while (!ends_excmd(*arg) && !got_int) { - arg_end = skiptowhite(arg); + arg_end = (char_u *)skiptowhite((char *)arg); if (*arg == '@') { int id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); if (id == 0) { @@ -4029,7 +4029,7 @@ static void add_keyword(char_u *const name, const int id, const int flags, /// Return NULL if the end of the command was found instead of further args. static char *get_group_name(char *arg, char **name_end) { - *name_end = (char *)skiptowhite((char_u *)arg); + *name_end = skiptowhite(arg); char *rest = skipwhite(*name_end); // Check if there are enough arguments. The first argument may be a @@ -4163,7 +4163,7 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i return NULL; } gname_start = (char_u *)arg; - arg = (char *)skiptowhite((char_u *)arg); + arg = skiptowhite(arg); if (gname_start == (char_u *)arg) { return NULL; } @@ -4600,7 +4600,7 @@ static void syn_cmd_region(exarg_T *eap, int syncing) } if (item == ITEM_MATCHGROUP) { - p = (char *)skiptowhite((char_u *)rest); + p = skiptowhite(rest); if ((p - rest == 4 && STRNCMP(rest, "NONE", 4) == 0) || eap->skip) { matchgroup_id = 0; } else { @@ -5141,7 +5141,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) } while (!ends_excmd(*arg_start)) { - arg_end = (char *)skiptowhite(arg_start); + arg_end = skiptowhite((char *)arg_start); next_arg = (char_u *)skipwhite(arg_end); xfree(key); key = vim_strnsave_up(arg_start, (size_t)(arg_end - (char *)arg_start)); @@ -5150,7 +5150,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; } if (!ends_excmd(*next_arg)) { - arg_end = (char *)skiptowhite(next_arg); + arg_end = skiptowhite((char *)next_arg); if (!eap->skip) { curwin->w_s->b_syn_sync_id = (int16_t)syn_check_group((char *)next_arg, (size_t)(arg_end - (char *)next_arg)); @@ -5693,10 +5693,10 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg) // (part of) subcommand already typed if (*arg != NUL) { - const char *p = (const char *)skiptowhite((const char_u *)arg); + const char *p = (const char *)skiptowhite(arg); if (*p != NUL) { // Past first word. xp->xp_pattern = skipwhite(p); - if (*skiptowhite((char_u *)xp->xp_pattern) != NUL) { + if (*skiptowhite(xp->xp_pattern) != NUL) { xp->xp_context = EXPAND_NOTHING; } else if (STRNICMP(arg, "case", p - arg) == 0) { expand_what = EXP_CASE; @@ -6028,7 +6028,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((char *)p->pattern, len); msg_puts("\n"); } ga_clear(&ga); diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 11825ce1c4..5270412382 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -738,7 +738,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char mt_names[matches[i][0] & MT_MASK]); msg_puts((char *)IObuff); if (tagp.tagkind != NULL) { - msg_outtrans_len(tagp.tagkind, + msg_outtrans_len((char *)tagp.tagkind, (int)(tagp.tagkind_end - tagp.tagkind)); } msg_advance(13); @@ -752,7 +752,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char // it and put "..." in the middle p = tag_full_fname(&tagp); if (p != NULL) { - msg_outtrans_attr(p, HL_ATTR(HLF_D)); + msg_outtrans_attr((char *)p, HL_ATTR(HLF_D)); XFREE_CLEAR(p); } if (msg_col > 0) { @@ -794,7 +794,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char } msg_advance(15); } - p = msg_outtrans_one(p, attr); + p = (char_u *)msg_outtrans_one((char *)p, attr); if (*p == TAB) { msg_puts_attr(" ", attr); break; @@ -852,7 +852,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char msg_putchar(' '); p++; } else { - p = msg_outtrans_one(p, 0); + p = (char_u *)msg_outtrans_one((char *)p, 0); } // don't display the "$/;\"" and "$?;\"" @@ -1052,7 +1052,7 @@ void do_tags(exarg_T *eap) tagstack[i].tagname, tagstack[i].fmark.mark.lnum); msg_outtrans((char *)IObuff); - msg_outtrans_attr(name, tagstack[i].fmark.fnum == curbuf->b_fnum + msg_outtrans_attr((char *)name, tagstack[i].fmark.fnum == curbuf->b_fnum ? HL_ATTR(HLF_D) : 0); xfree(name); } @@ -1561,7 +1561,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc // Try tag file names from tags option one by one. for (first_file = true; - use_cscope || get_tagfname(&tn, first_file, tag_fname) == OK; + use_cscope || get_tagfname(&tn, first_file, (char *)tag_fname) == OK; first_file = false) { // A file that doesn't exist is silently ignored. Only when not a // single file is found, an error message is given (further on). @@ -1705,7 +1705,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc eof = vim_fgets(lbuf, lbuf_size, fp); } // skip empty and blank lines - while (!eof && vim_isblankline(lbuf)) { + while (!eof && vim_isblankline((char *)lbuf)) { search_info.curr_offset = vim_ftell(fp); eof = vim_fgets(lbuf, lbuf_size, fp); } @@ -1726,7 +1726,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc eof = use_cscope ? cs_fgets(lbuf, lbuf_size) : vim_fgets(lbuf, lbuf_size, fp); - } while (!eof && vim_isblankline(lbuf)); + } while (!eof && vim_isblankline((char *)lbuf)); if (eof) { break; // end of file @@ -1741,7 +1741,7 @@ line_read_in: // Convert every line. Converting the pattern from 'enc' to // the tags file encoding doesn't work, because characters are // not recognized. - conv_line = string_convert(&vimconv, lbuf, NULL); + conv_line = (char_u *)string_convert(&vimconv, (char *)lbuf, NULL); if (conv_line != NULL) { // Copy or swap lbuf and conv_line. len = (int)STRLEN(conv_line) + 1; @@ -2340,10 +2340,10 @@ void free_tag_stuff(void) /// @param buf pointer to buffer of MAXPATHL chars /// /// @return FAIL if no more tag file names, OK otherwise. -int get_tagfname(tagname_T *tnp, int first, char_u *buf) +int get_tagfname(tagname_T *tnp, int first, char *buf) { - char_u *fname = NULL; - char_u *r_ptr; + char *fname = NULL; + char *r_ptr; if (first) { CLEAR_POINTER(tnp); @@ -2374,7 +2374,7 @@ int get_tagfname(tagname_T *tnp, int first, char_u *buf) #ifdef BACKSLASH_IN_FILENAME slash_adjust(buf); #endif - simplify_filename(buf); + simplify_filename((char_u *)buf); for (int i = 0; i < tag_fnames.ga_len; i++) { if (STRCMP(buf, ((char **)(tag_fnames.ga_data))[i]) == 0) { @@ -2402,7 +2402,7 @@ int get_tagfname(tagname_T *tnp, int first, char_u *buf) */ for (;;) { if (tnp->tn_did_filefind_init) { - fname = vim_findfile(tnp->tn_search_ctx); + fname = (char *)vim_findfile(tnp->tn_search_ctx); if (fname != NULL) { break; } @@ -2422,17 +2422,17 @@ int get_tagfname(tagname_T *tnp, int first, char_u *buf) * Copy next file name into buf. */ buf[0] = NUL; - (void)copy_option_part(&tnp->tn_np, (char *)buf, MAXPATHL - 1, " ,"); + (void)copy_option_part(&tnp->tn_np, buf, MAXPATHL - 1, " ,"); - r_ptr = vim_findfile_stopdir(buf); + r_ptr = (char *)vim_findfile_stopdir((char_u *)buf); // move the filename one char forward and truncate the // filepath with a NUL - filename = (char_u *)path_tail((char *)buf); + filename = (char_u *)path_tail(buf); STRMOVE(filename + 1, filename); *filename++ = NUL; - tnp->tn_search_ctx = vim_findfile_init(buf, filename, - r_ptr, 100, + tnp->tn_search_ctx = vim_findfile_init((char_u *)buf, filename, + (char_u *)r_ptr, 100, false, // don't free visited list FINDFILE_FILE, // we search for a file tnp->tn_search_ctx, true, (char_u *)curbuf->b_ffname); diff --git a/src/nvim/undo.c b/src/nvim/undo.c index ac52bce2f9..97a925f3ad 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -685,7 +685,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) *p-- = NUL; } - bool has_directory = os_isdir((char_u *)dir_name); + bool has_directory = os_isdir(dir_name); if (!has_directory && *dirp == NUL && !reading) { // Last directory in the list does not exist, create it. int ret; diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index ae312de61a..5b2101587f 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -216,7 +216,7 @@ const char *set_context_in_user_cmd(expand_T *xp, const char *arg_in) // Check for attributes while (*arg == '-') { arg++; // Skip "-". - p = (const char *)skiptowhite((const char_u *)arg); + p = (const char *)skiptowhite(arg); if (*p == NUL) { // Cursor is still in the attribute. p = strchr(arg, '='); @@ -248,7 +248,7 @@ const char *set_context_in_user_cmd(expand_T *xp, const char *arg_in) } // After the attributes comes the new command name. - p = (const char *)skiptowhite((const char_u *)arg); + p = (const char *)skiptowhite(arg); if (*p == NUL) { xp->xp_context = EXPAND_USER_COMMANDS; xp->xp_pattern = (char *)arg; @@ -434,7 +434,7 @@ static void uc_list(char *name, size_t name_len) msg_putchar(' '); } - msg_outtrans_attr((char_u *)cmd->uc_name, HL_ATTR(HLF_D)); + msg_outtrans_attr(cmd->uc_name, HL_ATTR(HLF_D)); len = (int)STRLEN(cmd->uc_name) + 4; do { @@ -930,7 +930,7 @@ void ex_command(exarg_T *eap) // Check for attributes while (*p == '-') { p++; - end = (char *)skiptowhite((char_u *)p); + end = skiptowhite(p); if (uc_scan_attr(p, (size_t)(end - p), &argt, &def, &flags, &compl, (char_u **)&compl_arg, &addr_type_arg) == FAIL) { return; diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 3e12d8b0b4..ec8d6ab153 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -230,10 +230,7 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext() # endif #endif -#define STRRCHR(s, c) (char_u *)strrchr((const char *)(s), (c)) - -#define STRCAT(d, s) strcat((char *)(d), (char *)(s)) -#define STRNCAT(d, s, n) strncat((char *)(d), (char *)(s), (size_t)(n)) +#define STRCAT(d, s) strcat((char *)(d), (char *)(s)) // NOLINT(runtime/printf) #define STRLCAT(d, s, n) xstrlcat((char *)(d), (char *)(s), (size_t)(n)) // Character used as separated in autoload function/variable names. diff --git a/src/nvim/viml/parser/parser.h b/src/nvim/viml/parser/parser.h index b8835127e7..55f54cedbe 100644 --- a/src/nvim/viml/parser/parser.h +++ b/src/nvim/viml/parser/parser.h @@ -142,9 +142,7 @@ static inline void viml_preader_get_line(ParserInputReader *const preader, .allocated = true, .size = pline.size, }; - cpline.data = (char *)string_convert(&preader->conv, - (char_u *)pline.data, - &cpline.size); + cpline.data = string_convert(&preader->conv, (char *)pline.data, &cpline.size); if (pline.allocated) { xfree((void *)pline.data); } diff --git a/src/nvim/window.c b/src/nvim/window.c index 832cb82bda..5adc8db088 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -730,7 +730,7 @@ void win_set_minimal_style(win_T *wp) char_u *old = (char_u *)wp->w_p_fcs; wp->w_p_fcs = ((*old == NUL) ? xstrdup("eob: ") - : (char *)concat_str(old, (char_u *)",eob: ")); + : concat_str((char *)old, ",eob: ")); free_string_option((char *)old); } @@ -739,7 +739,7 @@ void win_set_minimal_style(win_T *wp) char_u *old = (char_u *)wp->w_p_winhl; wp->w_p_winhl = ((*old == NUL) ? xstrdup("EndOfBuffer:") - : (char *)concat_str(old, (char_u *)",EndOfBuffer:")); + : concat_str((char *)old, ",EndOfBuffer:")); free_string_option((char *)old); parse_winhl_opt(wp); -- cgit From 6b7eed1884c3b022cc15568c39f80f8f4da0780b Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 30 Aug 2022 21:16:03 +0200 Subject: Vim 9.0.{0314,0319}: some filetypes are not recognized (#20005) * vim-patch:9.0.0314: VDM files are not recognized Problem: VDM files are not recognized. Solution: Add patterns for VDM files. (Alessandro Pezzoni, closes vim/vim#11004) https://github.com/vim/vim/commit/bf26941f40923d331169a4ecb7341608f5d1ca38 * vim-patch:9.0.0319: Godot shader files are not recognized Problem: Godot shader files are not recognized. Solution: Add patterns for "gdshader". (Maxim Kim, closes vim/vim#11006) https://github.com/vim/vim/commit/d5c8f11905abc1bdf3b8864dbc40187855ed9374 --- src/nvim/testdir/test_filetype.vim | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index e3a8370661..68ce9148a4 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -209,6 +209,7 @@ let s:filename_checks = { \ 'gdmo': ['file.mo', 'file.gdmo'], \ 'gdresource': ['file.tscn', 'file.tres'], \ 'gdscript': ['file.gd'], + \ 'gdshader': ['file.gdshader', 'file.shader'], \ 'gedcom': ['file.ged', 'lltxxxxx.txt', '/tmp/lltmp', '/tmp/lltmp-file', 'any/tmp/lltmp', 'any/tmp/lltmp-file'], \ 'gemtext': ['file.gmi', 'file.gemini'], \ 'gift': ['file.gift'], @@ -588,6 +589,9 @@ let s:filename_checks = { \ 'usw2kagtlog': ['usw2kagt.log', 'USW2KAGT.LOG', 'usw2kagt.file.log', 'USW2KAGT.FILE.LOG', 'file.usw2kagt.log', 'FILE.USW2KAGT.LOG'], \ 'vala': ['file.vala'], \ 'vb': ['file.sba', 'file.vb', 'file.vbs', 'file.dsm', 'file.ctl'], + \ 'vdmpp': ['file.vpp', 'file.vdmpp'], + \ 'vdmrt': ['file.vdmrt'], + \ 'vdmsl': ['file.vdm', 'file.vdmsl'], \ 'vera': ['file.vr', 'file.vri', 'file.vrh'], \ 'verilog': ['file.v'], \ 'verilogams': ['file.va', 'file.vams'], -- cgit From 813476bf7291dfaf9fc0ef77c9f53a07258a3801 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Tue, 30 Aug 2022 23:13:52 +0100 Subject: fix(exceptions): restore `did_throw` (#20000) `!did_throw` doesn't exactly imply `!current_exception`, as `did_throw = false` is sometimes used to defer exception handling for later (without forgetting the exception). E.g: uncaught exception handling in `do_cmdline()` may be deferred to a different call (e.g: when `try_level > 0`). In #7881, `current_exception = NULL` in `do_cmdline()` is used as an analogue of `did_throw = false`, but also causes the pending exception to be lost, which also leaks as `discard_exception()` wasn't used. It may be possible to fix this by saving/restoring `current_exception`, but handling all of `did_throw`'s edge cases seems messier. Maybe not worth diverging over. This fix also uncovers a `man_spec.lua` bug on Windows: exceptions are thrown due to Windows missing `man`, but they're lost; skip these tests if `man` isn't executable. --- src/nvim/api/private/helpers.c | 8 +- src/nvim/api/private/helpers.h | 1 + src/nvim/api/vimscript.c | 4 +- src/nvim/eval.c | 2 +- src/nvim/eval/userfunc.c | 2 +- src/nvim/ex_docmd.c | 32 ++++---- src/nvim/ex_eval.c | 163 +++++++++++++++++++---------------------- src/nvim/globals.h | 6 +- src/nvim/lua/executor.c | 2 +- 9 files changed, 109 insertions(+), 111 deletions(-) (limited to 'src') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index e35c58bf1b..ebcf6cca6d 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -58,6 +58,7 @@ void try_enter(TryState *const tstate) .private_msg_list = NULL, .trylevel = trylevel, .got_int = got_int, + .did_throw = did_throw, .need_rethrow = need_rethrow, .did_emsg = did_emsg, }; @@ -65,6 +66,7 @@ void try_enter(TryState *const tstate) current_exception = NULL; trylevel = 1; got_int = false; + did_throw = false; need_rethrow = false; did_emsg = false; } @@ -85,6 +87,7 @@ bool try_leave(const TryState *const tstate, Error *const err) assert(trylevel == 0); assert(!need_rethrow); assert(!got_int); + assert(!did_throw); assert(!did_emsg); assert(msg_list == &tstate->private_msg_list); assert(*msg_list == NULL); @@ -93,6 +96,7 @@ bool try_leave(const TryState *const tstate, Error *const err) current_exception = tstate->current_exception; trylevel = tstate->trylevel; got_int = tstate->got_int; + did_throw = tstate->did_throw; need_rethrow = tstate->need_rethrow; did_emsg = tstate->did_emsg; return ret; @@ -127,7 +131,7 @@ bool try_end(Error *err) force_abort = false; if (got_int) { - if (current_exception) { + if (did_throw) { // If we got an interrupt, discard the current exception discard_current_exception(); } @@ -146,7 +150,7 @@ bool try_end(Error *err) if (should_free) { xfree(msg); } - } else if (current_exception) { + } else if (did_throw) { api_set_error(err, kErrorTypeException, "%s", current_exception->value); discard_current_exception(); } diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 4608554448..2157ad0ec2 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -134,6 +134,7 @@ typedef struct { const msglist_T *const *msg_list; int trylevel; int got_int; + bool did_throw; int need_rethrow; int did_emsg; } TryState; diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index a28bfd2ab9..f6d0e39327 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -137,7 +137,7 @@ Object nvim_eval(String expr, Error *err) if (!recursive) { force_abort = false; suppress_errthrow = false; - current_exception = NULL; + did_throw = false; // `did_emsg` is set by emsg(), which cancels execution. did_emsg = false; } @@ -196,7 +196,7 @@ static Object _call_function(String fn, Array args, dict_T *self, Error *err) if (!recursive) { force_abort = false; suppress_errthrow = false; - current_exception = NULL; + did_throw = false; // `did_emsg` is set by emsg(), which cancels execution. did_emsg = false; } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 508d7cf491..2dbaa2f8ac 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5985,7 +5985,7 @@ void timer_due_cb(TimeWatcher *tw, void *data) // Handle error message if (called_emsg > called_emsg_before && did_emsg) { timer->emsg_count++; - if (current_exception != NULL) { + if (did_throw) { discard_current_exception(); } } diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index b9a94a971b..1f94f9c2b7 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -3010,7 +3010,7 @@ void ex_call(exarg_T *eap) // When inside :try we need to check for following "| catch" or "| endtry". // Not when there was an error, but do check if an exception was thrown. - if ((!aborting() || current_exception != NULL) && (!failed || eap->cstack->cs_trylevel > 0)) { + if ((!aborting() || did_throw) && (!failed || eap->cstack->cs_trylevel > 0)) { // Check for trailing illegal characters and a following command. if (!ends_excmd(*arg)) { if (!failed && !aborting()) { diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 1fa14f4e4f..bf518f3849 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -134,6 +134,7 @@ struct dbg_stuff { char *vv_throwpoint; int did_emsg; int got_int; + bool did_throw; int need_rethrow; int check_cstack; except_T *current_exception; @@ -165,6 +166,7 @@ static void save_dbg_stuff(struct dbg_stuff *dsp) // Necessary for debugging an inactive ":catch", ":finally", ":endtry". dsp->did_emsg = did_emsg; did_emsg = false; dsp->got_int = got_int; got_int = false; + dsp->did_throw = did_throw; did_throw = false; dsp->need_rethrow = need_rethrow; need_rethrow = false; dsp->check_cstack = check_cstack; check_cstack = false; dsp->current_exception = current_exception; current_exception = NULL; @@ -180,6 +182,7 @@ static void restore_dbg_stuff(struct dbg_stuff *dsp) (void)v_throwpoint(dsp->vv_throwpoint); did_emsg = dsp->did_emsg; got_int = dsp->got_int; + did_throw = dsp->did_throw; need_rethrow = dsp->need_rethrow; check_cstack = dsp->check_cstack; current_exception = dsp->current_exception; @@ -397,7 +400,8 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) initial_trylevel = trylevel; - current_exception = NULL; + // "did_throw" will be set to true when an exception is being thrown. + did_throw = false; // "did_emsg" will be set to true when emsg() is used, in which case we // cancel the whole command line, and any if/endif or loop. // If force_abort is set, we cancel everything. @@ -625,7 +629,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) // not to use a cs_line[] from an entry that isn't a ":while" // or ":for": It would make "current_line" invalid and can // cause a crash. - if (!did_emsg && !got_int && !current_exception + if (!did_emsg && !got_int && !did_throw && cstack.cs_idx >= 0 && (cstack.cs_flags[cstack.cs_idx] & (CSF_WHILE | CSF_FOR)) @@ -666,7 +670,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) current_line = 0; } - // A ":finally" makes did_emsg, got_int and current_exception pending for + // A ":finally" makes did_emsg, got_int and did_throw pending for // being restored at the ":endtry". Reset them here and set the // ACTIVE and FINALLY flags, so that the finally clause gets executed. // This includes the case where a missing ":endif", ":endwhile" or @@ -675,9 +679,8 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) cstack.cs_lflags &= ~CSL_HAD_FINA; report_make_pending((cstack.cs_pending[cstack.cs_idx] & (CSTP_ERROR | CSTP_INTERRUPT | CSTP_THROW)), - current_exception); - did_emsg = got_int = false; - current_exception = NULL; + did_throw ? current_exception : NULL); + did_emsg = got_int = did_throw = false; cstack.cs_flags[cstack.cs_idx] |= CSF_ACTIVE | CSF_FINALLY; } @@ -690,7 +693,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) // exception, cancel everything. If it is left normally, reset // force_abort to get the non-EH compatible abortion behavior for // the rest of the script. - if (trylevel == 0 && !did_emsg && !got_int && !current_exception) { + if (trylevel == 0 && !did_emsg && !got_int && !did_throw) { force_abort = false; } @@ -704,7 +707,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) // - didn't get an error message or lines are not typed // - there is a command after '|', inside a :if, :while, :for or :try, or // looping for ":source" command or function call. - } while (!((got_int || (did_emsg && force_abort) || current_exception) + } while (!((got_int || (did_emsg && force_abort) || did_throw) && cstack.cs_trylevel == 0) && !(did_emsg // Keep going when inside try/catch, so that the error can be @@ -724,7 +727,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) if (cstack.cs_idx >= 0) { // If a sourced file or executed function ran to its end, report the // unclosed conditional. - if (!got_int && !current_exception + if (!got_int && !did_throw && ((getline_equal(fgetline, cookie, getsourceline) && !source_finished(fgetline, cookie)) || (getline_equal(fgetline, cookie, get_func_line) @@ -767,7 +770,8 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) // conditional, discard the uncaught exception, disable the conversion // of interrupts or errors to exceptions, and ensure that no more // commands are executed. - if (current_exception) { + if (did_throw) { + assert(current_exception != NULL); char *p = NULL; msglist_T *messages = NULL; msglist_T *next; @@ -829,14 +833,14 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) // cstack belongs to the same function or, respectively, script file, it // will have to be checked for finally clauses to be executed due to the // ":return" or ":finish". This is done in do_one_cmd(). - if (current_exception) { + if (did_throw) { need_rethrow = true; } if ((getline_equal(fgetline, cookie, getsourceline) && ex_nesting_level > source_level(real_cookie)) || (getline_equal(fgetline, cookie, get_func_line) && ex_nesting_level > func_level(real_cookie) + 1)) { - if (!current_exception) { + if (!did_throw) { check_cstack = true; } } else { @@ -1675,7 +1679,7 @@ static void profile_cmd(const exarg_T *eap, cstack_T *cstack, LineGetter fgetlin && (!eap->skip || cstack->cs_idx == 0 || (cstack->cs_idx > 0 && (cstack->cs_flags[cstack->cs_idx - 1] & CSF_ACTIVE)))) { - int skip = did_emsg || got_int || current_exception; + bool skip = did_emsg || got_int || did_throw; if (eap->cmdidx == CMD_catch) { skip = !skip && !(cstack->cs_idx >= 0 @@ -1872,7 +1876,7 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter ea.skip = (did_emsg || got_int - || current_exception + || did_throw || (cstack->cs_idx >= 0 && !(cstack->cs_flags[cstack->cs_idx] & CSF_ACTIVE))); diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 11795684cf..6dddafcfcb 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -49,16 +49,15 @@ // interrupt (got_int) under an active try conditional terminates the script // after the non-active finally clauses of all active try conditionals have been // executed. Otherwise, errors and/or interrupts are converted into catchable -// exceptions, which terminate the script only if not caught. For user -// exceptions, only current_exception is set. (Note: got_int can be set -// asynchronously afterwards by a SIGINT, so current_exception && got_int is not +// exceptions (did_throw additionally set), which terminate the script only if +// not caught. For user exceptions, only did_throw is set. (Note: got_int can +// be set asynchronously afterwards by a SIGINT, so did_throw && got_int is not // a reliant test that the exception currently being thrown is an interrupt // exception. Similarly, did_emsg can be set afterwards on an error in an -// (unskipped) conditional command inside an inactive conditional, so -// current_exception && did_emsg is not a reliant test that the exception -// currently being thrown is an error exception.) - The macros can be defined -// as expressions checking for a variable that is allowed to be changed during -// execution of a script. +// (unskipped) conditional command inside an inactive conditional, so did_throw +// && did_emsg is not a reliant test that the exception currently being thrown +// is an error exception.) - The macros can be defined as expressions checking +// for a variable that is allowed to be changed during execution of a script. // Values used for the Vim release. #define THROW_ON_ERROR true @@ -71,7 +70,7 @@ #define CHECK_SKIP \ (did_emsg \ || got_int \ - || current_exception \ + || did_throw \ || (cstack->cs_idx > 0 \ && !(cstack->cs_flags[cstack->cs_idx - 1] & CSF_ACTIVE))) @@ -104,7 +103,7 @@ static int cause_abort = false; /// value. "got_int" is also set by calling interrupt(). int aborting(void) { - return (did_emsg && force_abort) || got_int || current_exception; + return (did_emsg && force_abort) || got_int || did_throw; } /// The value of "force_abort" is temporarily reset by the first emsg() call @@ -186,7 +185,7 @@ bool cause_errthrow(const char *mesg, bool severe, bool *ignore) * currently throwing an exception, do nothing. The message text will * then be stored to v:errmsg by emsg() without displaying it. */ - if (((trylevel == 0 && !cause_abort) || emsg_silent) && !current_exception) { + if (((trylevel == 0 && !cause_abort) || emsg_silent) && !did_throw) { return false; } @@ -217,7 +216,7 @@ bool cause_errthrow(const char *mesg, bool severe, bool *ignore) * exception currently being thrown to prevent it from being caught. Just * execute finally clauses and terminate. */ - if (current_exception) { + if (did_throw) { // When discarding an interrupt exception, reset got_int to prevent the // same interrupt being converted to an exception again and discarding // the error exception we are about to throw here. @@ -349,7 +348,7 @@ int do_intthrow(cstack_T *cstack) { // If no interrupt occurred or no try conditional is active and no exception // is being thrown, do nothing (for compatibility of non-EH scripts). - if (!got_int || (trylevel == 0 && !current_exception)) { + if (!got_int || (trylevel == 0 && !did_throw)) { return false; } @@ -358,7 +357,7 @@ int do_intthrow(cstack_T *cstack) // The interrupt aborts everything except for executing finally clauses. // Discard any user or error or interrupt exception currently being // thrown. - if (current_exception) { + if (did_throw) { discard_current_exception(); } } else { @@ -369,7 +368,7 @@ int do_intthrow(cstack_T *cstack) // will be terminated then. - If an interrupt exception is already // being thrown, do nothing. - if (current_exception) { + if (did_throw) { if (current_exception->type == ET_INTERRUPT) { return false; } @@ -596,6 +595,7 @@ void discard_current_exception(void) } // Note: all globals manipulated here should be saved/restored in // try_enter/try_leave. + did_throw = false; need_rethrow = false; } @@ -1237,6 +1237,8 @@ void do_throw(cstack_T *cstack) cstack->cs_flags[idx] &= ~CSF_ACTIVE; cstack->cs_exception[idx] = current_exception; } + + did_throw = true; } /// Handle ":try" @@ -1345,7 +1347,7 @@ void ex_catch(exarg_T *eap) * corresponding try block never got active (because of an inactive * surrounding conditional or after an error or interrupt or throw). */ - if (!current_exception || !(cstack->cs_flags[idx] & CSF_TRUE)) { + if (!did_throw || !(cstack->cs_flags[idx] & CSF_TRUE)) { skip = true; } @@ -1406,10 +1408,10 @@ void ex_catch(exarg_T *eap) } if (caught) { - // Make this ":catch" clause active and reset did_emsg and got_int. - // Put the exception on the caught stack. + // Make this ":catch" clause active and reset did_emsg, got_int, + // and did_throw. Put the exception on the caught stack. cstack->cs_flags[idx] |= CSF_ACTIVE | CSF_CAUGHT; - did_emsg = got_int = false; + did_emsg = got_int = did_throw = false; catch_exception((except_T *)cstack->cs_exception[idx]); // It's mandatory that the current exception is stored in the cstack // so that it can be discarded at the next ":catch", ":finally", or @@ -1419,10 +1421,6 @@ void ex_catch(exarg_T *eap) if (cstack->cs_exception[cstack->cs_idx] != current_exception) { internal_error("ex_catch()"); } - // Discarding current_exceptions happens based on what is stored in - // cstack->cs_exception, *all* calls to discard_current_exception() are - // (and must be) guarded by current_exception check. - current_exception = NULL; } else { /* * If there is a preceding catch clause and it caught the exception, @@ -1477,14 +1475,12 @@ void ex_finally(exarg_T *eap) rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, &cstack->cs_looplevel); - /* - * Don't do something when the corresponding try block never got active - * (because of an inactive surrounding conditional or after an error or - * interrupt or throw) or for a ":finally" without ":try" or a multiple - * ":finally". After every other error (did_emsg or the conditional - * errors detected above) or after an interrupt (got_int) or an - * exception (current_exception), the finally clause must be executed. - */ + // Don't do something when the corresponding try block never got active + // (because of an inactive surrounding conditional or after an error or + // interrupt or throw) or for a ":finally" without ":try" or a multiple + // ":finally". After every other error (did_emsg or the conditional + // errors detected above) or after an interrupt (got_int) or an + // exception (did_throw), the finally clause must be executed. skip = !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE); if (!skip) { @@ -1509,22 +1505,20 @@ void ex_finally(exarg_T *eap) */ cleanup_conditionals(cstack, CSF_TRY, false); - /* - * Make did_emsg, got_int, current_exception pending. If set, they - * overrule a pending ":continue", ":break", ":return", or ":finish". - * Then we have particularly to discard a pending return value (as done - * by the call to cleanup_conditionals() above when did_emsg or - * got_int is set). The pending values are restored by the - * ":endtry", except if there is a new error, interrupt, exception, - * ":continue", ":break", ":return", or ":finish" in the following - * finally clause. A missing ":endwhile", ":endfor" or ":endif" - * detected here is treated as if did_emsg and current_exception had - * already been set, respectively in case that the error is not - * converted to an exception, current_exception had already been unset. - * We must not set did_emsg here since that would suppress the - * error message. - */ - if (pending == CSTP_ERROR || did_emsg || got_int || current_exception) { + // Make did_emsg, got_int, did_throw pending. If set, they overrule + // a pending ":continue", ":break", ":return", or ":finish". Then + // we have particularly to discard a pending return value (as done + // by the call to cleanup_conditionals() above when did_emsg or + // got_int is set). The pending values are restored by the + // ":endtry", except if there is a new error, interrupt, exception, + // ":continue", ":break", ":return", or ":finish" in the following + // finally clause. A missing ":endwhile", ":endfor" or ":endif" + // detected here is treated as if did_emsg and did_throw had + // already been set, respectively in case that the error is not + // converted to an exception, did_throw had already been unset. + // We must not set did_emsg here since that would suppress the + // error message. + if (pending == CSTP_ERROR || did_emsg || got_int || did_throw) { if (cstack->cs_pending[cstack->cs_idx] == CSTP_RETURN) { report_discard_pending(CSTP_RETURN, cstack->cs_rettv[cstack->cs_idx]); @@ -1533,7 +1527,7 @@ void ex_finally(exarg_T *eap) if (pending == CSTP_ERROR && !did_emsg) { pending |= (THROW_ON_ERROR ? CSTP_THROW : 0); } else { - pending |= (current_exception ? CSTP_THROW : 0); + pending |= (did_throw ? CSTP_THROW : 0); } pending |= did_emsg ? CSTP_ERROR : 0; pending |= got_int ? CSTP_INTERRUPT : 0; @@ -1547,19 +1541,16 @@ void ex_finally(exarg_T *eap) // exception. When emsg() is called for a missing ":endif" or // a missing ":endwhile"/":endfor" detected here, the // exception will be discarded. - if (current_exception - && cstack->cs_exception[cstack->cs_idx] != current_exception) { + if (did_throw && cstack->cs_exception[cstack->cs_idx] != current_exception) { internal_error("ex_finally()"); } } - /* - * Set CSL_HAD_FINA, so do_cmdline() will reset did_emsg, - * got_int, and current_exception and make the finally clause active. - * This will happen after emsg() has been called for a missing - * ":endif" or a missing ":endwhile"/":endfor" detected here, so - * that the following finally clause will be executed even then. - */ + // Set CSL_HAD_FINA, so do_cmdline() will reset did_emsg, + // got_int, and did_throw and make the finally clause active. + // This will happen after emsg() has been called for a missing + // ":endif" or a missing ":endwhile"/":endfor" detected here, so + // that the following finally clause will be executed even then. cstack->cs_lflags |= CSL_HAD_FINA; } } @@ -1587,8 +1578,7 @@ void ex_endtry(exarg_T *eap) // made inactive by a ":continue", ":break", ":return", or ":finish" in // the finally clause. The latter case need not be tested since then // anything pending has already been discarded. - bool skip = did_emsg || got_int || current_exception - || !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE); + bool skip = did_emsg || got_int || did_throw || !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE); if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { eap->errmsg = get_end_emsg(cstack); @@ -1602,14 +1592,12 @@ void ex_endtry(exarg_T *eap) &cstack->cs_looplevel); skip = true; - /* - * If an exception is being thrown, discard it to prevent it from - * being rethrown at the end of this function. It would be - * discarded by the error message, anyway. Resets current_exception. - * This does not affect the script termination due to the error - * since "trylevel" is decremented after emsg() has been called. - */ - if (current_exception) { + // If an exception is being thrown, discard it to prevent it from + // being rethrown at the end of this function. It would be + // discarded by the error message, anyway. Resets did_throw. + // This does not affect the script termination due to the error + // since "trylevel" is decremented after emsg() has been called. + if (did_throw) { discard_current_exception(); } @@ -1624,7 +1612,7 @@ void ex_endtry(exarg_T *eap) * a finally clause, we need to rethrow it after closing the try * conditional. */ - if (current_exception + if (did_throw && (cstack->cs_flags[idx] & CSF_TRUE) && !(cstack->cs_flags[idx] & CSF_FINALLY)) { rethrow = true; @@ -1648,10 +1636,10 @@ void ex_endtry(exarg_T *eap) if (got_int) { skip = true; (void)do_intthrow(cstack); - // The do_intthrow() call may have reset current_exception or + // The do_intthrow() call may have reset did_throw or // cstack->cs_pending[idx]. rethrow = false; - if (current_exception && !(cstack->cs_flags[idx] & CSF_FINALLY)) { + if (did_throw && !(cstack->cs_flags[idx] & CSF_FINALLY)) { rethrow = true; } } @@ -1721,7 +1709,7 @@ void ex_endtry(exarg_T *eap) // When the finally clause was entered due to an error, // interrupt or throw (as opposed to a ":continue", ":break", // ":return", or ":finish"), restore the pending values of - // did_emsg, got_int, and current_exception. This is skipped, if there + // did_emsg, got_int, and did_throw. This is skipped, if there // was a new error, interrupt, throw, ":continue", ":break", // ":return", or ":finish". in the finally clause. default: @@ -1768,24 +1756,22 @@ void enter_cleanup(cleanup_T *csp) { int pending = CSTP_NONE; - /* - * Postpone did_emsg, got_int, current_exception. The pending values will be - * restored by leave_cleanup() except if there was an aborting error, - * interrupt, or uncaught exception after this function ends. - */ - if (did_emsg || got_int || current_exception || need_rethrow) { + // Postpone did_emsg, got_int, did_throw. The pending values will be + // restored by leave_cleanup() except if there was an aborting error, + // interrupt, or uncaught exception after this function ends. + if (did_emsg || got_int || did_throw || need_rethrow) { csp->pending = (did_emsg ? CSTP_ERROR : 0) | (got_int ? CSTP_INTERRUPT : 0) - | (current_exception ? CSTP_THROW : 0) + | (did_throw ? CSTP_THROW : 0) | (need_rethrow ? CSTP_THROW : 0); - // If we are currently throwing an exception, save it as well. On an error - // not yet converted to an exception, update "force_abort" and reset - // "cause_abort" (as do_errthrow() would do). This is needed for the - // do_cmdline() call that is going to be made for autocommand execution. We - // need not save *msg_list because there is an extra instance for every call - // of do_cmdline(), anyway. - if (current_exception || need_rethrow) { + // If we are currently throwing an exception (did_throw), save it as + // well. On an error not yet converted to an exception, update + // "force_abort" and reset "cause_abort" (as do_errthrow() would do). + // This is needed for the do_cmdline() call that is going to be made + // for autocommand execution. We need not save *msg_list because + // there is an extra instance for every call of do_cmdline(), anyway. + if (did_throw || need_rethrow) { csp->exception = current_exception; current_exception = NULL; } else { @@ -1795,8 +1781,7 @@ void enter_cleanup(cleanup_T *csp) cause_abort = false; } } - did_emsg = got_int = need_rethrow = false; - current_exception = NULL; + did_emsg = got_int = did_throw = need_rethrow = false; // Report if required by the 'verbose' option or when debugging. report_make_pending(pending, csp->exception); @@ -1866,7 +1851,7 @@ void leave_cleanup(cleanup_T *csp) force_abort = false; } - // Restore the pending values of did_emsg, got_int, and current_exception. + // Restore the pending values of did_emsg, got_int, and did_throw. if (pending & CSTP_ERROR) { did_emsg = true; } @@ -1874,7 +1859,7 @@ void leave_cleanup(cleanup_T *csp) got_int = true; } if (pending & CSTP_THROW) { - need_rethrow = true; // current_exception will be set by do_one_cmd() + need_rethrow = true; // did_throw will be set by do_one_cmd() } // Report if required by the 'verbose' option or when debugging. diff --git a/src/nvim/globals.h b/src/nvim/globals.h index ddbe727db9..060db3b3b1 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -241,9 +241,13 @@ EXTERN int do_profiling INIT(= PROF_NONE); ///< PROF_ values /// Exception currently being thrown. Used to pass an exception to a different /// cstack. Also used for discarding an exception before it is caught or made -/// pending. +/// pending. Only valid when did_throw is true. EXTERN except_T *current_exception; +/// An exception is being thrown. Reset when the exception is caught or as +/// long as it is pending in a finally clause. +EXTERN bool did_throw INIT(= false); + /// Set when a throw that cannot be handled in do_cmdline() must be propagated /// to the cstack of the previously called do_cmdline(). EXTERN bool need_rethrow INIT(= false); diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 39585ac182..42aa13cfc1 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1027,7 +1027,7 @@ int nlua_call(lua_State *lstate) // TODO(bfredl): this should be simplified in error handling refactor force_abort = false; suppress_errthrow = false; - current_exception = NULL; + did_throw = false; did_emsg = false; try_start(); -- cgit From 94a2bc594020f2bb1f41d5e2e92d05ce9c293254 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 31 Aug 2022 06:27:39 +0800 Subject: vim-patch:9.0.0332: overwrite check may block BufWriteCmd (#20014) Problem: Overwrite check may block BufWriteCmd. Solution: Do not use overwrite check when 'buftype' is "acwrite". (closes vim/vim#11011) https://github.com/vim/vim/commit/9c8f94636b3610b898ffbbd07f6b75866d16cbca --- src/nvim/ex_cmds.c | 13 +++++++++---- src/nvim/testdir/test_autocmd.vim | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index fc753cf65c..e672b80d69 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1996,11 +1996,16 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int oth { // Write to another file or b_flags set or not writing the whole file: // overwriting only allowed with '!' + // If "other" is false and bt_nofilename(buf) is true, this must be + // writing an "acwrite" buffer to the same file as its b_ffname, and + // buf_write() will only allow writing with BufWriteCmd autocommands, + // so there is no need for an overwrite check. if ((other - || (buf->b_flags & BF_NOTEDITED) - || ((buf->b_flags & BF_NEW) - && vim_strchr(p_cpo, CPO_OVERNEW) == NULL) - || (buf->b_flags & BF_READERR)) + || (!bt_nofilename(buf) + && ((buf->b_flags & BF_NOTEDITED) + || ((buf->b_flags & BF_NEW) + && vim_strchr(p_cpo, CPO_OVERNEW) == NULL) + || (buf->b_flags & BF_READERR)))) && !p_wa && os_path_exists((char_u *)ffname)) { if (!eap->forceit && !eap->append) { diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 27bc6303cf..3064b199d9 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1836,6 +1836,21 @@ func Test_BufReadCmd() au! BufWriteCmd endfunc +func Test_BufWriteCmd() + autocmd BufWriteCmd Xbufwritecmd let g:written = 1 + new + file Xbufwritecmd + set buftype=acwrite + call mkdir('Xbufwritecmd') + write + " BufWriteCmd should be triggered even if a directory has the same name + call assert_equal(1, g:written) + call delete('Xbufwritecmd', 'd') + unlet g:written + au! BufWriteCmd + bwipe! +endfunc + func SetChangeMarks(start, end) exe a:start .. 'mark [' exe a:end .. 'mark ]' -- cgit From 518b5c65b0c6f5ee75718048fc661e629a01429b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 31 Aug 2022 06:58:28 +0800 Subject: vim-patch:8.1.2037: can call win_gotoid() in cmdline window (#20015) Problem: Can call win_gotoid() in cmdline window. Solution: Disallow switching windows. (Yasuhiro Matsumoto, closes vim/vim#4940) https://github.com/vim/vim/commit/a046b37c22bcabdea5f0fd6d21ca4bd0aa4c768e --- src/nvim/eval/funcs.c | 14 +++++++++++++- src/nvim/testdir/test_cmdline.vim | 10 ++++++++++ src/nvim/window.c | 13 ------------- 3 files changed, 23 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index f21011d22b..aa328d50ef 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -9659,7 +9659,19 @@ static void f_win_gettype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "win_gotoid()" function static void f_win_gotoid(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - rettv->vval.v_number = win_gotoid(argvars); + int id = (int)tv_get_number(&argvars[0]); + + if (cmdwin_type != 0) { + emsg(_(e_cmdwin)); + return; + } + FOR_ALL_TAB_WINDOWS(tp, wp) { + if (wp->handle == id) { + goto_tabpage_win(tp, wp); + rettv->vval.v_number = 1; + return; + } + } } /// "win_id2tabwin()" function diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 045504b8bf..4bfd22cb6c 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1260,6 +1260,16 @@ func Test_cmdline_overstrike() let &encoding = encoding_save endfunc +func Test_cmdwin_bug() + let winid = win_getid() + sp + try + call feedkeys("q::call win_gotoid(" .. winid .. ")\:q\", 'x!') + catch /^Vim\%((\a\+)\)\=:E11/ + endtry + bw! +endfunc + func Test_cmdwin_restore() CheckScreendump diff --git a/src/nvim/window.c b/src/nvim/window.c index 5adc8db088..74ea1172ee 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -7396,19 +7396,6 @@ int win_getid(typval_T *argvars) return 0; } -int win_gotoid(typval_T *argvars) -{ - int id = (int)tv_get_number(&argvars[0]); - - FOR_ALL_TAB_WINDOWS(tp, wp) { - if (wp->handle == id) { - goto_tabpage_win(tp, wp); - return 1; - } - } - return 0; -} - void win_get_tabwin(handle_T id, int *tabnr, int *winnr) { *tabnr = 0; -- cgit From 5ff2ea66873dc0bcd1921158a93e363f009b245d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 31 Aug 2022 07:24:16 +0800 Subject: vim-patch:8.2.0301: insufficient testing for exception handling (#20016) Problem: Insufficient testing for exception handling and the "attention" prompt. Solution: Add test cases. (Yegappan Lakshmanan, closes vim/vim#5681) https://github.com/vim/vim/commit/b654103ad1e379348616f354272db86804ab4bdb Fix memory leak from last char_u refactor. --- src/nvim/eval/userfunc.c | 3 +- src/nvim/testdir/test_swap.vim | 1 + src/nvim/testdir/test_trycatch.vim | 175 +++++++++++++++++++++++++++++++++++-- 3 files changed, 171 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 1f94f9c2b7..4be922a055 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -3111,8 +3111,7 @@ char *get_return_cmd(void *rettv) char *tofree = NULL; if (rettv != NULL) { - tofree = encode_tv2echo((typval_T *)rettv, NULL); - s = encode_tv2echo((typval_T *)rettv, NULL); + tofree = s = encode_tv2echo((typval_T *)rettv, NULL); } if (s == NULL) { s = ""; diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 923e1cbf50..5c9e39f1f4 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -2,6 +2,7 @@ source check.vim source shared.vim +source term_util.vim func s:swapname() return trim(execute('swapname')) diff --git a/src/nvim/testdir/test_trycatch.vim b/src/nvim/testdir/test_trycatch.vim index 646594e482..d71bb5bbb8 100644 --- a/src/nvim/testdir/test_trycatch.vim +++ b/src/nvim/testdir/test_trycatch.vim @@ -2027,16 +2027,179 @@ func Test_try_catch_verbose() endtry redir END let expected = [ - \ 'Exception thrown: Vim(echo):E121: Undefined variable: i', - \ '', - \ 'Exception caught: Vim(echo):E121: Undefined variable: i', - \ '', - \ 'Exception finished: Vim(echo):E121: Undefined variable: i' - \ ] + \ 'Exception thrown: Vim(echo):E121: Undefined variable: i', '', + \ 'Exception caught: Vim(echo):E121: Undefined variable: i', '', + \ 'Exception finished: Vim(echo):E121: Undefined variable: i'] call assert_equal(expected, split(msg, "\n")) + + " Test for verbose messages displayed when an exception is discarded + redir => msg + try + try + throw 'abc' + finally + throw 'xyz' + endtry + catch + endtry + redir END + let expected = [ + \ 'Exception thrown: abc', '', + \ 'Exception made pending: abc', '', + \ 'Exception thrown: xyz', '', + \ 'Exception discarded: abc', '', + \ 'Exception caught: xyz', '', + \ 'Exception finished: xyz'] + call assert_equal(expected, split(msg, "\n")) + + " Test for messages displayed when :throw is resumed after :finally + redir => msg + try + try + throw 'abc' + finally + endtry + catch + endtry + redir END + let expected = [ + \ 'Exception thrown: abc', '', + \ 'Exception made pending: abc', '', + \ 'Exception resumed: abc', '', + \ 'Exception caught: abc', '', + \ 'Exception finished: abc'] + call assert_equal(expected, split(msg, "\n")) + + " Test for messages displayed when :break is resumed after :finally + redir => msg + for i in range(1) + try + break + finally + endtry + endfor + redir END + let expected = [':break made pending', '', ':break resumed'] + call assert_equal(expected, split(msg, "\n")) + + " Test for messages displayed when :continue is resumed after :finally + redir => msg + for i in range(1) + try + continue + finally + endtry + endfor + redir END + let expected = [':continue made pending', '', ':continue resumed'] + call assert_equal(expected, split(msg, "\n")) + + " Test for messages displayed when :return is resumed after :finally + func Xtest() + try + return 'vim' + finally + endtry + endfunc + redir => msg + call Xtest() + redir END + let expected = [ + \ 'calling Xtest()', '', + \ ':return vim made pending', '', + \ ':return vim resumed', '', + \ 'Xtest returning ''vim''', '', + \ 'continuing in Test_try_catch_verbose'] + call assert_equal(expected, split(msg, "\n")) + delfunc Xtest + + " Test for messages displayed when :finish is resumed after :finally + call writefile(['try', 'finish', 'finally', 'endtry'], 'Xscript') + redir => msg + source Xscript + redir END + let expected = [ + \ ':finish made pending', '', + \ ':finish resumed', '', + \ 'finished sourcing Xscript', + \ 'continuing in Test_try_catch_verbose'] + call assert_equal(expected, split(msg, "\n")[1:]) + call delete('Xscript') + + " Test for messages displayed when a pending :continue is discarded by an + " exception in a finally handler + redir => msg + try + for i in range(1) + try + continue + finally + throw 'abc' + endtry + endfor + catch + endtry + redir END + let expected = [ + \ ':continue made pending', '', + \ 'Exception thrown: abc', '', + \ ':continue discarded', '', + \ 'Exception caught: abc', '', + \ 'Exception finished: abc'] + call assert_equal(expected, split(msg, "\n")) + set verbose& endfunc +" Test for throwing an exception from a BufEnter autocmd {{{1 +func Test_BufEnter_exception() + augroup bufenter_exception + au! + autocmd BufEnter Xfile1 throw 'abc' + augroup END + + let caught_abc = 0 + try + sp Xfile1 + catch /^abc/ + let caught_abc = 1 + endtry + call assert_equal(1, caught_abc) + call assert_equal(1, winnr('$')) + + augroup bufenter_exception + au! + augroup END + augroup! bufenter_exception + %bwipe! + + " Test for recursively throwing exceptions in autocmds + augroup bufenter_exception + au! + autocmd BufEnter Xfile1 throw 'bufenter' + autocmd BufLeave Xfile1 throw 'bufleave' + augroup END + + let ex_count = 0 + try + try + sp Xfile1 + catch /^bufenter/ + let ex_count += 1 + endtry + catch /^bufleave/ + let ex_count += 10 + endtry + call assert_equal(10, ex_count) + call assert_equal(2, winnr('$')) + + augroup bufenter_exception + au! + augroup END + augroup! bufenter_exception + %bwipe! +endfunc + " Test for using throw in a called function with following error {{{1 func Test_user_command_throw_in_function_call() let lines =<< trim END -- cgit From f4274d0f62625683486d3912dcd6e8e45877c6a4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 31 Aug 2022 09:41:00 +0800 Subject: vim-patch:8.2.3102: test for crash fix does not fail without the fix (#20018) Problem: Test for crash fix does not fail without the fix. Solution: Adjust the test sequence. (closes vim/vim#8506) https://github.com/vim/vim/commit/3777d6e32b22f0a70b774760c24160079e303bad Cherry-pick CheckUnix from patch 8.2.1432. --- src/nvim/testdir/test_swap.vim | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 5c9e39f1f4..34d1d585ce 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -375,24 +375,26 @@ func Test_swap_prompt_splitwin() call WaitForAssert({-> assert_match('^1$', term_getline(buf, 20))}) call StopVimInTerminal(buf) - " This caused Vim to crash when typing "q". - " TODO: it does not actually reproduce the crash. - call writefile(['au BufAdd * set virtualedit=all'], 'Xvimrc') - - let buf = RunVimInTerminal('-u Xvimrc Xfile1', {'rows': 20, 'wait_for_ruler': 0}) - call TermWait(buf) - call WaitForAssert({-> assert_match('^\[O\]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:', term_getline(buf, 20))}) + " This caused Vim to crash when typing "q" at the swap file prompt. + let buf = RunVimInTerminal('-c "au bufadd * let foo_w = wincol()"', {'rows': 18}) + call term_sendkeys(buf, ":e Xfile1\") + call WaitForAssert({-> assert_match('More', term_getline(buf, 18))}) + call term_sendkeys(buf, " ") + call WaitForAssert({-> assert_match('^\[O\]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:', term_getline(buf, 18))}) call term_sendkeys(buf, "q") + call TermWait(buf) + " check that Vim is still running + call term_sendkeys(buf, ":echo 'hello'\") + call WaitForAssert({-> assert_match('^hello', term_getline(buf, 18))}) + call term_sendkeys(buf, ":%bwipe!\") + call StopVimInTerminal(buf) %bwipe! call delete('Xfile1') - call delete('Xvimrc') endfunc func Test_swap_symlink() - if !has("unix") - return - endif + CheckUnix call writefile(['text'], 'Xtestfile') silent !ln -s -f Xtestfile Xtestlink -- cgit From fa747d004a1e91b30066020f2f592e4dc5d94084 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 31 Aug 2022 19:47:10 +0800 Subject: fix(api): nvim_set_hl bail out on invalid group name (#20021) --- src/nvim/api/vim.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index b164106cef..a1721d433f 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -86,8 +86,7 @@ Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Error *err) int id = syn_name2id(name.data); if (id == 0) { - api_set_error(err, kErrorTypeException, "Invalid highlight name: %s", - name.data); + api_set_error(err, kErrorTypeException, "Invalid highlight name: %s", name.data); return result; } result = nvim_get_hl_by_id(id, rgb, err); @@ -105,8 +104,7 @@ Dictionary nvim_get_hl_by_id(Integer hl_id, Boolean rgb, Error *err) { Dictionary dic = ARRAY_DICT_INIT; if (syn_get_final_id((int)hl_id) == 0) { - api_set_error(err, kErrorTypeException, - "Invalid highlight id: %" PRId64, hl_id); + api_set_error(err, kErrorTypeException, "Invalid highlight id: %" PRId64, hl_id); return dic; } int attrcode = syn_id2attr((int)hl_id); @@ -175,6 +173,10 @@ void nvim_set_hl(Integer ns_id, String name, Dict(highlight) *val, Error *err) FUNC_API_SINCE(7) { int hl_id = syn_check_group(name.data, name.size); + if (hl_id == 0) { + api_set_error(err, kErrorTypeException, "Invalid highlight name: %s", name.data); + return; + } int link_id = -1; HlAttrs attrs = dict2hlattrs(val, true, &link_id, err); -- cgit From fb1edb2f5728d74ae811c6ab32395598cea5609b Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/buffer.c | 2 +- src/nvim/change.c | 20 ++--- src/nvim/charset.c | 4 +- src/nvim/cmdexpand.c | 6 +- src/nvim/cursor.c | 2 +- src/nvim/diff.c | 8 +- src/nvim/drawline.c | 6 +- src/nvim/edit.c | 16 ++-- src/nvim/eval.c | 4 +- src/nvim/eval/funcs.c | 12 +-- src/nvim/eval/userfunc.c | 14 ++-- src/nvim/eval/vars.c | 3 +- src/nvim/event/socket.c | 2 +- src/nvim/ex_cmds.c | 36 ++++----- src/nvim/ex_cmds2.c | 6 +- src/nvim/ex_docmd.c | 17 ++-- src/nvim/ex_getln.c | 12 +-- src/nvim/file_search.c | 4 +- src/nvim/fileio.c | 26 +++--- src/nvim/fold.c | 12 +-- src/nvim/getchar.c | 4 +- src/nvim/hardcopy.c | 4 +- src/nvim/if_cscope.c | 8 +- src/nvim/indent.c | 14 ++-- src/nvim/indent_c.c | 66 +++++++-------- src/nvim/insexpand.c | 16 ++-- src/nvim/macros.h | 2 +- src/nvim/main.c | 4 +- src/nvim/mapping.c | 4 +- src/nvim/mark.c | 4 +- src/nvim/mbyte.c | 15 ++-- src/nvim/memline.c | 68 ++++++++-------- src/nvim/menu.c | 2 +- src/nvim/message.c | 204 +++++++++++++++++++++++------------------------ src/nvim/mouse.c | 6 +- src/nvim/normal.c | 10 +-- src/nvim/ops.c | 203 +++++++++++++++++++++++----------------------- src/nvim/os/fs.c | 4 +- src/nvim/os/shell.c | 8 +- src/nvim/path.c | 13 +-- src/nvim/plines.c | 14 ++-- src/nvim/quickfix.c | 12 +-- src/nvim/regexp.c | 2 +- src/nvim/regexp_bt.c | 4 +- src/nvim/regexp_nfa.c | 2 +- src/nvim/runtime.c | 2 +- src/nvim/search.c | 42 +++++----- src/nvim/spell.c | 4 +- src/nvim/spellfile.c | 12 +-- src/nvim/syntax.c | 4 +- src/nvim/tag.c | 18 ++--- src/nvim/textformat.c | 10 +-- src/nvim/textobject.c | 8 +- src/nvim/tui/terminfo.c | 4 +- src/nvim/undo.c | 6 +- src/nvim/usercmd.c | 2 +- src/nvim/window.c | 2 +- 57 files changed, 511 insertions(+), 508 deletions(-) (limited to 'src') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 514be4c56b..8f23102e2e 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3701,7 +3701,7 @@ static int chk_modeline(linenr_T lnum, int flags) int retval = OK; prev = -1; - for (s = (char *)ml_get(lnum); *s != NUL; s++) { + for (s = ml_get(lnum); *s != NUL; s++) { if (prev == -1 || ascii_isspace(prev)) { if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0) || STRNCMP(s, "vi:", (size_t)3) == 0) { diff --git a/src/nvim/change.c b/src/nvim/change.c index 85ab92e49b..5bea388f28 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -631,7 +631,7 @@ void ins_char_bytes(char *buf, size_t charlen) size_t col = (size_t)curwin->w_cursor.col; linenr_T lnum = curwin->w_cursor.lnum; - char *oldp = (char *)ml_get(lnum); + char *oldp = ml_get(lnum); size_t linelen = STRLEN(oldp) + 1; // length of old line including NUL // The lengths default to the values for when not replacing. @@ -739,7 +739,7 @@ void ins_str(char *s) } colnr_T col = curwin->w_cursor.col; - char *oldp = (char *)ml_get(lnum); + char *oldp = ml_get(lnum); int oldlen = (int)STRLEN(oldp); char *newp = xmalloc((size_t)oldlen + (size_t)newlen + 1); @@ -797,7 +797,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) linenr_T lnum = curwin->w_cursor.lnum; colnr_T col = curwin->w_cursor.col; bool fixpos = fixpos_arg; - char *oldp = (char *)ml_get(lnum); + char *oldp = ml_get(lnum); colnr_T oldlen = (colnr_T)STRLEN(oldp); // Can't do anything when the cursor is on the NUL after the line. @@ -843,7 +843,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) && (get_ve_flags() & VE_ONEMORE) == 0) { curwin->w_cursor.col--; curwin->w_cursor.coladd = 0; - curwin->w_cursor.col -= utf_head_off((char_u *)oldp, (char_u *)oldp + curwin->w_cursor.col); + curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col); } count = oldlen - col; movelen = 1; @@ -854,7 +854,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) bool was_alloced = ml_line_alloced(); // check if oldp was allocated char *newp; if (was_alloced) { - ml_add_deleted_len(curbuf->b_ml.ml_line_ptr, oldlen); + ml_add_deleted_len((char *)curbuf->b_ml.ml_line_ptr, oldlen); newp = oldp; // use same allocated memory } else { // need to allocate a new line newp = xmalloc((size_t)(oldlen + 1 - count)); @@ -1047,7 +1047,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // the line, replacing what was there before and pushing the right // stuff onto the replace stack. -- webb. if (curwin->w_cursor.lnum < orig_line_count) { - next_line = (char *)vim_strsave(ml_get(curwin->w_cursor.lnum + 1)); + next_line = xstrdup(ml_get(curwin->w_cursor.lnum + 1)); } else { next_line = xstrdup(""); } @@ -1119,7 +1119,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // Skip preprocessor directives, unless they are recognised as comments. if (lead_len == 0 && ptr[0] == '#') { while (ptr[0] == '#' && curwin->w_cursor.lnum > 1) { - ptr = (char *)ml_get(--curwin->w_cursor.lnum); + ptr = ml_get(--curwin->w_cursor.lnum); } newindent = get_indent(); } @@ -1210,7 +1210,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } else { was_backslashed = false; } - ptr = (char *)ml_get(++curwin->w_cursor.lnum); + ptr = ml_get(++curwin->w_cursor.lnum); } if (was_backslashed) { newindent = 0; // Got to end of file @@ -1465,7 +1465,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // blank-out any other chars from the old leader. while (--p >= leader) { - int l = utf_head_off((char_u *)leader, (char_u *)p); + int l = utf_head_off(leader, p); if (l > 1) { p -= l; @@ -1872,7 +1872,7 @@ void truncate_line(int fixpos) if (col == 0) { newp = xstrdup(""); } else { - newp = (char *)vim_strnsave(ml_get(lnum), (size_t)col); + newp = xstrnsave(ml_get(lnum), (size_t)col); } ml_replace(lnum, newp, false); diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 4efd8a4ad1..4604bf7716 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -927,11 +927,11 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en } } posptr = ptr + pos->col; - posptr -= utf_head_off(line, posptr); + posptr -= utf_head_off((char *)line, (char *)posptr); } chartabsize_T cts; - init_chartabsize_arg(&cts, wp, pos->lnum, 0, line, line); + init_chartabsize_arg(&cts, wp, pos->lnum, 0, (char *)line, (char *)line); // This function is used very often, do some speed optimizations. // When 'list', 'linebreak', 'showbreak' and 'breakindent' are not set diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 5c54404aab..1c35f28301 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -675,7 +675,7 @@ int showmatches(expand_T *xp, int wildmenu) msg_advance(maxlen + 1); msg_puts((const char *)p); msg_advance(maxlen + 3); - msg_outtrans_long_attr(p + 2, HL_ATTR(HLF_D)); + msg_outtrans_long_attr((char *)p + 2, HL_ATTR(HLF_D)); break; } for (j = maxlen - lastlen; --j >= 0;) { @@ -2720,7 +2720,7 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp) int j = cclp->cmdpos; int i = (int)((char_u *)xp->xp_pattern - cclp->cmdbuff); while (--j > i) { - j -= utf_head_off(cclp->cmdbuff, cclp->cmdbuff + j); + j -= utf_head_off((char *)cclp->cmdbuff, (char *)cclp->cmdbuff + j); if (vim_ispathsep(cclp->cmdbuff[j])) { found = true; break; @@ -2741,7 +2741,7 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp) int j = cclp->cmdpos - 1; int i = (int)((char_u *)xp->xp_pattern - cclp->cmdbuff); while (--j > i) { - j -= utf_head_off(cclp->cmdbuff, cclp->cmdbuff + j); + j -= utf_head_off((char *)cclp->cmdbuff, (char *)cclp->cmdbuff + j); if (vim_ispathsep(cclp->cmdbuff[j]) #ifdef BACKSLASH_IN_FILENAME && vim_strchr((const char_u *)" *?[{`$%#", cclp->cmdbuff[j + 1]) diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index ed0488cf76..54e5ffff37 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -138,7 +138,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a } chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, pos->lnum, 0, line, line); + init_chartabsize_arg(&cts, curwin, pos->lnum, 0, (char *)line, (char *)line); while (cts.cts_vcol <= wcol && *cts.cts_ptr != NUL) { // Count a tab for what it's worth (if list mode not on) csize = win_lbr_chartabsize(&cts, &head); diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 1cfb535fe8..a3046bb7d7 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -2348,8 +2348,8 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) // Move back to first byte of character in both lines (may // have "nn^" in line_org and "n^ in line_new). - si_org -= utf_head_off((char_u *)line_org, (char_u *)line_org + si_org); - si_new -= utf_head_off((char_u *)line_new, (char_u *)line_new + si_new); + si_org -= utf_head_off(line_org, line_org + si_org); + si_new -= utf_head_off(line_new, line_new + si_new); if (*startp > si_org) { *startp = si_org; @@ -2381,8 +2381,8 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) const char_u *p1 = (char_u *)line_org + ei_org; const char_u *p2 = (char_u *)line_new + ei_new; - p1 -= utf_head_off((char_u *)line_org, p1); - p2 -= utf_head_off((char_u *)line_new, p2); + p1 -= utf_head_off(line_org, (char *)p1); + p2 -= utf_head_off(line_new, (char *)p2); if (!diff_equal_char(p1, p2, &l)) { break; diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index b6c4400c60..66d8a1fb32 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -943,7 +943,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, chartabsize_T cts; int charsize; - init_chartabsize_arg(&cts, wp, lnum, (colnr_T)vcol, line, ptr); + init_chartabsize_arg(&cts, wp, lnum, (colnr_T)vcol, (char *)line, (char *)ptr); while (cts.cts_vcol < v && *cts.cts_ptr != NUL) { charsize = win_lbr_chartabsize(&cts, NULL); cts.cts_vcol += charsize; @@ -1803,11 +1803,11 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, // Found last space before word: check for line break. if (wp->w_p_lbr && c0 == c && vim_isbreak(c) && !vim_isbreak((int)(*ptr))) { - int mb_off = utf_head_off(line, ptr - 1); + int mb_off = utf_head_off((char *)line, (char *)ptr - 1); char_u *p = ptr - (mb_off + 1); chartabsize_T cts; - init_chartabsize_arg(&cts, wp, lnum, (colnr_T)vcol, line, p); + init_chartabsize_arg(&cts, wp, lnum, (colnr_T)vcol, (char *)line, (char *)p); n_extra = win_lbr_chartabsize(&cts, NULL) - 1; // We have just drawn the showbreak value, no need to add diff --git a/src/nvim/edit.c b/src/nvim/edit.c index aee8389900..642162284c 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1545,7 +1545,7 @@ void display_dollar(colnr_T col) // If on the last byte of a multi-byte move to the first byte. char_u *p = get_cursor_line_ptr(); - curwin->w_cursor.col -= utf_head_off(p, p + col); + curwin->w_cursor.col -= utf_head_off((char *)p, (char *)p + col); curs_columns(curwin, false); // Recompute w_wrow and w_wcol if (curwin->w_wcol < curwin->w_grid.cols) { edit_putchar('$', false); @@ -1672,7 +1672,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang last_vcol = 0; ptr = get_cursor_line_ptr(); chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, 0, 0, ptr, ptr); + init_chartabsize_arg(&cts, curwin, 0, 0, (char *)ptr, (char *)ptr); while (cts.cts_vcol <= (int)curwin->w_virtcol) { last_vcol = cts.cts_vcol; if (cts.cts_vcol > 0) { @@ -4642,7 +4642,7 @@ static bool ins_tab(void) char_u *tab = (char_u *)"\t"; chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, 0, vcol, tab, tab); + init_chartabsize_arg(&cts, curwin, 0, vcol, (char *)tab, (char *)tab); // Use as many TABs as possible. Beware of 'breakindent', 'showbreak' // and 'linebreak' adding extra virtual columns. @@ -4671,7 +4671,7 @@ static bool ins_tab(void) if (change_col >= 0) { int repl_off = 0; // Skip over the spaces we need. - init_chartabsize_arg(&cts, curwin, 0, vcol, ptr, ptr); + init_chartabsize_arg(&cts, curwin, 0, vcol, (char *)ptr, (char *)ptr); while (cts.cts_vcol < want_vcol && *cts.cts_ptr == ' ') { cts.cts_vcol += lbr_chartabsize(&cts); cts.cts_ptr++; @@ -4869,12 +4869,12 @@ int ins_copychar(linenr_T lnum) } // try to advance to the cursor column - line = ml_get(lnum); + line = (char_u *)ml_get(lnum); prev_ptr = line; validate_virtcol(); chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, lnum, 0, line, line); + init_chartabsize_arg(&cts, curwin, lnum, 0, (char *)line, (char *)line); while (cts.cts_vcol < curwin->w_virtcol && *cts.cts_ptr != NUL) { prev_ptr = (char_u *)cts.cts_ptr; cts.cts_vcol += lbr_chartabsize_adv(&cts); @@ -4958,7 +4958,7 @@ static void ins_try_si(int c) * case where an "if (..\n..) {" statement continues over multiple * lines -- webb */ - ptr = ml_get(pos->lnum); + ptr = (char_u *)ml_get(pos->lnum); i = pos->col; if (i > 0) { // skip blanks before '{' while (--i > 0 && ascii_iswhite(ptr[i])) {} @@ -4983,7 +4983,7 @@ static void ins_try_si(int c) old_pos = curwin->w_cursor; i = get_indent(); while (curwin->w_cursor.lnum > 1) { - ptr = (char_u *)skipwhite((char *)ml_get(--(curwin->w_cursor.lnum))); + ptr = (char_u *)skipwhite(ml_get(--(curwin->w_cursor.lnum))); // ignore empty lines and lines starting with '#'. if (*ptr != '#' && *ptr != NUL) { diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 2dbaa2f8ac..2ade64df3f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6369,7 +6369,7 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret } int len; if (charcol) { - len = mb_charlen(ml_get(pos.lnum)); + len = mb_charlen((char_u *)ml_get(pos.lnum)); } else { len = (int)STRLEN(ml_get(pos.lnum)); } @@ -8630,7 +8630,7 @@ void invoke_prompt_callback(void) if (curbuf->b_prompt_callback.type == kCallbackNone) { return; } - char *text = (char *)ml_get(lnum); + char *text = ml_get(lnum); char *prompt = (char *)prompt_text(); if (STRLEN(text) >= STRLEN(prompt)) { text += STRLEN(prompt); diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index aa328d50ef..6593a34f4a 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -1034,7 +1034,7 @@ static void f_confirm(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } if (!error) { - rettv->vval.v_number = do_dialog(type, NULL, (char_u *)message, (char_u *)buttons, def, NULL, + rettv->vval.v_number = do_dialog(type, NULL, (char *)message, (char *)buttons, def, NULL, false); } } @@ -3849,7 +3849,7 @@ static void f_hostname(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) os_get_hostname(hostname, 256); rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char *)vim_strsave((char_u *)hostname); + rettv->vval.v_string = xstrdup(hostname); } /// iconv() function @@ -5385,7 +5385,7 @@ static void f_nextnonblank(typval_T *argvars, typval_T *rettv, EvalFuncData fptr lnum = 0; break; } - if (*skipwhite((char *)ml_get(lnum)) != NUL) { + if (*skipwhite(ml_get(lnum)) != NUL) { break; } } @@ -5473,7 +5473,7 @@ static void f_prevnonblank(typval_T *argvars, typval_T *rettv, EvalFuncData fptr if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) { lnum = 0; } else { - while (lnum >= 1 && *skipwhite((char *)ml_get(lnum)) == NUL) { + while (lnum >= 1 && *skipwhite(ml_get(lnum)) == NUL) { lnum--; } } @@ -7810,7 +7810,7 @@ free_lstval: if (strval == NULL) { return; } - write_reg_contents_ex(regname, (const char_u *)strval, (ssize_t)STRLEN(strval), + write_reg_contents_ex(regname, strval, (ssize_t)STRLEN(strval), append, yank_type, (colnr_T)block_len); } if (pointreg != 0) { @@ -9639,7 +9639,7 @@ static void f_win_gettype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (argvars[0].v_type != VAR_UNKNOWN) { wp = find_win_by_nr_or_id(&argvars[0]); if (wp == NULL) { - rettv->vval.v_string = (char *)vim_strsave((char_u *)"unknown"); + rettv->vval.v_string = xstrdup("unknown"); return; } } diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 4be922a055..21bd662db5 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -378,7 +378,7 @@ char_u *deref_func_name(const char *name, int *lenp, partial_T **const partialp, *lenp = 0; return (char_u *)""; } - *lenp = (int)STRLEN(v->di_tv.vval.v_string); + *lenp = (int)strlen(v->di_tv.vval.v_string); return (char_u *)v->di_tv.vval.v_string; } @@ -970,11 +970,11 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett snprintf((char *)numbuf, sizeof(numbuf), "%d", ai + 1); name = (char *)numbuf; } - if (fixvar_idx < FIXVAR_CNT && STRLEN(name) <= VAR_SHORT_LEN) { + if (fixvar_idx < FIXVAR_CNT && strlen(name) <= VAR_SHORT_LEN) { v = (dictitem_T *)&fc->fixvar[fixvar_idx++]; v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; } else { - v = xmalloc(sizeof(dictitem_T) + STRLEN(name)); + v = xmalloc(sizeof(dictitem_T) + strlen(name)); v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX | DI_FLAGS_ALLOC; } STRCPY(v->di_key, name); @@ -1455,7 +1455,7 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t rettv->v_type = VAR_UNKNOWN; if (len <= 0) { - len = (int)STRLEN(funcname); + len = (int)strlen(funcname); } if (partial != NULL) { fp = partial->pt_func; @@ -2054,7 +2054,7 @@ void ex_function(exarg_T *eap) msg_putchar(' '); } } - msg_prt_line((char_u *)FUNCLINE(fp, j), false); + msg_prt_line(FUNCLINE(fp, j), false); ui_flush(); // show a line at a time os_breakcheck(); } @@ -2270,8 +2270,8 @@ void ex_function(exarg_T *eap) } else if (line_arg != NULL && *skipwhite((char *)line_arg) != NUL) { nextcmd = line_arg; } else if (*p != NUL && *p != '"' && p_verbose > 0) { - give_warning2((char_u *)_("W22: Text found after :endfunction: %s"), - p, true); + give_warning2(_("W22: Text found after :endfunction: %s"), + (char *)p, true); } if (nextcmd != NULL) { // Another command follows. If the line came from "eap" we diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index 75410d40d8..dbbb03b1b8 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -710,8 +710,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo } } if (p != NULL) { - write_reg_contents(*arg == '@' ? '"' : *arg, - (const char_u *)p, (ssize_t)STRLEN(p), false); + write_reg_contents(*arg == '@' ? '"' : *arg, p, (ssize_t)STRLEN(p), false); arg_end = arg + 1; } xfree(ptofree); diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c index 9496a568b9..9ca3dcc276 100644 --- a/src/nvim/event/socket.c +++ b/src/nvim/event/socket.c @@ -125,7 +125,7 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb) // Libuv converts ENOENT to EACCES for Windows compatibility, but if // the parent directory does not exist, ENOENT would be more accurate. *path_tail(watcher->addr) = NUL; - if (!os_path_exists((char_u *)watcher->addr)) { + if (!os_path_exists(watcher->addr)) { result = UV_ENOENT; } } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index e672b80d69..17d45f207e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -557,7 +557,7 @@ void ex_sort(exarg_T *eap) // matching and number conversion only has to be done once per line. // Also get the longest line length for allocating "sortbuf". for (lnum = eap->line1; lnum <= eap->line2; lnum++) { - s = (char *)ml_get(lnum); + s = ml_get(lnum); len = (int)STRLEN(s); if (maxlen < len) { maxlen = len; @@ -658,7 +658,7 @@ void ex_sort(exarg_T *eap) change_occurred = true; } - s = (char *)ml_get(get_lnum); + s = ml_get(get_lnum); size_t bytelen = STRLEN(s) + 1; // include EOL in bytelen old_count += (bcount_t)bytelen; if (!unique || i == 0 || string_compare(s, sortbuf1) != 0) { @@ -760,7 +760,7 @@ void ex_retab(exarg_T *eap) new_ts_str = xstrnsave(new_ts_str, (size_t)(eap->arg - new_ts_str)); } for (lnum = eap->line1; !got_int && lnum <= eap->line2; lnum++) { - ptr = (char *)ml_get(lnum); + ptr = ml_get(lnum); col = 0; vcol = 0; did_undo = false; @@ -941,7 +941,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) return FAIL; } for (extra = 0, l = line1; l <= line2; l++) { - str = (char *)vim_strsave(ml_get(l + extra)); + str = xstrdup(ml_get(l + extra)); ml_append(dest + l - line1, str, (colnr_T)0, false); xfree(str); if (dest < line1) { @@ -1088,7 +1088,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) while (line1 <= line2) { // need to use vim_strsave() because the line will be unlocked within // ml_append() - p = (char *)vim_strsave(ml_get(line1)); + p = xstrdup(ml_get(line1)); ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, false); xfree(p); @@ -1710,7 +1710,7 @@ void print_line(linenr_T lnum, int use_number, int list) int save_silent = silent_mode; // apply :filter /pat/ - if (message_filtered((char *)ml_get(lnum))) { + if (message_filtered(ml_get(lnum))) { return; } @@ -1897,7 +1897,7 @@ int do_write(exarg_T *eap) && !p_wa) { if (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) { if (vim_dialog_yesno(VIM_QUESTION, NULL, - (char_u *)_("Write partial file?"), 2) != VIM_YES) { + _("Write partial file?"), 2) != VIM_YES) { goto theend; } eap->forceit = true; @@ -2007,7 +2007,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int oth && vim_strchr(p_cpo, CPO_OVERNEW) == NULL) || (buf->b_flags & BF_READERR)))) && !p_wa - && os_path_exists((char_u *)ffname)) { + && os_path_exists(ffname)) { if (!eap->forceit && !eap->append) { #ifdef UNIX // It is possible to open a directory on Unix. @@ -2020,7 +2020,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int oth char buff[DIALOG_MSG_SIZE]; dialog_msg((char *)buff, _("Overwrite existing file \"%s\"?"), fname); - if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)buff, 2) != VIM_YES) { + if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) != VIM_YES) { return FAIL; } eap->forceit = true; @@ -2051,14 +2051,14 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int oth } swapname = (char *)makeswapname((char_u *)fname, (char_u *)ffname, curbuf, (char_u *)dir); xfree(dir); - if (os_path_exists((char_u *)swapname)) { + if (os_path_exists(swapname)) { if (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) { char buff[DIALOG_MSG_SIZE]; dialog_msg((char *)buff, _("Swap file \"%s\" exists, overwrite anyway?"), swapname); - if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)buff, 2) + if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) != VIM_YES) { xfree(swapname); return FAIL; @@ -2171,7 +2171,7 @@ static int check_readonly(int *forceit, buf_T *buf) // Handle a file being readonly when the 'readonly' option is set or when // the file exists and permissions are read-only. if (!*forceit && (buf->b_p_ro - || (os_path_exists((char_u *)buf->b_ffname) + || (os_path_exists(buf->b_ffname) && !os_file_is_writable(buf->b_ffname)))) { if ((p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) && buf->b_fname != NULL) { char buff[DIALOG_MSG_SIZE]; @@ -2187,7 +2187,7 @@ static int check_readonly(int *forceit, buf_T *buf) buf->b_fname); } - if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)buff, 2) == VIM_YES) { + if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES) { // Set forceit, to force the writing of a readonly file *forceit = true; return false; @@ -2678,7 +2678,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum } buf = curbuf; if (buf->b_fname != NULL) { - new_name = (char *)vim_strsave((char_u *)buf->b_fname); + new_name = xstrdup(buf->b_fname); } else { new_name = NULL; } @@ -3803,7 +3803,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T break; } if (sub_firstline == NULL) { - sub_firstline = (char *)vim_strsave(ml_get(sub_firstlnum)); + sub_firstline = xstrdup(ml_get(sub_firstlnum)); } // Save the line number of the last change for the final @@ -3944,7 +3944,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // really update the line, it would change // what matches. Temporarily replace the line // and change it back afterwards. - orig_line = (char *)vim_strsave(ml_get(lnum)); + orig_line = xstrdup(ml_get(lnum)); char *new_line = concat_str(new_start, sub_firstline + copycol); // Position the cursor relative to the end of the line, the @@ -4072,7 +4072,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T if (nmatch > 1) { \ sub_firstlnum += (linenr_T)nmatch - 1; \ xfree(sub_firstline); \ - sub_firstline = (char *)vim_strsave(ml_get(sub_firstlnum)); \ + sub_firstline = xstrdup(ml_get(sub_firstlnum)); \ /* When going beyond the last line, stop substituting. */ \ if (sub_firstlnum <= line2) { \ do_again = true; \ @@ -4148,7 +4148,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T if (nmatch == 1) { p1 = sub_firstline; } else { - p1 = (char *)ml_get(sub_firstlnum + (linenr_T)nmatch - 1); + p1 = ml_get(sub_firstlnum + (linenr_T)nmatch - 1); nmatch_tl += nmatch - 1; } size_t copy_len = (size_t)(regmatch.startpos[0].col - copycol); diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 11280eecbb..e551cbee0b 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -200,9 +200,9 @@ void dialog_changed(buf_T *buf, bool checkall) dialog_msg((char *)buff, _("Save changes to \"%s\"?"), buf->b_fname); if (checkall) { - ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, (char_u *)buff, 1); + ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1); } else { - ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, (char_u *)buff, 1); + ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1); } if (ret == VIM_YES) { @@ -252,7 +252,7 @@ bool dialog_close_terminal(buf_T *buf) dialog_msg(buff, _("Close \"%s\"?"), (buf->b_fname != NULL) ? buf->b_fname : "?"); - int ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, (char_u *)buff, 1); + int ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1); return ret == VIM_YES; } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index bf518f3849..8f72ba0e23 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -535,7 +535,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) if (flags & DOCMD_KEEPLINE) { xfree(repeat_cmdline); if (count == 0) { - repeat_cmdline = (char *)vim_strsave((char_u *)next_cmdline); + repeat_cmdline = xstrdup(next_cmdline); } else { repeat_cmdline = NULL; } @@ -2826,7 +2826,7 @@ static void append_command(char *cmd) if (len > IOSIZE - 100) { // Not enough space, truncate and put in "...". d = (char *)IObuff + IOSIZE - 100; - d -= utf_head_off(IObuff, (const char_u *)d); + d -= utf_head_off((char *)IObuff, d); STRCPY(d, "..."); } STRCAT(IObuff, ": "); @@ -3081,10 +3081,9 @@ void f_fullcommand(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) return; } - rettv->vval.v_string = (char *)vim_strsave(IS_USER_CMDIDX(ea.cmdidx) - ? (char_u *)get_user_command_name(ea.useridx, - ea.cmdidx) - : (char_u *)cmdnames[ea.cmdidx].cmd_name); + rettv->vval.v_string = xstrdup(IS_USER_CMDIDX(ea.cmdidx) + ? get_user_command_name(ea.useridx, ea.cmdidx) + : cmdnames[ea.cmdidx].cmd_name); } cmdidx_T excmd_get_cmdidx(const char *cmd, size_t len) @@ -4344,7 +4343,7 @@ static int check_more(int message, bool forceit) vim_snprintf((char *)buff, DIALOG_MSG_SIZE, NGETTEXT("%d more file to edit. Quit anyway?", "%d more files to edit. Quit anyway?", (unsigned long)n), n); - if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)buff, 1) == VIM_YES) { + if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 1) == VIM_YES) { return OK; } return FAIL; @@ -6007,7 +6006,7 @@ static void ex_redir(exarg_T *eap) // Make register empty when not using @A-@Z and the // command is valid. if (*arg == NUL && !isupper(redir_reg)) { - write_reg_contents(redir_reg, (char_u *)"", 0, false); + write_reg_contents(redir_reg, "", 0, false); } } } @@ -6162,7 +6161,7 @@ FILE *open_exfile(char_u *fname, int forceit, char *mode) return NULL; } #endif - if (!forceit && *mode != 'a' && os_path_exists(fname)) { + if (!forceit && *mode != 'a' && os_path_exists((char *)fname)) { semsg(_("E189: \"%s\" exists (add ! to override)"), fname); return NULL; } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 0998bdd867..e8af99805d 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1704,8 +1704,8 @@ static int command_line_handle_key(CommandLineState *s) do { ccline.cmdpos--; // Move to first byte of possibly multibyte char. - ccline.cmdpos -= utf_head_off(ccline.cmdbuff, - ccline.cmdbuff + ccline.cmdpos); + ccline.cmdpos -= utf_head_off((char *)ccline.cmdbuff, + (char *)ccline.cmdbuff + ccline.cmdpos); ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); } while (ccline.cmdpos > 0 && (s->c == K_S_LEFT || s->c == K_C_LEFT @@ -3208,7 +3208,7 @@ draw_cmdline_no_arabicshape: continue; } const int chunk_start = MAX(chunk.start, start); - msg_outtrans_len_attr(ccline.cmdbuff + chunk_start, + msg_outtrans_len_attr((char *)ccline.cmdbuff + chunk_start, chunk.end - chunk_start, chunk.attr); } @@ -3442,14 +3442,14 @@ void put_on_cmdline(char_u *str, int len, int redraw) i = 0; c = utf_ptr2char((char *)ccline.cmdbuff + ccline.cmdpos); while (ccline.cmdpos > 0 && utf_iscomposing(c)) { - i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; + i = utf_head_off((char *)ccline.cmdbuff, (char *)ccline.cmdbuff + ccline.cmdpos - 1) + 1; ccline.cmdpos -= i; len += i; c = utf_ptr2char((char *)ccline.cmdbuff + ccline.cmdpos); } if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) { // Check the previous character for Arabic combining pair. - i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; + i = utf_head_off((char *)ccline.cmdbuff, (char *)ccline.cmdbuff + ccline.cmdpos - 1) + 1; if (arabic_combine(utf_ptr2char((char *)ccline.cmdbuff + ccline.cmdpos - i), c)) { ccline.cmdpos -= i; len += i; @@ -3581,7 +3581,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) // Locate start of last word in the cmd buffer. for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff;) { - len = utf_head_off(ccline.cmdbuff, w - 1) + 1; + len = utf_head_off((char *)ccline.cmdbuff, (char *)w - 1) + 1; if (!vim_iswordc(utf_ptr2char((char *)w - len))) { break; } diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index bbc6e53aa8..e87e0853f3 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -825,7 +825,7 @@ char_u *vim_findfile(void *search_ctx_arg) for (;;) { // if file exists and we didn't already find it if ((path_with_url((char *)file_path) - || (os_path_exists(file_path) + || (os_path_exists((char *)file_path) && (search_ctx->ffsc_find_what == FINDFILE_BOTH || ((search_ctx->ffsc_find_what == FINDFILE_DIR) == os_isdir((char *)file_path))))) @@ -1473,7 +1473,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first buf = (char *)suffixes; for (;;) { if ( - (os_path_exists((char_u *)NameBuff) + (os_path_exists(NameBuff) && (find_what == FINDFILE_BOTH || ((find_what == FINDFILE_DIR) == os_isdir(NameBuff))))) { diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index d67cd36a85..517424f4c1 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -143,7 +143,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr) msg_scroll = msg_scroll_save; msg_scrolled_ign = true; // may truncate the message to avoid a hit-return prompt - msg_outtrans_attr((char *)msg_may_trunc(false, IObuff), attr); + msg_outtrans_attr(msg_may_trunc(false, (char *)IObuff), attr); msg_clr_eos(); ui_flush(); msg_scrolled_ign = false; @@ -1011,7 +1011,7 @@ retry: tlen = 0; for (;;) { - p = ml_get(read_buf_lnum) + read_buf_col; + p = (char_u *)ml_get(read_buf_lnum) + read_buf_col; n = (int)STRLEN(p); if ((int)tlen + n + 1 > size) { // Filled up to "size", append partial line. @@ -1371,7 +1371,7 @@ retry: if (*--p < 0x80) { u8c = *p; } else { - len = utf_head_off((char_u *)ptr, p); + len = utf_head_off(ptr, (char *)p); p -= len; u8c = (unsigned)utf_ptr2char((char *)p); if (len == 0) { @@ -2970,13 +2970,13 @@ nobackup: * delete an existing one, try to use another name. * Change one character, just before the extension. */ - if (!p_bk && os_path_exists((char_u *)backup)) { + if (!p_bk && os_path_exists(backup)) { p = backup + STRLEN(backup) - 1 - STRLEN(backup_ext); if (p < backup) { // empty file name ??? p = backup; } *p = 'z'; - while (*p > 'a' && os_path_exists((char_u *)backup)) { + while (*p > 'a' && os_path_exists(backup)) { (*p)--; } // They all exist??? Must be something wrong! @@ -3211,11 +3211,11 @@ restore_backup: // This may not work if the vim_rename() fails. // In that case we leave the copy around. // If file does not exist, put the copy in its place - if (!os_path_exists((char_u *)fname)) { + if (!os_path_exists(fname)) { vim_rename((char_u *)backup, (char_u *)fname); } // if original file does exist throw away the copy - if (os_path_exists((char_u *)fname)) { + if (os_path_exists(fname)) { os_remove(backup); } } else { @@ -3225,7 +3225,7 @@ restore_backup: } // if original file no longer exists give an extra warning - if (!newfile && !os_path_exists((char_u *)fname)) { + if (!newfile && !os_path_exists(fname)) { end = 0; } } @@ -3588,7 +3588,7 @@ restore_backup: */ if (org == NULL) { emsg(_("E205: Patchmode: can't save original file")); - } else if (!os_path_exists((char_u *)org)) { + } else if (!os_path_exists(org)) { vim_rename((char_u *)backup, (char_u *)org); XFREE_CLEAR(backup); // don't delete the file #ifdef UNIX @@ -4677,7 +4677,7 @@ int vim_rename(const char_u *from, const char_u *to) char *tail = path_tail((char *)tempname); snprintf(tail, (size_t)((MAXPATHL + 1) - (tail - (char *)tempname - 1)), "%d", n); - if (!os_path_exists(tempname)) { + if (!os_path_exists((char *)tempname)) { if (os_rename(from, tempname) == OK) { if (os_rename(tempname, to) == OK) { return 0; @@ -5028,7 +5028,7 @@ int buf_check_timestamp(buf_T *buf) } } } else if ((buf->b_flags & BF_NEW) && !(buf->b_flags & BF_NEW_W) - && os_path_exists((char_u *)buf->b_ffname)) { + && os_path_exists(buf->b_ffname)) { retval = 1; mesg = _("W13: Warning: File \"%s\" has been created after editing started"); buf->b_flags |= BF_NEW_W; @@ -5051,8 +5051,8 @@ int buf_check_timestamp(buf_T *buf) xstrlcat(tbuf, "\n", tbuf_len - 1); xstrlcat(tbuf, mesg2, tbuf_len - 1); } - switch (do_dialog(VIM_WARNING, (char_u *)_("Warning"), (char_u *)tbuf, - (char_u *)_("&OK\n&Load File\nLoad File &and Options"), + switch (do_dialog(VIM_WARNING, _("Warning"), tbuf, + _("&OK\n&Load File\nLoad File &and Options"), 1, NULL, true)) { case 2: reload = RELOAD_NORMAL; diff --git a/src/nvim/fold.c b/src/nvim/fold.c index b4ddb3ec08..d8c864df5b 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -995,7 +995,7 @@ void foldAdjustVisual(void) start->col = 0; } if (hasFolding(end->lnum, NULL, &end->lnum)) { - ptr = ml_get(end->lnum); + ptr = (char_u *)ml_get(end->lnum); end->col = (colnr_T)STRLEN(ptr); if (end->col > 0 && *p_sel == 'o') { end->col--; @@ -1588,7 +1588,7 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char_u *marker, size_t ma if (u_save(lnum - 1, lnum + 1) == OK) { // Check if the line ends with an unclosed comment - skip_comment(line, false, false, &line_is_comment); + skip_comment((char *)line, false, false, &line_is_comment); newline = xmalloc(line_len + markerlen + STRLEN(cms) + 1); STRCPY(newline, line); // Append the marker to the end of the line @@ -1601,7 +1601,7 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char_u *marker, size_t ma STRCPY(newline + line_len + (p - cms) + markerlen, p + 2); added = markerlen + STRLEN(cms) - 2; } - ml_replace_buf(buf, lnum, newline, false); + ml_replace_buf(buf, lnum, (char *)newline, false); if (added) { extmark_splice_cols(buf, (int)lnum - 1, (int)line_len, 0, (int)added, kExtmarkUndo); @@ -1666,7 +1666,7 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char_u *marker, size_t mark assert(p >= line); memcpy(newline, line, (size_t)(p - line)); STRCPY(newline + (p - line), p + len); - ml_replace_buf(buf, lnum, newline, false); + ml_replace_buf(buf, lnum, (char *)newline, false); extmark_splice_cols(buf, (int)lnum - 1, (int)(p - line), (int)len, 0, kExtmarkUndo); } @@ -3251,12 +3251,12 @@ void f_foldtext(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } // Find interesting text in this line. - char_u *s = (char_u *)skipwhite((char *)ml_get(lnum)); + char_u *s = (char_u *)skipwhite(ml_get(lnum)); // skip C comment-start if (s[0] == '/' && (s[1] == '*' || s[1] == '/')) { s = (char_u *)skipwhite((char *)s + 2); if (*skipwhite((char *)s) == NUL && lnum + 1 < foldend) { - s = (char_u *)skipwhite((char *)ml_get(lnum + 1)); + s = (char_u *)skipwhite(ml_get(lnum + 1)); if (*s == '*') { s = (char_u *)skipwhite((char *)s + 1); } diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 0a9457ef35..4d7339f3b5 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2569,7 +2569,7 @@ static int vgetorpeek(bool advance) ptr = get_cursor_line_ptr(); chartabsize_T cts; init_chartabsize_arg(&cts, curwin, - curwin->w_cursor.lnum, 0, ptr, ptr); + curwin->w_cursor.lnum, 0, (char *)ptr, (char *)ptr); while ((char_u *)cts.cts_ptr < ptr + curwin->w_cursor.col) { if (!ascii_iswhite(*cts.cts_ptr)) { curwin->w_wcol = cts.cts_vcol; @@ -2597,7 +2597,7 @@ static int vgetorpeek(bool advance) // Correct when the cursor is on the right halve // of a double-wide character. ptr = get_cursor_line_ptr(); - col -= utf_head_off(ptr, ptr + col); + col -= utf_head_off((char *)ptr, (char *)ptr + col); if (utf_ptr2cells((char *)ptr + col) > 1) { curwin->w_wcol--; } diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 602fa8b71d..d7f5730943 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -879,7 +879,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T } mch_print_start_line(false, page_line); - line = ml_get(ppos->file_line); + line = (char_u *)ml_get(ppos->file_line); /* * Loop over the columns until the end of the file line or right margin. @@ -897,7 +897,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T id = 0; } // Get the line again, a multi-line regexp may invalidate it. - line = ml_get(ppos->file_line); + line = (char_u *)ml_get(ppos->file_line); if (id != current_syn_id) { current_syn_id = id; diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 9413abb2e1..e54bffb587 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -446,7 +446,7 @@ staterr: if (arg2 != NULL) { ppath = xmalloc(MAXPATHL + 1); expand_env(arg2, ppath, MAXPATHL); - if (!os_path_exists((char_u *)ppath)) { + if (!os_path_exists(ppath)) { goto staterr; } } @@ -1651,7 +1651,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, } (void)snprintf(buf, bufsize, csfmt_str, i + 1, lno); msg_puts_attr(buf, HL_ATTR(HLF_CM)); - msg_outtrans_long_attr((char_u *)cs_pathcomponents(fname), HL_ATTR(HLF_CM)); + msg_outtrans_long_attr(cs_pathcomponents(fname), HL_ATTR(HLF_CM)); // compute the required space for the context char *context = cntxts[i] ? cntxts[i] : globalcntx; @@ -1673,11 +1673,11 @@ static void cs_print_tags_priv(char **matches, char **cntxts, msg_putchar('\n'); } msg_advance(12); - msg_outtrans_long_attr((char_u *)buf, 0); + msg_outtrans_long_attr(buf, 0); msg_putchar('\n'); if (extra != NULL) { msg_advance(13); - msg_outtrans_long_attr((char_u *)extra, 0); + msg_outtrans_long_attr(extra, 0); } // restore matches[i] diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 792f4d93c4..da4bcf6934 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -352,7 +352,7 @@ int get_indent(void) // Count the size (in window cells) of the indent in line "lnum". int get_indent_lnum(linenr_T lnum) { - return get_indent_str_vtab((char *)ml_get(lnum), + return get_indent_str_vtab(ml_get(lnum), curbuf->b_p_ts, curbuf->b_p_vts_array, false); @@ -710,7 +710,7 @@ int get_number_indent(linenr_T lnum) // In format_lines() (i.e. not insert mode), fo+=q is needed too... if ((State & MODE_INSERT) || has_format_option(FO_Q_COMS)) { - lead_len = get_leader_len((char *)ml_get(lnum), NULL, false, true); + lead_len = get_leader_len(ml_get(lnum), NULL, false, true); } regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC); @@ -719,9 +719,9 @@ int get_number_indent(linenr_T lnum) // vim_regexec() expects a pointer to a line. This lets us // start matching for the flp beyond any comment leader... - if (vim_regexec(®match, (char *)ml_get(lnum) + lead_len, (colnr_T)0)) { + if (vim_regexec(®match, ml_get(lnum) + lead_len, (colnr_T)0)) { pos.lnum = lnum; - pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum)); + pos.col = (colnr_T)(*regmatch.endp - (char_u *)ml_get(lnum)); pos.coladd = 0; } vim_regfree(regmatch.regprog); @@ -1036,7 +1036,7 @@ int get_lisp_indent(void) } else { char_u *line = that; chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, pos->lnum, 0, line, line); + init_chartabsize_arg(&cts, curwin, pos->lnum, 0, (char *)line, (char *)line); while (*cts.cts_ptr != NUL && col > 0) { cts.cts_vcol += lbr_chartabsize_adv(&cts); col--; @@ -1060,7 +1060,7 @@ int get_lisp_indent(void) firsttry = amount; init_chartabsize_arg(&cts, curwin, (colnr_T)(that - line), - amount, line, that); + amount, (char *)line, (char *)that); while (ascii_iswhite(*cts.cts_ptr)) { cts.cts_vcol += lbr_chartabsize(&cts); cts.cts_ptr++; @@ -1081,7 +1081,7 @@ int get_lisp_indent(void) quotecount = 0; init_chartabsize_arg(&cts, curwin, - (colnr_T)(that - line), amount, line, that); + (colnr_T)(that - line), amount, (char *)line, (char *)that); if (vi_lisp || ((*that != '"') && (*that != '\'') && (*that != '#') && ((*that < '0') || (*that > '9')))) { while (*cts.cts_ptr diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 166695ef5b..ccee4dd48a 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -52,7 +52,7 @@ pos_T *find_start_comment(int ind_maxcomment) // XXX * Check if the comment start we found is inside a string. * If it is then restrict the search to below this line and try again. */ - if (!is_pos_in_string(ml_get(pos->lnum), pos->col)) { + if (!is_pos_in_string((char_u *)ml_get(pos->lnum), pos->col)) { break; } cur_maxcomment = curwin->w_cursor.lnum - pos->lnum - 1; @@ -115,7 +115,7 @@ static pos_T *find_start_rawstring(int ind_maxcomment) // XXX // Check if the raw string start we found is inside a string. // If it is then restrict the search to below this line and try again. - if (!is_pos_in_string(ml_get(pos->lnum), pos->col)) { + if (!is_pos_in_string((char_u *)ml_get(pos->lnum), pos->col)) { break; } cur_maxcomment = curwin->w_cursor.lnum - pos->lnum - 1; @@ -291,7 +291,7 @@ static pos_T *find_line_comment(void) // XXX pos = curwin->w_cursor; while (--pos.lnum > 0) { - line = ml_get(pos.lnum); + line = (char_u *)ml_get(pos.lnum); p = (char_u *)skipwhite((char *)line); if (cin_islinecomment(p)) { pos.col = (int)(p - line); @@ -616,7 +616,7 @@ static int get_indent_nolabel(linenr_T lnum) // XXX colnr_T col; const char_u *p; - l = ml_get(lnum); + l = (char_u *)ml_get(lnum); p = after_label(l); if (p == NULL) { return 0; @@ -724,13 +724,14 @@ static int cin_get_equal_amount(linenr_T lnum) pos_T fp; if (lnum > 1) { - line = ml_get(lnum - 1); + line = (char_u *)ml_get(lnum - 1); if (*line != NUL && line[STRLEN(line) - 1] == '\\') { return -1; } } - line = s = ml_get(lnum); + s = (char_u *)ml_get(lnum); + line = s; while (*s != NUL && vim_strchr("=;{}\"'", *s) == NULL) { if (cin_iscomment(s)) { // ignore comments s = cin_skipcomment(s); @@ -792,14 +793,14 @@ static int cin_ispreproc_cont(const char_u **pp, linenr_T *lnump, int *amount) if (lnum == 1) { break; } - line = ml_get(--lnum); + line = (char_u *)ml_get(--lnum); if (*line == NUL || line[STRLEN(line) - 1] != '\\') { break; } } if (lnum != *lnump) { - *pp = ml_get(*lnump); + *pp = (char_u *)ml_get(*lnump); } if (retval) { *amount = candidate_amount; @@ -895,7 +896,7 @@ static int cin_isfuncdecl(const char_u **sp, linenr_T first_lnum, linenr_T min_l int just_started = true; if (sp == NULL) { - s = ml_get(lnum); + s = (char_u *)ml_get(lnum); } else { s = *sp; } @@ -908,7 +909,7 @@ static int cin_isfuncdecl(const char_u **sp, linenr_T first_lnum, linenr_T min_l curwin->w_cursor.lnum = save_lnum; return false; } - s = ml_get(lnum); + s = (char_u *)ml_get(lnum); } curwin->w_cursor.lnum = save_lnum; @@ -947,7 +948,7 @@ static int cin_isfuncdecl(const char_u **sp, linenr_T first_lnum, linenr_T min_l // #if defined(x) && {backslash} // defined(y) lnum = first_lnum - 1; - s = ml_get(lnum); + s = (char_u *)ml_get(lnum); if (*s == NUL || s[STRLEN(s) - 1] != '\\') { retval = true; } @@ -964,7 +965,7 @@ static int cin_isfuncdecl(const char_u **sp, linenr_T first_lnum, linenr_T min_l if (lnum >= curbuf->b_ml.ml_line_count) { break; } - s = ml_get(++lnum); + s = (char_u *)ml_get(++lnum); if (!cin_ispreproc(s)) { break; } @@ -989,7 +990,7 @@ static int cin_isfuncdecl(const char_u **sp, linenr_T first_lnum, linenr_T min_l done: if (lnum != first_lnum && sp != NULL) { - *sp = ml_get(first_lnum); + *sp = (char_u *)ml_get(first_lnum); } return retval; @@ -1121,7 +1122,7 @@ static int cin_iswhileofdo_end(int terminated) curwin->w_cursor.col = i; trypos = find_match_paren(curbuf->b_ind_maxparen); if (trypos != NULL) { - s = cin_skipcomment(ml_get(trypos->lnum)); + s = cin_skipcomment((char_u *)ml_get(trypos->lnum)); if (*s == '}') { // accept "} while (cond);" s = cin_skipcomment(s + 1); } @@ -1200,7 +1201,7 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) * {} */ while (lnum > 1) { - line = ml_get(lnum - 1); + line = (char_u *)ml_get(lnum - 1); s = (char_u *)skipwhite((char *)line); if (*s == '#' || *s == NUL) { break; @@ -1222,7 +1223,7 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) } pos->lnum = lnum; - line = ml_get(lnum); + line = (char_u *)ml_get(lnum); s = line; for (;;) { if (*s == NUL) { @@ -1230,7 +1231,7 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) break; } // Continue in the cursor line. - line = ml_get(++lnum); + line = (char_u *)ml_get(++lnum); s = line; } if (s == line) { @@ -1420,7 +1421,8 @@ static int cin_skip2pos(pos_T *trypos) const char_u *p; const char_u *new_p; - p = line = ml_get(trypos->lnum); + line = (char_u *)ml_get(trypos->lnum); + p = line; while (*p && (colnr_T)(p - line) < trypos->col) { if (cin_iscomment(p)) { p = cin_skipcomment(p); @@ -1952,7 +1954,7 @@ int get_c_indent(void) /* Get a copy of the current contents of the line. * This is required, because only the most recent line obtained with * ml_get is valid! */ - linecopy = vim_strsave(ml_get(cur_curpos.lnum)); + linecopy = vim_strsave((char_u *)ml_get(cur_curpos.lnum)); /* * In insert mode and the cursor is on a ')' truncate the line at the @@ -2019,7 +2021,7 @@ int get_c_indent(void) if (trypos == NULL && curwin->w_cursor.lnum > 1) { // There may be a statement before the comment, search from the end // of the line for a comment start. - linecomment_pos.col = check_linecomment((char *)ml_get(curwin->w_cursor.lnum - 1)); + linecomment_pos.col = check_linecomment(ml_get(curwin->w_cursor.lnum - 1)); if (linecomment_pos.col != MAXCOL) { trypos = &linecomment_pos; trypos->lnum = curwin->w_cursor.lnum - 1; @@ -2094,7 +2096,7 @@ int get_c_indent(void) * line, use the indent of that line plus offset. If * the middle comment string matches in the previous * line, use the indent of that line. XXX */ - look = (char_u *)skipwhite((char *)ml_get(curwin->w_cursor.lnum - 1)); + look = (char_u *)skipwhite(ml_get(curwin->w_cursor.lnum - 1)); if (STRNCMP(look, lead_start, lead_start_len) == 0) { amount = get_indent_lnum(curwin->w_cursor.lnum - 1); } else if (STRNCMP(look, lead_middle, lead_middle_len) == 0) { @@ -2156,7 +2158,7 @@ int get_c_indent(void) } if (amount == -1) { // use the comment opener if (!curbuf->b_ind_in_comment2) { - start = ml_get(comment_pos->lnum); + start = (char_u *)ml_get(comment_pos->lnum); look = start + comment_pos->col + 2; // skip / and * if (*look != NUL) { // if something after it comment_pos->col = (colnr_T)((char_u *)skipwhite((char *)look) - start); @@ -2208,7 +2210,7 @@ int get_c_indent(void) } else { amount = -1; for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; lnum--) { - l = (char_u *)skipwhite((char *)ml_get(lnum)); + l = (char_u *)skipwhite(ml_get(lnum)); if (cin_nocode(l)) { // skip comment lines continue; } @@ -2269,7 +2271,7 @@ int get_c_indent(void) curwin->w_cursor = cursor_save; - line = ml_get(outermost.lnum); + line = (char_u *)ml_get(outermost.lnum); is_if_for_while = cin_is_if_for_while_before_offset(line, &outermost.col); @@ -2297,7 +2299,7 @@ int get_c_indent(void) } curwin->w_cursor.lnum = save_lnum; - look = ml_get(our_paren_pos.lnum) + look_col; + look = (char_u *)ml_get(our_paren_pos.lnum) + look_col; } if (theline[0] == ')' || (curbuf->b_ind_unclosed == 0 && is_if_for_while == 0) @@ -2314,7 +2316,7 @@ int get_c_indent(void) */ if (theline[0] != ')') { cur_amount = MAXCOL; - l = ml_get(our_paren_pos.lnum); + l = (char_u *)ml_get(our_paren_pos.lnum); if (curbuf->b_ind_unclosed_wrapped && cin_ends_in(l, (char_u *)"(", NULL)) { /* look for opening unmatched paren, indent one level @@ -2435,7 +2437,7 @@ int get_c_indent(void) tryposBrace = &tryposCopy; trypos = tryposBrace; ourscope = trypos->lnum; - start = ml_get(ourscope); + start = (char_u *)ml_get(ourscope); /* * Now figure out how indented the line is in general. @@ -3054,7 +3056,7 @@ int get_c_indent(void) */ if (terminated == ',') { while (curwin->w_cursor.lnum > 1) { - l = ml_get(curwin->w_cursor.lnum - 1); + l = (char_u *)ml_get(curwin->w_cursor.lnum - 1); if (*l == NUL || l[STRLEN(l) - 1] != '\\') { break; } @@ -3607,7 +3609,7 @@ term_again: * here; */ while (n == 0 && curwin->w_cursor.lnum > 1) { - l = ml_get(curwin->w_cursor.lnum - 1); + l = (char_u *)ml_get(curwin->w_cursor.lnum - 1); if (*l == NUL || l[STRLEN(l) - 1] != '\\') { break; } @@ -3670,7 +3672,7 @@ term_again: pos_T curpos_save = curwin->w_cursor; while (curwin->w_cursor.lnum > 1) { - look = ml_get(--curwin->w_cursor.lnum); + look = (char_u *)ml_get(--curwin->w_cursor.lnum); if (!(cin_nocode(look) || cin_ispreproc_cont(&look, &curwin->w_cursor.lnum, &amount))) { break; @@ -3702,7 +3704,7 @@ term_again: * indent_to_0 here; */ if (cin_ends_in(l, (char_u *)";", NULL)) { - l = ml_get(curwin->w_cursor.lnum - 1); + l = (char_u *)ml_get(curwin->w_cursor.lnum - 1); if (cin_ends_in(l, (char_u *)",", NULL) || (*l != NUL && l[STRLEN(l) - 1] == '\\')) { break; @@ -3737,7 +3739,7 @@ term_again: // char *foo = "asdf{backslash} // here"; if (cur_curpos.lnum > 1) { - l = ml_get(cur_curpos.lnum - 1); + l = (char_u *)ml_get(cur_curpos.lnum - 1); if (*l != NUL && l[STRLEN(l) - 1] == '\\') { cur_amount = cin_get_equal_amount(cur_curpos.lnum - 1); if (cur_amount > 0) { diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index ba0a36cafe..a530061280 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2177,7 +2177,7 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) p = compl_orig_text; for (len = 0; p[len] != NUL && p[len] == ptr[len]; len++) {} if (len > 0) { - len -= utf_head_off(p, p + len); + len -= utf_head_off((char *)p, (char *)p + len); } for (p += len; *p != NUL; MB_PTR_ADV(p)) { AppendCharToRedobuff(K_BS); @@ -3726,16 +3726,16 @@ static int get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col) } else if (--startcol < 0 || !vim_iswordp(mb_prevptr(line, line + startcol + 1))) { // Match any word of at least two chars - compl_pattern = (char *)vim_strsave((char_u *)"\\<\\k\\k"); + compl_pattern = xstrdup("\\<\\k\\k"); compl_col += curs_col; compl_length = 0; } else { // Search the point of change class of multibyte character // or not a word single byte character backward. - startcol -= utf_head_off(line, line + startcol); + startcol -= utf_head_off((char *)line, (char *)line + startcol); int base_class = mb_get_class(line + startcol); while (--startcol >= 0) { - int head_off = utf_head_off(line, line + startcol); + int head_off = utf_head_off((char *)line, (char *)line + startcol); if (base_class != mb_get_class(line + startcol - head_off)) { break; } @@ -3893,7 +3893,7 @@ static int get_userdefined_compl_info(colnr_T curs_col) // Setup variables for completion. Need to obtain "line" again, // it may have become invalid. - char_u *line = ml_get(curwin->w_cursor.lnum); + char_u *line = (char_u *)ml_get(curwin->w_cursor.lnum); compl_length = curs_col - compl_col; compl_pattern = (char *)vim_strnsave(line + compl_col, (size_t)compl_length); @@ -3919,7 +3919,7 @@ static int get_spell_compl_info(int startcol, colnr_T curs_col) compl_length = (int)curs_col - compl_col; } // Need to obtain "line" again, it may have become invalid. - char_u *line = ml_get(curwin->w_cursor.lnum); + char_u *line = (char_u *)ml_get(curwin->w_cursor.lnum); compl_pattern = (char *)vim_strnsave(line + compl_col, (size_t)compl_length); return OK; @@ -4036,7 +4036,7 @@ static int ins_compl_start(void) return FAIL; } - char_u *line = ml_get(curwin->w_cursor.lnum); + char_u *line = (char_u *)ml_get(curwin->w_cursor.lnum); colnr_T curs_col = curwin->w_cursor.col; compl_pending = 0; @@ -4074,7 +4074,7 @@ static int ins_compl_start(void) } // If "line" was changed while getting completion info get it again. if (line_invalid) { - line = ml_get(curwin->w_cursor.lnum); + line = (char_u *)ml_get(curwin->w_cursor.lnum); } if (compl_status_adding()) { diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 5601db274b..b84539852f 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -104,7 +104,7 @@ // MB_PTR_BACK(): backup a pointer to the previous character, taking care of // multi-byte characters if needed. Only use with "p" > "s" ! #define MB_PTR_BACK(s, p) \ - (p -= utf_head_off((char_u *)(s), (char_u *)(p) - 1) + 1) + (p -= utf_head_off((char *)(s), (char *)(p) - 1) + 1) // MB_CHAR2BYTES(): convert character to bytes and advance pointer to bytes #define MB_CHAR2BYTES(c, b) ((b) += utf_char2bytes((c), ((char *)b))) diff --git a/src/nvim/main.c b/src/nvim/main.c index 883f946cad..1c7cfea768 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1914,9 +1914,9 @@ static bool do_user_initialization(void) char_u *user_vimrc = (char_u *)stdpaths_user_conf_subpath("init.vim"); // init.lua - if (os_path_exists(init_lua_path) + if (os_path_exists((char *)init_lua_path) && do_source((char *)init_lua_path, true, DOSO_VIMRC)) { - if (os_path_exists(user_vimrc)) { + if (os_path_exists((char *)user_vimrc)) { semsg(_("E5422: Conflicting configs: \"%s\" \"%s\""), init_lua_path, user_vimrc); } diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 333fb847f6..d740a0eb77 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -174,7 +174,7 @@ static void showmap(mapblock_T *mp, bool local) } // Display the LHS. Get length of what we write. - len = (size_t)msg_outtrans_special(mp->m_keys, true, 0); + len = (size_t)msg_outtrans_special((char *)mp->m_keys, true, 0); do { msg_putchar(' '); // padd with blanks len++; @@ -203,7 +203,7 @@ static void showmap(mapblock_T *mp, bool local) } else if (mp->m_str[0] == NUL) { msg_puts_attr("", HL_ATTR(HLF_8)); } else { - msg_outtrans_special((char_u *)mp->m_str, false, 0); + msg_outtrans_special(mp->m_str, false, 0); } if (mp->m_desc != NULL) { diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 9df4d416ff..816599271d 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -819,7 +819,7 @@ static char_u *mark_line(pos_T *mp, int lead_len) } assert(Columns >= 0); // Allow for up to 5 bytes per character. - s = vim_strnsave((char_u *)skipwhite((char *)ml_get(mp->lnum)), (size_t)Columns * 5); + s = vim_strnsave((char_u *)skipwhite(ml_get(mp->lnum)), (size_t)Columns * 5); // Truncate the line to fit it in the window len = 0; @@ -1758,7 +1758,7 @@ void mark_mb_adjustpos(buf_T *buf, pos_T *lp) if (*p == NUL || (int)STRLEN(p) < lp->col) { lp->col = 0; } else { - lp->col -= utf_head_off(p, p + lp->col); + lp->col -= utf_head_off((char *)p, (char *)p + lp->col); } // Reset "coladd" when the cursor would be on the right half of a // double-wide character. diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index b874f0dc94..f592b54f67 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1618,21 +1618,24 @@ void show_utf8(void) /// "base" must be the start of the string, which must be NUL terminated. /// If "p" points to the NUL at the end of the string return 0. /// Returns 0 when already at the first byte of a character. -int utf_head_off(const char_u *base, const char_u *p) +int utf_head_off(const char *base_in, const char *p_in) { int c; int len; - if (*p < 0x80) { // be quick for ASCII + if ((uint8_t)(*p_in) < 0x80) { // be quick for ASCII return 0; } + const uint8_t *base = (uint8_t *)base_in; + const uint8_t *p = (uint8_t *)p_in; + // Skip backwards over trailing bytes: 10xx.xxxx // Skip backwards again if on a composing char. - const char_u *q; + const uint8_t *q; for (q = p;; q--) { // Move s to the last byte of this char. - const char_u *s; + const uint8_t *s; for (s = q; (s[1] & 0xc0) == 0x80; s++) {} // Move q to the first byte of this char. @@ -1657,7 +1660,7 @@ int utf_head_off(const char_u *base, const char_u *p) if (arabic_maycombine(c)) { // Advance to get a sneak-peak at the next char - const char_u *j = q; + const uint8_t *j = q; j--; // Move j to the first byte of this char. while (j > base && (*j & 0xc0) == 0x80) { @@ -2042,7 +2045,7 @@ void mb_check_adjust_col(void *win_) win->w_cursor.col = len - 1; } // Move the cursor to the head byte. - win->w_cursor.col -= utf_head_off((char_u *)p, (char_u *)p + win->w_cursor.col); + win->w_cursor.col -= utf_head_off(p, p + win->w_cursor.col); } // Reset `coladd` when the cursor would be on the right half of a diff --git a/src/nvim/memline.c b/src/nvim/memline.c index b0b6b675cb..a30a98d6e9 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1177,7 +1177,7 @@ void ml_recover(bool checkext) } else { for (idx = 1; idx <= lnum; idx++) { // Need to copy one line, fetching the other one may flush it. - p = vim_strsave(ml_get(idx)); + p = vim_strsave((char_u *)ml_get(idx)); i = STRCMP(p, ml_get(idx + lnum)); xfree(p); if (i != 0) { @@ -1276,7 +1276,7 @@ int recover_names(char_u *fname, int list, int nr, char_u **fname_out) #ifdef HAVE_READLINK // Expand symlink in the file name, because the swap file is created // with the actual file instead of with the symlink. - if (resolve_symlink(fname, fname_buf) == OK) { + if (resolve_symlink((char *)fname, (char *)fname_buf) == OK) { fname_res = fname_buf; } else #endif @@ -1351,7 +1351,7 @@ int recover_names(char_u *fname, int list, int nr, char_u **fname_out) if (*dirp == NUL && file_count + num_files == 0 && fname != NULL) { char_u *swapname = (char_u *)modname((char *)fname_res, ".swp", true); if (swapname != NULL) { - if (os_path_exists(swapname)) { + if (os_path_exists((char *)swapname)) { files = xmalloc(sizeof(char_u *)); files[0] = (char *)swapname; swapname = NULL; @@ -1399,7 +1399,7 @@ int recover_names(char_u *fname, int list, int nr, char_u **fname_out) } } else { msg_puts(_(" In directory ")); - msg_home_replace(dir_name); + msg_home_replace((char *)dir_name); msg_puts(":\n"); } @@ -1592,7 +1592,7 @@ static bool swapfile_unchanged(char *fname) int ret = true; // Swap file must exist. - if (!os_path_exists((char_u *)fname)) { + if (!os_path_exists(fname)) { return false; } @@ -1793,9 +1793,9 @@ theend: /// /// On failure an error message is given and IObuff is returned (to avoid /// having to check for error everywhere). -char_u *ml_get(linenr_T lnum) +char *ml_get(linenr_T lnum) { - return ml_get_buf(curbuf, lnum, false); + return (char *)ml_get_buf(curbuf, lnum, false); } /// @return pointer to position "pos". @@ -2414,9 +2414,9 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b return OK; } -void ml_add_deleted_len(char_u *ptr, ssize_t len) +void ml_add_deleted_len(char *ptr, ssize_t len) { - ml_add_deleted_len_buf(curbuf, ptr, len); + ml_add_deleted_len_buf(curbuf, (char_u *)ptr, len); } void ml_add_deleted_len_buf(buf_T *buf, char_u *ptr, ssize_t len) @@ -2439,7 +2439,7 @@ void ml_add_deleted_len_buf(buf_T *buf, char_u *ptr, ssize_t len) int ml_replace(linenr_T lnum, char *line, bool copy) { - return ml_replace_buf(curbuf, lnum, (char_u *)line, copy); + return ml_replace_buf(curbuf, lnum, line, copy); } /// Replace line "lnum", with buffering, in current buffer. @@ -2454,7 +2454,7 @@ int ml_replace(linenr_T lnum, char *line, bool copy) /// changed_lines(), unless update_screen(UPD_NOT_VALID) is used. /// /// @return FAIL for failure, OK otherwise -int ml_replace_buf(buf_T *buf, linenr_T lnum, char_u *line, bool copy) +int ml_replace_buf(buf_T *buf, linenr_T lnum, char *line, bool copy) { if (line == NULL) { // just checking... return FAIL; @@ -2468,7 +2468,7 @@ int ml_replace_buf(buf_T *buf, linenr_T lnum, char_u *line, bool copy) bool readlen = true; if (copy) { - line = vim_strsave(line); + line = xstrdup(line); } if (buf->b_ml.ml_line_lnum != lnum) { // other line buffered ml_flush_line(buf); // flush it @@ -2483,7 +2483,7 @@ int ml_replace_buf(buf_T *buf, linenr_T lnum, char_u *line, bool copy) ml_add_deleted_len_buf(buf, ml_get_buf(buf, lnum, false), -1); } - buf->b_ml.ml_line_ptr = line; + buf->b_ml.ml_line_ptr = (char_u *)line; buf->b_ml.ml_line_lnum = lnum; buf->b_ml.ml_flags = (buf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY; @@ -3142,9 +3142,9 @@ static void ml_lineadd(buf_T *buf, int count) /// /// @return OK if it worked and the resolved link in "buf[MAXPATHL]", /// FAIL otherwise -int resolve_symlink(const char_u *fname, char_u *buf) +int resolve_symlink(const char *fname, char *buf) { - char_u tmp[MAXPATHL]; + char tmp[MAXPATHL]; int ret; int depth = 0; @@ -3162,7 +3162,7 @@ int resolve_symlink(const char_u *fname, char_u *buf) return FAIL; } - ret = (int)readlink((char *)tmp, (char *)buf, MAXPATHL - 1); + ret = (int)readlink(tmp, buf, MAXPATHL - 1); if (ret <= 0) { if (errno == EINVAL || errno == ENOENT) { // Found non-symlink or not existing file, stop here. @@ -3185,10 +3185,10 @@ int resolve_symlink(const char_u *fname, char_u *buf) // If it's relative, build a new path based on the directory // portion of the filename (if any) and the path the symlink // points to. - if (path_is_absolute(buf)) { + if (path_is_absolute((char_u *)buf)) { STRCPY(tmp, buf); } else { - char_u *tail = (char_u *)path_tail((char *)tmp); + char_u *tail = (char_u *)path_tail(tmp); if (STRLEN(tail) + STRLEN(buf) >= MAXPATHL) { return FAIL; } @@ -3201,7 +3201,7 @@ int resolve_symlink(const char_u *fname, char_u *buf) * be consistent even when opening a relative symlink from different * working directories. */ - return vim_FullName((char *)tmp, (char *)buf, MAXPATHL, true); + return vim_FullName(tmp, buf, MAXPATHL, true); } #endif @@ -3217,7 +3217,7 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name // Expand symlink in the file name, so that we put the swap file with the // actual file instead of with the symlink. - if (resolve_symlink(fname, fname_buf) == OK) { + if (resolve_symlink((char *)fname, (char *)fname_buf) == OK) { fname_res = fname_buf; } #endif @@ -3300,7 +3300,7 @@ static void attention_message(buf_T *buf, char_u *fname) no_wait_return++; (void)emsg(_("E325: ATTENTION")); msg_puts(_("\nFound a swap file by the name \"")); - msg_home_replace(fname); + msg_home_replace((char *)fname); msg_puts("\"\n"); const time_t swap_mtime = swapfile_info(fname); msg_puts(_("While opening file \"")); @@ -3499,7 +3499,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ // It's safe to delete the swap file if all these are true: // - the edited file exists // - the swap file has no changes and looks OK - if (os_path_exists((char_u *)buf->b_fname) && swapfile_unchanged(fname)) { + if (os_path_exists(buf->b_fname) && swapfile_unchanged(fname)) { choice = 4; if (p_verbose > 0) { verb_msg(_("Found a swap file that is not useful, deleting it")); @@ -3541,13 +3541,13 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ memcpy(name, sw_msg_1, sw_msg_1_len + 1); home_replace(NULL, fname, &name[sw_msg_1_len], fname_len, true); xstrlcat(name, sw_msg_2, name_len); - choice = do_dialog(VIM_WARNING, (char_u *)_("VIM - ATTENTION"), - (char_u *)name, + choice = do_dialog(VIM_WARNING, _("VIM - ATTENTION"), + name, process_still_running - ? (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover" - "\n&Quit\n&Abort") : - (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover" - "\n&Delete it\n&Quit\n&Abort"), + ? _("&Open Read-Only\n&Edit anyway\n&Recover" + "\n&Quit\n&Abort") : + _("&Open Read-Only\n&Edit anyway\n&Recover" + "\n&Delete it\n&Quit\n&Abort"), 1, NULL, false); if (process_still_running && choice >= 4) { @@ -3582,7 +3582,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ } // If the file was deleted this fname can be used. - if (!os_path_exists((char_u *)fname)) { + if (!os_path_exists(fname)) { break; } } else { @@ -4212,8 +4212,8 @@ int dec(pos_T *lp) lp->coladd = 0; if (lp->col == MAXCOL) { // past end of line - char_u *p = ml_get(lp->lnum); - lp->col = (colnr_T)STRLEN(p); + char *p = ml_get(lp->lnum); + lp->col = (colnr_T)strlen(p); lp->col -= utf_head_off(p, p + lp->col); return 0; } @@ -4221,15 +4221,15 @@ int dec(pos_T *lp) if (lp->col > 0) { // still within line lp->col--; - char_u *p = ml_get(lp->lnum); + char *p = ml_get(lp->lnum); lp->col -= utf_head_off(p, p + lp->col); return 0; } if (lp->lnum > 1) { // there is a prior line lp->lnum--; - char_u *p = ml_get(lp->lnum); - lp->col = (colnr_T)STRLEN(p); + char *p = ml_get(lp->lnum); + lp->col = (colnr_T)strlen(p); lp->col -= utf_head_off(p, p + lp->col); return 1; } diff --git a/src/nvim/menu.c b/src/nvim/menu.c index cb6918cd27..84a1defbe0 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -888,7 +888,7 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth) if (*menu->strings[bit] == NUL) { msg_puts_attr("", HL_ATTR(HLF_8)); } else { - msg_outtrans_special((char_u *)menu->strings[bit], false, 0); + msg_outtrans_special(menu->strings[bit], false, 0); } } } diff --git a/src/nvim/message.c b/src/nvim/message.c index 80b5f53f4e..e7959c73c6 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -59,7 +59,7 @@ struct msgchunk_S { char sb_eol; // true when line ends after this text int sb_msg_col; // column in which text starts int sb_attr; // text attributes - char_u sb_text[1]; // text to be displayed, actually longer + char sb_text[1]; // text to be displayed, actually longer }; // Magic chars used in confirm dialog strings @@ -70,8 +70,8 @@ static int confirm_msg_used = false; // displaying confirm_msg #ifdef INCLUDE_GENERATED_DECLARATIONS # include "message.c.generated.h" #endif -static char_u *confirm_msg = NULL; // ":confirm" message -static char_u *confirm_msg_tail; // tail of confirm_msg +static char *confirm_msg = NULL; // ":confirm" message +static char *confirm_msg_tail; // tail of confirm_msg MessageHistoryEntry *first_msg_hist = NULL; MessageHistoryEntry *last_msg_hist = NULL; @@ -251,7 +251,7 @@ void msg_multiline_attr(const char *s, int attr, bool check_int, bool *need_clea if (next_spec != NULL) { // Printing all char that are before the char found by strpbrk - msg_outtrans_len_attr((const char_u *)s, (int)(next_spec - s), attr); + msg_outtrans_len_attr(s, (int)(next_spec - s), attr); if (*next_spec != TAB && *need_clear) { msg_clr_eos(); @@ -294,7 +294,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) { static int entered = 0; int retval; - char_u *buf = NULL; + char *buf = NULL; if (keep && multiline) { // Not implemented. 'multiline' is only used by nvim-added messages, @@ -335,9 +335,9 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) // Truncate the message if needed. msg_start(); - buf = msg_strtrunc((char_u *)s, false); + buf = msg_strtrunc((char *)s, false); if (buf != NULL) { - s = (const char *)buf; + s = buf; } bool need_clear = true; @@ -367,9 +367,9 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) /// @return an allocated string or NULL when no truncating is done. /// /// @param force always truncate -char_u *msg_strtrunc(char_u *s, int force) +char *msg_strtrunc(char *s, int force) { - char_u *buf = NULL; + char *buf = NULL; int len; int room; @@ -377,7 +377,7 @@ char_u *msg_strtrunc(char_u *s, int force) if ((!msg_scroll && !need_wait_return && shortmess(SHM_TRUNCALL) && !exmode_active && msg_silent == 0 && !ui_has(kUIMessages)) || force) { - len = vim_strsize((char *)s); + len = vim_strsize(s); if (msg_scrolled != 0) { // Use all the columns. room = (Rows - msg_row) * Columns - 1; @@ -390,7 +390,7 @@ char_u *msg_strtrunc(char_u *s, int force) // composing chars) len = (room + 2) * 18; buf = xmalloc((size_t)len); - trunc_string((char *)s, (char *)buf, room, len); + trunc_string(s, buf, room, len); } } return buf; @@ -444,7 +444,7 @@ void trunc_string(char *s, char *buf, int room_in, int buflen) half = i = (int)STRLEN(s); for (;;) { do { - half = half - utf_head_off((char_u *)s, (char_u *)s + half - 1) - 1; + half = half - utf_head_off(s, s + half - 1) - 1; } while (half > 0 && utf_iscomposing(utf_ptr2char(s + half))); n = ptr2cells(s + half); if (len + n > room || half == 0) { @@ -900,7 +900,7 @@ char *msg_trunc_attr(char *s, bool force, int attr) // Add message to history before truncating. add_msg_hist(s, -1, attr, false); - char *ts = (char *)msg_may_trunc(force, (char_u *)s); + char *ts = msg_may_trunc(force, s); msg_hist_off = true; n = msg_attr(ts, attr); @@ -917,14 +917,14 @@ char *msg_trunc_attr(char *s, bool force, int attr) /// @return a pointer to where the truncated message starts. /// /// @note: May change the message by replacing a character with '<'. -char_u *msg_may_trunc(bool force, char_u *s) +char *msg_may_trunc(bool force, char *s) { int room; room = (Rows - cmdline_row - 1) * Columns + sc_col - 1; if ((force || (shortmess(SHM_TRUNC) && !exmode_active)) && (int)STRLEN(s) - room > 0 && p_ch > 0) { - int size = vim_strsize((char *)s); + int size = vim_strsize(s); // There may be room anyway when there are multibyte chars. if (size <= room) { @@ -932,8 +932,8 @@ char_u *msg_may_trunc(bool force, char_u *s) } int n; for (n = 0; size >= room;) { - size -= utf_ptr2cells((char *)s + n); - n += utfc_ptr2len((char *)s + n); + size -= utf_ptr2cells(s + n); + n += utfc_ptr2len(s + n); } n--; s += n; @@ -1497,19 +1497,19 @@ void msg_outnum(long n) msg_puts(buf); } -void msg_home_replace(char_u *fname) +void msg_home_replace(char *fname) { msg_home_replace_attr(fname, 0); } -void msg_home_replace_hl(char_u *fname) +void msg_home_replace_hl(char *fname) { msg_home_replace_attr(fname, HL_ATTR(HLF_D)); } -static void msg_home_replace_attr(char_u *fname, int attr) +static void msg_home_replace_attr(char *fname, int attr) { - char *name = home_replace_save(NULL, (char *)fname); + char *name = home_replace_save(NULL, fname); msg_outtrans_attr(name, attr); xfree(name); } @@ -1526,12 +1526,12 @@ int msg_outtrans(char *str) int msg_outtrans_attr(const char *str, int attr) { - return msg_outtrans_len_attr((char_u *)str, (int)STRLEN(str), attr); + return msg_outtrans_len_attr(str, (int)STRLEN(str), attr); } int msg_outtrans_len(const char *str, int len) { - return msg_outtrans_len_attr((char_u *)str, len, 0); + return msg_outtrans_len_attr(str, len, 0); } /// Output one character at "p". @@ -1543,19 +1543,19 @@ char *msg_outtrans_one(char *p, int attr) int l; if ((l = utfc_ptr2len(p)) > 1) { - msg_outtrans_len_attr((char_u *)p, l, attr); + msg_outtrans_len_attr(p, l, attr); return p + l; } msg_puts_attr((const char *)transchar_byte(*p), attr); return p + 1; } -int msg_outtrans_len_attr(const char_u *msgstr, int len, int attr) +int msg_outtrans_len_attr(const char *msgstr, int len, int attr) { int retval = 0; - const char *str = (const char *)msgstr; - const char *plain_start = (const char *)msgstr; - char_u *s; + const char *str = msgstr; + const char *plain_start = msgstr; + char *s; int mb_l; int c; int save_got_int = got_int; @@ -1601,7 +1601,7 @@ int msg_outtrans_len_attr(const char_u *msgstr, int len, int attr) len -= mb_l - 1; str += mb_l; } else { - s = transchar_byte((uint8_t)(*str)); + s = (char *)transchar_byte((uint8_t)(*str)); if (s[1] != NUL) { // Unprintable char: print the printable chars so far and the // translation of the unprintable char. @@ -1663,12 +1663,12 @@ void msg_make(char *arg) /// /// @param from true for LHS of a mapping /// @param maxlen screen columns, 0 for unlimited -int msg_outtrans_special(const char_u *strstart, bool from, int maxlen) +int msg_outtrans_special(const char *strstart, bool from, int maxlen) { if (strstart == NULL) { return 0; // Do nothing. } - const char_u *str = strstart; + const char *str = strstart; int retval = 0; int attr = HL_ATTR(HLF_8); @@ -1679,7 +1679,7 @@ int msg_outtrans_special(const char_u *strstart, bool from, int maxlen) text = ""; str++; } else { - text = str2special((const char **)&str, from, false); + text = str2special(&str, from, false); } if (text[0] != NUL && text[1] == NUL) { // single-byte character or illegal byte @@ -1818,20 +1818,20 @@ void str2specialbuf(const char *sp, char *buf, size_t len) } /// print line for :print or :list command -void msg_prt_line(char_u *s, int list) +void msg_prt_line(char *s, int list) { int c; int col = 0; int n_extra = 0; int c_extra = 0; int c_final = 0; - char_u *p_extra = NULL; // init to make SASC shut up + char *p_extra = NULL; // init to make SASC shut up int n; int attr = 0; - char_u *lead = NULL; + char *lead = NULL; bool in_multispace = false; int multispace_pos = 0; - char_u *trail = NULL; + char *trail = NULL; int l; if (curwin->w_p_list) { @@ -1873,16 +1873,16 @@ void msg_prt_line(char_u *s, int list) c = c_extra; } else { assert(p_extra != NULL); - c = *p_extra++; + c = (unsigned char)(*p_extra++); } - } else if ((l = utfc_ptr2len((char *)s)) > 1) { - col += utf_ptr2cells((char *)s); + } else if ((l = utfc_ptr2len(s)) > 1) { + col += utf_ptr2cells(s); char buf[MB_MAXBYTES + 1]; if (l >= MB_MAXBYTES) { xstrlcpy(buf, "?", sizeof(buf)); } else if (curwin->w_p_lcs_chars.nbsp != NUL && list - && (utf_ptr2char((char *)s) == 160 - || utf_ptr2char((char *)s) == 0x202f)) { + && (utf_ptr2char(s) == 160 + || utf_ptr2char(s) == 0x202f)) { int len = utf_char2bytes(curwin->w_p_lcs_chars.nbsp, buf); buf[len] = NUL; } else { @@ -1894,7 +1894,7 @@ void msg_prt_line(char_u *s, int list) continue; } else { attr = 0; - c = *s++; + c = (unsigned char)(*s++); in_multispace = c == ' ' && ((col > 0 && s[-2] == ' ') || *s == ' '); if (!in_multispace) { multispace_pos = 0; @@ -1920,7 +1920,7 @@ void msg_prt_line(char_u *s, int list) c = curwin->w_p_lcs_chars.nbsp; attr = HL_ATTR(HLF_0); } else if (c == NUL && list && curwin->w_p_lcs_chars.eol != NUL) { - p_extra = (char_u *)""; + p_extra = ""; c_extra = NUL; c_final = NUL; n_extra = 1; @@ -1929,10 +1929,10 @@ void msg_prt_line(char_u *s, int list) s--; } else if (c != NUL && (n = byte2cells(c)) > 1) { n_extra = n - 1; - p_extra = transchar_byte(c); + p_extra = (char *)transchar_byte(c); c_extra = NUL; c_final = NUL; - c = *p_extra++; + c = (unsigned char)(*p_extra++); // Use special coloring to be able to distinguish from // the same in plain text. attr = HL_ATTR(HLF_0); @@ -2023,12 +2023,12 @@ void msg_puts_title(const char *s) /// Show a message in such a way that it always fits in the line. Cut out a /// part in the middle and replace it with "..." when necessary. /// Does not handle multi-byte characters! -void msg_outtrans_long_attr(char_u *longstr, int attr) +void msg_outtrans_long_attr(char *longstr, int attr) { msg_outtrans_long_len_attr(longstr, (int)STRLEN(longstr), attr); } -void msg_outtrans_long_len_attr(char_u *longstr, int len, int attr) +void msg_outtrans_long_len_attr(char *longstr, int len, int attr) { int slen = len; int room; @@ -2105,7 +2105,7 @@ void msg_puts_attr_len(const char *const str, const ptrdiff_t len, int attr) } } if (!msg_use_printf() || (headless_mode && default_grid.chars)) { - msg_puts_display((const char_u *)str, (int)len, attr, false); + msg_puts_display(str, (int)len, attr, false); } need_fileinfo = false; @@ -2148,10 +2148,10 @@ static void msg_ext_emit_chunk(void) /// The display part of msg_puts_attr_len(). /// May be called recursively to display scroll-back text. -static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurse) +static void msg_puts_display(const char *str, int maxlen, int attr, int recurse) { - const char_u *s = str; - const char_u *t_s = str; // String from "t_s" to "s" is still todo. + const char *s = str; + const char *t_s = str; // String from "t_s" to "s" is still todo. int t_col = 0; // Screen cells todo, 0 when "t_s" not used. int l; int cw; @@ -2186,19 +2186,19 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs && (*s == '\n' || (cmdmsg_rl ? (msg_col <= 1 || (*s == TAB && msg_col <= 7) - || (utf_ptr2cells((char *)s) > 1 + || (utf_ptr2cells(s) > 1 && msg_col <= 2)) : ((*s != '\r' && msg_col + t_col >= Columns - 1) || (*s == TAB && msg_col + t_col >= ((Columns - 1) & ~7)) - || (utf_ptr2cells((char *)s) > 1 + || (utf_ptr2cells(s) > 1 && msg_col + t_col >= Columns - 2))))) { // The screen is scrolled up when at the last row (some terminals // scroll automatically, some don't. To avoid problems we scroll // ourselves). if (t_col > 0) { // output postponed text - t_puts(&t_col, (char *)t_s, (char *)s, attr); + t_puts(&t_col, t_s, s, attr); } // When no more prompt and no more room, truncate here @@ -2207,7 +2207,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs } // Scroll the screen up one line. - bool has_last_char = (*s >= ' ' && !cmdmsg_rl); + bool has_last_char = ((uint8_t)(*s) >= ' ' && !cmdmsg_rl); msg_scroll_up(!has_last_char); msg_row = Rows - 2; @@ -2219,11 +2219,11 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs if (has_last_char) { if (maxlen >= 0) { // Avoid including composing chars after the end. - l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); + l = utfc_ptr2len_len((char_u *)s, (int)((str + maxlen) - s)); } else { - l = utfc_ptr2len((char *)s); + l = utfc_ptr2len(s); } - s = (char_u *)screen_puts_mbyte((char *)s, l, attr); + s = screen_puts_mbyte((char *)s, l, attr); did_last_char = true; } else { did_last_char = false; @@ -2276,13 +2276,13 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs wrap = *s == '\n' || msg_col + t_col >= Columns - || (utf_ptr2cells((char *)s) > 1 + || (utf_ptr2cells(s) > 1 && msg_col + t_col >= Columns - 1) ; if (t_col > 0 && (wrap || *s == '\r' || *s == '\b' || *s == '\t' || *s == BELL)) { // Output any postponed text. - t_puts(&t_col, (char *)t_s, (char *)s, attr); + t_puts(&t_col, t_s, s, attr); } if (wrap && p_more && !recurse) { @@ -2312,20 +2312,20 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs } while (msg_col & 7); } else if (*s == BELL) { // beep (from ":sh") vim_beep(BO_SH); - } else if (*s >= 0x20) { // printable char - cw = utf_ptr2cells((char *)s); + } else if ((uint8_t)(*s) >= 0x20) { // printable char + cw = utf_ptr2cells(s); if (maxlen >= 0) { // avoid including composing chars after the end - l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); + l = utfc_ptr2len_len((char_u *)s, (int)((str + maxlen) - s)); } else { - l = utfc_ptr2len((char *)s); + l = utfc_ptr2len(s); } // When drawing from right to left or when a double-wide character // doesn't fit, draw a single character here. Otherwise collect // characters and draw them all at once later. if (cmdmsg_rl || (cw > 1 && msg_col + t_col >= Columns - 1)) { if (l > 1) { - s = (char_u *)screen_puts_mbyte((char *)s, l, attr) - 1; + s = screen_puts_mbyte((char *)s, l, attr) - 1; } else { msg_screen_putchar(*s, attr); } @@ -2343,7 +2343,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs // Output any postponed text. if (t_col > 0) { - t_puts(&t_col, (char *)t_s, (char *)s, attr); + t_puts(&t_col, t_s, s, attr); } if (p_more && !recurse) { store_sb_text((char **)&sb_str, (char *)s, attr, &sb_col, false); @@ -2679,7 +2679,7 @@ void msg_sb_eol(void) static msgchunk_T *disp_sb_line(int row, msgchunk_T *smp) { msgchunk_T *mp = smp; - char_u *p; + char *p; for (;;) { msg_row = row; @@ -3080,13 +3080,13 @@ static void msg_screen_putchar(int c, int attr) void msg_moremsg(int full) { int attr; - char_u *s = (char_u *)_("-- More --"); + char *s = _("-- More --"); attr = hl_combine_attr(HL_ATTR(HLF_MSG), HL_ATTR(HLF_M)); - grid_puts(&msg_grid_adj, (char *)s, Rows - 1, 0, attr); + grid_puts(&msg_grid_adj, s, Rows - 1, 0, attr); if (full) { grid_puts(&msg_grid_adj, _(" SPACE/d/j: screen/page/line down, b/u/k: up, q: quit "), - Rows - 1, vim_strsize((char *)s), attr); + Rows - 1, vim_strsize(s), attr); } } @@ -3281,7 +3281,7 @@ void msg_check(void) /// @param maxlen if -1, write the whole string, otherwise up to "maxlen" bytes. static void redir_write(const char *const str, const ptrdiff_t maxlen) { - const char_u *s = (char_u *)str; + const char *s = str; static int cur_col = 0; if (maxlen == 0) { @@ -3306,7 +3306,7 @@ static void redir_write(const char *const str, const ptrdiff_t maxlen) ga_concat_len(capture_ga, " ", 1); } if (redir_reg) { - write_reg_contents(redir_reg, (char_u *)" ", 1, true); + write_reg_contents(redir_reg, " ", 1, true); } else if (redir_vname) { var_redir_str(" ", -1); } else if (redir_fd != NULL) { @@ -3332,7 +3332,7 @@ static void redir_write(const char *const str, const ptrdiff_t maxlen) // Write and adjust the current column. while (*s != NUL - && (maxlen < 0 || (int)(s - (const char_u *)str) < maxlen)) { + && (maxlen < 0 || (int)(s - str) < maxlen)) { if (!redir_reg && !redir_vname && !capture_ga) { if (redir_fd != NULL) { putc(*s, redir_fd); @@ -3469,9 +3469,9 @@ void give_warning(char *message, bool hl) no_wait_return--; } -void give_warning2(char_u *const message, char_u *const a1, bool hl) +void give_warning2(char *const message, char *const a1, bool hl) { - vim_snprintf((char *)IObuff, IOSIZE, (char *)message, a1); + vim_snprintf((char *)IObuff, IOSIZE, message, a1); give_warning((char *)IObuff, hl); } @@ -3524,11 +3524,11 @@ void msg_advance(int col) /// @param textfiel IObuff for inputdialog(), NULL otherwise /// @param ex_cmd when true pressing : accepts default and starts Ex command /// @returns 0 if cancelled, otherwise the nth button (1-indexed). -int do_dialog(int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, - char_u *textfield, int ex_cmd) +int do_dialog(int type, char *title, char *message, char *buttons, int dfltbutton, char *textfield, + int ex_cmd) { int retval = 0; - char_u *hotkeys; + char *hotkeys; int c; int i; @@ -3578,10 +3578,10 @@ int do_dialog(int type, char_u *title, char_u *message, char_u *buttons, int dfl c = mb_tolower(c); retval = 1; for (i = 0; hotkeys[i]; i++) { - if (utf_ptr2char((char *)hotkeys + i) == c) { + if (utf_ptr2char(hotkeys + i) == c) { break; } - i += utfc_ptr2len((char *)hotkeys + i) - 1; + i += utfc_ptr2len(hotkeys + i) - 1; retval++; } if (hotkeys[i]) { @@ -3608,14 +3608,14 @@ int do_dialog(int type, char_u *title, char_u *message, char_u *buttons, int dfl /// characters. Return the length of the character in bytes. /// /// @param lowercase make character lower case -static int copy_char(const char_u *from, char_u *to, bool lowercase) +static int copy_char(const char *from, char *to, bool lowercase) FUNC_ATTR_NONNULL_ALL { if (lowercase) { - int c = mb_tolower(utf_ptr2char((char *)from)); - return utf_char2bytes(c, (char *)to); + int c = mb_tolower(utf_ptr2char(from)); + return utf_char2bytes(c, to); } - int len = utfc_ptr2len((char *)from); + int len = utfc_ptr2len(from); memmove(to, from, (size_t)len); return len; } @@ -3635,7 +3635,7 @@ static int copy_char(const char_u *from, char_u *to, bool lowercase) /// corresponding button has a hotkey /// /// @return Pointer to memory allocated for storing hotkeys -static char_u *console_dialog_alloc(const char_u *message, char_u *buttons, bool has_hotkey[]) +static char *console_dialog_alloc(const char *message, char *buttons, bool has_hotkey[]) { int lenhotkey = HOTK_LEN; // count first button has_hotkey[0] = false; @@ -3643,7 +3643,7 @@ static char_u *console_dialog_alloc(const char_u *message, char_u *buttons, bool // Compute the size of memory to allocate. int len = 0; int idx = 0; - char_u *r = buttons; + char *r = buttons; while (*r) { if (*r == DLG_BUTTON_SEP) { len += 3; // '\n' -> ', '; 'x' -> '(x)' @@ -3689,11 +3689,11 @@ static char_u *console_dialog_alloc(const char_u *message, char_u *buttons, bool /// The hotkeys can be multi-byte characters, but without combining chars. /// /// @return an allocated string with hotkeys. -static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfltbutton) +static char *msg_show_console_dialog(char *message, char *buttons, int dfltbutton) FUNC_ATTR_NONNULL_RET { bool has_hotkey[HAS_HOTKEY_LEN] = { false }; - char_u *hotk = console_dialog_alloc(message, buttons, has_hotkey); + char *hotk = console_dialog_alloc(message, buttons, has_hotkey); copy_hotkeys_and_msg(message, buttons, dfltbutton, has_hotkey, hotk); @@ -3709,13 +3709,13 @@ static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfl /// @param has_hotkey An element in this array is true if corresponding button /// has a hotkey /// @param[out] hotkeys_ptr Pointer to the memory location where hotkeys will be copied -static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons, int default_button_idx, - const bool has_hotkey[], char_u *hotkeys_ptr) +static void copy_hotkeys_and_msg(const char *message, char *buttons, int default_button_idx, + const bool has_hotkey[], char *hotkeys_ptr) { *confirm_msg = '\n'; STRCPY(confirm_msg + 1, message); - char_u *msgp = confirm_msg + 1 + STRLEN(message); + char *msgp = confirm_msg + 1 + STRLEN(message); // Define first default hotkey. Keep the hotkey string NUL // terminated to avoid reading past the end. @@ -3732,7 +3732,7 @@ static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons, int def } int idx = 0; - char_u *r = buttons; + char *r = buttons; while (*r) { if (*r == DLG_BUTTON_SEP) { *msgp++ = ','; @@ -3788,28 +3788,28 @@ void display_confirm_msg(void) confirm_msg_used++; if (confirm_msg != NULL) { msg_ext_set_kind("confirm"); - msg_puts_attr((const char *)confirm_msg, HL_ATTR(HLF_M)); + msg_puts_attr(confirm_msg, HL_ATTR(HLF_M)); } confirm_msg_used--; } -int vim_dialog_yesno(int type, char_u *title, char_u *message, int dflt) +int vim_dialog_yesno(int type, char *title, char *message, int dflt) { if (do_dialog(type, - title == NULL ? (char_u *)_("Question") : title, + title == NULL ? _("Question") : title, message, - (char_u *)_("&Yes\n&No"), dflt, NULL, false) == 1) { + _("&Yes\n&No"), dflt, NULL, false) == 1) { return VIM_YES; } return VIM_NO; } -int vim_dialog_yesnocancel(int type, char_u *title, char_u *message, int dflt) +int vim_dialog_yesnocancel(int type, char *title, char *message, int dflt) { switch (do_dialog(type, - title == NULL ? (char_u *)_("Question") : title, + title == NULL ? _("Question") : title, message, - (char_u *)_("&Yes\n&No\n&Cancel"), dflt, NULL, false)) { + _("&Yes\n&No\n&Cancel"), dflt, NULL, false)) { case 1: return VIM_YES; case 2: @@ -3818,12 +3818,12 @@ int vim_dialog_yesnocancel(int type, char_u *title, char_u *message, int dflt) return VIM_CANCEL; } -int vim_dialog_yesnoallcancel(int type, char_u *title, char_u *message, int dflt) +int vim_dialog_yesnoallcancel(int type, char *title, char *message, int dflt) { switch (do_dialog(type, - title == NULL ? (char_u *)"Question" : title, + title == NULL ? "Question" : title, message, - (char_u *)_("&Yes\n&No\nSave &All\n&Discard All\n&Cancel"), + _("&Yes\n&No\nSave &All\n&Discard All\n&Cancel"), dflt, NULL, false)) { case 1: return VIM_YES; diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 73147204a1..90084bde17 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -633,7 +633,7 @@ colnr_T vcol2col(win_T *const wp, const linenr_T lnum, const colnr_T vcol) // try to advance to the specified column char_u *line = ml_get_buf(wp->w_buffer, lnum, false); chartabsize_T cts; - init_chartabsize_arg(&cts, wp, lnum, 0, line, line); + init_chartabsize_arg(&cts, wp, lnum, 0, (char *)line, (char *)line); while (cts.cts_vcol < vcol && *cts.cts_ptr != NUL) { cts.cts_vcol += win_lbr_chartabsize(&cts, NULL); MB_PTR_ADV(cts.cts_ptr); @@ -666,7 +666,7 @@ void set_mouse_topline(win_T *wp) static colnr_T scroll_line_len(linenr_T lnum) { colnr_T col = 0; - char_u *line = ml_get(lnum); + char_u *line = (char_u *)ml_get(lnum); if (*line != NUL) { for (;;) { int numchar = win_chartabsize(curwin, (char *)line, col); @@ -771,7 +771,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col) // highlighting the second byte, not the ninth. linenr_T lnum = wp->w_cursor.lnum; - char_u *line = ml_get(lnum); + char_u *line = (char_u *)ml_get(lnum); char_u *ptr = line; char_u *ptr_end; char_u *ptr_row_offset = line; // Where we begin adjusting `ptr_end` diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 47ad000385..17b79e27c1 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2215,12 +2215,12 @@ static void find_start_of_word(pos_T *pos) int cclass; int col; - line = ml_get(pos->lnum); + line = (char_u *)ml_get(pos->lnum); cclass = get_mouse_class(line + pos->col); while (pos->col > 0) { col = pos->col - 1; - col -= utf_head_off(line, line + col); + col -= utf_head_off((char *)line, (char *)line + col); if (get_mouse_class(line + col) != cclass) { break; } @@ -2236,10 +2236,10 @@ static void find_end_of_word(pos_T *pos) int cclass; int col; - line = ml_get(pos->lnum); + line = (char_u *)ml_get(pos->lnum); if (*p_sel == 'e' && pos->col > 0) { pos->col--; - pos->col -= utf_head_off(line, line + pos->col); + pos->col -= utf_head_off((char *)line, (char *)line + pos->col); } cclass = get_mouse_class(line + pos->col); while (line[pos->col] != NUL) { @@ -2445,7 +2445,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char **text this_class = mb_get_class(ptr + col); } while (col > 0 && this_class != 0) { - prevcol = col - 1 - utf_head_off(ptr, ptr + col - 1); + prevcol = col - 1 - utf_head_off((char *)ptr, (char *)ptr + col - 1); prev_class = mb_get_class(ptr + prevcol); if (this_class != prev_class && (i == 0 diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 4f2b84d20f..adb071b754 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -272,7 +272,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) // Set "'[" and "']" marks. curbuf->b_op_start = oap->start; curbuf->b_op_end.lnum = oap->end.lnum; - curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); + curbuf->b_op_end.col = (colnr_T)strlen(ml_get(oap->end.lnum)); if (curbuf->b_op_end.col > 0) { curbuf->b_op_end.col--; } @@ -382,7 +382,7 @@ static void shift_block(oparg_T *oap, int amount) // TODO(vim): is passing bd.textstart for start of the line OK? chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, - bd.start_vcol, bd.textstart, bd.textstart); + bd.start_vcol, (char *)bd.textstart, (char *)bd.textstart); while (ascii_iswhite(*cts.cts_ptr)) { incr = lbr_chartabsize_adv(&cts); total += incr; @@ -448,7 +448,7 @@ static void shift_block(oparg_T *oap, int amount) chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, - non_white_col, bd.textstart, non_white); + non_white_col, (char *)bd.textstart, (char *)non_white); while (ascii_iswhite(*cts.cts_ptr)) { incr = lbr_chartabsize_adv(&cts); cts.cts_vcol += incr; @@ -477,7 +477,7 @@ static void shift_block(oparg_T *oap, int amount) verbatim_copy_width -= bd.start_char_vcols; } init_chartabsize_arg(&cts, curwin, 0, verbatim_copy_width, - bd.textstart, verbatim_copy_end); + (char *)bd.textstart, (char *)verbatim_copy_end); while (cts.cts_vcol < destination_col) { incr = lbr_chartabsize(&cts); if (cts.cts_vcol + incr > destination_col) { @@ -543,7 +543,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def continue; // OP_INSERT, line ends before block start } - oldp = ml_get(lnum); + oldp = (char_u *)ml_get(lnum); if (b_insert) { ts_val = bdp->start_char_vcols; @@ -572,7 +572,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def if (spaces > 0) { // avoid copying part of a multi-byte character - offset -= utf_head_off(oldp, oldp + offset); + offset -= utf_head_off((char *)oldp, (char *)oldp + offset); } if (spaces < 0) { // can happen when the cursor was moved spaces = 0; @@ -1014,7 +1014,7 @@ static int stuff_yank(int regname, char_u *p) yankreg_T *reg = get_yank_register(regname, YREG_YANK); if (is_append_register(regname) && reg->y_array != NULL) { char **pp = &(reg->y_array[reg->y_size - 1]); - char_u *lp = xmalloc(STRLEN(*pp) + STRLEN(p) + 1); + char_u *lp = xmalloc(strlen(*pp) + STRLEN(p) + 1); STRCPY(lp, *pp); // TODO(philix): use xstpcpy() in stuff_yank() STRCAT(lp, p); @@ -1513,7 +1513,7 @@ int op_delete(oparg_T *oap) && oap->line_count > 1 && oap->motion_force == NUL && oap->op_type == OP_DELETE) { - ptr = ml_get(oap->end.lnum) + oap->end.col; + ptr = (char_u *)ml_get(oap->end.lnum) + oap->end.col; if (*ptr != NUL) { ptr += oap->inclusive; } @@ -1617,7 +1617,7 @@ int op_delete(oparg_T *oap) // If we delete a TAB, it may be replaced by several characters. // Thus the number of characters may increase! n = bd.textlen - bd.startspaces - bd.endspaces; - oldp = ml_get(lnum); + oldp = (char_u *)ml_get(lnum); newp = (char_u *)xmalloc(STRLEN(oldp) - (size_t)n + 1); // copy up to deleted part memmove(newp, oldp, (size_t)bd.textcol); @@ -1662,7 +1662,7 @@ int op_delete(oparg_T *oap) beginline(0); // cursor in column 0 } - int old_len = (int)STRLEN(ml_get(curwin->w_cursor.lnum)); + int old_len = (int)strlen(ml_get(curwin->w_cursor.lnum)); truncate_line(false); // delete the rest of the line extmark_splice_cols(curbuf, @@ -1816,7 +1816,7 @@ setmarks: static void mb_adjust_opend(oparg_T *oap) { if (oap->inclusive) { - char *p = (char *)ml_get(oap->end.lnum); + char *p = ml_get(oap->end.lnum); oap->end.col += utf_cp_tail_off(p, p + oap->end.col); } } @@ -1990,7 +1990,7 @@ static int op_replace(oparg_T *oap, int c) if (oap->motion_type == kMTLineWise) { oap->start.col = 0; curwin->w_cursor.col = 0; - oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); + oap->end.col = (colnr_T)strlen(ml_get(oap->end.lnum)); if (oap->end.col) { oap->end.col--; } @@ -2104,7 +2104,7 @@ void op_tilde(oparg_T *oap) if (oap->motion_type == kMTLineWise) { oap->start.col = 0; pos.col = 0; - oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); + oap->end.col = (colnr_T)strlen(ml_get(oap->end.lnum)); if (oap->end.col) { oap->end.col--; } @@ -2281,7 +2281,7 @@ void op_insert(oparg_T *oap, long count1) // Get indent information ind_pre_col = (colnr_T)getwhitecols_curline(); ind_pre_vcol = get_indent(); - firstline = ml_get(oap->start.lnum) + bd.textcol; + firstline = (char_u *)ml_get(oap->start.lnum) + bd.textcol; if (oap->op_type == OP_APPEND) { firstline += bd.textlen; @@ -2413,7 +2413,7 @@ void op_insert(oparg_T *oap, long count1) * Subsequent calls to ml_get() flush the firstline data - take a * copy of the required string. */ - firstline = ml_get(oap->start.lnum); + firstline = (char_u *)ml_get(oap->start.lnum); const size_t len = STRLEN(firstline); colnr_T add = bd.textcol; colnr_T offset = 0; // offset when cursor was moved in insert mode @@ -2498,7 +2498,7 @@ int op_change(oparg_T *oap) || gchar_cursor() == NUL)) { coladvance_force(getviscol()); } - firstline = ml_get(oap->start.lnum); + firstline = (char_u *)ml_get(oap->start.lnum); pre_textlen = (long)STRLEN(firstline); pre_indent = (long)getwhitecols((char *)firstline); bd.textcol = curwin->w_cursor.col; @@ -2519,7 +2519,7 @@ int op_change(oparg_T *oap) && oap->start.lnum != oap->end.lnum && !got_int) { // Auto-indenting may have changed the indent. If the cursor was past // the indent, exclude that indent change from the inserted text. - firstline = ml_get(oap->start.lnum); + firstline = (char_u *)ml_get(oap->start.lnum); if (bd.textcol > (colnr_T)pre_indent) { long new_indent = (long)getwhitecols((char *)firstline); @@ -2547,7 +2547,7 @@ int op_change(oparg_T *oap) } else { vpos.coladd = 0; } - oldp = ml_get(linenr); + oldp = (char_u *)ml_get(linenr); newp = xmalloc(STRLEN(oldp) + (size_t)vpos.coladd + (size_t)ins_len + 1); // copy up to block start @@ -2691,14 +2691,14 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) break; case kMTLineWise: - reg->y_array[y_idx] = (char *)vim_strsave(ml_get(lnum)); + reg->y_array[y_idx] = xstrdup(ml_get(lnum)); break; case kMTCharWise: { colnr_T startcol = 0, endcol = MAXCOL; int is_oneChar = false; colnr_T cs, ce; - p = ml_get(lnum); + p = (char_u *)ml_get(lnum); bd.startspaces = 0; bd.endspaces = 0; @@ -2724,7 +2724,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) // Don't add space for double-wide // char; endcol will be on last byte // of multi-byte char. - && utf_head_off(p, p + endcol) == 0)) { + && utf_head_off((char *)p, (char *)p + endcol) == 0)) { if (oap->start.lnum == oap->end.lnum && oap->start.col == oap->end.col) { // Special case: inside a single char @@ -2776,8 +2776,8 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) // the new block, unless being Vi compatible. if (curr->y_type == kMTCharWise && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) { - pnew = xmalloc(STRLEN(curr->y_array[curr->y_size - 1]) - + STRLEN(reg->y_array[0]) + 1); + pnew = xmalloc(strlen(curr->y_array[curr->y_size - 1]) + + strlen(reg->y_array[0]) + 1); STRCPY(pnew, curr->y_array[--j]); STRCAT(pnew, reg->y_array[0]); xfree(curr->y_array[j]); @@ -2857,7 +2857,7 @@ static void yank_copy_line(yankreg_T *reg, struct block_def *bd, size_t y_idx, int s = bd->textlen + bd->endspaces; while (s > 0 && ascii_iswhite(*(bd->textstart + s - 1))) { - s = s - utf_head_off(bd->textstart, bd->textstart + s - 1) - 1; + s = s - utf_head_off((char *)bd->textstart, (char *)bd->textstart + s - 1) - 1; pnew--; } } @@ -3299,7 +3299,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) oldlen = STRLEN(oldp); chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, - oldp, oldp); + (char *)oldp, (char *)oldp); while (cts.cts_vcol < col && *cts.cts_ptr != NUL) { // Count a tab for what it's worth (if list mode not on) @@ -3320,7 +3320,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) bd.startspaces = incr - bd.endspaces; bd.textcol--; delcount = 1; - bd.textcol -= utf_head_off(oldp, oldp + bd.textcol); + bd.textcol -= utf_head_off((char *)oldp, (char *)oldp + bd.textcol); if (oldp[bd.textcol] != TAB) { /* Only a Tab can be split into spaces. Other * characters will have to be moved to after the @@ -3336,8 +3336,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // calculate number of spaces required to fill right side of // block spaces = y_width + 1; - init_chartabsize_arg(&cts, curwin, 0, 0, - (char_u *)y_array[i], (char_u *)y_array[i]); + init_chartabsize_arg(&cts, curwin, 0, 0, y_array[i], y_array[i]); for (int j = 0; j < yanklen; j++) { spaces -= lbr_chartabsize(&cts); cts.cts_ptr++; @@ -3483,7 +3482,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } else { totlen = (size_t)(count * yanklen); do { - oldp = ml_get(lnum); + oldp = (char_u *)ml_get(lnum); oldlen = STRLEN(oldp); if (lnum > start_lnum) { pos_T pos = { @@ -3510,7 +3509,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) ml_replace(lnum, (char *)newp, false); // compute the byte offset for the last character - first_byte_off = utf_head_off(newp, ptr - 1); + first_byte_off = utf_head_off((char *)newp, (char *)ptr - 1); // Place cursor on last putted char. if (lnum == curwin->w_cursor.lnum) { @@ -3554,7 +3553,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // First insert y_array[size - 1] in front of second line. // Then append y_array[0] to first line. lnum = new_cursor.lnum; - ptr = ml_get(lnum) + col; + ptr = (char_u *)ml_get(lnum) + col; totlen = STRLEN(y_array[y_size - 1]); newp = (char_u *)xmalloc((size_t)(STRLEN(ptr) + totlen + 1)); STRCPY(newp, y_array[y_size - 1]); @@ -3564,7 +3563,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) new_lnum++; xfree(newp); - oldp = ml_get(lnum); + oldp = (char_u *)ml_get(lnum); newp = (char_u *)xmalloc((size_t)col + (size_t)yanklen + 1); // copy first part of line memmove(newp, oldp, (size_t)col); @@ -3588,7 +3587,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (flags & PUT_FIXINDENT) { old_pos = curwin->w_cursor; curwin->w_cursor.lnum = lnum; - ptr = ml_get(lnum); + ptr = (char_u *)ml_get(lnum); if (cnt == count && i == y_size - 1) { lendiff = (int)STRLEN(ptr); } @@ -3668,8 +3667,8 @@ error: if (col > 1) { curbuf->b_op_end.col = col - 1; if (len > 0) { - curbuf->b_op_end.col -= utf_head_off((char_u *)y_array[y_size - 1], - (char_u *)y_array[y_size - 1] + len - 1); + curbuf->b_op_end.col -= utf_head_off(y_array[y_size - 1], + y_array[y_size - 1] + len - 1); } } else { curbuf->b_op_end.col = 0; @@ -3878,14 +3877,14 @@ void ex_display(exarg_T *eap) && (arg == NULL || vim_strchr((char *)arg, '.') != NULL) && !got_int && !message_filtered((char *)p)) { msg_puts("\n c \". "); - dis_msg(p, true); + dis_msg((char *)p, true); } // display last command line if (last_cmdline != NULL && (arg == NULL || vim_strchr((char *)arg, ':') != NULL) && !got_int && !message_filtered(last_cmdline)) { msg_puts("\n c \": "); - dis_msg((char_u *)last_cmdline, false); + dis_msg(last_cmdline, false); } // display current file name @@ -3893,7 +3892,7 @@ void ex_display(exarg_T *eap) && (arg == NULL || vim_strchr((char *)arg, '%') != NULL) && !got_int && !message_filtered(curbuf->b_fname)) { msg_puts("\n c \"% "); - dis_msg((char_u *)curbuf->b_fname, false); + dis_msg(curbuf->b_fname, false); } // display alternate file name @@ -3903,7 +3902,7 @@ void ex_display(exarg_T *eap) if (buflist_name_nr(0, &fname, &dummy) != FAIL && !message_filtered(fname)) { msg_puts("\n c \"# "); - dis_msg((char_u *)fname, false); + dis_msg(fname, false); } } @@ -3912,14 +3911,14 @@ void ex_display(exarg_T *eap) && (arg == NULL || vim_strchr((char *)arg, '/') != NULL) && !got_int && !message_filtered((char *)last_search_pat())) { msg_puts("\n c \"/ "); - dis_msg(last_search_pat(), false); + dis_msg((char *)last_search_pat(), false); } // display last used expression if (expr_line != NULL && (arg == NULL || vim_strchr((char *)arg, '=') != NULL) && !got_int && !message_filtered((char *)expr_line)) { msg_puts("\n c \"= "); - dis_msg(expr_line, false); + dis_msg((char *)expr_line, false); } } @@ -3927,7 +3926,7 @@ void ex_display(exarg_T *eap) /// truncate at end of screen line /// /// @param skip_esc if true, ignore trailing ESC -static void dis_msg(const char_u *p, bool skip_esc) +static void dis_msg(const char *p, bool skip_esc) FUNC_ATTR_NONNULL_ALL { int n; @@ -3936,12 +3935,12 @@ static void dis_msg(const char_u *p, bool skip_esc) n = Columns - 6; while (*p != NUL && !(*p == ESC && skip_esc && *(p + 1) == NUL) - && (n -= ptr2cells((char *)p)) >= 0) { - if ((l = utfc_ptr2len((char *)p)) > 1) { - msg_outtrans_len((char *)p, l); + && (n -= ptr2cells(p)) >= 0) { + if ((l = utfc_ptr2len(p)) > 1) { + msg_outtrans_len(p, l); p += l; } else { - msg_outtrans_len((char *)p++, 1); + msg_outtrans_len(p++, 1); } } os_breakcheck(); @@ -3958,11 +3957,11 @@ static void dis_msg(const char_u *p, bool skip_esc) /// @param include_space - whether to skip space following the comment leader /// @param[out] is_comment - whether the current line ends with an unclosed /// comment. -char_u *skip_comment(char_u *line, bool process, bool include_space, bool *is_comment) +char *skip_comment(char *line, bool process, bool include_space, bool *is_comment) { char *comment_flags = NULL; int lead_len; - int leader_offset = get_last_leader_offset((char *)line, &comment_flags); + int leader_offset = get_last_leader_offset(line, &comment_flags); *is_comment = false; if (leader_offset != -1) { @@ -3984,7 +3983,7 @@ char_u *skip_comment(char_u *line, bool process, bool include_space, bool *is_co return line; } - lead_len = get_leader_len((char *)line, &comment_flags, false, include_space); + lead_len = get_leader_len(line, &comment_flags, false, include_space); if (lead_len == 0) { return line; @@ -4022,11 +4021,11 @@ char_u *skip_comment(char_u *line, bool process, bool include_space, bool *is_co /// @return FAIL for failure, OK otherwise int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions, bool setmark) { - char_u *curr = NULL; - char_u *curr_start = NULL; - char_u *cend; - char_u *newp; - char_u *spaces; // number of spaces inserted before a line + char *curr = NULL; + char *curr_start = NULL; + char *cend; + char *newp; + char *spaces; // number of spaces inserted before a line int endcurr1 = NUL; int endcurr2 = NUL; int currsize = 0; // size of the current line @@ -4055,7 +4054,8 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions // Don't move anything, just compute the final line length // and setup the array of space strings lengths for (t = 0; t < (linenr_T)count; t++) { - curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); + curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); + curr = curr_start; if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // Set the '[ mark. curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; @@ -4065,8 +4065,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions // We don't want to remove the comment leader if the // previous line is not a comment. if (t > 0 && prev_was_comment) { - char_u *new_curr = skip_comment(curr, true, insert_space, - &prev_was_comment); + char *new_curr = skip_comment(curr, true, insert_space, &prev_was_comment); comments[t] = (int)(new_curr - curr); curr = new_curr; } else { @@ -4075,17 +4074,17 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions } if (insert_space && t > 0) { - curr = (char_u *)skipwhite((char *)curr); + curr = skipwhite(curr); if (*curr != NUL && *curr != ')' && sumsize != 0 && endcurr1 != TAB && (!has_format_option(FO_MBYTE_JOIN) - || (utf_ptr2char((char *)curr) < 0x100 && endcurr1 < 0x100)) + || (utf_ptr2char(curr) < 0x100 && endcurr1 < 0x100)) && (!has_format_option(FO_MBYTE_JOIN2) - || (utf_ptr2char((char *)curr) < 0x100 && !utf_eat_space(endcurr1)) + || (utf_ptr2char(curr) < 0x100 && !utf_eat_space(endcurr1)) || (endcurr1 < 0x100 - && !utf_eat_space(utf_ptr2char((char *)curr))))) { + && !utf_eat_space(utf_ptr2char(curr))))) { // don't add a space if the line is ending in a space if (endcurr1 == ' ') { endcurr1 = endcurr2; @@ -4112,10 +4111,10 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions if (insert_space && currsize > 0) { cend = curr + currsize; MB_PTR_BACK(curr, cend); - endcurr1 = utf_ptr2char((char *)cend); + endcurr1 = utf_ptr2char(cend); if (cend > curr) { MB_PTR_BACK(curr, cend); - endcurr2 = utf_ptr2char((char *)cend); + endcurr2 = utf_ptr2char(cend); } } line_breakcheck(); @@ -4129,7 +4128,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions col = sumsize - currsize - spaces[count - 1]; // allocate the space for the new line - newp = (char_u *)xmalloc((size_t)sumsize + 1); + newp = xmalloc((size_t)sumsize + 1); cend = newp + sumsize; *cend = 0; @@ -4165,17 +4164,18 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions break; } - curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); + curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); + curr = curr_start; if (remove_comments) { curr += comments[t - 1]; } if (insert_space && t > 1) { - curr = (char_u *)skipwhite((char *)curr); + curr = skipwhite(curr); } currsize = (int)STRLEN(curr); } - ml_replace(curwin->w_cursor.lnum, (char *)newp, false); + ml_replace(curwin->w_cursor.lnum, newp, false); if (setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // Set the '] mark. @@ -4234,11 +4234,11 @@ theend: static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool is_del) { int incr = 0; - char_u *pend; - char_u *pstart; - char_u *line; - char_u *prev_pstart; - char_u *prev_pend; + char *pend; + char *pstart; + char *line; + char *prev_pstart; + char *prev_pend; const int lbr_saved = curwin->w_p_lbr; // Avoid a problem with unwanted linebreaks in block mode. @@ -4271,11 +4271,11 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool bdp->pre_whitesp = 0; bdp->pre_whitesp_c = 0; } - prev_pstart = (char_u *)cts.cts_ptr; + prev_pstart = cts.cts_ptr; MB_PTR_ADV(cts.cts_ptr); } bdp->start_vcol = cts.cts_vcol; - pstart = (char_u *)cts.cts_ptr; + pstart = cts.cts_ptr; clear_chartabsize_arg(&cts); bdp->start_char_vcols = incr; @@ -4313,17 +4313,16 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool } } } else { - init_chartabsize_arg(&cts, curwin, lnum, bdp->end_vcol, - line, pend); + init_chartabsize_arg(&cts, curwin, lnum, bdp->end_vcol, line, pend); prev_pend = pend; while (cts.cts_vcol <= oap->end_vcol && *cts.cts_ptr != NUL) { // Count a tab for what it's worth (if list mode not on) - prev_pend = (char_u *)cts.cts_ptr; + prev_pend = cts.cts_ptr; incr = lbr_chartabsize_adv(&cts); cts.cts_vcol += incr; } bdp->end_vcol = cts.cts_vcol; - pend = (char_u *)cts.cts_ptr; + pend = cts.cts_ptr; clear_chartabsize_arg(&cts); if (bdp->end_vcol <= oap->end_vcol @@ -4356,7 +4355,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool bdp->textlen = (int)(pend - pstart); } bdp->textcol = (colnr_T)(pstart - line); - bdp->textstart = pstart; + bdp->textstart = (char_u *)pstart; curwin->w_p_lbr = lbr_saved; } @@ -4511,7 +4510,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } curwin->w_cursor = *pos; - ptr = ml_get(pos->lnum); + ptr = (char_u *)ml_get(pos->lnum); col = pos->col; if (*ptr == NUL || col + !!save_coladd >= (int)STRLEN(ptr)) { @@ -4523,14 +4522,14 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) if (do_bin) { while (col > 0 && ascii_isbdigit(ptr[col])) { col--; - col -= utf_head_off(ptr, ptr + col); + col -= utf_head_off((char *)ptr, (char *)ptr + col); } } if (do_hex) { while (col > 0 && ascii_isxdigit(ptr[col])) { col--; - col -= utf_head_off(ptr, ptr + col); + col -= utf_head_off((char *)ptr, (char *)ptr + col); } } if (do_bin @@ -4538,7 +4537,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) && !((col > 0 && (ptr[col] == 'X' || ptr[col] == 'x') && ptr[col - 1] == '0' - && !utf_head_off(ptr, ptr + col - 1) + && !utf_head_off((char *)ptr, (char *)ptr + col - 1) && ascii_isxdigit(ptr[col + 1])))) { // In case of binary/hexadecimal pattern overlap match, rescan @@ -4546,7 +4545,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) while (col > 0 && ascii_isdigit(ptr[col])) { col--; - col -= utf_head_off(ptr, ptr + col); + col -= utf_head_off((char *)ptr, (char *)ptr + col); } } @@ -4554,17 +4553,17 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) && col > 0 && (ptr[col] == 'X' || ptr[col] == 'x') && ptr[col - 1] == '0' - && !utf_head_off(ptr, ptr + col - 1) + && !utf_head_off((char *)ptr, (char *)ptr + col - 1) && ascii_isxdigit(ptr[col + 1])) || (do_bin && col > 0 && (ptr[col] == 'B' || ptr[col] == 'b') && ptr[col - 1] == '0' - && !utf_head_off(ptr, ptr + col - 1) + && !utf_head_off((char *)ptr, (char *)ptr + col - 1) && ascii_isbdigit(ptr[col + 1]))) { // Found hexadecimal or binary number, move to its start. col--; - col -= utf_head_off(ptr, ptr + col); + col -= utf_head_off((char *)ptr, (char *)ptr + col); } else { // Search forward and then backward to find the start of number. col = pos->col; @@ -4597,7 +4596,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } if (col > pos->col && ptr[col - 1] == '-' - && !utf_head_off(ptr, ptr + col - 1) + && !utf_head_off((char *)ptr, (char *)ptr + col - 1) && !do_unsigned) { negative = true; was_positive = false; @@ -4643,7 +4642,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) curwin->w_cursor.col = col; } else { if (col > 0 && ptr[col - 1] == '-' - && !utf_head_off(ptr, ptr + col - 1) + && !utf_head_off((char *)ptr, (char *)ptr + col - 1) && !visual && !do_unsigned) { // negative number @@ -5036,7 +5035,7 @@ static void finish_write_reg(int name, yankreg_T *reg, yankreg_T *old_y_previous /// store `str` in register `name` /// /// @see write_reg_contents_ex -void write_reg_contents(int name, const char_u *str, ssize_t len, int must_append) +void write_reg_contents(int name, const char *str, ssize_t len, int must_append) { write_reg_contents_ex(name, str, len, must_append, kMTUnknown, 0L); } @@ -5045,9 +5044,9 @@ void write_reg_contents_lst(int name, char **strings, bool must_append, MotionTy colnr_T block_len) { if (name == '/' || name == '=') { - char_u *s = (char_u *)strings[0]; + char *s = strings[0]; if (strings[0] == NULL) { - s = (char_u *)""; + s = ""; } else if (strings[1] != NULL) { emsg(_("E883: search pattern and expression register may not " "contain two or more lines")); @@ -5067,7 +5066,7 @@ void write_reg_contents_lst(int name, char **strings, bool must_append, MotionTy return; } - str_to_reg(reg, yank_type, (char *)strings, STRLEN((char_u *)strings), + str_to_reg(reg, yank_type, (char *)strings, STRLEN(strings), block_len, true); finish_write_reg(name, reg, old_y_previous); } @@ -5090,7 +5089,7 @@ void write_reg_contents_lst(int name, char **strings, bool must_append, MotionTy /// is an uppercase letter. /// @param yank_type The motion type (kMTUnknown to auto detect) /// @param block_len width of visual block -void write_reg_contents_ex(int name, const char_u *str, ssize_t len, bool must_append, +void write_reg_contents_ex(int name, const char *str, ssize_t len, bool must_append, MotionType yank_type, colnr_T block_len) { if (len < 0) { @@ -5099,7 +5098,7 @@ void write_reg_contents_ex(int name, const char_u *str, ssize_t len, bool must_a // Special case: '/' search pattern if (name == '/') { - set_last_search_pat(str, RE_SEARCH, true, true); + set_last_search_pat((char_u *)str, RE_SEARCH, true, true); return; } @@ -5107,14 +5106,14 @@ void write_reg_contents_ex(int name, const char_u *str, ssize_t len, bool must_a buf_T *buf; if (ascii_isdigit(*str)) { - int num = atoi((char *)str); + int num = atoi(str); buf = buflist_findnr(num); if (buf == NULL) { semsg(_(e_nobufnr), (int64_t)num); } } else { - buf = buflist_findnr(buflist_findpat((char *)str, (char *)str + STRLEN(str), + buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), true, false, false)); } if (buf == NULL) { @@ -5155,7 +5154,7 @@ void write_reg_contents_ex(int name, const char_u *str, ssize_t len, bool must_a if (!(reg = init_write_reg(name, &old_y_previous, must_append))) { return; } - str_to_reg(reg, yank_type, (char *)str, (size_t)len, block_len, false); + str_to_reg(reg, yank_type, str, (size_t)len, block_len, false); finish_write_reg(name, reg, old_y_previous); } @@ -5425,7 +5424,7 @@ void cursor_pos_info(dict_T *dict) len = (long)bd.textlen; break; case 'V': - s = ml_get(lnum); + s = (char_u *)ml_get(lnum); len = MAXCOL; break; case 'v': { @@ -5434,7 +5433,7 @@ void cursor_pos_info(dict_T *dict) colnr_T end_col = (lnum == max_pos.lnum) ? max_pos.col - start_col + 1 : MAXCOL; - s = ml_get(lnum) + start_col; + s = (char_u *)ml_get(lnum) + start_col; len = end_col; } break; @@ -5455,14 +5454,14 @@ void cursor_pos_info(dict_T *dict) word_count_cursor += word_count; char_count_cursor += char_count; byte_count_cursor = byte_count - + line_count_info(ml_get(lnum), &word_count_cursor, + + line_count_info((char_u *)ml_get(lnum), &word_count_cursor, &char_count_cursor, (varnumber_T)curwin->w_cursor.col + 1, eol_size); } } // Add to the running totals - byte_count += line_count_info(ml_get(lnum), &word_count, &char_count, + byte_count += line_count_info((char_u *)ml_get(lnum), &word_count, &char_count, (varnumber_T)MAXCOL, eol_size); } diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index c0d5616666..158c22efaf 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -821,10 +821,10 @@ int os_fchown(int fd, uv_uid_t owner, uv_gid_t group) /// Check if a path exists. /// /// @return `true` if `path` exists -bool os_path_exists(const char_u *path) +bool os_path_exists(const char *path) { uv_stat_t statbuf; - return os_stat((char *)path, &statbuf) == kLibuvSuccess; + return os_stat(path, &statbuf) == kLibuvSuccess; } /// Sets file access and modification times. diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 461a79c37b..35390e3dc1 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -503,7 +503,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // Move the file names to allocated memory. for (j = 0, i = 0; i < *num_file; i++) { // Require the files to exist. Helps when using /bin/sh - if (!(flags & EW_NOTFOUND) && !os_path_exists((char_u *)(*file)[i])) { + if (!(flags & EW_NOTFOUND) && !os_path_exists((*file)[i])) { continue; } @@ -1112,7 +1112,7 @@ static void out_data_append_to_screen(char *output, size_t *count, bool eof) goto end; } - (void)msg_outtrans_len_attr((char_u *)p, i, 0); + (void)msg_outtrans_len_attr(p, i, 0); p += i; } } @@ -1208,7 +1208,7 @@ static void read_input(DynamicBuffer *buf) { size_t written = 0, l = 0, len = 0; linenr_T lnum = curbuf->b_op_start.lnum; - char_u *lp = ml_get(lnum); + char_u *lp = (char_u *)ml_get(lnum); for (;;) { l = strlen((char *)lp + written); @@ -1240,7 +1240,7 @@ static void read_input(DynamicBuffer *buf) if (lnum > curbuf->b_op_end.lnum) { break; } - lp = ml_get(lnum); + lp = (char_u *)ml_get(lnum); written = 0; } else if (len > 0) { written += len; diff --git a/src/nvim/path.c b/src/nvim/path.c index a5cec6772f..5bbcbc7144 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -755,8 +755,9 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, backslash_halve((char *)buf + len + 1); } // add existing file or symbolic link - if ((flags & EW_ALLLINKS) ? os_fileinfo_link((char *)buf, &file_info) - : os_path_exists(buf)) { + if ((flags & EW_ALLLINKS) + ? os_fileinfo_link((char *)buf, &file_info) + : os_path_exists((char *)buf)) { addfile(gap, buf, flags); } } @@ -1461,7 +1462,7 @@ void addfile(garray_T *gap, char_u *f, int flags) if (!(flags & EW_NOTFOUND) && ((flags & EW_ALLLINKS) ? !os_fileinfo_link((char *)f, &file_info) - : !os_path_exists(f))) { + : !os_path_exists((char *)f))) { return; } @@ -1926,7 +1927,7 @@ void path_fix_case(char *name) while ((entry = (char *)os_scandir_next(&dir))) { // Only accept names that differ in case and are the same byte // length. TODO: accept different length name. - if (STRICMP(tail, entry) == 0 && STRLEN(tail) == STRLEN(entry)) { + if (STRICMP(tail, entry) == 0 && strlen(tail) == strlen(entry)) { char_u newname[MAXPATHL + 1]; // Verify the inode is equal. @@ -1951,7 +1952,7 @@ void path_fix_case(char *name) int after_pathsep(const char *b, const char *p) { return p > b && vim_ispathsep(p[-1]) - && utf_head_off((char_u *)b, (char_u *)p - 1) == 0; + && utf_head_off(b, p - 1) == 0; } /// Return true if file names "f1" and "f2" are in the same directory. @@ -2272,7 +2273,7 @@ int path_full_dir_name(char *directory, char *buffer, size_t len) int SUCCESS = 0; int retval = OK; - if (STRLEN(directory) == 0) { + if (strlen(directory) == 0) { return os_dirname((char_u *)buffer, len); } diff --git a/src/nvim/plines.c b/src/nvim/plines.c index cc730ba307..3ba09b45a1 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -149,7 +149,7 @@ int plines_win_col(win_T *wp, linenr_T lnum, long column) colnr_T col = 0; chartabsize_T cts; - init_chartabsize_arg(&cts, wp, lnum, 0, line, line); + init_chartabsize_arg(&cts, wp, lnum, 0, (char *)line, (char *)line); while (*cts.cts_ptr != NUL && --column >= 0) { cts.cts_vcol += win_lbr_chartabsize(&cts, NULL); MB_PTR_ADV(cts.cts_ptr); @@ -257,7 +257,7 @@ int linetabsize(char_u *s) int linetabsize_col(int startcol, char *s) { chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, 0, startcol, (char_u *)s, (char_u *)s); + init_chartabsize_arg(&cts, curwin, 0, startcol, s, s); while (*cts.cts_ptr != NUL) { cts.cts_vcol += lbr_chartabsize_adv(&cts); } @@ -275,7 +275,7 @@ int linetabsize_col(int startcol, char *s) unsigned int win_linetabsize(win_T *wp, linenr_T lnum, char_u *line, colnr_T len) { chartabsize_T cts; - init_chartabsize_arg(&cts, wp, lnum, 0, line, line); + init_chartabsize_arg(&cts, wp, lnum, 0, (char *)line, (char *)line); for (; *cts.cts_ptr != NUL && (len == MAXCOL || cts.cts_ptr < (char *)line + len); MB_PTR_ADV(cts.cts_ptr)) { cts.cts_vcol += win_lbr_chartabsize(&cts, NULL); @@ -288,14 +288,14 @@ unsigned int win_linetabsize(win_T *wp, linenr_T lnum, char_u *line, colnr_T len /// /// "line" is the start of the line, "ptr" is the first relevant character. /// When "lnum" is zero do not use text properties that insert text. -void init_chartabsize_arg(chartabsize_T *cts, win_T *wp, linenr_T lnum, colnr_T col, char_u *line, - char_u *ptr) +void init_chartabsize_arg(chartabsize_T *cts, win_T *wp, linenr_T lnum, colnr_T col, char *line, + char *ptr) { cts->cts_win = wp; cts->cts_lnum = lnum; cts->cts_vcol = col; - cts->cts_line = (char *)line; - cts->cts_ptr = (char *)ptr; + cts->cts_line = line; + cts->cts_ptr = ptr; cts->cts_cur_text_width = 0; // TODO(bfredl): actually lookup inline virtual text here cts->cts_has_virt_text = false; diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index f9c4892b91..f1fc48ef40 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -1250,7 +1250,7 @@ static int qf_parse_fmt_f(regmatch_T *rmp, int midx, qffields_T *fields, int pre // For separate filename patterns (%O, %P and %Q), the specified file // should exist. if (vim_strchr("OPQ", prefix) != NULL - && !os_path_exists((char_u *)fields->namebuf)) { + && !os_path_exists(fields->namebuf)) { return QF_FAIL; } @@ -1564,7 +1564,7 @@ static int qf_parse_dir_pfx(int idx, qffields_T *fields, qf_list_T *qfl) static int qf_parse_file_pfx(int idx, qffields_T *fields, qf_list_T *qfl, char *tail) { fields->valid = false; - if (*fields->namebuf == NUL || os_path_exists((char_u *)fields->namebuf)) { + if (*fields->namebuf == NUL || os_path_exists(fields->namebuf)) { if (*fields->namebuf && idx == 'P') { qfl->qf_currfile = qf_push_dir(fields->namebuf, &qfl->qf_file_stack, true); } else if (idx == 'Q') { @@ -2069,7 +2069,7 @@ static int qf_get_fnum(qf_list_T *qfl, char *directory, char *fname) // This should normally be true, but if make works without // "leaving directory"-messages we might have missed a // directory change. - if (!os_path_exists((char_u *)ptr)) { + if (!os_path_exists(ptr)) { xfree(ptr); directory = qf_guess_filepath(qfl, fname); if (directory) { @@ -2223,7 +2223,7 @@ static char *qf_guess_filepath(qf_list_T *qfl, char *filename) xfree(fullname); fullname = concat_fnames(ds_ptr->dirname, filename, true); - if (os_path_exists((char_u *)fullname)) { + if (os_path_exists(fullname)) { break; } @@ -3089,7 +3089,7 @@ static void qf_list_entry(qfline_T *qfp, int qf_idx, bool cursel) qf_fmt_text((fname != NULL || qfp->qf_lnum != 0) ? skipwhite(qfp->qf_text) : qfp->qf_text, (char *)tbuf, (int)tbuflen); - msg_prt_line(tbuf, false); + msg_prt_line((char *)tbuf, false); if (tbuf != IObuff) { xfree(tbuf); @@ -5075,7 +5075,7 @@ static void vgr_init_regmatch(regmmatch_T *regmatch, char *s) static void vgr_display_fname(char *fname) { msg_start(); - char *p = (char *)msg_strtrunc((char_u *)fname, true); + char *p = msg_strtrunc(fname, true); if (p == NULL) { msg_outtrans(fname); } else { diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index a52343e28b..f471f1c8e0 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1093,7 +1093,7 @@ void unref_extmatch(reg_extmatch_T *em) static int reg_prev_class(void) { if (rex.input > rex.line) { - return mb_get_class_tab(rex.input - 1 - utf_head_off(rex.line, rex.input - 1), + return mb_get_class_tab(rex.input - 1 - utf_head_off((char *)rex.line, (char *)rex.input - 1), rex.reg_buf->b_chartab); } return -1; diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c index 88f0d781af..b951df69d6 100644 --- a/src/nvim/regexp_bt.c +++ b/src/nvim/regexp_bt.c @@ -4765,8 +4765,8 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) reg_getline(rp->rs_un.regsave.rs_u.pos.lnum); rp->rs_un.regsave.rs_u.pos.col -= - utf_head_off(line, - line + rp->rs_un.regsave.rs_u.pos.col - 1) + utf_head_off((char *)line, + (char *)line + rp->rs_un.regsave.rs_u.pos.col - 1) + 1; } } else { diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index d4db710d93..e1327ce155 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -5595,7 +5595,7 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T } if ((int)(rex.input - rex.line) >= state->val) { rex.input -= state->val; - rex.input -= utf_head_off(rex.line, rex.input); + rex.input -= utf_head_off((char *)rex.line, (char *)rex.input); } else { rex.input = rex.line; } diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index e85167f8fd..a38f743081 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -1822,7 +1822,7 @@ static void cmd_source_buffer(const exarg_T *const eap) if (ga.ga_len > 400) { ga_set_growsize(&ga, MIN(ga.ga_len, 8000)); } - ga_concat(&ga, (char *)ml_get(curr_lnum)); + ga_concat(&ga, ml_get(curr_lnum)); ga_append(&ga, NL); } ((char *)ga.ga_data)[ga.ga_len - 1] = NUL; diff --git a/src/nvim/search.c b/src/nvim/search.c index e995081df8..d7f8d4e1cd 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -853,7 +853,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, pos->col--; if (pos->lnum <= buf->b_ml.ml_line_count) { ptr = ml_get_buf(buf, pos->lnum, false); - pos->col -= utf_head_off(ptr, ptr + pos->col); + pos->col -= utf_head_off((char *)ptr, (char *)ptr + pos->col); } } if (end_pos != NULL) { @@ -1250,7 +1250,7 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, memmove(msgbuf + STRLEN(p) + 1, off_buf, off_len); } - trunc = msg_strtrunc(msgbuf, true); + trunc = (char_u *)msg_strtrunc((char *)msgbuf, true); if (trunc != NULL) { xfree(msgbuf); msgbuf = trunc; @@ -1589,7 +1589,7 @@ int searchc(cmdarg_T *cap, int t_cmd) if (col == 0) { return FAIL; } - col -= utf_head_off(p, p + col - 1) + 1; + col -= utf_head_off((char *)p, (char *)p + col - 1) + 1; } if (lastc_bytelen == 1) { if (p[col] == c && stop) { @@ -1610,7 +1610,7 @@ int searchc(cmdarg_T *cap, int t_cmd) col += lastc_bytelen - 1; } else { // To previous char, which may be multi-byte. - col -= utf_head_off(p, p + col); + col -= utf_head_off((char *)p, (char *)p + col); } } curwin->w_cursor.col = col; @@ -1641,7 +1641,7 @@ static bool check_prevcol(char_u *linep, int col, int ch, int *prevcol) { col--; if (col > 0) { - col -= utf_head_off(linep, linep + col); + col -= utf_head_off((char *)linep, (char *)linep + col); } if (prevcol) { *prevcol = col; @@ -1664,7 +1664,7 @@ static bool find_rawstring_end(char_u *linep, pos_T *startpos, pos_T *endpos) char_u *delim_copy = vim_strnsave(linep + startpos->col + 1, delim_len); bool found = false; for (lnum = startpos->lnum; lnum <= endpos->lnum; lnum++) { - char_u *line = ml_get(lnum); + char_u *line = (char_u *)ml_get(lnum); for (p = line + (lnum == startpos->lnum ? startpos->col + 1 : 0); *p; p++) { if (lnum == endpos->lnum && (colnr_T)(p - line) >= endpos->col) { @@ -1768,7 +1768,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) pos = curwin->w_cursor; pos.coladd = 0; - char_u *linep = ml_get(pos.lnum); // pointer to current line + char_u *linep = (char_u *)ml_get(pos.lnum); // pointer to current line // vi compatible matching bool cpo_match = (vim_strchr(p_cpo, CPO_MATCH) != NULL); @@ -1923,7 +1923,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) break; } pos.lnum += hash_dir; - linep = ml_get(pos.lnum); + linep = (char_u *)ml_get(pos.lnum); line_breakcheck(); // check for CTRL-C typed ptr = (char_u *)skipwhite((char *)linep); if (*ptr != '#') { @@ -2003,7 +2003,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) break; } - linep = ml_get(pos.lnum); + linep = (char_u *)ml_get(pos.lnum); pos.col = (colnr_T)STRLEN(linep); // pos.col on trailing NUL do_quotes = -1; line_breakcheck(); @@ -2018,7 +2018,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) } } else { pos.col--; - pos.col -= utf_head_off(linep, linep + pos.col); + pos.col -= utf_head_off((char *)linep, (char *)linep + pos.col); } } else { // forward search if (linep[pos.col] == NUL @@ -2038,7 +2038,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) break; } - linep = ml_get(pos.lnum); + linep = (char_u *)ml_get(pos.lnum); pos.col = 0; do_quotes = -1; line_breakcheck(); @@ -2088,7 +2088,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) match_pos = pos; match_pos.col--; } - linep = ml_get(pos.lnum); // may have been released + linep = (char_u *)ml_get(pos.lnum); // may have been released } } else if (linep[pos.col - 1] == '/' && linep[pos.col] == '*' @@ -2158,7 +2158,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) } } if (pos.lnum > 1) { - ptr = ml_get(pos.lnum - 1); + ptr = (char_u *)ml_get(pos.lnum - 1); if (*ptr && *(ptr + STRLEN(ptr) - 1) == '\\') { do_quotes = 1; if (start_in_quotes == kNone) { @@ -2172,7 +2172,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) } // ml_get() only keeps one line, need to get linep again - linep = ml_get(pos.lnum); + linep = (char_u *)ml_get(pos.lnum); } } } @@ -2648,7 +2648,7 @@ int linewhite(linenr_T lnum) { char_u *p; - p = (char_u *)skipwhite((char *)ml_get(lnum)); + p = (char_u *)skipwhite(ml_get(lnum)); return *p == NUL; } @@ -3488,7 +3488,7 @@ void f_matchfuzzypos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// mark. static char_u *get_line_and_copy(linenr_T lnum, char_u *buf) { - char_u *line = ml_get(lnum); + char_u *line = (char_u *)ml_get(lnum); STRLCPY(buf, line, LSIZE); return buf; } @@ -3625,7 +3625,7 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo msg_putchar('\n'); // cursor below last one */ if (!got_int) { // don't display if 'q' typed at "--more--" // message - msg_home_replace_hl(new_fname); + msg_home_replace_hl((char *)new_fname); msg_puts(_(" (includes previously listed match)")); prev_fname = NULL; } @@ -3655,7 +3655,7 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo for (i = 0; i < depth_displayed; i++) { msg_puts(" "); } - msg_home_replace(files[depth_displayed].name); + msg_home_replace((char *)files[depth_displayed].name); msg_puts(" -->\n"); } if (!got_int) { // don't display if 'q' typed @@ -3937,7 +3937,7 @@ search_line: } if (!got_int) { // don't display if 'q' typed // at "--more--" message - msg_home_replace_hl(curr_fname); + msg_home_replace_hl((char *)curr_fname); } prev_fname = curr_fname; } @@ -4146,7 +4146,7 @@ static void show_pat_in_path(char_u *line, int type, bool did_show, int action, msg_puts_attr((const char *)IObuff, HL_ATTR(HLF_N)); msg_puts(" "); } - msg_prt_line(line, false); + msg_prt_line((char *)line, false); ui_flush(); // show one line at a time // Definition continues until line that doesn't end with '\' @@ -4163,7 +4163,7 @@ static void show_pat_in_path(char_u *line, int type, bool did_show, int action, if (++*lnum > curbuf->b_ml.ml_line_count) { break; } - line = ml_get(*lnum); + line = (char_u *)ml_get(*lnum); } msg_putchar('\n'); } diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 1259736e0e..d8bc4b22c2 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -571,7 +571,7 @@ static void find_word(matchinf_T *mip, int mode) arridx = endidx[endidxcnt]; wlen = endlen[endidxcnt]; - if (utf_head_off(ptr, ptr + wlen) > 0) { + if (utf_head_off((char *)ptr, (char *)ptr + wlen) > 0) { continue; // not at first byte of character } if (spell_iswordp(ptr + wlen, mip->mi_win)) { @@ -2479,7 +2479,7 @@ bool check_need_cap(linenr_T lnum, colnr_T col) if (lnum == 1) { need_cap = true; } else { - line = ml_get(lnum - 1); + line = (char_u *)ml_get(lnum - 1); if (*skipwhite((char *)line) == NUL) { need_cap = true; } else { diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 0f8034312e..c472cac27d 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -3197,7 +3197,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) _("line %6d, word %6ld - %s"), lnum, spin->si_foldwcount + spin->si_keepwcount, w); msg_start(); - msg_outtrans_long_attr(message, 0); + msg_outtrans_long_attr((char *)message, 0); msg_clr_eos(); msg_didout = false; msg_col = 0; @@ -5339,7 +5339,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool } else { // Check for overwriting before doing things that may take a lot of // time. - if (!over_write && os_path_exists((char_u *)wfname)) { + if (!over_write && os_path_exists(wfname)) { emsg(_(e_exists)); goto theend; } @@ -5389,7 +5389,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool spin.si_region = 1 << i; vim_snprintf((char *)fname, MAXPATHL, "%s.aff", innames[i]); - if (os_path_exists(fname)) { + if (os_path_exists((char *)fname)) { // Read the .aff file. Will init "spin->si_conv" based on the // "SET" line. afile[i] = spell_read_aff(&spin, fname); @@ -5500,7 +5500,7 @@ static void spell_message(const spellinfo_T *spin, char *str) // ":[count]spellrare {word}" void ex_spell(exarg_T *eap) { - spell_add_word((char_u *)eap->arg, (int)STRLEN(eap->arg), + spell_add_word((char_u *)eap->arg, (int)strlen(eap->arg), eap->cmdidx == CMD_spellwrong ? SPELL_ADD_BAD : eap->cmdidx == CMD_spellrare ? SPELL_ADD_RARE : SPELL_ADD_GOOD, eap->forceit ? 0 : (int)eap->line2, @@ -5810,7 +5810,7 @@ static int write_spell_prefcond(FILE *fd, garray_T *gap, size_t *fwv) // : char *p = ((char **)gap->ga_data)[i]; if (p != NULL) { - size_t len = STRLEN(p); + size_t len = strlen(p); if (fd != NULL) { assert(len <= INT_MAX); fputc((int)len, fd); @@ -5873,7 +5873,7 @@ static void set_map_str(slang_T *lp, char_u *map) utf_char2bytes(headc, b + cl + 1); b[cl + 1 + headcl] = NUL; hash = hash_hash((char_u *)b); - hi = hash_lookup(&lp->sl_map_hash, (const char *)b, STRLEN(b), hash); + hi = hash_lookup(&lp->sl_map_hash, (const char *)b, strlen(b), hash); if (HASHITEM_EMPTY(hi)) { hash_add_item(&lp->sl_map_hash, hi, (char_u *)b, hash); } else { diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index f055cc9b0e..1319894226 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -610,7 +610,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) * Skip lines that end in a backslash. */ for (; start_lnum > 1; start_lnum--) { - line = ml_get(start_lnum - 1); + line = (char_u *)ml_get(start_lnum - 1); if (*line == NUL || *(line + STRLEN(line) - 1) != '\\') { break; } @@ -1711,7 +1711,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con const char_u *cur_pos = line + current_col; if (vim_iswordp_buf(cur_pos, syn_buf) && (current_col == 0 - || !vim_iswordp_buf(cur_pos - 1 - utf_head_off(line, cur_pos - 1), + || !vim_iswordp_buf(cur_pos - 1 - utf_head_off((char *)line, (char *)cur_pos - 1), syn_buf))) { syn_id = check_keyword_id(line, (int)current_col, &endcol, &flags, &next_list, cur_si, &cchar); diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 5270412382..4fd99b058b 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -742,7 +742,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char (int)(tagp.tagkind_end - tagp.tagkind)); } msg_advance(13); - msg_outtrans_len_attr(tagp.tagname, + msg_outtrans_len_attr((char *)tagp.tagname, (int)(tagp.tagname_end - tagp.tagname), HL_ATTR(HLF_T)); msg_putchar(' '); @@ -1230,7 +1230,7 @@ static int find_tagfunc_tags(char_u *pat, garray_T *ga, int *match_count, int fl continue; } - len += STRLEN(tv->vval.v_string) + 1; // Space for "\tVALUE" + len += strlen(tv->vval.v_string) + 1; // Space for "\tVALUE" if (!STRCMP(dict_key, "name")) { res_name = (char_u *)tv->vval.v_string; continue; @@ -1497,7 +1497,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc curbuf->b_help = false; } - orgpat.len = (int)STRLEN(pat); + orgpat.len = (int)strlen(pat); if (curbuf->b_help) { // When "@ab" is specified use only the "ab" language, otherwise // search all languages. @@ -1550,7 +1550,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc if ((flags & TAG_KEEP_LANG) && help_lang_find == NULL && curbuf->b_fname != NULL - && (i = (int)STRLEN(curbuf->b_fname)) > 4 + && (i = (int)strlen(curbuf->b_fname)) > 4 && STRICMP(curbuf->b_fname + i - 4, ".txt") == 0) { is_txt = true; } @@ -1595,7 +1595,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc if ((flags & TAG_KEEP_LANG) && help_lang_find == NULL && curbuf->b_fname != NULL - && (i = (int)STRLEN(curbuf->b_fname)) > 4 + && (i = (int)strlen(curbuf->b_fname)) > 4 && curbuf->b_fname[i - 1] == 'x' && curbuf->b_fname[i - 4] == '.' && STRNICMP(curbuf->b_fname + i - 3, help_lang, 2) == 0) { @@ -2174,7 +2174,7 @@ parse_line: hash = hash_hash((char_u *)mfp); } hi = hash_lookup(&ht_match[mtt], (const char *)mfp, - STRLEN(mfp), hash); + strlen(mfp), hash); if (HASHITEM_EMPTY(hi)) { hash_add_item(&ht_match[mtt], hi, (char_u *)mfp, hash); ga_grow(&ga_match[mtt], 1); @@ -2713,7 +2713,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) * file. Also accept a file name for which there is a matching BufReadCmd * autocommand event (e.g., http://sys/file). */ - if (!os_path_exists(fname) + if (!os_path_exists((char *)fname) && !has_autocmd(EVENT_BUFREADCMD, (char *)fname, NULL)) { retval = NOTAGFILE; @@ -3168,7 +3168,7 @@ static int add_tag_field(dict_T *dict, const char *field_name, const char *start char_u *buf = xmalloc(MAXPATHL); if (start != NULL) { if (end == NULL) { - end = start + STRLEN(start); + end = start + strlen(start); while (end > start && (end[-1] == '\r' || end[-1] == '\n')) { end--; } @@ -3180,7 +3180,7 @@ static int add_tag_field(dict_T *dict, const char *field_name, const char *start STRLCPY(buf, start, len + 1); } buf[len] = NUL; - retval = tv_dict_add_str(dict, field_name, STRLEN(field_name), + retval = tv_dict_add_str(dict, field_name, strlen(field_name), (const char *)buf); xfree(buf); return retval; diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 125146f712..5ded0c9ab2 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -470,7 +470,7 @@ static int fmt_check_par(linenr_T lnum, int *leader_len, char_u **leader_flags, char_u *flags = NULL; // init for GCC char_u *ptr; - ptr = ml_get(lnum); + ptr = (char_u *)ml_get(lnum); if (do_comments) { *leader_len = get_leader_len((char *)ptr, (char **)leader_flags, false, true); } else { @@ -493,7 +493,7 @@ static int fmt_check_par(linenr_T lnum, int *leader_len, char_u **leader_flags, /// @return true if line "lnum" ends in a white character. static bool ends_in_white(linenr_T lnum) { - char_u *s = ml_get(lnum); + char_u *s = (char_u *)ml_get(lnum); size_t l; if (*s == NUL) { @@ -552,9 +552,9 @@ static bool same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, i // Get current line and next line, compare the leaders. // The first line has to be saved, only one line can be locked at a time. - line1 = vim_strsave(ml_get(lnum)); + line1 = vim_strsave((char_u *)ml_get(lnum)); for (idx1 = 0; ascii_iswhite(line1[idx1]); idx1++) {} - line2 = ml_get(lnum + 1); + line2 = (char_u *)ml_get(lnum + 1); for (idx2 = 0; idx2 < leader2_len; idx2++) { if (!ascii_iswhite(line2[idx2])) { if (line1[idx1++] != line2[idx2]) { @@ -586,7 +586,7 @@ static bool paragraph_start(linenr_T lnum) if (lnum <= 1) { return true; // start of the file } - p = ml_get(lnum - 1); + p = (char_u *)ml_get(lnum - 1); if (*p == NUL) { return true; // after empty line } diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 02174edeb1..a8f4cc7aeb 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -213,13 +213,13 @@ bool findpar(bool *pincl, int dir, long count, int what, bool both) } curwin->w_cursor.lnum = curr; if (curr == curbuf->b_ml.ml_line_count && what != '}') { - char_u *line = ml_get(curr); + char_u *line = (char_u *)ml_get(curr); // Put the cursor on the last character in the last line and make the // motion inclusive. if ((curwin->w_cursor.col = (colnr_T)STRLEN(line)) != 0) { curwin->w_cursor.col--; - curwin->w_cursor.col -= utf_head_off(line, line + curwin->w_cursor.col); + curwin->w_cursor.col -= utf_head_off((char *)line, (char *)line + curwin->w_cursor.col); *pincl = true; } } else { @@ -260,7 +260,7 @@ bool startPS(linenr_T lnum, int para, bool both) { char_u *s; - s = ml_get(lnum); + s = (char_u *)ml_get(lnum); if (*s == para || *s == '\f' || (both && *s == '}')) { return true; } @@ -1467,7 +1467,7 @@ static int find_prev_quote(char_u *line, int col_start, int quotechar, char_u *e while (col_start > 0) { col_start--; - col_start -= utf_head_off(line, line + col_start); + col_start -= utf_head_off((char *)line, (char *)line + col_start); n = 0; if (escape != NULL) { while (col_start - n > 0 && vim_strchr((char *)escape, diff --git a/src/nvim/tui/terminfo.c b/src/nvim/tui/terminfo.c index ce48059b94..229e340dc3 100644 --- a/src/nvim/tui/terminfo.c +++ b/src/nvim/tui/terminfo.c @@ -189,7 +189,7 @@ void terminfo_info_msg(const unibi_term *const ut) msg_printf_attr(0, " %-25s %-10s = ", unibi_name_str(i), unibi_short_name_str(i)); // Most of these strings will contain escape sequences. - msg_outtrans_special((char_u *)s, false, 0); + msg_outtrans_special(s, false, 0); msg_putchar('\n'); } } @@ -216,7 +216,7 @@ void terminfo_info_msg(const unibi_term *const ut) msg_puts("Extended string capabilities:\n"); for (size_t i = 0; i < unibi_count_ext_str(ut); i++) { msg_printf_attr(0, " %-25s = ", unibi_get_ext_str_name(ut, i)); - msg_outtrans_special((char_u *)unibi_get_ext_str(ut, i), false, 0); + msg_outtrans_special(unibi_get_ext_str(ut, i), false, 0); msg_putchar('\n'); } } diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 97a925f3ad..5f086df4e9 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -651,7 +651,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) char fname_buf[MAXPATHL]; // Expand symlink in the file name, so that we put the undo file with the // actual file instead of with the symlink. - if (resolve_symlink((const char_u *)ffname, (char_u *)fname_buf) == OK) { + if (resolve_symlink(ffname, fname_buf) == OK) { ffname = fname_buf; } #endif @@ -713,7 +713,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) // When reading check if the file exists. if (undo_file_name != NULL - && (!reading || os_path_exists((char_u *)undo_file_name))) { + && (!reading || os_path_exists(undo_file_name))) { break; } XFREE_CLEAR(undo_file_name); @@ -1177,7 +1177,7 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, // If the undo file already exists, verify that it actually is an undo // file, and delete it. - if (os_path_exists((char_u *)file_name)) { + if (os_path_exists(file_name)) { if (name == NULL || !forceit) { // Check we can read it and it's an undo file. fd = os_open(file_name, O_RDONLY, 0); diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 5b2101587f..9cc9fb5588 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -531,7 +531,7 @@ static void uc_list(char *name, size_t name_len) } } - msg_outtrans_special((char_u *)cmd->uc_rep, false, + msg_outtrans_special(cmd->uc_rep, false, name_len == 0 ? Columns - 47 : 0); if (p_verbose > 0) { last_set_msg(cmd->uc_script_ctx); diff --git a/src/nvim/window.c b/src/nvim/window.c index 74ea1172ee..c11484d1b8 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6578,7 +6578,7 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u * Go one char back to ":" before "//" even when ':' is not in 'isfname'. */ while ((char_u *)ptr > line) { - if ((len = (size_t)(utf_head_off(line, (char_u *)ptr - 1))) > 0) { + if ((len = (size_t)(utf_head_off((char *)line, ptr - 1))) > 0) { ptr -= len + 1; } else if (vim_isfilec(ptr[-1]) || ((options & FNAME_HYP) && path_is_url(ptr - 1))) { ptr--; -- cgit From 933c80e8f9d7ff4ab634c14d370440702c7c8ed7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 31 Aug 2022 21:14:14 +0800 Subject: refactor(mappings)!: mapblock_fill_dict() use API Dictionary (#20020) This introduces the following breaking changes: - nvim_get_keymap now always returns a LuaRef object as "callback" for a Lua mapping regardless of how it is called. The LuaRef object can be called from Lua and Vim script, but is lost over RPC. - maparg() now returns a Funcref instead of a ref number as "callback" for a Lua mapping. The Funcref can be called from Lua and Vim script, but is lost over RPC. This may also make nvim_get_keymap faster, but make maparg() slower. --- src/nvim/api/buffer.c | 4 +-- src/nvim/api/vim.c | 4 +-- src/nvim/mapping.c | 87 ++++++++++++++++++++++----------------------------- 3 files changed, 41 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 199650fc55..16f574f46d 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -945,7 +945,7 @@ Integer nvim_buf_get_changedtick(Buffer buffer, Error *err) /// @param[out] err Error details, if any /// @returns Array of |maparg()|-like dictionaries describing mappings. /// The "buffer" key holds the associated buffer handle. -ArrayOf(Dictionary) nvim_buf_get_keymap(uint64_t channel_id, Buffer buffer, String mode, Error *err) +ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err) FUNC_API_SINCE(3) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -954,7 +954,7 @@ ArrayOf(Dictionary) nvim_buf_get_keymap(uint64_t channel_id, Buffer buffer, Stri return (Array)ARRAY_DICT_INIT; } - return keymap_array(mode, buf, channel_id == LUA_INTERNAL_CALL); + return keymap_array(mode, buf); } /// Sets a buffer-local |mapping| for the given mode. diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index a1721d433f..9e1f2dd631 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1421,10 +1421,10 @@ Dictionary nvim_get_mode(void) /// @param mode Mode short-name ("n", "i", "v", ...) /// @returns Array of |maparg()|-like dictionaries describing mappings. /// The "buffer" key is always zero. -ArrayOf(Dictionary) nvim_get_keymap(uint64_t channel_id, String mode) +ArrayOf(Dictionary) nvim_get_keymap(String mode) FUNC_API_SINCE(3) { - return keymap_array(mode, NULL, channel_id == LUA_INTERNAL_CALL); + return keymap_array(mode, NULL); } /// Sets a global |mapping| for the given mode. diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 333fb847f6..caa040e79b 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1989,16 +1989,18 @@ void f_hasmapto(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } -/// Fill a dictionary with all applicable maparg() like dictionaries +/// Fill a Dictionary with all applicable maparg() like dictionaries /// -/// @param dict The dictionary to be filled /// @param mp The maphash that contains the mapping information /// @param buffer_value The "buffer" value /// @param compatible True for compatible with old maparg() dict -static void mapblock_fill_dict(dict_T *const dict, const mapblock_T *const mp, - const char *lhsrawalt, long buffer_value, bool compatible) - FUNC_ATTR_NONNULL_ARG(1, 2) +/// +/// @return A Dictionary. +static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhsrawalt, + const long buffer_value, const bool compatible) + FUNC_ATTR_NONNULL_ARG(1) { + Dictionary dict = ARRAY_DICT_INIT; char *const lhs = str2special_save((const char *)mp->m_keys, compatible, !compatible); char *const mapmode = map_mode_to_chars(mp->m_mode); @@ -2015,37 +2017,35 @@ static void mapblock_fill_dict(dict_T *const dict, const mapblock_T *const mp, } if (mp->m_luaref != LUA_NOREF) { - tv_dict_add_nr(dict, S_LEN("callback"), mp->m_luaref); + PUT(dict, "callback", LUAREF_OBJ(api_new_luaref(mp->m_luaref))); } else { - if (compatible) { - tv_dict_add_str(dict, S_LEN("rhs"), (const char *)mp->m_orig_str); - } else { - tv_dict_add_allocated_str(dict, S_LEN("rhs"), - str2special_save((const char *)mp->m_str, false, - true)); - } + PUT(dict, "rhs", STRING_OBJ(compatible + ? cstr_to_string(mp->m_orig_str) + : cstr_as_string(str2special_save(mp->m_str, false, true)))); } if (mp->m_desc != NULL) { - tv_dict_add_allocated_str(dict, S_LEN("desc"), xstrdup(mp->m_desc)); + PUT(dict, "desc", STRING_OBJ(cstr_to_string(mp->m_desc))); } - tv_dict_add_allocated_str(dict, S_LEN("lhs"), lhs); - tv_dict_add_str(dict, S_LEN("lhsraw"), (const char *)mp->m_keys); + PUT(dict, "lhs", STRING_OBJ(cstr_as_string(lhs))); + PUT(dict, "lhsraw", STRING_OBJ(cstr_to_string((const char *)mp->m_keys))); if (lhsrawalt != NULL) { // Also add the value for the simplified entry. - tv_dict_add_str(dict, S_LEN("lhsrawalt"), lhsrawalt); - } - tv_dict_add_nr(dict, S_LEN("noremap"), noremap_value); - tv_dict_add_nr(dict, S_LEN("script"), mp->m_noremap == REMAP_SCRIPT ? 1 : 0); - tv_dict_add_nr(dict, S_LEN("expr"), mp->m_expr ? 1 : 0); - tv_dict_add_nr(dict, S_LEN("silent"), mp->m_silent ? 1 : 0); - tv_dict_add_nr(dict, S_LEN("sid"), (varnumber_T)mp->m_script_ctx.sc_sid); - tv_dict_add_nr(dict, S_LEN("lnum"), (varnumber_T)mp->m_script_ctx.sc_lnum); - tv_dict_add_nr(dict, S_LEN("buffer"), (varnumber_T)buffer_value); - tv_dict_add_nr(dict, S_LEN("nowait"), mp->m_nowait ? 1 : 0); + PUT(dict, "lhsrawalt", STRING_OBJ(cstr_to_string(lhsrawalt))); + } + PUT(dict, "noremap", INTEGER_OBJ(noremap_value)); + PUT(dict, "script", INTEGER_OBJ(mp->m_noremap == REMAP_SCRIPT ? 1 : 0)); + PUT(dict, "expr", INTEGER_OBJ(mp->m_expr ? 1 : 0)); + PUT(dict, "silent", INTEGER_OBJ(mp->m_silent ? 1 : 0)); + PUT(dict, "sid", INTEGER_OBJ((varnumber_T)mp->m_script_ctx.sc_sid)); + PUT(dict, "lnum", INTEGER_OBJ((varnumber_T)mp->m_script_ctx.sc_lnum)); + PUT(dict, "buffer", INTEGER_OBJ((varnumber_T)buffer_value)); + PUT(dict, "nowait", INTEGER_OBJ(mp->m_nowait ? 1 : 0)); if (mp->m_replace_keycodes) { - tv_dict_add_nr(dict, S_LEN("replace_keycodes"), 1); + PUT(dict, "replace_keycodes", INTEGER_OBJ(1)); } - tv_dict_add_allocated_str(dict, S_LEN("mode"), mapmode); + PUT(dict, "mode", STRING_OBJ(cstr_as_string(mapmode))); + + return dict; } static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) @@ -2114,11 +2114,14 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) rettv->vval.v_string = nlua_funcref_str(mp->m_luaref); } } else { + // Return a dictionary. tv_dict_alloc_ret(rettv); if (mp != NULL && (rhs != NULL || rhs_lua != LUA_NOREF)) { - // Return a dictionary. - mapblock_fill_dict(rettv->vval.v_dict, mp, did_simplify ? (char *)keys_simplified : NULL, - buffer_local, true); + Dictionary dict = mapblock_fill_dict(mp, + did_simplify ? (char *)keys_simplified : NULL, + buffer_local, true); + (void)object_to_vim(DICTIONARY_OBJ(dict), rettv, NULL); + api_free_dictionary(dict); } } @@ -2599,12 +2602,10 @@ fail_and_free: /// /// @param mode The abbreviation for the mode /// @param buf The buffer to get the mapping array. NULL for global -/// @param from_lua Whether it is called from internal Lua api. /// @returns Array of maparg()-like dictionaries describing mappings -ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf, bool from_lua) +ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf) { Array mappings = ARRAY_DICT_INIT; - dict_T *const dict = tv_dict_alloc(); // Convert the string mode to the integer mode // that is stored within each mapblock @@ -2623,25 +2624,11 @@ ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf, bool from_lua) } // Check for correct mode if (int_mode & current_maphash->m_mode) { - mapblock_fill_dict(dict, current_maphash, NULL, buffer_value, false); - Object api_dict = vim_to_object((typval_T[]) { { .v_type = VAR_DICT, - .vval.v_dict = dict } }); - if (from_lua) { - Dictionary d = api_dict.data.dictionary; - for (size_t j = 0; j < d.size; j++) { - if (strequal("callback", d.items[j].key.data)) { - d.items[j].value.type = kObjectTypeLuaRef; - d.items[j].value.data.luaref = api_new_luaref((LuaRef)d.items[j].value.data.integer); - break; - } - } - } - ADD(mappings, api_dict); - tv_dict_clear(dict); + ADD(mappings, + DICTIONARY_OBJ(mapblock_fill_dict(current_maphash, NULL, buffer_value, false))); } } } - tv_dict_free(dict); return mappings; } -- cgit From f31db30975479cb6b57247f124a65f4362f80bfe Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 30 Jun 2022 13:26:31 +0600 Subject: feat(lua): vim.ui_attach to get ui events from lua Co-authored-by: Famiu Haque --- src/nvim/api/extmark.c | 2 +- src/nvim/api/ui.c | 1 + src/nvim/api/ui_events.in.h | 4 +- src/nvim/buffer_updates.c | 8 ++- src/nvim/eval.c | 9 +--- src/nvim/generators/gen_api_ui_events.lua | 2 + src/nvim/lua/executor.c | 89 +++++++++++++++++++++++++++++-- src/nvim/map.c | 1 + src/nvim/map.h | 1 + src/nvim/memory.c | 2 + src/nvim/ui.c | 7 ++- src/nvim/ui.h | 5 ++ src/nvim/ui_compositor.c | 87 +++++++++++++++++++++++++++++- 13 files changed, 196 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index 09b004637f..6ff0a2ed21 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -87,7 +87,7 @@ const char *describe_ns(NS ns_id) } // Is the Namespace in use? -static bool ns_initialized(uint32_t ns) +bool ns_initialized(uint32_t ns) { if (ns < 1) { return false; diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index e34dcbdb46..654eb19bec 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -223,6 +223,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona ui->msg_set_pos = remote_ui_msg_set_pos; ui->event = remote_ui_event; ui->inspect = remote_ui_inspect; + ui->win_viewport = remote_ui_win_viewport; CLEAR_FIELD(ui->ui_ext); diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index 8b7e01e1c3..17930dca85 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -100,7 +100,7 @@ void raw_line(Integer grid, Integer row, Integer startcol, FUNC_API_NOEXPORT FUNC_API_COMPOSITOR_IMPL; void event(char *name, Array args) - FUNC_API_NOEXPORT; + FUNC_API_NOEXPORT FUNC_API_COMPOSITOR_IMPL; void win_pos(Integer grid, Window win, Integer startrow, Integer startcol, Integer width, Integer height) @@ -121,7 +121,7 @@ void msg_set_pos(Integer grid, Integer row, Boolean scrolled, String sep_char) void win_viewport(Integer grid, Window win, Integer topline, Integer botline, Integer curline, Integer curcol, Integer line_count) - FUNC_API_SINCE(7) FUNC_API_REMOTE_ONLY; + FUNC_API_SINCE(7) FUNC_API_BRIDGE_IMPL; void win_extmark(Integer grid, Window win, Integer ns_id, Integer mark_id, Integer row, Integer col) diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c index 14973502ab..1b3c0bc28f 100644 --- a/src/nvim/buffer_updates.c +++ b/src/nvim/buffer_updates.c @@ -285,14 +285,13 @@ void buf_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added, args.items[7] = INTEGER_OBJ((Integer)deleted_codeunits); } textlock++; - Object res = nlua_call_ref(cb.on_lines, "lines", args, true, NULL); + Object res = nlua_call_ref(cb.on_lines, "lines", args, false, NULL); textlock--; if (res.type == kObjectTypeBoolean && res.data.boolean == true) { buffer_update_callbacks_free(cb); keep = false; } - api_free_object(res); } if (keep) { kv_A(buf->update_callbacks, j++) = kv_A(buf->update_callbacks, i); @@ -335,7 +334,7 @@ void buf_updates_send_splice(buf_T *buf, int start_row, colnr_T start_col, bcoun ADD_C(args, INTEGER_OBJ(new_byte)); textlock++; - Object res = nlua_call_ref(cb.on_bytes, "bytes", args, true, NULL); + Object res = nlua_call_ref(cb.on_bytes, "bytes", args, false, NULL); textlock--; if (res.type == kObjectTypeBoolean && res.data.boolean == true) { @@ -371,14 +370,13 @@ void buf_updates_changedtick(buf_T *buf) textlock++; Object res = nlua_call_ref(cb.on_changedtick, "changedtick", - args, true, NULL); + args, false, NULL); textlock--; if (res.type == kObjectTypeBoolean && res.data.boolean == true) { buffer_update_callbacks_free(cb); keep = false; } - api_free_object(res); } if (keep) { kv_A(buf->update_callbacks, j++) = kv_A(buf->update_callbacks, i); diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 2dbaa2f8ac..92082772e1 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5858,13 +5858,8 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co break; case kCallbackLua: - rv = nlua_call_ref(callback->data.luaref, NULL, args, true, NULL); - switch (rv.type) { - case kObjectTypeBoolean: - return rv.data.boolean; - default: - return false; - } + rv = nlua_call_ref(callback->data.luaref, NULL, args, false, NULL); + return (rv.type == kObjectTypeBoolean && rv.data.boolean == true); case kCallbackNone: return false; diff --git a/src/nvim/generators/gen_api_ui_events.lua b/src/nvim/generators/gen_api_ui_events.lua index f9e888c20d..ea66be7ee8 100755 --- a/src/nvim/generators/gen_api_ui_events.lua +++ b/src/nvim/generators/gen_api_ui_events.lua @@ -75,6 +75,8 @@ local function call_ui_event_method(output, ev) hlattrs_args_count = hlattrs_args_count + 1 elseif kind == 'Object' then output:write('args.items['..(j-1)..'];\n') + elseif kind == 'Window' then + output:write('(Window)args.items['..(j-1)..'].data.integer;\n') else output:write('args.items['..(j-1)..'].data.'..string.lower(kind)..';\n') end diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 42aa13cfc1..f144e47c3a 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -7,6 +7,7 @@ #include #include "luv/luv.h" +#include "nvim/api/extmark.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/api/vim.h" @@ -40,6 +41,9 @@ #include "nvim/os/os.h" #include "nvim/profile.h" #include "nvim/runtime.h" +#include "nvim/screen.h" +#include "nvim/ui.h" +#include "nvim/ui_compositor.h" #include "nvim/undo.h" #include "nvim/usercmd.h" #include "nvim/version.h" @@ -589,6 +593,71 @@ static bool nlua_init_packages(lua_State *lstate) return true; } +/// "vim.ui_attach(ns_id, {ext_foo=true}, cb)" function +static int nlua_ui_attach(lua_State *lstate) + FUNC_ATTR_NONNULL_ALL +{ + uint32_t ns_id = (uint32_t)luaL_checkinteger(lstate, 1); + + if (!ns_initialized(ns_id)) { + return luaL_error(lstate, "invalid ns_id"); + } + if (!lua_istable(lstate, 2)) { + return luaL_error(lstate, "ext_widgets must be a table"); + } + if (!lua_isfunction(lstate, 3)) { + return luaL_error(lstate, "callback must be a Lua function"); + } + + bool ext_widgets[kUIGlobalCount] = { false }; + bool tbl_has_true_val = false; + + lua_pushvalue(lstate, 2); + lua_pushnil(lstate); + while (lua_next(lstate, -2)) { + // [dict, key, val] + size_t len; + const char *s = lua_tolstring(lstate, -2, &len); + bool val = lua_toboolean(lstate, -1); + + for (size_t i = 0; i < kUIGlobalCount; i++) { + if (strequal(s, ui_ext_names[i])) { + if (val) { + tbl_has_true_val = true; + } + ext_widgets[i] = val; + goto ok; + } + } + + return luaL_error(lstate, "Unexpected key: %s", s); +ok: + lua_pop(lstate, 1); + } + + if (!tbl_has_true_val) { + return luaL_error(lstate, "ext_widgets table must contain at least one 'true' value"); + } + + LuaRef ui_event_cb = nlua_ref_global(lstate, 3); + ui_comp_add_cb(ns_id, ui_event_cb, ext_widgets); + return 0; +} + +/// "vim.ui_detach(ns_id)" function +static int nlua_ui_detach(lua_State *lstate) + FUNC_ATTR_NONNULL_ALL +{ + uint32_t ns_id = (uint32_t)luaL_checkinteger(lstate, 1); + + if (!ns_initialized(ns_id)) { + return luaL_error(lstate, "invalid ns_id"); + } + + ui_comp_remove_cb(ns_id); + return 0; +} + /// Initialize lua interpreter state /// /// Called by lua interpreter itself to initialize state. @@ -649,6 +718,14 @@ static bool nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL lua_pushcfunction(lstate, &nlua_wait); lua_setfield(lstate, -2, "wait"); + // ui_attach + lua_pushcfunction(lstate, &nlua_ui_attach); + lua_setfield(lstate, -2, "ui_attach"); + + // ui_detach + lua_pushcfunction(lstate, &nlua_ui_detach); + lua_setfield(lstate, -2, "ui_detach"); + nlua_common_vim_init(lstate, false); // patch require() (only for --startuptime) @@ -1422,9 +1499,10 @@ bool nlua_ref_is_function(LuaRef ref) /// @param name if non-NULL, sent to callback as first arg /// if NULL, only args are used /// @param retval if true, convert return value to Object -/// if false, discard return value +/// if false, only check if return value is truthy /// @param err Error details, if any (if NULL, errors are echoed) -/// @return Return value of function, if retval was set. Otherwise NIL. +/// @return Return value of function, if retval was set. Otherwise +/// BOOLEAN_OBJ(true) or NIL. Object nlua_call_ref(LuaRef ref, const char *name, Array args, bool retval, Error *err) { lua_State *const lstate = global_lstate; @@ -1438,7 +1516,7 @@ Object nlua_call_ref(LuaRef ref, const char *name, Array args, bool retval, Erro nlua_push_Object(lstate, args.items[i], false); } - if (nlua_pcall(lstate, nargs, retval ? 1 : 0)) { + if (nlua_pcall(lstate, nargs, 1)) { // if err is passed, the caller will deal with the error. if (err) { size_t len; @@ -1458,7 +1536,10 @@ Object nlua_call_ref(LuaRef ref, const char *name, Array args, bool retval, Erro } return nlua_pop_Object(lstate, false, err); } else { - return NIL; + bool value = lua_toboolean(lstate, -1); + lua_pop(lstate, 1); + + return value ? BOOLEAN_OBJ(true) : NIL; } } diff --git a/src/nvim/map.c b/src/nvim/map.c index d3058a5d52..1561b089a7 100644 --- a/src/nvim/map.c +++ b/src/nvim/map.c @@ -168,6 +168,7 @@ MAP_IMPL(int, cstr_t, DEFAULT_INITIALIZER) MAP_IMPL(cstr_t, ptr_t, DEFAULT_INITIALIZER) MAP_IMPL(cstr_t, int, DEFAULT_INITIALIZER) MAP_IMPL(ptr_t, ptr_t, DEFAULT_INITIALIZER) +MAP_IMPL(uint32_t, ptr_t, DEFAULT_INITIALIZER) MAP_IMPL(uint64_t, ptr_t, DEFAULT_INITIALIZER) MAP_IMPL(uint64_t, ssize_t, SSIZE_INITIALIZER) MAP_IMPL(uint64_t, uint64_t, DEFAULT_INITIALIZER) diff --git a/src/nvim/map.h b/src/nvim/map.h index 845daac3f7..f5f30f5a85 100644 --- a/src/nvim/map.h +++ b/src/nvim/map.h @@ -39,6 +39,7 @@ MAP_DECLS(int, cstr_t) MAP_DECLS(cstr_t, ptr_t) MAP_DECLS(cstr_t, int) MAP_DECLS(ptr_t, ptr_t) +MAP_DECLS(uint32_t, ptr_t) MAP_DECLS(uint64_t, ptr_t) MAP_DECLS(uint64_t, ssize_t) MAP_DECLS(uint64_t, uint64_t) diff --git a/src/nvim/memory.c b/src/nvim/memory.c index a9785fcb7c..acd2478c81 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -23,6 +23,7 @@ #include "nvim/message.h" #include "nvim/sign.h" #include "nvim/ui.h" +#include "nvim/ui_compositor.h" #include "nvim/vim.h" #ifdef UNIT_TESTING @@ -824,6 +825,7 @@ void free_all_mem(void) nlua_free_all_mem(); ui_free_all_mem(); + ui_comp_free_all_mem(); // should be last, in case earlier free functions deallocates arenas arena_free_reuse_blks(); diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 46f4d137c4..06be5676c7 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -198,13 +198,16 @@ void ui_refresh(void) ext_widgets[i] = true; } + UI *compositor = uis[0]; + bool inclusive = ui_override(); - for (size_t i = 0; i < ui_count; i++) { + for (size_t i = 1; i < ui_count; i++) { UI *ui = uis[i]; width = MIN(ui->width, width); height = MIN(ui->height, height); for (UIExtension j = 0; (int)j < kUIExtCount; j++) { - ext_widgets[j] &= (ui->ui_ext[j] || inclusive); + bool in_compositor = ui->composed && compositor->ui_ext[j]; + ext_widgets[j] &= (ui->ui_ext[j] || in_compositor || inclusive); } } diff --git a/src/nvim/ui.h b/src/nvim/ui.h index 996b3467a6..9034e7b764 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -69,6 +69,11 @@ struct ui_t { void (*inspect)(UI *ui, Dictionary *info); }; +typedef struct ui_event_callback { + LuaRef cb; + bool ext_widgets[kUIGlobalCount]; +} UIEventCallback; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui.h.generated.h" diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 2216e25db9..5167f291c3 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -20,6 +20,7 @@ #include "nvim/log.h" #include "nvim/lua/executor.h" #include "nvim/main.h" +#include "nvim/map.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/os/os.h" @@ -54,6 +55,8 @@ static bool msg_was_scrolled = false; static int msg_sep_row = -1; static schar_T msg_sep_char = { ' ', NUL }; +static PMap(uint32_t) ui_event_cbs = MAP_INIT; + static int dbghl_normal, dbghl_clear, dbghl_composed, dbghl_recompose; void ui_comp_init(void) @@ -69,14 +72,18 @@ void ui_comp_init(void) compositor->grid_cursor_goto = ui_comp_grid_cursor_goto; compositor->raw_line = ui_comp_raw_line; compositor->msg_set_pos = ui_comp_msg_set_pos; + compositor->event = ui_comp_event; // Be unopinionated: will be attached together with a "real" ui anyway compositor->width = INT_MAX; compositor->height = INT_MAX; - for (UIExtension i = 0; (int)i < kUIExtCount; i++) { + for (UIExtension i = kUIGlobalCount; (int)i < kUIExtCount; i++) { compositor->ui_ext[i] = true; } + // TODO(bfredl): one day. in the future. + compositor->ui_ext[kUIMultigrid] = false; + // TODO(bfredl): this will be more complicated if we implement // hlstate per UI (i e reduce hl ids for non-hlstate UIs) compositor->ui_ext[kUIHlState] = false; @@ -87,6 +94,15 @@ void ui_comp_init(void) ui_attach_impl(compositor, 0); } +void ui_comp_free_all_mem(void) +{ + UIEventCallback *event_cb; + map_foreach_value(&ui_event_cbs, event_cb, { + xfree(event_cb); + }) + pmap_destroy(uint32_t)(&ui_event_cbs); +} + void ui_comp_syn_init(void) { dbghl_normal = syn_check_group(S_LEN("RedrawDebugNormal")); @@ -676,3 +692,72 @@ static void ui_comp_grid_resize(UI *ui, Integer grid, Integer width, Integer hei } } } + +static void ui_comp_event(UI *ui, char *name, Array args) +{ + Error err = ERROR_INIT; + UIEventCallback *event_cb; + bool handled = false; + + map_foreach_value(&ui_event_cbs, event_cb, { + Object res = nlua_call_ref(event_cb->cb, name, args, false, &err); + if (res.type == kObjectTypeBoolean && res.data.boolean == true) { + handled = true; + } + }) + + if (!handled) { + ui_composed_call_event(name, args); + } +} + +static void ui_comp_update_ext(void) +{ + memset(compositor->ui_ext, 0, ARRAY_SIZE(compositor->ui_ext)); + + for (size_t i = 0; i < kUIGlobalCount; i++) { + UIEventCallback *event_cb; + + map_foreach_value(&ui_event_cbs, event_cb, { + if (event_cb->ext_widgets[i]) { + compositor->ui_ext[i] = true; + break; + } + }) + } +} + +void free_ui_event_callback(UIEventCallback *event_cb) +{ + api_free_luaref(event_cb->cb); + xfree(event_cb); +} + +void ui_comp_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) +{ + UIEventCallback *event_cb = xcalloc(1, sizeof(UIEventCallback)); + event_cb->cb = cb; + memcpy(event_cb->ext_widgets, ext_widgets, ARRAY_SIZE(event_cb->ext_widgets)); + if (event_cb->ext_widgets[kUIMessages]) { + event_cb->ext_widgets[kUICmdline] = true; + } + + UIEventCallback **item = (UIEventCallback **)pmap_ref(uint32_t)(&ui_event_cbs, ns_id, true); + if (*item) { + free_ui_event_callback(*item); + } + *item = event_cb; + + ui_comp_update_ext(); + ui_schedule_refresh(); +} + +void ui_comp_remove_cb(uint32_t ns_id) +{ + if (pmap_has(uint32_t)(&ui_event_cbs, ns_id)) { + free_ui_event_callback(pmap_get(uint32_t)(&ui_event_cbs, ns_id)); + pmap_del(uint32_t)(&ui_event_cbs, ns_id); + } + ui_comp_update_ext(); + ui_schedule_refresh(); +} -- cgit From ba8be7446d440053b24358046e8e4033e3447633 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 31 Aug 2022 14:49:15 +0200 Subject: refactor(highlight): make hlattrs2dict always use pre-allocated dict hlattrs2dict used to work with both allocated and unallocated dicts which was quite messy. Now always delegate allocation to caller. --- src/nvim/api/ui.c | 64 ++++++++++++++++++++++++---------------------- src/nvim/api/vim.c | 22 ++++++++-------- src/nvim/highlight.c | 30 ++++++++-------------- src/nvim/highlight.h | 2 ++ src/nvim/highlight_group.c | 16 +++++++----- 5 files changed, 66 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index e34dcbdb46..110bd6920e 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -748,10 +748,12 @@ static void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAt UIData *data = ui->data; Array args = data->call_buf; ADD_C(args, INTEGER_OBJ(id)); - MAXSIZE_TEMP_DICT(rgb, 16); - MAXSIZE_TEMP_DICT(cterm, 16); - ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(&rgb, rgb_attrs, true))); - ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(&cterm, cterm_attrs, false))); + MAXSIZE_TEMP_DICT(rgb, HLATTRS_DICT_SIZE); + MAXSIZE_TEMP_DICT(cterm, HLATTRS_DICT_SIZE); + hlattrs2dict(&rgb, rgb_attrs, true); + hlattrs2dict(&cterm, rgb_attrs, false); + ADD_C(args, DICTIONARY_OBJ(rgb)); + ADD_C(args, DICTIONARY_OBJ(cterm)); if (ui->ui_ext[kUIHlState]) { ADD_C(args, ARRAY_OBJ(info)); @@ -771,8 +773,9 @@ static void remote_ui_highlight_set(UI *ui, int id) return; } data->hl_id = id; - MAXSIZE_TEMP_DICT(dict, 16); - ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(&dict, syn_attr2entry(id), ui->rgb))); + MAXSIZE_TEMP_DICT(dict, HLATTRS_DICT_SIZE); + hlattrs2dict(&dict, syn_attr2entry(id), ui->rgb); + ADD_C(args, DICTIONARY_OBJ(dict)); push_call(ui, "highlight_set", args); } @@ -952,65 +955,63 @@ static void remote_ui_flush(UI *ui) } } -static Array translate_contents(UI *ui, Array contents) +static Array translate_contents(UI *ui, Array contents, Arena *arena) { - Array new_contents = ARRAY_DICT_INIT; + Array new_contents = arena_array(arena, contents.size); for (size_t i = 0; i < contents.size; i++) { Array item = contents.items[i].data.array; - Array new_item = ARRAY_DICT_INIT; + Array new_item = arena_array(arena, 2); int attr = (int)item.items[0].data.integer; if (attr) { - Dictionary rgb_attrs = hlattrs2dict(NULL, syn_attr2entry(attr), ui->rgb); + Dictionary rgb_attrs = arena_dict(arena, HLATTRS_DICT_SIZE); + hlattrs2dict(&rgb_attrs, syn_attr2entry(attr), ui->rgb); ADD(new_item, DICTIONARY_OBJ(rgb_attrs)); } else { ADD(new_item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); } - ADD(new_item, copy_object(item.items[1], NULL)); + ADD(new_item, item.items[1]); ADD(new_contents, ARRAY_OBJ(new_item)); } return new_contents; } -static Array translate_firstarg(UI *ui, Array args) +static Array translate_firstarg(UI *ui, Array args, Arena *arena) { - Array new_args = ARRAY_DICT_INIT; + Array new_args = arena_array(arena, args.size); Array contents = args.items[0].data.array; - ADD(new_args, ARRAY_OBJ(translate_contents(ui, contents))); + ADD_C(new_args, ARRAY_OBJ(translate_contents(ui, contents, arena))); for (size_t i = 1; i < args.size; i++) { - ADD(new_args, copy_object(args.items[i], NULL)); + ADD(new_args, args.items[i]); } return new_args; } static void remote_ui_event(UI *ui, char *name, Array args) { + Arena arena = ARENA_EMPTY; UIData *data = ui->data; if (!ui->ui_ext[kUILinegrid]) { // the representation of highlights in cmdline changed, translate back // never consumes args if (strequal(name, "cmdline_show")) { - Array new_args = translate_firstarg(ui, args); + Array new_args = translate_firstarg(ui, args, &arena); push_call(ui, name, new_args); - api_free_array(new_args); - return; + goto free_ret; } else if (strequal(name, "cmdline_block_show")) { Array new_args = data->call_buf; Array block = args.items[0].data.array; - Array new_block = ARRAY_DICT_INIT; + Array new_block = arena_array(&arena, block.size); for (size_t i = 0; i < block.size; i++) { - ADD(new_block, - ARRAY_OBJ(translate_contents(ui, block.items[i].data.array))); + ADD_C(new_block, ARRAY_OBJ(translate_contents(ui, block.items[i].data.array, &arena))); } ADD_C(new_args, ARRAY_OBJ(new_block)); push_call(ui, name, new_args); - api_free_array(new_block); - return; + goto free_ret; } else if (strequal(name, "cmdline_block_append")) { - Array new_args = translate_firstarg(ui, args); + Array new_args = translate_firstarg(ui, args, &arena); push_call(ui, name, new_args); - api_free_array(new_args); - return; + goto free_ret; } } @@ -1022,19 +1023,18 @@ static void remote_ui_event(UI *ui, char *name, Array args) if (data->wildmenu_active) { Array new_args = data->call_buf; Array items = args.items[0].data.array; - Array new_items = ARRAY_DICT_INIT; + Array new_items = arena_array(&arena, items.size); for (size_t i = 0; i < items.size; i++) { - ADD(new_items, copy_object(items.items[i].data.array.items[0], NULL)); + ADD_C(new_items, items.items[i].data.array.items[0]); } ADD_C(new_args, ARRAY_OBJ(new_items)); push_call(ui, "wildmenu_show", new_args); - api_free_array(new_items); if (args.items[1].data.integer != -1) { Array new_args2 = data->call_buf; ADD_C(new_args2, args.items[1]); push_call(ui, "wildmenu_select", new_args2); } - return; + goto free_ret; } } else if (strequal(name, "popupmenu_select")) { if (data->wildmenu_active) { @@ -1048,6 +1048,10 @@ static void remote_ui_event(UI *ui, char *name, Array args) } push_call(ui, name, args); + return; + +free_ret: + arena_mem_free(arena_finish(&arena)); } static void remote_ui_inspect(UI *ui, Dictionary *info) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9e1f2dd631..83d6ba8dc7 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -79,7 +79,7 @@ /// @param[out] err Error details, if any /// @return Highlight definition map /// @see nvim_get_hl_by_id -Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Error *err) +Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Arena *arena, Error *err) FUNC_API_SINCE(3) { Dictionary result = ARRAY_DICT_INIT; @@ -89,8 +89,7 @@ Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Error *err) api_set_error(err, kErrorTypeException, "Invalid highlight name: %s", name.data); return result; } - result = nvim_get_hl_by_id(id, rgb, err); - return result; + return nvim_get_hl_by_id(id, rgb, arena, err); } /// Gets a highlight definition by id. |hlID()| @@ -99,7 +98,7 @@ Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Error *err) /// @param[out] err Error details, if any /// @return Highlight definition map /// @see nvim_get_hl_by_name -Dictionary nvim_get_hl_by_id(Integer hl_id, Boolean rgb, Error *err) +Dictionary nvim_get_hl_by_id(Integer hl_id, Boolean rgb, Arena *arena, Error *err) FUNC_API_SINCE(3) { Dictionary dic = ARRAY_DICT_INIT; @@ -108,7 +107,7 @@ Dictionary nvim_get_hl_by_id(Integer hl_id, Boolean rgb, Error *err) return dic; } int attrcode = syn_id2attr((int)hl_id); - return hl_get_attr_by_id(attrcode, rgb, err); + return hl_get_attr_by_id(attrcode, rgb, arena, err); } /// Gets a highlight group by name @@ -120,10 +119,10 @@ Integer nvim_get_hl_id_by_name(String name) return syn_check_group(name.data, name.size); } -Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) +Dictionary nvim__get_hl_defs(Integer ns_id, Arena *arena, Error *err) { if (ns_id == 0) { - return get_global_hl_defs(); + return get_global_hl_defs(arena); } abort(); } @@ -1934,7 +1933,7 @@ void nvim_select_popupmenu_item(Integer item, Boolean insert, Boolean finish, Di } /// NB: if your UI doesn't use hlstate, this will not return hlstate first time -Array nvim__inspect_cell(Integer grid, Integer row, Integer col, Error *err) +Array nvim__inspect_cell(Integer grid, Integer row, Integer col, Arena *arena, Error *err) { Array ret = ARRAY_DICT_INIT; @@ -1958,13 +1957,14 @@ Array nvim__inspect_cell(Integer grid, Integer row, Integer col, Error *err) || col < 0 || col >= g->cols) { return ret; } + ret = arena_array(arena, 3); size_t off = g->line_offset[(size_t)row] + (size_t)col; - ADD(ret, STRING_OBJ(cstr_to_string((char *)g->chars[off]))); + ADD_C(ret, STRING_OBJ(cstr_as_string((char *)g->chars[off]))); int attr = g->attrs[off]; - ADD(ret, DICTIONARY_OBJ(hl_get_attr_by_id(attr, true, err))); + ADD_C(ret, DICTIONARY_OBJ(hl_get_attr_by_id(attr, true, arena, err))); // will not work first time if (!highlight_use_hlstate()) { - ADD(ret, ARRAY_OBJ(hl_inspect(attr))); + ADD_C(ret, ARRAY_OBJ(hl_inspect(attr))); } return ret; } diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index a78b933108..e42cb66422 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -788,7 +788,7 @@ HlAttrs syn_attr2entry(int attr) } /// Gets highlight description for id `attr_id` as a map. -Dictionary hl_get_attr_by_id(Integer attr_id, Boolean rgb, Error *err) +Dictionary hl_get_attr_by_id(Integer attr_id, Boolean rgb, Arena *arena, Error *err) { Dictionary dic = ARRAY_DICT_INIT; @@ -801,25 +801,21 @@ Dictionary hl_get_attr_by_id(Integer attr_id, Boolean rgb, Error *err) "Invalid attribute id: %" PRId64, attr_id); return dic; } - - return hlattrs2dict(NULL, syn_attr2entry((int)attr_id), rgb); + Dictionary retval = arena_dict(arena, HLATTRS_DICT_SIZE); + hlattrs2dict(&retval, syn_attr2entry((int)attr_id), rgb); + return retval; } /// Converts an HlAttrs into Dictionary /// -/// @param[out] hl optional pre-allocated dictionary for return value -/// if present, must be allocated with at least 16 elements! +/// @param[in/out] hl Dictionary with pre-allocated space for HLATTRS_DICT_SIZE elements /// @param[in] aep data to convert /// @param use_rgb use 'gui*' settings if true, else resorts to 'cterm*' -Dictionary hlattrs2dict(Dictionary *hl_alloc, HlAttrs ae, bool use_rgb) +void hlattrs2dict(Dictionary *dict, HlAttrs ae, bool use_rgb) { + assert(dict->capacity >= HLATTRS_DICT_SIZE); // at most 16 items + Dictionary hl = *dict; int mask = use_rgb ? ae.rgb_ae_attr : ae.cterm_ae_attr; - Dictionary hl = ARRAY_DICT_INIT; - if (hl_alloc) { - hl = *hl_alloc; - } else { - kv_ensure_space(hl, 16); - } if (mask & HL_BOLD) { PUT_C(hl, "bold", BOOLEAN_OBJ(true)); @@ -899,14 +895,7 @@ Dictionary hlattrs2dict(Dictionary *hl_alloc, HlAttrs ae, bool use_rgb) PUT_C(hl, "blend", INTEGER_OBJ(ae.hl_blend)); } - if (hl_alloc) { - *hl_alloc = hl; - return hl; - } else { - Dictionary allocated = copy_dictionary(hl, NULL); - kv_destroy(hl); - return allocated; - } + *dict = hl; } HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *err) @@ -1086,6 +1075,7 @@ int object_to_color(Object val, char *key, bool rgb, Error *err) Array hl_inspect(int attr) { + // TODO(bfredl): use arena allocation Array ret = ARRAY_DICT_INIT; if (hlstate_active) { hl_inspect_impl(&ret, attr); diff --git a/src/nvim/highlight.h b/src/nvim/highlight.h index 50299bb91c..e85e3859e2 100644 --- a/src/nvim/highlight.h +++ b/src/nvim/highlight.h @@ -19,6 +19,8 @@ static inline int win_hl_attr(win_T *wp, int hlf) return ((wp->w_ns_hl_attr && ns_hl_fast < 0) ? wp->w_ns_hl_attr : hl_attr_active)[hlf]; } +#define HLATTRS_DICT_SIZE 16 + #define HL_SET_DEFAULT_COLORS(rgb_fg, rgb_bg, rgb_sp) \ do { \ bool dark_ = (*p_bg == 'd'); \ diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index ed1f0185b7..97d4b421fe 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -1466,19 +1466,21 @@ static void highlight_list_one(const int id) } } -Dictionary get_global_hl_defs(void) +Dictionary get_global_hl_defs(Arena *arena) { - Dictionary rv = ARRAY_DICT_INIT; - for (int i = 1; i <= highlight_ga.ga_len && !got_int; i++) { + Dictionary rv = arena_dict(arena, (size_t)highlight_ga.ga_len); + for (int i = 1; i <= highlight_ga.ga_len; i++) { Dictionary attrs = ARRAY_DICT_INIT; HlGroup *h = &hl_table[i - 1]; if (h->sg_attr > 0) { - attrs = hlattrs2dict(NULL, syn_attr2entry(h->sg_attr), true); + attrs = arena_dict(arena, HLATTRS_DICT_SIZE); + hlattrs2dict(&attrs, syn_attr2entry(h->sg_attr), true); } else if (h->sg_link > 0) { - const char *link = (const char *)hl_table[h->sg_link - 1].sg_name; - PUT(attrs, "link", STRING_OBJ(cstr_to_string(link))); + attrs = arena_dict(arena, 1); + char *link = (char *)hl_table[h->sg_link - 1].sg_name; + PUT_C(attrs, "link", STRING_OBJ(cstr_as_string(link))); } - PUT(rv, (const char *)h->sg_name, DICTIONARY_OBJ(attrs)); + PUT_C(rv, (char *)h->sg_name, DICTIONARY_OBJ(attrs)); } return rv; -- cgit From bd51ac2a347c0a3efb64e4b09400b7314286844c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/cmdexpand.c | 4 +- src/nvim/debugger.c | 50 ++++---- src/nvim/decoration.c | 2 +- src/nvim/drawline.c | 4 +- src/nvim/edit.c | 4 +- src/nvim/eval.c | 6 +- src/nvim/eval/funcs.c | 4 +- src/nvim/eval/userfunc.c | 16 +-- src/nvim/eval/vars.c | 4 +- src/nvim/ex_cmds.c | 6 +- src/nvim/ex_docmd.c | 14 +-- src/nvim/ex_getln.c | 21 ++-- src/nvim/fold.c | 104 ++++++++-------- src/nvim/mbyte.c | 21 ++-- src/nvim/path.c | 2 +- src/nvim/regexp.c | 53 ++++---- src/nvim/regexp_bt.c | 14 +-- src/nvim/regexp_nfa.c | 8 +- src/nvim/search.c | 4 +- src/nvim/shada.c | 2 +- src/nvim/sign.c | 317 +++++++++++++++++++++++------------------------ src/nvim/sign_defs.h | 2 +- src/nvim/spell.c | 4 +- src/nvim/syntax.c | 247 ++++++++++++++++++------------------ src/nvim/tag.c | 88 +++++++------ src/nvim/ui.c | 2 +- 26 files changed, 493 insertions(+), 510 deletions(-) (limited to 'src') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 1c35f28301..7e2adf7f29 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1424,7 +1424,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons set_context_in_cscope_cmd(xp, arg, cmdidx); break; case CMD_sign: - set_context_in_sign_cmd(xp, (char_u *)arg); + set_context_in_sign_cmd(xp, (char *)arg); break; case CMD_bdelete: case CMD_bwipeout: @@ -2890,7 +2890,7 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } if (xpc.xp_context == EXPAND_SIGN) { - set_context_in_sign_cmd(&xpc, (char_u *)xpc.xp_pattern); + set_context_in_sign_cmd(&xpc, xpc.xp_pattern); xpc.xp_pattern_len = STRLEN(xpc.xp_pattern); } diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index 36df62b502..b720628e33 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -33,7 +33,7 @@ static char *debug_newval = NULL; struct debuggy { int dbg_nr; ///< breakpoint number int dbg_type; ///< DBG_FUNC or DBG_FILE or DBG_EXPR - char_u *dbg_name; ///< function, expression or file name + char *dbg_name; ///< function, expression or file name regprog_T *dbg_prog; ///< regexp program linenr_T dbg_lnum; ///< line number in function or file int dbg_forceit; ///< ! used @@ -60,7 +60,7 @@ void do_debug(char *cmd) bool typeahead_saved = false; int save_ignore_script = 0; int n; - char_u *cmdline = NULL; + char *cmdline = NULL; char *p; char *tail = NULL; static int last_cmd = 0; @@ -129,8 +129,8 @@ void do_debug(char *cmd) } xfree(cmdline); - cmdline = (char_u *)getcmdline_prompt('>', NULL, 0, EXPAND_NOTHING, NULL, - CALLBACK_NONE); + cmdline = getcmdline_prompt('>', NULL, 0, EXPAND_NOTHING, NULL, + CALLBACK_NONE); if (typeahead_saved) { restore_typeahead(&typeaheadbuf); @@ -144,7 +144,7 @@ void do_debug(char *cmd) // If this is a debug command, set "last_cmd". // If not, reset "last_cmd". // For a blank line use previous command. - p = skipwhite((char *)cmdline); + p = skipwhite(cmdline); if (*p != NUL) { switch (*p) { case 'c': @@ -239,14 +239,14 @@ void do_debug(char *cmd) last_cmd = CMD_STEP; break; case CMD_BACKTRACE: - do_showbacktrace((char_u *)cmd); + do_showbacktrace(cmd); continue; case CMD_FRAME: if (*p == NUL) { - do_showbacktrace((char_u *)cmd); + do_showbacktrace(cmd); } else { p = skipwhite(p); - do_setdebugtracelevel((char_u *)p); + do_setdebugtracelevel(p); } continue; case CMD_UP: @@ -266,7 +266,7 @@ void do_debug(char *cmd) // don't debug this command n = debug_break_level; debug_break_level = -1; - (void)do_cmdline((char *)cmdline, getexline, NULL, DOCMD_VERBOSE|DOCMD_EXCRESET); + (void)do_cmdline(cmdline, getexline, NULL, DOCMD_VERBOSE|DOCMD_EXCRESET); debug_break_level = n; } lines_left = Rows - 1; @@ -306,9 +306,9 @@ static int get_maxbacktrace_level(char *sname) return maxbacktrace; } -static void do_setdebugtracelevel(char_u *arg) +static void do_setdebugtracelevel(char *arg) { - int level = atoi((char *)arg); + int level = atoi(arg); if (*arg == '+' || level < 0) { debug_backtrace_level += level; } else { @@ -335,7 +335,7 @@ static void do_checkbacktracelevel(void) } } -static void do_showbacktrace(char_u *cmd) +static void do_showbacktrace(char *cmd) { char *sname = estack_sfile(ESTACK_NONE); int max = get_maxbacktrace_level(sname); @@ -470,7 +470,7 @@ static typval_T *eval_expr_no_emsg(struct debuggy *const bp) { // Disable error messages, a bad expression would make Vim unusable. emsg_off++; - typval_T *const tv = eval_expr((char *)bp->dbg_name); + typval_T *const tv = eval_expr(bp->dbg_name); emsg_off--; return tv; } @@ -482,9 +482,9 @@ static typval_T *eval_expr_no_emsg(struct debuggy *const bp) /// /// @param arg /// @param gap either &dbg_breakp or &prof_ga -static int dbg_parsearg(char_u *arg, garray_T *gap) +static int dbg_parsearg(char *arg, garray_T *gap) { - char *p = (char *)arg; + char *p = arg; char *q; bool here = false; @@ -531,11 +531,11 @@ static int dbg_parsearg(char_u *arg, garray_T *gap) } if (bp->dbg_type == DBG_FUNC) { - bp->dbg_name = vim_strsave((char_u *)p); + bp->dbg_name = xstrdup(p); } else if (here) { - bp->dbg_name = vim_strsave((char_u *)curbuf->b_ffname); + bp->dbg_name = xstrdup(curbuf->b_ffname); } else if (bp->dbg_type == DBG_EXPR) { - bp->dbg_name = vim_strsave((char_u *)p); + bp->dbg_name = xstrdup(p); bp->dbg_val = eval_expr_no_emsg(bp); } else { // Expand the file name in the same way as do_source(). This means @@ -551,10 +551,10 @@ static int dbg_parsearg(char_u *arg, garray_T *gap) return FAIL; } if (*p != '*') { - bp->dbg_name = (char_u *)fix_fname(p); + bp->dbg_name = fix_fname(p); xfree(p); } else { - bp->dbg_name = (char_u *)p; + bp->dbg_name = p; } } @@ -572,12 +572,12 @@ void ex_breakadd(exarg_T *eap) gap = &prof_ga; } - if (dbg_parsearg((char_u *)eap->arg, gap) == OK) { + if (dbg_parsearg(eap->arg, gap) == OK) { struct debuggy *bp = &DEBUGGY(gap, gap->ga_len); bp->dbg_forceit = eap->forceit; if (bp->dbg_type != DBG_EXPR) { - char *pat = file_pat_to_reg_pat((char *)bp->dbg_name, NULL, NULL, false); + char *pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, false); if (pat != NULL) { bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING); xfree(pat); @@ -639,7 +639,7 @@ void ex_breakdel(exarg_T *eap) del_all = true; } else { // ":breakdel {func|file|expr} [lnum] {name}" - if (dbg_parsearg((char_u *)eap->arg, gap) == FAIL) { + if (dbg_parsearg(eap->arg, gap) == FAIL) { return; } bp = &DEBUGGY(gap, gap->ga_len); @@ -697,13 +697,13 @@ void ex_breaklist(exarg_T *eap) for (int i = 0; i < dbg_breakp.ga_len; i++) { struct debuggy *bp = &BREAKP(i); if (bp->dbg_type == DBG_FILE) { - home_replace(NULL, (char *)bp->dbg_name, (char *)NameBuff, MAXPATHL, true); + home_replace(NULL, bp->dbg_name, (char *)NameBuff, MAXPATHL, true); } if (bp->dbg_type != DBG_EXPR) { smsg(_("%3d %s %s line %" PRId64), bp->dbg_nr, bp->dbg_type == DBG_FUNC ? "func" : "file", - bp->dbg_type == DBG_FUNC ? bp->dbg_name : (char_u *)NameBuff, + bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff, (int64_t)bp->dbg_lnum); } else { smsg(_("%3d expr %s"), bp->dbg_nr, bp->dbg_name); diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c index 9f3e5a8638..8955048f45 100644 --- a/src/nvim/decoration.c +++ b/src/nvim/decoration.c @@ -394,7 +394,7 @@ void decor_redraw_signs(buf_T *buf, int row, int *num_signs, SignTextAttrs sattr } if (j < SIGN_SHOW_MAX) { sattrs[j] = (SignTextAttrs) { - .text = decor->sign_text, + .text = (char *)decor->sign_text, .hl_attr_id = decor->sign_hl_id == 0 ? 0 : syn_id2attr(decor->sign_hl_id), .priority = decor->priority }; diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 66d8a1fb32..85a0bf2f5f 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -306,7 +306,7 @@ static void get_sign_display_info(bool nrcol, win_T *wp, linenr_T lnum, SignText if (row == startrow + filler_lines && filler_todo <= 0) { SignTextAttrs *sattr = sign_get_attr(sign_idx, sattrs, wp->w_scwidth); if (sattr != NULL) { - *pp_extra = sattr->text; + *pp_extra = (char_u *)sattr->text; if (*pp_extra != NULL) { *c_extrap = NUL; *c_finalp = NUL; @@ -1349,7 +1349,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, linenr_T lnume = lnum + foldinfo.fi_lines - 1; memset(buf_fold, ' ', FOLD_TEXT_LEN); - p_extra = get_foldtext(wp, lnum, lnume, foldinfo, buf_fold); + p_extra = (char_u *)get_foldtext(wp, lnum, lnume, foldinfo, (char *)buf_fold); n_extra = (int)STRLEN(p_extra); if (p_extra != buf_fold) { diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 642162284c..9144d055f7 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3236,7 +3236,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX); if (s + (p - look) <= line + curwin->w_cursor.col && (icase - ? mb_strnicmp(s, look, (size_t)(p - look)) + ? mb_strnicmp((char *)s, (char *)look, (size_t)(p - look)) : STRNCMP(s, look, p - look)) == 0) { match = true; } @@ -3250,7 +3250,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) if ((curwin->w_cursor.col == (colnr_T)(p - look) || !vim_iswordc(line[-(p - look) - 1])) && (icase - ? mb_strnicmp(line - (p - look), look, (size_t)(p - look)) + ? mb_strnicmp((char *)line - (p - look), (char *)look, (size_t)(p - look)) : STRNCMP(line - (p - look), look, p - look)) == 0) { match = true; } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 2ade64df3f..0b03cf3011 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2292,7 +2292,7 @@ int eval0(char *arg, typval_T *rettv, char **nextcmd, int evaluate) ret = FAIL; } if (nextcmd != NULL) { - *nextcmd = (char *)check_nextcmd((char_u *)p); + *nextcmd = check_nextcmd(p); } return ret; @@ -7639,7 +7639,7 @@ void ex_echo(exarg_T *eap) tv_clear(&rettv); arg = skipwhite(arg); } - eap->nextcmd = (char *)check_nextcmd((char_u *)arg); + eap->nextcmd = check_nextcmd(arg); if (eap->skip) { emsg_skip--; @@ -7736,7 +7736,7 @@ void ex_execute(exarg_T *eap) emsg_skip--; } - eap->nextcmd = (char *)check_nextcmd((char_u *)arg); + eap->nextcmd = check_nextcmd(arg); } /// Skip over the name of an option: "&option", "&g:option" or "&l:option". diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 6593a34f4a..5a5293780d 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -1065,7 +1065,7 @@ static void f_count(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const size_t len = STRLEN(expr); while (*p != NUL) { - if (mb_strnicmp(p, expr, len) == 0) { + if (mb_strnicmp((char *)p, (char *)expr, len) == 0) { n++; p += len; } else { @@ -8687,7 +8687,7 @@ static void f_submatch(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (retList == 0) { rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char *)reg_submatch(no); + rettv->vval.v_string = reg_submatch(no); } else { rettv->v_type = VAR_LIST; rettv->vval.v_list = reg_submatch_list(no); diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 21bd662db5..bcaca0ca13 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1942,7 +1942,7 @@ void ex_function(exarg_T *eap) } } } - eap->nextcmd = (char *)check_nextcmd((char_u *)eap->arg); + eap->nextcmd = check_nextcmd(eap->arg); return; } @@ -1978,7 +1978,7 @@ void ex_function(exarg_T *eap) if (*p == '/') { p++; } - eap->nextcmd = (char *)check_nextcmd(p); + eap->nextcmd = check_nextcmd((char *)p); return; } @@ -2032,7 +2032,7 @@ void ex_function(exarg_T *eap) semsg(_(e_trailing_arg), p); goto ret_free; } - eap->nextcmd = (char *)check_nextcmd(p); + eap->nextcmd = check_nextcmd((char *)p); if (eap->nextcmd != NULL) { *p = NUL; } @@ -2590,8 +2590,8 @@ int eval_fname_script(const char *const p) // Use mb_strnicmp() because in Turkish comparing the "I" may not work with // the standard library function. if (p[0] == '<' - && (mb_strnicmp((char_u *)p + 1, (char_u *)"SID>", 4) == 0 - || mb_strnicmp((char_u *)p + 1, (char_u *)"SNR>", 4) == 0)) { + && (mb_strnicmp(p + 1, "SID>", 4) == 0 + || mb_strnicmp(p + 1, "SNR>", 4) == 0)) { return 5; } if (p[0] == 's' && p[1] == ':') { @@ -2700,7 +2700,7 @@ void ex_delfunction(exarg_T *eap) semsg(_(e_trailing_arg), p); return; } - eap->nextcmd = (char *)check_nextcmd(p); + eap->nextcmd = check_nextcmd((char *)p); if (eap->nextcmd != NULL) { *p = NUL; } @@ -2889,7 +2889,7 @@ void ex_return(exarg_T *eap) if (returning) { eap->nextcmd = NULL; } else if (eap->nextcmd == NULL) { // no argument - eap->nextcmd = (char *)check_nextcmd(arg); + eap->nextcmd = check_nextcmd((char *)arg); } if (eap->skip) { @@ -3018,7 +3018,7 @@ void ex_call(exarg_T *eap) semsg(_(e_trailing_arg), arg); } } else { - eap->nextcmd = (char *)check_nextcmd(arg); + eap->nextcmd = check_nextcmd((char *)arg); } } diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index dbbb03b1b8..ba58254bdd 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -207,7 +207,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) list_func_vars(&first); list_vim_vars(&first); } - eap->nextcmd = (char *)check_nextcmd((char_u *)arg); + eap->nextcmd = check_nextcmd(arg); } else if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<') { // HERE document list_T *l = heredoc_get(eap, expr + 3); @@ -824,7 +824,7 @@ static void ex_unletlock(exarg_T *eap, char *argstart, int deep, ex_unletlock_ca arg = skipwhite(name_end); } while (!ends_excmd(*arg)); - eap->nextcmd = (char *)check_nextcmd((char_u *)arg); + eap->nextcmd = check_nextcmd(arg); } // TODO(ZyX-I): move to eval/ex_cmds diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 17d45f207e..d050562e4c 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -509,8 +509,8 @@ void ex_sort(exarg_T *eap) } else if (*p == '"') { // comment start break; - } else if (check_nextcmd((char_u *)p) != NULL) { - eap->nextcmd = (char *)check_nextcmd((char_u *)p); + } else if (check_nextcmd(p) != NULL) { + eap->nextcmd = check_nextcmd(p); break; } else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) { s = skip_regexp(p + 1, *p, true, NULL); @@ -3625,7 +3625,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T */ cmd = skipwhite(cmd); if (*cmd && *cmd != '"') { // if not end-of-line or comment - eap->nextcmd = (char *)check_nextcmd((char_u *)cmd); + eap->nextcmd = check_nextcmd(cmd); if (eap->nextcmd == NULL) { semsg(_(e_trailing_arg), cmd); return 0; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 8f72ba0e23..01d141e557 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1929,7 +1929,7 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter // If we got a line, but no command, then go to the line. // If we find a '|' or '\n' we set ea.nextcmd. if (*ea.cmd == NUL || *ea.cmd == '"' - || (ea.nextcmd = (char *)check_nextcmd((char_u *)ea.cmd)) != NULL) { + || (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) { // strange vi behaviour: // ":3" jumps to line 3 // ":3|..." prints line 3 @@ -3934,7 +3934,7 @@ void separate_nextcmd(exarg_T *eap) STRMOVE(p - 1, p); // remove the '\' p--; } else { - eap->nextcmd = (char *)check_nextcmd((char_u *)p); + eap->nextcmd = check_nextcmd(p); *p = NUL; break; } @@ -4311,12 +4311,12 @@ char *find_nextcmd(const char *p) /// Check if *p is a separator between Ex commands, skipping over white space. /// /// @return NULL if it isn't, the following character if it is. -char_u *check_nextcmd(char_u *p) +char *check_nextcmd(char *p) { - char *s = skipwhite((char *)p); + char *s = skipwhite(p); if (*s == '|' || *s == '\n') { - return (char_u *)(s + 1); + return s + 1; } else { return NULL; } @@ -5674,7 +5674,7 @@ static void ex_wincmd(exarg_T *eap) p = eap->arg + 1; } - eap->nextcmd = (char *)check_nextcmd((char_u *)p); + eap->nextcmd = check_nextcmd(p); p = skipwhite(p); if (*p != NUL && *p != '"' && eap->nextcmd == NULL) { emsg(_(e_invarg)); @@ -6465,7 +6465,7 @@ static void ex_findpat(exarg_T *eap) if (!ends_excmd(*p)) { eap->errmsg = ex_errmsg(e_trailing_arg, p); } else { - eap->nextcmd = (char *)check_nextcmd((char_u *)p); + eap->nextcmd = check_nextcmd(p); } } } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index e8af99805d..9d1cebd43e 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -328,7 +328,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s int empty; *end = NUL; - empty = empty_pattern((char_u *)p); + empty = empty_pattern(p); *end = c; if (empty) { goto theend; @@ -489,7 +489,7 @@ static void may_do_incsearch_highlighting(int firstc, long count, incsearch_stat if (!use_last_pat) { next_char = ccline.cmdbuff[skiplen + patlen]; ccline.cmdbuff[skiplen + patlen] = NUL; - if (empty_pattern(ccline.cmdbuff) && !no_hlsearch) { + if (empty_pattern((char *)ccline.cmdbuff) && !no_hlsearch) { redraw_all_later(UPD_SOME_VALID); set_no_hlsearch(true); } @@ -2027,7 +2027,7 @@ static int command_line_not_changed(CommandLineState *s) /// Guess that the pattern matches everything. Only finds specific cases, such /// as a trailing \|, which can happen while typing a pattern. -static int empty_pattern(char_u *p) +static int empty_pattern(char *p) { size_t n = STRLEN(p); @@ -3952,8 +3952,9 @@ static int get_cmdline_type(void) /// Get the current command line in allocated memory. /// Only works when the command line is being edited. -/// Returns NULL when something is wrong. -static char_u *get_cmdline_str(void) +/// +/// @return NULL when something is wrong. +static char *get_cmdline_str(void) { if (cmdline_star > 0) { return NULL; @@ -3963,11 +3964,11 @@ static char_u *get_cmdline_str(void) if (p == NULL) { return NULL; } - return vim_strnsave(p->cmdbuff, (size_t)p->cmdlen); + return (char *)vim_strnsave(p->cmdbuff, (size_t)p->cmdlen); } /// Get the current command-line completion type. -static char_u *get_cmdline_completion(void) +static char *get_cmdline_completion(void) { if (cmdline_star > 0) { return NULL; @@ -3978,7 +3979,7 @@ static char_u *get_cmdline_completion(void) set_expand_context(p->xpc); char *cmd_compl = get_user_cmd_complete(p->xpc, p->xpc->xp_context); if (cmd_compl != NULL) { - return vim_strsave((char_u *)cmd_compl); + return xstrdup(cmd_compl); } } @@ -3989,14 +3990,14 @@ static char_u *get_cmdline_completion(void) void f_getcmdcompltype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char *)get_cmdline_completion(); + rettv->vval.v_string = get_cmdline_completion(); } /// "getcmdline()" function void f_getcmdline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char *)get_cmdline_str(); + rettv->vval.v_string = get_cmdline_str(); } /// "getcmdpos()" function diff --git a/src/nvim/fold.c b/src/nvim/fold.c index d8c864df5b..0f085df3d0 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -111,7 +111,7 @@ static int prev_lnum_lvl = -1; #define DONE_FOLD 2 // did find a fold static size_t foldstartmarkerlen; -static char_u *foldendmarker; +static char *foldendmarker; static size_t foldendmarkerlen; // Exported folding functions. {{{1 @@ -982,7 +982,7 @@ void foldAdjustVisual(void) } pos_T *start, *end; - char_u *ptr; + char *ptr; if (ltoreq(VIsual, curwin->w_cursor)) { start = &VIsual; @@ -995,7 +995,7 @@ void foldAdjustVisual(void) start->col = 0; } if (hasFolding(end->lnum, NULL, &end->lnum)) { - ptr = (char_u *)ml_get(end->lnum); + ptr = ml_get(end->lnum); end->col = (colnr_T)STRLEN(ptr); if (end->col > 0 && *p_sel == 'o') { end->col--; @@ -1556,7 +1556,7 @@ static void foldCreateMarkers(win_T *wp, pos_T start, pos_T end) } parseMarker(wp); - foldAddMarker(buf, start, (char_u *)wp->w_p_fmr, foldstartmarkerlen); + foldAddMarker(buf, start, wp->w_p_fmr, foldstartmarkerlen); foldAddMarker(buf, end, foldendmarker, foldendmarkerlen); // Update both changes here, to avoid all folds after the start are @@ -1573,22 +1573,22 @@ static void foldCreateMarkers(win_T *wp, pos_T start, pos_T end) // foldAddMarker() {{{2 /// Add "marker[markerlen]" in 'commentstring' to position `pos`. -static void foldAddMarker(buf_T *buf, pos_T pos, const char_u *marker, size_t markerlen) +static void foldAddMarker(buf_T *buf, pos_T pos, const char *marker, size_t markerlen) { - char_u *cms = (char_u *)buf->b_p_cms; - char_u *newline; - char_u *p = (char_u *)strstr(buf->b_p_cms, "%s"); + char *cms = buf->b_p_cms; + char *newline; + char *p = strstr(buf->b_p_cms, "%s"); bool line_is_comment = false; linenr_T lnum = pos.lnum; // Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end - char_u *line = ml_get_buf(buf, lnum, false); + char *line = (char *)ml_get_buf(buf, lnum, false); size_t line_len = STRLEN(line); size_t added = 0; if (u_save(lnum - 1, lnum + 1) == OK) { // Check if the line ends with an unclosed comment - skip_comment((char *)line, false, false, &line_is_comment); + skip_comment(line, false, false, &line_is_comment); newline = xmalloc(line_len + markerlen + STRLEN(cms) + 1); STRCPY(newline, line); // Append the marker to the end of the line @@ -1601,7 +1601,7 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char_u *marker, size_t ma STRCPY(newline + line_len + (p - cms) + markerlen, p + 2); added = markerlen + STRLEN(cms) - 2; } - ml_replace_buf(buf, lnum, (char *)newline, false); + ml_replace_buf(buf, lnum, newline, false); if (added) { extmark_splice_cols(buf, (int)lnum - 1, (int)line_len, 0, (int)added, kExtmarkUndo); @@ -1621,7 +1621,7 @@ static void deleteFoldMarkers(win_T *wp, fold_T *fp, int recursive, linenr_T lnu lnum_off + fp->fd_top); } } - foldDelMarker(wp->w_buffer, fp->fd_top + lnum_off, (char_u *)wp->w_p_fmr, + foldDelMarker(wp->w_buffer, fp->fd_top + lnum_off, wp->w_p_fmr, foldstartmarkerlen); foldDelMarker(wp->w_buffer, fp->fd_top + lnum_off + fp->fd_len - 1, foldendmarker, foldendmarkerlen); @@ -1632,16 +1632,16 @@ static void deleteFoldMarkers(win_T *wp, fold_T *fp, int recursive, linenr_T lnu /// Delete 'commentstring' if it matches. /// If the marker is not found, there is no error message. Could be a missing /// close-marker. -static void foldDelMarker(buf_T *buf, linenr_T lnum, char_u *marker, size_t markerlen) +static void foldDelMarker(buf_T *buf, linenr_T lnum, char *marker, size_t markerlen) { // end marker may be missing and fold extends below the last line if (lnum > buf->b_ml.ml_line_count) { return; } - char_u *cms = (char_u *)buf->b_p_cms; - char_u *line = ml_get_buf(buf, lnum, false); - for (char_u *p = line; *p != NUL; p++) { + char *cms = buf->b_p_cms; + char *line = (char *)ml_get_buf(buf, lnum, false); + for (char *p = line; *p != NUL; p++) { if (STRNCMP(p, marker, markerlen) != 0) { continue; } @@ -1652,7 +1652,7 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char_u *marker, size_t mark } if (*cms != NUL) { // Also delete 'commentstring' if it matches. - char_u *cms2 = (char_u *)strstr((char *)cms, "%s"); + char *cms2 = strstr(cms, "%s"); if (p - line >= cms2 - cms && STRNCMP(p - (cms2 - cms), cms, cms2 - cms) == 0 && STRNCMP(p + len, cms2 + 2, STRLEN(cms2 + 2)) == 0) { @@ -1662,11 +1662,11 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char_u *marker, size_t mark } if (u_save(lnum - 1, lnum + 1) == OK) { // Make new line: text-before-marker + text-after-marker - char_u *newline = xmalloc(STRLEN(line) - len + 1); + char *newline = xmalloc(STRLEN(line) - len + 1); assert(p >= line); memcpy(newline, line, (size_t)(p - line)); STRCPY(newline + (p - line), p + len); - ml_replace_buf(buf, lnum, (char *)newline, false); + ml_replace_buf(buf, lnum, newline, false); extmark_splice_cols(buf, (int)lnum - 1, (int)(p - line), (int)len, 0, kExtmarkUndo); } @@ -1683,10 +1683,10 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char_u *marker, size_t mark /// @return the text for a closed fold /// /// Otherwise the result is in allocated memory. -char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo, char_u *buf) +char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo, char *buf) FUNC_ATTR_NONNULL_ARG(1) { - char_u *text = NULL; + char *text = NULL; // an error occurred when evaluating 'fdt' setting static bool got_fdt_error = false; int save_did_emsg = did_emsg; @@ -1728,9 +1728,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin curbuf = wp->w_buffer; emsg_silent++; // handle exceptions, but don't display errors - text = - (char_u *)eval_to_string_safe(wp->w_p_fdt, NULL, - was_set_insecurely(wp, "foldtext", OPT_LOCAL)); + text = eval_to_string_safe(wp->w_p_fdt, NULL, was_set_insecurely(wp, "foldtext", OPT_LOCAL)); emsg_silent--; if (text == NULL || did_emsg) { @@ -1751,23 +1749,23 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin if (text != NULL) { // Replace unprintable characters, if there are any. But // replace a TAB with a space. - char_u *p; + char *p; for (p = text; *p != NUL; p++) { - int len = utfc_ptr2len((char *)p); + int len = utfc_ptr2len(p); if (len > 1) { - if (!vim_isprintc(utf_ptr2char((char *)p))) { + if (!vim_isprintc(utf_ptr2char(p))) { break; } p += len - 1; } else if (*p == TAB) { *p = ' '; - } else if (ptr2cells((char *)p) > 1) { + } else if (ptr2cells(p) > 1) { break; } } if (*p != NUL) { - p = (char_u *)transstr((const char *)text, true); + p = transstr((const char *)text, true); xfree(text); text = p; } @@ -1776,7 +1774,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin if (text == NULL) { unsigned long count = (unsigned long)(lnume - lnum + 1); - vim_snprintf((char *)buf, FOLD_TEXT_LEN, + vim_snprintf(buf, FOLD_TEXT_LEN, NGETTEXT("+--%3ld line folded", "+--%3ld lines folded ", count), count); @@ -1787,17 +1785,17 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin // foldtext_cleanup() {{{2 /// Remove 'foldmarker' and 'commentstring' from "str" (in-place). -static void foldtext_cleanup(char_u *str) +static void foldtext_cleanup(char *str) { // Ignore leading and trailing white space in 'commentstring'. - char_u *cms_start = (char_u *)skipwhite(curbuf->b_p_cms); + char *cms_start = skipwhite(curbuf->b_p_cms); size_t cms_slen = STRLEN(cms_start); while (cms_slen > 0 && ascii_iswhite(cms_start[cms_slen - 1])) { cms_slen--; } // locate "%s" in 'commentstring', use the part before and after it. - char_u *cms_end = (char_u *)strstr((char *)cms_start, "%s"); + char *cms_end = strstr(cms_start, "%s"); size_t cms_elen = 0; if (cms_end != NULL) { cms_elen = cms_slen - (size_t)(cms_end - cms_start); @@ -1809,7 +1807,7 @@ static void foldtext_cleanup(char_u *str) } // skip "%s" and white space after it - char_u *s = (char_u *)skipwhite((char *)cms_end + 2); + char *s = skipwhite(cms_end + 2); cms_elen -= (size_t)(s - cms_end); cms_end = s; } @@ -1818,7 +1816,7 @@ static void foldtext_cleanup(char_u *str) bool did1 = false; bool did2 = false; - for (char_u *s = str; *s != NUL;) { + for (char *s = str; *s != NUL;) { size_t len = 0; if (STRNCMP(s, curwin->w_p_fmr, foldstartmarkerlen) == 0) { len = foldstartmarkerlen; @@ -1832,7 +1830,7 @@ static void foldtext_cleanup(char_u *str) // May remove 'commentstring' start. Useful when it's a double // quote and we already removed a double quote. - char_u *p; + char *p; for (p = s; p > str && ascii_iswhite(p[-1]); p--) {} if (p >= str + cms_slen && STRNCMP(p - cms_slen, cms_start, cms_slen) == 0) { @@ -2850,7 +2848,7 @@ static void foldlevelIndent(fline_T *flp) linenr_T lnum = flp->lnum + flp->off; buf_T *buf = flp->wp->w_buffer; - char_u *s = (char_u *)skipwhite((char *)ml_get_buf(buf, lnum, false)); + char *s = skipwhite((char *)ml_get_buf(buf, lnum, false)); // empty line or lines starting with a character in 'foldignore': level // depends on surrounding lines @@ -2985,8 +2983,8 @@ static void foldlevelExpr(fline_T *flp) /// Relies on the option value to have been checked for correctness already. static void parseMarker(win_T *wp) { - foldendmarker = (char_u *)vim_strchr(wp->w_p_fmr, ','); - foldstartmarkerlen = (size_t)(foldendmarker++ - (char_u *)wp->w_p_fmr); + foldendmarker = vim_strchr(wp->w_p_fmr, ','); + foldstartmarkerlen = (size_t)(foldendmarker++ - wp->w_p_fmr); foldendmarkerlen = STRLEN(foldendmarker); } @@ -3003,23 +3001,23 @@ static void foldlevelMarker(fline_T *flp) int start_lvl = flp->lvl; // cache a few values for speed - char_u *startmarker = (char_u *)flp->wp->w_p_fmr; - int cstart = *startmarker; + char *startmarker = flp->wp->w_p_fmr; + int cstart = (unsigned char)(*startmarker); startmarker++; - int cend = *foldendmarker; + int cend = (unsigned char)(*foldendmarker); // Default: no start found, next level is same as current level flp->start = 0; flp->lvl_next = flp->lvl; - char_u *s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false); + char *s = (char *)ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false); while (*s) { if (*s == cstart && STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0) { // found startmarker: set flp->lvl s += foldstartmarkerlen; if (ascii_isdigit(*s)) { - int n = atoi((char *)s); + int n = atoi(s); if (n > 0) { flp->lvl = n; flp->lvl_next = n; @@ -3039,7 +3037,7 @@ static void foldlevelMarker(fline_T *flp) // found endmarker: set flp->lvl_next s += foldendmarkerlen; if (ascii_isdigit(*s)) { - int n = atoi((char *)s); + int n = atoi(s); if (n > 0) { flp->lvl = n; flp->lvl_next = n - 1; @@ -3240,7 +3238,7 @@ void f_foldtext(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) linenr_T foldstart = (linenr_T)get_vim_var_nr(VV_FOLDSTART); linenr_T foldend = (linenr_T)get_vim_var_nr(VV_FOLDEND); - char_u *dashes = (char_u *)get_vim_var_str(VV_FOLDDASHES); + char *dashes = get_vim_var_str(VV_FOLDDASHES); if (foldstart > 0 && foldend <= curbuf->b_ml.ml_line_count) { // Find first non-empty line in the fold. linenr_T lnum; @@ -3268,20 +3266,20 @@ void f_foldtext(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) + STRLEN(dashes) // for %s + 20 // for %3ld + STRLEN(s); // concatenated - char_u *r = xmalloc(len); - snprintf((char *)r, len, txt, dashes, count); + char *r = xmalloc(len); + snprintf(r, len, txt, dashes, count); len = STRLEN(r); STRCAT(r, s); // remove 'foldmarker' and 'commentstring' foldtext_cleanup(r + len); - rettv->vval.v_string = (char *)r; + rettv->vval.v_string = r; } } /// "foldtextresult(lnum)" function void f_foldtextresult(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - char_u buf[FOLD_TEXT_LEN]; + char buf[FOLD_TEXT_LEN]; static bool entered = false; rettv->v_type = VAR_STRING; @@ -3298,11 +3296,11 @@ void f_foldtextresult(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) foldinfo_T info = fold_info(curwin, lnum); if (info.fi_lines > 0) { - char_u *text = get_foldtext(curwin, lnum, lnum + info.fi_lines - 1, info, buf); + char *text = get_foldtext(curwin, lnum, lnum + info.fi_lines - 1, info, buf); if (text == buf) { - text = vim_strsave(text); + text = xstrdup(text); } - rettv->vval.v_string = (char *)text; + rettv->vval.v_string = text; } entered = false; diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index f592b54f67..947594be4f 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1541,17 +1541,16 @@ ssize_t mb_utf_index_to_bytes(const char_u *s, size_t len, size_t index, bool us return -1; } -/* - * Version of strnicmp() that handles multi-byte characters. - * Needed for Big5, Shift-JIS and UTF-8 encoding. Other DBCS encodings can - * probably use strnicmp(), because there are no ASCII characters in the - * second byte. - * Returns zero if s1 and s2 are equal (ignoring case), the difference between - * two characters otherwise. - */ -int mb_strnicmp(const char_u *s1, const char_u *s2, const size_t nn) +/// Version of strnicmp() that handles multi-byte characters. +/// Needed for Big5, Shift-JIS and UTF-8 encoding. Other DBCS encodings can +/// probably use strnicmp(), because there are no ASCII characters in the +/// second byte. +/// +/// @return zero if s1 and s2 are equal (ignoring case), the difference between +/// two characters otherwise. +int mb_strnicmp(const char *s1, const char *s2, const size_t nn) { - return utf_strnicmp(s1, s2, nn, nn); + return utf_strnicmp((char_u *)s1, (char_u *)s2, nn, nn); } /// Compare strings case-insensitively @@ -1568,7 +1567,7 @@ int mb_strnicmp(const char_u *s1, const char_u *s2, const size_t nn) /// @return 0 if strings are equal, <0 if s1 < s2, >0 if s1 > s2. int mb_stricmp(const char *s1, const char *s2) { - return mb_strnicmp((const char_u *)s1, (const char_u *)s2, MAXCOL); + return mb_strnicmp(s1, s2, MAXCOL); } /* diff --git a/src/nvim/path.c b/src/nvim/path.c index 5bbcbc7144..8973d4dfdb 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -384,7 +384,7 @@ int path_fnamencmp(const char *const fname1, const char *const fname2, size_t le return p_fic ? CH_FOLD(c1) - CH_FOLD(c2) : c1 - c2; #else if (p_fic) { - return mb_strnicmp((const char_u *)fname1, (const char_u *)fname2, len); + return mb_strnicmp(fname1, fname2, len); } return strncmp(fname1, fname2, len); #endif diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index f471f1c8e0..563d85964c 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1282,7 +1282,7 @@ static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T e len = (int)STRLEN(p + ccol); } - if (cstrncmp(p + ccol, rex.input, &len) != 0) { + if (cstrncmp((char *)p + ccol, (char *)rex.input, &len) != 0) { return RA_NOMATCH; // doesn't match } if (bytelen != NULL) { @@ -1395,10 +1395,10 @@ static void mb_decompose(int c, int *c1, int *c2, int *c3) } } -// Compare two strings, ignore case if rex.reg_ic set. -// Return 0 if strings match, non-zero otherwise. -// Correct the length "*n" when composing characters are ignored. -static int cstrncmp(char_u *s1, char_u *s2, int *n) +/// Compare two strings, ignore case if rex.reg_ic set. +/// Return 0 if strings match, non-zero otherwise. +/// Correct the length "*n" when composing characters are ignored. +static int cstrncmp(char *s1, char *s2, int *n) { int result; @@ -1406,12 +1406,12 @@ static int cstrncmp(char_u *s1, char_u *s2, int *n) result = STRNCMP(s1, s2, *n); } else { assert(*n >= 0); - result = mb_strnicmp(s1, s2, (size_t)*n); + result = mb_strnicmp(s1, s2, (size_t)(*n)); } // if it failed and it's utf8 and we want to combineignore: if (result != 0 && rex.reg_icombine) { - char_u *str1, *str2; + char *str1, *str2; int c1, c2, c11, c12; int junk; @@ -2112,36 +2112,33 @@ exit: return (int)((dst - dest) + 1); } -/* - * Call reg_getline() with the line numbers from the submatch. If a - * substitute() was used the reg_maxline and other values have been - * overwritten. - */ -static char_u *reg_getline_submatch(linenr_T lnum) +/// Call reg_getline() with the line numbers from the submatch. If a +/// substitute() was used the reg_maxline and other values have been +/// overwritten. +static char *reg_getline_submatch(linenr_T lnum) { - char_u *s; + char *s; linenr_T save_first = rex.reg_firstlnum; linenr_T save_max = rex.reg_maxline; rex.reg_firstlnum = rsm.sm_firstlnum; rex.reg_maxline = rsm.sm_maxline; - s = reg_getline(lnum); + s = (char *)reg_getline(lnum); rex.reg_firstlnum = save_first; rex.reg_maxline = save_max; return s; } -/* - * Used for the submatch() function: get the string from the n'th submatch in - * allocated memory. - * Returns NULL when not in a ":s" command and for a non-existing submatch. - */ -char_u *reg_submatch(int no) +/// Used for the submatch() function: get the string from the n'th submatch in +/// allocated memory. +/// +/// @return NULL when not in a ":s" command and for a non-existing submatch. +char *reg_submatch(int no) { - char_u *retval = NULL; - char_u *s; + char *retval = NULL; + char *s; int round; linenr_T lnum; @@ -2211,11 +2208,11 @@ char_u *reg_submatch(int no) } } } else { - s = rsm.sm_match->startp[no]; + s = (char *)rsm.sm_match->startp[no]; if (s == NULL || rsm.sm_match->endp[no] == NULL) { retval = NULL; } else { - retval = vim_strnsave(s, (size_t)(rsm.sm_match->endp[no] - s)); + retval = xstrnsave(s, (size_t)(rsm.sm_match->endp[no] - (char_u *)s)); } } @@ -2250,16 +2247,16 @@ list_T *reg_submatch_list(int no) list = tv_list_alloc(elnum - slnum + 1); - s = (const char *)reg_getline_submatch(slnum) + scol; + s = reg_getline_submatch(slnum) + scol; if (slnum == elnum) { tv_list_append_string(list, s, ecol - scol); } else { tv_list_append_string(list, s, -1); for (int i = 1; i < elnum - slnum; i++) { - s = (const char *)reg_getline_submatch(slnum + i); + s = reg_getline_submatch(slnum + i); tv_list_append_string(list, s, -1); } - s = (const char *)reg_getline_submatch(elnum); + s = reg_getline_submatch(elnum); tv_list_append_string(list, s, ecol); } } else { diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c index b951df69d6..9b9b33b09f 100644 --- a/src/nvim/regexp_bt.c +++ b/src/nvim/regexp_bt.c @@ -4039,7 +4039,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) } else { // Need to match first byte again for multi-byte. len = (int)STRLEN(opnd); - if (cstrncmp(opnd, rex.input, &len) != 0) { + if (cstrncmp((char *)opnd, (char *)rex.input, &len) != 0) { status = RA_NOMATCH; } } @@ -4270,7 +4270,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) } else { // Compare current input with back-ref in the same line. len = (int)(rex.reg_endp[no] - rex.reg_startp[no]); - if (cstrncmp(rex.reg_startp[no], rex.input, &len) != 0) { + if (cstrncmp((char *)rex.reg_startp[no], (char *)rex.input, &len) != 0) { status = RA_NOMATCH; } } @@ -4283,8 +4283,8 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) && rex.reg_endpos[no].lnum == rex.lnum) { // Compare back-ref within the current line. len = rex.reg_endpos[no].col - rex.reg_startpos[no].col; - if (cstrncmp(rex.line + rex.reg_startpos[no].col, - rex.input, &len) != 0) { + if (cstrncmp((char *)rex.line + rex.reg_startpos[no].col, + (char *)rex.input, &len) != 0) { status = RA_NOMATCH; } } else { @@ -4320,7 +4320,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) if (re_extmatch_in != NULL && re_extmatch_in->matches[no] != NULL) { int len = (int)STRLEN(re_extmatch_in->matches[no]); - if (cstrncmp(re_extmatch_in->matches[no], rex.input, &len) != 0) { + if (cstrncmp((char *)re_extmatch_in->matches[no], (char *)rex.input, &len) != 0) { status = RA_NOMATCH; } else { rex.input += len; @@ -5069,14 +5069,14 @@ static long bt_regexec_both(char_u *line, colnr_T col, proftime_T *tm, int *time // the loop to avoid overhead of conditions. if (!rex.reg_ic) { while ((s = (char_u *)vim_strchr((char *)s, c)) != NULL) { - if (cstrncmp(s, prog->regmust, &prog->regmlen) == 0) { + if (cstrncmp((char *)s, (char *)prog->regmust, &prog->regmlen) == 0) { break; // Found it. } MB_PTR_ADV(s); } } else { while ((s = cstrchr(s, c)) != NULL) { - if (cstrncmp(s, prog->regmust, &prog->regmlen) == 0) { + if (cstrncmp((char *)s, (char *)prog->regmust, &prog->regmlen) == 0) { break; // Found it. } MB_PTR_ADV(s); diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index e1327ce155..d01404b5c2 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -5421,8 +5421,8 @@ retempty: && sub->list.multi[subidx].end_lnum == rex.lnum) { len = sub->list.multi[subidx].end_col - sub->list.multi[subidx].start_col; - if (cstrncmp(rex.line + sub->list.multi[subidx].start_col, - rex.input, &len) == 0) { + if (cstrncmp((char *)rex.line + sub->list.multi[subidx].start_col, + (char *)rex.input, &len) == 0) { *bytelen = len; return true; } @@ -5441,7 +5441,7 @@ retempty: goto retempty; } len = (int)(sub->list.line[subidx].end - sub->list.line[subidx].start); - if (cstrncmp(sub->list.line[subidx].start, rex.input, &len) == 0) { + if (cstrncmp((char *)sub->list.line[subidx].start, (char *)rex.input, &len) == 0) { *bytelen = len; return true; } @@ -5466,7 +5466,7 @@ static int match_zref(int subidx, int *bytelen) } len = (int)STRLEN(re_extmatch_in->matches[subidx]); - if (cstrncmp(re_extmatch_in->matches[subidx], rex.input, &len) == 0) { + if (cstrncmp((char *)re_extmatch_in->matches[subidx], (char *)rex.input, &len) == 0) { *bytelen = len; return true; } diff --git a/src/nvim/search.c b/src/nvim/search.c index d7f8d4e1cd..226d949825 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1504,7 +1504,7 @@ int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char_u *pat) } else if (*p != NUL) { // Ignore empty lines. // Expanding lines or words. assert(ins_compl_len() >= 0); - if ((p_ic ? mb_strnicmp(p, pat, (size_t)ins_compl_len()) + if ((p_ic ? mb_strnicmp((char *)p, (char *)pat, (size_t)ins_compl_len()) : STRNCMP(p, pat, ins_compl_len())) == 0) { return OK; } @@ -3792,7 +3792,7 @@ search_line: // compare the first "len" chars from "ptr" startp = (char_u *)skipwhite((char *)p); if (p_ic) { - matched = !mb_strnicmp(startp, ptr, len); + matched = !mb_strnicmp((char *)startp, (char *)ptr, len); } else { matched = !STRNCMP(startp, ptr, len); } diff --git a/src/nvim/shada.c b/src/nvim/shada.c index d2f1b39ca4..e20bce5b34 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -4001,7 +4001,7 @@ static bool shada_removable(const char *name) if (part[0] == 'r') { home_replace(NULL, part + 1, (char *)NameBuff, MAXPATHL, true); size_t n = STRLEN(NameBuff); - if (mb_strnicmp((char_u *)NameBuff, (char_u *)new_name, n) == 0) { + if (mb_strnicmp(NameBuff, new_name, n) == 0) { retval = true; break; } diff --git a/src/nvim/sign.c b/src/nvim/sign.c index ed7f53d3ba..7d931a853b 100644 --- a/src/nvim/sign.c +++ b/src/nvim/sign.c @@ -26,11 +26,11 @@ typedef struct sign sign_T; struct sign { - sign_T *sn_next; // next sign in list + sign_T *sn_next; // next sign in list int sn_typenr; // type number of sign - char_u *sn_name; // name of sign - char_u *sn_icon; // name of pixmap - char_u *sn_text; // text used instead of pixmap + char *sn_name; // name of sign + char *sn_icon; // name of pixmap + char *sn_text; // text used instead of pixmap int sn_line_hl; // highlight ID for line int sn_text_hl; // highlight ID for text int sn_cul_hl; // highlight ID for text on current line when 'cursorline' is set @@ -71,14 +71,13 @@ void init_signs(void) /// A new sign in group 'groupname' is added. If the group is not present, /// create it. Otherwise reference the group. -/// -static signgroup_T *sign_group_ref(const char_u *groupname) +static signgroup_T *sign_group_ref(const char *groupname) { hash_T hash; hashitem_T *hi; signgroup_T *group; - hash = hash_hash(groupname); + hash = hash_hash((char_u *)groupname); hi = hash_lookup(&sg_table, (char *)groupname, STRLEN(groupname), hash); if (HASHITEM_EMPTY(hi)) { // new group @@ -99,11 +98,11 @@ static signgroup_T *sign_group_ref(const char_u *groupname) /// A sign in group 'groupname' is removed. If all the signs in this group are /// removed, then remove the group. -static void sign_group_unref(char_u *groupname) +static void sign_group_unref(char *groupname) { signgroup_T *group; - hashitem_T *hi = hash_find(&sg_table, (char *)groupname); + hashitem_T *hi = hash_find(&sg_table, groupname); if (!HASHITEM_EMPTY(hi)) { group = HI2SG(hi); group->sg_refcount--; @@ -118,7 +117,7 @@ static void sign_group_unref(char_u *groupname) /// @return true if 'sign' is in 'group'. /// A sign can either be in the global group (sign->group == NULL) /// or in a named group. If 'group' is '*', then the sign is part of the group. -static bool sign_in_group(sign_entry_T *sign, const char_u *group) +static bool sign_in_group(sign_entry_T *sign, const char *group) { return ((group != NULL && STRCMP(group, "*") == 0) || (group == NULL && sign->se_group == NULL) @@ -127,7 +126,7 @@ static bool sign_in_group(sign_entry_T *sign, const char_u *group) } /// Get the next free sign identifier in the specified group -static int sign_group_get_next_signid(buf_T *buf, const char_u *groupname) +static int sign_group_get_next_signid(buf_T *buf, const char *groupname) { int id = 1; signgroup_T *group = NULL; @@ -154,7 +153,7 @@ static int sign_group_get_next_signid(buf_T *buf, const char_u *groupname) // Check whether this sign is already placed in the buffer found = true; FOR_ALL_SIGNS_IN_BUF(buf, sign) { - if (id == sign->se_id && sign_in_group(sign, groupname)) { + if (id == sign->se_id && sign_in_group(sign, (char *)groupname)) { found = false; // sign identifier is in use break; } @@ -177,7 +176,7 @@ static int sign_group_get_next_signid(buf_T *buf, const char_u *groupname) /// @param typenr typenr of sign we are adding /// @param has_text_or_icon sign has text or icon static void insert_sign(buf_T *buf, sign_entry_T *prev, sign_entry_T *next, int id, - const char_u *group, int prio, linenr_T lnum, int typenr, + const char *group, int prio, linenr_T lnum, int typenr, bool has_text_or_icon) { sign_entry_T *newsign = xmalloc(sizeof(sign_entry_T)); @@ -224,7 +223,7 @@ static void insert_sign(buf_T *buf, sign_entry_T *prev, sign_entry_T *next, int /// @param lnum line number which gets the mark /// @param typenr typenr of sign we are adding /// @param has_text_or_icon sign has text or icon -static void insert_sign_by_lnum_prio(buf_T *buf, sign_entry_T *prev, int id, const char_u *group, +static void insert_sign_by_lnum_prio(buf_T *buf, sign_entry_T *prev, int id, const char *group, int prio, linenr_T lnum, int typenr, bool has_text_or_icon) { sign_entry_T *sign; @@ -259,7 +258,7 @@ static sign_T *find_sign_by_typenr(int typenr) } /// Get the name of a sign by its typenr. -static char_u *sign_typenr2name(int typenr) +static char *sign_typenr2name(int typenr) { sign_T *sp; @@ -268,7 +267,7 @@ static char_u *sign_typenr2name(int typenr) return sp->sn_name; } } - return (char_u *)_("[Deleted]"); + return _("[Deleted]"); } /// Return information about a sign in a Dict @@ -280,7 +279,7 @@ static dict_T *sign_get_info(sign_entry_T *sign) ? (char *)"" : (char *)sign->se_group->sg_name)); tv_dict_add_nr(d, S_LEN("lnum"), sign->se_lnum); - tv_dict_add_str(d, S_LEN("name"), (char *)sign_typenr2name(sign->se_typenr)); + tv_dict_add_str(d, S_LEN("name"), sign_typenr2name(sign->se_typenr)); tv_dict_add_nr(d, S_LEN("priority"), sign->se_priority); return d; @@ -369,7 +368,7 @@ static void sign_sort_by_prio_on_line(buf_T *buf, sign_entry_T *sign) /// @param lnum line number which gets the mark /// @param typenr typenr of sign we are adding /// @param has_text_or_icon sign has text or icon -static void buf_addsign(buf_T *buf, int id, const char_u *groupname, int prio, linenr_T lnum, +static void buf_addsign(buf_T *buf, int id, const char *groupname, int prio, linenr_T lnum, int typenr, bool has_text_or_icon) { sign_entry_T *sign; // a sign in the signlist @@ -416,13 +415,13 @@ static void buf_addsign(buf_T *buf, int id, const char_u *groupname, int prio, l /// @param group sign group /// @param typenr typenr of sign we are adding /// @param prio sign priority -static linenr_T buf_change_sign_type(buf_T *buf, int markId, const char_u *group, int typenr, +static linenr_T buf_change_sign_type(buf_T *buf, int markId, const char *group, int typenr, int prio) { sign_entry_T *sign; // a sign in the signlist FOR_ALL_SIGNS_IN_BUF(buf, sign) { - if (sign->se_id == markId && sign_in_group(sign, group)) { + if (sign->se_id == markId && sign_in_group(sign, (char *)group)) { sign->se_typenr = typenr; sign->se_priority = prio; sign_sort_by_prio_on_line(buf, sign); @@ -534,7 +533,7 @@ int buf_get_signattrs(buf_T *buf, linenr_T lnum, SignTextAttrs sattrs[], HlPriAt /// /// @return the line number of the deleted sign. If multiple signs are deleted, /// then returns the line number of the last sign deleted. -static linenr_T buf_delsign(buf_T *buf, linenr_T atlnum, int id, char_u *group) +static linenr_T buf_delsign(buf_T *buf, linenr_T atlnum, int id, char *group) { sign_entry_T **lastp; // pointer to pointer to current sign sign_entry_T *sign; // a sign in a b_signlist @@ -555,7 +554,7 @@ static linenr_T buf_delsign(buf_T *buf, linenr_T atlnum, int id, char_u *group) lnum = sign->se_lnum; buf_signcols_del_check(buf, lnum, lnum); if (sign->se_group != NULL) { - sign_group_unref(sign->se_group->sg_name); + sign_group_unref((char *)sign->se_group->sg_name); } xfree(sign); redraw_buf_line_later(buf, lnum); @@ -590,7 +589,7 @@ static linenr_T buf_delsign(buf_T *buf, linenr_T atlnum, int id, char_u *group) /// @param buf buffer to store sign in /// @param id sign ID /// @param group sign group -static int buf_findsign(buf_T *buf, int id, char_u *group) +static int buf_findsign(buf_T *buf, int id, char *group) { sign_entry_T *sign; // a sign in the signlist @@ -609,7 +608,7 @@ static int buf_findsign(buf_T *buf, int id, char_u *group) /// @param buf buffer whose sign we are searching for /// @param lnum line number of sign /// @param groupname sign group name -static sign_entry_T *buf_getsign_at_line(buf_T *buf, linenr_T lnum, char_u *groupname) +static sign_entry_T *buf_getsign_at_line(buf_T *buf, linenr_T lnum, char *groupname) { sign_entry_T *sign; // a sign in the signlist @@ -633,7 +632,7 @@ static sign_entry_T *buf_getsign_at_line(buf_T *buf, linenr_T lnum, char_u *grou /// @param buf buffer whose sign we are searching for /// @param lnum line number of sign /// @param groupname sign group name -static int buf_findsign_id(buf_T *buf, linenr_T lnum, char_u *groupname) +static int buf_findsign_id(buf_T *buf, linenr_T lnum, char *groupname) { sign_entry_T *sign; // a sign in the signlist @@ -661,13 +660,13 @@ void buf_delete_signs(buf_T *buf, char *group) lastp = &buf->b_signlist; for (sign = buf->b_signlist; sign != NULL; sign = next) { next = sign->se_next; - if (sign_in_group(sign, (char_u *)group)) { + if (sign_in_group(sign, group)) { *lastp = next; if (next != NULL) { next->se_prev = sign->se_prev; } if (sign->se_group != NULL) { - sign_group_unref(sign->se_group->sg_name); + sign_group_unref((char *)sign->se_group->sg_name); } xfree(sign); } else { @@ -678,7 +677,7 @@ void buf_delete_signs(buf_T *buf, char *group) } /// List placed signs for "rbuf". If "rbuf" is NULL do it for all buffers. -static void sign_list_placed(buf_T *rbuf, char_u *sign_group) +static void sign_list_placed(buf_T *rbuf, char *sign_group) { buf_T *buf; sign_entry_T *sign; @@ -778,12 +777,12 @@ void sign_mark_adjust(linenr_T line1, linenr_T line2, linenr_T amount, linenr_T /// /// @param begin_cmd begin of sign subcmd /// @param end_cmd just after sign subcmd -static int sign_cmd_idx(char_u *begin_cmd, char_u *end_cmd) +static int sign_cmd_idx(char *begin_cmd, char *end_cmd) { int idx; - char_u save = *end_cmd; + char save = *end_cmd; - *end_cmd = (char_u)NUL; + *end_cmd = NUL; for (idx = 0;; idx++) { if (cmds[idx] == NULL || STRCMP(begin_cmd, cmds[idx]) == 0) { break; @@ -794,7 +793,7 @@ static int sign_cmd_idx(char_u *begin_cmd, char_u *end_cmd) } /// Find a sign by name. Also returns pointer to the previous sign. -static sign_T *sign_find(const char_u *name, sign_T **sp_prev) +static sign_T *sign_find(const char *name, sign_T **sp_prev) { sign_T *sp; @@ -814,7 +813,7 @@ static sign_T *sign_find(const char_u *name, sign_T **sp_prev) } /// Allocate a new sign -static sign_T *alloc_new_sign(char_u *name) +static sign_T *alloc_new_sign(char *name) { sign_T *sp; sign_T *lp; @@ -848,24 +847,24 @@ static sign_T *alloc_new_sign(char_u *name) next_sign_typenr = 1; // wrap around } - sp->sn_name = vim_strsave(name); + sp->sn_name = xstrdup(name); return sp; } /// Initialize the icon information for a new sign -static void sign_define_init_icon(sign_T *sp, char_u *icon) +static void sign_define_init_icon(sign_T *sp, char *icon) { xfree(sp->sn_icon); - sp->sn_icon = vim_strsave(icon); - backslash_halve((char *)sp->sn_icon); + sp->sn_icon = xstrdup(icon); + backslash_halve(sp->sn_icon); } /// Initialize the text for a new sign -static int sign_define_init_text(sign_T *sp, char_u *text) +static int sign_define_init_text(sign_T *sp, char *text) { - char_u *s; - char_u *endp; + char *s; + char *endp; int cells; size_t len; @@ -880,11 +879,11 @@ static int sign_define_init_text(sign_T *sp, char_u *text) } // Count cells and check for non-printable chars cells = 0; - for (s = text; s < endp; s += utfc_ptr2len((char *)s)) { - if (!vim_isprintc(utf_ptr2char((char *)s))) { + for (s = text; s < endp; s += utfc_ptr2len(s)) { + if (!vim_isprintc(utf_ptr2char(s))) { break; } - cells += utf_ptr2cells((char *)s); + cells += utf_ptr2cells(s); } // Currently must be empty, one or two display cells if (s != endp || cells > 2) { @@ -900,7 +899,7 @@ static int sign_define_init_text(sign_T *sp, char_u *text) // Allocate one byte more if we need to pad up // with a space. len = (size_t)(endp - text + ((cells == 1) ? 1 : 0)); - sp->sn_text = vim_strnsave(text, len); + sp->sn_text = xstrnsave(text, len); if (cells == 1) { STRCPY(sp->sn_text + len - 1, " "); @@ -910,8 +909,8 @@ static int sign_define_init_text(sign_T *sp, char_u *text) } /// Define a new sign or update an existing sign -static int sign_define_by_name(char_u *name, char_u *icon, char_u *linehl, char_u *text, - char_u *texthl, char_u *culhl, char *numhl) +static int sign_define_by_name(char *name, char *icon, char *linehl, char *text, char *texthl, + char *culhl, char *numhl) { sign_T *sp_prev; sign_T *sp; @@ -952,7 +951,7 @@ static int sign_define_by_name(char_u *name, char_u *icon, char_u *linehl, char_ if (*linehl == NUL) { sp->sn_line_hl = 0; } else { - sp->sn_line_hl = syn_check_group((char *)linehl, STRLEN(linehl)); + sp->sn_line_hl = syn_check_group(linehl, STRLEN(linehl)); } } @@ -960,7 +959,7 @@ static int sign_define_by_name(char_u *name, char_u *icon, char_u *linehl, char_ if (*texthl == NUL) { sp->sn_text_hl = 0; } else { - sp->sn_text_hl = syn_check_group((char *)texthl, STRLEN(texthl)); + sp->sn_text_hl = syn_check_group(texthl, STRLEN(texthl)); } } @@ -968,7 +967,7 @@ static int sign_define_by_name(char_u *name, char_u *icon, char_u *linehl, char_ if (*culhl == NUL) { sp->sn_cul_hl = 0; } else { - sp->sn_cul_hl = syn_check_group((char *)culhl, STRLEN(culhl)); + sp->sn_cul_hl = syn_check_group(culhl, STRLEN(culhl)); } } @@ -984,7 +983,7 @@ static int sign_define_by_name(char_u *name, char_u *icon, char_u *linehl, char_ } /// Free the sign specified by 'name'. -static int sign_undefine_by_name(const char_u *name) +static int sign_undefine_by_name(const char *name) { sign_T *sp_prev; sign_T *sp; @@ -1000,7 +999,7 @@ static int sign_undefine_by_name(const char_u *name) } /// List the signs matching 'name' -static void sign_list_by_name(char_u *name) +static void sign_list_by_name(char *name) { sign_T *sp; @@ -1024,7 +1023,7 @@ static void may_force_numberwidth_recompute(buf_T *buf, int unplace) } /// Place a sign at the specified file location or update a sign. -static int sign_place(int *sign_id, const char_u *sign_group, const char_u *sign_name, buf_T *buf, +static int sign_place(int *sign_id, const char *sign_group, const char *sign_name, buf_T *buf, linenr_T lnum, int prio) { sign_T *sp; @@ -1044,7 +1043,7 @@ static int sign_place(int *sign_id, const char_u *sign_group, const char_u *sign return FAIL; } if (*sign_id == 0) { - *sign_id = sign_group_get_next_signid(buf, sign_group); + *sign_id = sign_group_get_next_signid(buf, (char *)sign_group); } if (lnum > 0) { @@ -1053,14 +1052,14 @@ static int sign_place(int *sign_id, const char_u *sign_group, const char_u *sign bool has_text_or_icon = sp->sn_text != NULL || sp->sn_icon != NULL; buf_addsign(buf, *sign_id, - sign_group, + (char *)sign_group, prio, lnum, sp->sn_typenr, has_text_or_icon); } else { // ":sign place {id} file={fname}": change sign type and/or priority - lnum = buf_change_sign_type(buf, *sign_id, sign_group, sp->sn_typenr, prio); + lnum = buf_change_sign_type(buf, *sign_id, (char *)sign_group, sp->sn_typenr, prio); } if (lnum > 0) { redraw_buf_line_later(buf, lnum); @@ -1077,7 +1076,7 @@ static int sign_place(int *sign_id, const char_u *sign_group, const char_u *sign } /// Unplace the specified sign -static int sign_unplace(int sign_id, char_u *sign_group, buf_T *buf, linenr_T atlnum) +static int sign_unplace(int sign_id, char *sign_group, buf_T *buf, linenr_T atlnum) { if (buf->b_signlist == NULL) { // No signs in the buffer return OK; @@ -1085,7 +1084,7 @@ static int sign_unplace(int sign_id, char_u *sign_group, buf_T *buf, linenr_T at if (sign_id == 0) { // Delete all the signs in the specified buffer redraw_buf_later(buf, UPD_NOT_VALID); - buf_delete_signs(buf, (char *)sign_group); + buf_delete_signs(buf, sign_group); } else { linenr_T lnum; @@ -1108,7 +1107,7 @@ static int sign_unplace(int sign_id, char_u *sign_group, buf_T *buf, linenr_T at } /// Unplace the sign at the current cursor line. -static void sign_unplace_at_cursor(char_u *groupname) +static void sign_unplace_at_cursor(char *groupname) { int id = -1; @@ -1121,7 +1120,7 @@ static void sign_unplace_at_cursor(char_u *groupname) } /// Jump to a sign. -static linenr_T sign_jump(int sign_id, char_u *sign_group, buf_T *buf) +static linenr_T sign_jump(int sign_id, char *sign_group, buf_T *buf) { linenr_T lnum; @@ -1154,49 +1153,49 @@ static linenr_T sign_jump(int sign_id, char_u *sign_group, buf_T *buf) } /// ":sign define {name} ..." command -static void sign_define_cmd(char_u *sign_name, char_u *cmdline) -{ - char_u *arg; - char_u *p = cmdline; - char_u *icon = NULL; - char_u *text = NULL; - char_u *linehl = NULL; - char_u *texthl = NULL; - char_u *culhl = NULL; - char_u *numhl = NULL; +static void sign_define_cmd(char *sign_name, char *cmdline) +{ + char *arg; + char *p = cmdline; + char *icon = NULL; + char *text = NULL; + char *linehl = NULL; + char *texthl = NULL; + char *culhl = NULL; + char *numhl = NULL; int failed = false; // set values for a defined sign. for (;;) { - arg = (char_u *)skipwhite((char *)p); + arg = skipwhite(p); if (*arg == NUL) { break; } - p = (char_u *)skiptowhite_esc((char *)arg); + p = skiptowhite_esc(arg); if (STRNCMP(arg, "icon=", 5) == 0) { arg += 5; XFREE_CLEAR(icon); - icon = vim_strnsave(arg, (size_t)(p - arg)); + icon = xstrnsave(arg, (size_t)(p - arg)); } else if (STRNCMP(arg, "text=", 5) == 0) { arg += 5; XFREE_CLEAR(text); - text = vim_strnsave(arg, (size_t)(p - arg)); + text = xstrnsave(arg, (size_t)(p - arg)); } else if (STRNCMP(arg, "linehl=", 7) == 0) { arg += 7; XFREE_CLEAR(linehl); - linehl = vim_strnsave(arg, (size_t)(p - arg)); + linehl = xstrnsave(arg, (size_t)(p - arg)); } else if (STRNCMP(arg, "texthl=", 7) == 0) { arg += 7; XFREE_CLEAR(texthl); - texthl = vim_strnsave(arg, (size_t)(p - arg)); + texthl = xstrnsave(arg, (size_t)(p - arg)); } else if (STRNCMP(arg, "culhl=", 6) == 0) { arg += 6; XFREE_CLEAR(culhl); - culhl = vim_strnsave(arg, (size_t)(p - arg)); + culhl = xstrnsave(arg, (size_t)(p - arg)); } else if (STRNCMP(arg, "numhl=", 6) == 0) { arg += 6; XFREE_CLEAR(numhl); - numhl = vim_strnsave(arg, (size_t)(p - arg)); + numhl = xstrnsave(arg, (size_t)(p - arg)); } else { semsg(_(e_invarg2), arg); failed = true; @@ -1205,7 +1204,8 @@ static void sign_define_cmd(char_u *sign_name, char_u *cmdline) } if (!failed) { - sign_define_by_name(sign_name, icon, linehl, text, texthl, culhl, (char *)numhl); + sign_define_by_name(sign_name, icon, linehl, text, + texthl, culhl, numhl); } xfree(icon); @@ -1217,7 +1217,7 @@ static void sign_define_cmd(char_u *sign_name, char_u *cmdline) } /// ":sign place" command -static void sign_place_cmd(buf_T *buf, linenr_T lnum, char_u *sign_name, int id, char_u *group, +static void sign_place_cmd(buf_T *buf, linenr_T lnum, char *sign_name, int id, char *group, int prio) { if (id <= 0) { @@ -1250,7 +1250,7 @@ static void sign_place_cmd(buf_T *buf, linenr_T lnum, char_u *sign_name, int id, } /// ":sign unplace" command -static void sign_unplace_cmd(buf_T *buf, linenr_T lnum, char_u *sign_name, int id, char_u *group) +static void sign_unplace_cmd(buf_T *buf, linenr_T lnum, char *sign_name, int id, char *group) { if (lnum >= 0 || sign_name != NULL || (group != NULL && *group == '\0')) { emsg(_(e_invarg)); @@ -1272,7 +1272,7 @@ static void sign_unplace_cmd(buf_T *buf, linenr_T lnum, char_u *sign_name, int i // :sign unplace * group=* FOR_ALL_BUFFERS(cbuf) { if (cbuf->b_signlist != NULL) { - buf_delete_signs(cbuf, (char *)group); + buf_delete_signs(cbuf, group); } } } @@ -1307,7 +1307,7 @@ static void sign_unplace_cmd(buf_T *buf, linenr_T lnum, char_u *sign_name, int i /// :sign jump {id} buffer={nr} /// :sign jump {id} group={group} file={fname} /// :sign jump {id} group={group} buffer={nr} -static void sign_jump_cmd(buf_T *buf, linenr_T lnum, char_u *sign_name, int id, char_u *group) +static void sign_jump_cmd(buf_T *buf, linenr_T lnum, char *sign_name, int id, char *group) { if (sign_name == NULL && group == NULL && id == -1) { emsg(_(e_argreq)); @@ -1329,31 +1329,31 @@ static void sign_jump_cmd(buf_T *buf, linenr_T lnum, char_u *sign_name, int id, /// ":sign jump" commands. /// The supported arguments are: line={lnum} name={name} group={group} /// priority={prio} and file={fname} or buffer={nr}. -static int parse_sign_cmd_args(int cmd, char_u *arg, char_u **sign_name, int *signid, - char_u **group, int *prio, buf_T **buf, linenr_T *lnum) +static int parse_sign_cmd_args(int cmd, char *arg, char **sign_name, int *signid, char **group, + int *prio, buf_T **buf, linenr_T *lnum) { - char_u *arg1; - char_u *name; - char_u *filename = NULL; + char *arg1; + char *name; + char *filename = NULL; int lnum_arg = false; // first arg could be placed sign id arg1 = arg; if (ascii_isdigit(*arg)) { - *signid = getdigits_int((char **)&arg, true, 0); + *signid = getdigits_int(&arg, true, 0); if (!ascii_iswhite(*arg) && *arg != NUL) { *signid = -1; arg = arg1; } else { - arg = (char_u *)skipwhite((char *)arg); + arg = skipwhite(arg); } } while (*arg != NUL) { if (STRNCMP(arg, "line=", 5) == 0) { arg += 5; - *lnum = atoi((char *)arg); - arg = (char_u *)skiptowhite((char *)arg); + *lnum = atoi(arg); + arg = skiptowhite(arg); lnum_arg = true; } else if (STRNCMP(arg, "*", 1) == 0 && cmd == SIGNCMD_UNPLACE) { if (*signid != -1) { @@ -1361,11 +1361,11 @@ static int parse_sign_cmd_args(int cmd, char_u *arg, char_u **sign_name, int *si return FAIL; } *signid = -2; - arg = (char_u *)skiptowhite((char *)arg + 1); + arg = skiptowhite(arg + 1); } else if (STRNCMP(arg, "name=", 5) == 0) { arg += 5; name = arg; - arg = (char_u *)skiptowhite((char *)arg); + arg = skiptowhite(arg); if (*arg != NUL) { *arg++ = NUL; } @@ -1376,24 +1376,24 @@ static int parse_sign_cmd_args(int cmd, char_u *arg, char_u **sign_name, int *si } else if (STRNCMP(arg, "group=", 6) == 0) { arg += 6; *group = arg; - arg = (char_u *)skiptowhite((char *)arg); + arg = skiptowhite(arg); if (*arg != NUL) { *arg++ = NUL; } } else if (STRNCMP(arg, "priority=", 9) == 0) { arg += 9; - *prio = atoi((char *)arg); - arg = (char_u *)skiptowhite((char *)arg); + *prio = atoi(arg); + arg = skiptowhite(arg); } else if (STRNCMP(arg, "file=", 5) == 0) { arg += 5; filename = arg; - *buf = buflist_findname_exp((char *)arg); + *buf = buflist_findname_exp(arg); break; } else if (STRNCMP(arg, "buffer=", 7) == 0) { arg += 7; filename = arg; - *buf = buflist_findnr(getdigits_int((char **)&arg, true, 0)); - if (*skipwhite((char *)arg) != NUL) { + *buf = buflist_findnr(getdigits_int(&arg, true, 0)); + if (*skipwhite(arg) != NUL) { semsg(_(e_trailing_arg), arg); } break; @@ -1401,7 +1401,7 @@ static int parse_sign_cmd_args(int cmd, char_u *arg, char_u **sign_name, int *si emsg(_(e_invarg)); return FAIL; } - arg = (char_u *)skipwhite((char *)arg); + arg = skipwhite(arg); } if (filename != NULL && *buf == NULL) { @@ -1421,19 +1421,19 @@ static int parse_sign_cmd_args(int cmd, char_u *arg, char_u **sign_name, int *si /// ":sign" command void ex_sign(exarg_T *eap) { - char_u *arg = (char_u *)eap->arg; - char_u *p; + char *arg = eap->arg; + char *p; int idx; sign_T *sp; // Parse the subcommand. - p = (char_u *)skiptowhite((char *)arg); + p = skiptowhite(arg); idx = sign_cmd_idx(arg, p); if (idx == SIGNCMD_LAST) { semsg(_("E160: Unknown sign command: %s"), arg); return; } - arg = (char_u *)skipwhite((char *)p); + arg = skipwhite(p); if (idx <= SIGNCMD_LIST) { // Define, undefine or list signs. @@ -1445,18 +1445,18 @@ void ex_sign(exarg_T *eap) } else if (*arg == NUL) { emsg(_("E156: Missing sign name")); } else { - char_u *name; + char *name; // Isolate the sign name. If it's a number skip leading zeroes, // so that "099" and "99" are the same sign. But keep "0". - p = (char_u *)skiptowhite((char *)arg); + p = skiptowhite(arg); if (*p != NUL) { *p++ = NUL; } while (arg[0] == '0' && arg[1] != NUL) { arg++; } - name = vim_strsave(arg); + name = xstrdup(arg); if (idx == SIGNCMD_DEFINE) { sign_define_cmd(name, p); @@ -1474,8 +1474,8 @@ void ex_sign(exarg_T *eap) } else { int id = -1; linenr_T lnum = -1; - char_u *sign_name = NULL; - char_u *group = NULL; + char *sign_name = NULL; + char *group = NULL; int prio = SIGN_DEF_PRIO; buf_T *buf = NULL; @@ -1500,12 +1500,12 @@ static void sign_getinfo(sign_T *sp, dict_T *retdict) { const char *p; - tv_dict_add_str(retdict, S_LEN("name"), (char *)sp->sn_name); + tv_dict_add_str(retdict, S_LEN("name"), sp->sn_name); if (sp->sn_icon != NULL) { - tv_dict_add_str(retdict, S_LEN("icon"), (char *)sp->sn_icon); + tv_dict_add_str(retdict, S_LEN("icon"), sp->sn_icon); } if (sp->sn_text != NULL) { - tv_dict_add_str(retdict, S_LEN("text"), (char *)sp->sn_text); + tv_dict_add_str(retdict, S_LEN("text"), sp->sn_text); } if (sp->sn_line_hl > 0) { p = get_highlight_name_ext(NULL, sp->sn_line_hl - 1, false); @@ -1539,13 +1539,13 @@ static void sign_getinfo(sign_T *sp, dict_T *retdict) /// If 'name' is NULL, return a list of all the defined signs. /// Otherwise, return information about the specified sign. -static void sign_getlist(const char_u *name, list_T *retlist) +static void sign_getlist(const char *name, list_T *retlist) { sign_T *sp = first_sign; dict_T *dict; if (name != NULL) { - sp = sign_find(name, NULL); + sp = sign_find((char *)name, NULL); if (sp == NULL) { return; } @@ -1577,8 +1577,8 @@ list_T *get_buffer_signs(buf_T *buf) return l; } -/// Return information about all the signs placed in a buffer -static void sign_get_placed_in_buf(buf_T *buf, linenr_T lnum, int sign_id, const char_u *sign_group, +/// @return information about all the signs placed in a buffer +static void sign_get_placed_in_buf(buf_T *buf, linenr_T lnum, int sign_id, const char *sign_group, list_T *retlist) { dict_T *d; @@ -1594,7 +1594,7 @@ static void sign_get_placed_in_buf(buf_T *buf, linenr_T lnum, int sign_id, const tv_dict_add_list(d, S_LEN("signs"), l); FOR_ALL_SIGNS_IN_BUF(buf, sign) { - if (!sign_in_group(sign, sign_group)) { + if (!sign_in_group(sign, (char *)sign_group)) { continue; } if ((lnum == 0 && sign_id == 0) @@ -1609,7 +1609,7 @@ static void sign_get_placed_in_buf(buf_T *buf, linenr_T lnum, int sign_id, const /// Get a list of signs placed in buffer 'buf'. If 'num' is non-zero, return the /// sign placed at the line number. If 'lnum' is zero, return all the signs /// placed in 'buf'. If 'buf' is NULL, return signs placed in all the buffers. -static void sign_get_placed(buf_T *buf, linenr_T lnum, int sign_id, const char_u *sign_group, +static void sign_get_placed(buf_T *buf, linenr_T lnum, int sign_id, const char *sign_group, list_T *retlist) { if (buf != NULL) { @@ -1629,12 +1629,12 @@ static void sign_list_defined(sign_T *sp) smsg("sign %s", sp->sn_name); if (sp->sn_icon != NULL) { msg_puts(" icon="); - msg_outtrans((char *)sp->sn_icon); + msg_outtrans(sp->sn_icon); msg_puts(_(" (not supported)")); } if (sp->sn_text != NULL) { msg_puts(" text="); - msg_outtrans((char *)sp->sn_text); + msg_outtrans(sp->sn_text); } if (sp->sn_line_hl > 0) { msg_puts(" linehl="); @@ -1710,8 +1710,8 @@ static enum { EXP_SIGN_GROUPS, // expand with name of placed sign groups } expand_what; -// Return the n'th sign name (used for command line completion) -static char_u *get_nth_sign_name(int idx) +/// @return the n'th sign name (used for command line completion) +static char *get_nth_sign_name(int idx) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { // Complete with name of signs already defined @@ -1724,8 +1724,8 @@ static char_u *get_nth_sign_name(int idx) return NULL; } -// Return the n'th sign group name (used for command line completion) -static char_u *get_nth_sign_group_name(int idx) +/// @return the n'th sign group name (used for command line completion) +static char *get_nth_sign_group_name(int idx) { // Complete with name of sign groups already defined int current_idx = 0; @@ -1735,7 +1735,7 @@ static char_u *get_nth_sign_group_name(int idx) todo--; if (current_idx++ == idx) { signgroup_T *const group = HI2SG(hi); - return group->sg_name; + return (char *)group->sg_name; } } } @@ -1768,28 +1768,28 @@ char *get_sign_name(expand_T *xp, int idx) return unplace_arg[idx]; } case EXP_SIGN_NAMES: - return (char *)get_nth_sign_name(idx); + return get_nth_sign_name(idx); case EXP_SIGN_GROUPS: - return (char *)get_nth_sign_group_name(idx); + return get_nth_sign_group_name(idx); default: return NULL; } } /// Handle command line completion for :sign command. -void set_context_in_sign_cmd(expand_T *xp, char_u *arg) +void set_context_in_sign_cmd(expand_T *xp, char *arg) { - char_u *end_subcmd; - char_u *last; + char *end_subcmd; + char *last; int cmd_idx; - char_u *begin_subcmd_args; + char *begin_subcmd_args; // Default: expand subcommands. xp->xp_context = EXPAND_SIGN; expand_what = EXP_SUBCMD; - xp->xp_pattern = (char *)arg; + xp->xp_pattern = arg; - end_subcmd = (char_u *)skiptowhite((char *)arg); + end_subcmd = skiptowhite(arg); if (*end_subcmd == NUL) { // expand subcmd name // :sign {subcmd} @@ -1801,7 +1801,7 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg) // :sign {subcmd} {subcmd_args} // | // begin_subcmd_args - begin_subcmd_args = (char_u *)skipwhite((char *)end_subcmd); + begin_subcmd_args = skipwhite(end_subcmd); // Expand last argument of subcmd. // @@ -1810,21 +1810,21 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg) // p // Loop until reaching last argument. - char_u *p = begin_subcmd_args; + char *p = begin_subcmd_args; do { - p = (char_u *)skipwhite((char *)p); + p = skipwhite(p); last = p; - p = (char_u *)skiptowhite((char *)p); + p = skiptowhite(p); } while (*p != NUL); - p = (char_u *)vim_strchr((char *)last, '='); + p = vim_strchr(last, '='); // :sign define {name} {args}... {last}= // | | // last p if (p == NULL) { // Expand last argument name (before equal sign). - xp->xp_pattern = (char *)last; + xp->xp_pattern = last; switch (cmd_idx) { case SIGNCMD_DEFINE: expand_what = EXP_DEFINE; @@ -1854,7 +1854,7 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg) } } else { // Expand last argument value (after equal sign). - xp->xp_pattern = (char *)p + 1; + xp->xp_pattern = p + 1; switch (cmd_idx) { case SIGNCMD_DEFINE: if (STRNCMP(last, "texthl", 6) == 0 @@ -1928,8 +1928,8 @@ static int sign_define_from_dict(const char *name_arg, dict_T *dict) numhl = tv_dict_get_string(dict, "numhl", true); } - if (sign_define_by_name((char_u *)name, (char_u *)icon, (char_u *)linehl, - (char_u *)text, (char_u *)texthl, (char_u *)culhl, numhl) + if (sign_define_by_name(name, icon, linehl, + text, texthl, culhl, numhl) == OK) { retval = 0; } @@ -2005,7 +2005,7 @@ void f_sign_getdefined(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) name = tv_get_string(&argvars[0]); } - sign_getlist((const char_u *)name, rettv->vval.v_list); + sign_getlist(name, rettv->vval.v_list); } /// "sign_getplaced()" function @@ -2062,8 +2062,7 @@ void f_sign_getplaced(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } - sign_get_placed(buf, lnum, sign_id, (const char_u *)group, - rettv->vval.v_list); + sign_get_placed(buf, lnum, sign_id, group, rettv->vval.v_list); } /// "sign_jump()" function @@ -2103,7 +2102,7 @@ void f_sign_jump(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) goto cleanup; } - rettv->vval.v_number = sign_jump(sign_id, (char_u *)sign_group, buf); + rettv->vval.v_number = sign_jump(sign_id, sign_group, buf); cleanup: xfree(sign_group); @@ -2115,8 +2114,8 @@ static int sign_place_from_dict(typval_T *id_tv, typval_T *group_tv, typval_T *n typval_T *buf_tv, dict_T *dict) { int sign_id = 0; - char_u *group = NULL; - char_u *sign_name = NULL; + char *group = NULL; + char *sign_name = NULL; buf_T *buf = NULL; dictitem_T *di; linenr_T lnum = 0; @@ -2154,14 +2153,14 @@ static int sign_place_from_dict(typval_T *id_tv, typval_T *group_tv, typval_T *n if (group_tv == NULL) { group = NULL; // global group } else { - group = (char_u *)tv_get_string_chk(group_tv); + group = (char *)tv_get_string_chk(group_tv); if (group == NULL) { goto cleanup; } if (group[0] == '\0') { // global sign group group = NULL; } else { - group = vim_strsave(group); + group = xstrdup(group); } } @@ -2175,7 +2174,7 @@ static int sign_place_from_dict(typval_T *id_tv, typval_T *group_tv, typval_T *n if (name_tv == NULL) { goto cleanup; } - sign_name = (char_u *)tv_get_string_chk(name_tv); + sign_name = (char *)tv_get_string_chk(name_tv); if (sign_name == NULL) { goto cleanup; } @@ -2269,13 +2268,13 @@ void f_sign_placelist(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// Undefine multiple signs static void sign_undefine_multiple(list_T *l, list_T *retlist) { - char_u *name; + char *name; int retval; TV_LIST_ITER_CONST(l, li, { retval = -1; - name = (char_u *)tv_get_string_chk(TV_LIST_ITEM_TV(li)); - if (name != NULL && (sign_undefine_by_name(name) == OK)) { + name = (char *)tv_get_string_chk(TV_LIST_ITEM_TV(li)); + if (name != NULL && (sign_undefine_by_name((char *)name) == OK)) { retval = 0; } tv_list_append_number(retlist, retval); @@ -2308,7 +2307,7 @@ void f_sign_undefine(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) return; } - if (sign_undefine_by_name((const char_u *)name) == OK) { + if (sign_undefine_by_name(name) == OK) { rettv->vval.v_number = 0; } } @@ -2321,20 +2320,20 @@ static int sign_unplace_from_dict(typval_T *group_tv, dict_T *dict) dictitem_T *di; int sign_id = 0; buf_T *buf = NULL; - char_u *group = NULL; + char *group = NULL; int retval = -1; // sign group if (group_tv != NULL) { - group = (char_u *)tv_get_string(group_tv); + group = (char *)tv_get_string(group_tv); } else { - group = (char_u *)tv_dict_get_string(dict, "group", false); + group = tv_dict_get_string(dict, "group", false); } if (group != NULL) { if (group[0] == '\0') { // global sign group group = NULL; } else { - group = vim_strsave(group); + group = xstrdup(group); } } diff --git a/src/nvim/sign_defs.h b/src/nvim/sign_defs.h index a4fb325ec8..1efde30008 100644 --- a/src/nvim/sign_defs.h +++ b/src/nvim/sign_defs.h @@ -34,7 +34,7 @@ struct sign_entry { /// Sign attributes. Used by the screen refresh routines. typedef struct { - char_u *text; + char *text; int hl_attr_id; int priority; } SignTextAttrs; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index d8bc4b22c2..7c05c9fe53 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -3289,7 +3289,7 @@ void spell_dump_compl(char_u *pat, int ic, Direction *dir, int dumpflags_arg) // ignore case... assert(depth >= 0); if (depth <= patlen - && mb_strnicmp(word, pat, (size_t)depth) != 0) { + && mb_strnicmp((char *)word, (char *)pat, (size_t)depth) != 0) { depth--; } } @@ -3371,7 +3371,7 @@ static void dump_word(slang_T *slang, char_u *word, char_u *pat, Direction *dir, ml_append(lnum, (char *)p, (colnr_T)0, false); } else if (((dumpflags & DUMPFLAG_ICASE) - ? mb_strnicmp(p, pat, STRLEN(pat)) == 0 + ? mb_strnicmp((char *)p, (char *)pat, STRLEN(pat)) == 0 : STRNCMP(p, pat, STRLEN(pat)) == 0) && ins_compl_add_infercase(p, (int)STRLEN(p), p_ic, NULL, *dir, false) == OK) { diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 1319894226..d8de23182c 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -797,7 +797,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) validate_current_state(); } -static void save_chartab(char_u *chartab) +static void save_chartab(char *chartab) { if (syn_block->b_syn_isk != empty_option) { memmove(chartab, syn_buf->b_chartab, (size_t)32); @@ -805,7 +805,7 @@ static void save_chartab(char_u *chartab) } } -static void restore_chartab(char_u *chartab) +static void restore_chartab(char *chartab) { if (syn_win->w_s->b_syn_isk != empty_option) { memmove(syn_buf->b_chartab, chartab, (size_t)32); @@ -819,7 +819,7 @@ static int syn_match_linecont(linenr_T lnum) regmmatch_T regmatch; // chartab array for syn iskeyword char_u buf_chartab[32]; - save_chartab(buf_chartab); + save_chartab((char *)buf_chartab); regmatch.rmm_ic = syn_block->b_syn_linecont_ic; regmatch.regprog = syn_block->b_syn_linecont_prog; @@ -827,7 +827,7 @@ static int syn_match_linecont(linenr_T lnum) IF_SYN_TIME(&syn_block->b_syn_linecont_time)); syn_block->b_syn_linecont_prog = regmatch.regprog; - restore_chartab(buf_chartab); + restore_chartab((char *)buf_chartab); return r; } return false; @@ -1677,7 +1677,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con ga_init(&zero_width_next_ga, (int)sizeof(int), 10); // use syntax iskeyword option - save_chartab(buf_chartab); + save_chartab((char *)buf_chartab); /* * Repeat matching keywords and patterns, to find contained items at the @@ -1713,7 +1713,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con && (current_col == 0 || !vim_iswordp_buf(cur_pos - 1 - utf_head_off((char *)line, (char *)cur_pos - 1), syn_buf))) { - syn_id = check_keyword_id(line, (int)current_col, &endcol, &flags, + syn_id = check_keyword_id((char *)line, (int)current_col, &endcol, &flags, &next_list, cur_si, &cchar); if (syn_id != 0) { push_current_state(KEYWORD_IDX); @@ -2004,7 +2004,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con } } while (found_match); - restore_chartab(buf_chartab); + restore_chartab((char *)buf_chartab); /* * Use attributes from the current state, if within its highlighting. @@ -2596,7 +2596,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ best_regmatch.startpos[0].col = 0; // avoid compiler warning // use syntax iskeyword option - save_chartab(buf_chartab); + save_chartab((char *)buf_chartab); for (;;) { /* @@ -2747,7 +2747,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ m_endpos->lnum = 0; } - restore_chartab(buf_chartab); + restore_chartab((char *)buf_chartab); // Remove external matches. unref_extmatch(re_extmatch_in); @@ -2932,17 +2932,17 @@ static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T /// @param next_listp return: next_list of matching keyword /// @param cur_si item at the top of the stack /// @param ccharp conceal substitution char -static int check_keyword_id(char_u *const line, const int startcol, int *const endcolp, +static int check_keyword_id(char *const line, const int startcol, int *const endcolp, long *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 // checked. - char_u *const kwp = line + startcol; + char *const kwp = line + startcol; int kwlen = 0; do { - kwlen += utfc_ptr2len((char *)kwp + kwlen); - } while (vim_iswordp_buf(kwp + kwlen, syn_buf)); + kwlen += utfc_ptr2len(kwp + kwlen); + } while (vim_iswordp_buf((char_u *)kwp + kwlen, syn_buf)); if (kwlen > MAXKEYWLEN) { return 0; @@ -2957,13 +2957,13 @@ static int check_keyword_id(char_u *const line, const int startcol, int *const e // matching case if (syn_block->b_keywtab.ht_used != 0) { - kp = match_keyword(keyword, &syn_block->b_keywtab, cur_si); + kp = match_keyword((char *)keyword, &syn_block->b_keywtab, cur_si); } // ignoring case if (kp == NULL && syn_block->b_keywtab_ic.ht_used != 0) { - str_foldcase(kwp, kwlen, keyword, MAXKEYWLEN + 1); - kp = match_keyword(keyword, &syn_block->b_keywtab_ic, cur_si); + str_foldcase((char_u *)kwp, kwlen, keyword, MAXKEYWLEN + 1); + kp = match_keyword((char *)keyword, &syn_block->b_keywtab_ic, cur_si); } if (kp != NULL) { @@ -2982,9 +2982,9 @@ static int check_keyword_id(char_u *const line, const int startcol, int *const e /// When current_next_list is non-zero accept only that group, otherwise: /// Accept a not-contained keyword at toplevel. /// Accept a keyword at other levels only if it is in the contains list. -static keyentry_T *match_keyword(char_u *keyword, hashtab_T *ht, stateitem_T *cur_si) +static keyentry_T *match_keyword(char *keyword, hashtab_T *ht, stateitem_T *cur_si) { - hashitem_T *hi = hash_find(ht, (char *)keyword); + hashitem_T *hi = hash_find(ht, keyword); if (!HASHITEM_EMPTY(hi)) { for (keyentry_T *kp = HI2KE(hi); kp != NULL; kp = kp->ke_next) { if (current_next_list != 0 @@ -3029,20 +3029,18 @@ static void syn_cmd_conceal(exarg_T *eap, int syncing) } } -/* - * Handle ":syntax case" command. - */ +/// Handle ":syntax case" command. static void syn_cmd_case(exarg_T *eap, int syncing) { - char_u *arg = (char_u *)eap->arg; - char_u *next; + char *arg = eap->arg; + char *next; - eap->nextcmd = find_nextcmd((char *)arg); + eap->nextcmd = find_nextcmd(arg); if (eap->skip) { return; } - next = (char_u *)skiptowhite((char *)arg); + next = skiptowhite(arg); if (*arg == NUL) { if (curwin->w_s->b_syn_ic) { msg("syntax case ignore"); @@ -3097,20 +3095,18 @@ static void syn_cmd_foldlevel(exarg_T *eap, int syncing) } } -/* - * Handle ":syntax spell" command. - */ +/// Handle ":syntax spell" command. static void syn_cmd_spell(exarg_T *eap, int syncing) { - char_u *arg = (char_u *)eap->arg; - char_u *next; + char *arg = eap->arg; + char *next; - eap->nextcmd = find_nextcmd((char *)arg); + eap->nextcmd = find_nextcmd(arg); if (eap->skip) { return; } - next = (char_u *)skiptowhite((char *)arg); + next = skiptowhite(arg); if (*arg == NUL) { if (curwin->w_s->b_syn_spell == SYNSPL_TOP) { msg("syntax spell toplevel"); @@ -3137,15 +3133,15 @@ static void syn_cmd_spell(exarg_T *eap, int syncing) /// Handle ":syntax iskeyword" command. static void syn_cmd_iskeyword(exarg_T *eap, int syncing) { - char_u *arg = (char_u *)eap->arg; - char_u save_chartab[32]; - char_u *save_isk; + char *arg = eap->arg; + char save_chartab[32]; + char *save_isk; if (eap->skip) { return; } - arg = (char_u *)skipwhite((char *)arg); + arg = skipwhite(arg); if (*arg == NUL) { msg_puts("\n"); if (curwin->w_s->b_syn_isk != empty_option) { @@ -3160,15 +3156,15 @@ static void syn_cmd_iskeyword(exarg_T *eap, int syncing) clear_string_option(&curwin->w_s->b_syn_isk); } else { memmove(save_chartab, curbuf->b_chartab, (size_t)32); - save_isk = (char_u *)curbuf->b_p_isk; - curbuf->b_p_isk = (char *)vim_strsave(arg); + save_isk = curbuf->b_p_isk; + curbuf->b_p_isk = xstrdup(arg); buf_init_chartab(curbuf, false); memmove(curwin->w_s->b_syn_chartab, curbuf->b_chartab, (size_t)32); memmove(curbuf->b_chartab, save_chartab, (size_t)32); clear_string_option(&curwin->w_s->b_syn_isk); curwin->w_s->b_syn_isk = curbuf->b_p_isk; - curbuf->b_p_isk = (char *)save_isk; + curbuf->b_p_isk = save_isk; } } redraw_later(curwin, UPD_NOT_VALID); @@ -3303,16 +3299,14 @@ static void syn_clear_cluster(synblock_T *block, int i) xfree(SYN_CLSTR(block)[i].scl_list); } -/* - * Handle ":syntax clear" command. - */ +/// Handle ":syntax clear" command. static void syn_cmd_clear(exarg_T *eap, int syncing) { - char_u *arg = (char_u *)eap->arg; - char_u *arg_end; + char *arg = eap->arg; + char *arg_end; int id; - eap->nextcmd = find_nextcmd((char *)arg); + eap->nextcmd = find_nextcmd(arg); if (eap->skip) { return; } @@ -3345,7 +3339,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing) * Clear the group IDs that are in the argument. */ while (!ends_excmd(*arg)) { - arg_end = (char_u *)skiptowhite((char *)arg); + arg_end = skiptowhite(arg); if (*arg == '@') { id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); if (id == 0) { @@ -3360,7 +3354,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing) XFREE_CLEAR(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); } } else { - id = syn_name2id_len((char *)arg, (size_t)(arg_end - arg)); + id = syn_name2id_len(arg, (size_t)(arg_end - arg)); if (id == 0) { semsg(_(e_nogroup), arg); break; @@ -3368,7 +3362,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing) syn_clear_one(id, syncing); } } - arg = (char_u *)skipwhite((char *)arg_end); + arg = skipwhite(arg_end); } } redraw_curbuf_later(UPD_SOME_VALID); @@ -3412,7 +3406,7 @@ static void syn_cmd_on(exarg_T *eap, int syncing) */ static void syn_cmd_reset(exarg_T *eap, int syncing) { - eap->nextcmd = (char *)check_nextcmd((char_u *)eap->arg); + eap->nextcmd = check_nextcmd(eap->arg); if (!eap->skip) { init_highlight(true, true); } @@ -3437,7 +3431,7 @@ static void syn_cmd_off(exarg_T *eap, int syncing) static void syn_cmd_onoff(exarg_T *eap, char *name) FUNC_ATTR_NONNULL_ALL { - eap->nextcmd = (char *)check_nextcmd((char_u *)eap->arg); + eap->nextcmd = check_nextcmd(eap->arg); if (!eap->skip) { did_syntax_onoff = true; char buf[100]; @@ -3524,7 +3518,7 @@ static void syn_cmd_list(exarg_T *eap, int syncing) while (!ends_excmd(*arg) && !got_int) { arg_end = (char_u *)skiptowhite((char *)arg); if (*arg == '@') { - int id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); + int id = syn_scl_namen2id((char *)arg + 1, (int)(arg_end - arg - 1)); if (id == 0) { semsg(_("E392: No such syntax cluster: %s"), arg); } else { @@ -3541,7 +3535,7 @@ static void syn_cmd_list(exarg_T *eap, int syncing) arg = (char_u *)skipwhite((char *)arg_end); } } - eap->nextcmd = (char *)check_nextcmd(arg); + eap->nextcmd = check_nextcmd((char *)arg); } static void syn_lines_msg(void) @@ -3977,13 +3971,14 @@ static void clear_keywtab(hashtab_T *ht) /// @param flags flags for this keyword /// @param cont_in_list containedin for this keyword /// @param next_list nextgroup for this keyword -static void add_keyword(char_u *const name, const int id, const int flags, +static void add_keyword(char *const name, const int id, const int flags, int16_t *const cont_in_list, int16_t *const next_list, const int conceal_char) { - char_u name_folded[MAXKEYWLEN + 1]; - const char_u *const name_ic = (curwin->w_s->b_syn_ic) - ? str_foldcase(name, (int)STRLEN(name), name_folded, sizeof(name_folded)) + char name_folded[MAXKEYWLEN + 1]; + const char *const name_ic = (curwin->w_s->b_syn_ic) + ? (char *)str_foldcase((char_u *)name, (int)STRLEN(name), (char_u *)name_folded, + sizeof(name_folded)) : name; keyentry_T *const kp = xmalloc(sizeof(keyentry_T) + STRLEN(name_ic)); @@ -4249,7 +4244,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing) emsg(_("E397: Filename required")); return; } - sgl_id = syn_check_cluster((char_u *)arg, (int)(group_name_end - arg)); + sgl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); if (sgl_id == 0) { return; } @@ -4364,7 +4359,7 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing) if (p != NULL) { *p = NUL; } - add_keyword((char_u *)kw, syn_id, syn_opt_arg.flags, + add_keyword(kw, syn_id, syn_opt_arg.flags, syn_opt_arg.cont_in_list, syn_opt_arg.next_list, conceal_char); if (p == NULL) { @@ -4399,7 +4394,7 @@ error: } if (rest != NULL) { - eap->nextcmd = (char *)check_nextcmd((char_u *)rest); + eap->nextcmd = check_nextcmd(rest); } else { semsg(_(e_invarg2), arg); } @@ -4439,7 +4434,7 @@ static void syn_cmd_match(exarg_T *eap, int syncing) // get the pattern. init_syn_patterns(); CLEAR_FIELD(item); - rest = get_syn_pattern((char_u *)rest, &item); + rest = get_syn_pattern(rest, &item); if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) { syn_opt_arg.flags |= HL_HAS_EOL; } @@ -4451,7 +4446,7 @@ static void syn_cmd_match(exarg_T *eap, int syncing) /* * Check for trailing command and illegal trailing arguments. */ - eap->nextcmd = (char *)check_nextcmd((char_u *)rest); + eap->nextcmd = check_nextcmd(rest); if (!ends_excmd(*rest) || eap->skip) { rest = NULL; } else { @@ -4631,7 +4626,7 @@ static void syn_cmd_region(exarg_T *eap, int syncing) assert(item == ITEM_SKIP || item == ITEM_END); reg_do_extmatch = REX_USE; } - rest = get_syn_pattern((char_u *)rest, ppp->pp_synp); + rest = get_syn_pattern(rest, ppp->pp_synp); reg_do_extmatch = 0; if (item == ITEM_END && vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) { @@ -4658,7 +4653,7 @@ static void syn_cmd_region(exarg_T *eap, int syncing) * Check for trailing garbage or command. * If OK, add the item. */ - eap->nextcmd = (char *)check_nextcmd((char_u *)rest); + eap->nextcmd = check_nextcmd(rest); if (!ends_excmd(*rest) || eap->skip) { rest = NULL; } else { @@ -4863,12 +4858,12 @@ static void syn_combine_list(int16_t **const clstr1, int16_t **const clstr2, con *clstr1 = clstr; } -// Lookup a syntax cluster name and return its ID. -// If it is not found, 0 is returned. -static int syn_scl_name2id(char_u *name) +/// Lookup a syntax cluster name and return its ID. +/// If it is not found, 0 is returned. +static int syn_scl_name2id(char *name) { // Avoid using stricmp() too much, it's slow on some systems - char_u *name_u = vim_strsave_up(name); + char *name_u = (char *)vim_strsave_up((char_u *)name); int i; for (i = curwin->w_s->b_syn_clusters.ga_len; --i >= 0;) { if (SYN_CLSTR(curwin->w_s)[i].scl_name_u != NULL @@ -4880,25 +4875,24 @@ static int syn_scl_name2id(char_u *name) return i < 0 ? 0 : i + SYNID_CLUSTER; } -/* - * Like syn_scl_name2id(), but take a pointer + length argument. - */ -static int syn_scl_namen2id(char_u *linep, int len) +/// Like syn_scl_name2id(), but take a pointer + length argument. +static int syn_scl_namen2id(char *linep, int len) { - char_u *name = vim_strnsave(linep, (size_t)len); + char *name = xstrnsave(linep, (size_t)len); int id = syn_scl_name2id(name); xfree(name); return id; } -// Find syntax cluster name in the table and return its ID. -// The argument is a pointer to the name and the length of the name. -// If it doesn't exist yet, a new entry is created. -// Return 0 for failure. -static int syn_check_cluster(char_u *pp, int len) +/// Find syntax cluster name in the table and return its ID. +/// The argument is a pointer to the name and the length of the name. +/// If it doesn't exist yet, a new entry is created. +/// +/// @return 0 for failure. +static int syn_check_cluster(char *pp, int len) { - char_u *name = vim_strnsave(pp, (size_t)len); + char *name = xstrnsave(pp, (size_t)len); int id = syn_scl_name2id(name); if (id == 0) { // doesn't exist yet id = syn_add_cluster(name); @@ -4908,10 +4902,11 @@ static int syn_check_cluster(char_u *pp, int len) return id; } -// Add new syntax cluster and return its ID. -// "name" must be an allocated string, it will be consumed. -// Return 0 for failure. -static int syn_add_cluster(char_u *name) +/// Add new syntax cluster and return its ID. +/// "name" must be an allocated string, it will be consumed. +/// +/// @return 0 for failure. +static int syn_add_cluster(char *name) { /* * First call for this growarray: init growing array. @@ -4931,8 +4926,8 @@ static int syn_add_cluster(char_u *name) syn_cluster_T *scp = GA_APPEND_VIA_PTR(syn_cluster_T, &curwin->w_s->b_syn_clusters); CLEAR_POINTER(scp); - scp->scl_name = name; - scp->scl_name_u = vim_strsave_up(name); + scp->scl_name = (char_u *)name; + scp->scl_name_u = vim_strsave_up((char_u *)name); scp->scl_list = NULL; if (STRICMP(name, "Spell") == 0) { @@ -4966,7 +4961,7 @@ static void syn_cmd_cluster(exarg_T *eap, int syncing) rest = get_group_name(arg, &group_name_end); if (rest != NULL) { - int scl_id = syn_check_cluster((char_u *)arg, (int)(group_name_end - arg)); + int scl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); if (scl_id == 0) { return; } @@ -5030,7 +5025,7 @@ static void init_syn_patterns(void) /// Stores the pattern and program in a synpat_T. /// /// @return a pointer to the next argument, or NULL in case of an error. -static char *get_syn_pattern(char_u *arg, synpat_T *ci) +static char *get_syn_pattern(char *arg, synpat_T *ci) { char *end; int *p; @@ -5042,13 +5037,13 @@ static char *get_syn_pattern(char_u *arg, synpat_T *ci) return NULL; } - end = skip_regexp((char *)arg + 1, *arg, true, NULL); - if (*end != (char)(*arg)) { // end delimiter not found + end = skip_regexp(arg + 1, *arg, true, NULL); + if (*end != *arg) { // end delimiter not found semsg(_("E401: Pattern delimiter not found: %s"), arg); return NULL; } // store the pattern and compiled regexp program - ci->sp_pattern = vim_strnsave(arg + 1, (size_t)(end - (char *)arg) - 1); + ci->sp_pattern = vim_strnsave((char_u *)arg + 1, (size_t)(end - arg) - 1); // Make 'cpoptions' empty, to avoid the 'l' flag cpo_save = p_cpo; @@ -5122,15 +5117,13 @@ static char *get_syn_pattern(char_u *arg, synpat_T *ci) return skipwhite(end); } -/* - * Handle ":syntax sync .." command. - */ +/// Handle ":syntax sync .." command. static void syn_cmd_sync(exarg_T *eap, int syncing) { - char_u *arg_start = (char_u *)eap->arg; + char *arg_start = eap->arg; char *arg_end; - char_u *key = NULL; - char_u *next_arg; + char *key = NULL; + char *next_arg; int illegal = false; int finished = false; char *cpo_save; @@ -5141,21 +5134,21 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) } while (!ends_excmd(*arg_start)) { - arg_end = skiptowhite((char *)arg_start); - next_arg = (char_u *)skipwhite(arg_end); + arg_end = skiptowhite(arg_start); + next_arg = skipwhite(arg_end); xfree(key); - key = vim_strnsave_up(arg_start, (size_t)(arg_end - (char *)arg_start)); + key = (char *)vim_strnsave_up((char_u *)arg_start, (size_t)(arg_end - arg_start)); if (STRCMP(key, "CCOMMENT") == 0) { if (!eap->skip) { curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; } if (!ends_excmd(*next_arg)) { - arg_end = skiptowhite((char *)next_arg); + arg_end = skiptowhite(next_arg); if (!eap->skip) { curwin->w_s->b_syn_sync_id = - (int16_t)syn_check_group((char *)next_arg, (size_t)(arg_end - (char *)next_arg)); + (int16_t)syn_check_group(next_arg, (size_t)(arg_end - next_arg)); } - next_arg = (char_u *)skipwhite(arg_end); + next_arg = skipwhite(arg_end); } else if (!eap->skip) { curwin->w_s->b_syn_sync_id = (int16_t)syn_name2id("Comment"); } @@ -5164,11 +5157,11 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) || STRNCMP(key, "MAXLINES", 8) == 0 || STRNCMP(key, "LINEBREAKS", 10) == 0) { if (key[4] == 'S') { - arg_end = (char *)key + 6; + arg_end = key + 6; } else if (key[0] == 'L') { - arg_end = (char *)key + 11; + arg_end = key + 11; } else { - arg_end = (char *)key + 9; + arg_end = key + 9; } if (arg_end[-1] != '=' || !ascii_isdigit(*arg_end)) { illegal = true; @@ -5199,8 +5192,8 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) finished = true; break; } - arg_end = skip_regexp((char *)next_arg + 1, *next_arg, true, NULL); - if (*arg_end != (char)(*next_arg)) { // end delimiter not found + arg_end = skip_regexp(next_arg + 1, *next_arg, true, NULL); + if (*arg_end != *next_arg) { // end delimiter not found illegal = true; break; } @@ -5208,7 +5201,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) if (!eap->skip) { // store the pattern and compiled regexp program curwin->w_s->b_syn_linecont_pat = - (char *)vim_strnsave(next_arg + 1, (size_t)(arg_end - (char *)next_arg) - 1); + xstrnsave(next_arg + 1, (size_t)(arg_end - next_arg) - 1); curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic; // Make 'cpoptions' empty, to avoid the 'l' flag @@ -5225,9 +5218,9 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) break; } } - next_arg = (char_u *)skipwhite(arg_end + 1); + next_arg = skipwhite(arg_end + 1); } else { - eap->arg = (char *)next_arg; + eap->arg = next_arg; if (STRCMP(key, "MATCH") == 0) { syn_cmd_match(eap, true); } else if (STRCMP(key, "REGION") == 0) { @@ -5246,7 +5239,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) if (illegal) { semsg(_("E404: Illegal arguments: %s"), arg_start); } else if (!finished) { - eap->nextcmd = (char *)check_nextcmd(arg_start); + eap->nextcmd = check_nextcmd(arg_start); redraw_curbuf_later(UPD_SOME_VALID); syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. } @@ -5327,7 +5320,7 @@ static int get_id_list(char **const arg, const int keylen, int16_t **const list, if (skip) { id = -1; } else { - id = syn_check_cluster((char_u *)name + 2, (int)(end - p - 1)); + id = syn_check_cluster(name + 2, (int)(end - p - 1)); } } else { /* @@ -5565,21 +5558,19 @@ static struct subcommand subcommands[] = { NULL, NULL } }; -/* - * ":syntax". - * This searches the subcommands[] table for the subcommand name, and calls a - * syntax_subcommand() function to do the rest. - */ +/// ":syntax". +/// This searches the subcommands[] table for the subcommand name, and calls a +/// syntax_subcommand() function to do the rest. void ex_syntax(exarg_T *eap) { - char_u *arg = (char_u *)eap->arg; - char_u *subcmd_end; + char *arg = eap->arg; + char *subcmd_end; syn_cmdlinep = eap->cmdlinep; // isolate subcommand name for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); subcmd_end++) {} - char_u *const subcmd_name = vim_strnsave(arg, (size_t)(subcmd_end - arg)); + char *const subcmd_name = xstrnsave(arg, (size_t)(subcmd_end - arg)); if (eap->skip) { // skip error messages for all subcommands emsg_skip++; } @@ -5588,8 +5579,8 @@ void ex_syntax(exarg_T *eap) semsg(_("E410: Invalid :syntax subcommand: %s"), subcmd_name); break; } - if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0) { - eap->arg = skipwhite((char *)subcmd_end); + if (STRCMP(subcmd_name, subcommands[i].name) == 0) { + eap->arg = skipwhite(subcmd_end); (subcommands[i].func)(eap, false); break; } @@ -5602,8 +5593,8 @@ void ex_syntax(exarg_T *eap) void ex_ownsyntax(exarg_T *eap) { - char_u *old_value; - char_u *new_value; + char *old_value; + char *new_value; if (curwin->w_s == &curwin->w_buffer->b_s) { curwin->w_s = xcalloc(1, sizeof(synblock_T)); @@ -5620,25 +5611,25 @@ void ex_ownsyntax(exarg_T *eap) } // Save value of b:current_syntax. - old_value = get_var_value("b:current_syntax"); + old_value = (char *)get_var_value("b:current_syntax"); if (old_value != NULL) { - old_value = vim_strsave(old_value); + old_value = xstrdup(old_value); } // Apply the "syntax" autocommand event, this finds and loads the syntax file. 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"); + new_value = (char *)get_var_value("b:current_syntax"); if (new_value != NULL) { - set_internal_string_var("w:current_syntax", (char *)new_value); + set_internal_string_var("w:current_syntax", new_value); } // Restore value of b:current_syntax. if (old_value == NULL) { do_unlet(S_LEN("b:current_syntax"), true); } else { - set_internal_string_var("b:current_syntax", (char *)old_value); + set_internal_string_var("b:current_syntax", old_value); xfree(old_value); } } diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 4fd99b058b..54c1dc7741 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -502,9 +502,9 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) // Find the position of each old match in the new list. Need // to use parse_match() to find the tag line. for (j = 0; j < num_matches; j++) { - parse_match((char_u *)matches[j], &tagp); + parse_match(matches[j], &tagp); for (i = idx; i < new_num_matches; i++) { - parse_match((char_u *)new_matches[i], &tagp2); + parse_match(new_matches[i], &tagp2); if (STRCMP(tagp.tagname, tagp2.tagname) == 0) { char_u *p = (char_u *)new_matches[i]; for (k = i; k > idx; k--) { @@ -585,7 +585,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) tagstack[tagstackidx].cur_fnum = cur_fnum; // store user-provided data originating from tagfunc - if (use_tfu && parse_match((char_u *)matches[cur_match], &tagp2) == OK + if (use_tfu && parse_match(matches[cur_match], &tagp2) == OK && tagp2.user_data) { XFREE_CLEAR(tagstack[tagstackidx].user_data); tagstack[tagstackidx].user_data = (char *)vim_strnsave(tagp2.user_data, @@ -705,7 +705,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char // Assume that the first match indicates how long the tags can // be, and align the file names to that. - parse_match((char_u *)matches[0], &tagp); + parse_match(matches[0], &tagp); taglen = (int)(tagp.tagname_end - tagp.tagname + 2); if (taglen < 18) { taglen = 18; @@ -723,7 +723,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char msg_puts_attr(_("file\n"), HL_ATTR(HLF_T)); for (i = 0; i < num_matches && !got_int; i++) { - parse_match((char_u *)matches[i], &tagp); + parse_match(matches[i], &tagp); if (!new_tag && ( (g_do_tagpreview != 0 && i == ptag_entry.cur_match) @@ -897,7 +897,7 @@ static int add_llist_tags(char_u *tag, int num_matches, char **matches) long lnum; dict_T *dict; - parse_match((char_u *)matches[i], &tagp); + parse_match(matches[i], &tagp); // Save the tag name len = (int)(tagp.tagname_end - tagp.tagname); @@ -1957,7 +1957,7 @@ parse_line: break; } else if (state == TS_SKIP_BACK) { assert(cmplen >= 0); - if (mb_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen) != 0) { + if (mb_strnicmp((char *)tagp.tagname, (char *)orgpat.head, (size_t)cmplen) != 0) { state = TS_STEP_FORWARD; } else { // Have to skip back more. Restore the curr_offset @@ -1967,7 +1967,7 @@ parse_line: continue; } else if (state == TS_STEP_FORWARD) { assert(cmplen >= 0); - if (mb_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen) != 0) { + if (mb_strnicmp((char *)tagp.tagname, (char *)orgpat.head, (size_t)cmplen) != 0) { if ((off_T)vim_ftell(fp) > search_info.match_offset) { break; // past last match } else { @@ -1978,7 +1978,7 @@ parse_line: // skip this match if it can't match assert(cmplen >= 0); } - if (mb_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen) != 0) { + if (mb_strnicmp((char *)tagp.tagname, (char *)orgpat.head, (size_t)cmplen) != 0) { continue; } @@ -2014,7 +2014,7 @@ parse_line: } else { if (orgpat.regmatch.rm_ic) { assert(cmplen >= 0); - match = mb_strnicmp(tagp.tagname, orgpat.pat, (size_t)cmplen) == 0; + match = mb_strnicmp((char *)tagp.tagname, (char *)orgpat.pat, (size_t)cmplen) == 0; if (match) { match_no_ic = (STRNCMP(tagp.tagname, orgpat.pat, cmplen) == 0); @@ -2552,18 +2552,17 @@ static size_t matching_line_len(const char_u *const lbuf) /// @param tagp output: pointers into the line /// /// @return OK or FAIL. -static int parse_match(char_u *lbuf, tagptrs_T *tagp) +static int parse_match(char *lbuf, tagptrs_T *tagp) { int retval; - char_u *p; - char_u *pc, *pt; + char *p; + char *pc, *pt; - tagp->tag_fname = lbuf + 1; + tagp->tag_fname = (char_u *)lbuf + 1; lbuf += STRLEN(tagp->tag_fname) + 2; // Find search pattern and the file name for non-etags. - retval = parse_tag_line(lbuf, - tagp); + retval = parse_tag_line((char_u *)lbuf, tagp); tagp->tagkind = NULL; tagp->user_data = NULL; @@ -2572,32 +2571,32 @@ static int parse_match(char_u *lbuf, tagptrs_T *tagp) if (retval == OK) { // Try to find a kind field: "kind:" or just "" - p = tagp->command; - if (find_extra(&p) == OK) { - tagp->command_end = p; - if (p > tagp->command && p[-1] == '|') { - tagp->command_end = p - 1; // drop trailing bar + p = (char *)tagp->command; + if (find_extra((char_u **)&p) == OK) { + tagp->command_end = (char_u *)p; + if (p > (char *)tagp->command && p[-1] == '|') { + tagp->command_end = (char_u *)p - 1; // drop trailing bar } p += 2; // skip ";\"" if (*p++ == TAB) { // Accept ASCII alphabetic kind characters and any multi-byte // character. - while (ASCII_ISALPHA(*p) || utfc_ptr2len((char *)p) > 1) { + while (ASCII_ISALPHA(*p) || utfc_ptr2len(p) > 1) { if (STRNCMP(p, "kind:", 5) == 0) { - tagp->tagkind = p + 5; + tagp->tagkind = (char_u *)p + 5; } else if (STRNCMP(p, "user_data:", 10) == 0) { - tagp->user_data = p + 10; + tagp->user_data = (char_u *)p + 10; } else if (STRNCMP(p, "line:", 5) == 0) { - tagp->tagline = atoi((char *)p + 5); + tagp->tagline = atoi(p + 5); } if (tagp->tagkind != NULL && tagp->user_data != NULL) { break; } - pc = (char_u *)vim_strchr((char *)p, ':'); - pt = (char_u *)vim_strchr((char *)p, '\t'); + pc = vim_strchr(p, ':'); + pt = vim_strchr(p, '\t'); if (pc == NULL || (pt != NULL && pc > pt)) { - tagp->tagkind = p; + tagp->tagkind = (char_u *)p; } if (pt == NULL) { break; @@ -2608,16 +2607,16 @@ static int parse_match(char_u *lbuf, tagptrs_T *tagp) } } if (tagp->tagkind != NULL) { - for (p = tagp->tagkind; + for (p = (char *)tagp->tagkind; *p && *p != '\t' && *p != '\r' && *p != '\n'; MB_PTR_ADV(p)) {} - tagp->tagkind_end = p; + tagp->tagkind_end = (char_u *)p; } if (tagp->user_data != NULL) { - for (p = tagp->user_data; + for (p = (char *)tagp->user_data; *p && *p != '\t' && *p != '\r' && *p != '\n'; MB_PTR_ADV(p)) {} - tagp->user_data_end = p; + tagp->user_data_end = (char_u *)p; } } return retval; @@ -2671,7 +2670,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) pbuf = xmalloc(LSIZE); // parse the match line into the tagp structure - if (parse_match(lbuf, &tagp) == FAIL) { + if (parse_match((char *)lbuf, &tagp) == FAIL) { tagp.fname_end = NULL; goto erret; } @@ -3121,7 +3120,7 @@ int expand_tags(int tagnames, char_u *pat, int *num_file, char ***file) for (i = 0; i < *num_file; i++) { size_t len; - parse_match((char_u *)(*file)[i], &t_p); + parse_match((*file)[i], &t_p); len = (size_t)(t_p.tagname_end - t_p.tagname); if (len > name_buf_size - 3) { char_u *buf; @@ -3201,7 +3200,7 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) TAG_REGEXP | TAG_NOIC, MAXCOL, (char *)buf_fname); if (ret == OK && num_matches > 0) { for (i = 0; i < num_matches; i++) { - int parse_result = parse_match((char_u *)matches[i], &tp); + int parse_result = parse_match(matches[i], &tp); // Avoid an unused variable warning in release builds. (void)parse_result; @@ -3350,9 +3349,9 @@ static void tagstack_shift(win_T *wp) wp->w_tagstacklen--; } -// Push a new item to the tag stack -static void tagstack_push_item(win_T *wp, char_u *tagname, int cur_fnum, int cur_match, pos_T mark, - int fnum, char_u *user_data) +/// Push a new item to the tag stack +static void tagstack_push_item(win_T *wp, char *tagname, int cur_fnum, int cur_match, pos_T mark, + int fnum, char *user_data) { taggy_T *tagstack = wp->w_tagstack; int idx = wp->w_tagstacklen; // top of the stack @@ -3364,7 +3363,7 @@ static void tagstack_push_item(win_T *wp, char_u *tagname, int cur_fnum, int cur } wp->w_tagstacklen++; - tagstack[idx].tagname = (char *)tagname; + tagstack[idx].tagname = tagname; tagstack[idx].cur_fnum = cur_fnum; tagstack[idx].cur_match = cur_match; if (tagstack[idx].cur_match < 0) { @@ -3372,16 +3371,16 @@ static void tagstack_push_item(win_T *wp, char_u *tagname, int cur_fnum, int cur } tagstack[idx].fmark.mark = mark; tagstack[idx].fmark.fnum = fnum; - tagstack[idx].user_data = (char *)user_data; + tagstack[idx].user_data = user_data; } -// Add a list of items to the tag stack in the specified window +/// Add a list of items to the tag stack in the specified window static void tagstack_push_items(win_T *wp, list_T *l) { listitem_T *li; dictitem_T *di; dict_T *itemdict; - char_u *tagname; + char *tagname; pos_T mark; int fnum; @@ -3400,8 +3399,7 @@ static void tagstack_push_items(win_T *wp, list_T *l) if (list2fpos(&di->di_tv, &mark, &fnum, NULL, false) != OK) { continue; } - if ((tagname = (char_u *)tv_dict_get_string(itemdict, "tagname", true)) - == NULL) { + if ((tagname = tv_dict_get_string(itemdict, "tagname", true)) == NULL) { continue; } @@ -3413,7 +3411,7 @@ static void tagstack_push_items(win_T *wp, list_T *l) (int)tv_dict_get_number(itemdict, "bufnr"), (int)tv_dict_get_number(itemdict, "matchnr") - 1, mark, fnum, - (char_u *)tv_dict_get_string(itemdict, "user_data", true)); + tv_dict_get_string(itemdict, "user_data", true)); } } diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 46f4d137c4..08c1946e13 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -565,7 +565,7 @@ void ui_check_mouse(void) // - 'a' is in 'mouse' and "c" is in MOUSE_A, or // - the current buffer is a help file and 'h' is in 'mouse' and we are in a // normal editing mode (not at hit-return message). - for (char_u *p = (char_u *)p_mouse; *p; p++) { + for (char *p = p_mouse; *p; p++) { switch (*p) { case 'a': if (vim_strchr(MOUSE_A, checkfor) != NULL) { -- cgit From 0c6b39894f4cac99c3d81857986e4eae533fb59a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 06:19:49 +0800 Subject: feat(mapset): support restoring Lua callback (#20024) vim-patch:9.0.0341: mapset() does not restore mapping properly Problem: mapset() does not restore mapping properly. Solution: Use an empty string for . (closes vim/vim#11022) https://github.com/vim/vim/commit/92a3d20682d46359bb50a452b4f831659e799155 --- src/nvim/mapping.c | 46 ++++++++++++++++++++++++++-------------- src/nvim/testdir/test_maparg.vim | 33 ++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index ae37141eac..5c9903aa6b 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -277,21 +277,29 @@ static bool set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs mapargs->alt_lhs_len = 0; } + set_maparg_rhs(orig_rhs, orig_rhs_len, rhs_lua, cpo_flags, mapargs); + + return true; +} + +/// @see set_maparg_lhs_rhs +static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len, + const LuaRef rhs_lua, const int cpo_flags, MapArguments *const mapargs) +{ mapargs->rhs_lua = rhs_lua; if (rhs_lua == LUA_NOREF) { mapargs->orig_rhs_len = orig_rhs_len; mapargs->orig_rhs = xcalloc(mapargs->orig_rhs_len + 1, sizeof(char_u)); STRLCPY(mapargs->orig_rhs, orig_rhs, mapargs->orig_rhs_len + 1); - if (STRICMP(orig_rhs, "") == 0) { // "" means nothing - mapargs->rhs = xcalloc(1, sizeof(char_u)); // single null-char + mapargs->rhs = xcalloc(1, sizeof(char_u)); // single NUL-char mapargs->rhs_len = 0; mapargs->rhs_is_noop = true; } else { char *rhs_buf = NULL; - replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, REPTERM_DO_LT, NULL, - cpo_flags); + char *replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, REPTERM_DO_LT, NULL, + cpo_flags); mapargs->rhs_len = STRLEN(replaced); // NB: replace_termcodes may produce an empty string even if orig_rhs is non-empty // (e.g. a single ^V, see :h map-empty-rhs) @@ -308,7 +316,6 @@ static bool set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs (char_u)KS_EXTRA, KE_LUA, rhs_lua); mapargs->rhs = vim_strsave((char_u *)tmp_buf); } - return true; } /// Parse a string of |:map-arguments| into a @ref MapArguments struct. @@ -2150,29 +2157,36 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) char *lhs = tv_dict_get_string(d, "lhs", false); char *lhsraw = tv_dict_get_string(d, "lhsraw", false); char *lhsrawalt = tv_dict_get_string(d, "lhsrawalt", false); - char *rhs = tv_dict_get_string(d, "rhs", false); - if (lhs == NULL || lhsraw == NULL || rhs == NULL) { + char *orig_rhs = tv_dict_get_string(d, "rhs", false); + LuaRef rhs_lua = LUA_NOREF; + dictitem_T *callback_di = tv_dict_find(d, S_LEN("callback")); + if (callback_di != NULL) { + Object callback_obj = vim_to_object(&callback_di->di_tv); + if (callback_obj.type == kObjectTypeLuaRef && callback_obj.data.luaref != LUA_NOREF) { + rhs_lua = callback_obj.data.luaref; + orig_rhs = ""; // need non-NULL for strlen() + callback_obj.data.luaref = LUA_NOREF; + } + api_free_object(callback_obj); + } + if (lhs == NULL || lhsraw == NULL || (orig_rhs == NULL && rhs_lua == LUA_NOREF)) { emsg(_("E460: entries missing in mapset() dict argument")); + api_free_luaref(rhs_lua); return; } - char *orig_rhs = rhs; - char *arg_buf = NULL; - rhs = replace_termcodes(rhs, STRLEN(rhs), &arg_buf, REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); - int noremap = tv_dict_get_number(d, "noremap") ? REMAP_NONE : 0; + int noremap = tv_dict_get_number(d, "noremap") != 0 ? REMAP_NONE : 0; if (tv_dict_get_number(d, "script") != 0) { noremap = REMAP_SCRIPT; } - MapArguments args = { // TODO(zeertzjq): support restoring "callback"? - .rhs = (char_u *)rhs, - .rhs_lua = LUA_NOREF, - .orig_rhs = vim_strsave((char_u *)orig_rhs), + MapArguments args = { .expr = tv_dict_get_number(d, "expr") != 0, .silent = tv_dict_get_number(d, "silent") != 0, .nowait = tv_dict_get_number(d, "nowait") != 0, .replace_keycodes = tv_dict_get_number(d, "replace_keycodes") != 0, .desc = tv_dict_get_string(d, "desc", false), }; + set_maparg_rhs(orig_rhs, strlen(orig_rhs), rhs_lua, CPO_TO_CPO_FLAGS, &args); scid_T sid = (scid_T)tv_dict_get_number(d, "sid"); linenr_T lnum = (linenr_T)tv_dict_get_number(d, "lnum"); bool buffer = tv_dict_get_number(d, "buffer") != 0; @@ -2183,7 +2197,7 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) // Delete any existing mapping for this lhs and mode. MapArguments unmap_args = MAP_ARGUMENTS_INIT; - set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &unmap_args); + set_maparg_lhs_rhs(lhs, strlen(lhs), "", 0, LUA_NOREF, 0, &unmap_args); unmap_args.buffer = buffer; buf_do_map(MAPTYPE_UNMAP, &unmap_args, mode, false, curbuf); xfree(unmap_args.rhs); diff --git a/src/nvim/testdir/test_maparg.vim b/src/nvim/testdir/test_maparg.vim index 17c5f433ac..f903f5b934 100644 --- a/src/nvim/testdir/test_maparg.vim +++ b/src/nvim/testdir/test_maparg.vim @@ -158,11 +158,11 @@ func Test_range_map() call assert_equal("abcd", getline(1)) endfunc -func One_mapset_test(keys) - exe 'nnoremap ' .. a:keys .. ' original' +func One_mapset_test(keys, rhs) + exe 'nnoremap ' .. a:keys .. ' ' .. a:rhs let orig = maparg(a:keys, 'n', 0, 1) call assert_equal(a:keys, orig.lhs) - call assert_equal('original', orig.rhs) + call assert_equal(a:rhs, orig.rhs) call assert_equal('n', orig.mode) exe 'nunmap ' .. a:keys @@ -172,15 +172,16 @@ func One_mapset_test(keys) call mapset('n', 0, orig) let d = maparg(a:keys, 'n', 0, 1) call assert_equal(a:keys, d.lhs) - call assert_equal('original', d.rhs) + call assert_equal(a:rhs, d.rhs) call assert_equal('n', d.mode) exe 'nunmap ' .. a:keys endfunc func Test_mapset() - call One_mapset_test('K') - call One_mapset_test('') + call One_mapset_test('K', 'original') + call One_mapset_test('', 'original') + call One_mapset_test('', 'Nop>') " Check <> key conversion new @@ -203,6 +204,26 @@ func Test_mapset() iunmap K + " Test that is restored properly + inoremap K + call feedkeys("SK\", 'xt') + call assert_equal('', getline(1)) + + let orig = maparg('K', 'i', 0, 1) + call assert_equal('K', orig.lhs) + call assert_equal('', orig.rhs) + call assert_equal('i', orig.mode) + + inoremap K foo + call feedkeys("SK\", 'xt') + call assert_equal('foo', getline(1)) + + call mapset('i', 0, orig) + call feedkeys("SK\", 'xt') + call assert_equal('', getline(1)) + + iunmap K + " Test literal using a backslash let cpo_save = &cpo set cpo-=B -- cgit From 8740e0bd58c7311826e781591db5d29b4b3ffa73 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 09:12:20 +0800 Subject: vim-patch:9.0.0343: ColorScheme autocommand triggered when colorscheme not found (#20032) Problem: ColorScheme autocommand triggered when colorscheme is not found. (Romain Lafourcade) Solution: Only trigger ColorScheme when loading the colorscheme succeeds. (closes vim/vim#11024) https://github.com/vim/vim/commit/5d09a401ec393dc930e1104ceb38eab34681de64 Most of Test_colorscheme() is applicable to Nvim. --- src/nvim/highlight_group.c | 4 +++- src/nvim/testdir/test_gui.vim | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/nvim/testdir/test_gui.vim (limited to 'src') diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index ed1f0185b7..da842e9f84 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -632,7 +632,9 @@ int load_colors(char_u *name) retval = source_runtime((char *)buf, DIP_START + DIP_OPT); } xfree(buf); - apply_autocmds(EVENT_COLORSCHEME, (char *)name, curbuf->b_fname, false, curbuf); + if (retval == OK) { + apply_autocmds(EVENT_COLORSCHEME, (char *)name, curbuf->b_fname, false, curbuf); + } recursive = false; diff --git a/src/nvim/testdir/test_gui.vim b/src/nvim/testdir/test_gui.vim new file mode 100644 index 0000000000..c3f1f3163a --- /dev/null +++ b/src/nvim/testdir/test_gui.vim @@ -0,0 +1,43 @@ + +func Test_colorscheme() + " call assert_equal('16777216', &t_Co) + + let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default' + let g:color_count = 0 + augroup TestColors + au! + au ColorScheme * let g:color_count += 1 + \ | let g:after_colors = g:color_count + \ | let g:color_after = expand('') + au ColorSchemePre * let g:color_count += 1 + \ | let g:before_colors = g:color_count + \ | let g:color_pre = expand('') + augroup END + + colorscheme torte + redraw! + call assert_equal('dark', &background) + call assert_equal(1, g:before_colors) + call assert_equal(2, g:after_colors) + call assert_equal('torte', g:color_pre) + call assert_equal('torte', g:color_after) + call assert_equal("\ntorte", execute('colorscheme')) + + let a = substitute(execute('hi Search'), "\n\\s\\+", ' ', 'g') + " FIXME: temporarily check less while the colorscheme changes + " call assert_match("\nSearch xxx term=reverse cterm=reverse ctermfg=196 ctermbg=16 gui=reverse guifg=#ff0000 guibg=#000000", a) + " call assert_match("\nSearch xxx term=reverse ", a) + + call assert_fails('colorscheme does_not_exist', 'E185:') + call assert_equal('does_not_exist', g:color_pre) + call assert_equal('torte', g:color_after) + + exec 'colorscheme' colorscheme_saved + augroup TestColors + au! + augroup END + unlet g:color_count g:after_colors g:before_colors + redraw! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From a62cb406b16c53dcfbcc74c164f5ebe888ddcd89 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 10:22:28 +0800 Subject: fix(maparg): remove double allocation (#20033) ASAN doesn't catch this, as it is referenced by the garbage collector. Also remove a condition that is always true. --- src/nvim/mapping.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 5c9903aa6b..50360ee084 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2008,8 +2008,7 @@ static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhs FUNC_ATTR_NONNULL_ARG(1) { Dictionary dict = ARRAY_DICT_INIT; - char *const lhs = str2special_save((const char *)mp->m_keys, - compatible, !compatible); + char *const lhs = str2special_save((const char *)mp->m_keys, compatible, !compatible); char *const mapmode = map_mode_to_chars(mp->m_mode); varnumber_T noremap_value; @@ -2122,13 +2121,15 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) } } else { // Return a dictionary. - tv_dict_alloc_ret(rettv); if (mp != NULL && (rhs != NULL || rhs_lua != LUA_NOREF)) { Dictionary dict = mapblock_fill_dict(mp, did_simplify ? (char *)keys_simplified : NULL, buffer_local, true); (void)object_to_vim(DICTIONARY_OBJ(dict), rettv, NULL); api_free_dictionary(dict); + } else { + // Return an empty dictionary. + tv_dict_alloc_ret(rettv); } } @@ -2164,12 +2165,12 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) Object callback_obj = vim_to_object(&callback_di->di_tv); if (callback_obj.type == kObjectTypeLuaRef && callback_obj.data.luaref != LUA_NOREF) { rhs_lua = callback_obj.data.luaref; - orig_rhs = ""; // need non-NULL for strlen() + orig_rhs = ""; callback_obj.data.luaref = LUA_NOREF; } api_free_object(callback_obj); } - if (lhs == NULL || lhsraw == NULL || (orig_rhs == NULL && rhs_lua == LUA_NOREF)) { + if (lhs == NULL || lhsraw == NULL || orig_rhs == NULL) { emsg(_("E460: entries missing in mapset() dict argument")); api_free_luaref(rhs_lua); return; -- cgit From 5f92d9b345e11adb73df33dc22a8e656aca73b6c Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 1 Sep 2022 09:44:01 +0200 Subject: perf(messages): don't call ui_flush() per message line in various places When msgsep is used, message scrolling is emulated. To make message output fast, inhibit emulated scrolling until the full message text is known --- src/nvim/cmdexpand.c | 1 - src/nvim/cmdhist.c | 1 - src/nvim/ex_cmds.c | 1 - src/nvim/ex_docmd.c | 3 --- src/nvim/mapping.c | 1 - src/nvim/mark.c | 3 --- src/nvim/ops.c | 1 - src/nvim/option.c | 1 - src/nvim/quickfix.c | 2 -- src/nvim/search.c | 2 -- src/nvim/tag.c | 1 - 11 files changed, 17 deletions(-) (limited to 'src') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 1c35f28301..7180a8de46 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -717,7 +717,6 @@ int showmatches(expand_T *xp, int wildmenu) msg_clr_eos(); msg_putchar('\n'); } - ui_flush(); // show one line at a time if (got_int) { got_int = false; break; diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c index 1426054d0b..2057b0db9e 100644 --- a/src/nvim/cmdhist.c +++ b/src/nvim/cmdhist.c @@ -650,7 +650,6 @@ void ex_history(exarg_T *eap) STRCAT(IObuff, hist[i].hisstr); } msg_outtrans((char *)IObuff); - ui_flush(); } if (i == idx) { break; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 17d45f207e..2c82436a25 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -5004,7 +5004,6 @@ void ex_oldfiles(exarg_T *eap) msg_outtrans((char *)tv_get_string(TV_LIST_ITEM_TV(li))); msg_clr_eos(); msg_putchar('\n'); - ui_flush(); // output one line at a time os_breakcheck(); } }); diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 8f72ba0e23..9e196e9516 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -4833,7 +4833,6 @@ static void ex_print(exarg_T *eap) if (++eap->line1 > eap->line2) { break; } - ui_flush(); // show one line at a time } setpcmark(); // put cursor at last line @@ -5035,7 +5034,6 @@ static void ex_tabs(exarg_T *eap) msg_putchar('\n'); vim_snprintf((char *)IObuff, IOSIZE, _("Tab page %d"), tabcount++); msg_outtrans_attr((char *)IObuff, HL_ATTR(HLF_T)); - ui_flush(); // output one line at a time os_breakcheck(); FOR_ALL_WINDOWS_IN_TAB(wp, tp) { @@ -5054,7 +5052,6 @@ static void ex_tabs(exarg_T *eap) home_replace(wp->w_buffer, wp->w_buffer->b_fname, (char *)IObuff, IOSIZE, true); } msg_outtrans((char *)IObuff); - ui_flush(); // output one line at a time os_breakcheck(); } } diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index ae37141eac..a3705d5c6f 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -214,7 +214,6 @@ static void showmap(mapblock_T *mp, bool local) last_set_msg(mp->m_script_ctx); } msg_clr_eos(); - ui_flush(); // show one line at a time } /// Replace termcodes in the given LHS and RHS and store the results into the diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 816599271d..7eab37e797 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -925,7 +925,6 @@ static void show_one_mark(int c, char_u *arg, pos_T *p, char_u *name_arg, int cu msg_outtrans_attr((char *)name, current ? HL_ATTR(HLF_D) : 0); } } - ui_flush(); // show one line at a time } if (mustfree) { xfree(name); @@ -1058,7 +1057,6 @@ void ex_jumps(exarg_T *eap) xfree(name); os_breakcheck(); } - ui_flush(); } if (curwin->w_jumplistidx == curwin->w_jumplistlen) { msg_puts("\n>"); @@ -1101,7 +1099,6 @@ void ex_changes(exarg_T *eap) xfree(name); os_breakcheck(); } - ui_flush(); } if (curwin->w_changelistidx == curbuf->b_changelistlen) { msg_puts("\n>"); diff --git a/src/nvim/ops.c b/src/nvim/ops.c index adb071b754..d2321be4a4 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3866,7 +3866,6 @@ void ex_display(exarg_T *eap) if (n > 1 && yb->y_type == kMTLineWise) { msg_puts_attr("^J", attr); } - ui_flush(); // show one line at a time } os_breakcheck(); } diff --git a/src/nvim/option.c b/src/nvim/option.c index 455070c742..269a21b512 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3355,7 +3355,6 @@ static void showoptions(int all, int opt_flags) showoneopt(items[i], opt_flags); col += INC; } - ui_flush(); os_breakcheck(); } } diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index f1fc48ef40..86f60cb57e 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3094,8 +3094,6 @@ static void qf_list_entry(qfline_T *qfp, int qf_idx, bool cursel) if (tbuf != IObuff) { xfree(tbuf); } - - ui_flush(); // show one line at a time } // ":clist": list all errors diff --git a/src/nvim/search.c b/src/nvim/search.c index d7f8d4e1cd..e9ac9ecf2b 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -3714,7 +3714,6 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo } } } - ui_flush(); // output each line directly } if (new_fname != NULL) { @@ -4147,7 +4146,6 @@ static void show_pat_in_path(char_u *line, int type, bool did_show, int action, msg_puts(" "); } msg_prt_line((char *)line, false); - ui_flush(); // show one line at a time // Definition continues until line that doesn't end with '\' if (got_int || type != FIND_DEFINE || p < line || *p != '\\') { diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 4fd99b058b..b694297d63 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -1056,7 +1056,6 @@ void do_tags(exarg_T *eap) ? HL_ATTR(HLF_D) : 0); xfree(name); } - ui_flush(); // show one line at a time } if (tagstackidx == tagstacklen) { // idx at top of stack msg_puts("\n>"); -- cgit From db2e5f46f5aa5a6300395eaa9c4923835683c770 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 16:37:29 +0800 Subject: fix(lua): make ui_attach()/ui_detach() take effect immediately (#20037) --- src/nvim/ui_compositor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 5167f291c3..b8c7834e2b 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -749,7 +749,7 @@ void ui_comp_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) *item = event_cb; ui_comp_update_ext(); - ui_schedule_refresh(); + ui_refresh(); } void ui_comp_remove_cb(uint32_t ns_id) @@ -759,5 +759,5 @@ void ui_comp_remove_cb(uint32_t ns_id) pmap_del(uint32_t)(&ui_event_cbs, ns_id); } ui_comp_update_ext(); - ui_schedule_refresh(); + ui_refresh(); } -- cgit From 49e893f296bca9eef5ff45a3d746c261d055bf10 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/change.c | 10 +- src/nvim/charset.c | 54 +++++----- src/nvim/cmdexpand.c | 71 +++++++------ src/nvim/cmdhist.c | 24 ++--- src/nvim/cmdhist.h | 2 +- src/nvim/cursor.c | 4 +- src/nvim/digraph.c | 24 ++--- src/nvim/edit.c | 36 +++---- src/nvim/eval.c | 4 +- src/nvim/eval/decode.c | 4 +- src/nvim/eval/funcs.c | 42 ++++---- src/nvim/eval/typval.c | 3 +- src/nvim/eval/userfunc.c | 197 ++++++++++++++++++------------------- src/nvim/ex_cmds.c | 8 +- src/nvim/ex_docmd.c | 4 +- src/nvim/ex_getln.c | 134 ++++++++++++------------- src/nvim/ex_getln.h | 2 +- src/nvim/file_search.c | 104 +++++++++----------- src/nvim/fileio.c | 22 ++--- src/nvim/getchar.c | 4 +- src/nvim/grid.c | 2 +- src/nvim/indent.c | 10 +- src/nvim/indent_c.c | 82 +++++++-------- src/nvim/insexpand.c | 120 +++++++++++----------- src/nvim/keycodes.c | 8 +- src/nvim/mark.c | 22 ++--- src/nvim/match.c | 26 ++--- src/nvim/mbyte.c | 42 ++++---- src/nvim/memline.c | 40 ++++---- src/nvim/message.c | 6 +- src/nvim/normal.c | 24 ++--- src/nvim/ops.c | 82 ++++++++------- src/nvim/option.c | 6 +- src/nvim/os/shell.c | 4 +- src/nvim/path.c | 33 ++++--- src/nvim/regexp.c | 6 +- src/nvim/regexp_bt.c | 16 +-- src/nvim/regexp_nfa.c | 10 +- src/nvim/search.c | 31 +++--- src/nvim/shada.c | 8 +- src/nvim/spell.c | 22 ++--- src/nvim/spellsuggest.c | 47 +++++---- src/nvim/strings.c | 21 +--- src/nvim/syntax.c | 33 ++++--- src/nvim/tag.c | 31 +++--- src/nvim/textformat.c | 14 +-- src/nvim/textobject.c | 4 +- src/nvim/viml/parser/expressions.c | 9 +- src/nvim/window.c | 6 +- 49 files changed, 742 insertions(+), 776 deletions(-) (limited to 'src') diff --git a/src/nvim/change.c b/src/nvim/change.c index 5bea388f28..5e9edac4f2 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -599,7 +599,7 @@ void ins_bytes_len(char *p, size_t len) size_t n; for (size_t i = 0; i < len; i += n) { // avoid reading past p[len] - n = (size_t)utfc_ptr2len_len((char_u *)p + i, (int)(len - i)); + n = (size_t)utfc_ptr2len_len(p + i, (int)(len - i)); ins_char_bytes(p + i, n); } } @@ -828,7 +828,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) col = n; count = utf_ptr2len(oldp + n); n += count; - } while (utf_composinglike((char_u *)oldp + col, (char_u *)oldp + n)); + } while (utf_composinglike(oldp + col, oldp + n)); fixpos = false; } } @@ -1036,7 +1036,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) colnr_T mincol = curwin->w_cursor.col + 1; // make a copy of the current line so we can mess with it - char *saved_line = (char *)vim_strsave(get_cursor_line_ptr()); + char *saved_line = (char *)vim_strsave((char_u *)get_cursor_line_ptr()); if (State & VREPLACE_FLAG) { // With MODE_VREPLACE we make a copy of the next line, which we will be @@ -1181,7 +1181,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if ((pos = findmatch(NULL, '(')) != NULL) { curwin->w_cursor.lnum = pos->lnum; newindent = get_indent(); - ptr = (char *)get_cursor_line_ptr(); + ptr = get_cursor_line_ptr(); } } // If last character is '{' do indent, without @@ -1838,7 +1838,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // stuff onto the replace stack (via ins_char()). if (State & VREPLACE_FLAG) { // Put new line in p_extra - p_extra = (char *)vim_strsave(get_cursor_line_ptr()); + p_extra = xstrdup(get_cursor_line_ptr()); // Put back original line ml_replace(curwin->w_cursor.lnum, next_line, false); diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 4604bf7716..3396e2de41 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -789,7 +789,7 @@ bool vim_iswordc_buf(const int c, buf_T *const buf) bool vim_iswordp(const char_u *const p) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return vim_iswordp_buf(p, curbuf); + return vim_iswordp_buf((char *)p, curbuf); } /// Just like vim_iswordc_buf() but uses a pointer to the (multi-byte) @@ -799,13 +799,13 @@ bool vim_iswordp(const char_u *const p) /// @param buf buffer whose keywords to use /// /// @return true if "p" points to a keyword character. -bool vim_iswordp_buf(const char_u *const p, buf_T *const buf) +bool vim_iswordp_buf(const char *const p, buf_T *const buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - int c = *p; + int c = (uint8_t)(*p); if (MB_BYTE2LEN(c) > 1) { - c = utf_ptr2char((char *)p); + c = utf_ptr2char(p); } return vim_iswordc_buf(c, buf); } @@ -829,8 +829,8 @@ bool vim_isfilec(int c) bool vim_isfilec_or_wc(int c) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - char_u buf[2]; - buf[0] = (char_u)c; + char buf[2]; + buf[0] = (char)c; buf[1] = NUL; return vim_isfilec(c) || c == ']' || path_has_wildcard(buf); } @@ -905,15 +905,15 @@ bool in_win_border(win_T *wp, colnr_T vcol) /// @param end void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end) { - char_u *ptr; // points to current char - char_u *posptr; // points to char at pos->col + char *ptr; // points to current char + char *posptr; // points to char at pos->col int incr; int head; long *vts = wp->w_buffer->b_p_vts_array; int ts = (int)wp->w_buffer->b_p_ts; colnr_T vcol = 0; - char_u *line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line + char *line = ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line if (pos->col == MAXCOL) { // continue until the NUL @@ -927,11 +927,11 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en } } posptr = ptr + pos->col; - posptr -= utf_head_off((char *)line, (char *)posptr); + posptr -= utf_head_off(line, posptr); } chartabsize_T cts; - init_chartabsize_arg(&cts, wp, pos->lnum, 0, (char *)line, (char *)line); + init_chartabsize_arg(&cts, wp, pos->lnum, 0, line, line); // This function is used very often, do some speed optimizations. // When 'list', 'linebreak', 'showbreak' and 'breakindent' are not set @@ -944,7 +944,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en && !cts.cts_has_virt_text) { for (;;) { head = 0; - int c = *ptr; + int c = (uint8_t)(*ptr); // make sure we don't go past the end of the line if (c == NUL) { @@ -960,7 +960,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en // For utf-8, if the byte is >= 0x80, need to look at // further bytes to find the cell width. if (c >= 0x80) { - incr = utf_ptr2cells((char *)ptr); + incr = utf_ptr2cells(ptr); } else { incr = g_chartab[c] & CT_CELL_MASK; } @@ -970,7 +970,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en // cells wide. if ((incr == 2) && wp->w_p_wrap - && (MB_BYTE2LEN(*ptr) > 1) + && (MB_BYTE2LEN((uint8_t)(*ptr)) > 1) && in_win_border(wp, vcol)) { incr++; head = 1; @@ -999,7 +999,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en break; } - if ((posptr != NULL) && ((char_u *)cts.cts_ptr >= posptr)) { + if ((posptr != NULL) && (cts.cts_ptr >= posptr)) { // character at pos->col break; } @@ -1008,7 +1008,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en MB_PTR_ADV(cts.cts_ptr); } vcol = cts.cts_vcol; - ptr = (char_u *)cts.cts_ptr; + ptr = cts.cts_ptr; } clear_chartabsize_arg(&cts); @@ -1076,10 +1076,10 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *e colnr_T endadd = 0; // Cannot put the cursor on part of a wide character. - char_u *ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); + char *ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false); if (pos->col < (colnr_T)STRLEN(ptr)) { - int c = utf_ptr2char((char *)ptr + pos->col); + int c = utf_ptr2char(ptr + pos->col); if ((c != TAB) && vim_isprintc(c)) { endadd = (colnr_T)(char2cells(c) - 1); if (coladd > endadd) { @@ -1182,7 +1182,7 @@ char *skipwhite_len(const char *p, size_t len) // columns (bytes) at the start of a given line intptr_t getwhitecols_curline(void) { - return getwhitecols((char *)get_cursor_line_ptr()); + return getwhitecols(get_cursor_line_ptr()); } intptr_t getwhitecols(const char *p) @@ -1338,7 +1338,7 @@ char *skip_to_newline(const char *const p) /// Gets a number from a string and skips over it, signalling overflow. /// -/// @param[out] pp A pointer to a pointer to char_u. +/// @param[out] pp A pointer to a pointer to char. /// It will be advanced past the read number. /// @param[out] nr Number read from the string. /// @@ -1355,7 +1355,7 @@ bool try_getdigits(char **pp, intmax_t *nr) /// Gets a number from a string and skips over it. /// -/// @param[out] pp Pointer to a pointer to char_u. +/// @param[out] pp Pointer to a pointer to char. /// It will be advanced past the read number. /// @param strict Abort on overflow. /// @param def Default value, if parsing fails or overflow occurs. @@ -1463,14 +1463,14 @@ bool vim_isblankline(char *lbuf) /// @param strict If true, fail if the number has unexpected trailing /// alphanumeric chars: *len is set to 0 and nothing else is /// returned. -void vim_str2nr(const char_u *const start, int *const prep, int *const len, const int what, +void vim_str2nr(const char *const start, int *const prep, int *const len, const int what, varnumber_T *const nptr, uvarnumber_T *const unptr, const int maxlen, const bool strict) FUNC_ATTR_NONNULL_ARG(1) { - const char *ptr = (const char *)start; + const char *ptr = start; #define STRING_ENDED(ptr) \ - (!(maxlen == 0 || (int)((ptr) - (const char *)start) < maxlen)) + (!(maxlen == 0 || (int)((ptr) - start) < maxlen)) int pre = 0; // default is decimal const bool negative = (ptr[0] == '-'); uvarnumber_T un = 0; @@ -1522,7 +1522,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len, cons } else if ((what & (STR2NR_HEX | STR2NR_OCT | STR2NR_OOCT | STR2NR_BIN)) && !STRING_ENDED(ptr + 1) && ptr[0] == '0' && ptr[1] != '8' && ptr[1] != '9') { - pre = (char_u)ptr[1]; + pre = (uint8_t)ptr[1]; // Detect hexadecimal: 0x or 0X followed by hex digit. if ((what & STR2NR_HEX) && !STRING_ENDED(ptr + 2) @@ -1610,7 +1610,7 @@ vim_str2nr_hex: vim_str2nr_proceed: // Check for an alphanumeric character immediately following, that is // most likely a typo. - if (strict && ptr - (const char *)start != maxlen && ASCII_ISALNUM(*ptr)) { + if (strict && ptr - start != maxlen && ASCII_ISALNUM(*ptr)) { return; } @@ -1619,7 +1619,7 @@ vim_str2nr_proceed: } if (len != NULL) { - *len = (int)(ptr - (const char *)start); + *len = (int)(ptr - start); } if (nptr != NULL) { diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 6fc63f72a1..0d3aefc83e 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -177,7 +177,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) ui_flush(); } - i = (int)((char_u *)xp->xp_pattern - ccline->cmdbuff); + i = (int)(xp->xp_pattern - ccline->cmdbuff); assert(ccline->cmdpos >= i); xp->xp_pattern_len = (size_t)ccline->cmdpos - (size_t)i; @@ -186,20 +186,20 @@ int nextwild(expand_T *xp, int type, int options, bool escape) p2 = ExpandOne(xp, NULL, NULL, 0, type); } else { // Translate string into pattern and expand it. - p1 = addstar((char_u *)xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); + p1 = (char_u *)addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); const int use_options = (options | WILD_HOME_REPLACE | WILD_ADD_SLASH | WILD_SILENT | (escape ? WILD_ESCAPE : 0) | (p_wic ? WILD_ICASE : 0)); - p2 = ExpandOne(xp, p1, vim_strnsave(&ccline->cmdbuff[i], xp->xp_pattern_len), + p2 = ExpandOne(xp, p1, (char_u *)xstrnsave(&ccline->cmdbuff[i], xp->xp_pattern_len), use_options, type); xfree(p1); // xp->xp_pattern might have been modified by ExpandOne (for example, // in lua completion), so recompute the pattern index and length - i = (int)((char_u *)xp->xp_pattern - ccline->cmdbuff); + i = (int)(xp->xp_pattern - ccline->cmdbuff); xp->xp_pattern_len = (size_t)ccline->cmdpos - (size_t)i; // Longest match: make sure it is not shorter, happens with :help. @@ -220,7 +220,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) difflen = (int)STRLEN(p2) - (int)(xp->xp_pattern_len); if (ccline->cmdlen + difflen + 4 > ccline->cmdbufflen) { realloc_cmdbuff(ccline->cmdlen + difflen + 4); - xp->xp_pattern = (char *)ccline->cmdbuff + i; + xp->xp_pattern = ccline->cmdbuff + i; } assert(ccline->cmdpos <= ccline->cmdlen); memmove(&ccline->cmdbuff[ccline->cmdpos + difflen], @@ -573,7 +573,7 @@ int showmatches(expand_T *xp, int wildmenu) if (xp->xp_numfiles == -1) { set_expand_context(xp); - i = expand_cmdline(xp, ccline->cmdbuff, ccline->cmdpos, + i = expand_cmdline(xp, (char_u *)ccline->cmdbuff, ccline->cmdpos, &num_files, &files_found); showtail = expand_showtail(xp); if (i != EXPAND_OK) { @@ -602,7 +602,7 @@ int showmatches(expand_T *xp, int wildmenu) .pum_kind = NULL, }; } - char_u *endpos = (char_u *)(showtail ? sm_gettail(xp->xp_pattern, true) : xp->xp_pattern); + char *endpos = (showtail ? sm_gettail(xp->xp_pattern, true) : xp->xp_pattern); if (ui_has(kUICmdline)) { compl_startcol = (int)(endpos - ccline->cmdbuff); } else { @@ -803,13 +803,13 @@ static bool expand_showtail(expand_T *xp) /// the name into allocated memory and prepend "^". /// /// @param context EXPAND_FILES etc. -char_u *addstar(char_u *fname, size_t len, int context) +char *addstar(char *fname, size_t len, int context) FUNC_ATTR_NONNULL_RET { - char_u *retval; + char *retval; size_t i, j; size_t new_len; - char_u *tail; + char *tail; int ends_in_star; if (context != EXPAND_FILES @@ -831,7 +831,7 @@ char_u *addstar(char_u *fname, size_t len, int context) || context == EXPAND_PACKADD || ((context == EXPAND_TAGS_LISTFILES || context == EXPAND_TAGS) && fname[0] == '/')) { - retval = vim_strnsave(fname, len); + retval = xstrnsave(fname, len); } else { new_len = len + 2; // +2 for '^' at start, NUL at end for (i = 0; i < len; i++) { @@ -901,7 +901,7 @@ char_u *addstar(char_u *fname, size_t len, int context) // $ could be anywhere in the tail. // ` could be anywhere in the file name. // When the name ends in '$' don't add a star, remove the '$'. - tail = (char_u *)path_tail((char *)retval); + tail = path_tail(retval); ends_in_star = (len > 0 && retval[len - 1] == '*'); #ifndef BACKSLASH_IN_FILENAME for (ssize_t k = (ssize_t)len - 2; k >= 0; k--) { @@ -913,8 +913,8 @@ char_u *addstar(char_u *fname, size_t len, int context) #endif if ((*retval != '~' || tail != retval) && !ends_in_star - && vim_strchr((char *)tail, '$') == NULL - && vim_strchr((char *)retval, '`') == NULL) { + && vim_strchr(tail, '$') == NULL + && vim_strchr(retval, '`') == NULL) { retval[len++] = '*'; } else if (len > 0 && retval[len - 1] == '$') { len--; @@ -976,7 +976,7 @@ void set_expand_context(expand_T *xp) xp->xp_context = EXPAND_NOTHING; return; } - set_cmd_context(xp, ccline->cmdbuff, ccline->cmdlen, ccline->cmdpos, true); + set_cmd_context(xp, (char_u *)ccline->cmdbuff, ccline->cmdlen, ccline->cmdpos, true); } /// Sets the index of a built-in or user defined command "cmd" in eap->cmdidx. @@ -1850,7 +1850,7 @@ void set_cmd_context(expand_T *xp, char_u *str, int len, int col, int use_ccline set_context_for_expression(xp, (char *)str, CMD_SIZE); } else if (use_ccline && ccline->input_fn) { xp->xp_context = ccline->xp_context; - xp->xp_pattern = (char *)ccline->cmdbuff; + xp->xp_pattern = ccline->cmdbuff; xp->xp_arg = (char *)ccline->xp_arg; } else { while (nextcomm != NULL) { @@ -1897,7 +1897,7 @@ int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, char *** // add star to file name, or convert to regexp if not exp. files. assert((str + col) - (char_u *)xp->xp_pattern >= 0); xp->xp_pattern_len = (size_t)((str + col) - (char_u *)xp->xp_pattern); - file_str = addstar((char_u *)xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); + file_str = (char_u *)addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); if (p_wic) { options += WILD_ICASE; @@ -2437,9 +2437,9 @@ static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T FUNC_ATTR_NONNULL_ALL { CmdlineInfo *const ccline = get_cmdline_info(); - char_u keep = 0; + char keep = 0; typval_T args[4]; - char_u *pat = NULL; + char *pat = NULL; const sctx_T save_current_sctx = current_sctx; if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) { @@ -2453,12 +2453,12 @@ static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T ccline->cmdbuff[ccline->cmdlen] = 0; } - pat = vim_strnsave((char_u *)xp->xp_pattern, xp->xp_pattern_len); + pat = xstrnsave(xp->xp_pattern, xp->xp_pattern_len); args[0].v_type = VAR_STRING; args[1].v_type = VAR_STRING; args[2].v_type = VAR_NUMBER; args[3].v_type = VAR_UNKNOWN; - args[0].vval.v_string = (char *)pat; + args[0].vval.v_string = pat; args[1].vval.v_string = xp->xp_line; args[2].vval.v_number = xp->xp_col; @@ -2478,30 +2478,29 @@ static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T /// Expand names with a function defined by the user. static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***file) { - char_u *e; + char *e; garray_T ga; - char_u *const retstr = call_user_expand_func((user_expand_func_T)call_func_retstr, xp, num_file, - file); + char *const retstr = call_user_expand_func((user_expand_func_T)call_func_retstr, xp, num_file, + file); if (retstr == NULL) { return FAIL; } ga_init(&ga, (int)sizeof(char *), 3); - for (char_u *s = retstr; *s != NUL; s = e) { - e = (char_u *)vim_strchr((char *)s, '\n'); + for (char *s = retstr; *s != NUL; s = e) { + e = vim_strchr(s, '\n'); if (e == NULL) { e = s + STRLEN(s); } - const char_u keep = *e; + const char keep = *e; *e = NUL; - const bool skip = xp->xp_pattern[0] - && vim_regexec(regmatch, (char *)s, (colnr_T)0) == 0; + const bool skip = xp->xp_pattern[0] && vim_regexec(regmatch, s, (colnr_T)0) == 0; *e = keep; if (!skip) { - GA_APPEND(char_u *, &ga, vim_strnsave(s, (size_t)(e - s))); + GA_APPEND(char *, &ga, xstrnsave(s, (size_t)(e - s))); } if (*e != NUL) { @@ -2662,7 +2661,7 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp) // cursor int found = false; - int j = (int)((char_u *)xp->xp_pattern - cclp->cmdbuff); + int j = (int)(xp->xp_pattern - cclp->cmdbuff); int i = 0; while (--j > 0) { // check for start of menu name @@ -2717,9 +2716,9 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp) int found = false; int j = cclp->cmdpos; - int i = (int)((char_u *)xp->xp_pattern - cclp->cmdbuff); + int i = (int)(xp->xp_pattern - cclp->cmdbuff); while (--j > i) { - j -= utf_head_off((char *)cclp->cmdbuff, (char *)cclp->cmdbuff + j); + j -= utf_head_off(cclp->cmdbuff, cclp->cmdbuff + j); if (vim_ispathsep(cclp->cmdbuff[j])) { found = true; break; @@ -2738,9 +2737,9 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp) int found = false; int j = cclp->cmdpos - 1; - int i = (int)((char_u *)xp->xp_pattern - cclp->cmdbuff); + int i = (int)(xp->xp_pattern - cclp->cmdbuff); while (--j > i) { - j -= utf_head_off((char *)cclp->cmdbuff, (char *)cclp->cmdbuff + j); + j -= utf_head_off(cclp->cmdbuff, cclp->cmdbuff + j); if (vim_ispathsep(cclp->cmdbuff[j]) #ifdef BACKSLASH_IN_FILENAME && vim_strchr((const char_u *)" *?[{`$%#", cclp->cmdbuff[j + 1]) @@ -2894,7 +2893,7 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } theend: - pat = addstar((char_u *)xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context); + pat = (char_u *)addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context); ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP); tv_list_alloc_ret(rettv, xpc.xp_numfiles); diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c index 2057b0db9e..629c47f24a 100644 --- a/src/nvim/cmdhist.c +++ b/src/nvim/cmdhist.c @@ -201,7 +201,7 @@ static int in_history(int type, char_u *str, int move_to_front, int sep) // For search history, check that the separator character matches as // well. - char_u *p = history[type][i].hisstr; + char_u *p = (char_u *)history[type][i].hisstr; if (STRCMP(str, p) == 0 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) { if (!move_to_front) { @@ -217,7 +217,7 @@ static int in_history(int type, char_u *str, int move_to_front, int sep) if (last_i >= 0) { list_T *const list = history[type][i].additional_elements; - str = history[type][i].hisstr; + str = (char_u *)history[type][i].hisstr; while (i != hisidx[type]) { if (++i >= hislen) { i = 0; @@ -227,7 +227,7 @@ static int in_history(int type, char_u *str, int move_to_front, int sep) } tv_list_unref(list); history[type][i].hisnum = ++hisnum[type]; - history[type][i].hisstr = str; + history[type][i].hisstr = (char *)str; history[type][i].timestamp = os_time(); history[type][i].additional_elements = NULL; return true; @@ -276,7 +276,7 @@ static int last_maptick = -1; // last seen maptick /// @param histype may be one of the HIST_ values. /// @param in_map consider maptick when inside a mapping /// @param sep separator character used (search hist) -void add_to_history(int histype, char_u *new_entry, int in_map, int sep) +void add_to_history(int histype, char *new_entry, int in_map, int sep) { histentry_T *hisptr; @@ -304,7 +304,7 @@ void add_to_history(int histype, char_u *new_entry, int in_map, int sep) } last_maptick = -1; } - if (!in_history(histype, new_entry, true, sep)) { + if (!in_history(histype, (char_u *)new_entry, true, sep)) { if (++hisidx[histype] == hislen) { hisidx[histype] = 0; } @@ -313,10 +313,10 @@ void add_to_history(int histype, char_u *new_entry, int in_map, int sep) // Store the separator after the NUL of the string. size_t len = STRLEN(new_entry); - hisptr->hisstr = vim_strnsave(new_entry, len + 2); + hisptr->hisstr = xstrnsave(new_entry, len + 2); hisptr->timestamp = os_time(); hisptr->additional_elements = NULL; - hisptr->hisstr[len + 1] = (char_u)sep; + hisptr->hisstr[len + 1] = (char)sep; hisptr->hisnum = ++hisnum[histype]; if (histype == HIST_SEARCH && in_map) { @@ -386,7 +386,7 @@ static char_u *get_history_entry(int histype, int idx) { idx = calc_hist_idx(histype, idx); if (idx >= 0) { - return history[histype][idx].hisstr; + return (char_u *)history[histype][idx].hisstr; } else { return (char_u *)""; } @@ -438,7 +438,7 @@ static int del_history_entry(int histype, char_u *str) if (hisptr->hisstr == NULL) { break; } - if (vim_regexec(®match, (char *)hisptr->hisstr, (colnr_T)0)) { + if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) { found = true; hist_free_entry(hisptr); } else { @@ -509,7 +509,7 @@ void f_histadd(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) str = tv_get_string_buf(&argvars[1], buf); if (*str != NUL) { init_history(); - add_to_history(histype, (char_u *)str, false, NUL); + add_to_history(histype, (char *)str, false, NUL); rettv->vval.v_number = true; return; } @@ -643,8 +643,8 @@ void ex_history(exarg_T *eap) msg_putchar('\n'); snprintf((char *)IObuff, IOSIZE, "%c%6d ", i == idx ? '>' : ' ', hist[i].hisnum); - if (vim_strsize((char *)hist[i].hisstr) > Columns - 10) { - trunc_string((char *)hist[i].hisstr, (char *)IObuff + STRLEN(IObuff), + if (vim_strsize(hist[i].hisstr) > Columns - 10) { + trunc_string(hist[i].hisstr, (char *)IObuff + STRLEN(IObuff), Columns - 10, IOSIZE - (int)STRLEN(IObuff)); } else { STRCAT(IObuff, hist[i].hisstr); diff --git a/src/nvim/cmdhist.h b/src/nvim/cmdhist.h index 797b79a5f0..8b7bb7ac24 100644 --- a/src/nvim/cmdhist.h +++ b/src/nvim/cmdhist.h @@ -22,7 +22,7 @@ typedef enum { /// History entry definition typedef struct hist_entry { int hisnum; ///< Entry identifier number. - char_u *hisstr; ///< Actual entry, separator char after the NUL. + char *hisstr; ///< Actual entry, separator char after the NUL. Timestamp timestamp; ///< Time when entry was added. list_T *additional_elements; ///< Additional entries from ShaDa file. } histentry_T; diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 54e5ffff37..2a3fe9701c 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -493,9 +493,9 @@ void pchar_cursor(char_u c) } /// @return pointer to cursor line. -char_u *get_cursor_line_ptr(void) +char *get_cursor_line_ptr(void) { - return ml_get_buf(curbuf, curwin->w_cursor.lnum, false); + return (char *)ml_get_buf(curbuf, curwin->w_cursor.lnum, false); } /// @return pointer to cursor position. diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index e4528f9038..53b6c66c46 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -2010,8 +2010,8 @@ void f_digraph_setlist(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// structure used for b_kmap_ga.ga_data typedef struct { - char_u *from; - char_u *to; + char *from; + char *to; } kmap_T; #define KMAP_MAXLEN 20 // maximum length of "from" or "to" @@ -2064,10 +2064,10 @@ char *keymap_init(void) /// @param eap void ex_loadkeymap(exarg_T *eap) { - char_u *s; + char *s; #define KMAP_LLEN 200 // max length of "to" and "from" together - char_u buf[KMAP_LLEN + 11]; + char buf[KMAP_LLEN + 11]; char *save_cpo = p_cpo; if (!getline_equal(eap->getline, eap->cookie, getsourceline)) { @@ -2092,15 +2092,15 @@ void ex_loadkeymap(exarg_T *eap) break; } - char_u *p = (char_u *)skipwhite(line); + char *p = skipwhite(line); if ((*p != '"') && (*p != NUL)) { kmap_T *kp = GA_APPEND_VIA_PTR(kmap_T, &curbuf->b_kmap_ga); - s = (char_u *)skiptowhite((char *)p); - kp->from = vim_strnsave(p, (size_t)(s - p)); - p = (char_u *)skipwhite((char *)s); - s = (char_u *)skiptowhite((char *)p); - kp->to = vim_strnsave(p, (size_t)(s - p)); + s = skiptowhite(p); + kp->from = xstrnsave(p, (size_t)(s - p)); + p = skipwhite(s); + s = skiptowhite(p); + kp->to = xstrnsave(p, (size_t)(s - p)); if ((STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN) || (*kp->from == NUL) @@ -2118,10 +2118,10 @@ void ex_loadkeymap(exarg_T *eap) // setup ":lmap" to map the keys for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) { - vim_snprintf((char *)buf, sizeof(buf), " %s %s", + vim_snprintf(buf, sizeof(buf), " %s %s", ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from, ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to); - (void)do_map(MAPTYPE_MAP, buf, MODE_LANGMAP, false); + (void)do_map(MAPTYPE_MAP, (char_u *)buf, MODE_LANGMAP, false); } p_cpo = save_cpo; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 9144d055f7..eac184c096 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -190,7 +190,7 @@ static void insert_enter(InsertState *s) } } - Insstart_textlen = (colnr_T)linetabsize(get_cursor_line_ptr()); + Insstart_textlen = (colnr_T)linetabsize((char_u *)get_cursor_line_ptr()); Insstart_blank_vcol = MAXCOL; if (!did_ai) { @@ -274,7 +274,7 @@ static void insert_enter(InsertState *s) update_curswant(); if (((ins_at_eol && curwin->w_cursor.lnum == o_lnum) || curwin->w_curswant > curwin->w_virtcol) - && *(s->ptr = get_cursor_line_ptr() + curwin->w_cursor.col) != NUL) { + && *(s->ptr = (char_u *)get_cursor_line_ptr() + curwin->w_cursor.col) != NUL) { if (s->ptr[1] == NUL) { curwin->w_cursor.col++; } else { @@ -1470,7 +1470,7 @@ static void init_prompt(int cmdchar_todo) char_u *text; curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - text = get_cursor_line_ptr(); + text = (char_u *)get_cursor_line_ptr(); if (STRNCMP(text, prompt, STRLEN(prompt)) != 0) { // prompt is missing, insert it or append a line with it if (*text == NUL) { @@ -1544,7 +1544,7 @@ void display_dollar(colnr_T col) curwin->w_cursor.col = col; // If on the last byte of a multi-byte move to the first byte. - char_u *p = get_cursor_line_ptr(); + char_u *p = (char_u *)get_cursor_line_ptr(); curwin->w_cursor.col -= utf_head_off((char *)p, (char *)p + col); curs_columns(curwin, false); // Recompute w_wrow and w_wcol if (curwin->w_wcol < curwin->w_grid.cols) { @@ -1590,7 +1590,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang // MODE_VREPLACE state needs to know what the line was like before changing if (State & VREPLACE_FLAG) { - orig_line = vim_strsave(get_cursor_line_ptr()); // Deal with NULL below + orig_line = vim_strsave((char_u *)get_cursor_line_ptr()); // Deal with NULL below orig_col = curwin->w_cursor.col; } @@ -1670,7 +1670,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang // Advance the cursor until we reach the right screen column. last_vcol = 0; - ptr = get_cursor_line_ptr(); + ptr = (char_u *)get_cursor_line_ptr(); chartabsize_T cts; init_chartabsize_arg(&cts, curwin, 0, 0, (char *)ptr, (char *)ptr); while (cts.cts_vcol <= (int)curwin->w_virtcol) { @@ -1761,7 +1761,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang // then put it back again the way we wanted it. if (State & VREPLACE_FLAG) { // Save new line - new_line = vim_strsave(get_cursor_line_ptr()); + new_line = vim_strsave((char_u *)get_cursor_line_ptr()); // We only put back the new line up to the cursor new_line[curwin->w_cursor.col] = NUL; @@ -2082,7 +2082,7 @@ void insertchar(int c, int flags, int second_indent) // Need to remove existing (middle) comment leader and insert end // comment leader. First, check what comment leader we can find. - char_u *line = get_cursor_line_ptr(); + char_u *line = (char_u *)get_cursor_line_ptr(); int i = get_leader_len((char *)line, &p, false, true); if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL) { // Just checking // Skip middle-comment string @@ -2287,7 +2287,7 @@ int stop_arrow(void) // right, except when nothing was inserted yet. update_Insstart_orig = false; } - Insstart_textlen = (colnr_T)linetabsize(get_cursor_line_ptr()); + Insstart_textlen = (colnr_T)linetabsize((char_u *)get_cursor_line_ptr()); if (u_save_cursor() == OK) { arrow_used = false; @@ -2484,7 +2484,7 @@ void beginline(int flags) if (flags & (BL_WHITE | BL_SOL)) { char_u *ptr; - for (ptr = get_cursor_line_ptr(); ascii_iswhite(*ptr) + for (ptr = (char_u *)get_cursor_line_ptr(); ascii_iswhite(*ptr) && !((flags & BL_FIX) && ptr[1] == NUL); ptr++) { curwin->w_cursor.col++; } @@ -2799,7 +2799,7 @@ static bool echeck_abbr(int c) return false; } - return check_abbr(c, get_cursor_line_ptr(), curwin->w_cursor.col, + return check_abbr(c, (char_u *)get_cursor_line_ptr(), curwin->w_cursor.col, curwin->w_cursor.lnum == Insstart.lnum ? Insstart.col : 0); } @@ -3148,7 +3148,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) // cursor. } else if (*look == 'e') { if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4) { - p = get_cursor_line_ptr(); + p = (char_u *)get_cursor_line_ptr(); if ((char_u *)skipwhite((char *)p) == p + curwin->w_cursor.col - 4 && STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0) { return true; @@ -3161,12 +3161,12 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) // class::method for C++). } else if (*look == ':') { if (try_match && keytyped == ':') { - p = get_cursor_line_ptr(); + p = (char_u *)get_cursor_line_ptr(); if (cin_iscase(p, false) || cin_isscopedecl(p) || cin_islabel()) { return true; } // Need to get the line again after cin_islabel(). - p = get_cursor_line_ptr(); + p = (char_u *)get_cursor_line_ptr(); if (curwin->w_cursor.col > 2 && p[curwin->w_cursor.col - 1] == ':' && p[curwin->w_cursor.col - 2] == ':') { @@ -3174,7 +3174,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) const bool i = cin_iscase(p, false) || cin_isscopedecl(p) || cin_islabel(); - p = get_cursor_line_ptr(); + p = (char_u *)get_cursor_line_ptr(); p[curwin->w_cursor.col - 1] = ':'; if (i) { return true; @@ -3226,7 +3226,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) /* Just completed a word, check if it starts with "look". * search back for the start of a word. */ - line = get_cursor_line_ptr(); + line = (char_u *)get_cursor_line_ptr(); for (s = line + curwin->w_cursor.col; s > line; s = n) { n = mb_prevptr(line, s); if (!vim_iswordp(n)) { @@ -3805,7 +3805,7 @@ static void ins_shift(int c, int lastc) change_indent(c == Ctrl_D ? INDENT_DEC : INDENT_INC, 0, true, 0, true); } - if (did_ai && *skipwhite((char *)get_cursor_line_ptr()) != NUL) { + if (did_ai && *skipwhite(get_cursor_line_ptr()) != NUL) { did_ai = false; } did_si = false; @@ -4609,7 +4609,7 @@ static bool ins_tab(void) if (State & VREPLACE_FLAG) { pos = curwin->w_cursor; cursor = &pos; - saved_line = vim_strsave(get_cursor_line_ptr()); + saved_line = vim_strsave((char_u *)get_cursor_line_ptr()); ptr = saved_line + pos.col; } else { ptr = get_cursor_pos_ptr(); diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 8927e52349..06ee4c8d81 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2995,7 +2995,7 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) *arg = bp; } else { // decimal, hex or octal number - vim_str2nr((char_u *)(*arg), NULL, &len, STR2NR_ALL, &n, NULL, 0, true); + vim_str2nr(*arg, NULL, &len, STR2NR_ALL, &n, NULL, 0, true); if (len == 0) { semsg(_(e_invexpr2), *arg); ret = FAIL; @@ -6450,7 +6450,7 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret } else { pos.lnum = curwin->w_cursor.lnum; if (charcol) { - pos.col = (colnr_T)mb_charlen(get_cursor_line_ptr()); + pos.col = (colnr_T)mb_charlen((char_u *)get_cursor_line_ptr()); } else { pos.col = (colnr_T)STRLEN(get_cursor_line_ptr()); } diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index 7b975ce775..d585509df4 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -430,7 +430,7 @@ static inline int parse_json_string(const char *const buf, const size_t buf_len, const char ubuf[] = { t[1], t[2], t[3], t[4] }; t += 4; uvarnumber_T ch; - vim_str2nr((char_u *)ubuf, NULL, NULL, + vim_str2nr(ubuf, NULL, NULL, STR2NR_HEX | STR2NR_FORCE, NULL, &ch, 4, true); if (ch == 0) { hasnul = true; @@ -600,7 +600,7 @@ parse_json_number_check: // Convert integer varnumber_T nr; int num_len; - vim_str2nr((char_u *)s, NULL, &num_len, 0, &nr, NULL, (int)(p - s), true); + vim_str2nr(s, NULL, &num_len, 0, &nr, NULL, (int)(p - s), true); if ((int)exp_num_len != num_len) { semsg(_("E685: internal error: while converting number \"%.*s\" " "to integer vim_str2nr consumed %i bytes in place of %zu"), diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 5a5293780d..60a6ec6201 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -5869,9 +5869,9 @@ static void f_readfile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) bool binary = false; bool blob = false; FILE *fd; - char_u buf[(IOSIZE/256) * 256]; // rounded to avoid odd + 1 + char buf[(IOSIZE/256) * 256]; // rounded to avoid odd + 1 int io_size = sizeof(buf); - char_u *prev = NULL; // previously read bytes, if any + char *prev = NULL; // previously read bytes, if any long prevlen = 0; // length of data in prev long prevsize = 0; // size of prev buffer long maxline = MAXLNUM; @@ -5922,13 +5922,13 @@ static void f_readfile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) // - an incomplete line gets written // - a "binary" file gets an empty line at the end if it ends in a // newline. - char_u *p; // Position in buf. - char_u *start; // Start of current line. + char *p; // Position in buf. + char *start; // Start of current line. for (p = buf, start = buf; p < buf + readlen || (readlen <= 0 && (prevlen > 0 || binary)); p++) { if (*p == '\n' || readlen <= 0) { - char_u *s = NULL; + char *s = NULL; size_t len = (size_t)(p - start); // Finished a line. Remove CRs before NL. @@ -5945,7 +5945,7 @@ static void f_readfile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } if (prevlen == 0) { assert(len < INT_MAX); - s = vim_strnsave(start, len); + s = xstrnsave(start, len); } else { // Change "prev" buffer to be the right size. This way // the bytes are only copied once, and very long lines are @@ -5960,7 +5960,7 @@ static void f_readfile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) tv_list_append_owned_tv(l, (typval_T) { .v_type = VAR_STRING, .v_lock = VAR_UNLOCKED, - .vval.v_string = (char *)s, + .vval.v_string = s, }); start = p + 1; // Step over newline. @@ -5980,18 +5980,18 @@ static void f_readfile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) *p = '\n'; // Check for utf8 "bom"; U+FEFF is encoded as EF BB BF. Do this // when finding the BF and check the previous two bytes. - } else if (*p == 0xbf && !binary) { + } else if ((uint8_t)(*p) == 0xbf && !binary) { // Find the two bytes before the 0xbf. If p is at buf, or buf + 1, // these may be in the "prev" string. - char_u back1 = p >= buf + 1 ? p[-1] + char back1 = p >= buf + 1 ? p[-1] : prevlen >= 1 ? prev[prevlen - 1] : NUL; - char_u back2 = p >= buf + 2 ? p[-2] + char back2 = p >= buf + 2 ? p[-2] : p == buf + 1 && prevlen >= 1 ? prev[prevlen - 1] : prevlen >= - 2 ? prev[prevlen - 2] : NUL; + 2 ? prev[prevlen - 2] : NUL; - if (back2 == 0xef && back1 == 0xbb) { - char_u *dest = p - 2; + if ((uint8_t)back2 == 0xef && (uint8_t)back1 == 0xbb) { + char *dest = p - 2; // Usually a BOM is at the beginning of a file, and so at // the beginning of a line; then we can just step over it. @@ -8304,7 +8304,7 @@ static void f_str2nr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) break; } varnumber_T n; - vim_str2nr(p, NULL, NULL, what, &n, NULL, 0, false); + vim_str2nr((char *)p, NULL, NULL, what, &n, NULL, 0, false); // Text after the number is silently ignored. if (isneg) { rettv->vval.v_number = -n; @@ -9416,10 +9416,10 @@ static void f_trim(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { char buf1[NUMBUFLEN]; char buf2[NUMBUFLEN]; - const char_u *head = (const char_u *)tv_get_string_buf_chk(&argvars[0], buf1); - const char_u *mask = NULL; - const char_u *prev; - const char_u *p; + const char *head = tv_get_string_buf_chk(&argvars[0], buf1); + const char *mask = NULL; + const char *prev; + const char *p; int dir = 0; rettv->v_type = VAR_STRING; @@ -9434,7 +9434,7 @@ static void f_trim(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } if (argvars[1].v_type == VAR_STRING) { - mask = (const char_u *)tv_get_string_buf_chk(&argvars[1], buf2); + mask = tv_get_string_buf_chk(&argvars[1], buf2); if (argvars[2].v_type != VAR_UNKNOWN) { bool error = false; // leading or trailing characters to trim @@ -9472,7 +9472,7 @@ static void f_trim(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } - const char_u *tail = head + STRLEN(head); + const char *tail = head + STRLEN(head); if (dir == 0 || dir == 2) { // Trim trailing characters for (; tail > head; tail = prev) { @@ -9495,7 +9495,7 @@ static void f_trim(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } } - rettv->vval.v_string = (char *)vim_strnsave(head, (size_t)(tail - head)); + rettv->vval.v_string = xstrnsave(head, (size_t)(tail - head)); } /// "type(expr)" function diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index d5b2b1f2ae..a409271596 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -3717,8 +3717,7 @@ varnumber_T tv_get_number_chk(const typval_T *const tv, bool *const ret_error) case VAR_STRING: { varnumber_T n = 0; if (tv->vval.v_string != NULL) { - vim_str2nr((char_u *)tv->vval.v_string, NULL, NULL, STR2NR_ALL, &n, NULL, 0, - false); + vim_str2nr(tv->vval.v_string, NULL, NULL, STR2NR_ALL, &n, NULL, 0, false); } return n; } diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index bcaca0ca13..6611133ea4 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -525,22 +525,22 @@ static inline bool eval_fname_sid(const char *const name) /// /// @return transformed name: either `fname_buf` or a pointer to an allocated /// memory. -static char_u *fname_trans_sid(const char_u *const name, char_u *const fname_buf, - char_u **const tofree, int *const error) +static char *fname_trans_sid(const char *const name, char *const fname_buf, char **const tofree, + int *const error) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { - char_u *fname; - const int llen = eval_fname_script((const char *)name); + char *fname; + const int llen = eval_fname_script(name); if (llen > 0) { - fname_buf[0] = K_SPECIAL; - fname_buf[1] = KS_EXTRA; + fname_buf[0] = (char)K_SPECIAL; + fname_buf[1] = (char)KS_EXTRA; fname_buf[2] = KE_SNR; int i = 3; - if (eval_fname_sid((const char *)name)) { // "" or "s:" + if (eval_fname_sid(name)) { // "" or "s:" if (current_sctx.sc_sid <= 0) { *error = ERROR_SCRIPT; } else { - snprintf((char *)fname_buf + i, (size_t)(FLEN_FIXED + 1 - i), "%" PRId64 "_", + snprintf(fname_buf + i, (size_t)(FLEN_FIXED + 1 - i), "%" PRId64 "_", (int64_t)current_sctx.sc_sid); i = (int)STRLEN(fname_buf); } @@ -555,7 +555,7 @@ static char_u *fname_trans_sid(const char_u *const name, char_u *const fname_buf STRCPY(fname + i, name + llen); } } else { - fname = (char_u *)name; + fname = (char *)name; } return fname; @@ -1437,10 +1437,10 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t int ret = FAIL; int error = ERROR_NONE; ufunc_T *fp = NULL; - char_u fname_buf[FLEN_FIXED + 1]; - char_u *tofree = NULL; - char_u *fname = NULL; - char_u *name = NULL; + char fname_buf[FLEN_FIXED + 1]; + char *tofree = NULL; + char *fname = NULL; + char *name = NULL; int argcount = argcount_in; typval_T *argvars = argvars_in; dict_T *selfdict = funcexe->selfdict; @@ -1463,8 +1463,8 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t if (fp == NULL) { // Make a copy of the name, if it comes from a funcref variable it could // be changed or deleted in the called function. - name = vim_strnsave((char_u *)funcname, (size_t)len); - fname = fname_trans_sid(name, fname_buf, &tofree, &error); + name = xstrnsave(funcname, (size_t)len); + fname = fname_trans_sid(name, (char *)fname_buf, &tofree, &error); } if (funcexe->doesrange != NULL) { @@ -1495,7 +1495,7 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t } if (error == ERROR_NONE && funcexe->evaluate) { - char_u *rfname = fname; + char *rfname = fname; // Ignore "g:" before a function name. if (fp == NULL && fname[0] == 'g' && fname[1] == ':') { @@ -1519,21 +1519,21 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t } else if (fp != NULL || !builtin_function((const char *)rfname, -1)) { // User defined function. if (fp == NULL) { - fp = find_func(rfname); + fp = find_func((char_u *)rfname); } // Trigger FuncUndefined event, may load the function. if (fp == NULL - && apply_autocmds(EVENT_FUNCUNDEFINED, (char *)rfname, (char *)rfname, true, NULL) + && apply_autocmds(EVENT_FUNCUNDEFINED, rfname, rfname, true, NULL) && !aborting()) { // executed an autocommand, search for the function again - fp = find_func(rfname); + fp = find_func((char_u *)rfname); } // Try loading a package. if (fp == NULL && script_autoload((const char *)rfname, STRLEN(rfname), true) && !aborting()) { // Loaded a package, search for the function again. - fp = find_func(rfname); + fp = find_func((char_u *)rfname); } if (fp != NULL && (fp->uf_flags & FC_DELETED)) { @@ -1570,11 +1570,11 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t } else if (funcexe->basetv != NULL) { // expr->method(): Find the method name in the table, call its // implementation with the base as one of the arguments. - error = call_internal_method(fname, argcount, argvars, rettv, + error = call_internal_method((char_u *)fname, argcount, argvars, rettv, funcexe->basetv); } else { // Find the function name in the table, call its implementation. - error = call_internal_func(fname, argcount, argvars, rettv); + error = call_internal_func((char_u *)fname, argcount, argvars, rettv); } /* * The function call (or "FuncUndefined" autocommand sequence) might @@ -1596,7 +1596,7 @@ theend: // Report an error unless the argument evaluation or function call has been // cancelled due to an aborting error, an interrupt, or an exception. if (!aborting()) { - user_func_error(error, (name != NULL) ? name : (char_u *)funcname); + user_func_error(error, (name != NULL) ? (char_u *)name : (char_u *)funcname); } // clear the copies made from the partial @@ -1890,15 +1890,15 @@ theend: /// ":function" void ex_function(exarg_T *eap) { - char_u *theline; - char_u *line_to_free = NULL; - char_u c; + char *theline; + char *line_to_free = NULL; + char c; int saved_did_emsg; bool saved_wait_return = need_wait_return; - char_u *name = NULL; - char_u *p; - char_u *arg; - char_u *line_arg = NULL; + char *name = NULL; + char *p; + char *arg; + char *line_arg = NULL; garray_T newargs; garray_T default_args; garray_T newlines; @@ -1918,8 +1918,8 @@ void ex_function(exarg_T *eap) linenr_T sourcing_lnum_off; linenr_T sourcing_lnum_top; bool is_heredoc = false; - char_u *skip_until = NULL; - char_u *heredoc_trimmed = NULL; + char *skip_until = NULL; + char *heredoc_trimmed = NULL; bool show_block = false; bool do_concat = true; @@ -1950,7 +1950,7 @@ void ex_function(exarg_T *eap) * ":function /pat": list functions matching pattern. */ if (*eap->arg == '/') { - p = (char_u *)skip_regexp(eap->arg + 1, '/', true, NULL); + p = skip_regexp(eap->arg + 1, '/', true, NULL); if (!eap->skip) { regmatch_T regmatch; @@ -1978,7 +1978,7 @@ void ex_function(exarg_T *eap) if (*p == '/') { p++; } - eap->nextcmd = check_nextcmd((char *)p); + eap->nextcmd = check_nextcmd(p); return; } @@ -1996,9 +1996,9 @@ void ex_function(exarg_T *eap) // "fudi.fd_di" set, "fudi.fd_newkey" == NULL // s:func script-local function name // g:func global function name, same as "func" - p = (char_u *)eap->arg; - name = trans_function_name((char **)&p, eap->skip, TFN_NO_AUTOLOAD, &fudi, NULL); - paren = (vim_strchr((char *)p, '(') != NULL); + p = eap->arg; + name = (char *)trans_function_name(&p, eap->skip, TFN_NO_AUTOLOAD, &fudi, NULL); + paren = (vim_strchr(p, '(') != NULL); if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) { /* * Return on an invalid expression in braces, unless the expression @@ -2028,16 +2028,16 @@ void ex_function(exarg_T *eap) // - exclude line numbers from function body // if (!paren) { - if (!ends_excmd(*skipwhite((char *)p))) { + if (!ends_excmd(*skipwhite(p))) { semsg(_(e_trailing_arg), p); goto ret_free; } - eap->nextcmd = check_nextcmd((char *)p); + eap->nextcmd = check_nextcmd(p); if (eap->nextcmd != NULL) { *p = NUL; } if (!eap->skip && !got_int) { - fp = find_func(name); + fp = find_func((char_u *)name); if (fp != NULL) { list_func_head(fp, !eap->forceit, eap->forceit); for (int j = 0; j < fp->uf_lines.ga_len && !got_int; j++) { @@ -2063,7 +2063,7 @@ void ex_function(exarg_T *eap) msg_puts(eap->forceit ? "endfunction" : " endfunction"); } } else { - emsg_funcname(N_("E123: Undefined function: %s"), name); + emsg_funcname(N_("E123: Undefined function: %s"), (char_u *)name); } } goto ret_free; @@ -2072,18 +2072,18 @@ void ex_function(exarg_T *eap) /* * ":function name(arg1, arg2)" Define function. */ - p = (char_u *)skipwhite((char *)p); + p = skipwhite(p); if (*p != '(') { if (!eap->skip) { semsg(_("E124: Missing '(': %s"), eap->arg); goto ret_free; } // attempt to continue by skipping some text - if (vim_strchr((char *)p, '(') != NULL) { - p = (char_u *)vim_strchr((char *)p, '('); + if (vim_strchr(p, '(') != NULL) { + p = vim_strchr(p, '('); } } - p = (char_u *)skipwhite((char *)p + 1); + p = skipwhite(p + 1); ga_init(&newargs, (int)sizeof(char_u *), 3); ga_init(&newlines, (int)sizeof(char_u *), 3); @@ -2094,15 +2094,15 @@ void ex_function(exarg_T *eap) if (name != NULL) { arg = name; } else { - arg = fudi.fd_newkey; + arg = (char *)fudi.fd_newkey; } if (arg != NULL && (fudi.fd_di == NULL || !tv_is_func(fudi.fd_di->di_tv))) { - int j = (*arg == K_SPECIAL) ? 3 : 0; + int j = ((uint8_t)(*arg) == K_SPECIAL) ? 3 : 0; while (arg[j] != NUL && (j == 0 ? eval_isnamec1(arg[j]) : eval_isnamec(arg[j]))) { j++; } if (arg[j] != NUL) { - emsg_funcname((char *)e_invarg2, arg); + emsg_funcname((char *)e_invarg2, (char_u *)arg); } } // Disallow using the g: dict. @@ -2111,7 +2111,7 @@ void ex_function(exarg_T *eap) } } - if (get_function_args((char **)&p, ')', &newargs, &varargs, + if (get_function_args(&p, ')', &newargs, &varargs, &default_args, eap->skip) == FAIL) { goto errret_2; } @@ -2123,7 +2123,7 @@ void ex_function(exarg_T *eap) // find extra arguments "range", "dict", "abort" and "closure" for (;;) { - p = (char_u *)skipwhite((char *)p); + p = skipwhite(p); if (STRNCMP(p, "range", 5) == 0) { flags |= FC_RANGE; p += 5; @@ -2137,9 +2137,8 @@ void ex_function(exarg_T *eap) flags |= FC_CLOSURE; p += 7; if (current_funccal == NULL) { - emsg_funcname(N_ - ("E932: Closure function should not be at top level: %s"), - name == NULL ? (char_u *)"" : name); + emsg_funcname(N_("E932: Closure function should not be at top level: %s"), + name == NULL ? (char_u *)"" : (char_u *)name); goto erret; } } else { @@ -2165,8 +2164,8 @@ void ex_function(exarg_T *eap) if (!eap->skip && !eap->forceit) { if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL) { emsg(_(e_funcdict)); - } else if (name != NULL && find_func(name) != NULL) { - emsg_funcname(e_funcexts, name); + } else if (name != NULL && find_func((char_u *)name) != NULL) { + emsg_funcname(e_funcexts, (char_u *)name); } } @@ -2195,7 +2194,7 @@ void ex_function(exarg_T *eap) if (line_arg != NULL) { // Use eap->arg, split up in parts by line breaks. theline = line_arg; - p = (char_u *)vim_strchr((char *)theline, '\n'); + p = vim_strchr(theline, '\n'); if (p == NULL) { line_arg += STRLEN(line_arg); } else { @@ -2205,9 +2204,9 @@ void ex_function(exarg_T *eap) } else { xfree(line_to_free); if (eap->getline == NULL) { - theline = getcmdline(':', 0L, indent, do_concat); + theline = (char *)getcmdline(':', 0L, indent, do_concat); } else { - theline = (char_u *)eap->getline(':', eap->cookie, indent, do_concat); + theline = eap->getline(':', eap->cookie, indent, do_concat); } line_to_free = theline; } @@ -2237,13 +2236,13 @@ void ex_function(exarg_T *eap) // * ":python < 0) { - give_warning2(_("W22: Text found after :endfunction: %s"), - (char *)p, true); + give_warning2(_("W22: Text found after :endfunction: %s"), p, true); } if (nextcmd != NULL) { // Another command follows. If the line came from "eap" we // can simply point into it, otherwise we need to change // "eap->cmdlinep". - eap->nextcmd = (char *)nextcmd; + eap->nextcmd = nextcmd; if (line_to_free != NULL) { xfree(*eap->cmdlinep); - *eap->cmdlinep = (char *)line_to_free; + *eap->cmdlinep = line_to_free; line_to_free = NULL; } } @@ -2299,13 +2297,13 @@ void ex_function(exarg_T *eap) } // Check for defining a function inside this function. - if (checkforcmd((char **)&p, "function", 2)) { + if (checkforcmd(&p, "function", 2)) { if (*p == '!') { - p = (char_u *)skipwhite((char *)p + 1); + p = skipwhite(p + 1); } p += eval_fname_script((const char *)p); - xfree(trans_function_name((char **)&p, true, 0, NULL, NULL)); - if (*skipwhite((char *)p) == '(') { + xfree(trans_function_name(&p, true, 0, NULL, NULL)); + if (*skipwhite(p) == '(') { if (nesting == MAX_FUNC_NESTING - 1) { emsg(_("E1058: function nesting too deep")); } else { @@ -2316,7 +2314,7 @@ void ex_function(exarg_T *eap) } // Check for ":append", ":change", ":insert". - p = (char_u *)skip_range((char *)p, NULL); + p = skip_range(p, NULL); if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p')) || (p[0] == 'c' && (!ASCII_ISALPHA(p[1]) @@ -2328,11 +2326,11 @@ void ex_function(exarg_T *eap) && (!ASCII_ISALPHA(p[1]) || (p[1] == 'n' && (!ASCII_ISALPHA(p[2]) || (p[2] == 's')))))) { - skip_until = vim_strsave((char_u *)"."); + skip_until = xstrdup("."); } // heredoc: Check for ":python <di_tv.v_type == VAR_FUNC) { emsg_funcname(N_("E707: Function name conflicts with variable: %s"), - name); + (char_u *)name); goto erret; } - fp = find_func(name); + fp = find_func((char_u *)name); if (fp != NULL) { // Function can be replaced with "function!" and when sourcing the // same script again, but only once. if (!eap->forceit && (fp->uf_script_ctx.sc_sid != current_sctx.sc_sid || fp->uf_script_ctx.sc_seq == current_sctx.sc_seq)) { - emsg_funcname(e_funcexts, name); + emsg_funcname(e_funcexts, (char_u *)name); goto erret; } if (fp->uf_calls > 0) { emsg_funcname(N_("E127: Cannot redefine function %s: It is in use"), - name); + (char_u *)name); goto erret; } if (fp->uf_refcount > 1) { @@ -2480,12 +2477,12 @@ void ex_function(exarg_T *eap) // Give the function a sequential number. Can only be used with a // Funcref! xfree(name); - sprintf(numbuf, "%d", ++func_nr); - name = vim_strsave((char_u *)numbuf); + sprintf(numbuf, "%d", ++func_nr); // NOLINT(runtime/printf) + name = xstrdup(numbuf); } if (fp == NULL) { - if (fudi.fd_dict == NULL && vim_strchr((char *)name, AUTOLOAD_CHAR) != NULL) { + if (fudi.fd_dict == NULL && vim_strchr(name, AUTOLOAD_CHAR) != NULL) { int slen, plen; char_u *scriptname; @@ -2493,7 +2490,7 @@ void ex_function(exarg_T *eap) int j = FAIL; if (SOURCING_NAME != NULL) { scriptname = (char_u *)autoload_name((const char *)name, STRLEN(name)); - p = (char_u *)vim_strchr((char *)scriptname, '/'); + p = vim_strchr((char *)scriptname, '/'); plen = (int)STRLEN(p); slen = (int)STRLEN(SOURCING_NAME); if (slen > plen && FNAMECMP(p, SOURCING_NAME + slen - plen) == 0) { @@ -2524,16 +2521,16 @@ void ex_function(exarg_T *eap) tv_clear(&fudi.fd_di->di_tv); } fudi.fd_di->di_tv.v_type = VAR_FUNC; - fudi.fd_di->di_tv.vval.v_string = (char *)vim_strsave(name); + fudi.fd_di->di_tv.vval.v_string = xstrdup(name); // behave like "dict" was used flags |= FC_DICT; } // insert the new function in the function list - set_ufunc_name(fp, name); + set_ufunc_name(fp, (char_u *)name); if (overwrite) { - hi = hash_find(&func_hashtab, (char *)name); + hi = hash_find(&func_hashtab, name); hi->hi_key = UF2HIKEY(fp); } else if (hash_add(&func_hashtab, UF2HIKEY(fp)) == FAIL) { xfree(fp); @@ -3213,7 +3210,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) ? (char_u *)rettv->vval.v_string : rettv->vval.v_partial->pt_name; // Translate "s:func" to the stored function name. - fname = fname_trans_sid(fname, fname_buf, &tofree, &error); + fname = (char_u *)fname_trans_sid((char *)fname, (char *)fname_buf, (char **)&tofree, &error); fp = find_func(fname); xfree(tofree); } @@ -3559,7 +3556,7 @@ bool set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID) } if (fp_in == NULL) { - fname = fname_trans_sid(name, fname_buf, &tofree, &error); + fname = (char_u *)fname_trans_sid((char *)name, (char *)fname_buf, (char **)&tofree, &error); fp = find_func(fname); } if (fp != NULL) { diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index db79187b7d..126129b24d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -330,7 +330,7 @@ static int linelen(int *has_tab) // Get the line. If it's empty bail out early (could be the empty string // for an unloaded buffer). - line = (char *)get_cursor_line_ptr(); + line = get_cursor_line_ptr(); if (*line == NUL) { return 0; } @@ -601,7 +601,7 @@ void ex_sort(exarg_T *eap) nrs[lnum - eap->line1].st_u.num.value = 0; } else { nrs[lnum - eap->line1].st_u.num.is_number = true; - vim_str2nr((char_u *)s, NULL, NULL, sort_what, + vim_str2nr(s, NULL, NULL, sort_what, &nrs[lnum - eap->line1].st_u.num.value, NULL, 0, false); } } else { @@ -2808,7 +2808,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // keep it. Also when it moves within a line. But not when it moves // to the first non-blank. if (!equalpos(curwin->w_cursor, orig_pos)) { - const char *text = (char *)get_cursor_line_ptr(); + const char *text = get_cursor_line_ptr(); if (curwin->w_cursor.lnum != orig_pos.lnum || curwin->w_cursor.col != (int)(skipwhite(text) - text)) { @@ -3354,7 +3354,7 @@ static bool sub_joining_lines(exarg_T *eap, char *pat, char *sub, char *cmd, boo save_re_pat(RE_SUBST, (char_u *)pat, p_magic); } // put pattern in history - add_to_history(HIST_SEARCH, (char_u *)pat, true, NUL); + add_to_history(HIST_SEARCH, pat, true, NUL); } return true; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 0af737ff50..8ef7903db5 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -3689,7 +3689,7 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) // Decide to expand wildcards *before* replacing '%', '#', etc. If // the file name contains a wildcard it should not cause expanding. // (it will be expanded anyway if there is a wildcard before replacing). - int has_wildcards = path_has_wildcard((char_u *)p); + int has_wildcards = path_has_wildcard(p); while (*p != NUL) { // Skip over `=expr`, wildcards in it are not expanded. if (p[0] == '`' && p[1] == '=') { @@ -3794,7 +3794,7 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) if (vim_strchr(eap->arg, '$') != NULL || vim_strchr(eap->arg, '~') != NULL) { expand_env_esc((char_u *)eap->arg, (char_u *)NameBuff, MAXPATHL, true, true, NULL); - has_wildcards = path_has_wildcard((char_u *)NameBuff); + has_wildcards = path_has_wildcard(NameBuff); p = (char *)NameBuff; } else { p = NULL; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 9d1cebd43e..2112385533 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -255,7 +255,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s exarg_T ea = { .line1 = 1, .line2 = 1, - .cmd = (char *)ccline.cmdbuff, + .cmd = ccline.cmdbuff, .addr_type = ADDR_LINES, }; @@ -336,7 +336,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s } // found a non-empty pattern or // - *skiplen = (int)((char_u *)p - ccline.cmdbuff); + *skiplen = (int)(p - ccline.cmdbuff); *patlen = (int)(end - p); // parse the address range @@ -409,7 +409,7 @@ static void may_do_incsearch_highlighting(int firstc, long count, incsearch_stat int found; // do_search() result // Use the previous pattern for ":s//". - next_char = ccline.cmdbuff[skiplen + patlen]; + next_char = (char_u)ccline.cmdbuff[skiplen + patlen]; use_last_pat = patlen == 0 && skiplen > 0 && ccline.cmdbuff[skiplen - 1] == next_char; @@ -436,9 +436,9 @@ static void may_do_incsearch_highlighting(int firstc, long count, incsearch_stat .sa_tm = &tm, }; found = do_search(NULL, firstc == ':' ? '/' : firstc, search_delim, - ccline.cmdbuff + skiplen, count, + (char_u *)ccline.cmdbuff + skiplen, count, search_flags, &sia); - ccline.cmdbuff[skiplen + patlen] = next_char; + ccline.cmdbuff[skiplen + patlen] = (char)next_char; emsg_off--; if (curwin->w_cursor.lnum < search_first_line || curwin->w_cursor.lnum > search_last_line) { @@ -487,13 +487,13 @@ static void may_do_incsearch_highlighting(int firstc, long count, incsearch_stat // Disable 'hlsearch' highlighting if the pattern matches // everything. Avoids a flash when typing "foo\|". if (!use_last_pat) { - next_char = ccline.cmdbuff[skiplen + patlen]; + next_char = (char_u)ccline.cmdbuff[skiplen + patlen]; ccline.cmdbuff[skiplen + patlen] = NUL; - if (empty_pattern((char *)ccline.cmdbuff) && !no_hlsearch) { + if (empty_pattern(ccline.cmdbuff) && !no_hlsearch) { redraw_all_later(UPD_SOME_VALID); set_no_hlsearch(true); } - ccline.cmdbuff[skiplen + patlen] = next_char; + ccline.cmdbuff[skiplen + patlen] = (char)next_char; } validate_cursor(); @@ -548,7 +548,7 @@ static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s) // command line has no uppercase characters, convert // the character to lowercase if (p_ic && p_scs - && !pat_has_uppercase(ccline.cmdbuff + skiplen)) { + && !pat_has_uppercase((char_u *)ccline.cmdbuff + skiplen)) { *c = mb_tolower(*c); } if (*c == search_delim @@ -724,7 +724,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init if (ccline.input_fn) { s->xpc.xp_context = ccline.xp_context; - s->xpc.xp_pattern = (char *)ccline.cmdbuff; + s->xpc.xp_pattern = ccline.cmdbuff; s->xpc.xp_arg = (char *)ccline.xp_arg; } @@ -854,7 +854,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init s->histype == HIST_SEARCH ? s->firstc : NUL); if (s->firstc == ':') { xfree(new_last_cmdline); - new_last_cmdline = (char *)vim_strsave(ccline.cmdbuff); + new_last_cmdline = xstrdup(ccline.cmdbuff); } } @@ -897,7 +897,7 @@ theend: xfree(ccline.last_colors.cmdbuff); kv_destroy(ccline.last_colors.colors); - char_u *p = ccline.cmdbuff; + char_u *p = (char_u *)ccline.cmdbuff; if (ui_has(kUICmdline)) { ui_call_cmdline_hide(ccline.level); @@ -1339,7 +1339,7 @@ static int may_do_command_line_next_incsearch(int firstc, long count, incsearch_ skiplen = 0; patlen = (int)STRLEN(pat); } else { - pat = ccline.cmdbuff + skiplen; + pat = (char_u *)ccline.cmdbuff + skiplen; } if (next_match) { @@ -1483,24 +1483,24 @@ static int command_line_handle_key(CommandLineState *s) } if (s->c == K_DEL) { - ccline.cmdpos += mb_off_next(ccline.cmdbuff, - ccline.cmdbuff + ccline.cmdpos); + ccline.cmdpos += mb_off_next((char_u *)ccline.cmdbuff, + (char_u *)ccline.cmdbuff + ccline.cmdpos); } if (ccline.cmdpos > 0) { char_u *p; int j = ccline.cmdpos; - p = mb_prevptr(ccline.cmdbuff, ccline.cmdbuff + j); + p = mb_prevptr((char_u *)ccline.cmdbuff, (char_u *)ccline.cmdbuff + j); if (s->c == Ctrl_W) { - while (p > ccline.cmdbuff && ascii_isspace(*p)) { - p = mb_prevptr(ccline.cmdbuff, p); + while (p > (char_u *)ccline.cmdbuff && ascii_isspace(*p)) { + p = mb_prevptr((char_u *)ccline.cmdbuff, p); } int i = mb_get_class(p); - while (p > ccline.cmdbuff && mb_get_class(p) == i) { - p = mb_prevptr(ccline.cmdbuff, p); + while (p > (char_u *)ccline.cmdbuff && mb_get_class(p) == i) { + p = mb_prevptr((char_u *)ccline.cmdbuff, p); } if (mb_get_class(p) != i) { @@ -1508,7 +1508,7 @@ static int command_line_handle_key(CommandLineState *s) } } - ccline.cmdpos = (int)(p - ccline.cmdbuff); + ccline.cmdpos = (int)(p - (char_u *)ccline.cmdbuff); ccline.cmdlen -= j - ccline.cmdpos; int i = ccline.cmdpos; @@ -1688,7 +1688,7 @@ static int command_line_handle_key(CommandLineState *s) } ccline.cmdspos += cells; - ccline.cmdpos += utfc_ptr2len((char *)ccline.cmdbuff + ccline.cmdpos); + ccline.cmdpos += utfc_ptr2len(ccline.cmdbuff + ccline.cmdpos); } while ((s->c == K_S_RIGHT || s->c == K_C_RIGHT || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) && ccline.cmdbuff[ccline.cmdpos] != ' '); @@ -1704,8 +1704,8 @@ static int command_line_handle_key(CommandLineState *s) do { ccline.cmdpos--; // Move to first byte of possibly multibyte char. - ccline.cmdpos -= utf_head_off((char *)ccline.cmdbuff, - (char *)ccline.cmdbuff + ccline.cmdpos); + ccline.cmdpos -= utf_head_off(ccline.cmdbuff, + ccline.cmdbuff + ccline.cmdpos); ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); } while (ccline.cmdpos > 0 && (s->c == K_S_LEFT || s->c == K_C_LEFT @@ -1761,7 +1761,7 @@ static int command_line_handle_key(CommandLineState *s) // Count ">" for double-wide char that doesn't fit. correct_screencol(ccline.cmdpos, cells, &ccline.cmdspos); - ccline.cmdpos += utfc_ptr2len((char *)ccline.cmdbuff + ccline.cmdpos) - 1; + ccline.cmdpos += utfc_ptr2len(ccline.cmdbuff + ccline.cmdpos) - 1; ccline.cmdspos += cells; } return command_line_not_changed(s); @@ -1855,7 +1855,7 @@ static int command_line_handle_key(CommandLineState *s) // save current command string so it can be restored later if (s->lookfor == NULL) { - s->lookfor = vim_strsave(ccline.cmdbuff); + s->lookfor = vim_strsave((char_u *)ccline.cmdbuff); s->lookfor[ccline.cmdpos] = NUL; } @@ -1874,7 +1874,7 @@ static int command_line_handle_key(CommandLineState *s) if (s->hiscnt == get_hislen()) { p = s->lookfor; // back to the old one } else { - p = get_histentry(s->histype)[s->hiscnt].hisstr; + p = (char_u *)get_histentry(s->histype)[s->hiscnt].hisstr; } if (s->histype == HIST_SEARCH @@ -1892,7 +1892,7 @@ static int command_line_handle_key(CommandLineState *s) if (p[j] == old_firstc && (j == 0 || p[j - 1] != '\\')) { if (i > 0) { - ccline.cmdbuff[len] = (char_u)s->firstc; + ccline.cmdbuff[len] = (char)s->firstc; } } else { // Escape new sep, unless it is already @@ -1906,7 +1906,7 @@ static int command_line_handle_key(CommandLineState *s) } if (i > 0) { - ccline.cmdbuff[len] = p[j]; + ccline.cmdbuff[len] = (char)p[j]; } } len++; @@ -2281,7 +2281,7 @@ static bool cmdpreview_may_show(CommandLineState *s) CmdParseInfo cmdinfo; // Copy the command line so we can modify it. int cmdpreview_type = 0; - char *cmdline = xstrdup((char *)ccline.cmdbuff); + char *cmdline = xstrdup(ccline.cmdbuff); char *errormsg = NULL; emsg_off++; // Block errors when parsing the command line, and don't update v:errmsg if (!parse_cmdline(cmdline, &ea, &cmdinfo, &errormsg)) { @@ -2659,7 +2659,7 @@ static int cmdline_charsize(int idx) if (cmdline_star > 0) { // showing '*', always 1 position return 1; } - return ptr2cells((char *)ccline.cmdbuff + idx); + return ptr2cells(ccline.cmdbuff + idx); } /// Compute the offset of the cursor on the command line for the prompt and @@ -2685,7 +2685,7 @@ int cmd_screencol(int bytepos) } for (int i = 0; i < ccline.cmdlen && i < bytepos; - i += utfc_ptr2len((char *)ccline.cmdbuff + i)) { + i += utfc_ptr2len(ccline.cmdbuff + i)) { int c = cmdline_charsize(i); // Count ">" for double-wide multi-byte char that doesn't fit. correct_screencol(i, c, &col); @@ -2704,8 +2704,8 @@ int cmd_screencol(int bytepos) /// character that doesn't fit, so that a ">" must be displayed. static void correct_screencol(int idx, int cells, int *col) { - if (utfc_ptr2len((char *)ccline.cmdbuff + idx) > 1 - && utf_ptr2cells((char *)ccline.cmdbuff + idx) > 1 + if (utfc_ptr2len(ccline.cmdbuff + idx) > 1 + && utf_ptr2cells(ccline.cmdbuff + idx) > 1 && (*col) % Columns + cells > Columns) { (*col)++; } @@ -2764,7 +2764,7 @@ void realloc_cmdbuff(int len) return; // no need to resize } - char_u *p = ccline.cmdbuff; + char_u *p = (char_u *)ccline.cmdbuff; alloc_cmdbuff(len); // will get some more // There isn't always a NUL after the command, but it may need to be // there, thus copy up to the NUL and add a NUL. @@ -2781,7 +2781,7 @@ void realloc_cmdbuff(int len) // If xp_pattern points inside the old cmdbuff it needs to be adjusted // to point into the newly allocated memory. if (i >= 0 && i <= ccline.cmdlen) { - ccline.xpc->xp_pattern = (char *)ccline.cmdbuff + i; + ccline.xpc->xp_pattern = ccline.cmdbuff + i; } } } @@ -2904,7 +2904,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) bool arg_allocated = false; typval_T arg = { .v_type = VAR_STRING, - .vval.v_string = (char *)colored_ccline->cmdbuff, + .vval.v_string = colored_ccline->cmdbuff, }; typval_T tv = { .v_type = VAR_UNKNOWN }; @@ -3107,16 +3107,16 @@ static void draw_cmdline(int start, int len) if (cmdline_star > 0) { for (int i = 0; i < len; i++) { msg_putchar('*'); - i += utfc_ptr2len((char *)ccline.cmdbuff + start + i) - 1; + i += utfc_ptr2len(ccline.cmdbuff + start + i) - 1; } } else if (p_arshape && !p_tbidi && len > 0) { bool do_arabicshape = false; int mb_l; for (int i = start; i < start + len; i += mb_l) { - char_u *p = ccline.cmdbuff + i; + char_u *p = (char_u *)ccline.cmdbuff + i; int u8cc[MAX_MCO]; int u8c = utfc_ptr2char_len(p, u8cc, start + len - i); - mb_l = utfc_ptr2len_len(p, start + len - i); + mb_l = utfc_ptr2len_len((char *)p, start + len - i); if (ARABIC_CHAR(u8c)) { do_arabicshape = true; break; @@ -3140,7 +3140,7 @@ static void draw_cmdline(int start, int len) } int newlen = 0; - if (utf_iscomposing(utf_ptr2char((char *)ccline.cmdbuff + start))) { + if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) { // Prepend a space to draw the leading composing char on. arshape_buf[0] = ' '; newlen = 1; @@ -3149,10 +3149,10 @@ static void draw_cmdline(int start, int len) int prev_c = 0; int prev_c1 = 0; for (int i = start; i < start + len; i += mb_l) { - char_u *p = ccline.cmdbuff + i; + char_u *p = (char_u *)ccline.cmdbuff + i; int u8cc[MAX_MCO]; int u8c = utfc_ptr2char_len(p, u8cc, start + len - i); - mb_l = utfc_ptr2len_len(p, start + len - i); + mb_l = utfc_ptr2len_len((char *)p, start + len - i); if (ARABIC_CHAR(u8c)) { int pc; int pc1 = 0; @@ -3208,12 +3208,12 @@ draw_cmdline_no_arabicshape: continue; } const int chunk_start = MAX(chunk.start, start); - msg_outtrans_len_attr((char *)ccline.cmdbuff + chunk_start, + msg_outtrans_len_attr(ccline.cmdbuff + chunk_start, chunk.end - chunk_start, chunk.attr); } } else { - msg_outtrans_len((char *)ccline.cmdbuff + start, len); + msg_outtrans_len(ccline.cmdbuff + start, len); } } } @@ -3225,7 +3225,7 @@ static void ui_ext_cmdline_show(CmdlineInfo *line) if (cmdline_star) { content = arena_array(&arena, 1); size_t len = 0; - for (char_u *p = ccline.cmdbuff; *p; MB_PTR_ADV(p)) { + for (char_u *p = (char_u *)ccline.cmdbuff; *p; MB_PTR_ADV(p)) { len++; } char *buf = arena_alloc(&arena, len, false); @@ -3380,7 +3380,7 @@ void unputcmdline(void) if (ccline.cmdlen == ccline.cmdpos && !ui_has(kUICmdline)) { msg_putchar(' '); } else { - draw_cmdline(ccline.cmdpos, utfc_ptr2len((char *)ccline.cmdbuff + ccline.cmdpos)); + draw_cmdline(ccline.cmdpos, utfc_ptr2len(ccline.cmdbuff + ccline.cmdpos)); } msg_no_more = false; cursorcmd(); @@ -3422,7 +3422,7 @@ void put_on_cmdline(char_u *str, int len, int redraw) // Count nr of bytes in cmdline that are overwritten by these // characters. for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; - i += utfc_ptr2len((char *)ccline.cmdbuff + i)) { + i += utfc_ptr2len(ccline.cmdbuff + i)) { m--; } if (i < ccline.cmdlen) { @@ -3440,17 +3440,17 @@ void put_on_cmdline(char_u *str, int len, int redraw) // When the inserted text starts with a composing character, // backup to the character before it. There could be two of them. i = 0; - c = utf_ptr2char((char *)ccline.cmdbuff + ccline.cmdpos); + c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); while (ccline.cmdpos > 0 && utf_iscomposing(c)) { - i = utf_head_off((char *)ccline.cmdbuff, (char *)ccline.cmdbuff + ccline.cmdpos - 1) + 1; + i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; ccline.cmdpos -= i; len += i; - c = utf_ptr2char((char *)ccline.cmdbuff + ccline.cmdpos); + c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); } if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) { // Check the previous character for Arabic combining pair. - i = utf_head_off((char *)ccline.cmdbuff, (char *)ccline.cmdbuff + ccline.cmdpos - 1) + 1; - if (arabic_combine(utf_ptr2char((char *)ccline.cmdbuff + ccline.cmdpos - i), c)) { + i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; + if (arabic_combine(utf_ptr2char(ccline.cmdbuff + ccline.cmdpos - i), c)) { ccline.cmdpos -= i; len += i; } else { @@ -3459,7 +3459,7 @@ void put_on_cmdline(char_u *str, int len, int redraw) } if (i != 0) { // Also backup the cursor position. - i = ptr2cells((char *)ccline.cmdbuff + ccline.cmdpos); + i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); ccline.cmdspos -= i; msg_col -= i; if (msg_col < 0) { @@ -3498,7 +3498,7 @@ void put_on_cmdline(char_u *str, int len, int redraw) if (ccline.cmdspos + c < m) { ccline.cmdspos += c; } - c = utfc_ptr2len((char *)ccline.cmdbuff + ccline.cmdpos) - 1; + c = utfc_ptr2len(ccline.cmdbuff + ccline.cmdpos) - 1; if (c > len - i - 1) { c = len - i - 1; } @@ -3580,14 +3580,14 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) int len; // Locate start of last word in the cmd buffer. - for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff;) { - len = utf_head_off((char *)ccline.cmdbuff, (char *)w - 1) + 1; + for (w = (char_u *)ccline.cmdbuff + ccline.cmdpos; w > (char_u *)ccline.cmdbuff;) { + len = utf_head_off(ccline.cmdbuff, (char *)w - 1) + 1; if (!vim_iswordc(utf_ptr2char((char *)w - len))) { break; } w -= len; } - len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); + len = (int)(((char_u *)ccline.cmdbuff + ccline.cmdpos) - w); if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) { p += len; } @@ -3823,7 +3823,7 @@ static int ccheck_abbr(int c) spos = 0; } - return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); + return check_abbr(c, (char_u *)ccline.cmdbuff, ccline.cmdpos, spos); } /// Escape special characters in "fname", depending on "what": @@ -3964,7 +3964,7 @@ static char *get_cmdline_str(void) if (p == NULL) { return NULL; } - return (char *)vim_strnsave(p->cmdbuff, (size_t)p->cmdlen); + return xstrnsave(p->cmdbuff, (size_t)p->cmdlen); } /// Get the current command-line completion type. @@ -4126,7 +4126,7 @@ int get_list_range(char **str, int *num1, int *num2) *str = skipwhite((*str)); if (**str == '-' || ascii_isdigit(**str)) { // parse "from" part of range - vim_str2nr((char_u *)(*str), NULL, &len, 0, &num, NULL, 0, false); + vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, false); *str += len; *num1 = (int)num; first = true; @@ -4134,7 +4134,7 @@ int get_list_range(char **str, int *num1, int *num2) *str = skipwhite((*str)); if (**str == ',') { // parse "to" part of range *str = skipwhite((*str) + 1); - vim_str2nr((char_u *)(*str), NULL, &len, 0, &num, NULL, 0, false); + vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, false); if (len > 0) { *num2 = (int)num; *str = skipwhite((*str) + len); @@ -4270,7 +4270,7 @@ static int open_cmdwin(void) i = 0; } if (get_histentry(histtype)[i].hisstr != NULL) { - ml_append(lnum++, (char *)get_histentry(histtype)[i].hisstr, (colnr_T)0, false); + ml_append(lnum++, get_histentry(histtype)[i].hisstr, (colnr_T)0, false); } } while (i != *get_hisidx(histtype)); } @@ -4278,7 +4278,7 @@ static int open_cmdwin(void) // Replace the empty last line with the current command-line and put the // cursor there. - ml_replace(curbuf->b_ml.ml_line_count, (char *)ccline.cmdbuff, true); + ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, true); curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_cursor.col = ccline.cmdpos; changed_line_abv_curs(); @@ -4348,7 +4348,7 @@ static int open_cmdwin(void) if (histtype == HIST_CMD) { // Execute the command directly. - ccline.cmdbuff = (char_u *)xstrdup(p); + ccline.cmdbuff = xstrdup(p); cmdwin_result = CAR; } else { // First need to cancel what we were doing. @@ -4362,10 +4362,10 @@ static int open_cmdwin(void) // and don't modify the cmd window. ccline.cmdbuff = NULL; } else { - ccline.cmdbuff = vim_strsave(get_cursor_line_ptr()); + ccline.cmdbuff = xstrdup(get_cursor_line_ptr()); } if (ccline.cmdbuff == NULL) { - ccline.cmdbuff = vim_strsave((char_u *)""); + ccline.cmdbuff = xstrdup(""); ccline.cmdlen = 0; ccline.cmdbufflen = 1; ccline.cmdpos = 0; diff --git a/src/nvim/ex_getln.h b/src/nvim/ex_getln.h index 5e3ad20a31..919a6c8f11 100644 --- a/src/nvim/ex_getln.h +++ b/src/nvim/ex_getln.h @@ -41,7 +41,7 @@ typedef enum { /// structure. typedef struct cmdline_info CmdlineInfo; struct cmdline_info { - char_u *cmdbuff; ///< pointer to command line buffer + char *cmdbuff; ///< pointer to command line buffer int cmdbufflen; ///< length of cmdbuff int cmdlen; ///< number of chars in command line int cmdpos; ///< current cursor position diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index e87e0853f3..f75dc51ca5 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -174,12 +174,12 @@ typedef struct ff_search_ctx_T { ff_visited_list_hdr_T *ffsc_dir_visited_list; ff_visited_list_hdr_T *ffsc_visited_lists_list; ff_visited_list_hdr_T *ffsc_dir_visited_lists_list; - char_u *ffsc_file_to_search; - char_u *ffsc_start_dir; - char_u *ffsc_fix_path; - char_u *ffsc_wc_path; + char *ffsc_file_to_search; + char *ffsc_start_dir; + char *ffsc_fix_path; + char *ffsc_wc_path; int ffsc_level; - char_u **ffsc_stopdirs_v; + char **ffsc_stopdirs_v; int ffsc_find_what; int ffsc_tagfile; } ff_search_ctx_T; @@ -245,11 +245,10 @@ static char_u e_pathtoolong[] = N_("E854: path too long for completion"); /// /// @param tagfile expanding names of tags files /// @param rel_fname file name to use for "." -void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int level, - int free_visited, int find_what, void *search_ctx_arg, int tagfile, - char_u *rel_fname) +void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, int free_visited, + int find_what, void *search_ctx_arg, int tagfile, char *rel_fname) { - char_u *wc_part; + char *wc_part; ff_stack_T *sptr; ff_search_ctx_T *search_ctx; @@ -274,12 +273,12 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le /* Reuse old visited lists. Get the visited list for the given * filename. If no list for the current filename exists, creates a new * one. */ - search_ctx->ffsc_visited_list = ff_get_visited_list(filename, + search_ctx->ffsc_visited_list = ff_get_visited_list((char_u *)filename, &search_ctx->ffsc_visited_lists_list); if (search_ctx->ffsc_visited_list == NULL) { goto error_return; } - search_ctx->ffsc_dir_visited_list = ff_get_visited_list(filename, + search_ctx->ffsc_dir_visited_list = ff_get_visited_list((char_u *)filename, &search_ctx->ffsc_dir_visited_lists_list); if (search_ctx->ffsc_dir_visited_list == NULL) { goto error_return; @@ -296,19 +295,19 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le && (vim_ispathsep(path[1]) || path[1] == NUL) && (!tagfile || vim_strchr(p_cpo, CPO_DOTTAG) == NULL) && rel_fname != NULL) { - size_t len = (size_t)((char_u *)path_tail((char *)rel_fname) - rel_fname); + size_t len = (size_t)(path_tail(rel_fname) - rel_fname); - if (!vim_isAbsName(rel_fname) && len + 1 < MAXPATHL) { + if (!vim_isAbsName((char_u *)rel_fname) && len + 1 < MAXPATHL) { // Make the start dir an absolute path name. STRLCPY(ff_expand_buffer, rel_fname, len + 1); - search_ctx->ffsc_start_dir = (char_u *)FullName_save((char *)ff_expand_buffer, false); + search_ctx->ffsc_start_dir = FullName_save((char *)ff_expand_buffer, false); } else { - search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len); + search_ctx->ffsc_start_dir = xstrnsave(rel_fname, len); } if (*++path != NUL) { path++; } - } else if (*path == NUL || !vim_isAbsName(path)) { + } else if (*path == NUL || !vim_isAbsName((char_u *)path)) { #ifdef BACKSLASH_IN_FILENAME // "c:dir" needs "c:" to be expanded, otherwise use current dir if (*path != NUL && path[1] == ':') { @@ -329,7 +328,7 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le goto error_return; } - search_ctx->ffsc_start_dir = vim_strsave(ff_expand_buffer); + search_ctx->ffsc_start_dir = (char *)vim_strsave(ff_expand_buffer); #ifdef BACKSLASH_IN_FILENAME /* A path that starts with "/dir" is relative to the drive, not to the @@ -352,7 +351,7 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le * ff_path_in_stoplist() for details. */ if (stopdirs != NULL) { - char_u *walker = stopdirs; + char *walker = stopdirs; while (*walker == ';') { walker++; @@ -362,25 +361,23 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le search_ctx->ffsc_stopdirs_v = xmalloc(sizeof(char_u *)); do { - char_u *helper; + char *helper; void *ptr; helper = walker; ptr = xrealloc(search_ctx->ffsc_stopdirs_v, (dircount + 1) * sizeof(char_u *)); search_ctx->ffsc_stopdirs_v = ptr; - walker = (char_u *)vim_strchr((char *)walker, ';'); + walker = vim_strchr(walker, ';'); if (walker) { assert(walker - helper >= 0); - search_ctx->ffsc_stopdirs_v[dircount - 1] = - vim_strnsave(helper, (size_t)(walker - helper)); + search_ctx->ffsc_stopdirs_v[dircount - 1] = xstrnsave(helper, (size_t)(walker - helper)); walker++; } else { /* this might be "", which means ascent till top * of directory tree. */ - search_ctx->ffsc_stopdirs_v[dircount - 1] = - vim_strsave(helper); + search_ctx->ffsc_stopdirs_v[dircount - 1] = xstrdup(helper); } dircount++; @@ -394,7 +391,7 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le * -fix path * -wildcard_stuff (might be NULL) */ - wc_part = (char_u *)vim_strchr((char *)path, '*'); + wc_part = vim_strchr(path, '*'); if (wc_part != NULL) { int64_t llevel; int len; @@ -402,7 +399,7 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le // save the fix part of the path assert(wc_part - path >= 0); - search_ctx->ffsc_fix_path = vim_strnsave(path, (size_t)(wc_part - path)); + search_ctx->ffsc_fix_path = xstrnsave(path, (size_t)(wc_part - path)); /* * copy wc_path and add restricts to the '**' wildcard. @@ -420,19 +417,19 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le break; } if (STRNCMP(wc_part, "**", 2) == 0) { - ff_expand_buffer[len++] = *wc_part++; - ff_expand_buffer[len++] = *wc_part++; + ff_expand_buffer[len++] = (char_u)(*wc_part++); + ff_expand_buffer[len++] = (char_u)(*wc_part++); - llevel = strtol((char *)wc_part, &errpt, 10); - if ((char_u *)errpt != wc_part && llevel > 0 && llevel < 255) { + llevel = strtol(wc_part, &errpt, 10); + if (errpt != wc_part && llevel > 0 && llevel < 255) { ff_expand_buffer[len++] = (char_u)llevel; - } else if ((char_u *)errpt != wc_part && llevel == 0) { + } else if (errpt != wc_part && llevel == 0) { // restrict is 0 -> remove already added '**' len -= 2; } else { ff_expand_buffer[len++] = FF_MAX_STAR_STAR_EXPAND; } - wc_part = (char_u *)errpt; + wc_part = errpt; if (*wc_part != NUL && !vim_ispathsep(*wc_part)) { semsg(_( "E343: Invalid path: '**[number]' must be at the end of the path or be followed by '%s'."), @@ -440,20 +437,20 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le goto error_return; } } else { - ff_expand_buffer[len++] = *wc_part++; + ff_expand_buffer[len++] = (char_u)(*wc_part++); } } ff_expand_buffer[len] = NUL; - search_ctx->ffsc_wc_path = vim_strsave(ff_expand_buffer); + search_ctx->ffsc_wc_path = (char *)vim_strsave(ff_expand_buffer); } else { - search_ctx->ffsc_fix_path = vim_strsave(path); + search_ctx->ffsc_fix_path = xstrdup(path); } if (search_ctx->ffsc_start_dir == NULL) { /* store the fix part as startdir. * This is needed if the parameter path is fully qualified. */ - search_ctx->ffsc_start_dir = vim_strsave(search_ctx->ffsc_fix_path); + search_ctx->ffsc_start_dir = xstrdup(search_ctx->ffsc_fix_path); search_ctx->ffsc_fix_path[0] = NUL; } @@ -475,9 +472,9 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path); add_pathsep((char *)ff_expand_buffer); } else { - char_u *p = (char_u *)path_tail((char *)search_ctx->ffsc_fix_path); - char_u *wc_path = NULL; - char_u *temp = NULL; + char *p = path_tail(search_ctx->ffsc_fix_path); + char *wc_path = NULL; + char *temp = NULL; int len = 0; if (p > search_ctx->ffsc_fix_path) { @@ -495,7 +492,7 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le } if (search_ctx->ffsc_wc_path != NULL) { - wc_path = vim_strsave(search_ctx->ffsc_wc_path); + wc_path = xstrdup(search_ctx->ffsc_wc_path); temp = xmalloc(STRLEN(search_ctx->ffsc_wc_path) + STRLEN(search_ctx->ffsc_fix_path + len) + 1); @@ -509,10 +506,10 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le xfree(buf); } - sptr = ff_create_stack_element(ff_expand_buffer, search_ctx->ffsc_wc_path, level, 0); + sptr = ff_create_stack_element(ff_expand_buffer, (char_u *)search_ctx->ffsc_wc_path, level, 0); ff_push(search_ctx, sptr); - search_ctx->ffsc_file_to_search = vim_strsave(filename); + search_ctx->ffsc_file_to_search = xstrdup(filename); return search_ctx; error_return: @@ -598,8 +595,7 @@ char_u *vim_findfile(void *search_ctx_arg) // store the end of the start dir -- needed for upward search if (search_ctx->ffsc_start_dir != NULL) { - path_end = &search_ctx->ffsc_start_dir[ - STRLEN(search_ctx->ffsc_start_dir)]; + path_end = (char_u *)&search_ctx->ffsc_start_dir[STRLEN(search_ctx->ffsc_start_dir)]; } // upward search loop @@ -930,19 +926,17 @@ char_u *vim_findfile(void *search_ctx_arg) ff_stack_T *sptr; // is the last starting directory in the stop list? - if (ff_path_in_stoplist(search_ctx->ffsc_start_dir, - (int)(path_end - search_ctx->ffsc_start_dir), - search_ctx->ffsc_stopdirs_v) == true) { + if (ff_path_in_stoplist((char_u *)search_ctx->ffsc_start_dir, + (int)(path_end - (char_u *)search_ctx->ffsc_start_dir), + (char_u **)search_ctx->ffsc_stopdirs_v) == true) { break; } // cut of last dir - while (path_end > search_ctx->ffsc_start_dir - && vim_ispathsep(*path_end)) { + while (path_end > (char_u *)search_ctx->ffsc_start_dir && vim_ispathsep(*path_end)) { path_end--; } - while (path_end > search_ctx->ffsc_start_dir - && !vim_ispathsep(path_end[-1])) { + while (path_end > (char_u *)search_ctx->ffsc_start_dir && !vim_ispathsep(path_end[-1])) { path_end--; } *path_end = 0; @@ -964,7 +958,7 @@ char_u *vim_findfile(void *search_ctx_arg) // create a new stack entry sptr = ff_create_stack_element(file_path, - search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); + (char_u *)search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); ff_push(search_ctx, sptr); } else { break; @@ -1528,9 +1522,9 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first // get the stopdir string r_ptr = vim_findfile_stopdir((char_u *)buf); - fdip_search_ctx = vim_findfile_init((char_u *)buf, ff_file_to_find, - r_ptr, 100, false, find_what, - fdip_search_ctx, false, rel_fname); + fdip_search_ctx = vim_findfile_init(buf, (char *)ff_file_to_find, + (char *)r_ptr, 100, false, find_what, + fdip_search_ctx, false, (char *)rel_fname); if (fdip_search_ctx != NULL) { did_findfile_init = true; } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 517424f4c1..889e569672 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -719,7 +719,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, fenc_alloced = false; } else { fenc_next = p_fencs; // try items in 'fileencodings' - fenc = (char *)next_fenc(&fenc_next, &fenc_alloced); + fenc = next_fenc(&fenc_next, &fenc_alloced); } /* @@ -813,7 +813,7 @@ retry: xfree(fenc); } if (fenc_next != NULL) { - fenc = (char *)next_fenc(&fenc_next, &fenc_alloced); + fenc = next_fenc(&fenc_next, &fenc_alloced); } else { fenc = ""; fenc_alloced = false; @@ -2068,25 +2068,25 @@ void set_forced_fenc(exarg_T *eap) /// NULL. /// When *pp is not set to NULL, the result is in allocated memory and "alloced" /// is set to true. -static char_u *next_fenc(char **pp, bool *alloced) +static char *next_fenc(char **pp, bool *alloced) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { - char_u *p; - char_u *r; + char *p; + char *r; *alloced = false; if (**pp == NUL) { *pp = NULL; - return (char_u *)""; + return ""; } - p = (char_u *)vim_strchr((*pp), ','); + p = vim_strchr((*pp), ','); if (p == NULL) { - r = (char_u *)enc_canonize(*pp); + r = enc_canonize(*pp); *pp += STRLEN(*pp); } else { - r = vim_strnsave((char_u *)(*pp), (size_t)(p - (char_u *)(*pp))); - *pp = (char *)p + 1; - p = (char_u *)enc_canonize((char *)r); + r = xstrnsave(*pp, (size_t)(p - *pp)); + *pp = p + 1; + p = enc_canonize(r); xfree(r); r = p; } diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 4d7339f3b5..97c3b1c61f 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2566,7 +2566,7 @@ static int vgetorpeek(bool advance) // white-space, so find the last non-white // character -- webb curwin->w_wcol = 0; - ptr = get_cursor_line_ptr(); + ptr = (char_u *)get_cursor_line_ptr(); chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, (char *)ptr, (char *)ptr); @@ -2596,7 +2596,7 @@ static int vgetorpeek(bool advance) if (col > 0 && curwin->w_wcol > 0) { // Correct when the cursor is on the right halve // of a double-wide character. - ptr = get_cursor_line_ptr(); + ptr = (char_u *)get_cursor_line_ptr(); col -= utf_head_off((char *)ptr, (char *)ptr + col); if (utf_ptr2cells((char *)ptr + col) > 1) { curwin->w_wcol--; diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 329adfda12..22445b9ec7 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -240,7 +240,7 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, c = (unsigned char)(*ptr); // check if this is the first byte of a multibyte mbyte_blen = len > 0 - ? utfc_ptr2len_len((char_u *)ptr, (int)((text + len) - ptr)) + ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) : utfc_ptr2len(ptr); u8c = len >= 0 ? utfc_ptr2char_len((char_u *)ptr, u8cc, (int)((text + len) - ptr)) diff --git a/src/nvim/indent.c b/src/nvim/indent.c index da4bcf6934..a41a396abc 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -343,7 +343,7 @@ int get_sts_value(void) // Count the size (in window cells) of the indent in the current line. int get_indent(void) { - return get_indent_str_vtab((char *)get_cursor_line_ptr(), + return get_indent_str_vtab(get_cursor_line_ptr(), curbuf->b_p_ts, curbuf->b_p_vts_array, false); @@ -454,7 +454,7 @@ int set_indent(int size, int flags) // characters needed for the indent. todo = size; ind_len = 0; - p = oldline = get_cursor_line_ptr(); + p = oldline = (char_u *)get_cursor_line_ptr(); // Calculate the buffer size for the new indent, and check to see if it // isn't already set. @@ -857,7 +857,7 @@ int inindent(int extra) char_u *ptr; colnr_T col; - for (col = 0, ptr = get_cursor_line_ptr(); ascii_iswhite(*ptr); col++) { + for (col = 0, ptr = (char_u *)get_cursor_line_ptr(); ascii_iswhite(*ptr); col++) { ptr++; } @@ -979,7 +979,7 @@ int get_lisp_indent(void) continue; } - for (that = get_cursor_line_ptr(); *that != NUL; that++) { + for (that = (char_u *)get_cursor_line_ptr(); *that != NUL; that++) { if (*that == ';') { while (*(that + 1) != NUL) { that++; @@ -1029,7 +1029,7 @@ int get_lisp_indent(void) curwin->w_cursor.col = pos->col; col = pos->col; - that = get_cursor_line_ptr(); + that = (char_u *)get_cursor_line_ptr(); if (vi_lisp && (get_indent() == 0)) { amount = 2; diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index ccee4dd48a..7dcc9e3c27 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -355,7 +355,7 @@ static bool cin_islabel_skip(const char_u **s) // Note: curwin->w_cursor must be where we are looking for the label. bool cin_islabel(void) // XXX { - const char_u *s = cin_skipcomment(get_cursor_line_ptr()); + const char_u *s = cin_skipcomment((char_u *)get_cursor_line_ptr()); // Exclude "default" from labels, since it should be indented // like a switch label. Same for C++ scope declarations. @@ -390,7 +390,7 @@ bool cin_islabel(void) // XXX curwin->w_cursor = *trypos; } - line = get_cursor_line_ptr(); + line = (char_u *)get_cursor_line_ptr(); if (cin_ispreproc(line)) { // ignore #defines, #if, etc. continue; } @@ -421,7 +421,7 @@ static int cin_isinit(void) const char_u *s; static char *skip[] = { "static", "public", "protected", "private" }; - s = cin_skipcomment(get_cursor_line_ptr()); + s = cin_skipcomment((char_u *)get_cursor_line_ptr()); if (cin_starts_with(s, "typedef")) { s = cin_skipcomment(s + 7); @@ -642,17 +642,17 @@ static int skip_label(linenr_T lnum, const char_u **pp) cursor_save = curwin->w_cursor; curwin->w_cursor.lnum = lnum; - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); // XXX if (cin_iscase(l, false) || cin_isscopedecl(l) || cin_islabel()) { amount = get_indent_nolabel(lnum); - l = after_label(get_cursor_line_ptr()); + l = after_label((char_u *)get_cursor_line_ptr()); if (l == NULL) { // just in case - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); } } else { amount = get_indent(); - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); } *pp = l; @@ -674,7 +674,7 @@ static int cin_first_id_amount(void) pos_T fp; colnr_T col; - line = get_cursor_line_ptr(); + line = (char_u *)get_cursor_line_ptr(); p = (char_u *)skipwhite((char *)line); len = (int)((char_u *)skiptowhite((char *)p) - p); if (len == 6 && STRNCMP(p, "static", 6) == 0) { @@ -1033,7 +1033,7 @@ static int cin_iswhileofdo(const char_u *p, linenr_T lnum) // XXX cursor_save = curwin->w_cursor; curwin->w_cursor.lnum = lnum; curwin->w_cursor.col = 0; - p = get_cursor_line_ptr(); + p = (char_u *)get_cursor_line_ptr(); while (*p && *p != 'w') { // skip any '}', until the 'w' of the "while" p++; curwin->w_cursor.col++; @@ -1110,7 +1110,7 @@ static int cin_iswhileofdo_end(int terminated) return false; } - p = line = get_cursor_line_ptr(); + p = line = (char_u *)get_cursor_line_ptr(); while (*p != NUL) { p = cin_skipcomment(p); if (*p == ')') { @@ -1133,7 +1133,7 @@ static int cin_iswhileofdo_end(int terminated) } // Searching may have made "line" invalid, get it again. - line = get_cursor_line_ptr(); + line = (char_u *)get_cursor_line_ptr(); p = line + i; } } @@ -1168,7 +1168,7 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) const char_u *s; int class_or_struct, lookfor_ctor_init, cpp_base_class; linenr_T lnum = curwin->w_cursor.lnum; - const char_u *line = get_cursor_line_ptr(); + const char_u *line = (char_u *)get_cursor_line_ptr(); if (pos->lnum <= lnum) { return cached->found; // Use the cached result @@ -1322,11 +1322,11 @@ static int get_baseclass_amount(int col) if (col == 0) { amount = get_indent(); - if (find_last_paren(get_cursor_line_ptr(), '(', ')') + if (find_last_paren((char_u *)get_cursor_line_ptr(), '(', ')') && (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) { amount = get_indent_lnum(trypos->lnum); // XXX } - if (!cin_ends_in(get_cursor_line_ptr(), (char_u *)",", NULL)) { + if (!cin_ends_in((char_u *)get_cursor_line_ptr(), (char_u *)",", NULL)) { amount += curbuf->b_ind_cpp_baseclass; } } else { @@ -2287,7 +2287,7 @@ int get_c_indent(void) /* Ignore a '(' in front of the line that has a match before * our matching '('. */ curwin->w_cursor.lnum = our_paren_pos.lnum; - line = get_cursor_line_ptr(); + line = (char_u *)get_cursor_line_ptr(); look_col = (int)(look - line); curwin->w_cursor.col = look_col + 1; if ((trypos = findmatchlimit(NULL, ')', 0, @@ -2472,7 +2472,7 @@ int get_c_indent(void) // ldfd) { // } if ((curbuf->b_ind_js || curbuf->b_ind_keep_case_label) - && cin_iscase((char_u *)skipwhite((char *)get_cursor_line_ptr()), false)) { + && cin_iscase((char_u *)skipwhite(get_cursor_line_ptr()), false)) { amount = get_indent(); } else if (curbuf->b_ind_js) { amount = get_indent_lnum(lnum); @@ -2539,7 +2539,7 @@ int get_c_indent(void) if (start_brace == BRACE_AT_END) { // '{' is at end of line amount += curbuf->b_ind_open_imag; - l = (char_u *)skipwhite((char *)get_cursor_line_ptr()); + l = (char_u *)skipwhite(get_cursor_line_ptr()); if (cin_is_cpp_namespace(l)) { amount += curbuf->b_ind_cpp_namespace; } else if (cin_is_cpp_extern_c(l)) { @@ -2614,7 +2614,7 @@ int get_c_indent(void) break; } - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); /* * If we're in a comment or raw string now, skip to @@ -2734,7 +2734,7 @@ int get_c_indent(void) break; } - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); /* If we're in a comment or raw string now, skip * to the start of it. */ @@ -2777,7 +2777,7 @@ int get_c_indent(void) continue; } - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); /* * If this is a switch() label, may line up relative to that. @@ -2853,7 +2853,7 @@ int get_c_indent(void) // -> y = y + 1; if (n) { amount = n; - l = after_label(get_cursor_line_ptr()); + l = after_label((char_u *)get_cursor_line_ptr()); if (l != NULL && cin_is_cinword((char *)l)) { if (theline[0] == '{') { amount += curbuf->b_ind_open_extra; @@ -2898,7 +2898,7 @@ int get_c_indent(void) * Ignore jump labels with nothing after them. */ if (!curbuf->b_ind_js && cin_islabel()) { - l = after_label(get_cursor_line_ptr()); + l = after_label((char_u *)get_cursor_line_ptr()); if (l == NULL || cin_nocode(l)) { continue; } @@ -2910,7 +2910,7 @@ int get_c_indent(void) * (need to get the line again, cin_islabel() may have * unlocked it) */ - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount) || cin_nocode(l)) { continue; @@ -2922,7 +2922,7 @@ int get_c_indent(void) n = 0; if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0) { n = cin_is_cpp_baseclass(&cache_cpp_baseclass); - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); } if (n) { if (lookfor == LOOKFOR_UNTERM) { @@ -3039,7 +3039,7 @@ int get_c_indent(void) * asdf) */ curwin->w_cursor = *trypos; - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); if (cin_iscase(l, false) || cin_isscopedecl(l)) { curwin->w_cursor.lnum++; curwin->w_cursor.col = 0; @@ -3154,7 +3154,7 @@ int get_c_indent(void) * x = 1; * -> here */ - l = (char_u *)skipwhite((char *)get_cursor_line_ptr()); + l = (char_u *)skipwhite(get_cursor_line_ptr()); if (cin_isdo(l)) { if (whilelevel == 0) { break; @@ -3174,7 +3174,7 @@ int get_c_indent(void) * not the one from "if () {". */ if (*l == '}') { curwin->w_cursor.col = - (colnr_T)(l - get_cursor_line_ptr()) + 1; + (colnr_T)(l - (char_u *)get_cursor_line_ptr()) + 1; } if ((trypos = find_start_brace()) == NULL @@ -3231,7 +3231,7 @@ int get_c_indent(void) // line up with this line, remember its indent // 100 + // NOLINT(whitespace/tab) // -> here; // NOLINT(whitespace/tab) - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); amount = cur_amount; n = (int)STRLEN(l); @@ -3341,7 +3341,7 @@ int get_c_indent(void) * may be lined up with the case label. */ if (lookfor == LOOKFOR_NOBREAK - && cin_isbreak((char_u *)skipwhite((char *)get_cursor_line_ptr()))) { + && cin_isbreak((char_u *)skipwhite(get_cursor_line_ptr()))) { lookfor = LOOKFOR_ANY; continue; } @@ -3350,7 +3350,7 @@ int get_c_indent(void) * Handle "do {" line. */ if (whilelevel > 0) { - l = cin_skipcomment(get_cursor_line_ptr()); + l = cin_skipcomment((char_u *)get_cursor_line_ptr()); if (cin_isdo(l)) { amount = get_indent(); // XXX whilelevel--; @@ -3408,7 +3408,7 @@ int get_c_indent(void) * here; */ term_again: - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); if (find_last_paren(l, '(', ')') && (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) { // Check if we are on a case label now. This is @@ -3416,7 +3416,7 @@ term_again: // case xx: if ( asdf && // asdf) curwin->w_cursor = *trypos; - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); if (cin_iscase(l, false) || cin_isscopedecl(l)) { curwin->w_cursor.lnum++; curwin->w_cursor.col = 0; @@ -3475,13 +3475,13 @@ term_again: * If we're at the end of a block, skip to the start of * that block. */ - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); if (find_last_paren(l, '{', '}') // XXX && (trypos = find_start_brace()) != NULL) { curwin->w_cursor = *trypos; // if not "else {" check for terminated again // but skip block for "} else {" - l = cin_skipcomment(get_cursor_line_ptr()); + l = cin_skipcomment((char_u *)get_cursor_line_ptr()); if (*l == '}' || !cin_iselse(l)) { goto term_again; } @@ -3547,7 +3547,7 @@ term_again: curwin->w_cursor.lnum--; curwin->w_cursor.col = 0; - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); // If we're in a comment or raw string now, skip to the start // of it. @@ -3563,7 +3563,7 @@ term_again: n = 0; if (curbuf->b_ind_cpp_baseclass != 0) { n = cin_is_cpp_baseclass(&cache_cpp_baseclass); - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); } if (n) { // XXX @@ -3635,7 +3635,7 @@ term_again: if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0)) { // XXX break; } - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); /* * Finding the closing '}' of a previous function. Put @@ -3709,7 +3709,7 @@ term_again: || (*l != NUL && l[STRLEN(l) - 1] == '\\')) { break; } - l = get_cursor_line_ptr(); + l = (char_u *)get_cursor_line_ptr(); } /* @@ -3786,7 +3786,7 @@ static int find_match(int lookfor, linenr_T ourscope) curwin->w_cursor.lnum--; curwin->w_cursor.col = 0; - look = cin_skipcomment(get_cursor_line_ptr()); + look = cin_skipcomment((char_u *)get_cursor_line_ptr()); if (!cin_iselse(look) && !cin_isif(look) && !cin_isdo(look) // XXX @@ -3826,7 +3826,7 @@ static int find_match(int lookfor, linenr_T ourscope) * then we need to go back to another if, so * increment elselevel */ - look = cin_skipcomment(get_cursor_line_ptr()); + look = cin_skipcomment((char_u *)get_cursor_line_ptr()); if (cin_iselse(look)) { mightbeif = cin_skipcomment(look + 4); if (!cin_isif(mightbeif)) { @@ -3845,7 +3845,7 @@ static int find_match(int lookfor, linenr_T ourscope) } // If it's an "if" decrement elselevel - look = cin_skipcomment(get_cursor_line_ptr()); + look = cin_skipcomment((char_u *)get_cursor_line_ptr()); if (cin_isif(look)) { elselevel--; /* diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index a530061280..dce72a2611 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -231,7 +231,7 @@ static pos_T compl_startpos; static int compl_length = 0; static colnr_T compl_col = 0; ///< column where the text starts ///< that is being completed -static char_u *compl_orig_text = NULL; ///< text as it was before +static char *compl_orig_text = NULL; ///< text as it was before ///< completion started static int compl_cont_mode = 0; static expand_T compl_xp; @@ -587,7 +587,7 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_ // Rule 1: Were any chars converted to lower? { - const char_u *p = compl_orig_text; + const char_u *p = (char_u *)compl_orig_text; for (int i = 0; i < min_len; i++) { const int c = mb_ptr2char_adv(&p); if (mb_islower(c)) { @@ -606,7 +606,7 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_ // Rule 2: No lower case, 2nd consecutive letter converted to // upper case. if (!has_lower) { - const char_u *p = compl_orig_text; + const char_u *p = (char_u *)compl_orig_text; for (int i = 0; i < min_len; i++) { const int c = mb_ptr2char_adv(&p); if (was_letter && mb_isupper(c) && mb_islower(wca[i])) { @@ -622,7 +622,7 @@ static char_u *ins_compl_infercase_gettext(char_u *str, int char_len, int compl_ // Copy the original case of the part we typed. { - const char_u *p = compl_orig_text; + const char_u *p = (char_u *)compl_orig_text; for (int i = 0; i < min_len; i++) { const int c = mb_ptr2char_adv(&p); if (mb_islower(c)) { @@ -699,7 +699,7 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname, // Find actual length of original text. { - const char_u *p = compl_orig_text; + const char_u *p = (char_u *)compl_orig_text; compl_char_len = 0; while (*p != NUL) { MB_PTR_ADV(p); @@ -720,7 +720,7 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname, flags |= CP_ICASE; } - int res = ins_compl_add(str, len, fname, NULL, false, NULL, dir, flags, false); + int res = ins_compl_add((char *)str, len, (char *)fname, NULL, false, NULL, dir, flags, false); xfree(tofree); return res; } @@ -748,9 +748,9 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname, /// @return NOTDONE if the given string is already in the list of completions, /// otherwise it is added to the list and OK is returned. FAIL will be /// returned in case of error. -static int ins_compl_add(char_u *const str, int len, char_u *const fname, - char_u *const *const cptext, const bool cptext_allocated, - typval_T *user_data, const Direction cdir, int flags_arg, const bool adup) +static int ins_compl_add(char *const str, int len, char *const fname, char *const *const cptext, + const bool cptext_allocated, typval_T *user_data, const Direction cdir, + int flags_arg, const bool adup) FUNC_ATTR_NONNULL_ARG(1) { compl_T *match; @@ -802,7 +802,7 @@ static int ins_compl_add(char_u *const str, int len, char_u *const fname, if (flags & CP_ORIGINAL_TEXT) { match->cp_number = 0; } - match->cp_str = vim_strnsave(str, (size_t)len); + match->cp_str = (char_u *)xstrnsave(str, (size_t)len); // match-fname is: // - compl_curr_match->cp_fname if it is a string equal to fname. @@ -814,7 +814,7 @@ static int ins_compl_add(char_u *const str, int len, char_u *const fname, && STRCMP(fname, compl_curr_match->cp_fname) == 0) { match->cp_fname = compl_curr_match->cp_fname; } else if (fname != NULL) { - match->cp_fname = vim_strsave(fname); + match->cp_fname = vim_strsave((char_u *)fname); flags |= CP_FREE_FNAME; } else { match->cp_fname = NULL; @@ -830,8 +830,8 @@ static int ins_compl_add(char_u *const str, int len, char_u *const fname, } if (*cptext[i] != NUL) { match->cp_text[i] = (cptext_allocated - ? cptext[i] - : (char_u *)xstrdup((char *)cptext[i])); + ? (char_u *)cptext[i] + : (char_u *)xstrdup(cptext[i])); } else if (cptext_allocated) { xfree(cptext[i]); } @@ -957,7 +957,7 @@ static void ins_compl_add_matches(int num_matches, char **matches, int icase) Direction dir = compl_direction; for (int i = 0; i < num_matches && add_r != FAIL; i++) { - if ((add_r = ins_compl_add((char_u *)matches[i], -1, NULL, NULL, false, NULL, dir, + if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, false, NULL, dir, CP_FAST | (icase ? CP_ICASE : 0), false)) == OK) { // If dir was BACKWARD then honor it just once. @@ -1621,8 +1621,8 @@ int ins_compl_len(void) /// to be got from the user. int ins_compl_bs(void) { - char_u *line = get_cursor_line_ptr(); - char_u *p = line + curwin->w_cursor.col; + char *line = get_cursor_line_ptr(); + char *p = line + curwin->w_cursor.col; MB_PTR_BACK(line, p); ptrdiff_t p_off = p - line; @@ -1649,7 +1649,7 @@ int ins_compl_bs(void) line = get_cursor_line_ptr(); xfree(compl_leader); - compl_leader = vim_strnsave(line + compl_col, (size_t)(p_off - (ptrdiff_t)compl_col)); + compl_leader = (char_u *)xstrnsave(line + compl_col, (size_t)(p_off - (ptrdiff_t)compl_col)); ins_compl_new_leader(); if (compl_shown_match != NULL) { @@ -1743,8 +1743,8 @@ void ins_compl_addleader(int c) } xfree(compl_leader); - compl_leader = vim_strnsave(get_cursor_line_ptr() + compl_col, - (size_t)(curwin->w_cursor.col - compl_col)); + compl_leader = (char_u *)xstrnsave(get_cursor_line_ptr() + compl_col, + (size_t)(curwin->w_cursor.col - compl_col)); ins_compl_new_leader(); } @@ -2008,7 +2008,7 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) if (compl_leader != NULL) { p = compl_leader; } else if (compl_first_match != NULL) { - p = compl_orig_text; + p = (char_u *)compl_orig_text; } if (p != NULL) { const int compl_len = get_compl_len(); @@ -2174,7 +2174,7 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) } } if (compl_orig_text != NULL) { - p = compl_orig_text; + p = (char_u *)compl_orig_text; for (len = 0; p[len] != NUL && p[len] == ptr[len]; len++) {} if (len > 0) { len -= utf_head_off((char *)p, (char *)p + len); @@ -2360,7 +2360,7 @@ static int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast) tv_clear(&user_data); return FAIL; } - int status = ins_compl_add((char_u *)word, -1, NULL, (char_u **)cptext, true, + int status = ins_compl_add((char *)word, -1, NULL, cptext, true, &user_data, dir, flags, dup); if (status != OK) { tv_clear(&user_data); @@ -2430,8 +2430,8 @@ static void set_completion(colnr_T startcol, list_T *list) compl_col = startcol; compl_length = (int)curwin->w_cursor.col - (int)startcol; // compl_pattern doesn't need to be set - compl_orig_text = vim_strnsave(get_cursor_line_ptr() + compl_col, - (size_t)compl_length); + compl_orig_text = xstrnsave(get_cursor_line_ptr() + compl_col, + (size_t)compl_length); if (p_ic) { flags |= CP_ICASE; } @@ -3513,7 +3513,7 @@ static int ins_compl_next(bool allow_get_expansion, int count, bool insert_match // Insert the text of the new completion, or the compl_leader. if (compl_no_insert && !started) { - ins_bytes((char *)compl_orig_text + get_compl_len()); + ins_bytes(compl_orig_text + get_compl_len()); compl_used_match = false; } else if (insert_match) { if (!compl_get_longest || compl_used_match) { @@ -3697,7 +3697,7 @@ static bool ins_compl_use_match(int c) /// completion) /// Sets the global variables: compl_col, compl_length and compl_pattern. /// Uses the global variables: compl_cont_status and ctrl_x_mode -static int get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col) +static int get_normal_compl_info(char *line, int startcol, colnr_T curs_col) { if ((compl_cont_status & CONT_SOL) || ctrl_x_mode_path_defines()) { if (!compl_status_adding()) { @@ -3706,25 +3706,25 @@ static int get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col) compl_length = curs_col - startcol; } if (p_ic) { - compl_pattern = (char *)str_foldcase(line + compl_col, compl_length, NULL, 0); + compl_pattern = (char *)str_foldcase((char_u *)line + compl_col, compl_length, NULL, 0); } else { - compl_pattern = (char *)vim_strnsave(line + compl_col, (size_t)compl_length); + compl_pattern = xstrnsave(line + compl_col, (size_t)compl_length); } } else if (compl_status_adding()) { char_u *prefix = (char_u *)"\\<"; // we need up to 2 extra chars for the prefix - compl_pattern = xmalloc(quote_meta(NULL, line + compl_col, - compl_length) + 2); - if (!vim_iswordp(line + compl_col) - || (compl_col > 0 && (vim_iswordp(mb_prevptr(line, line + compl_col))))) { + compl_pattern = xmalloc(quote_meta(NULL, (char_u *)line + compl_col, compl_length) + 2); + if (!vim_iswordp((char_u *)line + compl_col) + || (compl_col > 0 + && (vim_iswordp(mb_prevptr((char_u *)line, (char_u *)line + compl_col))))) { prefix = (char_u *)""; } STRCPY(compl_pattern, prefix); (void)quote_meta((char_u *)compl_pattern + STRLEN(prefix), - line + compl_col, compl_length); + (char_u *)line + compl_col, compl_length); } else if (--startcol < 0 - || !vim_iswordp(mb_prevptr(line, line + startcol + 1))) { + || !vim_iswordp(mb_prevptr((char_u *)line, (char_u *)line + startcol + 1))) { // Match any word of at least two chars compl_pattern = xstrdup("\\<\\k\\k"); compl_col += curs_col; @@ -3732,11 +3732,11 @@ static int get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col) } else { // Search the point of change class of multibyte character // or not a word single byte character backward. - startcol -= utf_head_off((char *)line, (char *)line + startcol); - int base_class = mb_get_class(line + startcol); + startcol -= utf_head_off(line, line + startcol); + int base_class = mb_get_class((char_u *)line + startcol); while (--startcol >= 0) { - int head_off = utf_head_off((char *)line, (char *)line + startcol); - if (base_class != mb_get_class(line + startcol - head_off)) { + int head_off = utf_head_off(line, line + startcol); + if (base_class != mb_get_class((char_u *)line + startcol - head_off)) { break; } startcol -= head_off; @@ -3749,13 +3749,13 @@ static int get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col) // xmalloc(7) is enough -- Acevedo compl_pattern = xmalloc(7); STRCPY(compl_pattern, "\\<"); - (void)quote_meta((char_u *)compl_pattern + 2, line + compl_col, 1); + (void)quote_meta((char_u *)compl_pattern + 2, (char_u *)line + compl_col, 1); STRCAT(compl_pattern, "\\k"); } else { - compl_pattern = xmalloc(quote_meta(NULL, line + compl_col, + compl_pattern = xmalloc(quote_meta(NULL, (char_u *)line + compl_col, compl_length) + 2); STRCPY(compl_pattern, "\\<"); - (void)quote_meta((char_u *)compl_pattern + 2, line + compl_col, compl_length); + (void)quote_meta((char_u *)compl_pattern + 2, (char_u *)line + compl_col, compl_length); } } @@ -3765,17 +3765,17 @@ static int get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col) /// Get the pattern, column and length for whole line completion or for the /// complete() function. /// Sets the global variables: compl_col, compl_length and compl_pattern. -static int get_wholeline_compl_info(char_u *line, colnr_T curs_col) +static int get_wholeline_compl_info(char *line, colnr_T curs_col) { - compl_col = (colnr_T)getwhitecols((char *)line); + compl_col = (colnr_T)getwhitecols(line); compl_length = (int)curs_col - (int)compl_col; if (compl_length < 0) { // cursor in indent: empty pattern compl_length = 0; } if (p_ic) { - compl_pattern = (char *)str_foldcase(line + compl_col, compl_length, NULL, 0); + compl_pattern = (char *)str_foldcase((char_u *)line + compl_col, compl_length, NULL, 0); } else { - compl_pattern = (char *)vim_strnsave(line + compl_col, (size_t)compl_length); + compl_pattern = xstrnsave(line + compl_col, (size_t)compl_length); } return OK; @@ -3802,16 +3802,16 @@ static int get_filename_compl_info(char_u *line, int startcol, colnr_T curs_col) compl_col += startcol; compl_length = (int)curs_col - startcol; - compl_pattern = (char *)addstar(line + compl_col, (size_t)compl_length, EXPAND_FILES); + compl_pattern = addstar((char *)line + compl_col, (size_t)compl_length, EXPAND_FILES); return OK; } /// Get the pattern, column and length for command-line completion. /// Sets the global variables: compl_col, compl_length and compl_pattern. -static int get_cmdline_compl_info(char_u *line, colnr_T curs_col) +static int get_cmdline_compl_info(char *line, colnr_T curs_col) { - compl_pattern = (char *)vim_strnsave(line, (size_t)curs_col); + compl_pattern = xstrnsave(line, (size_t)curs_col); set_cmd_context(&compl_xp, (char_u *)compl_pattern, (int)STRLEN(compl_pattern), curs_col, false); if (compl_xp.xp_context == EXPAND_UNSUCCESSFUL || compl_xp.xp_context == EXPAND_NOTHING) { @@ -3893,9 +3893,9 @@ static int get_userdefined_compl_info(colnr_T curs_col) // Setup variables for completion. Need to obtain "line" again, // it may have become invalid. - char_u *line = (char_u *)ml_get(curwin->w_cursor.lnum); + char *line = ml_get(curwin->w_cursor.lnum); compl_length = curs_col - compl_col; - compl_pattern = (char *)vim_strnsave(line + compl_col, (size_t)compl_length); + compl_pattern = xstrnsave(line + compl_col, (size_t)compl_length); return OK; } @@ -3919,8 +3919,8 @@ static int get_spell_compl_info(int startcol, colnr_T curs_col) compl_length = (int)curs_col - compl_col; } // Need to obtain "line" again, it may have become invalid. - char_u *line = (char_u *)ml_get(curwin->w_cursor.lnum); - compl_pattern = (char *)vim_strnsave(line + compl_col, (size_t)compl_length); + char *line = ml_get(curwin->w_cursor.lnum); + compl_pattern = xstrnsave(line + compl_col, (size_t)compl_length); return OK; } @@ -3939,13 +3939,13 @@ static int compl_get_info(char_u *line, int startcol, colnr_T curs_col, bool *li if (ctrl_x_mode_normal() || ((ctrl_x_mode & CTRL_X_WANT_IDENT) && !thesaurus_func_complete(ctrl_x_mode))) { - return get_normal_compl_info(line, startcol, curs_col); + return get_normal_compl_info((char *)line, startcol, curs_col); } else if (ctrl_x_mode_line_or_eval()) { - return get_wholeline_compl_info(line, curs_col); + return get_wholeline_compl_info((char *)line, curs_col); } else if (ctrl_x_mode_files()) { return get_filename_compl_info(line, startcol, curs_col); } else if (ctrl_x_mode == CTRL_X_CMDLINE) { - return get_cmdline_compl_info(line, curs_col); + return get_cmdline_compl_info((char *)line, curs_col); } else if (ctrl_x_mode_function() || ctrl_x_mode_omni() || thesaurus_func_complete(ctrl_x_mode)) { if (get_userdefined_compl_info(curs_col) == FAIL) { @@ -4036,7 +4036,7 @@ static int ins_compl_start(void) return FAIL; } - char_u *line = (char_u *)ml_get(curwin->w_cursor.lnum); + char *line = ml_get(curwin->w_cursor.lnum); colnr_T curs_col = curwin->w_cursor.col; compl_pending = 0; @@ -4044,7 +4044,7 @@ static int ins_compl_start(void) && compl_cont_mode == ctrl_x_mode) { // this same ctrl-x_mode was interrupted previously. Continue the // completion. - ins_compl_continue_search(line); + ins_compl_continue_search((char_u *)line); } else { compl_cont_status &= CONT_LOCAL; } @@ -4064,7 +4064,7 @@ static int ins_compl_start(void) // Work out completion pattern and original text -- webb bool line_invalid = false; - if (compl_get_info(line, startcol, curs_col, &line_invalid) == FAIL) { + if (compl_get_info((char_u *)line, startcol, curs_col, &line_invalid) == FAIL) { if (ctrl_x_mode_function() || ctrl_x_mode_omni() || thesaurus_func_complete(ctrl_x_mode)) { // restore did_ai, so that adding comment leader works @@ -4074,7 +4074,7 @@ static int ins_compl_start(void) } // If "line" was changed while getting completion info get it again. if (line_invalid) { - line = (char_u *)ml_get(curwin->w_cursor.lnum); + line = ml_get(curwin->w_cursor.lnum); } if (compl_status_adding()) { @@ -4108,7 +4108,7 @@ static int ins_compl_start(void) // Always add completion for the original text. xfree(compl_orig_text); - compl_orig_text = vim_strnsave(line + compl_col, (size_t)compl_length); + compl_orig_text = xstrnsave(line + compl_col, (size_t)compl_length); int flags = CP_ORIGINAL_TEXT; if (p_ic) { flags |= CP_ICASE; diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index 2b00d371f0..a3763ea9bb 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -650,7 +650,7 @@ int find_special_key(const char_u **const srcp, const size_t src_len, int *const if (*bp == '-') { last_dash = bp; if (bp + 1 <= end) { - l = utfc_ptr2len_len(bp + 1, (int)(end - bp) + 1); + l = utfc_ptr2len_len((char *)bp + 1, (int)(end - bp) + 1); // Anything accepted, like . // or are not special in strings as " is // the string delimiter. With a backslash it works: @@ -665,7 +665,7 @@ int find_special_key(const char_u **const srcp, const size_t src_len, int *const if (end - bp > 3 && bp[0] == 't' && bp[1] == '_') { bp += 3; // skip t_xx, xx may be '-' or '>' } else if (end - bp > 4 && STRNICMP(bp, "char-", 5) == 0) { - vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, true); + vim_str2nr((char *)bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, true); if (l == 0) { emsg(_(e_invarg)); return 0; @@ -695,7 +695,7 @@ int find_special_key(const char_u **const srcp, const size_t src_len, int *const if (STRNICMP(last_dash + 1, "char-", 5) == 0 && ascii_isdigit(last_dash[6])) { // or or - vim_str2nr(last_dash + 6, NULL, &l, STR2NR_ALL, NULL, &n, 0, true); + vim_str2nr((char *)last_dash + 6, NULL, &l, STR2NR_ALL, NULL, &n, 0, true); if (l == 0) { emsg(_(e_invarg)); return 0; @@ -993,7 +993,7 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co } // skip multibyte char correctly - for (i = utfc_ptr2len_len(src, (int)(end - src) + 1); i > 0; i--) { + for (i = utfc_ptr2len_len((char *)src, (int)(end - src) + 1); i > 0; i--) { // If the character is K_SPECIAL, replace it with K_SPECIAL // KS_SPECIAL KE_FILLER. if (*src == K_SPECIAL) { diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 7eab37e797..c6d08eb689 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -800,31 +800,29 @@ void clrallmarks(buf_T *const buf) char_u *fm_getname(fmark_T *fmark, int lead_len) { if (fmark->fnum == curbuf->b_fnum) { // current buffer - return mark_line(&(fmark->mark), lead_len); + return (char_u *)mark_line(&(fmark->mark), lead_len); } return (char_u *)buflist_nr2name(fmark->fnum, false, true); } -/* - * Return the line at mark "mp". Truncate to fit in window. - * The returned string has been allocated. - */ -static char_u *mark_line(pos_T *mp, int lead_len) +/// Return the line at mark "mp". Truncate to fit in window. +/// The returned string has been allocated. +static char *mark_line(pos_T *mp, int lead_len) { - char_u *s, *p; + char *s, *p; int len; if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count) { - return vim_strsave((char_u *)"-invalid-"); + return xstrdup("-invalid-"); } assert(Columns >= 0); // Allow for up to 5 bytes per character. - s = vim_strnsave((char_u *)skipwhite(ml_get(mp->lnum)), (size_t)Columns * 5); + s = xstrnsave(skipwhite(ml_get(mp->lnum)), (size_t)Columns * 5); // Truncate the line to fit it in the window len = 0; for (p = s; *p != NUL; MB_PTR_ADV(p)) { - len += ptr2cells((char *)p); + len += ptr2cells(p); if (len >= Columns - lead_len) { break; } @@ -908,7 +906,7 @@ static void show_one_mark(int c, char_u *arg, pos_T *p, char_u *name_arg, int cu && p->lnum != 0) { // don't output anything if 'q' typed at --more-- prompt if (name == NULL && current) { - name = mark_line(p, 15); + name = (char_u *)mark_line(p, 15); mustfree = true; } if (!message_filtered((char *)name)) { @@ -1094,7 +1092,7 @@ void ex_changes(exarg_T *eap) (long)curbuf->b_changelist[i].mark.lnum, curbuf->b_changelist[i].mark.col); msg_outtrans((char *)IObuff); - name = mark_line(&curbuf->b_changelist[i].mark, 17); + name = (char_u *)mark_line(&curbuf->b_changelist[i].mark, 17); msg_outtrans_attr((char *)name, HL_ATTR(HLF_D)); xfree(name); os_breakcheck(); diff --git a/src/nvim/match.c b/src/nvim/match.c index 48f0d0fc05..b6d700b148 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -1159,9 +1159,9 @@ void f_matchdelete(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// skipping commands to find the next command. void ex_match(exarg_T *eap) { - char_u *p; - char_u *g = NULL; - char_u *end; + char *p; + char *g = NULL; + char *end; int c; int id; @@ -1178,25 +1178,25 @@ void ex_match(exarg_T *eap) } if (ends_excmd(*eap->arg)) { - end = (char_u *)eap->arg; + end = eap->arg; } else if ((STRNICMP(eap->arg, "none", 4) == 0 && (ascii_iswhite(eap->arg[4]) || ends_excmd(eap->arg[4])))) { - end = (char_u *)eap->arg + 4; + end = eap->arg + 4; } else { - p = (char_u *)skiptowhite(eap->arg); + p = skiptowhite(eap->arg); if (!eap->skip) { - g = vim_strnsave((char_u *)eap->arg, (size_t)(p - (char_u *)eap->arg)); + g = xstrnsave(eap->arg, (size_t)(p - eap->arg)); } - p = (char_u *)skipwhite((char *)p); + p = skipwhite(p); if (*p == NUL) { // There must be two arguments. xfree(g); semsg(_(e_invarg2), eap->arg); return; } - end = (char_u *)skip_regexp((char *)p + 1, *p, true, NULL); + end = skip_regexp(p + 1, *p, true, NULL); if (!eap->skip) { - if (*end != NUL && !ends_excmd(*skipwhite((char *)end + 1))) { + if (*end != NUL && !ends_excmd(*skipwhite(end + 1))) { xfree(g); eap->errmsg = ex_errmsg(e_trailing_arg, (const char *)end); return; @@ -1207,13 +1207,13 @@ void ex_match(exarg_T *eap) return; } - c = *end; + c = (uint8_t)(*end); *end = NUL; match_add(curwin, (const char *)g, (const char *)p + 1, 10, id, NULL, NULL); xfree(g); - *end = (char_u)c; + *end = (char)c; } } - eap->nextcmd = find_nextcmd((char *)end); + eap->nextcmd = find_nextcmd(end); } diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 947594be4f..0a4182a892 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -587,7 +587,7 @@ size_t mb_string2cells_len(const char *str, size_t size) size_t clen = 0; for (const char_u *p = (char_u *)str; *p != NUL && p < (char_u *)str + size; - p += utfc_ptr2len_len(p, (int)size + (int)(p - (char_u *)str))) { + p += utfc_ptr2len_len((char *)p, (int)size + (int)(p - (char_u *)str))) { clen += (size_t)utf_ptr2cells((char *)p); } @@ -727,12 +727,10 @@ int mb_cptr2char_adv(const char_u **pp) return c; } -/* - * Check if the character pointed to by "p2" is a composing character when it - * comes after "p1". For Arabic sometimes "ab" is replaced with "c", which - * behaves like a composing character. - */ -bool utf_composinglike(const char_u *p1, const char_u *p2) +/// Check if the character pointed to by "p2" is a composing character when it +/// comes after "p1". For Arabic sometimes "ab" is replaced with "c", which +/// behaves like a composing character. +bool utf_composinglike(const char *p1, const char *p2) { int c2; @@ -765,7 +763,7 @@ int utfc_ptr2char(const char *p_in, int *pcc) // Only accept a composing char when the first char isn't illegal. if ((len > 1 || *p < 0x80) && p[len] >= 0x80 - && utf_composinglike(p, p + len)) { + && utf_composinglike((char *)p, (char *)p + len)) { int cc = utf_ptr2char((char *)p + len); for (;;) { pcc[i++] = cc; @@ -809,7 +807,7 @@ int utfc_ptr2char_len(const char_u *p, int *pcc, int maxlen) int len_cc = utf_ptr2len_len(p + len, maxlen - len); safe = len_cc > 1 && len_cc <= maxlen - len; if (!safe || (pcc[i] = utf_ptr2char((char *)p + len)) < 0x80 - || !(i == 0 ? utf_composinglike(p, p + len) : utf_iscomposing(pcc[i]))) { + || !(i == 0 ? utf_composinglike((char *)p, (char *)p + len) : utf_iscomposing(pcc[i]))) { break; } len += len_cc; @@ -916,7 +914,7 @@ int utfc_ptr2len(const char *const p_in) // skip all of them (otherwise the cursor would get stuck). int prevlen = 0; for (;;) { - if (p[len] < 0x80 || !utf_composinglike(p + prevlen, p + len)) { + if (p[len] < 0x80 || !utf_composinglike((char *)p + prevlen, (char *)p + len)) { return len; } @@ -926,13 +924,11 @@ int utfc_ptr2len(const char *const p_in) } } -/* - * Return the number of bytes the UTF-8 encoding of the character at "p[size]" - * takes. This includes following composing characters. - * Returns 0 for an empty string. - * Returns 1 for an illegal char or an incomplete byte sequence. - */ -int utfc_ptr2len_len(const char_u *p, int size) +/// Return the number of bytes the UTF-8 encoding of the character at "p[size]" +/// takes. This includes following composing characters. +/// Returns 0 for an empty string. +/// Returns 1 for an illegal char or an incomplete byte sequence. +int utfc_ptr2len_len(const char *p, int size) { int len; int prevlen; @@ -940,15 +936,15 @@ int utfc_ptr2len_len(const char_u *p, int size) if (size < 1 || *p == NUL) { return 0; } - if (p[0] < 0x80 && (size == 1 || p[1] < 0x80)) { // be quick for ASCII + if ((uint8_t)p[0] < 0x80 && (size == 1 || (uint8_t)p[1] < 0x80)) { // be quick for ASCII return 1; } // Skip over first UTF-8 char, stopping at a NUL byte. - len = utf_ptr2len_len(p, size); + len = utf_ptr2len_len((char_u *)p, size); // Check for illegal byte and incomplete byte sequence. - if ((len == 1 && p[0] >= 0x80) || len > size) { + if ((len == 1 && (uint8_t)p[0] >= 0x80) || len > size) { return 1; } @@ -960,7 +956,7 @@ int utfc_ptr2len_len(const char_u *p, int size) while (len < size) { int len_next_char; - if (p[len] < 0x80) { + if ((uint8_t)p[len] < 0x80) { break; } @@ -968,7 +964,7 @@ int utfc_ptr2len_len(const char_u *p, int size) * Next character length should not go beyond size to ensure that * utf_composinglike(...) does not read beyond size. */ - len_next_char = utf_ptr2len_len(p + len, size - len); + len_next_char = utf_ptr2len_len((char_u *)p + len, size - len); if (len_next_char > size - len) { break; } @@ -2420,7 +2416,7 @@ static char_u *iconv_string(const vimconv_T *const vcp, char_u *str, size_t slen if (utf_ptr2cells(from) > 1) { *to++ = '?'; } - l = utfc_ptr2len_len((const char_u *)from, (int)fromlen); + l = utfc_ptr2len_len(from, (int)fromlen); from += l; fromlen -= (size_t)l; } else if (ICONV_ERRNO != ICONV_E2BIG) { diff --git a/src/nvim/memline.c b/src/nvim/memline.c index a30a98d6e9..cd143bd52c 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -735,12 +735,12 @@ void ml_recover(bool checkext) { buf_T *buf = NULL; memfile_T *mfp = NULL; - char_u *fname; - char_u *fname_used = NULL; + char *fname; + char *fname_used = NULL; bhdr_T *hp = NULL; ZERO_BL *b0p; int b0_ff; - char_u *b0_fenc = NULL; + char *b0_fenc = NULL; PTR_BL *pp; DATA_BL *dp; infoptr_T *ip; @@ -748,7 +748,7 @@ void ml_recover(bool checkext) int len; bool directly; linenr_T lnum; - char_u *p; + char *p; int i; long error; bool cannot_open; @@ -770,9 +770,9 @@ void ml_recover(bool checkext) // If the file name ends in ".s[a-w][a-z]" we assume this is the swap file. // Otherwise a search is done to find the swap file(s). - fname = (char_u *)curbuf->b_fname; + fname = curbuf->b_fname; if (fname == NULL) { // When there is no file name - fname = (char_u *)""; + fname = ""; } len = (int)STRLEN(fname); if (checkext && len >= 4 @@ -780,12 +780,12 @@ void ml_recover(bool checkext) && vim_strchr("abcdefghijklmnopqrstuvw", TOLOWER_ASC(fname[len - 2])) != NULL && ASCII_ISALPHA(fname[len - 1])) { directly = true; - fname_used = vim_strsave(fname); // make a copy for mf_open() + fname_used = xstrdup(fname); // make a copy for mf_open() } else { directly = false; // count the number of matching swap files - len = recover_names(fname, false, 0, NULL); + len = recover_names((char_u *)fname, false, 0, NULL); if (len == 0) { // no swap files found semsg(_("E305: No swap file found for %s"), fname); goto theend; @@ -794,7 +794,7 @@ void ml_recover(bool checkext) i = 1; } else { // several swap files found, choose // list the names of the swap files - (void)recover_names(fname, true, 0, NULL); + (void)recover_names((char_u *)fname, true, 0, NULL); msg_putchar('\n'); msg_puts(_("Enter number of swap file to use (0 to quit): ")); i = get_number(false, NULL); @@ -803,7 +803,7 @@ void ml_recover(bool checkext) } } // get the swap file name that will be used - (void)recover_names(fname, false, i, &fname_used); + (void)recover_names((char_u *)fname, false, i, (char_u **)&fname_used); } if (fname_used == NULL) { goto theend; // user chose invalid number. @@ -833,9 +833,9 @@ void ml_recover(bool checkext) /* * open the memfile from the old swap file */ - p = vim_strsave(fname_used); // save "fname_used" for the message: - // mf_open() will consume "fname_used"! - mfp = mf_open((char *)fname_used, O_RDONLY); + p = xstrdup(fname_used); // save "fname_used" for the message: + // mf_open() will consume "fname_used"! + mfp = mf_open(fname_used, O_RDONLY); fname_used = p; if (mfp == NULL || mfp->mf_fd < 0) { semsg(_("E306: Cannot open %s"), fname_used); @@ -962,8 +962,8 @@ void ml_recover(bool checkext) if (b0p->b0_flags & B0_HAS_FENC) { int fnsize = B0_FNAME_SIZE_NOCRYPT; - for (p = b0p->b0_fname + fnsize; p > b0p->b0_fname && p[-1] != NUL; p--) {} - b0_fenc = vim_strnsave(p, (size_t)(b0p->b0_fname + fnsize - p)); + for (p = (char *)b0p->b0_fname + fnsize; (char_u *)p > b0p->b0_fname && p[-1] != NUL; p--) {} + b0_fenc = xstrnsave(p, (size_t)(b0p->b0_fname + fnsize - (char_u *)p)); } mf_put(mfp, hp, false, false); // release block 0 @@ -991,7 +991,7 @@ void ml_recover(bool checkext) set_fileformat(b0_ff - 1, OPT_LOCAL); } if (b0_fenc != NULL) { - set_option_value_give_err("fenc", 0L, (char *)b0_fenc, OPT_LOCAL); + set_option_value_give_err("fenc", 0L, b0_fenc, OPT_LOCAL); xfree(b0_fenc); } unchanged(curbuf, true, true); @@ -1133,12 +1133,12 @@ void ml_recover(bool checkext) txt_start = (dp->db_index[i] & DB_INDEX_MASK); if (txt_start <= (int)HEADER_SIZE || txt_start >= (int)dp->db_txt_end) { - p = (char_u *)"???"; + p = "???"; error++; } else { - p = (char_u *)dp + txt_start; + p = (char *)dp + txt_start; } - ml_append(lnum++, (char *)p, (colnr_T)0, true); + ml_append(lnum++, p, (colnr_T)0, true); } if (has_error) { ml_append(lnum++, _("???END"), (colnr_T)0, true); @@ -1177,7 +1177,7 @@ void ml_recover(bool checkext) } else { for (idx = 1; idx <= lnum; idx++) { // Need to copy one line, fetching the other one may flush it. - p = vim_strsave((char_u *)ml_get(idx)); + p = xstrdup(ml_get(idx)); i = STRCMP(p, ml_get(idx + lnum)); xfree(p); if (i != 0) { diff --git a/src/nvim/message.c b/src/nvim/message.c index e7959c73c6..87cfe06edc 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1581,7 +1581,7 @@ int msg_outtrans_len_attr(const char *msgstr, int len, int attr) */ while (--len >= 0 && !got_int) { // Don't include composing chars after the end. - mb_l = utfc_ptr2len_len((char_u *)str, len + 1); + mb_l = utfc_ptr2len_len(str, len + 1); if (mb_l > 1) { c = utf_ptr2char(str); if (vim_isprintc(c)) { @@ -2219,7 +2219,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse) if (has_last_char) { if (maxlen >= 0) { // Avoid including composing chars after the end. - l = utfc_ptr2len_len((char_u *)s, (int)((str + maxlen) - s)); + l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); } else { l = utfc_ptr2len(s); } @@ -2316,7 +2316,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse) cw = utf_ptr2cells(s); if (maxlen >= 0) { // avoid including composing chars after the end - l = utfc_ptr2len_len((char_u *)s, (int)((str + maxlen) - s)); + l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); } else { l = utfc_ptr2len(s); } diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 17b79e27c1..66038d0c3c 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3134,7 +3134,7 @@ bool find_decl(char_u *ptr, size_t len, bool locally, bool thisblock, int flags_ } else { par_pos = curwin->w_cursor; while (curwin->w_cursor.lnum > 1 - && *skipwhite((char *)get_cursor_line_ptr()) != NUL) { + && *skipwhite(get_cursor_line_ptr()) != NUL) { curwin->w_cursor.lnum--; } } @@ -3171,13 +3171,13 @@ bool find_decl(char_u *ptr, size_t len, bool locally, bool thisblock, int flags_ } break; } - if (get_leader_len((char *)get_cursor_line_ptr(), NULL, false, true) > 0) { + if (get_leader_len(get_cursor_line_ptr(), NULL, false, true) > 0) { // Ignore this line, continue at start of next line. curwin->w_cursor.lnum++; curwin->w_cursor.col = 0; continue; } - bool valid = is_ident(get_cursor_line_ptr(), curwin->w_cursor.col); + bool valid = is_ident((char_u *)get_cursor_line_ptr(), curwin->w_cursor.col); // If the current position is not a valid identifier and a previous match is // present, favor that one instead. @@ -3232,7 +3232,7 @@ bool find_decl(char_u *ptr, size_t len, bool locally, bool thisblock, int flags_ /// @return true if able to move cursor, false otherwise. static bool nv_screengo(oparg_T *oap, int dir, long dist) { - int linelen = linetabsize(get_cursor_line_ptr()); + int linelen = linetabsize((char_u *)get_cursor_line_ptr()); bool retval = true; bool atend = false; int n; @@ -3303,7 +3303,7 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist) } curwin->w_cursor.lnum--; - linelen = linetabsize(get_cursor_line_ptr()); + linelen = linetabsize((char_u *)get_cursor_line_ptr()); if (linelen > width1) { int w = (((linelen - width1 - 1) / width2) + 1) * width2; assert(curwin->w_curswant <= INT_MAX - w); @@ -3339,7 +3339,7 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist) if (curwin->w_curswant >= width1) { curwin->w_curswant -= width2; } - linelen = linetabsize(get_cursor_line_ptr()); + linelen = linetabsize((char_u *)get_cursor_line_ptr()); } } } @@ -4294,7 +4294,7 @@ static void nv_ident(cmdarg_T *cap) // Call setpcmark() first, so "*``" puts the cursor back where // it was. setpcmark(); - curwin->w_cursor.col = (colnr_T)(ptr - (char *)get_cursor_line_ptr()); + curwin->w_cursor.col = (colnr_T)(ptr - get_cursor_line_ptr()); if (!g_cmd && vim_iswordp((char_u *)ptr)) { STRCPY(buf, "\\<"); @@ -4382,13 +4382,13 @@ static void nv_ident(cmdarg_T *cap) // Execute the command. if (cmdchar == '*' || cmdchar == '#') { if (!g_cmd - && vim_iswordp(mb_prevptr(get_cursor_line_ptr(), (char_u *)ptr))) { + && vim_iswordp(mb_prevptr((char_u *)get_cursor_line_ptr(), (char_u *)ptr))) { STRCAT(buf, "\\>"); } // put pattern in search history init_history(); - add_to_history(HIST_SEARCH, (char_u *)buf, true, NUL); + add_to_history(HIST_SEARCH, buf, true, NUL); (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0, NULL); } else { @@ -4425,7 +4425,7 @@ bool get_visual_text(cmdarg_T *cap, char **pp, size_t *lenp) return false; } if (VIsual_mode == 'V') { - *pp = (char *)get_cursor_line_ptr(); + *pp = get_cursor_line_ptr(); *lenp = STRLEN(*pp); } else { if (lt(curwin->w_cursor, VIsual)) { @@ -6068,7 +6068,7 @@ static void nv_g_underscore_cmd(cmdarg_T *cap) return; } - char_u *ptr = get_cursor_line_ptr(); + char_u *ptr = (char_u *)get_cursor_line_ptr(); // In Visual mode we may end up after the line. if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) { @@ -6279,7 +6279,7 @@ static void nv_g_cmd(cmdarg_T *cap) case 'M': oap->motion_type = kMTCharWise; oap->inclusive = false; - i = linetabsize(get_cursor_line_ptr()); + i = linetabsize((char_u *)get_cursor_line_ptr()); if (cap->count0 > 0 && cap->count0 <= 100) { coladvance((colnr_T)(i * cap->count0 / 100)); } else { diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d2321be4a4..01fd4bb9a7 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -225,7 +225,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) } for (i = oap->line_count - 1; i >= 0; i--) { - first_char = *get_cursor_line_ptr(); + first_char = (uint8_t)(*get_cursor_line_ptr()); if (first_char == NUL) { // empty line curwin->w_cursor.col = 0; } else if (oap->motion_type == kMTBlockWise) { @@ -356,7 +356,7 @@ static void shift_block(oparg_T *oap, int amount) return; // multiplication overflow } - char_u *const oldp = get_cursor_line_ptr(); + char_u *const oldp = (char_u *)get_cursor_line_ptr(); int startcol, oldlen, newlen; @@ -668,7 +668,7 @@ void op_reindent(oparg_T *oap, Indenter how) // indented, unless there is only one line. if (i != oap->line_count - 1 || oap->line_count == 1 || how != get_lisp_indent) { - l = (char_u *)skipwhite((char *)get_cursor_line_ptr()); + l = (char_u *)skipwhite(get_cursor_line_ptr()); if (*l == NUL) { // empty or blank line amount = 0; } else { @@ -1735,7 +1735,7 @@ int op_delete(oparg_T *oap) if (virtual_op) { // fix up things for virtualedit-delete: // break the tabs which are going to get in our way - char_u *curline = get_cursor_line_ptr(); + char_u *curline = (char_u *)get_cursor_line_ptr(); int len = (int)STRLEN(curline); if (oap->end.coladd != 0 @@ -1926,7 +1926,7 @@ static int op_replace(oparg_T *oap, int c) num_chars = numc; numc *= utf_char2len(c); - oldp = get_cursor_line_ptr(); + oldp = (char_u *)get_cursor_line_ptr(); oldlen = (int)STRLEN(oldp); size_t newp_size = (size_t)bd.textcol + (size_t)bd.startspaces; @@ -2240,7 +2240,7 @@ bool swapchar(int op_type, pos_T *pos) void op_insert(oparg_T *oap, long count1) { long ins_len, pre_textlen = 0; - char_u *firstline, *ins_text; + char *firstline, *ins_text; colnr_T ind_pre_col = 0, ind_post_col; int ind_pre_vcol = 0, ind_post_vcol = 0; struct block_def bd; @@ -2281,7 +2281,7 @@ void op_insert(oparg_T *oap, long count1) // Get indent information ind_pre_col = (colnr_T)getwhitecols_curline(); ind_pre_vcol = get_indent(); - firstline = (char_u *)ml_get(oap->start.lnum) + bd.textcol; + firstline = ml_get(oap->start.lnum) + bd.textcol; if (oap->op_type == OP_APPEND) { firstline += bd.textlen; @@ -2413,7 +2413,7 @@ void op_insert(oparg_T *oap, long count1) * Subsequent calls to ml_get() flush the firstline data - take a * copy of the required string. */ - firstline = (char_u *)ml_get(oap->start.lnum); + firstline = ml_get(oap->start.lnum); const size_t len = STRLEN(firstline); colnr_T add = bd.textcol; colnr_T offset = 0; // offset when cursor was moved in insert mode @@ -2438,10 +2438,10 @@ void op_insert(oparg_T *oap, long count1) } ins_len = (long)STRLEN(firstline) - pre_textlen - offset; if (pre_textlen >= 0 && ins_len > 0) { - ins_text = vim_strnsave(firstline, (size_t)ins_len); + ins_text = xstrnsave(firstline, (size_t)ins_len); // block handled here if (u_save(oap->start.lnum, (linenr_T)(oap->end.lnum + 1)) == OK) { - block_insert(oap, ins_text, (oap->op_type == OP_INSERT), &bd); + block_insert(oap, (char_u *)ins_text, (oap->op_type == OP_INSERT), &bd); } curwin->w_cursor.col = oap->start.col; @@ -2934,9 +2934,9 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg) /// @param dir BACKWARD for 'P', FORWARD for 'p' void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) { - char_u *ptr; - char_u *newp; - char_u *oldp; + char *ptr; + char *newp; + char *oldp; int yanklen; size_t totlen = 0; // init for gcc linenr_T lnum = 0; @@ -3082,13 +3082,13 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) * Loop twice: count the number of lines and save them. */ for (;;) { y_size = 0; - ptr = (char_u *)insert_string; + ptr = insert_string; while (ptr != NULL) { if (y_array != NULL) { - y_array[y_size] = (char *)ptr; + y_array[y_size] = ptr; } y_size++; - ptr = (char_u *)vim_strchr((char *)ptr, '\n'); + ptr = vim_strchr(ptr, '\n'); if (ptr != NULL) { if (y_array != NULL) { *ptr = NUL; @@ -3136,12 +3136,12 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (u_save_cursor() == FAIL) { goto end; } - char_u *p = get_cursor_pos_ptr(); + char *p = (char *)get_cursor_pos_ptr(); if (dir == FORWARD && *p != NUL) { MB_PTR_ADV(p); } - ptr = vim_strsave(p); - ml_append(curwin->w_cursor.lnum, (char *)ptr, (colnr_T)0, false); + ptr = xstrdup(p); + ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, false); xfree(ptr); oldp = get_cursor_line_ptr(); @@ -3149,8 +3149,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (dir == FORWARD && *p != NUL) { MB_PTR_ADV(p); } - ptr = vim_strnsave(oldp, (size_t)(p - oldp)); - ml_replace(curwin->w_cursor.lnum, (char *)ptr, false); + ptr = xstrnsave(oldp, (size_t)(p - oldp)); + ml_replace(curwin->w_cursor.lnum, ptr, false); nr_lines++; dir = FORWARD; } @@ -3298,8 +3298,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) oldp = get_cursor_line_ptr(); oldlen = STRLEN(oldp); chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, - (char *)oldp, (char *)oldp); + init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, oldp, oldp); while (cts.cts_vcol < col && *cts.cts_ptr != NUL) { // Count a tab for what it's worth (if list mode not on) @@ -3307,7 +3306,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) cts.cts_vcol += incr; } vcol = cts.cts_vcol; - ptr = (char_u *)cts.cts_ptr; + ptr = cts.cts_ptr; bd.textcol = (colnr_T)(ptr - oldp); clear_chartabsize_arg(&cts); @@ -3320,7 +3319,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) bd.startspaces = incr - bd.endspaces; bd.textcol--; delcount = 1; - bd.textcol -= utf_head_off((char *)oldp, (char *)oldp + bd.textcol); + bd.textcol -= utf_head_off(oldp, oldp + bd.textcol); if (oldp[bd.textcol] != TAB) { /* Only a Tab can be split into spaces. Other * characters will have to be moved to after the @@ -3356,9 +3355,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) break; } - totlen = (size_t)(count * (yanklen + spaces) - + bd.startspaces + bd.endspaces); - newp = (char_u *)xmalloc(totlen + oldlen + 1); + totlen = (size_t)(count * (yanklen + spaces) + bd.startspaces + bd.endspaces); + newp = xmalloc(totlen + oldlen + 1); // copy part up to cursor to new line ptr = newp; @@ -3391,7 +3389,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) int columns = (int)oldlen - bd.textcol - delcount + 1; assert(columns >= 0); memmove(ptr, oldp + bd.textcol + delcount, (size_t)columns); - ml_replace(curwin->w_cursor.lnum, (char *)newp, false); + ml_replace(curwin->w_cursor.lnum, newp, false); extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum - 1, bd.textcol, delcount, (int)totlen + lines_appended, kExtmarkUndo); @@ -3482,7 +3480,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } else { totlen = (size_t)(count * yanklen); do { - oldp = (char_u *)ml_get(lnum); + oldp = ml_get(lnum); oldlen = STRLEN(oldp); if (lnum > start_lnum) { pos_T pos = { @@ -3498,7 +3496,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) lnum++; continue; } - newp = (char_u *)xmalloc(totlen + oldlen + 1); + newp = xmalloc(totlen + oldlen + 1); memmove(newp, oldp, (size_t)col); ptr = newp + col; for (i = 0; i < (size_t)count; i++) { @@ -3506,10 +3504,10 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) ptr += yanklen; } STRMOVE(ptr, oldp + col); - ml_replace(lnum, (char *)newp, false); + ml_replace(lnum, newp, false); // compute the byte offset for the last character - first_byte_off = utf_head_off((char *)newp, (char *)ptr - 1); + first_byte_off = utf_head_off(newp, ptr - 1); // Place cursor on last putted char. if (lnum == curwin->w_cursor.lnum) { @@ -3553,23 +3551,23 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // First insert y_array[size - 1] in front of second line. // Then append y_array[0] to first line. lnum = new_cursor.lnum; - ptr = (char_u *)ml_get(lnum) + col; + ptr = ml_get(lnum) + col; totlen = STRLEN(y_array[y_size - 1]); - newp = (char_u *)xmalloc((size_t)(STRLEN(ptr) + totlen + 1)); + newp = xmalloc((size_t)(STRLEN(ptr) + totlen + 1)); STRCPY(newp, y_array[y_size - 1]); STRCAT(newp, ptr); // insert second line - ml_append(lnum, (char *)newp, (colnr_T)0, false); + ml_append(lnum, newp, (colnr_T)0, false); new_lnum++; xfree(newp); - oldp = (char_u *)ml_get(lnum); - newp = (char_u *)xmalloc((size_t)col + (size_t)yanklen + 1); + oldp = ml_get(lnum); + newp = xmalloc((size_t)col + (size_t)yanklen + 1); // copy first part of line memmove(newp, oldp, (size_t)col); // append to first line memmove(newp + col, y_array[0], (size_t)yanklen + 1); - ml_replace(lnum, (char *)newp, false); + ml_replace(lnum, newp, false); curwin->w_cursor.lnum = lnum; i = 1; @@ -3587,7 +3585,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (flags & PUT_FIXINDENT) { old_pos = curwin->w_cursor; curwin->w_cursor.lnum = lnum; - ptr = (char_u *)ml_get(lnum); + ptr = ml_get(lnum); if (cnt == count && i == y_size - 1) { lendiff = (int)STRLEN(ptr); } @@ -4656,7 +4654,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) : length); } - vim_str2nr(ptr + col, &pre, &length, + vim_str2nr((char *)ptr + col, &pre, &length, 0 + (do_bin ? STR2NR_BIN : 0) + (do_oct ? STR2NR_OCT : 0) + (do_hex ? STR2NR_HEX : 0), @@ -5504,7 +5502,7 @@ void cursor_pos_info(dict_T *dict) (int64_t)byte_count_cursor, (int64_t)byte_count); } } else { - p = get_cursor_line_ptr(); + p = (char_u *)get_cursor_line_ptr(); validate_virtcol(); col_print((char *)buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); diff --git a/src/nvim/option.c b/src/nvim/option.c index 269a21b512..f8b7d96305 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -664,8 +664,8 @@ void set_init_3(void) : !(options[idx_sp].flags & P_WAS_SET); size_t len = 0; - char_u *p = (char_u *)invocation_path_tail(p_sh, &len); - p = vim_strnsave(p, len); + char *p = (char *)invocation_path_tail(p_sh, &len); + p = xstrnsave(p, len); { // @@ -1131,7 +1131,7 @@ int do_set(char *arg, int opt_flags) } } else if (*arg == '-' || ascii_isdigit(*arg)) { // Allow negative, octal and hex numbers. - vim_str2nr((char_u *)arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, true); + vim_str2nr(arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, true); if (i == 0 || (arg[i] != NUL && !ascii_iswhite(arg[i]))) { errmsg = e_number_required_after_equal; goto skip; diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 35390e3dc1..f3b3c1dfbf 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -64,7 +64,7 @@ static void save_patterns(int num_pat, char **pat, int *num_file, char ***file) static bool have_wildcard(int num, char **file) { for (int i = 0; i < num; i++) { - if (path_has_wildcard((char_u *)file[i])) { + if (path_has_wildcard(file[i])) { return true; } } @@ -1106,7 +1106,7 @@ static void out_data_append_to_screen(char *output, size_t *count, bool eof) // incomplete UTF-8 sequence that could be composing with the last // complete sequence. // This will be corrected when we switch to vterm based implementation - int i = *p ? utfc_ptr2len_len((char_u *)p, (int)(end - p)) : 1; + int i = *p ? utfc_ptr2len_len(p, (int)(end - p)) : 1; if (!eof && i == 1 && utf8len_tab_zero[*(uint8_t *)p] > (end - p)) { *count = (size_t)(p - output); goto end; diff --git a/src/nvim/path.c b/src/nvim/path.c index 8973d4dfdb..e6de5388e0 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -509,7 +509,7 @@ char *save_abs_path(const char *name) /// @param p The path to expand. /// @returns Unix: True if it contains one of "?[{`'$". /// @returns Windows: True if it contains one of "*?$[". -bool path_has_wildcard(const char_u *p) +bool path_has_wildcard(const char *p) FUNC_ATTR_NONNULL_ALL { for (; *p; MB_PTR_ADV(p)) { @@ -1252,7 +1252,7 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i p = (char_u *)pat[i]; if (vim_backtick(p)) { - add_pat = expand_backtick(&ga, p, flags); + add_pat = expand_backtick(&ga, (char *)p, flags); if (add_pat == -1) { recursive = false; FreeWild(ga.ga_len, ga.ga_data); @@ -1367,14 +1367,14 @@ static int vim_backtick(char_u *p) /// Returns number of file names found, -1 if an error is encountered. /// /// @param flags EW_* flags -static int expand_backtick(garray_T *gap, char_u *pat, int flags) +static int expand_backtick(garray_T *gap, char *pat, int flags) { char *p; char *buffer; int cnt = 0; // Create the command: lop off the backticks. - char *cmd = (char *)vim_strnsave(pat + 1, STRLEN(pat) - 2); + char *cmd = xstrnsave(pat + 1, STRLEN(pat) - 2); if (*cmd == '=') { // `={expr}`: Expand expression buffer = eval_to_string(cmd + 1, &p, true); @@ -1683,17 +1683,17 @@ static char *eval_includeexpr(const char *const ptr, const size_t len) /// Otherwise like file_name_at_cursor(). /// /// @param rel_fname file we are searching relative to -char_u *find_file_name_in_path(char_u *ptr, size_t len, int options, long count, char_u *rel_fname) +char *find_file_name_in_path(char *ptr, size_t len, int options, long count, char *rel_fname) { - char_u *file_name; - char_u *tofree = NULL; + char *file_name; + char *tofree = NULL; if (len == 0) { return NULL; } if ((options & FNAME_INCL) && *curbuf->b_p_inex != NUL) { - tofree = (char_u *)eval_includeexpr((char *)ptr, len); + tofree = eval_includeexpr(ptr, len); if (tofree != NULL) { ptr = tofree; len = STRLEN(ptr); @@ -1701,8 +1701,8 @@ char_u *find_file_name_in_path(char_u *ptr, size_t len, int options, long count, } if (options & FNAME_EXP) { - file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, true, - rel_fname); + file_name = (char *)find_file_in_path((char_u *)ptr, len, options & ~FNAME_MESS, true, + (char_u *)rel_fname); /* * If the file could not be found in a normal way, try applying @@ -1710,16 +1710,16 @@ char_u *find_file_name_in_path(char_u *ptr, size_t len, int options, long count, */ if (file_name == NULL && !(options & FNAME_INCL) && *curbuf->b_p_inex != NUL) { - tofree = (char_u *)eval_includeexpr((char *)ptr, len); + tofree = eval_includeexpr(ptr, len); if (tofree != NULL) { ptr = tofree; len = STRLEN(ptr); - file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, - true, rel_fname); + file_name = (char *)find_file_in_path((char_u *)ptr, len, options & ~FNAME_MESS, + true, (char_u *)rel_fname); } } if (file_name == NULL && (options & FNAME_MESS)) { - char_u c = ptr[len]; + char c = ptr[len]; ptr[len] = NUL; semsg(_("E447: Can't find file \"%s\" in path"), ptr); ptr[len] = c; @@ -1729,10 +1729,11 @@ char_u *find_file_name_in_path(char_u *ptr, size_t len, int options, long count, * appears several times in the path. */ while (file_name != NULL && --count > 0) { xfree(file_name); - file_name = find_file_in_path(ptr, len, options, false, rel_fname); + file_name = + (char *)find_file_in_path((char_u *)ptr, len, options, false, (char_u *)rel_fname); } } else { - file_name = vim_strnsave(ptr, len); + file_name = xstrnsave(ptr, len); } xfree(tofree); diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 563d85964c..ffa68c56b2 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1623,14 +1623,14 @@ static int fill_submatch_list(int argc FUNC_ATTR_UNUSED, typval_T *argv, int arg // There are always 10 list items in staticList10_T. listitem_T *li = tv_list_first(listarg->vval.v_list); for (int i = 0; i < 10; i++) { - char_u *s = rsm.sm_match->startp[i]; + char *s = (char *)rsm.sm_match->startp[i]; if (s == NULL || rsm.sm_match->endp[i] == NULL) { s = NULL; } else { - s = vim_strnsave(s, (size_t)(rsm.sm_match->endp[i] - s)); + s = xstrnsave(s, (size_t)(rsm.sm_match->endp[i] - (char_u *)s)); } TV_LIST_ITEM_TV(li)->v_type = VAR_STRING; - TV_LIST_ITEM_TV(li)->vval.v_string = (char *)s; + TV_LIST_ITEM_TV(li)->vval.v_string = s; li = TV_LIST_ITEM_NEXT(argv->vval.v_list, li); } return argskip + 1; diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c index 9b9b33b09f..ccf2b60da2 100644 --- a/src/nvim/regexp_bt.c +++ b/src/nvim/regexp_bt.c @@ -2469,7 +2469,7 @@ do_multibyte: // Need to get composing character too. for (;;) { l = utf_ptr2len((char *)regparse); - if (!utf_composinglike((char_u *)regparse, (char_u *)regparse + l)) { + if (!utf_composinglike(regparse, regparse + l)) { break; } regmbc(utf_ptr2char((char *)regparse)); @@ -3192,7 +3192,7 @@ static int regrepeat(char_u *p, long maxcount) case SKWORD: case SKWORD + ADD_NL: while (count < maxcount) { - if (vim_iswordp_buf(scan, rex.reg_buf) + if (vim_iswordp_buf((char *)scan, rex.reg_buf) && (testval || !ascii_isdigit(*scan))) { MB_PTR_ADV(scan); } else if (*scan == NUL) { @@ -3829,7 +3829,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) break; case KWORD: - if (!vim_iswordp_buf(rex.input, rex.reg_buf)) { + if (!vim_iswordp_buf((char *)rex.input, rex.reg_buf)) { status = RA_NOMATCH; } else { ADVANCE_REGINPUT(); @@ -3838,7 +3838,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) case SKWORD: if (ascii_isdigit(*rex.input) - || !vim_iswordp_buf(rex.input, rex.reg_buf)) { + || !vim_iswordp_buf((char *)rex.input, rex.reg_buf)) { status = RA_NOMATCH; } else { ADVANCE_REGINPUT(); @@ -4046,7 +4046,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) // 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((char *)rex.input, (char *)rex.input + len) && !rex.reg_icombine && OP(next) != RE_COMPOSING) { // raaron: This code makes a composing character get @@ -4975,13 +4975,13 @@ static long regtry(bt_regprog_T *prog, colnr_T col, proftime_T *tm, int *timed_o && reg_endzpos[i].lnum == reg_startzpos[i].lnum && reg_endzpos[i].col >= reg_startzpos[i].col) { re_extmatch_out->matches[i] = - vim_strnsave(reg_getline(reg_startzpos[i].lnum) + reg_startzpos[i].col, - (size_t)(reg_endzpos[i].col - reg_startzpos[i].col)); + (char_u *)xstrnsave((char *)reg_getline(reg_startzpos[i].lnum) + reg_startzpos[i].col, + (size_t)(reg_endzpos[i].col - reg_startzpos[i].col)); } } else { if (reg_startzp[i] != NULL && reg_endzp[i] != NULL) { re_extmatch_out->matches[i] = - vim_strnsave(reg_startzp[i], (size_t)(reg_endzp[i] - reg_startzp[i])); + (char_u *)xstrnsave((char *)reg_startzp[i], (size_t)(reg_endzp[i] - reg_startzp[i])); } } } diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index d01404b5c2..4c1058ba36 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -6643,13 +6643,13 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm break; case NFA_KWORD: // \k - result = vim_iswordp_buf(rex.input, rex.reg_buf); + result = vim_iswordp_buf((char *)rex.input, rex.reg_buf); ADD_STATE_IF_MATCH(t->state); break; case NFA_SKWORD: // \K result = !ascii_isdigit(curc) - && vim_iswordp_buf(rex.input, rex.reg_buf); + && vim_iswordp_buf((char *)rex.input, rex.reg_buf); ADD_STATE_IF_MATCH(t->state); break; @@ -7362,15 +7362,15 @@ static long nfa_regtry(nfa_regprog_T *prog, colnr_T col, proftime_T *tm, int *ti && mpos->start_lnum == mpos->end_lnum && mpos->end_col >= mpos->start_col) { re_extmatch_out->matches[i] = - vim_strnsave(reg_getline(mpos->start_lnum) + mpos->start_col, - (size_t)(mpos->end_col - mpos->start_col)); + (char_u *)xstrnsave((char *)reg_getline(mpos->start_lnum) + mpos->start_col, + (size_t)(mpos->end_col - mpos->start_col)); } } else { struct linepos *lpos = &subs.synt.list.line[i]; if (lpos->start != NULL && lpos->end != NULL) { re_extmatch_out->matches[i] = - vim_strnsave(lpos->start, (size_t)(lpos->end - lpos->start)); + (char_u *)xstrnsave((char *)lpos->start, (size_t)(lpos->end - lpos->start)); } } } diff --git a/src/nvim/search.c b/src/nvim/search.c index db1c766eb2..5c1fe3a657 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -161,7 +161,7 @@ int search_regcomp(char_u *pat, int pat_save, int pat_use, int options, regmmatc magic = spats[i].magic; no_smartcase = spats[i].no_scs; } else if (options & SEARCH_HIS) { // put new pattern in history - add_to_history(HIST_SEARCH, pat, true, NUL); + add_to_history(HIST_SEARCH, (char *)pat, true, NUL); } if (mr_pattern_alloced) { @@ -1574,7 +1574,7 @@ int searchc(cmdarg_T *cap, int t_cmd) cap->oap->inclusive = true; } - p = get_cursor_line_ptr(); + p = (char_u *)get_cursor_line_ptr(); col = curwin->w_cursor.col; len = (int)STRLEN(p); @@ -1649,22 +1649,21 @@ static bool check_prevcol(char_u *linep, int col, int ch, int *prevcol) return col >= 0 && linep[col] == ch; } -/* - * Raw string start is found at linep[startpos.col - 1]. - * Return true if the matching end can be found between startpos and endpos. - */ -static bool find_rawstring_end(char_u *linep, pos_T *startpos, pos_T *endpos) +/// Raw string start is found at linep[startpos.col - 1]. +/// +/// @return true if the matching end can be found between startpos and endpos. +static bool find_rawstring_end(char *linep, pos_T *startpos, pos_T *endpos) { - char_u *p; + char *p; linenr_T lnum; for (p = linep + startpos->col + 1; *p && *p != '('; p++) {} size_t delim_len = (size_t)((p - linep) - startpos->col - 1); - char_u *delim_copy = vim_strnsave(linep + startpos->col + 1, delim_len); + char *delim_copy = xstrnsave(linep + startpos->col + 1, delim_len); bool found = false; for (lnum = startpos->lnum; lnum <= endpos->lnum; lnum++) { - char_u *line = (char_u *)ml_get(lnum); + char *line = ml_get(lnum); for (p = line + (lnum == startpos->lnum ? startpos->col + 1 : 0); *p; p++) { if (lnum == endpos->lnum && (colnr_T)(p - line) >= endpos->col) { @@ -2082,7 +2081,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) // delimiter we can check if it ends before where we // started searching, or before the previously found // raw string start. - if (!find_rawstring_end(linep, &pos, + if (!find_rawstring_end((char *)linep, &pos, count > 0 ? &match_pos : &curwin->w_cursor)) { count++; match_pos = pos; @@ -3598,11 +3597,11 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo if (inc_opt != NULL && strstr(inc_opt, "\\zs") != NULL) { // Use text from '\zs' to '\ze' (or end) of 'include'. - new_fname = find_file_name_in_path(incl_regmatch.startp[0], - (size_t)(incl_regmatch.endp[0] - - incl_regmatch.startp[0]), - FNAME_EXP|FNAME_INCL|FNAME_REL, - 1L, p_fname); + new_fname = (char_u *)find_file_name_in_path((char *)incl_regmatch.startp[0], + (size_t)(incl_regmatch.endp[0] + - incl_regmatch.startp[0]), + FNAME_EXP|FNAME_INCL|FNAME_REL, + 1L, (char *)p_fname); } else { // Use text after match with 'include'. new_fname = file_name_in_line(incl_regmatch.endp[0], 0, diff --git a/src/nvim/shada.c b/src/nvim/shada.c index e20bce5b34..1a70b77053 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -882,10 +882,10 @@ static const void *shada_hist_iter(const void *const iter, const uint8_t history .data = { .history_item = { .histtype = history_type, - .string = (char *)hist_he.hisstr, + .string = hist_he.hisstr, .sep = (char)(history_type == HIST_SEARCH - ? (char)hist_he.hisstr[STRLEN(hist_he.hisstr) + 1] - : 0), + ? hist_he.hisstr[STRLEN(hist_he.hisstr) + 1] + : 0), .additional_elements = hist_he.additional_elements, } } @@ -1008,7 +1008,7 @@ static inline void hms_to_he_array(const HistoryMergerState *const hms_p, HMLL_FORALL(&hms_p->hmll, cur_entry, { hist->timestamp = cur_entry->data.timestamp; hist->hisnum = (int)(hist - hist_array) + 1; - hist->hisstr = (char_u *)cur_entry->data.data.history_item.string; + hist->hisstr = cur_entry->data.data.history_item.string; hist->additional_elements = cur_entry->data.data.history_item.additional_elements; hist++; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 7c05c9fe53..c0d05eb799 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2104,8 +2104,8 @@ static void clear_midword(win_T *wp) XFREE_CLEAR(wp->w_s->b_spell_ismw_mb); } -// Use the "sl_midword" field of language "lp" for buffer "buf". -// They add up to any currently used midword characters. +/// Use the "sl_midword" field of language "lp" for buffer "buf". +/// They add up to any currently used midword characters. static void use_midword(slang_T *lp, win_T *wp) FUNC_ATTR_NONNULL_ALL { @@ -2113,20 +2113,20 @@ static void use_midword(slang_T *lp, win_T *wp) return; } - for (char_u *p = lp->sl_midword; *p != NUL;) { - const int c = utf_ptr2char((char *)p); - const int l = utfc_ptr2len((char *)p); + for (char *p = (char *)lp->sl_midword; *p != NUL;) { + const int c = utf_ptr2char(p); + const int l = utfc_ptr2len(p); if (c < 256 && l <= 2) { wp->w_s->b_spell_ismw[c] = true; } else if (wp->w_s->b_spell_ismw_mb == NULL) { // First multi-byte char in "b_spell_ismw_mb". - wp->w_s->b_spell_ismw_mb = (char *)vim_strnsave(p, (size_t)l); + wp->w_s->b_spell_ismw_mb = xstrnsave(p, (size_t)l); } else { // Append multi-byte chars to "b_spell_ismw_mb". const int n = (int)STRLEN(wp->w_s->b_spell_ismw_mb); - char_u *bp = vim_strnsave((char_u *)wp->w_s->b_spell_ismw_mb, (size_t)n + (size_t)l); + char *bp = xstrnsave(wp->w_s->b_spell_ismw_mb, (size_t)n + (size_t)l); xfree(wp->w_s->b_spell_ismw_mb); - wp->w_s->b_spell_ismw_mb = (char *)bp; + wp->w_s->b_spell_ismw_mb = bp; STRLCPY(bp + n, p, l + 1); } p += l; @@ -2470,7 +2470,7 @@ bool check_need_cap(linenr_T lnum, colnr_T col) return false; } - char_u *line = get_cursor_line_ptr(); + char_u *line = (char_u *)get_cursor_line_ptr(); char_u *line_copy = NULL; colnr_T endcol = 0; if (getwhitecols((char *)line) >= (int)col) { @@ -2548,7 +2548,7 @@ void ex_spellrepall(exarg_T *eap) // Only replace when the right word isn't there yet. This happens // when changing "etc" to "etc.". - char_u *line = get_cursor_line_ptr(); + char_u *line = (char_u *)get_cursor_line_ptr(); if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, repl_to, STRLEN(repl_to)) != 0) { char_u *p = xmalloc(STRLEN(line) + (size_t)addlen + 1); @@ -3497,7 +3497,7 @@ int spell_word_start(int startcol) return startcol; } - char_u *line = get_cursor_line_ptr(); + char_u *line = (char_u *)get_cursor_line_ptr(); char_u *p; // Find a word character before "startcol". diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 23c8c621b5..c07e460ea8 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -65,7 +65,7 @@ typedef struct suginfo_S { /// One word suggestion. Used in "si_ga". typedef struct { - char_u *st_word; ///< suggested word, allocated string + char *st_word; ///< suggested word, allocated string int st_wordlen; ///< STRLEN(st_word) int st_orglen; ///< length of replaced text int st_score; ///< lower is better @@ -453,7 +453,7 @@ void spell_suggest(int count) // No bad word or it starts after the cursor: use the word under the // cursor. curwin->w_cursor = prev_cursor; - line = get_cursor_line_ptr(); + line = (char_u *)get_cursor_line_ptr(); p = line + curwin->w_cursor.col; // Backup to before start of word. while (p > line && spell_iswordp_nmw(p, curwin)) { @@ -477,7 +477,7 @@ void spell_suggest(int count) need_cap = check_need_cap(curwin->w_cursor.lnum, curwin->w_cursor.col); // Make a copy of current line since autocommands may free the line. - line = vim_strsave(get_cursor_line_ptr()); + line = vim_strsave((char_u *)get_cursor_line_ptr()); spell_suggest_timeout = 5000; // Get the list of suggestions. Limit to 'lines' - 2 or the number in @@ -593,15 +593,15 @@ void spell_suggest(int count) if (sug.su_badlen > stp->st_orglen) { // Replacing less than "su_badlen", append the remainder to // repl_to. - repl_from = vim_strnsave(sug.su_badptr, (size_t)sug.su_badlen); + repl_from = (char_u *)xstrnsave((char *)sug.su_badptr, (size_t)sug.su_badlen); vim_snprintf((char *)IObuff, IOSIZE, "%s%.*s", stp->st_word, sug.su_badlen - stp->st_orglen, sug.su_badptr + stp->st_orglen); repl_to = vim_strsave(IObuff); } else { // Replacing su_badlen or more, use the whole word. - repl_from = vim_strnsave(sug.su_badptr, (size_t)stp->st_orglen); - repl_to = vim_strsave(stp->st_word); + repl_from = (char_u *)xstrnsave((char *)sug.su_badptr, (size_t)stp->st_orglen); + repl_to = vim_strsave((char_u *)stp->st_word); } // Replace the word. @@ -748,7 +748,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma c = utf_ptr2char((char *)su->su_badptr); if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) { make_case_word(su->su_badword, buf, WF_ONECAP); - add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE, + add_suggestion(su, &su->su_ga, (char *)buf, su->su_badlen, SCORE_ICASE, 0, true, su->su_sallang, false); } @@ -814,7 +814,7 @@ static void spell_suggest_expr(suginfo_T *su, char_u *expr) // Get the word and the score from the items. score = get_spellword(TV_LIST_ITEM_TV(li)->vval.v_list, &p); if (score >= 0 && score <= su->su_maxscore) { - add_suggestion(su, &su->su_ga, (const char_u *)p, su->su_badlen, + add_suggestion(su, &su->su_ga, p, su->su_badlen, score, 0, true, su->su_sallang, false); } } @@ -864,7 +864,7 @@ static void spell_suggest_file(suginfo_T *su, char_u *fname) p = cword; } - add_suggestion(su, &su->su_ga, p, su->su_badlen, + add_suggestion(su, &su->su_ga, (char *)p, su->su_badlen, SCORE_FILE, 0, true, su->su_sallang, false); } } @@ -985,7 +985,7 @@ static void suggest_try_special(suginfo_T *su) // Give a soundalike score of 0, compute the score as if deleting one // character. - add_suggestion(su, &su->su_ga, word, su->su_badlen, + add_suggestion(su, &su->su_ga, (char *)word, su->su_badlen, RESCORE(SCORE_REP, 0), 0, true, su->su_sallang, false); } } @@ -1330,7 +1330,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so sp->ts_prewordlen > 0); // Add the suggestion if the score isn't too bad. if (newscore <= su->su_maxscore) { - add_suggestion(su, &su->su_ga, preword, + add_suggestion(su, &su->su_ga, (char *)preword, sp->ts_splitfidx - repextra, newscore, 0, false, lp->lp_sallang, false); @@ -1492,7 +1492,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Add the suggestion if the score isn't too bad. if (score <= su->su_maxscore) { - add_suggestion(su, &su->su_ga, preword, + add_suggestion(su, &su->su_ga, (char *)preword, sp->ts_fidx - repextra, score, 0, false, lp->lp_sallang, false); @@ -1505,7 +1505,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so preword + sp->ts_prewordlen, c == 0 ? WF_ALLCAP : 0); - add_suggestion(su, &su->su_ga, preword, + add_suggestion(su, &su->su_ga, (char *)preword, sp->ts_fidx - repextra, score + SCORE_ICASE, 0, false, lp->lp_sallang, false); @@ -2494,7 +2494,7 @@ static void score_comp_sal(suginfo_T *su) if (score < SCORE_MAXMAX) { // Add the suggestion. sstp = &SUG(su->su_sga, su->su_sga.ga_len); - sstp->st_word = vim_strsave(stp->st_word); + sstp->st_word = xstrdup(stp->st_word); sstp->st_wordlen = stp->st_wordlen; sstp->st_score = score; sstp->st_altscore = 0; @@ -2551,8 +2551,7 @@ static void score_combine(suginfo_T *su) // Add the alternate score to su_sga. for (int i = 0; i < su->su_sga.ga_len; i++) { stp = &SUG(su->su_sga, i); - stp->st_altscore = spell_edit_score(slang, - su->su_badword, stp->st_word); + stp->st_altscore = spell_edit_score(slang, su->su_badword, (char_u *)stp->st_word); if (stp->st_score == SCORE_MAXMAX) { stp->st_score = (SCORE_BIG * 7 + stp->st_altscore) / 8; } else { @@ -2579,7 +2578,7 @@ static void score_combine(suginfo_T *su) gap = round == 1 ? &su->su_ga : &su->su_sga; if (i < gap->ga_len) { // Don't add a word if it's already there. - p = SUG(*gap, i).st_word; + p = (char_u *)SUG(*gap, i).st_word; int j; for (j = 0; j < ga.ga_len; j++) { if (STRCMP(stp[j].st_word, p) == 0) { @@ -2636,7 +2635,7 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u * // removing the space. Don't do it when the good word also contains a // space. if (ascii_iswhite(su->su_badptr[su->su_badlen]) - && *skiptowhite((char *)stp->st_word) == NUL) { + && *skiptowhite(stp->st_word) == NUL) { for (p = fword; *(p = (char_u *)skiptowhite((char *)p)) != NUL;) { STRMOVE(p, p + 1); } @@ -2654,7 +2653,7 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u * su->su_badptr + su->su_badlen - lendiff, lendiff + 1); pgood = goodword; } else { - pgood = stp->st_word; + pgood = (char_u *)stp->st_word; } // Sound-fold the word and compute the score for the difference. @@ -2883,7 +2882,7 @@ badword: if (sps_flags & SPS_DOUBLE) { // Add the suggestion if the score isn't too bad. if (score <= su->su_maxscore) { - add_suggestion(su, &su->su_sga, p, su->su_badlen, + add_suggestion(su, &su->su_sga, (char *)p, su->su_badlen, score, 0, false, slang, false); } } else { @@ -2931,7 +2930,7 @@ badword: // Add the suggestion if the score isn't too bad. goodscore = RESCORE(goodscore, score); if (goodscore <= su->su_sfmaxscore) { - add_suggestion(su, &su->su_ga, p, su->su_badlen, + add_suggestion(su, &su->su_ga, (char *)p, su->su_badlen, goodscore, score, true, slang, true); } } @@ -3061,7 +3060,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2) /// @param had_bonus value for st_had_bonus /// @param slang language for sound folding /// @param maxsf su_maxscore applies to soundfold score, su_sfmaxscore to the total score. -static void add_suggestion(suginfo_T *su, garray_T *gap, const char_u *goodword, int badlenarg, +static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, int badlenarg, int score, int altscore, bool had_bonus, slang_T *slang, bool maxsf) { int goodlen; // len of goodword changed @@ -3071,7 +3070,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char_u *goodword, // Minimize "badlen" for consistency. Avoids that changing "the the" to // "thee the" is added next to changing the first "the" the "thee". - const char_u *pgood = goodword + STRLEN(goodword); + const char *pgood = goodword + STRLEN(goodword); char_u *pbad = su->su_badptr + badlenarg; for (;;) { goodlen = (int)(pgood - goodword); @@ -3144,7 +3143,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char_u *goodword, if (i < 0) { // Add a suggestion. stp = GA_APPEND_VIA_PTR(suggest_T, gap); - stp->st_word = vim_strnsave(goodword, (size_t)goodlen); + stp->st_word = xstrnsave(goodword, (size_t)goodlen); stp->st_wordlen = goodlen; stp->st_score = score; stp->st_altscore = altscore; diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 16691d0ded..423436eccc 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -59,15 +59,6 @@ char_u *vim_strsave(const char_u *string) /// Copy up to `len` bytes of `string` into newly allocated memory and /// terminate with a NUL. The allocated memory always has size `len + 1`, even /// when `string` is shorter. -char_u *vim_strnsave(const char_u *string, size_t len) - FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL -{ - // strncpy is intentional: some parts of Vim use `string` shorter than `len` - // and expect the remainder to be zeroed out. - return (char_u *)strncpy(xmallocz(len), (char *)string, len); -} - -/// A clone of vim_strnsave() that uses char* instead of char_u* char *xstrnsave(const char *string, size_t len) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { @@ -318,15 +309,13 @@ char_u *vim_strsave_up(const char_u *string) return p1; } -/* - * Like vim_strnsave(), but make all characters uppercase. - * This uses ASCII lower-to-upper case translation, language independent. - */ -char_u *vim_strnsave_up(const char_u *string, size_t len) +/// Like xstrnsave(), but make all characters uppercase. +/// This uses ASCII lower-to-upper case translation, language independent. +char *vim_strnsave_up(const char *string, size_t len) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { - char_u *p1 = vim_strnsave(string, len); - vim_strup(p1); + char *p1 = xstrnsave(string, len); + vim_strup((char_u *)p1); return p1; } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index d8de23182c..9eb412b803 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -93,7 +93,7 @@ typedef struct syn_pattern { int16_t *sp_cont_list; // cont. group IDs, if non-zero int16_t *sp_next_list; // next group IDs, if non-zero struct sp_syn sp_syn; // struct passed to in_id_list() - char_u *sp_pattern; // regexp to match, pattern + char *sp_pattern; // regexp to match, pattern regprog_T *sp_prog; // regexp to match, program syn_time_T sp_time; } synpat_T; @@ -1709,9 +1709,10 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con if (do_keywords) { line = (char_u *)syn_getcurline(); const char_u *cur_pos = line + current_col; - if (vim_iswordp_buf(cur_pos, syn_buf) + if (vim_iswordp_buf((char *)cur_pos, syn_buf) && (current_col == 0 - || !vim_iswordp_buf(cur_pos - 1 - utf_head_off((char *)line, (char *)cur_pos - 1), + || !vim_iswordp_buf((char *)cur_pos - 1 - + utf_head_off((char *)line, (char *)cur_pos - 1), syn_buf))) { syn_id = check_keyword_id((char *)line, (int)current_col, &endcol, &flags, &next_list, cur_si, &cchar); @@ -2942,7 +2943,7 @@ static int check_keyword_id(char *const line, const int startcol, int *const end int kwlen = 0; do { kwlen += utfc_ptr2len(kwp + kwlen); - } while (vim_iswordp_buf((char_u *)kwp + kwlen, syn_buf)); + } while (vim_iswordp_buf(kwp + kwlen, syn_buf)); if (kwlen > MAXKEYWLEN) { return 0; @@ -3772,14 +3773,14 @@ static void put_pattern(const char *const s, const int c, const synpat_T *const msg_putchar(c); // output the pattern, in between a char that is not in the pattern - for (i = 0; vim_strchr((char *)spp->sp_pattern, sepchars[i]) != NULL;) { + for (i = 0; vim_strchr(spp->sp_pattern, sepchars[i]) != NULL;) { if (sepchars[++i] == NUL) { i = 0; // no good char found, just use the first one break; } } msg_putchar(sepchars[i]); - msg_outtrans((char *)spp->sp_pattern); + msg_outtrans(spp->sp_pattern); msg_putchar(sepchars[i]); // output any pattern options @@ -4048,7 +4049,7 @@ 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_u *gname_start, *gname; + char *gname_start, *gname; int syn_id; int len = 0; char *p; @@ -4157,16 +4158,16 @@ 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 = (char_u *)arg; + gname_start = arg; arg = skiptowhite(arg); - if (gname_start == (char_u *)arg) { + if (gname_start == arg) { return NULL; } - gname = vim_strnsave(gname_start, (size_t)((char_u *)arg - gname_start)); + gname = xstrnsave(gname_start, (size_t)(arg - gname_start)); if (STRCMP(gname, "NONE") == 0) { *opt->sync_idx = NONE_IDX; } else { - syn_id = syn_name2id((char *)gname); + syn_id = syn_name2id(gname); int i; for (i = curwin->w_s->b_syn_patterns.ga_len; --i >= 0;) { if (SYN_ITEMS(curwin->w_s)[i].sp_syn.id == syn_id @@ -4566,7 +4567,7 @@ static void syn_cmd_region(exarg_T *eap, int syncing) key_end++; } xfree(key); - key = (char *)vim_strnsave_up((char_u *)rest, (size_t)(key_end - rest)); + key = vim_strnsave_up(rest, (size_t)(key_end - rest)); if (STRCMP(key, "MATCHGROUP") == 0) { item = ITEM_MATCHGROUP; } else if (STRCMP(key, "START") == 0) { @@ -5043,12 +5044,12 @@ static char *get_syn_pattern(char *arg, synpat_T *ci) return NULL; } // store the pattern and compiled regexp program - ci->sp_pattern = vim_strnsave((char_u *)arg + 1, (size_t)(end - arg) - 1); + 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; - ci->sp_prog = vim_regcomp((char *)ci->sp_pattern, RE_MAGIC); + ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC); p_cpo = cpo_save; if (ci->sp_prog == NULL) { @@ -5137,7 +5138,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) arg_end = skiptowhite(arg_start); next_arg = skipwhite(arg_end); xfree(key); - key = (char *)vim_strnsave_up((char_u *)arg_start, (size_t)(arg_end - arg_start)); + key = vim_strnsave_up(arg_start, (size_t)(arg_end - arg_start)); if (STRCMP(key, "CCOMMENT") == 0) { if (!eap->skip) { curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; @@ -5975,7 +5976,7 @@ static void syntime_report(void) proftime_T tm = profile_divide(spp->sp_time.total, (int)spp->sp_time.count); p->average = tm; p->id = spp->sp_syn.id; - p->pattern = spp->sp_pattern; + p->pattern = (char_u *)spp->sp_pattern; } } diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 648eb751fe..d1d5514648 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -66,11 +66,11 @@ typedef struct tag_pointers { char_u *command_end; // first char after command char_u *tag_fname; // file name of the tags file. This is used // when 'tr' is set. - char_u *tagkind; // "kind:" value - char_u *tagkind_end; // end of tagkind - char_u *user_data; // user_data string + char_u *tagkind; // "kind:" value + char_u *tagkind_end; // end of tagkind + char *user_data; // user_data string char_u *user_data_end; // end of user_data - linenr_T tagline; // "line:" value + linenr_T tagline; // "line:" value } tagptrs_T; /* @@ -588,9 +588,8 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) if (use_tfu && parse_match(matches[cur_match], &tagp2) == OK && tagp2.user_data) { XFREE_CLEAR(tagstack[tagstackidx].user_data); - tagstack[tagstackidx].user_data = (char *)vim_strnsave(tagp2.user_data, - (size_t)(tagp2.user_data_end - - tagp2.user_data)); + tagstack[tagstackidx].user_data = + xstrnsave(tagp2.user_data, (size_t)(tagp2.user_data_end - (char_u *)tagp2.user_data)); } tagstackidx++; @@ -1425,7 +1424,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc int help_pri = 0; char_u *help_lang_find = NULL; // lang to be found char_u help_lang[3]; // lang of current tags file - char_u *saved_pat = NULL; // copy of pat[] + char *saved_pat = NULL; // copy of pat[] bool is_txt = false; pat_T orgpat; // holds unconverted pattern info @@ -1503,9 +1502,9 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc if (orgpat.len > 3 && pat[orgpat.len - 3] == '@' && ASCII_ISALPHA(pat[orgpat.len - 2]) && ASCII_ISALPHA(pat[orgpat.len - 1])) { - saved_pat = vim_strnsave((char_u *)pat, (size_t)orgpat.len - 3); + saved_pat = xstrnsave(pat, (size_t)orgpat.len - 3); help_lang_find = (char_u *)&pat[orgpat.len - 2]; - orgpat.pat = saved_pat; + orgpat.pat = (char_u *)saved_pat; orgpat.len -= 3; } } @@ -2430,11 +2429,11 @@ int get_tagfname(tagname_T *tnp, int first, char *buf) STRMOVE(filename + 1, filename); *filename++ = NUL; - tnp->tn_search_ctx = vim_findfile_init((char_u *)buf, filename, - (char_u *)r_ptr, 100, + tnp->tn_search_ctx = vim_findfile_init(buf, (char *)filename, + r_ptr, 100, false, // don't free visited list FINDFILE_FILE, // we search for a file - tnp->tn_search_ctx, true, (char_u *)curbuf->b_ffname); + tnp->tn_search_ctx, true, curbuf->b_ffname); if (tnp->tn_search_ctx != NULL) { tnp->tn_did_filefind_init = true; } @@ -2584,7 +2583,7 @@ static int parse_match(char *lbuf, tagptrs_T *tagp) if (STRNCMP(p, "kind:", 5) == 0) { tagp->tagkind = (char_u *)p + 5; } else if (STRNCMP(p, "user_data:", 10) == 0) { - tagp->user_data = (char_u *)p + 10; + tagp->user_data = p + 10; } else if (STRNCMP(p, "line:", 5) == 0) { tagp->tagline = atoi(p + 5); } @@ -2612,7 +2611,7 @@ static int parse_match(char *lbuf, tagptrs_T *tagp) tagp->tagkind_end = (char_u *)p; } if (tagp->user_data != NULL) { - for (p = (char *)tagp->user_data; + for (p = tagp->user_data; *p && *p != '\t' && *p != '\r' && *p != '\n'; MB_PTR_ADV(p)) {} tagp->user_data_end = (char_u *)p; @@ -2980,7 +2979,7 @@ static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, const bo /* * Expand file name (for environment variables) when needed. */ - if (expand && path_has_wildcard(fname)) { + if (expand && path_has_wildcard((char *)fname)) { ExpandInit(&xpc); xpc.xp_context = EXPAND_FILES; expanded_fname = ExpandOne(&xpc, fname, NULL, diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 5ded0c9ab2..6e69fb95c8 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -117,7 +117,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on // Don't break until after the comment leader if (do_comments) { - char_u *line = get_cursor_line_ptr(); + char_u *line = (char_u *)get_cursor_line_ptr(); leader_len = get_leader_len((char *)line, NULL, false, true); if (leader_len == 0 && curbuf->b_p_cin) { // Check for a line comment after code. @@ -624,8 +624,8 @@ void auto_format(bool trailblank, bool prev_line) { pos_T pos; colnr_T len; - char_u *old; - char_u *new, *pnew; + char *old; + char *new, *pnew; int wasatend; int cc; @@ -663,7 +663,7 @@ void auto_format(bool trailblank, bool prev_line) // With the 'c' flag in 'formatoptions' and 't' missing: only format // comments. if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP) - && get_leader_len((char *)old, NULL, false, true) == 0) { + && get_leader_len(old, NULL, false, true) == 0) { return; } @@ -700,10 +700,10 @@ void auto_format(bool trailblank, bool prev_line) new = get_cursor_line_ptr(); len = (colnr_T)STRLEN(new); if (curwin->w_cursor.col == len) { - pnew = vim_strnsave(new, (size_t)len + 2); + pnew = xstrnsave(new, (size_t)len + 2); pnew[len] = ' '; pnew[len + 1] = NUL; - ml_replace(curwin->w_cursor.lnum, (char *)pnew, false); + ml_replace(curwin->w_cursor.lnum, pnew, false); // remove the space later did_add_space = true; } else { @@ -1026,7 +1026,7 @@ void format_lines(linenr_T line_count, bool avoid_fex) // paragraph doesn't really end. if (next_leader_flags == NULL || STRNCMP(next_leader_flags, "://", 3) != 0 - || check_linecomment((char *)get_cursor_line_ptr()) == MAXCOL) { + || check_linecomment(get_cursor_line_ptr()) == MAXCOL) { is_end_par = true; } } diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index a8f4cc7aeb..6863b40599 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -1032,7 +1032,7 @@ int current_block(oparg_T *oap, long count, bool include, int what, int other) /// @return true if the cursor is on a "" tag. Ignore "". static bool in_html_tag(bool end_tag) { - char_u *line = get_cursor_line_ptr(); + char_u *line = (char_u *)get_cursor_line_ptr(); char_u *p; int c; int lc = NUL; @@ -1493,7 +1493,7 @@ static int find_prev_quote(char_u *line, int col_start, int quotechar, char_u *e bool current_quote(oparg_T *oap, long count, bool include, int quotechar) FUNC_ATTR_NONNULL_ALL { - char_u *line = get_cursor_line_ptr(); + char_u *line = (char_u *)get_cursor_line_ptr(); int col_end; int col_start = curwin->w_cursor.col; bool inclusive = false; diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 387b9d61f2..d12a690b83 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -66,8 +66,6 @@ #include "nvim/viml/parser/expressions.h" #include "nvim/viml/parser/parser.h" -#define VIM_STR2NR(s, ...) vim_str2nr((const char_u *)(s), __VA_ARGS__) - typedef kvec_withinit_t(ExprASTNode **, 16) ExprASTStack; /// Which nodes may be wanted @@ -371,7 +369,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) significand_part = significand_part * 10 + (pline.data[i] - '0'); } if (exp_start) { - VIM_STR2NR(pline.data + exp_start, NULL, NULL, 0, NULL, &exp_part, + vim_str2nr(pline.data + exp_start, NULL, NULL, 0, NULL, &exp_part, (int)(ret.len - exp_start), false); } if (exp_negative) { @@ -389,7 +387,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) } else { int len; int prep; - VIM_STR2NR(pline.data, &prep, &len, STR2NR_ALL, NULL, + vim_str2nr(pline.data, &prep, &len, STR2NR_ALL, NULL, &ret.data.num.val.integer, (int)pline.size, false); ret.len = (size_t)len; const uint8_t bases[] = { @@ -696,8 +694,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) // Everything else is not valid. default: - ret.len = (size_t)utfc_ptr2len_len((const char_u *)pline.data, - (int)pline.size); + ret.len = (size_t)utfc_ptr2len_len(pline.data, (int)pline.size); ret.type = kExprLexInvalid; ret.data.err.type = kExprLexPlainIdentifier; ret.data.err.msg = _("E15: Unidentified character: %.*s"); diff --git a/src/nvim/window.c b/src/nvim/window.c index c11484d1b8..8ca40cdd35 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6522,7 +6522,7 @@ char_u *grab_file_name(long count, linenr_T *file_lnum) *file_lnum = (linenr_T)getdigits_long(&p, false, 0); } - return find_file_name_in_path((char_u *)ptr, len, options, count, (char_u *)curbuf->b_ffname); + return (char_u *)find_file_name_in_path(ptr, len, options, count, curbuf->b_ffname); } return file_name_at_cursor(options | FNAME_HYP, count, file_lnum); } @@ -6542,7 +6542,7 @@ char_u *grab_file_name(long count, linenr_T *file_lnum) */ char_u *file_name_at_cursor(int options, long count, linenr_T *file_lnum) { - return file_name_in_line(get_cursor_line_ptr(), + return file_name_in_line((char_u *)get_cursor_line_ptr(), curwin->w_cursor.col, options, count, (char_u *)curbuf->b_ffname, file_lnum); } @@ -6649,7 +6649,7 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u } } - return find_file_name_in_path((char_u *)ptr, len, options, count, rel_fname); + return (char_u *)find_file_name_in_path(ptr, len, options, count, (char *)rel_fname); } /// Add or remove a status line from window(s), according to the -- cgit From c65b1f3e15662cd14c443e34862237d3dee30977 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 20:18:17 +0800 Subject: vim-patch:9.0.0342: ":wincmd =" equalizes in two directions Problem: ":wincmd =" equalizes in two directions. Solution: Make ":vertical wincmd =" equalize vertically only and ":horizontal wincmd =" equalize horizontally only. https://github.com/vim/vim/commit/21c3a80a7fd6b7fc250ce5dc287963511f54b86f --- src/nvim/ex_cmds.lua | 6 ++++++ src/nvim/ex_docmd.c | 6 +++++- src/nvim/testdir/test_window_cmd.vim | 40 ++++++++++++++++++++++++++++++++++++ src/nvim/window.c | 8 +++++--- src/nvim/window.h | 17 +++++++-------- 5 files changed, 65 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index 4bed1e94b9..04b8832428 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -1140,6 +1140,12 @@ module.cmds = { addr_type='ADDR_NONE', func='ex_history', }, + { + command='horizontal', + flags=bit.bor(NEEDARG, EXTRA, NOTRLCOM), + addr_type='ADDR_NONE', + func='ex_wrongmodifier', + }, { command='insert', flags=bit.bor(BANG, RANGE, TRLBAR, CMDWIN, LOCK_OK, MODIFY), diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 0af737ff50..f99253ea75 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2438,8 +2438,12 @@ int parse_command_modifiers(exarg_T *eap, char **errormsg, cmdmod_T *cmod, bool continue; } - // ":hide" and ":hide | cmd" are not modifiers case 'h': + if (checkforcmd(&eap->cmd, "horizontal", 3)) { + cmod->cmod_split |= WSP_HOR; + continue; + } + // ":hide" and ":hide | cmd" are not modifiers if (p != eap->cmd || !checkforcmd(&p, "hide", 3) || *p == NUL || ends_excmd(*p)) { break; diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 83a3216534..1f4b9b77c6 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -343,6 +343,46 @@ func Test_window_height() bw Xa Xb Xc endfunc +func Test_wincmd_equal() + edit Xone + below split Xtwo + rightbelow vsplit Xthree + call assert_equal('Xone', bufname(winbufnr(1))) + call assert_equal('Xtwo', bufname(winbufnr(2))) + call assert_equal('Xthree', bufname(winbufnr(3))) + + " Xone and Xtwo should be about the same height + let [wh1, wh2] = [winheight(1), winheight(2)] + call assert_inrange(wh1 - 1, wh1 + 1, wh2) + " Xtwo and Xthree should be about the same width + let [ww2, ww3] = [winwidth(2), winwidth(3)] + call assert_inrange(ww2 - 1, ww2 + 1, ww3) + + 1wincmd w + 10wincmd _ + 2wincmd w + 20wincmd | + call assert_equal(10, winheight(1)) + call assert_equal(20, winwidth(2)) + + " equalizing horizontally doesn't change the heights + hor wincmd = + call assert_equal(10, winheight(1)) + let [ww2, ww3] = [winwidth(2), winwidth(3)] + call assert_inrange(ww2 - 1, ww2 + 1, ww3) + + 2wincmd w + 20wincmd | + call assert_equal(20, winwidth(2)) + " equalizing vertically doesn't change the widths + vert wincmd = + call assert_equal(20, winwidth(2)) + let [wh1, wh2] = [winheight(1), winheight(2)] + call assert_inrange(wh1 - 1, wh1 + 1, wh2) + + bwipe Xone Xtwo Xthree +endfunc + func Test_window_width() e Xa vsplit Xb diff --git a/src/nvim/window.c b/src/nvim/window.c index c11484d1b8..c0b73ff837 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -417,10 +417,12 @@ newwindow: | ((nchar == 'H' || nchar == 'K') ? WSP_TOP : WSP_BOT)); break; - // make all windows the same height - case '=': - win_equal(NULL, false, 'b'); + // make all windows the same width and/or height + case '=': { + int mod = cmdmod.cmod_split & (WSP_VERT | WSP_HOR); + win_equal(NULL, false, mod == WSP_VERT ? 'v' : mod == WSP_HOR ? 'h' : 'b'); break; + } // increase current window height case '+': diff --git a/src/nvim/window.h b/src/nvim/window.h index b75b8abd9b..3137035b25 100644 --- a/src/nvim/window.h +++ b/src/nvim/window.h @@ -17,14 +17,15 @@ #define FNAME_UNESC 32 // remove backslashes used for escaping // arguments for win_split() -#define WSP_ROOM 1 // require enough room -#define WSP_VERT 2 // split vertically -#define WSP_TOP 4 // window at top-left of shell -#define WSP_BOT 8 // window at bottom-right of shell -#define WSP_HELP 16 // creating the help window -#define WSP_BELOW 32 // put new window below/right -#define WSP_ABOVE 64 // put new window above/left -#define WSP_NEWLOC 128 // don't copy location list +#define WSP_ROOM 0x01 // require enough room +#define WSP_VERT 0x02 // split/equalize vertically +#define WSP_HOR 0x04 // equalize horizontally +#define WSP_TOP 0x08 // window at top-left of shell +#define WSP_BOT 0x10 // window at bottom-right of shell +#define WSP_HELP 0x20 // creating the help window +#define WSP_BELOW 0x40 // put new window below/right +#define WSP_ABOVE 0x80 // put new window above/left +#define WSP_NEWLOC 0x100 // don't copy location list // Minimum screen size #define MIN_COLUMNS 12 // minimal columns for screen -- cgit From 56bf026deac8eddb1abc8e1d46fde992cfc67ac2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 20:25:34 +0800 Subject: vim-patch:9.0.0346: :horizontal modifier not fully supported Problem: :horizontal modifier not fully supported. Solution: Also use :horizontal for completion and user commands. (closes vim/vim#11025) https://github.com/vim/vim/commit/d3de178e5352fedf0f30b979f46a2fcbca24ea40 --- src/nvim/cmdexpand.c | 1 + src/nvim/ex_docmd.c | 1 + src/nvim/testdir/test_cmdline.vim | 4 ++++ src/nvim/testdir/test_usercommands.vim | 4 ++++ src/nvim/usercmd.c | 4 ++++ 5 files changed, 14 insertions(+) (limited to 'src') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 6fc63f72a1..9d8dd197bd 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1203,6 +1203,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons case CMD_folddoclosed: case CMD_folddoopen: case CMD_hide: + case CMD_horizontal: case CMD_keepalt: case CMD_keepjumps: case CMD_keepmarks: diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index f99253ea75..ea21dc8ae7 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1757,6 +1757,7 @@ static bool skip_cmd(const exarg_T *eap) case CMD_filter: case CMD_help: case CMD_hide: + case CMD_horizontal: case CMD_ijump: case CMD_ilist: case CMD_isearch: diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 4bfd22cb6c..bc06e70ff4 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -926,6 +926,10 @@ func Test_cmdline_complete_various() call feedkeys(":all abc\\\"\", 'xt') call assert_equal("\"all abc\", @:) + " completion for :wincmd with :horizontal modifier + call feedkeys(":horizontal wincm\\\"\", 'xt') + call assert_equal("\"horizontal wincmd", @:) + " completion for a command with a command modifier call feedkeys(":topleft new\\\"\", 'xt') call assert_equal("\"topleft new", @:) diff --git a/src/nvim/testdir/test_usercommands.vim b/src/nvim/testdir/test_usercommands.vim index e37fe43b22..1065dd16e2 100644 --- a/src/nvim/testdir/test_usercommands.vim +++ b/src/nvim/testdir/test_usercommands.vim @@ -101,6 +101,10 @@ function Test_cmdmods() call assert_equal('vertical', g:mods) vert MyCmd call assert_equal('vertical', g:mods) + horizontal MyCmd + call assert_equal('horizontal', g:mods) + hor MyCmd + call assert_equal('horizontal', g:mods) aboveleft belowright botright browse confirm hide keepalt keepjumps \ keepmarks keeppatterns lockmarks noautocmd noswapfile silent diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 9cc9fb5588..3726273d28 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -1247,6 +1247,10 @@ size_t add_win_cmd_modifers(char *buf, const cmdmod_T *cmod, bool *multi_mods) if (cmod->cmod_split & WSP_VERT) { result += add_cmd_modifier(buf, "vertical", multi_mods); } + // :horizontal + if (cmod->cmod_split & WSP_HOR) { + result += add_cmd_modifier(buf, "horizontal", multi_mods); + } return result; } -- cgit From 689f5d604e59eba1ddab6f91b458a8163dc6629d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 20:32:59 +0800 Subject: feat(api): add support for :horizontal modifier --- src/nvim/api/command.c | 7 +++++++ src/nvim/api/keysets.lua | 1 + src/nvim/lua/executor.c | 2 ++ 3 files changed, 10 insertions(+) (limited to 'src') diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index 1323fc347b..b821e07d60 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -62,6 +62,7 @@ /// - browse: (boolean) |:browse|. /// - confirm: (boolean) |:confirm|. /// - hide: (boolean) |:hide|. +/// - horizontal: (boolean) |:horizontal|. /// - keepalt: (boolean) |:keepalt|. /// - keepjumps: (boolean) |:keepjumps|. /// - keepmarks: (boolean) |:keepmarks|. @@ -250,6 +251,7 @@ Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err) PUT(mods, "lockmarks", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_LOCKMARKS)); PUT(mods, "noswapfile", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_NOSWAPFILE)); PUT(mods, "vertical", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_split & WSP_VERT)); + PUT(mods, "horizontal", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_split & WSP_HOR)); const char *split; if (cmdinfo.cmdmod.cmod_split & WSP_BOT) { @@ -576,6 +578,10 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error OBJ_TO_BOOL(vertical, mods.vertical, false, "'mods.vertical'"); cmdinfo.cmdmod.cmod_split |= (vertical ? WSP_VERT : 0); + bool horizontal; + OBJ_TO_BOOL(horizontal, mods.horizontal, false, "'mods.horizontal'"); + cmdinfo.cmdmod.cmod_split |= (horizontal ? WSP_HOR : 0); + if (HAS_KEY(mods.split)) { if (mods.split.type != kObjectTypeString) { VALIDATION_ERROR("'mods.split' must be a String"); @@ -753,6 +759,7 @@ static void build_cmdline_str(char **cmdlinep, exarg_T *eap, CmdParseInfo *cmdin } while (0) CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_split & WSP_VERT, "vertical "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_split & WSP_HOR, "horizontal "); CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_SANDBOX, "sandbox "); CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_NOAUTOCMD, "noautocmd "); CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_BROWSE, "browse "); diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua index 6fad52ba75..af3dc24f51 100644 --- a/src/nvim/api/keysets.lua +++ b/src/nvim/api/keysets.lua @@ -188,6 +188,7 @@ return { "browse"; "confirm"; "hide"; + "horizontal"; "keepalt"; "keepjumps"; "keepmarks"; diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index f144e47c3a..2315ecd874 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -2103,6 +2103,8 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview) lua_pushboolean(lstate, cmdmod.cmod_split & WSP_VERT); lua_setfield(lstate, -2, "vertical"); + lua_pushboolean(lstate, cmdmod.cmod_split & WSP_HOR); + lua_setfield(lstate, -2, "horizontal"); lua_pushboolean(lstate, cmdmod.cmod_flags & CMOD_SILENT); lua_setfield(lstate, -2, "silent"); lua_pushboolean(lstate, cmdmod.cmod_flags & CMOD_ERRSILENT); -- cgit From ce80b8f50d7d56ac12aa06a64a65799ec18b69af Mon Sep 17 00:00:00 2001 From: Jonas Strittmatter <40792180+smjonas@users.noreply.github.com> Date: Fri, 2 Sep 2022 08:16:17 +0200 Subject: vim-patch:9.0.0349: filetype of *.sil files not well detected (#20050) Problem: Filetype of *.sil files not well detected. Solution: Inspect the file contents to guess the filetype. https://github.com/vim/vim/commit/be807d582499acbe314ead3891481cba6ca136df --- src/nvim/testdir/test_filetype.vim | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 68ce9148a4..4f5ae830b7 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -1824,6 +1824,44 @@ func Test_sig_file() filetype off endfunc +" Test dist#ft#FTsil() +func Test_sil_file() + filetype on + + split Xfile.sil + call assert_equal('sil', &filetype) + bwipe! + + let lines =<< trim END + // valid + let protoErasedPathA = \ABCProtocol.a + + // also valid + let protoErasedPathA = + \ABCProtocol.a + END + call writefile(lines, 'Xfile.sil') + + split Xfile.sil + call assert_equal('sil', &filetype) + bwipe! + + " SILE + + call writefile(['% some comment'], 'Xfile.sil') + split Xfile.sil + call assert_equal('sile', &filetype) + bwipe! + + call writefile(['\begin[papersize=a6]{document}foo\end{document}'], 'Xfile.sil') + split Xfile.sil + call assert_equal('sile', &filetype) + bwipe! + + call delete('Xfile.sil') + filetype off +endfunc + func Test_inc_file() filetype on -- cgit From 2dd55f81f736d5fe9697cd0e15c96f763eb90458 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Fri, 2 Sep 2022 17:44:14 +0600 Subject: fix(ui): ui compositor does not correctly free event callbacks Prior to this PR, when freeing event callbacks, UI compositor did not free the luarefs which could cause potential memory leaks. This PR fixes that by freeing the luarefs properly. --- src/nvim/ui_compositor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index b8c7834e2b..2fb70eae8a 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -98,7 +98,7 @@ void ui_comp_free_all_mem(void) { UIEventCallback *event_cb; map_foreach_value(&ui_event_cbs, event_cb, { - xfree(event_cb); + free_ui_event_callback(event_cb); }) pmap_destroy(uint32_t)(&ui_event_cbs); } -- cgit From 2afcdbd63a5b0cbeaad9d83b096a3af5201c67a9 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 2 Sep 2022 15:20:29 +0100 Subject: feat(Man): port to Lua (#19912) Co-authored-by: zeertzjq --- src/nvim/testdir/test_profile.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_profile.vim b/src/nvim/testdir/test_profile.vim index fdb6f13e2b..4225b91bc4 100644 --- a/src/nvim/testdir/test_profile.vim +++ b/src/nvim/testdir/test_profile.vim @@ -40,8 +40,8 @@ func Test_profile_func() call writefile(lines, 'Xprofile_func.vim') call system(GetVimCommand() \ . ' -es --clean' - \ . ' -c "so Xprofile_func.vim"' - \ . ' -c "qall!"') + \ . ' --cmd "so Xprofile_func.vim"' + \ . ' --cmd "qall!"') call assert_equal(0, v:shell_error) let lines = readfile('Xprofile_func.log') @@ -475,7 +475,7 @@ func Test_profdel_func() call Foo3() [CODE] call writefile(lines, 'Xprofile_file.vim') - call system(GetVimCommandClean() . ' -es -c "so Xprofile_file.vim" -c q') + call system(GetVimCommandClean() . ' -es --cmd "so Xprofile_file.vim" --cmd q') call assert_equal(0, v:shell_error) let lines = readfile('Xprofile_file.log') -- cgit From 1ef7720567b08caec0c077605fb2a01a9d6eafbc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 18:46:34 +0800 Subject: fix(api)!: correctly deal with number before :tab Now nvim_parse_cmd and nvim_create_user_command use a "tab" value which is the same as the number passed before :tab modifier instead of the number plus 1, and "tab" value is -1 if :tab modifier is not used. --- src/nvim/api/command.c | 14 ++++++++------ src/nvim/lua/executor.c | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index b821e07d60..11715a49dc 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -69,7 +69,7 @@ /// - keeppatterns: (boolean) |:keeppatterns|. /// - lockmarks: (boolean) |:lockmarks|. /// - noswapfile: (boolean) |:noswapfile|. -/// - tab: (integer) |:tab|. +/// - tab: (integer) |:tab|. -1 when omitted. /// - verbose: (integer) |:verbose|. -1 when omitted. /// - vertical: (boolean) |:vertical|. /// - split: (string) Split modifier string, is an empty string when there's no split @@ -239,7 +239,7 @@ Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err) PUT(mods, "unsilent", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_UNSILENT)); PUT(mods, "sandbox", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_SANDBOX)); PUT(mods, "noautocmd", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_NOAUTOCMD)); - PUT(mods, "tab", INTEGER_OBJ(cmdinfo.cmdmod.cmod_tab)); + PUT(mods, "tab", INTEGER_OBJ(cmdinfo.cmdmod.cmod_tab - 1)); PUT(mods, "verbose", INTEGER_OBJ(cmdinfo.cmdmod.cmod_verbose - 1)); PUT(mods, "browse", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_BROWSE)); PUT(mods, "confirm", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_CONFIRM)); @@ -559,15 +559,17 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error } if (HAS_KEY(mods.tab)) { - if (mods.tab.type != kObjectTypeInteger || mods.tab.data.integer < 0) { - VALIDATION_ERROR("'mods.tab' must be a non-negative Integer"); + if (mods.tab.type != kObjectTypeInteger) { + VALIDATION_ERROR("'mods.tab' must be an Integer"); + } else if ((int)mods.tab.data.integer >= 0) { + // Silently ignore negative integers to allow mods.tab to be set to -1. + cmdinfo.cmdmod.cmod_tab = (int)mods.tab.data.integer + 1; } - cmdinfo.cmdmod.cmod_tab = (int)mods.tab.data.integer + 1; } if (HAS_KEY(mods.verbose)) { if (mods.verbose.type != kObjectTypeInteger) { - VALIDATION_ERROR("'mods.verbose' must be a Integer"); + VALIDATION_ERROR("'mods.verbose' must be an Integer"); } else if ((int)mods.verbose.data.integer >= 0) { // Silently ignore negative integers to allow mods.verbose to be set to -1. cmdinfo.cmdmod.cmod_verbose = (int)mods.verbose.data.integer + 1; diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 2315ecd874..1013cf76f9 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -2082,7 +2082,7 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview) lua_newtable(lstate); // smods table - lua_pushinteger(lstate, cmdmod.cmod_tab); + lua_pushinteger(lstate, cmdmod.cmod_tab - 1); lua_setfield(lstate, -2, "tab"); lua_pushinteger(lstate, cmdmod.cmod_verbose - 1); -- cgit From 1ffd527c837fb2465c9659273bbe5447a1352db2 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 2 Sep 2022 17:39:49 +0100 Subject: refactor: migrate comment style (#20012) Done automatically using the following perl command: perl -pi -0777pe 's#\n\K */\*\n(.+?)\s*\*/\n#join("\n", map { $_ =~ s:^\s*\K \*://:; $_ } split("\n", $1)) . "\n"#sge' src/nvim/**/*.c Co-authored-by: zeertzjq Co-authored-by: zeertzjq --- src/nvim/buffer_defs.h | 337 ++++++-------- src/nvim/edit.c | 385 ++++++---------- src/nvim/eval.h | 52 ++- src/nvim/eval/userfunc.c | 54 +-- src/nvim/ex_cmds.c | 430 +++++++----------- src/nvim/ex_eval.c | 378 +++++++--------- src/nvim/ex_getln.c | 82 ++-- src/nvim/file_search.c | 224 ++++----- src/nvim/fileio.c | 535 ++++++++-------------- src/nvim/fold.h | 6 +- src/nvim/getchar.c | 257 ++++------- src/nvim/hardcopy.c | 442 +++++++----------- src/nvim/hardcopy.h | 12 +- src/nvim/if_cscope.c | 141 +++--- src/nvim/indent_c.c | 1121 +++++++++++++++++++--------------------------- src/nvim/main.c | 61 +-- src/nvim/mark.c | 133 ++---- src/nvim/mark_defs.h | 6 +- src/nvim/mbyte.c | 242 ++++------ src/nvim/mbyte.h | 10 +- src/nvim/memline.c | 686 +++++++++++----------------- src/nvim/memory.c | 18 +- src/nvim/menu.c | 148 ++---- src/nvim/message.c | 160 +++---- src/nvim/message.h | 8 +- src/nvim/move.c | 384 ++++++---------- src/nvim/normal.h | 8 +- src/nvim/ops.c | 166 +++---- src/nvim/ops.h | 16 +- src/nvim/option.c | 227 ++++------ src/nvim/option_defs.h | 12 +- src/nvim/path.c | 154 +++---- src/nvim/path.h | 4 +- src/nvim/search.c | 369 ++++++--------- src/nvim/strings.c | 78 ++-- src/nvim/syntax.c | 1046 +++++++++++++++--------------------------- src/nvim/tag.c | 341 +++++--------- src/nvim/window.c | 599 +++++++++---------------- 38 files changed, 3494 insertions(+), 5838 deletions(-) (limited to 'src') diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index c1ac20fd98..c26b18a7e7 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -48,25 +48,23 @@ typedef struct { #define GETFILE_SUCCESS(x) ((x) <= 0) #define MODIFIABLE(buf) (buf->b_p_ma) -/* - * Flags for w_valid. - * These are set when something in a window structure becomes invalid, except - * when the cursor is moved. Call check_cursor_moved() before testing one of - * the flags. - * These are reset when that thing has been updated and is valid again. - * - * Every function that invalidates one of these must call one of the - * invalidate_* functions. - * - * w_valid is supposed to be used only in screen.c. From other files, use the - * functions that set or reset the flags. - * - * VALID_BOTLINE VALID_BOTLINE_AP - * on on w_botline valid - * off on w_botline approximated - * off off w_botline not valid - * on off not possible - */ +// Flags for w_valid. +// These are set when something in a window structure becomes invalid, except +// when the cursor is moved. Call check_cursor_moved() before testing one of +// the flags. +// These are reset when that thing has been updated and is valid again. +// +// Every function that invalidates one of these must call one of the +// invalidate_* functions. +// +// w_valid is supposed to be used only in screen.c. From other files, use the +// functions that set or reset the flags. +// +// VALID_BOTLINE VALID_BOTLINE_AP +// on on w_botline valid +// off on w_botline approximated +// off off w_botline not valid +// on off not possible #define VALID_WROW 0x01 // w_wrow (window row) is valid #define VALID_WCOL 0x02 // w_wcol (window col) is valid #define VALID_VIRTCOL 0x04 // w_virtcol (file col) is valid @@ -112,9 +110,7 @@ typedef uint64_t disptick_T; // display tick type #include "nvim/sign_defs.h" #include "nvim/terminal.h" // for Terminal -/* - * The taggy struct is used to store the information about a :tag command. - */ +// The taggy struct is used to store the information about a :tag command. typedef struct taggy { char *tagname; // tag name fmark_T fmark; // cursor position BEFORE ":tag" @@ -126,17 +122,13 @@ typedef struct taggy { typedef struct buffblock buffblock_T; typedef struct buffheader buffheader_T; -/* - * structure used to store one block of the stuff/redo/recording buffers - */ +// structure used to store one block of the stuff/redo/recording buffers struct buffblock { buffblock_T *b_next; // pointer to next buffblock char b_str[1]; // contents (actually longer) }; -/* - * header used for the stuff buffer and the redo buffer - */ +// header used for the stuff buffer and the redo buffer struct buffheader { buffblock_T bh_first; // first (dummy) block of list buffblock_T *bh_curr; // buffblock for appending @@ -149,11 +141,9 @@ typedef struct { buffheader_T sr_old_redobuff; } save_redo_T; -/* - * Structure that contains all options that are local to a window. - * Used twice in a window: for the current buffer and for all buffers. - * Also used in wininfo_T. - */ +// Structure that contains all options that are local to a window. +// Used twice in a window: for the current buffer and for all buffers. +// Also used in wininfo_T. typedef struct { int wo_arab; #define w_p_arab w_onebuf_opt.wo_arab // 'arabic' @@ -268,16 +258,14 @@ typedef struct { #define w_p_script_ctx w_onebuf_opt.wo_script_ctx } winopt_T; -/* - * Window info stored with a buffer. - * - * Two types of info are kept for a buffer which are associated with a - * specific window: - * 1. Each window can have a different line number associated with a buffer. - * 2. The window-local options for a buffer work in a similar way. - * The window-info is kept in a list at b_wininfo. It is kept in - * most-recently-used order. - */ +// Window info stored with a buffer. +// +// Two types of info are kept for a buffer which are associated with a +// specific window: +// 1. Each window can have a different line number associated with a buffer. +// 2. The window-local options for a buffer work in a similar way. +// The window-info is kept in a list at b_wininfo. It is kept in +// most-recently-used order. struct wininfo_S { wininfo_T *wi_next; // next entry or NULL for last entry wininfo_T *wi_prev; // previous entry or NULL for first entry @@ -290,12 +278,10 @@ struct wininfo_S { int wi_changelistidx; // copy of w_changelistidx }; -/* - * Argument list: Array of file names. - * Used for the global argument list and the argument lists local to a window. - * - * TODO: move struct arglist to another header - */ +// Argument list: Array of file names. +// Used for the global argument list and the argument lists local to a window. +// +// TODO(neovim): move struct arglist to another header typedef struct arglist { garray_T al_ga; // growarray with the array of file names int al_refcount; // number of windows using this arglist @@ -321,9 +307,7 @@ typedef struct argentry { #define ARGCOUNT (ALIST(curwin)->al_ga.ga_len) #define WARGCOUNT(wp) (ALIST(wp)->al_ga.ga_len) -/* - * Used for the typeahead buffer: typebuf. - */ +// Used for the typeahead buffer: typebuf. typedef struct { uint8_t *tb_buf; // buffer for typed characters uint8_t *tb_noremap; // mapping flags for characters in tb_buf[] @@ -347,9 +331,7 @@ typedef struct { String save_inputbuf; } tasave_T; -/* - * Structure used for mappings and abbreviations. - */ +// Structure used for mappings and abbreviations. typedef struct mapblock mapblock_T; struct mapblock { mapblock_T *m_next; // next mapblock in list @@ -414,9 +396,7 @@ struct stl_item { typedef struct qf_info_S qf_info_T; -/* - * Used for :syntime: timing of executing a syntax pattern. - */ +// Used for :syntime: timing of executing a syntax pattern. typedef struct { proftime_T total; // total time used proftime_T slowest; // time of slowest call @@ -424,10 +404,8 @@ typedef struct { long match; // nr of times matched } syn_time_T; -/* - * These are items normally related to a buffer. But when using ":ownsyntax" - * a window may have its own instance. - */ +// These are items normally related to a buffer. But when using ":ownsyntax" +// a window may have its own instance. typedef struct { hashtab_T b_keywtab; // syntax keywords hash table hashtab_T b_keywtab_ic; // idem, ignore case @@ -514,13 +492,11 @@ EXTERN int curbuf_splice_pending INIT(= 0); // Maximum number of maphash blocks we will have #define MAX_MAPHASH 256 -/* - * buffer: structure that holds information about one file - * - * Several windows can share a single Buffer - * A buffer is unallocated if there is no memfile for it. - * A buffer is new if the associated file has never been loaded yet. - */ +// buffer: structure that holds information about one file +// +// Several windows can share a single Buffer +// A buffer is unallocated if there is no memfile for it. +// A buffer is new if the associated file has never been loaded yet. struct file_buffer { handle_T handle; // unique id for the buffer (buffer number) @@ -570,15 +546,13 @@ struct file_buffer { varnumber_T b_last_changedtick_pum; // b:changedtick when TextChangedP was // last triggered. - bool b_saving; /* Set to true if we are in the middle of - saving the buffer. */ + bool b_saving; // Set to true if we are in the middle of + // saving the buffer. - /* - * Changes to a buffer require updating of the display. To minimize the - * work, remember changes made and update everything at once. - */ - bool b_mod_set; /* true when there are changes since the last - time the display was updated */ + // Changes to a buffer require updating of the display. To minimize the + // work, remember changes made and update everything at once. + bool b_mod_set; // true when there are changes since the last + // time the display was updated linenr_T b_mod_top; // topmost lnum that was changed linenr_T b_mod_bot; // lnum below last changed line, AFTER the // change @@ -609,17 +583,13 @@ struct file_buffer { fmark_T b_last_insert; // where Insert mode was left fmark_T b_last_change; // position of last change: '. mark - /* - * the changelist contains old change positions - */ + // the changelist contains old change positions fmark_T b_changelist[JUMPLISTSIZE]; int b_changelistlen; // number of active entries bool b_new_change; // set by u_savecommon() - /* - * Character table, only used in charset.c for 'iskeyword' - * bitset with 4*64=256 bits: 1 bit per character 0-255. - */ + // Character table, only used in charset.c for 'iskeyword' + // bitset with 4*64=256 bits: 1 bit per character 0-255. uint64_t b_chartab[4]; // Table used for mappings local to a buffer. @@ -629,18 +599,14 @@ struct file_buffer { mapblock_T *b_first_abbr; // User commands local to the buffer. garray_T b_ucmds; - /* - * start and end of an operator, also used for '[ and '] - */ + // start and end of an operator, also used for '[ and '] pos_T b_op_start; pos_T b_op_start_orig; // used for Insstart_orig pos_T b_op_end; bool b_marks_read; // Have we read ShaDa marks yet? - /* - * The following only used in undo.c. - */ + // The following only used in undo.c. u_header_T *b_u_oldhead; // pointer to oldest header u_header_T *b_u_newhead; // pointer to newest header; may not be valid // if b_u_curhead is not NULL @@ -673,11 +639,9 @@ struct file_buffer { #define KEYMAP_LOADED 2 // 'keymap' mappings have been loaded garray_T b_kmap_ga; // the keymap table - /* - * Options local to a buffer. - * They are here because their value depends on the type of file - * or contents of the file being edited. - */ + // Options local to a buffer. + // They are here because their value depends on the type of file + // or contents of the file being edited. bool b_p_initialized; // set when options initialized LastSet b_p_script_ctx[BV_COUNT]; // SCTXs for buffer-local options @@ -834,19 +798,17 @@ struct file_buffer { ScopeDictDictItem b_bufvar; ///< Variable for "b:" Dictionary. dict_T *b_vars; ///< b: scope dictionary. - /* When a buffer is created, it starts without a swap file. b_may_swap is - * then set to indicate that a swap file may be opened later. It is reset - * if a swap file could not be opened. - */ + // When a buffer is created, it starts without a swap file. b_may_swap is + // then set to indicate that a swap file may be opened later. It is reset + // if a swap file could not be opened. bool b_may_swap; bool b_did_warn; /* Set to true if user has been warned on first change of a read-only file */ - /* Two special kinds of buffers: - * help buffer - used for help files, won't use a swap file. - * spell buffer - used for spell info, never displayed and doesn't have a - * file name. - */ + // Two special kinds of buffers: + // help buffer - used for help files, won't use a swap file. + // spell buffer - used for spell info, never displayed and doesn't have a + // file name. bool b_help; // true for help file buffer (when set b_p_bt // is "help") bool b_spell; // True for a spell file buffer, most fields @@ -906,25 +868,21 @@ struct file_buffer { int b_diff_failed; // internal diff failed for this buffer }; -/* - * Stuff for diff mode. - */ +// Stuff for diff mode. #define DB_COUNT 8 // up to four buffers can be diff'ed -/* - * Each diffblock defines where a block of lines starts in each of the buffers - * and how many lines it occupies in that buffer. When the lines are missing - * in the buffer the df_count[] is zero. This is all counted in - * buffer lines. - * There is always at least one unchanged line in between the diffs. - * Otherwise it would have been included in the diff above or below it. - * df_lnum[] + df_count[] is the lnum below the change. When in one buffer - * lines have been inserted, in the other buffer df_lnum[] is the line below - * the insertion and df_count[] is zero. When appending lines at the end of - * the buffer, df_lnum[] is one beyond the end! - * This is using a linked list, because the number of differences is expected - * to be reasonable small. The list is sorted on lnum. - */ +// Each diffblock defines where a block of lines starts in each of the buffers +// and how many lines it occupies in that buffer. When the lines are missing +// in the buffer the df_count[] is zero. This is all counted in +// buffer lines. +// There is always at least one unchanged line in between the diffs. +// Otherwise it would have been included in the diff above or below it. +// df_lnum[] + df_count[] is the lnum below the change. When in one buffer +// lines have been inserted, in the other buffer df_lnum[] is the line below +// the insertion and df_count[] is zero. When appending lines at the end of +// the buffer, df_lnum[] is one beyond the end! +// This is using a linked list, because the number of differences is expected +// to be reasonable small. The list is sorted on lnum. typedef struct diffblock_S diff_T; struct diffblock_S { diff_T *df_next; @@ -964,18 +922,16 @@ struct tabpage_S { char *tp_prevdir; ///< Previous directory. }; -/* - * Structure to cache info for displayed lines in w_lines[]. - * Each logical line has one entry. - * The entry tells how the logical line is currently displayed in the window. - * This is updated when displaying the window. - * When the display is changed (e.g., when clearing the screen) w_lines_valid - * is changed to exclude invalid entries. - * When making changes to the buffer, wl_valid is reset to indicate wl_size - * may not reflect what is actually in the buffer. When wl_valid is false, - * the entries can only be used to count the number of displayed lines used. - * wl_lnum and wl_lastlnum are invalid too. - */ +// Structure to cache info for displayed lines in w_lines[]. +// Each logical line has one entry. +// The entry tells how the logical line is currently displayed in the window. +// This is updated when displaying the window. +// When the display is changed (e.g., when clearing the screen) w_lines_valid +// is changed to exclude invalid entries. +// When making changes to the buffer, wl_valid is reset to indicate wl_size +// may not reflect what is actually in the buffer. When wl_valid is false, +// the entries can only be used to count the number of displayed lines used. +// wl_lnum and wl_lastlnum are invalid too. typedef struct w_line { linenr_T wl_lnum; // buffer line number for logical line uint16_t wl_size; // height in screen lines @@ -984,10 +940,8 @@ typedef struct w_line { linenr_T wl_lastlnum; // last buffer line number for logical line } wline_T; -/* - * Windows are kept in a tree of frames. Each frame has a column (FR_COL) - * or row (FR_ROW) layout or is a leaf, which has a window. - */ +// Windows are kept in a tree of frames. Each frame has a column (FR_COL) +// or row (FR_ROW) layout or is a leaf, which has a window. struct frame_S { char fr_layout; // FR_LEAF, FR_COL or FR_ROW int fr_width; @@ -1008,12 +962,10 @@ struct frame_S { #define FR_ROW 1 // frame with a row of windows #define FR_COL 2 // frame with a column of windows -/* - * Struct used for highlighting 'hlsearch' matches, matches defined by - * ":match" and matches defined by match functions. - * For 'hlsearch' there is one pattern for all windows. For ":match" and the - * match functions there is a different pattern for each window. - */ +// Struct used for highlighting 'hlsearch' matches, matches defined by +// ":match" and matches defined by match functions. +// For 'hlsearch' there is one pattern for all windows. For ":match" and the +// match functions there is a different pattern for each window. typedef struct { regmmatch_T rm; // points to the regexp program; contains last found // match (may continue in next line) @@ -1049,10 +1001,8 @@ struct posmatch { linenr_T botlnum; ///< bottom buffer line }; -/* - * matchitem_T provides a linked list for storing match items for ":match" and - * the match functions. - */ +// matchitem_T provides a linked list for storing match items for ":match" and +// the match functions. typedef struct matchitem matchitem_T; struct matchitem { matchitem_T *next; @@ -1221,12 +1171,10 @@ struct window_S { int eob; } w_p_fcs_chars; - /* - * "w_topline", "w_leftcol" and "w_skipcol" specify the offsets for - * displaying the buffer. - */ - linenr_T w_topline; /* buffer line number of the line at the - top of the window */ + // "w_topline", "w_leftcol" and "w_skipcol" specify the offsets for + // displaying the buffer. + linenr_T w_topline; // buffer line number of the line at the + // top of the window char w_topline_was_set; // flag set to true when topline is set, // e.g. by winrestview() int w_topfill; // number of filler lines above w_topline @@ -1279,15 +1227,12 @@ struct window_S { int w_height_outer; int w_width_outer; - /* - * === start of cached values ==== - */ - /* - * Recomputing is minimized by storing the result of computations. - * Use functions in screen.c to check if they are valid and to update. - * w_valid is a bitfield of flags, which indicate if specific values are - * valid or need to be recomputed. - */ + // === start of cached values ==== + + // Recomputing is minimized by storing the result of computations. + // Use functions in screen.c to check if they are valid and to update. + // w_valid is a bitfield of flags, which indicate if specific values are + // valid or need to be recomputed. int w_valid; pos_T w_valid_cursor; /* last known position of w_cursor, used to adjust w_valid */ @@ -1295,10 +1240,8 @@ struct window_S { bool w_viewport_invalid; - /* - * w_cline_height is the number of physical lines taken by the buffer line - * that the cursor is on. We use this to avoid extra calls to plines_win(). - */ + // w_cline_height is the number of physical lines taken by the buffer line + // that the cursor is on. We use this to avoid extra calls to plines_win(). int w_cline_height; // current size of cursor line bool w_cline_folded; // cursor line is folded @@ -1311,11 +1254,9 @@ struct window_S { // more than one screen line or when // w_leftcol is non-zero - /* - * w_wrow and w_wcol specify the cursor position in the window. - * This is related to positions in the window, not in the display or - * buffer, thus w_wrow is relative to w_winrow. - */ + // w_wrow and w_wcol specify the cursor position in the window. + // This is related to positions in the window, not in the display or + // buffer, thus w_wrow is relative to w_winrow. int w_wrow, w_wcol; // cursor position in window linenr_T w_botline; // number of the line below the bottom of @@ -1324,16 +1265,14 @@ struct window_S { int w_filler_rows; // number of filler rows at the end of the // window - /* - * Info about the lines currently in the window is remembered to avoid - * recomputing it every time. The allocated size of w_lines[] is Rows. - * Only the w_lines_valid entries are actually valid. - * When the display is up-to-date w_lines[0].wl_lnum is equal to w_topline - * and w_lines[w_lines_valid - 1].wl_lnum is equal to w_botline. - * Between changing text and updating the display w_lines[] represents - * what is currently displayed. wl_valid is reset to indicated this. - * This is used for efficient redrawing. - */ + // Info about the lines currently in the window is remembered to avoid + // recomputing it every time. The allocated size of w_lines[] is Rows. + // Only the w_lines_valid entries are actually valid. + // When the display is up-to-date w_lines[0].wl_lnum is equal to w_topline + // and w_lines[w_lines_valid - 1].wl_lnum is equal to w_botline. + // Between changing text and updating the display w_lines[] represents + // what is currently displayed. wl_valid is reset to indicated this. + // This is used for efficient redrawing. int w_lines_valid; // number of valid entries wline_T *w_lines; @@ -1346,9 +1285,7 @@ struct window_S { // column being used int w_scwidth; // width of 'signcolumn' - /* - * === end of cached values === - */ + // === end of cached values === int w_redr_type; // type of redraw to be performed on win int w_upd_rows; // number of window lines to update when @@ -1406,17 +1343,13 @@ struct window_S { ScopeDictDictItem w_winvar; ///< Variable for "w:" dictionary. dict_T *w_vars; ///< Dictionary with w: variables. - /* - * The w_prev_pcmark field is used to check whether we really did jump to - * a new line after setting the w_pcmark. If not, then we revert to - * using the previous w_pcmark. - */ + // The w_prev_pcmark field is used to check whether we really did jump to + // a new line after setting the w_pcmark. If not, then we revert to + // using the previous w_pcmark. pos_T w_pcmark; // previous context mark pos_T w_prev_pcmark; // previous w_pcmark - /* - * the jumplist contains old cursor positions - */ + // the jumplist contains old cursor positions xfmark_T w_jumplist[JUMPLISTSIZE]; int w_jumplistlen; // number of active entries int w_jumplistidx; // current position @@ -1426,12 +1359,10 @@ struct window_S { matchitem_T *w_match_head; // head of match list int w_next_match_id; // next match ID - /* - * the tagstack grows from 0 upwards: - * entry 0: older - * entry 1: newer - * entry 2: newest - */ + // the tagstack grows from 0 upwards: + // entry 0: older + // entry 1: newer + // entry 2: newest taggy_T w_tagstack[TAGSTACKSIZE]; // the tag stack int w_tagstackidx; // idx just below active entry int w_tagstacklen; // number of tags on stack @@ -1442,12 +1373,10 @@ struct window_S { bool w_floating; ///< whether the window is floating FloatConfig w_float_config; - /* - * w_fraction is the fractional row of the cursor within the window, from - * 0 at the top row to FRACTION_MULT at the last row. - * w_prev_fraction_row was the actual cursor row when w_fraction was last - * calculated. - */ + // w_fraction is the fractional row of the cursor within the window, from + // 0 at the top row to FRACTION_MULT at the last row. + // w_prev_fraction_row was the actual cursor row when w_fraction was last + // calculated. int w_fraction; int w_prev_fraction_row; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index eac184c096..b85d349726 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1,9 +1,7 @@ // 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 -/* - * edit.c: functions for Insert mode - */ +// edit.c: functions for Insert mode #include #include @@ -1359,9 +1357,7 @@ void ins_redraw(bool ready) emsg_on_display = false; // may remove error message now } -/* - * Handle a CTRL-V or CTRL-Q typed in Insert mode. - */ +// Handle a CTRL-V or CTRL-Q typed in Insert mode. static void ins_ctrl_v(void) { int c; @@ -1391,10 +1387,8 @@ static void ins_ctrl_v(void) revins_legal++; } -/* - * Put a character directly onto the screen. It's not stored in a buffer. - * Used while handling CTRL-K, CTRL-V, etc. in Insert mode. - */ +// Put a character directly onto the screen. It's not stored in a buffer. +// Used while handling CTRL-K, CTRL-V, etc. in Insert mode. static int pc_status; #define PC_STATUS_UNSET 0 // pc_bytes was not set #define PC_STATUS_RIGHT 1 // right half of double-wide char @@ -1511,9 +1505,7 @@ bool prompt_curpos_editable(void) && curwin->w_cursor.col >= (int)STRLEN(prompt_text()); } -/* - * Undo the previous edit_putchar(). - */ +// Undo the previous edit_putchar(). void edit_unputchar(void) { if (pc_status != PC_STATUS_UNSET && pc_row >= msg_scrolled) { @@ -1528,10 +1520,8 @@ void edit_unputchar(void) } } -/* - * Called when p_dollar is set: display a '$' at the end of the changed text - * Only works when cursor is in the line that changes. - */ +// Called when p_dollar is set: display a '$' at the end of the changed text +// Only works when cursor is in the line that changes. void display_dollar(colnr_T col) { colnr_T save_col; @@ -1554,10 +1544,8 @@ void display_dollar(colnr_T col) curwin->w_cursor.col = save_col; } -/* - * Call this function before moving the cursor from the normal insert position - * in insert mode. - */ +// Call this function before moving the cursor from the normal insert position +// in insert mode. void undisplay_dollar(void) { if (dollar_vcol >= 0) { @@ -1600,11 +1588,9 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang vc = getvcol_nolist(&curwin->w_cursor); vcol = vc; - /* - * For Replace mode we need to fix the replace stack later, which is only - * possible when the cursor is in the indent. Remember the number of - * characters before the cursor if it's possible. - */ + // For Replace mode we need to fix the replace stack later, which is only + // possible when the cursor is in the indent. Remember the number of + // characters before the cursor if it's possible. start_col = curwin->w_cursor.col; // determine offset from first non-blank @@ -1614,10 +1600,8 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang insstart_less = curwin->w_cursor.col; - /* - * If the cursor is in the indent, compute how many screen columns the - * cursor is to the left of the first non-blank. - */ + // If the cursor is in the indent, compute how many screen columns the + // cursor is to the left of the first non-blank. if (new_cursor_col < 0) { vcol = get_indent() - vcol; } @@ -1626,9 +1610,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang start_col = -1; } - /* - * Set the new indent. The cursor will be put on the first non-blank. - */ + // Set the new indent. The cursor will be put on the first non-blank. if (type == INDENT_SET) { (void)set_indent(amount, call_changed_bytes ? SIN_CHANGED : 0); } else { @@ -1643,20 +1625,16 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang } insstart_less -= curwin->w_cursor.col; - /* - * Try to put cursor on same character. - * If the cursor is at or after the first non-blank in the line, - * compute the cursor column relative to the column of the first - * non-blank character. - * If we are not in insert mode, leave the cursor on the first non-blank. - * If the cursor is before the first non-blank, position it relative - * to the first non-blank, counted in screen columns. - */ + // Try to put cursor on same character. + // If the cursor is at or after the first non-blank in the line, + // compute the cursor column relative to the column of the first + // non-blank character. + // If we are not in insert mode, leave the cursor on the first non-blank. + // If the cursor is before the first non-blank, position it relative + // to the first non-blank, counted in screen columns. if (new_cursor_col >= 0) { - /* - * When changing the indent while the cursor is touching it, reset - * Insstart_col to 0. - */ + // When changing the indent while the cursor is touching it, reset + // Insstart_col to 0. if (new_cursor_col == 0) { insstart_less = MAXCOL; } @@ -1687,10 +1665,8 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang new_cursor_col = (int)(cts.cts_ptr - cts.cts_line); clear_chartabsize_arg(&cts); - /* - * May need to insert spaces to be able to position the cursor on - * the right screen column. - */ + // May need to insert spaces to be able to position the cursor on + // the right screen column. if (vcol != (int)curwin->w_virtcol) { curwin->w_cursor.col = (colnr_T)new_cursor_col; size_t i = (size_t)(curwin->w_virtcol - vcol); @@ -1701,10 +1677,8 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang xfree(ptr); } - /* - * When changing the indent while the cursor is in it, reset - * Insstart_col to 0. - */ + // When changing the indent while the cursor is in it, reset + // Insstart_col to 0. insstart_less = MAXCOL; } @@ -1718,9 +1692,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang curwin->w_set_curswant = true; changed_cline_bef_curs(); - /* - * May have to adjust the start of the insert. - */ + // May have to adjust the start of the insert. if (State & MODE_INSERT) { if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0) { if ((int)Insstart.col <= insstart_less) { @@ -1998,15 +1970,13 @@ static void insert_special(int c, int allow_modmask, int ctrlv) } } -/* - * Special characters in this context are those that need processing other - * than the simple insertion that can be performed here. This includes ESC - * which terminates the insert, and CR/NL which need special processing to - * open up a new line. This routine tries to optimize insertions performed by - * the "redo", "undo" or "put" commands, so it needs to know when it should - * stop and defer processing to the "normal" mechanism. - * '0' and '^' are special, because they can be followed by CTRL-D. - */ +// Special characters in this context are those that need processing other +// than the simple insertion that can be performed here. This includes ESC +// which terminates the insert, and CR/NL which need special processing to +// open up a new line. This routine tries to optimize insertions performed by +// the "redo", "undo" or "put" commands, so it needs to know when it should +// stop and defer processing to the "normal" mechanism. +// '0' and '^' are special, because they can be followed by CTRL-D. #define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^') /// @@ -2207,9 +2177,7 @@ void insertchar(int c, int flags, int second_indent) } } -/* - * Put a character in the redo buffer, for when just after a CTRL-V. - */ +// Put a character in the redo buffer, for when just after a CTRL-V. static void redo_literal(int c) { char buf[10]; @@ -2259,10 +2227,8 @@ static void start_arrow_common(pos_T *end_insert_pos, bool end_change) check_spell_redraw(); } -/* - * If we skipped highlighting word at cursor, do it now. - * It may be skipped again, thus reset spell_redraw_lnum first. - */ +// If we skipped highlighting word at cursor, do it now. +// It may be skipped again, thus reset spell_redraw_lnum first. static void check_spell_redraw(void) { if (spell_redraw_lnum != 0) { @@ -2273,11 +2239,9 @@ static void check_spell_redraw(void) } } -/* - * stop_arrow() is called before a change is made in insert mode. - * If an arrow key has been used, start a new insertion. - * Returns FAIL if undo is impossible, shouldn't insert then. - */ +// stop_arrow() is called before a change is made in insert mode. +// If an arrow key has been used, start a new insertion. +// Returns FAIL if undo is impossible, shouldn't insert then. int stop_arrow(void) { if (arrow_used) { @@ -2327,11 +2291,9 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove) stop_redo_ins(); replace_flush(); // abandon replace stack - /* - * Save the inserted text for later redo with ^@ and CTRL-A. - * Don't do it when "restart_edit" was set and nothing was inserted, - * otherwise CTRL-O w and then will clear "last_insert". - */ + // Save the inserted text for later redo with ^@ and CTRL-A. + // Don't do it when "restart_edit" was set and nothing was inserted, + // otherwise CTRL-O w and then will clear "last_insert". ptr = get_inserted(); if (did_restart_edit == 0 || (ptr != NULL && (int)STRLEN(ptr) > new_insert_skip)) { @@ -2438,10 +2400,8 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove) } } -/* - * Set the last inserted text to a single character. - * Used for the replace command. - */ +// Set the last inserted text to a single character. +// Used for the replace command. void set_last_insert(int c) { char_u *s; @@ -2466,13 +2426,11 @@ void free_last_insert(void) } #endif -/* - * move cursor to start of line - * if flags & BL_WHITE move to first non-white - * if flags & BL_SOL move to first non-white if startofline is set, - * otherwise keep "curswant" column - * if flags & BL_FIX don't leave the cursor on a NUL. - */ +// move cursor to start of line +// if flags & BL_WHITE move to first non-white +// if flags & BL_SOL move to first non-white if startofline is set, +// otherwise keep "curswant" column +// if flags & BL_FIX don't leave the cursor on a NUL. void beginline(int flags) { if ((flags & BL_SOL) && !p_sol) { @@ -2493,13 +2451,11 @@ void beginline(int flags) } } -/* - * oneright oneleft cursor_down cursor_up - * - * Move one char {right,left,down,up}. - * Doesn't move onto the NUL past the end of the line, unless it is allowed. - * Return OK when successful, FAIL when we hit a line of file boundary. - */ +// oneright oneleft cursor_down cursor_up +// +// Move one char {right,left,down,up}. +// Doesn't move onto the NUL past the end of the line, unless it is allowed. +// Return OK when successful, FAIL when we hit a line of file boundary. int oneright(void) { @@ -2600,9 +2556,8 @@ int cursor_up(long n, int upd_topline) if (n >= lnum) { lnum = 1; } else if (hasAnyFolding(curwin)) { - /* - * Count each sequence of folded lines as one logical line. - */ + // Count each sequence of folded lines as one logical line. + // go to the start of the current fold (void)hasFolding(lnum, &lnum, NULL); @@ -2761,10 +2716,8 @@ char_u *get_last_insert(void) return last_insert + last_insert_skip; } -/* - * Get last inserted string, and remove trailing . - * Returns pointer to allocated memory (must be freed) or NULL. - */ +// Get last inserted string, and remove trailing . +// Returns pointer to allocated memory (must be freed) or NULL. char_u *get_last_insert_save(void) { char_u *s; @@ -2803,20 +2756,18 @@ static bool echeck_abbr(int c) curwin->w_cursor.lnum == Insstart.lnum ? Insstart.col : 0); } -/* - * replace-stack functions - * - * When replacing characters, the replaced characters are remembered for each - * new character. This is used to re-insert the old text when backspacing. - * - * There is a NUL headed list of characters for each character that is - * currently in the file after the insertion point. When BS is used, one NUL - * headed list is put back for the deleted character. - * - * For a newline, there are two NUL headed lists. One contains the characters - * that the NL replaced. The extra one stores the characters after the cursor - * that were deleted (always white space). - */ +// replace-stack functions +// +// When replacing characters, the replaced characters are remembered for each +// new character. This is used to re-insert the old text when backspacing. +// +// There is a NUL headed list of characters for each character that is +// currently in the file after the insertion point. When BS is used, one NUL +// headed list is put back for the deleted character. +// +// For a newline, there are two NUL headed lists. One contains the characters +// that the NL replaced. The extra one stores the characters after the cursor +// that were deleted (always white space). static char_u *replace_stack = NULL; static ssize_t replace_stack_nr = 0; // next entry in replace stack @@ -2901,10 +2852,8 @@ static void replace_pop_ins(void) State = oldState; } -/* - * Insert bytes popped from the replace stack. "cc" is the first byte. If it - * indicates a multi-byte char, pop the other bytes too. - */ +// Insert bytes popped from the replace stack. "cc" is the first byte. If it +// indicates a multi-byte char, pop the other bytes too. static void mb_replace_pop_ins(int cc) { int n; @@ -2951,10 +2900,8 @@ static void mb_replace_pop_ins(int cc) } } -/* - * make the replace stack empty - * (called when exiting replace mode) - */ +// make the replace stack empty +// (called when exiting replace mode) static void replace_flush(void) { XFREE_CLEAR(replace_stack); @@ -2962,15 +2909,13 @@ static void replace_flush(void) replace_stack_nr = 0; } -/* - * Handle doing a BS for one character. - * cc < 0: replace stack empty, just move cursor - * cc == 0: character was inserted, delete it - * cc > 0: character was replaced, put cc (first byte of original char) back - * and check for more characters to be put back - * When "limit_col" is >= 0, don't delete before this column. Matters when - * using composing characters, use del_char_after_col() instead of del_char(). - */ +// Handle doing a BS for one character. +// cc < 0: replace stack empty, just move cursor +// cc == 0: character was inserted, delete it +// cc > 0: character was replaced, put cc (first byte of original char) back +// and check for more characters to be put back +// When "limit_col" is >= 0, don't delete before this column. Matters when +// using composing characters, use del_char_after_col() instead of del_char(). static void replace_do_bs(int limit_col) { int cc; @@ -3033,12 +2978,10 @@ bool cindent_on(void) return !p_paste && (curbuf->b_p_cin || *curbuf->b_p_inde != NUL); } -/* - * Re-indent the current line, based on the current contents of it and the - * surrounding lines. Fixing the cursor position seems really easy -- I'm very - * confused what all the part that handles Control-T is doing that I'm not. - * "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent. - */ +// Re-indent the current line, based on the current contents of it and the +// surrounding lines. Fixing the cursor position seems really easy -- I'm very +// confused what all the part that handles Control-T is doing that I'm not. +// "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent. void fixthisline(IndentGetter get_the_indent) { int amount = get_the_indent(); @@ -3096,10 +3039,8 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) look = (char_u *)curbuf->b_p_cink; // 'indentexpr' empty: use 'cinkeys' } while (*look) { - /* - * Find out if we want to try a match with this key, depending on - * 'when' and a '*' or '!' before the key. - */ + // Find out if we want to try a match with this key, depending on + // 'when' and a '*' or '!' before the key. switch (when) { case '*': try_match = (*look == '*'); break; @@ -3286,9 +3227,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) return false; } -/* - * Map Hebrew keyboard when in hkmap mode. - */ +// Map Hebrew keyboard when in hkmap mode. int hkmap(int c) FUNC_ATTR_PURE { @@ -3390,9 +3329,7 @@ static void ins_reg(void) int literally = 0; int vis_active = VIsual_active; - /* - * If we are going to wait for a character, show a '"'. - */ + // If we are going to wait for a character, show a '"'. pc_status = PC_STATUS_UNSET; if (redrawing() && !char_avail()) { // may need to redraw when no more chars available now @@ -3474,9 +3411,7 @@ static void ins_reg(void) } } -/* - * CTRL-G commands in Insert mode. - */ +// CTRL-G commands in Insert mode. static void ins_ctrl_g(void) { int c; @@ -3530,9 +3465,7 @@ static void ins_ctrl_g(void) } } -/* - * CTRL-^ in Insert mode. - */ +// CTRL-^ in Insert mode. static void ins_ctrl_hat(void) { if (map_to_exists_mode("", MODE_LANGMAP, false)) { @@ -3576,10 +3509,8 @@ static bool ins_esc(long *count, int cmdchar, bool nomove) AppendToRedobuff(ESC_STR); } - /* - * Repeating insert may take a long time. Check for - * interrupt now and then. - */ + // Repeating insert may take a long time. Check for + // interrupt now and then. if (*count > 0) { line_breakcheck(); if (got_int) { @@ -3622,10 +3553,8 @@ static bool ins_esc(long *count, int cmdchar, bool nomove) RESET_FMARK(&curbuf->b_last_insert, curwin->w_cursor, curbuf->b_fnum, view); } - /* - * The cursor should end up on the last inserted character. - * Don't do it for CTRL-O, unless past the end of the line. - */ + // The cursor should end up on the last inserted character. + // Don't do it for CTRL-O, unless past the end of the line. if (!nomove && (curwin->w_cursor.col != 0 || curwin->w_cursor.coladd > 0) && (restart_edit == NUL || (gchar_cursor() == NUL && !VIsual_active)) @@ -3663,10 +3592,8 @@ static bool ins_esc(long *count, int cmdchar, bool nomove) return true; } -/* - * Toggle language: hkmap and revins_on. - * Move to end of reverse inserted text. - */ +// Toggle language: hkmap and revins_on. +// Move to end of reverse inserted text. static void ins_ctrl_(void) { if (revins_on && revins_chars && revins_scol >= 0) { @@ -3733,9 +3660,7 @@ static bool ins_start_select(int c) return false; } -/* - * key in Insert mode: toggle insert/replace mode. - */ +// key in Insert mode: toggle insert/replace mode. static void ins_insert(int replaceState) { set_vim_var_string(VV_INSERTMODE, ((State & REPLACE_FLAG) ? "i" : @@ -3753,9 +3678,7 @@ static void ins_insert(int replaceState) ui_cursor_shape(); // may show different cursor shape } -/* - * Pressed CTRL-O in Insert mode. - */ +// Pressed CTRL-O in Insert mode. static void ins_ctrl_o(void) { if (State & VREPLACE_FLAG) { @@ -3772,13 +3695,11 @@ static void ins_ctrl_o(void) } } -/* - * If the cursor is on an indent, ^T/^D insert/delete one - * shiftwidth. Otherwise ^T/^D behave like a "<<" or ">>". - * Always round the indent to 'shiftwidth', this is compatible - * with vi. But vi only supports ^T and ^D after an - * autoindent, we support it everywhere. - */ +// If the cursor is on an indent, ^T/^D insert/delete one +// shiftwidth. Otherwise ^T/^D behave like a "<<" or ">>". +// Always round the indent to 'shiftwidth', this is compatible +// with vi. But vi only supports ^T and ^D after an +// autoindent, we support it everywhere. static void ins_shift(int c, int lastc) { if (stop_arrow() == FAIL) { @@ -3786,9 +3707,7 @@ static void ins_shift(int c, int lastc) } AppendCharToRedobuff(c); - /* - * 0^D and ^^D: remove all indent. - */ + // 0^D and ^^D: remove all indent. if (c == Ctrl_D && (lastc == '0' || lastc == '^') && curwin->w_cursor.col > 0) { curwin->w_cursor.col--; @@ -3844,9 +3763,7 @@ static void ins_del(void) AppendCharToRedobuff(K_DEL); } -/* - * Delete one character for ins_bs(). - */ +// Delete one character for ins_bs(). static void ins_bs_one(colnr_T *vcolp) { dec_cursor(); @@ -3941,11 +3858,9 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) Insstart.lnum--; Insstart.col = (colnr_T)STRLEN(ml_get(Insstart.lnum)); } - /* - * In replace mode: - * cc < 0: NL was inserted, delete it - * cc >= 0: NL was replaced, put original characters back - */ + // In replace mode: + // cc < 0: NL was inserted, delete it + // cc >= 0: NL was replaced, put original characters back cc = -1; if (State & REPLACE_FLAG) { cc = replace_pop(); // returns -1 if NL was inserted @@ -4025,9 +3940,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) curwin->w_cursor.col = save_col; } - /* - * Handle deleting one 'shiftwidth' or 'softtabstop'. - */ + // Handle deleting one 'shiftwidth' or 'softtabstop'. if (mode == BACKSPACE_CHAR && ((p_sta && in_indent) || ((get_sts_value() != 0 @@ -4589,9 +4502,7 @@ static bool ins_tab(void) } } - /* - * When 'expandtab' not set: Replace spaces by TABs where possible. - */ + // When 'expandtab' not set: Replace spaces by TABs where possible. if (!curbuf->b_p_et && (tabstop_count(curbuf->b_p_vsts_array) > 0 || get_sts_value() > 0 || (p_sta && ind))) { @@ -4742,11 +4653,9 @@ bool ins_eol(int c) } undisplay_dollar(); - /* - * Strange Vi behaviour: In Replace mode, typing a NL will not delete the - * character under the cursor. Only push a NUL on the replace stack, - * nothing to put back when the NL is deleted. - */ + // Strange Vi behaviour: In Replace mode, typing a NL will not delete the + // character under the cursor. Only push a NUL on the replace stack, + // nothing to put back when the NL is deleted. if ((State & REPLACE_FLAG) && !(State & VREPLACE_FLAG)) { replace_push(NUL); @@ -4780,11 +4689,9 @@ bool ins_eol(int c) return i; } -/* - * Handle digraph in insert mode. - * Returns character still to be inserted, or NUL when nothing remaining to be - * done. - */ +// Handle digraph in insert mode. +// Returns character still to be inserted, or NUL when nothing remaining to be +// done. static int ins_digraph(void) { int c; @@ -4853,10 +4760,8 @@ static int ins_digraph(void) return NUL; } -/* - * Handle CTRL-E and CTRL-Y in Insert mode: copy char from other line. - * Returns the char to be inserted, or NUL if none found. - */ +// Handle CTRL-E and CTRL-Y in Insert mode: copy char from other line. +// Returns the char to be inserted, or NUL if none found. int ins_copychar(linenr_T lnum) { int c; @@ -4894,9 +4799,7 @@ int ins_copychar(linenr_T lnum) return c; } -/* - * CTRL-Y or CTRL-E typed in Insert mode. - */ +// CTRL-Y or CTRL-E typed in Insert mode. static int ins_ctrl_ey(int tc) { int c = tc; @@ -4933,10 +4836,8 @@ static int ins_ctrl_ey(int tc) return c; } -/* - * Try to do some very smart auto-indenting. - * Used when inserting a "normal" character. - */ +// Try to do some very smart auto-indenting. +// Used when inserting a "normal" character. static void ins_try_si(int c) { pos_T *pos, old_pos; @@ -4944,20 +4845,16 @@ static void ins_try_si(int c) int i; bool temp; - /* - * do some very smart indenting when entering '{' or '}' - */ + // do some very smart indenting when entering '{' or '}' if (((did_si || can_si_back) && c == '{') || (can_si && c == '}' && inindent(0))) { // for '}' set indent equal to indent of line containing matching '{' if (c == '}' && (pos = findmatch(NULL, '{')) != NULL) { old_pos = curwin->w_cursor; - /* - * If the matching '{' has a ')' immediately before it (ignoring - * white-space), then line up with the start of the line - * containing the matching '(' if there is one. This handles the - * case where an "if (..\n..) {" statement continues over multiple - * lines -- webb - */ + // If the matching '{' has a ')' immediately before it (ignoring + // white-space), then line up with the start of the line + // containing the matching '(' if there is one. This handles the + // case where an "if (..\n..) {" statement continues over multiple + // lines -- webb ptr = (char_u *)ml_get(pos->lnum); i = pos->col; if (i > 0) { // skip blanks before '{' @@ -5001,9 +4898,7 @@ static void ins_try_si(int c) } } - /* - * set indent of '#' always to 0 - */ + // set indent of '#' always to 0 if (curwin->w_cursor.col > 0 && can_si && c == '#' && inindent(0)) { // remember current indent for next line old_indent = get_indent(); @@ -5016,10 +4911,8 @@ static void ins_try_si(int c) } } -/* - * Get the value that w_virtcol would have when 'list' is off. - * Unless 'cpo' contains the 'L' flag. - */ +// Get the value that w_virtcol would have when 'list' is off. +// Unless 'cpo' contains the 'L' flag. colnr_T get_nolist_virtcol(void) { // check validity of cursor in current buffer @@ -5034,12 +4927,10 @@ colnr_T get_nolist_virtcol(void) return curwin->w_virtcol; } -/* - * Handle the InsertCharPre autocommand. - * "c" is the character that was typed. - * Return a pointer to allocated memory with the replacement string. - * Return NULL to continue inserting "c". - */ +// Handle the InsertCharPre autocommand. +// "c" is the character that was typed. +// Return a pointer to allocated memory with the replacement string. +// Return NULL to continue inserting "c". static char_u *do_insert_char_pre(int c) { char buf[MB_MAXBYTES + 1]; diff --git a/src/nvim/eval.h b/src/nvim/eval.h index b0cb5fd8c1..afebdf5acb 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -11,33 +11,31 @@ #define COPYID_INC 2 #define COPYID_MASK (~0x1) -/* - * Structure returned by get_lval() and used by set_var_lval(). - * For a plain name: - * "name" points to the variable name. - * "exp_name" is NULL. - * "tv" is NULL - * For a magic braces name: - * "name" points to the expanded variable name. - * "exp_name" is non-NULL, to be freed later. - * "tv" is NULL - * For an index in a list: - * "name" points to the (expanded) variable name. - * "exp_name" NULL or non-NULL, to be freed later. - * "tv" points to the (first) list item value - * "li" points to the (first) list item - * "range", "n1", "n2" and "empty2" indicate what items are used. - * For an existing Dict item: - * "name" points to the (expanded) variable name. - * "exp_name" NULL or non-NULL, to be freed later. - * "tv" points to the dict item value - * "newkey" is NULL - * For a non-existing Dict item: - * "name" points to the (expanded) variable name. - * "exp_name" NULL or non-NULL, to be freed later. - * "tv" points to the Dictionary typval_T - * "newkey" is the key for the new item. - */ +// Structure returned by get_lval() and used by set_var_lval(). +// For a plain name: +// "name" points to the variable name. +// "exp_name" is NULL. +// "tv" is NULL +// For a magic braces name: +// "name" points to the expanded variable name. +// "exp_name" is non-NULL, to be freed later. +// "tv" is NULL +// For an index in a list: +// "name" points to the (expanded) variable name. +// "exp_name" NULL or non-NULL, to be freed later. +// "tv" points to the (first) list item value +// "li" points to the (first) list item +// "range", "n1", "n2" and "empty2" indicate what items are used. +// For an existing Dict item: +// "name" points to the (expanded) variable name. +// "exp_name" NULL or non-NULL, to be freed later. +// "tv" points to the dict item value +// "newkey" is NULL +// For a non-existing Dict item: +// "name" points to the (expanded) variable name. +// "exp_name" NULL or non-NULL, to be freed later. +// "tv" points to the Dictionary typval_T +// "newkey" is the key for the new item. typedef struct lval_S { const char *ll_name; ///< Start of variable name (can be NULL). size_t ll_name_len; ///< Length of the .ll_name. diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 6611133ea4..3ab66c319f 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1576,16 +1576,14 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t // Find the function name in the table, call its implementation. error = call_internal_func((char_u *)fname, argcount, argvars, rettv); } - /* - * The function call (or "FuncUndefined" autocommand sequence) might - * have been aborted by an error, an interrupt, or an explicitly thrown - * exception that has not been caught so far. This situation can be - * tested for by calling aborting(). For an error in an internal - * function or for the "E132" error in call_user_func(), however, the - * throw point at which the "force_abort" flag (temporarily reset by - * emsg()) is normally updated has not been reached yet. We need to - * update that flag first to make aborting() reliable. - */ + // The function call (or "FuncUndefined" autocommand sequence) might + // have been aborted by an error, an interrupt, or an explicitly thrown + // exception that has not been caught so far. This situation can be + // tested for by calling aborting(). For an error in an internal + // function or for the "E132" error in call_user_func(), however, the + // throw point at which the "force_abort" flag (temporarily reset by + // emsg()) is normally updated has not been reached yet. We need to + // update that flag first to make aborting() reliable. update_force_abort(); } if (error == ERROR_NONE) { @@ -1720,11 +1718,9 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa goto theend; } if (end == NULL || (lv.ll_tv != NULL && (lead > 2 || lv.ll_range))) { - /* - * Report an invalid expression in braces, unless the expression - * evaluation has been cancelled due to an aborting error, an - * interrupt, or an exception. - */ + // Report an invalid expression in braces, unless the expression + // evaluation has been cancelled due to an aborting error, an + // interrupt, or an exception. if (!aborting()) { if (end != NULL) { semsg(_(e_invarg2), start); @@ -1923,9 +1919,7 @@ void ex_function(exarg_T *eap) bool show_block = false; bool do_concat = true; - /* - * ":function" without argument: list functions. - */ + // ":function" without argument: list functions. if (ends_excmd(*eap->arg)) { if (!eap->skip) { todo = (int)func_hashtab.ht_used; @@ -1946,9 +1940,7 @@ void ex_function(exarg_T *eap) return; } - /* - * ":function /pat": list functions matching pattern. - */ + // ":function /pat": list functions matching pattern. if (*eap->arg == '/') { p = skip_regexp(eap->arg + 1, '/', true, NULL); if (!eap->skip) { @@ -2000,11 +1992,9 @@ void ex_function(exarg_T *eap) name = (char *)trans_function_name(&p, eap->skip, TFN_NO_AUTOLOAD, &fudi, NULL); paren = (vim_strchr(p, '(') != NULL); if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) { - /* - * Return on an invalid expression in braces, unless the expression - * evaluation has been cancelled due to an aborting error, an - * interrupt, or an exception. - */ + // Return on an invalid expression in braces, unless the expression + // evaluation has been cancelled due to an aborting error, an + // interrupt, or an exception. if (!aborting()) { if (fudi.fd_newkey != NULL) { semsg(_(e_dictkey), fudi.fd_newkey); @@ -2069,9 +2059,7 @@ void ex_function(exarg_T *eap) goto ret_free; } - /* - * ":function name(arg1, arg2)" Define function. - */ + // ":function name(arg1, arg2)" Define function. p = skipwhite(p); if (*p != '(') { if (!eap->skip) { @@ -2154,9 +2142,7 @@ void ex_function(exarg_T *eap) semsg(_(e_trailing_arg), p); } - /* - * Read the body of the function, until ":endfunction" is found. - */ + // Read the body of the function, until ":endfunction" is found. if (KeyTyped) { // Check if the function already exists, don't let the user type the // whole function before telling him it doesn't work! For a script we @@ -2410,9 +2396,7 @@ void ex_function(exarg_T *eap) goto erret; } - /* - * If there are no errors, add the function - */ + // If there are no errors, add the function if (fudi.fd_dict == NULL) { v = find_var((const char *)name, STRLEN(name), &ht, false); if (v != NULL && v->di_tv.v_type == VAR_FUNC) { diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 126129b24d..8f256728e3 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1,9 +1,7 @@ // 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 -/* - * ex_cmds.c: some functions for command line commands - */ +// ex_cmds.c: some functions for command line commands #include #include @@ -249,11 +247,9 @@ void ex_align(exarg_T *eap) indent = width; } } else { - /* - * if 'textwidth' set, use it - * else if 'wrapmargin' set, use it - * if invalid value, use 80 - */ + // if 'textwidth' set, use it + // else if 'wrapmargin' set, use it + // if invalid value, use 80 if (width <= 0) { width = (int)curbuf->b_p_tw; } @@ -287,18 +283,14 @@ void ex_align(exarg_T *eap) } else { new_indent = width - len; // right align - /* - * Make sure that embedded TABs don't make the text go too far - * to the right. - */ + // Make sure that embedded TABs don't make the text go too far + // to the right. if (has_tab) { while (new_indent > 0) { (void)set_indent(new_indent, 0); if (linelen(NULL) <= width) { - /* - * Now try to move the line as much as possible to - * the right. Stop when it moves too far. - */ + // Now try to move the line as much as possible to + // the right. Stop when it moves too far. do { (void)set_indent(++new_indent, 0); } while (linelen(NULL) <= width); @@ -933,10 +925,8 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) num_lines = line2 - line1 + 1; - /* - * First we copy the old text to its new location -- webb - * Also copy the flag that ":global" command uses. - */ + // First we copy the old text to its new location -- webb + // Also copy the flag that ":global" command uses. if (u_save(dest, dest + 1) == FAIL) { return FAIL; } @@ -949,21 +939,19 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) } } - /* - * Now we must be careful adjusting our marks so that we don't overlap our - * mark_adjust() calls. - * - * We adjust the marks within the old text so that they refer to the - * last lines of the file (temporarily), because we know no other marks - * will be set there since these line numbers did not exist until we added - * our new lines. - * - * Then we adjust the marks on lines between the old and new text positions - * (either forwards or backwards). - * - * And Finally we adjust the marks we put at the end of the file back to - * their final destination at the new text position -- webb - */ + // Now we must be careful adjusting our marks so that we don't overlap our + // mark_adjust() calls. + // + // We adjust the marks within the old text so that they refer to the + // last lines of the file (temporarily), because we know no other marks + // will be set there since these line numbers did not exist until we added + // our new lines. + // + // Then we adjust the marks on lines between the old and new text positions + // (either forwards or backwards). + // + // And Finally we adjust the marks we put at the end of the file back to + // their final destination at the new text position -- webb last_line = curbuf->b_ml.ml_line_count; mark_adjust_nofold(line1, line2, last_line - line2, 0L, kExtmarkNOOP); @@ -1011,9 +999,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) // send update regarding the new lines that were added buf_updates_send_changes(curbuf, dest + 1, num_lines, 0); - /* - * Now we delete the original text -- webb - */ + // Now we delete the original text -- webb if (u_save(line1 + extra - 1, line2 + extra + 1) == FAIL) { return FAIL; } @@ -1030,9 +1016,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) dest + line_off, 0, dest_byte + byte_off, kExtmarkUndo); - /* - * Leave the cursor on the last of the moved lines. - */ + // Leave the cursor on the last of the moved lines. if (dest >= line1) { curwin->w_cursor.lnum = dest; } else { @@ -1069,17 +1053,15 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) curbuf->b_op_start.col = curbuf->b_op_end.col = 0; } - /* - * there are three situations: - * 1. destination is above line1 - * 2. destination is between line1 and line2 - * 3. destination is below line2 - * - * n = destination (when starting) - * curwin->w_cursor.lnum = destination (while copying) - * line1 = start of source (while copying) - * line2 = end of source (while copying) - */ + // there are three situations: + // 1. destination is above line1 + // 2. destination is between line1 and line2 + // 3. destination is below line2 + // + // n = destination (when starting) + // curwin->w_cursor.lnum = destination (while copying) + // line1 = start of source (while copying) + // line2 = end of source (while copying) if (u_save(n, n + 1) == FAIL) { return; } @@ -1155,10 +1137,8 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out msg_scroll = scroll_save; } - /* - * Try to find an embedded bang, like in :! ! [args] - * (:!! is indicated by the 'forceit' variable) - */ + // Try to find an embedded bang, like in :! ! [args] + // (:!! is indicated by the 'forceit' variable) bool ins_prevcmd = forceit; trailarg = arg; do { @@ -1187,10 +1167,8 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out xfree(newcmd); newcmd = t; - /* - * Scan the rest of the argument for '!', which is replaced by the - * previous command. "\!" is replaced by "!" (this is vi compatible). - */ + // Scan the rest of the argument for '!', which is replaced by the + // previous command. "\!" is replaced by "!" (this is vi compatible). trailarg = NULL; while (*p) { if (*p == '!') { @@ -1221,9 +1199,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out AppendToRedobuff("\n"); bangredo = false; } - /* - * Add quotes around the command, for shells that need them. - */ + // Add quotes around the command, for shells that need them. if (*p_shq != NUL) { newcmd = xmalloc(STRLEN(prevcmd) + 2 * STRLEN(p_shq) + 1); STRCPY(newcmd, p_shq); @@ -1298,18 +1274,16 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b changed_line_abv_curs(); invalidate_botline(); - /* - * When using temp files: - * 1. * Form temp file names - * 2. * Write the lines to a temp file - * 3. Run the filter command on the temp file - * 4. * Read the output of the command into the buffer - * 5. * Delete the original lines to be filtered - * 6. * Remove the temp files - * - * When writing the input with a pipe or when catching the output with a - * pipe only need to do 3. - */ + // When using temp files: + // 1. * Form temp file names + // 2. * Write the lines to a temp file + // 3. Run the filter command on the temp file + // 4. * Read the output of the command into the buffer + // 5. * Delete the original lines to be filtered + // 6. * Remove the temp files + // + // When writing the input with a pipe or when catching the output with a + // pipe only need to do 3. if (do_out) { shell_flags |= kShellOptDoOut; @@ -1337,10 +1311,8 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b goto filterend; } - /* - * The writing and reading of temp files will not be shown. - * Vi also doesn't do this and the messages are not very informative. - */ + // The writing and reading of temp files will not be shown. + // Vi also doesn't do this and the messages are not very informative. no_wait_return++; // don't call wait_return() while busy if (itmp != NULL && buf_write(curbuf, itmp, NULL, line1, line2, eap, false, false, false, true) == FAIL) { @@ -1428,10 +1400,8 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b } } - /* - * Put cursor on first filtered line for ":range!cmd". - * Adjust '[ and '] (set by buf_write()). - */ + // Put cursor on first filtered line for ":range!cmd". + // Adjust '[ and '] (set by buf_write()). curwin->w_cursor.lnum = line1; del_lines(linecount, true); curbuf->b_op_start.lnum -= linecount; // adjust '[ @@ -1440,9 +1410,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b // for next write foldUpdate(curwin, curbuf->b_op_start.lnum, curbuf->b_op_end.lnum); } else { - /* - * Put cursor on last new line for ":r !cmd". - */ + // Put cursor on last new line for ":r !cmd". linecount = curbuf->b_op_end.lnum - curbuf->b_op_start.lnum + 1; curwin->w_cursor.lnum = curbuf->b_op_end.lnum; } @@ -1504,10 +1472,8 @@ void do_shell(char *cmd, int flags) return; } - /* - * For autocommands we want to get the output on the current screen, to - * avoid having to type return below. - */ + // For autocommands we want to get the output on the current screen, to + // avoid having to type return below. msg_putchar('\r'); // put cursor at start of line msg_putchar('\n'); // may shift screen one line up @@ -1740,13 +1706,11 @@ int rename_buffer(char *new_fname) if (aborting()) { // autocmds may abort script processing return FAIL; } - /* - * The name of the current buffer will be changed. - * A new (unlisted) buffer entry needs to be made to hold the old file - * name, which will become the alternate file name. - * But don't set the alternate file name if the buffer didn't have a - * name. - */ + // The name of the current buffer will be changed. + // A new (unlisted) buffer entry needs to be made to hold the old file + // name, which will become the alternate file name. + // But don't set the alternate file name if the buffer didn't have a + // name. fname = curbuf->b_ffname; sfname = curbuf->b_sfname; xfname = curbuf->b_fname; @@ -1860,9 +1824,7 @@ int do_write(exarg_T *eap) other = otherfile(ffname); } - /* - * If we have a new file, put its name in the list of alternate file names. - */ + // If we have a new file, put its name in the list of alternate file names. if (other) { if (vim_strchr(p_cpo, CPO_ALTWRITE) != NULL || eap->cmdidx == CMD_saveas) { @@ -2113,13 +2075,11 @@ void do_wqall(exarg_T *eap) } else if (!bufIsChanged(buf) || bt_dontwrite(buf)) { continue; } - /* - * Check if there is a reason the buffer cannot be written: - * 1. if the 'write' option is set - * 2. if there is no file name (even after browsing) - * 3. if the 'readonly' is set (even after a dialog) - * 4. if overwriting is allowed (even after a dialog) - */ + // Check if there is a reason the buffer cannot be written: + // 1. if the 'write' option is set + // 2. if there is no file name (even after browsing) + // 3. if the 'readonly' is set (even after a dialog) + // 4. if overwriting is allowed (even after a dialog) if (not_writing()) { error++; break; @@ -2405,10 +2365,8 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum goto theend; } - /* - * End Visual mode before switching to another buffer, so the text can be - * copied into the GUI selection buffer. - */ + // End Visual mode before switching to another buffer, so the text can be + // copied into the GUI selection buffer. reset_VIsual(); if ((command != NULL || newlnum > (linenr_T)0) @@ -2426,10 +2384,8 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum xfree(p); } - /* - * If we are starting to edit another file, open a (new) buffer. - * Otherwise we re-use the current buffer. - */ + // If we are starting to edit another file, open a (new) buffer. + // Otherwise we re-use the current buffer. if (other_file) { const int prev_alt_fnum = curwin->w_alt_fnum; @@ -2507,12 +2463,10 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum solcol = pos->col; } - /* - * Make the (new) buffer the one used by the current window. - * If the old buffer becomes unused, free it if ECMD_HIDE is false. - * If the current buffer was empty and has no file name, curbuf - * is returned by buflist_new(), nothing to do here. - */ + // Make the (new) buffer the one used by the current window. + // If the old buffer becomes unused, free it if ECMD_HIDE is false. + // If the current buffer was empty and has no file name, curbuf + // is returned by buflist_new(), nothing to do here. if (buf != curbuf) { const int save_cmdwin_type = cmdwin_type; @@ -2663,13 +2617,11 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // highlighting to work in the other file. did_filetype = false; - /* - * other_file oldbuf - * false false re-edit same file, buffer is re-used - * false true re-edit same file, nothing changes - * true false start editing new file, new buffer - * true true start editing in existing buffer (nothing to do) - */ + // other_file oldbuf + // false false re-edit same file, buffer is re-used + // false true re-edit same file, nothing changes + // true false start editing new file, new buffer + // true true start editing in existing buffer (nothing to do) if (!other_file && !oldbuf) { // re-use the buffer set_last_cursor(curwin); // may set b_last_cursor if (newlnum == ECMD_LAST || newlnum == ECMD_LASTL) { @@ -2728,9 +2680,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum curbuf->b_op_end.lnum = 0; } - /* - * If we get here we are sure to start editing - */ + // If we get here we are sure to start editing // Assume success now retval = OK; @@ -2741,17 +2691,13 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum curbuf->b_flags &= ~BF_NOTEDITED; } - /* - * Check if we are editing the w_arg_idx file in the argument list. - */ + // Check if we are editing the w_arg_idx file in the argument list. check_arg_idx(curwin); if (!auto_buf) { - /* - * Set cursor and init window before reading the file and executing - * autocommands. This allows for the autocommands to position the - * cursor. - */ + // Set cursor and init window before reading the file and executing + // autocommands. This allows for the autocommands to position the + // cursor. curwin_init(); // It's possible that all lines in the buffer changed. Need to update @@ -2765,19 +2711,15 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // Change directories when the 'acd' option is set. do_autochdir(); - /* - * Careful: open_buffer() and apply_autocmds() may change the current - * buffer and window. - */ + // Careful: open_buffer() and apply_autocmds() may change the current + // buffer and window. orig_pos = curwin->w_cursor; topline = curwin->w_topline; if (!oldbuf) { // need to read the file swap_exists_action = SEA_DIALOG; curbuf->b_flags |= BF_CHECK_RO; // set/reset 'ro' flag - /* - * Open the buffer and read the file. - */ + // Open the buffer and read the file. if (flags & ECMD_NOWINENTER) { readfile_flags |= READ_NOWINENTER; } @@ -2868,10 +2810,8 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // Check if cursors in other windows on the same buffer are still valid check_lnums(false); - /* - * Did not read the file, need to show some info about the file. - * Do this after setting the cursor. - */ + // Did not read the file, need to show some info about the file. + // Do this after setting the cursor. if (oldbuf && !auto_buf) { int msg_scroll_save = msg_scroll; @@ -3559,10 +3499,8 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T } } - /* - * Small incompatibility: vi sees '\n' as end of the command, but in - * Vim we want to use '\n' to find/substitute a NUL. - */ + // Small incompatibility: vi sees '\n' as end of the command, but in + // Vim we want to use '\n' to find/substitute a NUL. sub = cmd; // remember the start of the substitution while (cmd[0]) { @@ -3620,9 +3558,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T } } - /* - * check for trailing command or garbage - */ + // check for trailing command or garbage cmd = skipwhite(cmd); if (*cmd && *cmd != '"') { // if not end-of-line or comment eap->nextcmd = check_nextcmd(cmd); @@ -3711,50 +3647,48 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T bool skip_match = false; linenr_T sub_firstlnum; // nr of first sub line - /* - * The new text is build up step by step, to avoid too much - * copying. There are these pieces: - * sub_firstline The old text, unmodified. - * copycol Column in the old text where we started - * looking for a match; from here old text still - * needs to be copied to the new text. - * matchcol Column number of the old text where to look - * for the next match. It's just after the - * previous match or one further. - * prev_matchcol Column just after the previous match (if any). - * Mostly equal to matchcol, except for the first - * match and after skipping an empty match. - * regmatch.*pos Where the pattern matched in the old text. - * new_start The new text, all that has been produced so - * far. - * new_end The new text, where to append new text. - * - * lnum The line number where we found the start of - * the match. Can be below the line we searched - * when there is a \n before a \zs in the - * pattern. - * sub_firstlnum The line number in the buffer where to look - * for a match. Can be different from "lnum" - * when the pattern or substitute string contains - * line breaks. - * - * Special situations: - * - When the substitute string contains a line break, the part up - * to the line break is inserted in the text, but the copy of - * the original line is kept. "sub_firstlnum" is adjusted for - * the inserted lines. - * - When the matched pattern contains a line break, the old line - * is taken from the line at the end of the pattern. The lines - * in the match are deleted later, "sub_firstlnum" is adjusted - * accordingly. - * - * The new text is built up in new_start[]. It has some extra - * room to avoid using xmalloc()/free() too often. - * - * Make a copy of the old line, so it won't be taken away when - * updating the screen or handling a multi-line match. The "old_" - * pointers point into this copy. - */ + // The new text is build up step by step, to avoid too much + // copying. There are these pieces: + // sub_firstline The old text, unmodified. + // copycol Column in the old text where we started + // looking for a match; from here old text still + // needs to be copied to the new text. + // matchcol Column number of the old text where to look + // for the next match. It's just after the + // previous match or one further. + // prev_matchcol Column just after the previous match (if any). + // Mostly equal to matchcol, except for the first + // match and after skipping an empty match. + // regmatch.*pos Where the pattern matched in the old text. + // new_start The new text, all that has been produced so + // far. + // new_end The new text, where to append new text. + // + // lnum The line number where we found the start of + // the match. Can be below the line we searched + // when there is a \n before a \zs in the + // pattern. + // sub_firstlnum The line number in the buffer where to look + // for a match. Can be different from "lnum" + // when the pattern or substitute string contains + // line breaks. + // + // Special situations: + // - When the substitute string contains a line break, the part up + // to the line break is inserted in the text, but the copy of + // the original line is kept. "sub_firstlnum" is adjusted for + // the inserted lines. + // - When the matched pattern contains a line break, the old line + // is taken from the line at the end of the pattern. The lines + // in the match are deleted later, "sub_firstlnum" is adjusted + // accordingly. + // + // The new text is built up in new_start[]. It has some extra + // room to avoid using xmalloc()/free() too often. + // + // Make a copy of the old line, so it won't be taken away when + // updating the screen or handling a multi-line match. The "old_" + // pointers point into this copy. sub_firstlnum = lnum; copycol = 0; matchcol = 0; @@ -3765,14 +3699,12 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T got_match = true; } - /* - * Loop until nothing more to replace in this line. - * 1. Handle match with empty string. - * 2. If subflags.do_ask is set, ask for confirmation. - * 3. substitute the string. - * 4. if subflags.do_all is set, find next match - * 5. break if there isn't another match in this line - */ + // Loop until nothing more to replace in this line. + // 1. Handle match with empty string. + // 2. If subflags.do_ask is set, ask for confirmation. + // 3. substitute the string. + // 4. if subflags.do_all is set, find next match + // 5. break if there isn't another match in this line for (;;) { SubResult current_match = { .start = { 0, 0 }, @@ -3811,11 +3743,9 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T curwin->w_cursor.lnum = lnum; do_again = false; - /* - * 1. Match empty string does not count, except for first - * match. This reproduces the strange vi behaviour. - * This also catches endless loops. - */ + // 1. Match empty string does not count, except for first + // match. This reproduces the strange vi behaviour. + // This also catches endless loops. if (matchcol == prev_matchcol && regmatch.endpos[0].lnum == 0 && matchcol == regmatch.endpos[0].col) { @@ -3880,9 +3810,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T no_u_sync++; } - /* - * Loop until 'y', 'n', 'q', CTRL-E or CTRL-Y typed. - */ + // Loop until 'y', 'n', 'q', CTRL-E or CTRL-Y typed. while (subflags.do_ask) { if (exmode_active) { char *prompt; @@ -4266,15 +4194,13 @@ skip: && !re_multiline(regmatch.regprog))); nmatch = -1; - /* - * Replace the line in the buffer when needed. This is - * skipped when there are more matches. - * The check for nmatch_tl is needed for when multi-line - * matching must replace the lines before trying to do another - * match, otherwise "\@<=" won't work. - * When the match starts below where we start searching also - * need to replace the line first (using \zs after \n). - */ + // Replace the line in the buffer when needed. This is + // skipped when there are more matches. + // The check for nmatch_tl is needed for when multi-line + // matching must replace the lines before trying to do another + // match, otherwise "\@<=" won't work. + // When the match starts below where we start searching also + // need to replace the line first (using \zs after \n). if (lastone || nmatch_tl > 0 || (nmatch = vim_regexec_multi(®match, curwin, @@ -4282,13 +4208,11 @@ skip: matchcol, NULL, NULL)) == 0 || regmatch.startpos[0].lnum > 0) { if (new_start != NULL) { - /* - * Copy the rest of the line, that didn't match. - * "matchcol" has to be adjusted, we use the end of - * the line as reference, because the substitute may - * have changed the number of characters. Same for - * "prev_matchcol". - */ + // Copy the rest of the line, that didn't match. + // "matchcol" has to be adjusted, we use the end of + // the line as reference, because the substitute may + // have changed the number of characters. Same for + // "prev_matchcol". STRCAT(new_start, sub_firstline + copycol); matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; prev_matchcol = (colnr_T)STRLEN(sub_firstline) @@ -4300,12 +4224,10 @@ skip: ml_replace(lnum, new_start, true); if (nmatch_tl > 0) { - /* - * Matched lines have now been substituted and are - * useless, delete them. The part after the match - * has been appended to new_start, we don't need - * it in the buffer. - */ + // Matched lines have now been substituted and are + // useless, delete them. The part after the match + // has been appended to new_start, we don't need + // it in the buffer. lnum++; if (u_savedel(lnum, nmatch_tl) != OK) { break; @@ -4348,9 +4270,7 @@ skip: sub_firstlnum, matchcol, NULL, NULL); } - /* - * 5. break if there isn't another match in this line - */ + // 5. break if there isn't another match in this line if (nmatch <= 0) { // If the match found didn't start where we were // searching, do the next search in the line where we @@ -4513,12 +4433,10 @@ skip: /// @return true if a message was given. bool do_sub_msg(bool count_only) { - /* - * Only report substitutions when: - * - more than 'report' substitutions - * - command was typed by user, or number of changed lines > 'report' - * - giving messages is not disabled by 'lazyredraw' - */ + // Only report substitutions when: + // - more than 'report' substitutions + // - command was typed by user, or number of changed lines > 'report' + // - giving messages is not disabled by 'lazyredraw' if (((sub_nsubs > p_report && (KeyTyped || sub_nlines > 1 || p_report < 1)) || count_only) && messaging()) { @@ -4609,11 +4527,9 @@ void ex_global(exarg_T *eap) cmd = eap->arg; which_pat = RE_LAST; // default: use last used regexp - /* - * undocumented vi feature: - * "\/" and "\?": use previous search pattern. - * "\&": use previous substitute pattern. - */ + // undocumented vi feature: + // "\/" and "\?": use previous search pattern. + // "\&": use previous substitute pattern. if (*cmd == '\\') { cmd++; if (vim_strchr("/?&", *cmd) == NULL) { @@ -4752,9 +4668,7 @@ void free_old_sub(void) /// @return true when it was created. bool prepare_tagpreview(bool undo_sync) { - /* - * If there is already a preview window open, use that one. - */ + // If there is already a preview window open, use that one. if (!curwin->w_p_pvw) { bool found_win = false; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { @@ -4765,9 +4679,7 @@ bool prepare_tagpreview(bool undo_sync) } } if (!found_win) { - /* - * There is no preview window open yet. Create one. - */ + // There is no preview window open yet. Create one. if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0) == FAIL) { return false; diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 6dddafcfcb..20725b81ee 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -79,15 +79,13 @@ static void discard_pending_return(typval_T *p) tv_free(p); } -/* - * When several errors appear in a row, setting "force_abort" is delayed until - * the failing command returned. "cause_abort" is set to true meanwhile, in - * order to indicate that situation. This is useful when "force_abort" was set - * during execution of a function call from an expression: the aborting of the - * expression evaluation is done without producing any error messages, but all - * error messages on parsing errors during the expression evaluation are given - * (even if a try conditional is active). - */ +// When several errors appear in a row, setting "force_abort" is delayed until +// the failing command returned. "cause_abort" is set to true meanwhile, in +// order to indicate that situation. This is useful when "force_abort" was set +// during execution of a function call from an expression: the aborting of the +// expression evaluation is done without producing any error messages, but all +// error messages on parsing errors during the expression evaluation are given +// (even if a try conditional is active). static int cause_abort = false; /// @return true when immediately aborting on error, or when an interrupt @@ -153,69 +151,57 @@ bool cause_errthrow(const char *mesg, bool severe, bool *ignore) msglist_T *elem; msglist_T **plist; - /* - * Do nothing when displaying the interrupt message or reporting an - * uncaught exception (which has already been discarded then) at the top - * level. Also when no exception can be thrown. The message will be - * displayed by emsg(). - */ + // Do nothing when displaying the interrupt message or reporting an + // uncaught exception (which has already been discarded then) at the top + // level. Also when no exception can be thrown. The message will be + // displayed by emsg(). if (suppress_errthrow) { return false; } - /* - * If emsg() has not been called previously, temporarily reset - * "force_abort" until the throw point for error messages has been - * reached. This ensures that aborting() returns the same value for all - * errors that appear in the same command. This means particularly that - * for parsing errors during expression evaluation emsg() will be called - * multiply, even when the expression is evaluated from a finally clause - * that was activated due to an aborting error, interrupt, or exception. - */ + // If emsg() has not been called previously, temporarily reset + // "force_abort" until the throw point for error messages has been + // reached. This ensures that aborting() returns the same value for all + // errors that appear in the same command. This means particularly that + // for parsing errors during expression evaluation emsg() will be called + // multiply, even when the expression is evaluated from a finally clause + // that was activated due to an aborting error, interrupt, or exception. if (!did_emsg) { cause_abort = force_abort; force_abort = false; } - /* - * If no try conditional is active and no exception is being thrown and - * there has not been an error in a try conditional or a throw so far, do - * nothing (for compatibility of non-EH scripts). The message will then - * be displayed by emsg(). When ":silent!" was used and we are not - * currently throwing an exception, do nothing. The message text will - * then be stored to v:errmsg by emsg() without displaying it. - */ + // If no try conditional is active and no exception is being thrown and + // there has not been an error in a try conditional or a throw so far, do + // nothing (for compatibility of non-EH scripts). The message will then + // be displayed by emsg(). When ":silent!" was used and we are not + // currently throwing an exception, do nothing. The message text will + // then be stored to v:errmsg by emsg() without displaying it. if (((trylevel == 0 && !cause_abort) || emsg_silent) && !did_throw) { return false; } - /* - * Ignore an interrupt message when inside a try conditional or when an - * exception is being thrown or when an error in a try conditional or - * throw has been detected previously. This is important in order that an - * interrupt exception is catchable by the innermost try conditional and - * not replaced by an interrupt message error exception. - */ + // Ignore an interrupt message when inside a try conditional or when an + // exception is being thrown or when an error in a try conditional or + // throw has been detected previously. This is important in order that an + // interrupt exception is catchable by the innermost try conditional and + // not replaced by an interrupt message error exception. if (mesg == _(e_interr)) { *ignore = true; return true; } - /* - * Ensure that all commands in nested function calls and sourced files - * are aborted immediately. - */ + // Ensure that all commands in nested function calls and sourced files + // are aborted immediately. cause_abort = true; - /* - * When an exception is being thrown, some commands (like conditionals) are - * not skipped. Errors in those commands may affect what of the subsequent - * commands are regarded part of catch and finally clauses. Catching the - * exception would then cause execution of commands not intended by the - * user, who wouldn't even get aware of the problem. Therefore, discard the - * exception currently being thrown to prevent it from being caught. Just - * execute finally clauses and terminate. - */ + // When an exception is being thrown, some commands (like conditionals) are + // not skipped. Errors in those commands may affect what of the subsequent + // commands are regarded part of catch and finally clauses. Catching the + // exception would then cause execution of commands not intended by the + // user, who wouldn't even get aware of the problem. Therefore, discard the + // exception currently being thrown to prevent it from being caught. Just + // execute finally clauses and terminate. if (did_throw) { // When discarding an interrupt exception, reset got_int to prevent the // same interrupt being converted to an exception again and discarding @@ -228,25 +214,21 @@ bool cause_errthrow(const char *mesg, bool severe, bool *ignore) #ifdef THROW_TEST if (!THROW_ON_ERROR) { - /* - * Print error message immediately without searching for a matching - * catch clause; just finally clauses are executed before the script - * is terminated. - */ + // Print error message immediately without searching for a matching + // catch clause; just finally clauses are executed before the script + // is terminated. return false; } else // NOLINT(readability/braces) #endif { - /* - * Prepare the throw of an error exception, so that everything will - * be aborted (except for executing finally clauses), until the error - * exception is caught; if still uncaught at the top level, the error - * message will be displayed and the script processing terminated - * then. - This function has no access to the conditional stack. - * Thus, the actual throw is made after the failing command has - * returned. - Throw only the first of several errors in a row, except - * a severe error is following. - */ + // Prepare the throw of an error exception, so that everything will + // be aborted (except for executing finally clauses), until the error + // exception is caught; if still uncaught at the top level, the error + // message will be displayed and the script processing terminated + // then. - This function has no access to the conditional stack. + // Thus, the actual throw is made after the failing command has + // returned. - Throw only the first of several errors in a row, except + // a severe error is following. if (msg_list != NULL) { plist = msg_list; while (*plist != NULL) { @@ -312,10 +294,8 @@ void free_global_msglist(void) /// has returned (see do_one_cmd()). void do_errthrow(cstack_T *cstack, char *cmdname) { - /* - * Ensure that all commands in nested function calls and sourced files - * are aborted immediately. - */ + // Ensure that all commands in nested function calls and sourced files + // are aborted immediately. if (cause_abort) { cause_abort = false; force_abort = true; @@ -455,11 +435,9 @@ static int throw_exception(void *value, except_type_T type, char *cmdname) except_T *excp; int should_free; - /* - * Disallow faking Interrupt or error exceptions as user exceptions. They - * would be treated differently from real interrupt or error exceptions - * when no active try block is found, see do_cmdline(). - */ + // Disallow faking Interrupt or error exceptions as user exceptions. They + // would be treated differently from real interrupt or error exceptions + // when no active try block is found, see do_cmdline(). if (type == ET_USER) { if (STRNCMP((char_u *)value, "Vim", 3) == 0 && (((char_u *)value)[3] == NUL || ((char_u *)value)[3] == ':' @@ -678,9 +656,7 @@ static void finish_exception(except_T *excp) discard_exception(excp, true); } -/* - * Flags specifying the message displayed by report_pending. - */ +// Flags specifying the message displayed by report_pending. #define RP_MAKE 0 #define RP_RESUME 1 #define RP_DISCARD 2 @@ -958,11 +934,9 @@ void ex_while(exarg_T *eap) if (cstack->cs_idx == CSTACK_LEN - 1) { eap->errmsg = _("E585: :while/:for nesting too deep"); } else { - /* - * The loop flag is set when we have jumped back from the matching - * ":endwhile" or ":endfor". When not set, need to initialise this - * cstack entry. - */ + // The loop flag is set when we have jumped back from the matching + // ":endwhile" or ":endfor". When not set, need to initialise this + // cstack entry. if ((cstack->cs_lflags & CSL_HAD_LOOP) == 0) { cstack->cs_idx++; cstack->cs_looplevel++; @@ -973,16 +947,12 @@ void ex_while(exarg_T *eap) skip = CHECK_SKIP; if (eap->cmdidx == CMD_while) { - /* - * ":while bool-expr" - */ + // ":while bool-expr" result = eval_to_bool(eap->arg, &error, &eap->nextcmd, skip); } else { void *fi; - /* - * ":for var in list-expr" - */ + // ":for var in list-expr" if ((cstack->cs_lflags & CSL_HAD_LOOP) != 0) { // Jumping here from a ":continue" or ":endfor": use the // previously evaluated list. @@ -1007,11 +977,9 @@ void ex_while(exarg_T *eap) } } - /* - * If this cstack entry was just initialised and is active, set the - * loop flag, so do_cmdline() will set the line number in cs_line[]. - * If executing the command a second time, clear the loop flag. - */ + // If this cstack entry was just initialised and is active, set the + // loop flag, so do_cmdline() will set the line number in cs_line[]. + // If executing the command a second time, clear the loop flag. if (!skip && !error && result) { cstack->cs_flags[cstack->cs_idx] |= (CSF_ACTIVE | CSF_TRUE); cstack->cs_lflags ^= CSL_HAD_LOOP; @@ -1046,10 +1014,8 @@ void ex_continue(exarg_T *eap) if (cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR)) { rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel); - /* - * Set CSL_HAD_CONT, so do_cmdline() will jump back to the - * matching ":while". - */ + // Set CSL_HAD_CONT, so do_cmdline() will jump back to the + // matching ":while". cstack->cs_lflags |= CSL_HAD_CONT; // let do_cmdline() handle it } else { // If a try conditional not in its finally clause is reached first, @@ -1147,10 +1113,8 @@ void ex_endwhile(exarg_T *eap) (void)do_intthrow(cstack); } - /* - * Set loop flag, so do_cmdline() will jump back to the matching - * ":while" or ":for". - */ + // Set loop flag, so do_cmdline() will jump back to the matching + // ":while" or ":for". cstack->cs_lflags |= CSL_HAD_ENDLOOP; } } @@ -1211,19 +1175,17 @@ void do_throw(cstack_T *cstack) #endif idx = cleanup_conditionals(cstack, 0, inactivate_try); if (idx >= 0) { - /* - * If this try conditional is active and we are before its first - * ":catch", set THROWN so that the ":catch" commands will check - * whether the exception matches. When the exception came from any of - * the catch clauses, it will be made pending at the ":finally" (if - * present) and rethrown at the ":endtry". This will also happen if - * the try conditional is inactive. This is the case when we are - * throwing an exception due to an error or interrupt on the way from - * a preceding ":continue", ":break", ":return", ":finish", error or - * interrupt (not converted to an exception) to the finally clause or - * from a preceding throw of a user or error or interrupt exception to - * the matching catch clause or the finally clause. - */ + // If this try conditional is active and we are before its first + // ":catch", set THROWN so that the ":catch" commands will check + // whether the exception matches. When the exception came from any of + // the catch clauses, it will be made pending at the ":finally" (if + // present) and rethrown at the ":endtry". This will also happen if + // the try conditional is inactive. This is the case when we are + // throwing an exception due to an error or interrupt on the way from + // a preceding ":continue", ":break", ":return", ":finish", error or + // interrupt (not converted to an exception) to the finally clause or + // from a preceding throw of a user or error or interrupt exception to + // the matching catch clause or the finally clause. if (!(cstack->cs_flags[idx] & CSF_CAUGHT)) { if (cstack->cs_flags[idx] & CSF_ACTIVE) { cstack->cs_flags[idx] |= CSF_THROWN; @@ -1263,22 +1225,20 @@ void ex_try(exarg_T *eap) // that the finally clause needs to be executed. cstack->cs_flags[cstack->cs_idx] |= CSF_ACTIVE | CSF_TRUE; - /* - * ":silent!", even when used in a try conditional, disables - * displaying of error messages and conversion of errors to - * exceptions. When the silent commands again open a try - * conditional, save "emsg_silent" and reset it so that errors are - * again converted to exceptions. The value is restored when that - * try conditional is left. If it is left normally, the commands - * following the ":endtry" are again silent. If it is left by - * a ":continue", ":break", ":return", or ":finish", the commands - * executed next are again silent. If it is left due to an - * aborting error, an interrupt, or an exception, restoring - * "emsg_silent" does not matter since we are already in the - * aborting state and/or the exception has already been thrown. - * The effect is then just freeing the memory that was allocated - * to save the value. - */ + // ":silent!", even when used in a try conditional, disables + // displaying of error messages and conversion of errors to + // exceptions. When the silent commands again open a try + // conditional, save "emsg_silent" and reset it so that errors are + // again converted to exceptions. The value is restored when that + // try conditional is left. If it is left normally, the commands + // following the ":endtry" are again silent. If it is left by + // a ":continue", ":break", ":return", or ":finish", the commands + // executed next are again silent. If it is left due to an + // aborting error, an interrupt, or an exception, restoring + // "emsg_silent" does not matter since we are already in the + // aborting state and/or the exception has already been thrown. + // The effect is then just freeing the memory that was allocated + // to save the value. if (emsg_silent) { eslist_T *elem = xmalloc(sizeof(*elem)); elem->saved_emsg_silent = emsg_silent; @@ -1342,20 +1302,16 @@ void ex_catch(exarg_T *eap) } if (!give_up) { - /* - * Don't do something when no exception has been thrown or when the - * corresponding try block never got active (because of an inactive - * surrounding conditional or after an error or interrupt or throw). - */ + // Don't do something when no exception has been thrown or when the + // corresponding try block never got active (because of an inactive + // surrounding conditional or after an error or interrupt or throw). if (!did_throw || !(cstack->cs_flags[idx] & CSF_TRUE)) { skip = true; } - /* - * Check for a match only if an exception is thrown but not caught by - * a previous ":catch". An exception that has replaced a discarded - * exception is not checked (THROWN is not set then). - */ + // Check for a match only if an exception is thrown but not caught by + // a previous ":catch". An exception that has replaced a discarded + // exception is not checked (THROWN is not set then). if (!skip && (cstack->cs_flags[idx] & CSF_THROWN) && !(cstack->cs_flags[idx] & CSF_CAUGHT)) { if (end != NULL && *end != NUL && !ends_excmd(*skipwhite(end + 1))) { @@ -1422,16 +1378,14 @@ void ex_catch(exarg_T *eap) internal_error("ex_catch()"); } } else { - /* - * If there is a preceding catch clause and it caught the exception, - * finish the exception now. This happens also after errors except - * when this ":catch" was after the ":finally" or not within - * a ":try". Make the try conditional inactive so that the - * following catch clauses are skipped. On an error or interrupt - * after the preceding try block or catch clause was left by - * a ":continue", ":break", ":return", or ":finish", discard the - * pending action. - */ + // If there is a preceding catch clause and it caught the exception, + // finish the exception now. This happens also after errors except + // when this ":catch" was after the ":finally" or not within + // a ":try". Make the try conditional inactive so that the + // following catch clauses are skipped. On an error or interrupt + // after the preceding try block or catch clause was left by + // a ":continue", ":break", ":return", or ":finish", discard the + // pending action. cleanup_conditionals(cstack, CSF_TRY, true); } } @@ -1495,14 +1449,12 @@ void ex_finally(exarg_T *eap) (void)do_intthrow(cstack); } - /* - * If there is a preceding catch clause and it caught the exception, - * finish the exception now. This happens also after errors except - * when this is a multiple ":finally" or one not within a ":try". - * After an error or interrupt, this also discards a pending - * ":continue", ":break", ":finish", or ":return" from the preceding - * try block or catch clause. - */ + // If there is a preceding catch clause and it caught the exception, + // finish the exception now. This happens also after errors except + // when this is a multiple ":finally" or one not within a ":try". + // After an error or interrupt, this also discards a pending + // ":continue", ":break", ":finish", or ":return" from the preceding + // try block or catch clause. cleanup_conditionals(cstack, CSF_TRY, false); // Make did_emsg, got_int, did_throw pending. If set, they overrule @@ -1606,12 +1558,10 @@ void ex_endtry(exarg_T *eap) } else { idx = cstack->cs_idx; - /* - * If we stopped with the exception currently being thrown at this - * try conditional since we didn't know that it doesn't have - * a finally clause, we need to rethrow it after closing the try - * conditional. - */ + // If we stopped with the exception currently being thrown at this + // try conditional since we didn't know that it doesn't have + // a finally clause, we need to rethrow it after closing the try + // conditional. if (did_throw && (cstack->cs_flags[idx] & CSF_TRUE) && !(cstack->cs_flags[idx] & CSF_FINALLY)) { @@ -1645,12 +1595,10 @@ void ex_endtry(exarg_T *eap) } } - /* - * If a ":return" is pending, we need to resume it after closing the - * try conditional; remember the return value. If there was a finally - * clause making an exception pending, we need to rethrow it. Make it - * the exception currently being thrown. - */ + // If a ":return" is pending, we need to resume it after closing the + // try conditional; remember the return value. If there was a finally + // clause making an exception pending, we need to rethrow it. Make it + // the exception currently being thrown. if (!skip) { pending = cstack->cs_pending[idx]; cstack->cs_pending[idx] = CSTP_NONE; @@ -1661,16 +1609,14 @@ void ex_endtry(exarg_T *eap) } } - /* - * Discard anything pending on an error, interrupt, or throw in the - * finally clause. If there was no ":finally", discard a pending - * ":continue", ":break", ":return", or ":finish" if an error or - * interrupt occurred afterwards, but before the ":endtry" was reached. - * If an exception was caught by the last of the catch clauses and there - * was no finally clause, finish the exception now. This happens also - * after errors except when this ":endtry" is not within a ":try". - * Restore "emsg_silent" if it has been reset by this try conditional. - */ + // Discard anything pending on an error, interrupt, or throw in the + // finally clause. If there was no ":finally", discard a pending + // ":continue", ":break", ":return", or ":finish" if an error or + // interrupt occurred afterwards, but before the ":endtry" was reached. + // If an exception was caught by the last of the catch clauses and there + // was no finally clause, finish the exception now. This happens also + // after errors except when this ":endtry" is not within a ":try". + // Restore "emsg_silent" if it has been reset by this try conditional. (void)cleanup_conditionals(cstack, CSF_TRY | CSF_SILENT, true); if (cstack->cs_idx >= 0 && (cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { @@ -1733,18 +1679,16 @@ void ex_endtry(exarg_T *eap) } } -/* - * enter_cleanup() and leave_cleanup() - * - * Functions to be called before/after invoking a sequence of autocommands for - * cleanup for a failed command. (Failure means here that a call to emsg() - * has been made, an interrupt occurred, or there is an uncaught exception - * from a previous autocommand execution of the same command.) - * - * Call enter_cleanup() with a pointer to a cleanup_T and pass the same - * pointer to leave_cleanup(). The cleanup_T structure stores the pending - * error/interrupt/exception state. - */ +// enter_cleanup() and leave_cleanup() +// +// Functions to be called before/after invoking a sequence of autocommands for +// cleanup for a failed command. (Failure means here that a call to emsg() +// has been made, an interrupt occurred, or there is an uncaught exception +// from a previous autocommand execution of the same command.) +// +// Call enter_cleanup() with a pointer to a cleanup_T and pass the same +// pointer to leave_cleanup(). The cleanup_T structure stores the pending +// error/interrupt/exception state. /// This function works a bit like ex_finally() except that there was not /// actually an extra try block around the part that failed and an error or @@ -1829,18 +1773,14 @@ void leave_cleanup(cleanup_T *csp) if (msg_list != NULL) { free_global_msglist(); } - } - /* - * If there was no new error, interrupt, or throw between the calls - * to enter_cleanup() and leave_cleanup(), restore the pending - * error/interrupt/exception state. - */ - else { - /* - * If there was an exception being thrown when enter_cleanup() was - * called, we need to rethrow it. Make it the exception currently - * being thrown. - */ + } else { + // If there was no new error, interrupt, or throw between the calls + // to enter_cleanup() and leave_cleanup(), restore the pending + // error/interrupt/exception state. + + // If there was an exception being thrown when enter_cleanup() was + // called, we need to rethrow it. Make it the exception currently + // being thrown. if (pending & CSTP_THROW) { current_exception = csp->exception; } else if (pending & CSTP_ERROR) { @@ -1893,12 +1833,10 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive) for (idx = cstack->cs_idx; idx >= 0; idx--) { if (cstack->cs_flags[idx] & CSF_TRY) { - /* - * Discard anything pending in a finally clause and continue the - * search. There may also be a pending ":continue", ":break", - * ":return", or ":finish" before the finally clause. We must not - * discard it, unless an error or interrupt occurred afterwards. - */ + // Discard anything pending in a finally clause and continue the + // search. There may also be a pending ":continue", ":break", + // ":return", or ":finish" before the finally clause. We must not + // discard it, unless an error or interrupt occurred afterwards. if (did_emsg || got_int || (cstack->cs_flags[idx] & CSF_FINALLY)) { switch (cstack->cs_pending[idx]) { case CSTP_NONE: @@ -1934,11 +1872,9 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive) } } - /* - * Stop at a try conditional not in its finally clause. If this try - * conditional is in an active catch clause, finish the caught - * exception. - */ + // Stop at a try conditional not in its finally clause. If this try + // conditional is in an active catch clause, finish the caught + // exception. if (!(cstack->cs_flags[idx] & CSF_FINALLY)) { if ((cstack->cs_flags[idx] & CSF_ACTIVE) && (cstack->cs_flags[idx] & CSF_CAUGHT) && !(cstack->cs_flags[idx] & CSF_FINISHED)) { @@ -1973,11 +1909,9 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive) break; } - /* - * When leaving a try conditional that reset "emsg_silent" on its - * entry after saving the original value, restore that value here and - * free the memory used to store it. - */ + // When leaving a try conditional that reset "emsg_silent" on its + // entry after saving the original value, restore that value here and + // free the memory used to store it. if ((cstack->cs_flags[idx] & CSF_TRY) && (cstack->cs_flags[idx] & CSF_SILENT)) { eslist_T *elem; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 2112385533..da99a03c38 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1,9 +1,7 @@ // 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 -/* - * ex_getln.c: Functions for entering and editing an Ex command line. - */ +// ex_getln.c: Functions for entering and editing an Ex command line. #include #include @@ -2603,10 +2601,8 @@ bool text_locked(void) return textlock != 0; } -/* - * Give an error message for a command that isn't allowed while the cmdline - * window is open or editing the cmdline in another way. - */ +// Give an error message for a command that isn't allowed while the cmdline +// window is open or editing the cmdline in another way. void text_locked_msg(void) { emsg(_(get_text_locked_msg())); @@ -2738,15 +2734,11 @@ bool cmdline_at_end(void) return (ccline.cmdpos >= ccline.cmdlen); } -/* - * Allocate a new command line buffer. - * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. - */ +// Allocate a new command line buffer. +// Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. static void alloc_cmdbuff(int len) { - /* - * give some extra space to avoid having to allocate all the time - */ + // give some extra space to avoid having to allocate all the time if (len < 80) { len = 100; } else { @@ -3088,10 +3080,8 @@ color_cmdline_error: #undef PRINT_ERRMSG } -/* - * Draw part of the cmdline at the current cursor position. But draw stars - * when cmdline_star is true. - */ +// Draw part of the cmdline at the current cursor position. But draw stars +// when cmdline_star is true. static void draw_cmdline(int start, int len) { if (!color_cmdline(&ccline)) { @@ -3342,11 +3332,9 @@ void cmdline_ui_flush(void) } } -/* - * Put a character on the command line. Shifts the following text to the - * right when "shift" is true. Used for CTRL-V, CTRL-K, etc. - * "c" must be printable (fit in one display cell)! - */ +// Put a character on the command line. Shifts the following text to the +// right when "shift" is true. Used for CTRL-V, CTRL-K, etc. +// "c" must be printable (fit in one display cell)! void putcmdline(char c, int shift) { if (cmd_silent) { @@ -3388,14 +3376,12 @@ void unputcmdline(void) ui_cursor_shape(); } -/* - * Put the given string, of the given length, onto the command line. - * If len is -1, then STRLEN() is used to calculate the length. - * If 'redraw' is true then the new part of the command line, and the remaining - * part will be redrawn, otherwise it will not. If this function is called - * twice in a row, then 'redraw' should be false and redrawcmd() should be - * called afterwards. - */ +// Put the given string, of the given length, onto the command line. +// If len is -1, then STRLEN() is used to calculate the length. +// If 'redraw' is true then the new part of the command line, and the remaining +// part will be redrawn, otherwise it will not. If this function is called +// twice in a row, then 'redraw' should be false and redrawcmd() should be +// called afterwards. void put_on_cmdline(char_u *str, int len, int redraw) { int i; @@ -3603,12 +3589,10 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) return cmdline_paste_reg(regname, literally, remcr); } -/* - * Put a string on the command line. - * When "literally" is true, insert literally. - * When "literally" is false, insert as typed, but don't leave the command - * line. - */ +// Put a string on the command line. +// When "literally" is true, insert literally. +// When "literally" is false, insert as typed, but don't leave the command +// line. void cmdline_paste_str(char_u *s, int literally) { int c, cv; @@ -3675,9 +3659,7 @@ static void redrawcmdprompt(void) } } -/* - * Redraw what is currently on the command line. - */ +// Redraw what is currently on the command line. void redrawcmd(void) { if (cmd_silent) { @@ -3714,10 +3696,8 @@ void redrawcmd(void) putcmdline(ccline.special_char, ccline.special_shift); } - /* - * An emsg() before may have set msg_scroll. This is used in normal mode, - * in cmdline mode we can reset them now. - */ + // An emsg() before may have set msg_scroll. This is used in normal mode, + // in cmdline mode we can reset them now. msg_scroll = false; // next message overwrites cmdline // Typing ':' at the more prompt may set skip_redraw. We don't want this @@ -3794,12 +3774,10 @@ void gotocmdline(bool clr) cmd_cursor_goto(cmdline_row, 0); } -/* - * Check the word in front of the cursor for an abbreviation. - * Called when the non-id character "c" has been entered. - * When an abbreviation is recognized it is removed from the text with - * backspaces and the replacement string is inserted, followed by "c". - */ +// Check the word in front of the cursor for an abbreviation. +// Called when the non-id character "c" has been entered. +// When an abbreviation is recognized it is removed from the text with +// backspaces and the replacement string is inserted, followed by "c". static int ccheck_abbr(int c) { int spos = 0; @@ -4310,9 +4288,7 @@ static int open_cmdwin(void) RedrawingDisabled = 0; int save_count = save_batch_count(); - /* - * Call the main loop until or CTRL-C is typed. - */ + // Call the main loop until or CTRL-C is typed. normal_enter(true, false); RedrawingDisabled = i; diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index f75dc51ca5..a604c5ff3e 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -71,9 +71,7 @@ static char_u *ff_expand_buffer = NULL; // used for expanding filenames -/* - * type for the directory search stack - */ +// type for the directory search stack typedef struct ff_stack { struct ff_stack *ffs_prev; @@ -104,9 +102,7 @@ typedef struct ff_stack { int ffs_star_star_empty; } ff_stack_T; -/* - * type for already visited directories or files. - */ +// type for already visited directories or files. typedef struct ff_visited { struct ff_visited *ffv_next; @@ -122,20 +118,18 @@ typedef struct ff_visited { char_u ffv_fname[1]; // actually longer } ff_visited_T; -/* - * We might have to manage several visited lists during a search. - * This is especially needed for the tags option. If tags is set to: - * "./++/tags,./++/TAGS,++/tags" (replace + with *) - * So we have to do 3 searches: - * 1) search from the current files directory downward for the file "tags" - * 2) search from the current files directory downward for the file "TAGS" - * 3) search from Vims current directory downwards for the file "tags" - * As you can see, the first and the third search are for the same file, so for - * the third search we can use the visited list of the first search. For the - * second search we must start from an empty visited list. - * The struct ff_visited_list_hdr is used to manage a linked list of already - * visited lists. - */ +// We might have to manage several visited lists during a search. +// This is especially needed for the tags option. If tags is set to: +// "./++/tags,./++/TAGS,++/tags" (replace + with *) +// So we have to do 3 searches: +// 1) search from the current files directory downward for the file "tags" +// 2) search from the current files directory downward for the file "TAGS" +// 3) search from Vims current directory downwards for the file "tags" +// As you can see, the first and the third search are for the same file, so for +// the third search we can use the visited list of the first search. For the +// second search we must start from an empty visited list. +// The struct ff_visited_list_hdr is used to manage a linked list of already +// visited lists. typedef struct ff_visited_list_hdr { struct ff_visited_list_hdr *ffvl_next; @@ -145,29 +139,25 @@ typedef struct ff_visited_list_hdr { ff_visited_T *ffvl_visited_list; } ff_visited_list_hdr_T; -/* - * '**' can be expanded to several directory levels. - * Set the default maximum depth. - */ +// '**' can be expanded to several directory levels. +// Set the default maximum depth. #define FF_MAX_STAR_STAR_EXPAND ((char_u)30) -/* - * The search context: - * ffsc_stack_ptr: the stack for the dirs to search - * ffsc_visited_list: the currently active visited list - * ffsc_dir_visited_list: the currently active visited list for search dirs - * ffsc_visited_lists_list: the list of all visited lists - * ffsc_dir_visited_lists_list: the list of all visited lists for search dirs - * ffsc_file_to_search: the file to search for - * ffsc_start_dir: the starting directory, if search path was relative - * ffsc_fix_path: the fix part of the given path (without wildcards) - * Needed for upward search. - * ffsc_wc_path: the part of the given path containing wildcards - * ffsc_level: how many levels of dirs to search downwards - * ffsc_stopdirs_v: array of stop directories for upward search - * ffsc_find_what: FINDFILE_BOTH, FINDFILE_DIR or FINDFILE_FILE - * ffsc_tagfile: searching for tags file, don't use 'suffixesadd' - */ +// The search context: +// ffsc_stack_ptr: the stack for the dirs to search +// ffsc_visited_list: the currently active visited list +// ffsc_dir_visited_list: the currently active visited list for search dirs +// ffsc_visited_lists_list: the list of all visited lists +// ffsc_dir_visited_lists_list: the list of all visited lists for search dirs +// ffsc_file_to_search: the file to search for +// ffsc_start_dir: the starting directory, if search path was relative +// ffsc_fix_path: the fix part of the given path (without wildcards) +// Needed for upward search. +// ffsc_wc_path: the part of the given path containing wildcards +// ffsc_level: how many levels of dirs to search downwards +// ffsc_stopdirs_v: array of stop directories for upward search +// ffsc_find_what: FINDFILE_BOTH, FINDFILE_DIR or FINDFILE_FILE +// ffsc_tagfile: searching for tags file, don't use 'suffixesadd' typedef struct ff_search_ctx_T { ff_stack_T *ffsc_stack_ptr; ff_visited_list_hdr_T *ffsc_visited_list; @@ -341,15 +331,13 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i #endif } - /* - * If stopdirs are given, split them into an array of pointers. - * If this fails (mem allocation), there is no upward search at all or a - * stop directory is not recognized -> continue silently. - * If stopdirs just contains a ";" or is empty, - * search_ctx->ffsc_stopdirs_v will only contain a NULL pointer. This - * is handled as unlimited upward search. See function - * ff_path_in_stoplist() for details. - */ + // If stopdirs are given, split them into an array of pointers. + // If this fails (mem allocation), there is no upward search at all or a + // stop directory is not recognized -> continue silently. + // If stopdirs just contains a ";" or is empty, + // search_ctx->ffsc_stopdirs_v will only contain a NULL pointer. This + // is handled as unlimited upward search. See function + // ff_path_in_stoplist() for details. if (stopdirs != NULL) { char *walker = stopdirs; @@ -401,15 +389,13 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i assert(wc_part - path >= 0); search_ctx->ffsc_fix_path = xstrnsave(path, (size_t)(wc_part - path)); - /* - * copy wc_path and add restricts to the '**' wildcard. - * The octet after a '**' is used as a (binary) counter. - * So '**3' is transposed to '**^C' ('^C' is ASCII value 3) - * or '**76' is transposed to '**N'( 'N' is ASCII value 76). - * If no restrict is given after '**' the default is used. - * Due to this technique the path looks awful if you print it as a - * string. - */ + // copy wc_path and add restricts to the '**' wildcard. + // The octet after a '**' is used as a (binary) counter. + // So '**3' is transposed to '**^C' ('^C' is ASCII value 3) + // or '**76' is transposed to '**N'( 'N' is ASCII value 76). + // If no restrict is given after '**' the default is used. + // Due to this technique the path looks awful if you print it as a + // string. len = 0; while (*wc_part != NUL) { if (len + 5 >= MAXPATHL) { @@ -513,11 +499,9 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i return search_ctx; error_return: - /* - * We clear the search context now! - * Even when the caller gave us a (perhaps valid) context we free it here, - * as we might have already destroyed it. - */ + // We clear the search context now! + // Even when the caller gave us a (perhaps valid) context we free it here, + // as we might have already destroyed it. vim_findfile_cleanup(search_ctx); return NULL; } @@ -587,10 +571,8 @@ char_u *vim_findfile(void *search_ctx_arg) search_ctx = (ff_search_ctx_T *)search_ctx_arg; - /* - * filepath is used as buffer for various actions and as the storage to - * return a found filename. - */ + // filepath is used as buffer for various actions and as the storage to + // return a found filename. file_path = xmalloc(MAXPATHL); // store the end of the start dir -- needed for upward search @@ -614,25 +596,23 @@ char_u *vim_findfile(void *search_ctx_arg) break; } - /* - * TODO: decide if we leave this test in - * - * GOOD: don't search a directory(-tree) twice. - * BAD: - check linked list for every new directory entered. - * - check for double files also done below - * - * Here we check if we already searched this directory. - * We already searched a directory if: - * 1) The directory is the same. - * 2) We would use the same wildcard string. - * - * Good if you have links on same directory via several ways - * or you have selfreferences in directories (e.g. SuSE Linux 6.3: - * /etc/rc.d/init.d is linked to /etc/rc.d -> endless loop) - * - * This check is only needed for directories we work on for the - * first time (hence stackp->ff_filearray == NULL) - */ + // TODO(vim): decide if we leave this test in + // + // GOOD: don't search a directory(-tree) twice. + // BAD: - check linked list for every new directory entered. + // - check for double files also done below + // + // Here we check if we already searched this directory. + // We already searched a directory if: + // 1) The directory is the same. + // 2) We would use the same wildcard string. + // + // Good if you have links on same directory via several ways + // or you have selfreferences in directories (e.g. SuSE Linux 6.3: + // /etc/rc.d/init.d is linked to /etc/rc.d -> endless loop) + // + // This check is only needed for directories we work on for the + // first time (hence stackp->ff_filearray == NULL) if (stackp->ffs_filearray == NULL && ff_check_visited(&search_ctx->ffsc_dir_visited_list->ffvl_visited_list, stackp->ffs_fix_path, stackp->ffs_wc_path) == FAIL) { @@ -666,12 +646,10 @@ char_u *vim_findfile(void *search_ctx_arg) file_path[0] = NUL; - /* - * If no filearray till now expand wildcards - * The function expand_wildcards() can handle an array of paths - * and all possible expands are returned in one array. We use this - * to handle the expansion of '**' into an empty string. - */ + // If no filearray till now expand wildcards + // The function expand_wildcards() can handle an array of paths + // and all possible expands are returned in one array. We use this + // to handle the expansion of '**' into an empty string. if (stackp->ffs_filearray == NULL) { char *dirptrs[2]; @@ -737,13 +715,11 @@ char_u *vim_findfile(void *search_ctx_arg) } } - /* - * Here we copy until the next path separator or the end of - * the path. If we stop at a path separator, there is - * still something else left. This is handled below by - * pushing every directory returned from expand_wildcards() - * on the stack again for further search. - */ + // Here we copy until the next path separator or the end of + // the path. If we stop at a path separator, there is + // still something else left. This is handled below by + // pushing every directory returned from expand_wildcards() + // on the stack again for further search. while (*rest_of_wildcards && !vim_ispathsep(*rest_of_wildcards)) { if (len + 1 >= MAXPATHL) { @@ -759,10 +735,8 @@ char_u *vim_findfile(void *search_ctx_arg) } } - /* - * Expand wildcards like "*" and "$VAR". - * If the path is a URL don't try this. - */ + // Expand wildcards like "*" and "$VAR". + // If the path is a URL don't try this. if (path_with_url(dirptrs[0])) { stackp->ffs_filearray = xmalloc(sizeof(char *)); stackp->ffs_filearray[0] = xstrdup(dirptrs[0]); @@ -786,10 +760,8 @@ char_u *vim_findfile(void *search_ctx_arg) if (stackp->ffs_stage == 0) { // this is the first time we work on this directory if (*rest_of_wildcards == NUL) { - /* - * We don't have further wildcards to expand, so we have to - * check for the final file now. - */ + // We don't have further wildcards to expand, so we have to + // check for the final file now. for (int i = stackp->ffs_filearray_cur; i < stackp->ffs_filearray_size; i++) { if (!path_with_url(stackp->ffs_filearray[i]) && !os_isdir(stackp->ffs_filearray[i])) { @@ -808,10 +780,8 @@ char_u *vim_findfile(void *search_ctx_arg) } STRCAT(file_path, search_ctx->ffsc_file_to_search); - /* - * Try without extra suffix and then with suffixes - * from 'suffixesadd'. - */ + // Try without extra suffix and then with suffixes + // from 'suffixesadd'. len = STRLEN(file_path); if (search_ctx->ffsc_tagfile) { suf = ""; @@ -894,10 +864,8 @@ char_u *vim_findfile(void *search_ctx_arg) stackp->ffs_stage = 1; } - /* - * if wildcards contains '**' we have to descent till we reach the - * leaves of the directory tree. - */ + // if wildcards contains '**' we have to descent till we reach the + // leaves of the directory tree. if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) { for (int i = stackp->ffs_filearray_cur; i < stackp->ffs_filearray_size; i++) { @@ -1048,9 +1016,7 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, } #endif - /* - * if we reach this we didn't find a list and we have to allocate new list - */ + // if we reach this we didn't find a list and we have to allocate new list retptr = xmalloc(sizeof(*retptr)); retptr->ffvl_visited_list = NULL; @@ -1136,9 +1102,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * } } - /* - * New file/dir. Add it to the list of visited files/dirs. - */ + // New file/dir. Add it to the list of visited files/dirs. vp = xmalloc(sizeof(ff_visited_T) + STRLEN(ff_expand_buffer)); if (!url) { @@ -1434,11 +1398,9 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first || (ff_file_to_find[0] != NUL && ff_file_to_find[1] == ':') #endif ) { - /* - * Absolute path, no need to use "path_option". - * If this is not a first call, return NULL. We already returned a - * filename on the first call. - */ + // Absolute path, no need to use "path_option". + // If this is not a first call, return NULL. We already returned a + // filename on the first call. if (first == true) { if (path_with_url((char *)ff_file_to_find)) { file_name = vim_strsave(ff_file_to_find); @@ -1483,11 +1445,9 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first } } } else { - /* - * Loop over all paths in the 'path' or 'cdpath' option. - * When "first" is set, first setup to the start of the option. - * Otherwise continue to find the next match. - */ + // Loop over all paths in the 'path' or 'cdpath' option. + // When "first" is set, first setup to the start of the option. + // Otherwise continue to find the next match. if (first == true) { // vim_findfile_free_visited can handle a possible NULL pointer vim_findfile_free_visited(fdip_search_ctx); diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 889e569672..a29a0efe40 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -90,9 +90,7 @@ * with iconv() to be able to allocate a buffer. */ #define ICONV_MULT 8 -/* - * Structure to pass arguments from buf_write() to buf_write_bytes(). - */ +// Structure to pass arguments from buf_write() to buf_write_bytes(). struct bw_info { int bw_fd; // file descriptor char_u *bw_buf; // buffer with data to be written @@ -257,12 +255,10 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, curbuf->b_no_eol_lnum = 0; // in case it was set by the previous read - /* - * If there is no file name yet, use the one for the read file. - * BF_NOTEDITED is set to reflect this. - * Don't do this for a read from a filter. - * Only do this when 'cpoptions' contains the 'f' flag. - */ + // If there is no file name yet, use the one for the read file. + // BF_NOTEDITED is set to reflect this. + // Don't do this for a read from a filter. + // Only do this when 'cpoptions' contains the 'f' flag. if (curbuf->b_ffname == NULL && !filtering && fname != NULL @@ -401,12 +397,10 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, // Set default or forced 'fileformat' and 'binary'. set_file_options(set_options, eap); - /* - * When opening a new file we take the readonly flag from the file. - * Default is r/w, can be set to r/o below. - * Don't reset it when in readonly mode - * Only set/reset b_p_ro when BF_CHECK_RO is set. - */ + // When opening a new file we take the readonly flag from the file. + // Default is r/w, can be set to r/o below. + // Don't reset it when in readonly mode + // Only set/reset b_p_ro when BF_CHECK_RO is set. check_readonly = (newfile && (curbuf->b_flags & BF_CHECK_RO)); if (check_readonly && !readonlymode) { curbuf->b_p_ro = false; @@ -419,17 +413,15 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, curbuf->b_mtime_read = curbuf->b_mtime; curbuf->b_mtime_read_ns = curbuf->b_mtime_ns; #ifdef UNIX - /* - * Use the protection bits of the original file for the swap file. - * This makes it possible for others to read the name of the - * edited file from the swapfile, but only if they can read the - * edited file. - * Remove the "write" and "execute" bits for group and others - * (they must not write the swapfile). - * Add the "read" and "write" bits for the user, otherwise we may - * not be able to write to the file ourselves. - * Setting the bits is done below, after creating the swap file. - */ + // Use the protection bits of the original file for the swap file. + // This makes it possible for others to read the name of the + // edited file from the swapfile, but only if they can read the + // edited file. + // Remove the "write" and "execute" bits for group and others + // (they must not write the swapfile). + // Add the "read" and "write" bits for the user, otherwise we may + // not be able to write to the file ourselves. + // Setting the bits is done below, after creating the swap file. swap_mode = ((int)file_info.stat.st_mode & 0644) | 0600; #endif } else { @@ -520,10 +512,8 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, return FAIL; } - /* - * Only set the 'ro' flag for readonly files the first time they are - * loaded. Help files always get readonly mode - */ + // Only set the 'ro' flag for readonly files the first time they are + // loaded. Help files always get readonly mode if ((check_readonly && file_readonly) || curbuf->b_help) { curbuf->b_p_ro = true; } @@ -645,13 +635,11 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, curbuf->b_p_ro = true; // must use "w!" now return FAIL; } - /* - * Don't allow the autocommands to change the current buffer. - * Try to re-open the file. - * - * Don't allow the autocommands to change the buffer name either - * (cd for example) if it invalidates fname or sfname. - */ + // Don't allow the autocommands to change the current buffer. + // Try to re-open the file. + // + // Don't allow the autocommands to change the buffer name either + // (cd for example) if it invalidates fname or sfname. if (!read_stdin && (curbuf != old_curbuf || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) || (using_b_fname && (old_b_fname != curbuf->b_fname)) @@ -679,10 +667,8 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, msg_scroll = false; // overwrite the file message - /* - * Set linecnt now, before the "retry" caused by a wrong guess for - * fileformat, and after the autocommands, which may change them. - */ + // Set linecnt now, before the "retry" caused by a wrong guess for + // fileformat, and after the autocommands, which may change them. linecnt = curbuf->b_ml.ml_line_count; // "++bad=" argument. @@ -695,9 +681,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, curbuf->b_bad_char = 0; } - /* - * Decide which 'encoding' to use or use first. - */ + // Decide which 'encoding' to use or use first. if (eap != NULL && eap->force_enc != 0) { fenc = enc_canonize(eap->cmd + eap->force_enc); fenc_alloced = true; @@ -722,25 +706,23 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, fenc = next_fenc(&fenc_next, &fenc_alloced); } - /* - * Jump back here to retry reading the file in different ways. - * Reasons to retry: - * - encoding conversion failed: try another one from "fenc_next" - * - BOM detected and fenc was set, need to setup conversion - * - "fileformat" check failed: try another - * - * Variables set for special retry actions: - * "file_rewind" Rewind the file to start reading it again. - * "advance_fenc" Advance "fenc" using "fenc_next". - * "skip_read" Re-use already read bytes (BOM detected). - * "did_iconv" iconv() conversion failed, try 'charconvert'. - * "keep_fileformat" Don't reset "fileformat". - * - * Other status indicators: - * "tmpname" When != NULL did conversion with 'charconvert'. - * Output file has to be deleted afterwards. - * "iconv_fd" When != -1 did conversion with iconv(). - */ + // Jump back here to retry reading the file in different ways. + // Reasons to retry: + // - encoding conversion failed: try another one from "fenc_next" + // - BOM detected and fenc was set, need to setup conversion + // - "fileformat" check failed: try another + // + // Variables set for special retry actions: + // "file_rewind" Rewind the file to start reading it again. + // "advance_fenc" Advance "fenc" using "fenc_next". + // "skip_read" Re-use already read bytes (BOM detected). + // "did_iconv" iconv() conversion failed, try 'charconvert'. + // "keep_fileformat" Don't reset "fileformat". + // + // Other status indicators: + // "tmpname" When != NULL did conversion with 'charconvert'. + // Output file has to be deleted afterwards. + // "iconv_fd" When != -1 did conversion with iconv(). retry: if (file_rewind) { @@ -764,10 +746,8 @@ retry: conv_error = 0; } - /* - * When retrying with another "fenc" and the first time "fileformat" - * will be reset. - */ + // When retrying with another "fenc" and the first time "fileformat" + // will be reset. if (keep_fileformat) { keep_fileformat = false; } else { @@ -793,9 +773,7 @@ retry: #endif if (advance_fenc) { - /* - * Try the next entry in 'fileencodings'. - */ + // Try the next entry in 'fileencodings'. advance_fenc = false; if (eap != NULL && eap->force_enc != 0) { @@ -825,10 +803,8 @@ retry: } } - /* - * Conversion may be required when the encoding of the file is different - * from 'encoding' or 'encoding' is UTF-16, UCS-2 or UCS-4. - */ + // Conversion may be required when the encoding of the file is different + // from 'encoding' or 'encoding' is UTF-16, UCS-2 or UCS-4. fio_flags = 0; converted = need_conversion((char_u *)fenc); if (converted) { @@ -855,10 +831,8 @@ retry: } #endif - /* - * Use the 'charconvert' expression when conversion is required - * and we can't do it internally or with iconv(). - */ + // Use the 'charconvert' expression when conversion is required + // and we can't do it internally or with iconv(). if (fio_flags == 0 && !read_stdin && !read_buffer && *p_ccv != NUL && !read_fifo #ifdef HAVE_ICONV @@ -922,12 +896,10 @@ retry: } while (!error && !got_int) { - /* - * We allocate as much space for the file as we can get, plus - * space for the old line plus room for one terminating NUL. - * The amount is limited by the fact that read() only can read - * up to max_unsigned characters (and other things). - */ + // We allocate as much space for the file as we can get, plus + // space for the old line plus room for one terminating NUL. + // The amount is limited by the fact that read() only can read + // up to max_unsigned characters (and other things). { if (!skip_read) { // Use buffer >= 64K. Add linerest to double the size if the @@ -999,10 +971,8 @@ retry: } if (read_buffer) { - /* - * Read bytes from curbuf. Used for converting text read - * from stdin. - */ + // Read bytes from curbuf. Used for converting text read + // from stdin. if (read_buf_lnum > from) { size = 0; } else { @@ -1052,9 +1022,7 @@ retry: } } } else { - /* - * Read bytes from the file. - */ + // Read bytes from the file. size = read_eintr(fd, ptr, (size_t)size); } @@ -1062,10 +1030,8 @@ retry: if (size < 0) { // read error error = true; } else if (conv_restlen > 0) { - /* - * Reached end-of-file but some trailing bytes could - * not be converted. Truncated file? - */ + // Reached end-of-file but some trailing bytes could + // not be converted. Truncated file? // When we did a conversion report an error. if (fio_flags != 0 @@ -1118,12 +1084,10 @@ retry: skip_read = false; - /* - * At start of file: Check for BOM. - * Also check for a BOM for other Unicode encodings, but not after - * converting with 'charconvert' or when a BOM has already been - * found. - */ + // At start of file: Check for BOM. + // Also check for a BOM for other Unicode encodings, but not after + // converting with 'charconvert' or when a BOM has already been + // found. if ((filesize == 0) && (fio_flags == FIO_UCSBOM || (!curbuf->b_p_bomb @@ -1172,9 +1136,7 @@ retry: ptr -= conv_restlen; size += conv_restlen; conv_restlen = 0; - /* - * Break here for a read error or end-of-file. - */ + // Break here for a read error or end-of-file. if (size <= 0) { break; } @@ -1188,11 +1150,9 @@ retry: char *top = ptr; size_t to_size = (size_t)(real_size - size); - /* - * If there is conversion error or not enough room try using - * another conversion. Except for when there is no - * alternative (help files). - */ + // If there is conversion error or not enough room try using + // another conversion. Except for when there is no + // alternative (help files). while ((iconv(iconv_fd, (void *)&fromp, &from_size, &top, &to_size) == (size_t)-1 && ICONV_ERRNO != ICONV_EINVAL) @@ -1493,9 +1453,7 @@ rewind_retry: // count the number of characters (after conversion!) filesize += size; - /* - * when reading the first part of a file: guess EOL type - */ + // when reading the first part of a file: guess EOL type if (fileformat == EOL_UNKNOWN) { // First try finding a NL, for Dos and Unix if (try_dos || try_unix) { @@ -1560,10 +1518,8 @@ rewind_retry: } } - /* - * This loop is executed once for every character read. - * Keep it fast! - */ + // This loop is executed once for every character read. + // Keep it fast! if (fileformat == EOL_MAC) { ptr--; while (++ptr, --size >= 0) { @@ -1665,11 +1621,9 @@ failed: error = false; } - /* - * If we get EOF in the middle of a line, note the fact and - * complete the line ourselves. - * In Dos format ignore a trailing CTRL-Z, unless 'binary' set. - */ + // If we get EOF in the middle of a line, note the fact and + // complete the line ourselves. + // In Dos format ignore a trailing CTRL-Z, unless 'binary' set. if (!error && !got_int && linerest != 0 @@ -1738,9 +1692,7 @@ failed: } no_wait_return--; // may wait for return now - /* - * In recovery mode everything but autocommands is skipped. - */ + // In recovery mode everything but autocommands is skipped. if (!recoverymode) { // need to delete the last line, which comes from the empty buffer if (newfile && wasempty && !(curbuf->b_ml.ml_flags & ML_EMPTY)) { @@ -1767,11 +1719,9 @@ failed: appended_lines_mark(from, linecnt); } - /* - * If we were reading from the same terminal as where messages go, - * the screen will have been messed up. - * Switch on raw mode now and clear the screen. - */ + // If we were reading from the same terminal as where messages go, + // the screen will have been messed up. + // Switch on raw mode now and clear the screen. if (read_stdin) { screenclear(); } @@ -1878,10 +1828,8 @@ failed: u_clearline(); // cannot use "U" command after adding lines - /* - * In Ex mode: cursor at last new line. - * Otherwise: cursor at first new line. - */ + // In Ex mode: cursor at last new line. + // Otherwise: cursor at first new line. if (exmode_active) { curwin->w_cursor.lnum = from + linecnt; } else { @@ -1900,17 +1848,13 @@ failed: } msg_scroll = msg_save; - /* - * Get the marks before executing autocommands, so they can be used there. - */ + // Get the marks before executing autocommands, so they can be used there. check_marks_read(); - /* - * We remember if the last line of the read didn't have - * an eol even when 'binary' is off, to support turning 'fixeol' off, - * or writing the read again with 'binary' on. The latter is required - * for ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work. - */ + // We remember if the last line of the read didn't have + // an eol even when 'binary' is off, to support turning 'fixeol' off, + // or writing the read again with 'binary' on. The latter is required + // for ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work. curbuf->b_no_eol_lnum = read_no_eol_lnum; // When reloading a buffer put the cursor at the first line that is @@ -1919,9 +1863,7 @@ failed: u_find_first_changed(); } - /* - * When opening a new file locate undo info and read it. - */ + // When opening a new file locate undo info and read it. if (read_undo_file) { char_u hash[UNDO_HASH_SIZE]; @@ -1939,11 +1881,9 @@ failed: save_file_ff(curbuf); } - /* - * The output from the autocommands should not overwrite anything and - * should not be overwritten: Set msg_scroll, restore its value if no - * output was done. - */ + // The output from the autocommands should not overwrite anything and + // should not be overwritten: Set msg_scroll, restore its value if no + // output was done. msg_scroll = true; if (filtering) { apply_autocmds_exarg(EVENT_FILTERREADPOST, NULL, sfname, @@ -2256,10 +2196,8 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en return FAIL; } - /* - * Disallow writing from .exrc and .vimrc in current directory for - * security reasons. - */ + // Disallow writing from .exrc and .vimrc in current directory for + // security reasons. if (check_secure()) { return FAIL; } @@ -2283,13 +2221,11 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en * the line. */ ex_no_reprint = true; - /* - * If there is no file name yet, use the one for the written file. - * BF_NOTEDITED is set to reflect this (in case the write fails). - * Don't do this when the write is for a filter command. - * Don't do this when appending. - * Only do this when 'cpoptions' contains the 'F' flag. - */ + // If there is no file name yet, use the one for the written file. + // BF_NOTEDITED is set to reflect this (in case the write fails). + // Don't do this when the write is for a filter command. + // Don't do this when appending. + // Only do this when 'cpoptions' contains the 'F' flag. if (buf->b_ffname == NULL && reset_changed && whole @@ -2325,9 +2261,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en no_wait_return++; // don't wait for return yet - /* - * Set '[ and '] marks to the lines to be written. - */ + // Set '[ and '] marks to the lines to be written. buf->b_op_start.lnum = start; buf->b_op_start.col = 0; buf->b_op_end.lnum = end; @@ -2344,11 +2278,9 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en int empty_memline = (buf->b_ml.ml_mfp == NULL); bufref_T bufref; - /* - * Apply PRE autocommands. - * Set curbuf to the buffer to be written. - * Careful: The autocommands may call buf_write() recursively! - */ + // Apply PRE autocommands. + // Set curbuf to the buffer to be written. + // Careful: The autocommands may call buf_write() recursively! if (ffname == buf->b_ffname) { buf_ffname = true; } @@ -2471,12 +2403,10 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en return FAIL; } - /* - * The autocommands may have changed the number of lines in the file. - * When writing the whole file, adjust the end. - * When writing part of the file, assume that the autocommands only - * changed the number of lines that are to be written (tricky!). - */ + // The autocommands may have changed the number of lines in the file. + // When writing the whole file, adjust the end. + // When writing part of the file, assume that the autocommands only + // changed the number of lines that are to be written (tricky!). if (buf->b_ml.ml_line_count != old_line_count) { if (whole) { // write all end = buf->b_ml.ml_line_count; @@ -2493,10 +2423,8 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en } } - /* - * The autocommands may have changed the name of the buffer, which may - * be kept in fname, ffname and sfname. - */ + // The autocommands may have changed the name of the buffer, which may + // be kept in fname, ffname and sfname. if (buf_ffname) { ffname = buf->b_ffname; } @@ -2543,9 +2471,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en bufsize = BUFSIZE; } - /* - * Get information about original file (if there is one). - */ + // Get information about original file (if there is one). FileInfo file_info_old; #if defined(UNIX) perm = -1; @@ -2595,10 +2521,8 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en #endif // !UNIX if (!device && !newfile) { - /* - * Check if the file is really writable (when renaming the file to - * make a backup we won't discover it later). - */ + // Check if the file is really writable (when renaming the file to + // make a backup we won't discover it later). file_readonly = !os_file_is_writable(fname); if (!forceit && file_readonly) { @@ -2610,9 +2534,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en goto fail; } - /* - * Check if the timestamp hasn't changed since reading the file. - */ + // Check if the timestamp hasn't changed since reading the file. if (overwriting) { retval = check_mtime(buf, &file_info_old); if (retval == FAIL) { @@ -2622,41 +2544,33 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en } #ifdef HAVE_ACL - /* - * For systems that support ACL: get the ACL from the original file. - */ + // For systems that support ACL: get the ACL from the original file. if (!newfile) { acl = mch_get_acl((char_u *)fname); } #endif - /* - * If 'backupskip' is not empty, don't make a backup for some files. - */ + // If 'backupskip' is not empty, don't make a backup for some files. dobackup = (p_wb || p_bk || *p_pm != NUL); if (dobackup && *p_bsk != NUL && match_file_list(p_bsk, (char_u *)sfname, (char_u *)ffname)) { dobackup = false; } - /* - * Save the value of got_int and reset it. We don't want a previous - * interruption cancel writing, only hitting CTRL-C while writing should - * abort it. - */ + // Save the value of got_int and reset it. We don't want a previous + // interruption cancel writing, only hitting CTRL-C while writing should + // abort it. prev_got_int = got_int; got_int = false; // Mark the buffer as 'being saved' to prevent changed buffer warnings buf->b_saving = true; - /* - * If we are not appending or filtering, the file exists, and the - * 'writebackup', 'backup' or 'patchmode' option is set, need a backup. - * When 'patchmode' is set also make a backup when appending. - * - * Do not make any backup, if 'writebackup' and 'backup' are both switched - * off. This helps when editing large files on almost-full disks. - */ + // If we are not appending or filtering, the file exists, and the + // 'writebackup', 'backup' or 'patchmode' option is set, need a backup. + // When 'patchmode' is set also make a backup when appending. + // + // Do not make any backup, if 'writebackup' and 'backup' are both switched + // off. This helps when editing large files on almost-full disks. if (!(append && *p_pm == NUL) && !filtering && perm >= 0 && dobackup) { FileInfo file_info; const bool no_prepend_dot = false; @@ -2666,23 +2580,19 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en } else if ((bkc & BKC_AUTO)) { // "auto" int i; - /* - * Don't rename the file when: - * - it's a hard link - * - it's a symbolic link - * - we don't have write permission in the directory - */ + // Don't rename the file when: + // - it's a hard link + // - it's a symbolic link + // - we don't have write permission in the directory if (os_fileinfo_hardlinks(&file_info_old) > 1 || !os_fileinfo_link(fname, &file_info) || !os_fileinfo_id_equal(&file_info, &file_info_old)) { backup_copy = true; } else { - /* - * Check if we can create a file and set the owner/group to - * the ones from the original file. - * First find a file name that doesn't exist yet (use some - * arbitrary numbers). - */ + // Check if we can create a file and set the owner/group to + // the ones from the original file. + // First find a file name that doesn't exist yet (use some + // arbitrary numbers). STRCPY(IObuff, fname); for (i = 4913;; i += 123) { char *tail = path_tail((char *)IObuff); @@ -2714,9 +2624,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en } } - /* - * Break symlinks and/or hardlinks if we've been asked to. - */ + // Break symlinks and/or hardlinks if we've been asked to. if ((bkc & BKC_BREAKSYMLINK) || (bkc & BKC_BREAKHARDLINK)) { #ifdef UNIX bool file_info_link_ok = os_fileinfo_link(fname, &file_info); @@ -2752,23 +2660,19 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en char *rootname; char *p; - /* - * Try to make the backup in each directory in the 'bdir' option. - * - * Unix semantics has it, that we may have a writable file, - * that cannot be recreated with a simple open(..., O_CREAT, ) e.g: - * - the directory is not writable, - * - the file may be a symbolic link, - * - the file may belong to another user/group, etc. - * - * For these reasons, the existing writable file must be truncated - * and reused. Creation of a backup COPY will be attempted. - */ + // Try to make the backup in each directory in the 'bdir' option. + // + // Unix semantics has it, that we may have a writable file, + // that cannot be recreated with a simple open(..., O_CREAT, ) e.g: + // - the directory is not writable, + // - the file may be a symbolic link, + // - the file may belong to another user/group, etc. + // + // For these reasons, the existing writable file must be truncated + // and reused. Creation of a backup COPY will be attempted. dirp = p_bdir; while (*dirp) { - /* - * Isolate one directory name, using an entry in 'bdir'. - */ + // Isolate one directory name, using an entry in 'bdir'. size_t dir_len = copy_option_part(&dirp, (char *)IObuff, IOSIZE, ","); p = (char *)IObuff + dir_len; bool trailing_pathseps = after_pathsep((char *)IObuff, p) && p[-1] == p[-2]; @@ -2814,9 +2718,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en goto nobackup; } - /* - * Check if backup file already exists. - */ + // Check if backup file already exists. if (os_fileinfo(backup, &file_info_new)) { if (os_fileinfo_id_equal(&file_info_new, &file_info_old)) { // @@ -2848,9 +2750,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en } xfree(rootname); - /* - * Try to create the backup file - */ + // Try to create the backup file if (backup != NULL) { // remove old backup, if present os_remove(backup); @@ -2906,30 +2806,22 @@ nobackup: char *p; char *rootname; - /* - * Make a backup by renaming the original file. - */ - /* - * If 'cpoptions' includes the "W" flag, we don't want to - * overwrite a read-only file. But rename may be possible - * anyway, thus we need an extra check here. - */ + // Make a backup by renaming the original file. + + // If 'cpoptions' includes the "W" flag, we don't want to + // overwrite a read-only file. But rename may be possible + // anyway, thus we need an extra check here. if (file_readonly && vim_strchr(p_cpo, CPO_FWRITE) != NULL) { SET_ERRMSG_NUM("E504", _(err_readonly)); goto fail; } - /* - * - * Form the backup file name - change path/fo.o.h to - * path/fo.o.h.bak Try all directories in 'backupdir', first one - * that works is used. - */ + // Form the backup file name - change path/fo.o.h to + // path/fo.o.h.bak Try all directories in 'backupdir', first one + // that works is used. dirp = p_bdir; while (*dirp) { - /* - * Isolate one directory name and make the backup file name. - */ + // Isolate one directory name and make the backup file name. size_t dir_len = copy_option_part(&dirp, (char *)IObuff, IOSIZE, ","); p = (char *)IObuff + dir_len; bool trailing_pathseps = after_pathsep((char *)IObuff, p) && p[-1] == p[-2]; @@ -2965,11 +2857,9 @@ nobackup: } if (backup != NULL) { - /* - * If we are not going to keep the backup file, don't - * delete an existing one, try to use another name. - * Change one character, just before the extension. - */ + // If we are not going to keep the backup file, don't + // delete an existing one, try to use another name. + // Change one character, just before the extension. if (!p_bk && os_path_exists(backup)) { p = backup + STRLEN(backup) - 1 - STRLEN(backup_ext); if (p < backup) { // empty file name ??? @@ -3099,11 +2989,9 @@ nobackup: } else { #endif - /* - * When the file needs to be converted with 'charconvert' after - * writing, write to a temp file instead and let the conversion - * overwrite the original file. - */ + // When the file needs to be converted with 'charconvert' after + // writing, write to a temp file instead and let the conversion + // overwrite the original file. if (*p_ccv != NUL) { wfname = (char *)vim_tempname(); if (wfname == NULL) { // Can't write without a tempfile! @@ -3561,10 +3449,8 @@ restore_backup: u_update_save_nr(buf); } - /* - * If written to the current file, update the timestamp of the swap file - * and reset the BF_WRITE_MASK flags. Also sets buf->b_mtime. - */ + // If written to the current file, update the timestamp of the swap file + // and reset the BF_WRITE_MASK flags. Also sets buf->b_mtime. if (overwriting) { ml_timestamp(buf); if (append) { @@ -3574,18 +3460,14 @@ restore_backup: } } - /* - * If we kept a backup until now, and we are in patch mode, then we make - * the backup file our 'original' file. - */ + // If we kept a backup until now, and we are in patch mode, then we make + // the backup file our 'original' file. if (*p_pm && dobackup) { char *const org = modname(fname, p_pm, false); if (backup != NULL) { - /* - * If the original file does not exist yet - * the current backup file becomes the original file - */ + // If the original file does not exist yet + // the current backup file becomes the original file if (org == NULL) { emsg(_("E205: Patchmode: can't save original file")); } else if (!os_path_exists(org)) { @@ -3597,12 +3479,9 @@ restore_backup: (double)file_info_old.stat.st_mtim.tv_sec); #endif } - } - /* - * If there is no backup file, remember that a (new) file was - * created. - */ - else { + } else { + // If there is no backup file, remember that a (new) file was + // created. int empty_fd; if (org == NULL @@ -3620,9 +3499,7 @@ restore_backup: } } - /* - * Remove the backup unless 'backup' option is set - */ + // Remove the backup unless 'backup' option is set if (!p_bk && backup != NULL && !write_info.bw_conv_error && os_remove(backup) != 0) { @@ -3631,9 +3508,7 @@ restore_backup: goto nofail; - /* - * Finish up. We get here either after failure or success. - */ + // Finish up. We get here either after failure or success. fail: no_wait_return--; // may wait for return now nofail: @@ -3698,10 +3573,8 @@ nofail: } msg_scroll = msg_save; - /* - * When writing the whole file and 'undofile' is set, also write the undo - * file. - */ + // When writing the whole file and 'undofile' is set, also write the undo + // file. if (retval == OK && write_undo_file) { char hash[UNDO_HASH_SIZE]; @@ -3714,10 +3587,8 @@ nofail: curbuf->b_no_eol_lnum = 0; // in case it was set by the previous read - /* - * Apply POST autocommands. - * Careful: The autocommands may call buf_write() recursively! - */ + // Apply POST autocommands. + // Careful: The autocommands may call buf_write() recursively! aucmd_prepbuf(&aco, buf); if (append) { @@ -3918,18 +3789,14 @@ static int buf_write_bytes(struct bw_info *ip) int flags = ip->bw_flags; // extra flags #endif - /* - * Skip conversion when writing the BOM. - */ + // Skip conversion when writing the BOM. if (!(flags & FIO_NOCONVERT)) { char_u *p; unsigned c; int n; if (flags & FIO_UTF8) { - /* - * Convert latin1 in the buffer to UTF-8 in the file. - */ + // Convert latin1 in the buffer to UTF-8 in the file. p = ip->bw_conv_buf; // translate to buffer for (wlen = 0; wlen < len; wlen++) { p += utf_char2bytes(buf[wlen], (char *)p); @@ -3937,10 +3804,8 @@ static int buf_write_bytes(struct bw_info *ip) buf = ip->bw_conv_buf; len = (int)(p - ip->bw_conv_buf); } else if (flags & (FIO_UCS4 | FIO_UTF16 | FIO_UCS2 | FIO_LATIN1)) { - /* - * Convert UTF-8 bytes in the buffer to UCS-2, UCS-4, UTF-16 or - * Latin1 chars in the file. - */ + // Convert UTF-8 bytes in the buffer to UCS-2, UCS-4, UTF-16 or + // Latin1 chars in the file. if (flags & FIO_LATIN1) { p = buf; // translate in-place (can only get shorter) } else { @@ -4063,9 +3928,7 @@ static int buf_write_bytes(struct bw_info *ip) ip->bw_first = false; } - /* - * If iconv() has an error or there is not enough room, fail. - */ + // If iconv() has an error or there is not enough room, fail. if ((iconv(ip->bw_iconv_fd, (void *)&from, &fromlen, &to, &tolen) == (size_t)-1 && ICONV_ERRNO != ICONV_EINVAL) || fromlen > CONV_RESTLEN) { @@ -4633,11 +4496,9 @@ int vim_rename(const char_u *from, const char_u *to) #endif bool use_tmp_file = false; - /* - * When the names are identical, there is nothing to do. When they refer - * to the same file (ignoring case and slash/backslash differences) but - * the file name differs we need to go through a temp file. - */ + // When the names are identical, there is nothing to do. When they refer + // to the same file (ignoring case and slash/backslash differences) but + // the file name differs we need to go through a temp file. if (FNAMECMP(from, to) == 0) { if (p_fic && (STRCMP(path_tail((char *)from), path_tail((char *)to)) != 0)) { @@ -4665,10 +4526,8 @@ int vim_rename(const char_u *from, const char_u *to) if (use_tmp_file) { char_u tempname[MAXPATHL + 1]; - /* - * Find a name that doesn't exist and is in the same directory. - * Rename "from" to "tempname" and then rename "tempname" to "to". - */ + // Find a name that doesn't exist and is in the same directory. + // Rename "from" to "tempname" and then rename "tempname" to "to". if (STRLEN(from) >= MAXPATHL - 5) { return -1; } @@ -4695,24 +4554,18 @@ int vim_rename(const char_u *from, const char_u *to) return -1; } - /* - * Delete the "to" file, this is required on some systems to make the - * os_rename() work, on other systems it makes sure that we don't have - * two files when the os_rename() fails. - */ + // Delete the "to" file, this is required on some systems to make the + // os_rename() work, on other systems it makes sure that we don't have + // two files when the os_rename() fails. os_remove((char *)to); - /* - * First try a normal rename, return if it works. - */ + // First try a normal rename, return if it works. if (os_rename(from, to) == OK) { return 0; } - /* - * Rename() failed, try copying the file. - */ + // Rename() failed, try copying the file. perm = os_getperm((const char *)from); #ifdef HAVE_ACL // For systems that support ACL: get the ACL from the original file. @@ -5553,12 +5406,10 @@ bool match_file_pat(char *pattern, regprog_T **prog, char *fname, char *sfname, } } - /* - * Try for a match with the pattern with: - * 1. the full file name, when the pattern has a '/'. - * 2. the short file name, when the pattern has a '/'. - * 3. the tail of the file name, when the pattern has no '/'. - */ + // Try for a match with the pattern with: + // 1. the full file name, when the pattern has a '/'. + // 2. the short file name, when the pattern has a '/'. + // 3. the tail of the file name, when the pattern has no '/'. if (regmatch.regprog != NULL && ((allow_dirs && (vim_regexec(®match, fname, (colnr_T)0) diff --git a/src/nvim/fold.h b/src/nvim/fold.h index f34e6d43c3..395cd8e30a 100644 --- a/src/nvim/fold.h +++ b/src/nvim/fold.h @@ -8,10 +8,8 @@ #include "nvim/pos.h" #include "nvim/types.h" -/* - * Info used to pass info about a fold from the fold-detection code to the - * code that displays the foldcolumn. - */ +// Info used to pass info about a fold from the fold-detection code to the +// code that displays the foldcolumn. typedef struct foldinfo { linenr_T fi_lnum; // line number where fold starts int fi_level; // level of the fold; when this is zero the diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 97c3b1c61f..22c350d36b 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -87,25 +87,23 @@ static int block_redo = false; static int KeyNoremap = 0; // remapping flags -/* - * Variables used by vgetorpeek() and flush_buffers() - * - * typebuf.tb_buf[] contains all characters that are not consumed yet. - * typebuf.tb_buf[typebuf.tb_off] is the first valid character. - * typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1] is the last valid char. - * typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len] must be NUL. - * The head of the buffer may contain the result of mappings, abbreviations - * and @a commands. The length of this part is typebuf.tb_maplen. - * typebuf.tb_silent is the part where applies. - * After the head are characters that come from the terminal. - * typebuf.tb_no_abbr_cnt is the number of characters in typebuf.tb_buf that - * should not be considered for abbreviations. - * Some parts of typebuf.tb_buf may not be mapped. These parts are remembered - * in typebuf.tb_noremap[], which is the same length as typebuf.tb_buf and - * contains RM_NONE for the characters that are not to be remapped. - * typebuf.tb_noremap[typebuf.tb_off] is the first valid flag. - * (typebuf has been put in globals.h, because check_termcode() needs it). - */ +// Variables used by vgetorpeek() and flush_buffers() +// +// typebuf.tb_buf[] contains all characters that are not consumed yet. +// typebuf.tb_buf[typebuf.tb_off] is the first valid character. +// typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1] is the last valid char. +// typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len] must be NUL. +// The head of the buffer may contain the result of mappings, abbreviations +// and @a commands. The length of this part is typebuf.tb_maplen. +// typebuf.tb_silent is the part where applies. +// After the head are characters that come from the terminal. +// typebuf.tb_no_abbr_cnt is the number of characters in typebuf.tb_buf that +// should not be considered for abbreviations. +// Some parts of typebuf.tb_buf may not be mapped. These parts are remembered +// in typebuf.tb_noremap[], which is the same length as typebuf.tb_buf and +// contains RM_NONE for the characters that are not to be remapped. +// typebuf.tb_noremap[typebuf.tb_off] is the first valid flag. +// (typebuf has been put in globals.h, because check_termcode() needs it). #define RM_YES 0 // tb_noremap: remap #define RM_NONE 1 // tb_noremap: don't remap #define RM_SCRIPT 2 // tb_noremap: remap local script mappings @@ -124,9 +122,7 @@ static size_t last_recorded_len = 0; // number of last recorded chars # include "getchar.c.generated.h" #endif -/* - * Free and clear a buffer. - */ +// Free and clear a buffer. void free_buff(buffheader_T *buf) { buffblock_T *p, *np; @@ -180,20 +176,16 @@ char_u *get_recorded(void) p = get_buffcont(&recordbuff, true); free_buff(&recordbuff); - /* - * Remove the characters that were added the last time, these must be the - * (possibly mapped) characters that stopped the recording. - */ + // Remove the characters that were added the last time, these must be the + // (possibly mapped) characters that stopped the recording. len = STRLEN(p); if (len >= last_recorded_len) { len -= last_recorded_len; p[len] = NUL; } - /* - * When stopping recording from Insert mode with CTRL-O q, also remove the - * CTRL-O. - */ + // When stopping recording from Insert mode with CTRL-O q, also remove the + // CTRL-O. if (len > 0 && restart_edit != 0 && p[len - 1] == Ctrl_O) { p[len - 1] = NUL; } @@ -351,9 +343,7 @@ static int read_readbuf(buffheader_T *buf, int advance) return c; } -/* - * Prepare the read buffers for reading (if they contain something). - */ +// Prepare the read buffers for reading (if they contain something). static void start_stuff(void) { if (readbuf1.bh_first.b_next != NULL) { @@ -381,19 +371,15 @@ int readbuf1_empty(void) return (readbuf1.bh_first.b_next == NULL); } -/* - * Set a typeahead character that won't be flushed. - */ +// Set a typeahead character that won't be flushed. void typeahead_noflush(int c) { typeahead_char = c; } -/* - * Remove the contents of the stuff buffer and the mapped characters in the - * typeahead buffer (used in case of an error). If "flush_typeahead" is true, - * flush all typeahead characters (used when interrupted by a CTRL-C). - */ +// Remove the contents of the stuff buffer and the mapped characters in the +// typeahead buffer (used in case of an error). If "flush_typeahead" is true, +// flush all typeahead characters (used when interrupted by a CTRL-C). void flush_buffers(flush_buffers_T flush_typeahead) { init_typebuf(); @@ -437,10 +423,8 @@ void beep_flush(void) } } -/* - * The previous contents of the redo buffer is kept in old_redobuffer. - * This is used for the CTRL-O <.> command in insert mode. - */ +// The previous contents of the redo buffer is kept in old_redobuffer. +// This is used for the CTRL-O <.> command in insert mode. void ResetRedobuff(void) { if (!block_redo) { @@ -450,10 +434,8 @@ void ResetRedobuff(void) } } -/* - * Discard the contents of the redo buffer and restore the previous redo - * buffer. - */ +// Discard the contents of the redo buffer and restore the previous redo +// buffer. void CancelRedo(void) { if (!block_redo) { @@ -559,9 +541,7 @@ void AppendCharToRedobuff(int c) } } -/* - * Append a number to the redo buffer. - */ +// Append a number to the redo buffer. void AppendNumberToRedobuff(long n) { if (!block_redo) { @@ -615,9 +595,7 @@ void stuffcharReadbuff(int c) add_char_buff(&readbuf1, c); } -/* - * Append a number to the stuff buffer. - */ +// Append a number to the stuff buffer. void stuffnumReadbuff(long n) { add_num_buff(&readbuf1, n); @@ -783,11 +761,9 @@ int start_redo(long count, bool old_redo) return OK; } -/* - * Repeat the last insert (R, o, O, a, A, i or I command) by stuffing - * the redo buffer into readbuf2. - * return FAIL for failure, OK otherwise - */ +// Repeat the last insert (R, o, O, a, A, i or I command) by stuffing +// the redo buffer into readbuf2. +// return FAIL for failure, OK otherwise int start_redo_ins(void) { int c; @@ -818,11 +794,9 @@ void stop_redo_ins(void) block_redo = false; } -/* - * Initialize typebuf.tb_buf to point to typebuf_init. - * alloc() cannot be used here: In out-of-memory situations it would - * be impossible to type anything. - */ +// Initialize typebuf.tb_buf to point to typebuf_init. +// alloc() cannot be used here: In out-of-memory situations it would +// be impossible to type anything. static void init_typebuf(void) { if (typebuf.tb_buf == NULL) { @@ -939,14 +913,12 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) val = RM_NONE; } - /* - * Adjust typebuf.tb_noremap[] for the new characters: - * If noremap == REMAP_NONE or REMAP_SCRIPT: new characters are - * (sometimes) not remappable - * If noremap == REMAP_YES: all the new characters are mappable - * If noremap > 0: "noremap" characters are not remappable, the rest - * mappable - */ + // Adjust typebuf.tb_noremap[] for the new characters: + // If noremap == REMAP_NONE or REMAP_SCRIPT: new characters are + // (sometimes) not remappable + // If noremap == REMAP_YES: all the new characters are mappable + // If noremap > 0: "noremap" characters are not remappable, the rest + // mappable if (noremap == REMAP_SKIP) { nrm = 1; } else if (noremap < 0) { @@ -1016,18 +988,14 @@ int typebuf_typed(void) return typebuf.tb_maplen == 0; } -/* - * Return the number of characters that are mapped (or not typed). - */ +// Return the number of characters that are mapped (or not typed). int typebuf_maplen(void) FUNC_ATTR_PURE { return typebuf.tb_maplen; } -/* - * remove "len" characters from typebuf.tb_buf[typebuf.tb_off + offset] - */ +// remove "len" characters from typebuf.tb_buf[typebuf.tb_off + offset] void del_typebuf(int len, int offset) { int i; @@ -1038,21 +1006,14 @@ void del_typebuf(int len, int offset) typebuf.tb_len -= len; - /* - * Easy case: Just increase typebuf.tb_off. - */ + // Easy case: Just increase typebuf.tb_off. if (offset == 0 && typebuf.tb_buflen - (typebuf.tb_off + len) >= 3 * MAXMAPLEN + 3) { typebuf.tb_off += len; - } - /* - * Have to move the characters in typebuf.tb_buf[] and typebuf.tb_noremap[] - */ - else { + } else { + // Have to move the characters in typebuf.tb_buf[] and typebuf.tb_noremap[] i = typebuf.tb_off + offset; - /* - * Leave some extra room at the end to avoid reallocation. - */ + // Leave some extra room at the end to avoid reallocation. if (typebuf.tb_off > MAXMAPLEN) { memmove(typebuf.tb_buf + MAXMAPLEN, typebuf.tb_buf + typebuf.tb_off, (size_t)offset); @@ -1101,10 +1062,8 @@ void del_typebuf(int len, int offset) } } -/* - * Write typed characters to script file. - * If recording is on put the character in the recordbuffer. - */ +// Write typed characters to script file. +// If recording is on put the character in the recordbuffer. static void gotchars(const char_u *chars, size_t len) FUNC_ATTR_NONNULL_ALL { @@ -1161,14 +1120,12 @@ void ungetchars(int len) } } -/* - * Sync undo. Called when typed characters are obtained from the typeahead - * buffer, or when a menu is used. - * Do not sync: - * - In Insert mode, unless cursor key has been used. - * - While reading a script file. - * - When no_u_sync is non-zero. - */ +// Sync undo. Called when typed characters are obtained from the typeahead +// buffer, or when a menu is used. +// Do not sync: +// - In Insert mode, unless cursor key has been used. +// - While reading a script file. +// - When no_u_sync is non-zero. void may_sync_undo(void) { if ((!(State & (MODE_INSERT | MODE_CMDLINE)) || arrow_used) @@ -1177,9 +1134,7 @@ void may_sync_undo(void) } } -/* - * Make "typebuf" empty and allocate new buffers. - */ +// Make "typebuf" empty and allocate new buffers. void alloc_typebuf(void) { typebuf.tb_buf = xmalloc(TYPELEN_INIT); @@ -1195,9 +1150,7 @@ void alloc_typebuf(void) } } -/* - * Free the buffers of "typebuf". - */ +// Free the buffers of "typebuf". void free_typebuf(void) { if (typebuf.tb_buf == typebuf_init) { @@ -1212,10 +1165,8 @@ void free_typebuf(void) } } -/* - * When doing ":so! file", the current typeahead needs to be saved, and - * restored when "file" has been read completely. - */ +// When doing ":so! file", the current typeahead needs to be saved, and +// restored when "file" has been read completely. static typebuf_T saved_typebuf[NSCRIPT]; void save_typebuf(void) @@ -1239,9 +1190,7 @@ static bool can_get_old_char(void) return old_char != -1 && (old_KeyStuffed || stuff_empty()); } -/* - * Save all three kinds of typeahead, so that the user must type at a prompt. - */ +// Save all three kinds of typeahead, so that the user must type at a prompt. void save_typeahead(tasave_T *tp) { tp->save_typebuf = typebuf; @@ -1257,10 +1206,8 @@ void save_typeahead(tasave_T *tp) readbuf2.bh_first.b_next = NULL; } -/* - * Restore the typeahead to what it was before calling save_typeahead(). - * The allocated memory is freed, can only be called once! - */ +// Restore the typeahead to what it was before calling save_typeahead(). +// The allocated memory is freed, can only be called once! void restore_typeahead(tasave_T *tp) { if (tp->typebuf_valid) { @@ -1314,12 +1261,10 @@ void openscript(char *name, bool directly) } save_typebuf(); - /* - * Execute the commands from the file right now when using ":source!" - * after ":global" or ":argdo" or in a loop. Also when another command - * follows. This means the display won't be updated. Don't do this - * always, "make test" would fail. - */ + // Execute the commands from the file right now when using ":source!" + // after ":global" or ":argdo" or in a loop. Also when another command + // follows. This means the display won't be updated. Don't do this + // always, "make test" would fail. if (directly) { oparg_T oa; int oldcurscript; @@ -1348,9 +1293,7 @@ void openscript(char *name, bool directly) } } -/* - * Close the currently active input script. - */ +// Close the currently active input script. static void closescript(void) { free_typebuf(); @@ -1452,10 +1395,8 @@ int vgetc(void) garbage_collect(false); } - /* - * If a character was put back with vungetc, it was already processed. - * Return it directly. - */ + // If a character was put back with vungetc, it was already processed. + // Return it directly. if (can_get_old_char()) { c = old_char; old_char = -1; @@ -1628,11 +1569,9 @@ int vgetc(void) last_vgetc_recorded_len = last_recorded_len; } - /* - * In the main loop "may_garbage_collect" can be set to do garbage - * collection in the first next vgetc(). It's disabled after that to - * avoid internally used Lists and Dicts to be freed. - */ + // In the main loop "may_garbage_collect" can be set to do garbage + // collection in the first next vgetc(). It's disabled after that to + // avoid internally used Lists and Dicts to be freed. may_garbage_collect = false; // Execute Lua on_key callbacks. @@ -1641,10 +1580,8 @@ int vgetc(void) return c; } -/* - * Like vgetc(), but never return a NUL when called recursively, get a key - * directly from the user (ignoring typeahead). - */ +// Like vgetc(), but never return a NUL when called recursively, get a key +// directly from the user (ignoring typeahead). int safe_vgetc(void) { int c; @@ -1656,10 +1593,8 @@ int safe_vgetc(void) return c; } -/* - * Like safe_vgetc(), but loop to handle K_IGNORE. - * Also ignore scrollbar events. - */ +// Like safe_vgetc(), but loop to handle K_IGNORE. +// Also ignore scrollbar events. int plain_vgetc(void) { int c; @@ -1672,12 +1607,10 @@ int plain_vgetc(void) return c; } -/* - * Check if a character is available, such that vgetc() will not block. - * If the next character is a special character or multi-byte, the returned - * character is not valid!. - * Returns NUL if no character is available. - */ +// Check if a character is available, such that vgetc() will not block. +// If the next character is a special character or multi-byte, the returned +// character is not valid!. +// Returns NUL if no character is available. int vpeekc(void) { if (can_get_old_char()) { @@ -1686,11 +1619,9 @@ int vpeekc(void) return vgetorpeek(false); } -/* - * Check if any character is available, also half an escape sequence. - * Trick: when no typeahead found, but there is something in the typeahead - * buffer, it must be an ESC that is recognized as the start of a key code. - */ +// Check if any character is available, also half an escape sequence. +// Trick: when no typeahead found, but there is something in the typeahead +// buffer, it must be an ESC that is recognized as the start of a key code. int vpeekc_any(void) { int c; @@ -1702,10 +1633,8 @@ int vpeekc_any(void) return c; } -/* - * Call vpeekc() without causing anything to be mapped. - * Return true if a character is available, false otherwise. - */ +// Call vpeekc() without causing anything to be mapped. +// Return true if a character is available, false otherwise. int char_avail(void) { int retval; @@ -2851,11 +2780,9 @@ int inchar(char_u *buf, int maxlen, long wait_time) ui_flush(); } - /* - * Don't reset these when at the hit-return prompt, otherwise an endless - * recursive loop may result (write error in swapfile, hit-return, timeout - * on char wait, flush swapfile, write error....). - */ + // Don't reset these when at the hit-return prompt, otherwise an endless + // recursive loop may result (write error in swapfile, hit-return, timeout + // on char wait, flush swapfile, write error....). if (State != MODE_HITRETURN) { did_outofmem_msg = false; // display out of memory message (again) did_swapwrite_msg = false; // display swap file write error again diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index d7f5730943..e280648fd2 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -1,9 +1,7 @@ // 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 -/* - * hardcopy.c: printing to paper - */ +// hardcopy.c: printing to paper #include #include @@ -36,64 +34,62 @@ #include "nvim/version.h" #include "nvim/vim.h" -/* - * To implement printing on a platform, the following functions must be - * defined: - * - * int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) - * Called once. Code should display printer dialogue (if appropriate) and - * determine printer font and margin settings. Reset has_color if the printer - * doesn't support colors at all. - * Returns FAIL to abort. - * - * int mch_print_begin(prt_settings_T *settings) - * Called to start the print job. - * Return false to abort. - * - * int mch_print_begin_page(char_u *msg) - * Called at the start of each page. - * "msg" indicates the progress of the print job, can be NULL. - * Return false to abort. - * - * int mch_print_end_page() - * Called at the end of each page. - * Return false to abort. - * - * int mch_print_blank_page() - * Called to generate a blank page for collated, duplex, multiple copy - * document. Return false to abort. - * - * void mch_print_end(prt_settings_T *psettings) - * Called at normal end of print job. - * - * void mch_print_cleanup() - * Called if print job ends normally or is abandoned. Free any memory, close - * devices and handles. Also called when mch_print_begin() fails, but not - * when mch_print_init() fails. - * - * void mch_print_set_font(int Bold, int Italic, int Underline); - * Called whenever the font style changes. - * - * void mch_print_set_bg(uint32_t bgcol); - * Called to set the background color for the following text. Parameter is an - * RGB value. - * - * void mch_print_set_fg(uint32_t fgcol); - * Called to set the foreground color for the following text. Parameter is an - * RGB value. - * - * mch_print_start_line(int margin, int page_line) - * Sets the current position at the start of line "page_line". - * If margin is true start in the left margin (for header and line number). - * - * int mch_print_text_out(char_u *p, size_t len); - * Output one character of text p[len] at the current position. - * Return true if there is no room for another character in the same line. - * - * Note that the generic code has no idea of margins. The machine code should - * simply make the page look smaller! The header and the line numbers are - * printed in the margin. - */ +// To implement printing on a platform, the following functions must be +// defined: +// +// int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) +// Called once. Code should display printer dialogue (if appropriate) and +// determine printer font and margin settings. Reset has_color if the printer +// doesn't support colors at all. +// Returns FAIL to abort. +// +// int mch_print_begin(prt_settings_T *settings) +// Called to start the print job. +// Return false to abort. +// +// int mch_print_begin_page(char_u *msg) +// Called at the start of each page. +// "msg" indicates the progress of the print job, can be NULL. +// Return false to abort. +// +// int mch_print_end_page() +// Called at the end of each page. +// Return false to abort. +// +// int mch_print_blank_page() +// Called to generate a blank page for collated, duplex, multiple copy +// document. Return false to abort. +// +// void mch_print_end(prt_settings_T *psettings) +// Called at normal end of print job. +// +// void mch_print_cleanup() +// Called if print job ends normally or is abandoned. Free any memory, close +// devices and handles. Also called when mch_print_begin() fails, but not +// when mch_print_init() fails. +// +// void mch_print_set_font(int Bold, int Italic, int Underline); +// Called whenever the font style changes. +// +// void mch_print_set_bg(uint32_t bgcol); +// Called to set the background color for the following text. Parameter is an +// RGB value. +// +// void mch_print_set_fg(uint32_t fgcol); +// Called to set the foreground color for the following text. Parameter is an +// RGB value. +// +// mch_print_start_line(int margin, int page_line) +// Sets the current position at the start of line "page_line". +// If margin is true start in the left margin (for header and line number). +// +// int mch_print_text_out(char_u *p, size_t len); +// Output one character of text p[len] at the current position. +// Return true if there is no room for another character in the same line. +// +// Note that the generic code has no idea of margins. The machine code should +// simply make the page look smaller! The header and the line numbers are +// printed in the margin. static option_table_T printer_opts[OPT_PRINT_NUM_OPTIONS] = { { "top", true, 0, NULL, 0, false }, @@ -154,9 +150,7 @@ static option_table_T mbfont_opts[OPT_MBFONT_NUM_OPTIONS] = { "o", false, 0, NULL, 0, false }, }; -/* - * These values determine the print position on a page. - */ +// These values determine the print position on a page. typedef struct { int lead_spaces; // remaining spaces for a TAB int print_pos; // virtual column for computing TABs @@ -255,33 +249,27 @@ struct prt_resfile_buffer_S { # include "hardcopy.c.generated.h" #endif -/* - * Parse 'printoptions' and set the flags in "printer_opts". - * Returns an error message or NULL; - */ +// Parse 'printoptions' and set the flags in "printer_opts". +// Returns an error message or NULL; char *parse_printoptions(void) { return parse_list_options((char_u *)p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS); } -/* - * Parse 'printoptions' and set the flags in "printer_opts". - * Returns an error message or NULL; - */ +// Parse 'printoptions' and set the flags in "printer_opts". +// Returns an error message or NULL; char *parse_printmbfont(void) { return parse_list_options((char_u *)p_pmfn, mbfont_opts, OPT_MBFONT_NUM_OPTIONS); } -/* - * Parse a list of options in the form - * option:value,option:value,option:value - * - * "value" can start with a number which is parsed out, e.g. margin:12mm - * - * Returns an error message for an illegal option, NULL otherwise. - * Only used for the printer at the moment... - */ +// Parse a list of options in the form +// option:value,option:value,option:value +// +// "value" can start with a number which is parsed out, e.g. margin:12mm +// +// Returns an error message for an illegal option, NULL otherwise. +// Only used for the printer at the moment... static char *parse_list_options(char_u *option_str, option_table_T *table, size_t table_size) { option_table_T *old_opts; @@ -301,9 +289,7 @@ static char *parse_list_options(char_u *option_str, option_table_T *table, size_ table[idx].present = false; } - /* - * Repeat for all comma separated parts. - */ + // Repeat for all comma separated parts. stringp = option_str; while (*stringp) { colonp = (char_u *)vim_strchr((char *)stringp, ':'); @@ -361,10 +347,8 @@ static char *parse_list_options(char_u *option_str, option_table_T *table, size_ return ret; } -/* - * If using a dark background, the colors will probably be too bright to show - * up well on white paper, so reduce their brightness. - */ +// If using a dark background, the colors will probably be too bright to show +// up well on white paper, so reduce their brightness. static uint32_t darken_rgb(uint32_t rgb) { return ((rgb >> 17) << 16) @@ -489,9 +473,7 @@ static void prt_line_number(prt_settings_T *const psettings, const int page_line } } -/* - * Get the currently effective header height. - */ +// Get the currently effective header height. int prt_header_height(void) { if (printer_opts[OPT_PRINT_HEADERHEIGHT].present) { @@ -507,10 +489,8 @@ int prt_use_number(void) && TOLOWER_ASC(printer_opts[OPT_PRINT_NUMBER].string[0]) == 'y'; } -/* - * Return the unit used in a margin item in 'printoptions'. - * Returns PRT_UNIT_NONE if not recognized. - */ +// Return the unit used in a margin item in 'printoptions'. +// Returns PRT_UNIT_NONE if not recognized. int prt_get_unit(int idx) { int u = PRT_UNIT_NONE; @@ -546,12 +526,10 @@ static void prt_header(prt_settings_T *const psettings, const int pagenum, const linenr_T tmp_lnum, tmp_topline, tmp_botline; int use_sandbox = false; - /* - * Need to (temporarily) set current line number and first/last line - * number on the 'window'. Since we don't know how long the page is, - * set the first and current line number to the top line, and guess - * that the page length is 64. - */ + // Need to (temporarily) set current line number and first/last line + // number on the 'window'. Since we don't know how long the page is, + // set the first and current line number to the top line, and guess + // that the page length is 64. tmp_lnum = curwin->w_cursor.lnum; tmp_topline = curwin->w_topline; tmp_botline = curwin->w_botline; @@ -606,9 +584,7 @@ static void prt_header(prt_settings_T *const psettings, const int pagenum, const } } -/* - * Display a print status message. - */ +// Display a print status message. static void prt_message(char_u *s) { // TODO(bfredl): delete this @@ -644,13 +620,11 @@ void ex_hardcopy(exarg_T *eap) settings.arguments = (char_u *)eap->arg; } - /* - * Initialise for printing. Ask the user for settings, unless forceit is - * set. - * The mch_print_init() code should set up margins if applicable. (It may - * not be a real printer - for example the engine might generate HTML or - * PS.) - */ + // Initialise for printing. Ask the user for settings, unless forceit is + // set. + // The mch_print_init() code should set up margins if applicable. (It may + // not be a real printer - for example the engine might generate HTML or + // PS.) if (mch_print_init(&settings, curbuf->b_fname == NULL ? (char_u *)buf_spname(curbuf) : curbuf->b_sfname == NULL ? (char_u *)curbuf->b_fname : (char_u *)curbuf->b_sfname, @@ -687,9 +661,7 @@ void ex_hardcopy(exarg_T *eap) prt_get_attr(id, &settings.number, settings.modec); } - /* - * Estimate the total lines to be printed - */ + // Estimate the total lines to be printed for (lnum = eap->line1; lnum <= eap->line2; lnum++) { bytes_to_print += STRLEN(skipwhite((char *)ml_get(lnum))); } @@ -717,9 +689,7 @@ void ex_hardcopy(exarg_T *eap) goto print_fail_no_begin; } - /* - * Loop over collated copies: 1 2 3, 1 2 3, ... - */ + // Loop over collated copies: 1 2 3, 1 2 3, ... page_count = 0; for (collated_copies = 0; collated_copies < settings.n_collated_copies; @@ -740,9 +710,7 @@ void ex_hardcopy(exarg_T *eap) } } - /* - * Loop over all pages in the print job: 1 2 3 ... - */ + // Loop over all pages in the print job: 1 2 3 ... for (page_count = 0; prtpos.file_line <= eap->line2; page_count++) { // Loop over uncollated copies: 1 1 1, 2 2 2, 3 3 3, ... // For duplex: 12 12 12 34 34 34, ... @@ -752,9 +720,7 @@ void ex_hardcopy(exarg_T *eap) // Set the print position to the start of this page. prtpos = page_prtpos; - /* - * Do front and rear side of a page. - */ + // Do front and rear side of a page. for (side = 0; side <= settings.duplex; side++) { // Print one page. @@ -780,9 +746,7 @@ void ex_hardcopy(exarg_T *eap) } prt_message(IObuff); - /* - * Output header if required - */ + // Output header if required if (prt_header_height() > 0) { prt_header(&settings, page_count + 1 + side, prtpos.file_line); @@ -814,10 +778,8 @@ void ex_hardcopy(exarg_T *eap) } } - /* - * Extra blank page for duplexing with odd number of pages and - * more copies to come. - */ + // Extra blank page for duplexing with odd number of pages and + // more copies to come. if (prtpos.file_line > eap->line2 && settings.duplex && side == 0 && uncollated_copies + 1 < settings.n_uncollated_copies) { @@ -850,10 +812,8 @@ print_fail_no_begin: mch_print_cleanup(); } -/* - * Print one page line. - * Return the next column to print, or zero if the line is finished. - */ +// Print one page line. +// Return the next column to print, or zero if the line is finished. static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T *ppos) { colnr_T col; @@ -881,9 +841,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T mch_print_start_line(false, page_line); line = (char_u *)ml_get(ppos->file_line); - /* - * Loop over the columns until the end of the file line or right margin. - */ + // Loop over the columns until the end of the file line or right margin. for (col = ppos->column; line[col] != NUL && !need_break; col += outputlen) { if ((outputlen = utfc_ptr2len((char *)line + col)) < 1) { outputlen = 1; @@ -908,9 +866,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T } } - /* - * Appropriately expand any tabs to spaces. - */ + // Appropriately expand any tabs to spaces. if (line[col] == TAB || tab_spaces != 0) { if (tab_spaces == 0) { tab_spaces = tabstop_padding(print_pos, @@ -945,10 +901,8 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T ppos->lead_spaces = tab_spaces; ppos->print_pos = print_pos; - /* - * Start next line of file if we clip lines, or have reached end of the - * line, unless we are doing a formfeed. - */ + // Start next line of file if we clip lines, or have reached end of the + // line, unless we are doing a formfeed. if (!ppos->ff && (line[col] == NUL || (printer_opts[OPT_PRINT_WRAP].present @@ -959,34 +913,32 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T return col; } -/* - * PS printer stuff. - * - * Sources of information to help maintain the PS printing code: - * - * 1. PostScript Language Reference, 3rd Edition, - * Addison-Wesley, 1999, ISBN 0-201-37922-8 - * 2. PostScript Language Program Design, - * Addison-Wesley, 1988, ISBN 0-201-14396-8 - * 3. PostScript Tutorial and Cookbook, - * Addison Wesley, 1985, ISBN 0-201-10179-3 - * 4. PostScript Language Document Structuring Conventions Specification, - * version 3.0, - * Adobe Technote 5001, 25th September 1992 - * 5. PostScript Printer Description File Format Specification, Version 4.3, - * Adobe technote 5003, 9th February 1996 - * 6. Adobe Font Metrics File Format Specification, Version 4.1, - * Adobe Technote 5007, 7th October 1998 - * 7. Adobe CMap and CIDFont Files Specification, Version 1.0, - * Adobe Technote 5014, 8th October 1996 - * 8. Adobe CJKV Character Collections and CMaps for CID-Keyed Fonts, - * Adoboe Technote 5094, 8th September, 2001 - * 9. CJKV Information Processing, 2nd Edition, - * O'Reilly, 2002, ISBN 1-56592-224-7 - * - * Some of these documents can be found in PDF form on Adobe's web site - - * http://www.adobe.com - */ +// PS printer stuff. +// +// Sources of information to help maintain the PS printing code: +// +// 1. PostScript Language Reference, 3rd Edition, +// Addison-Wesley, 1999, ISBN 0-201-37922-8 +// 2. PostScript Language Program Design, +// Addison-Wesley, 1988, ISBN 0-201-14396-8 +// 3. PostScript Tutorial and Cookbook, +// Addison Wesley, 1985, ISBN 0-201-10179-3 +// 4. PostScript Language Document Structuring Conventions Specification, +// version 3.0, +// Adobe Technote 5001, 25th September 1992 +// 5. PostScript Printer Description File Format Specification, Version 4.3, +// Adobe technote 5003, 9th February 1996 +// 6. Adobe Font Metrics File Format Specification, Version 4.1, +// Adobe Technote 5007, 7th October 1998 +// 7. Adobe CMap and CIDFont Files Specification, Version 1.0, +// Adobe Technote 5014, 8th October 1996 +// 8. Adobe CJKV Character Collections and CMaps for CID-Keyed Fonts, +// Adoboe Technote 5094, 8th September, 2001 +// 9. CJKV Information Processing, 2nd Edition, +// O'Reilly, 2002, ISBN 1-56592-224-7 +// +// Some of these documents can be found in PDF form on Adobe's web site - +// http://www.adobe.com #define PRT_PS_DEFAULT_DPI (72) // Default user space resolution #define PRT_PS_DEFAULT_FONTSIZE (10) @@ -1251,17 +1203,13 @@ static struct prt_dsc_comment_S prt_dsc_table[] = PRT_DSC_ENDCOMMENTS_TYPE } }; -/* - * Variables for the output PostScript file. - */ +// Variables for the output PostScript file. static FILE *prt_ps_fd; static bool prt_file_error; static char_u *prt_ps_file_name = NULL; -/* - * Various offsets and dimensions in default PostScript user space (points). - * Used for text positioning calculations - */ +// Various offsets and dimensions in default PostScript user space (points). +// Used for text positioning calculations static double prt_page_width; static double prt_page_height; static double prt_left_margin; @@ -1276,10 +1224,8 @@ static double prt_bgcol_offset; static double prt_pos_x_moveto = 0.0; static double prt_pos_y_moveto = 0.0; -/* - * Various control variables used to decide when and how to change the - * PostScript graphics state. - */ +// Various control variables used to decide when and how to change the +// PostScript graphics state. static bool prt_need_moveto; static bool prt_do_moveto; static bool prt_need_font; @@ -1298,9 +1244,7 @@ static double prt_text_run; static int prt_page_num; static int prt_bufsiz; -/* - * Variables controlling physical printing. - */ +// Variables controlling physical printing. static int prt_media; static int prt_portrait; static int prt_num_copies; @@ -1308,9 +1252,7 @@ static int prt_duplex; static int prt_tumble; static int prt_collate; -/* - * Buffers used when generating PostScript output - */ +// Buffers used when generating PostScript output static char prt_line_buffer[257]; static garray_T prt_ps_buffer = GA_EMPTY_INIT_VALUE; @@ -1345,36 +1287,28 @@ static void prt_write_file_len(char_u *buffer, size_t bytes) prt_write_file_raw_len(buffer, bytes); } -/* - * Write a string. - */ +// Write a string. static void prt_write_string(char *s) { vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%s", s); prt_write_file(prt_line_buffer); } -/* - * Write an int and a space. - */ +// Write an int and a space. static void prt_write_int(int i) { snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%d ", i); prt_write_file(prt_line_buffer); } -/* - * Write a boolean and a space. - */ +// Write a boolean and a space. static void prt_write_boolean(int b) { snprintf(prt_line_buffer, sizeof(prt_line_buffer), "%s ", (b ? "T" : "F")); prt_write_file(prt_line_buffer); } -/* - * Write PostScript to re-encode and define the font. - */ +// Write PostScript to re-encode and define the font. static void prt_def_font(char *new_name, char *encoding, int height, char *font) { vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), @@ -1390,9 +1324,7 @@ static void prt_def_font(char *new_name, char *encoding, int height, char *font) prt_write_file(prt_line_buffer); } -/* - * Write a line to define the CID font. - */ +// Write a line to define the CID font. static void prt_def_cidfont(char *new_name, int height, char *cidfont) { vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), @@ -1403,9 +1335,7 @@ static void prt_def_cidfont(char *new_name, int height, char *cidfont) prt_write_file(prt_line_buffer); } -/* - * Write a line to define a duplicate of a CID font - */ +// Write a line to define a duplicate of a CID font static void prt_dup_cidfont(char *original_name, char *new_name) { vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), @@ -1413,11 +1343,9 @@ static void prt_dup_cidfont(char *original_name, char *new_name) prt_write_file(prt_line_buffer); } -/* - * Convert a real value into an integer and fractional part as integers, with - * the fractional part being in the range [0,10^precision). The fractional part - * is also rounded based on the precision + 1'th fractional digit. - */ +// Convert a real value into an integer and fractional part as integers, with +// the fractional part being in the range [0,10^precision). The fractional part +// is also rounded based on the precision + 1'th fractional digit. static void prt_real_bits(double real, int precision, int *pinteger, int *pfraction) { int integer = (int)real; @@ -1433,11 +1361,9 @@ static void prt_real_bits(double real, int precision, int *pinteger, int *pfract *pfraction = (int)(fraction + 0.5); } -/* - * Write a real and a space. Save bytes if real value has no fractional part! - * We use prt_real_bits() as %f in sprintf uses the locale setting to decide - * what decimal point character to use, but PS always requires a '.'. - */ +// Write a real and a space. Save bytes if real value has no fractional part! +// We use prt_real_bits() as %f in sprintf uses the locale setting to decide +// what decimal point character to use, but PS always requires a '.'. static void prt_write_real(double val, int prec) { int integer; @@ -1463,9 +1389,7 @@ static void prt_write_real(double val, int prec) prt_write_file(prt_line_buffer); } -/* - * Write a line to define a numeric variable. - */ +// Write a line to define a numeric variable. static void prt_def_var(char *name, double value, int prec) { vim_snprintf(prt_line_buffer, sizeof(prt_line_buffer), @@ -2020,9 +1944,7 @@ static double to_device_units(int idx, double physsize, int def_number) return ret; } -/* - * Calculate margins for given width and height from printoptions settings. - */ +// Calculate margins for given width and height from printoptions settings. static void prt_page_margins(double width, double height, double *left, double *right, double *top, double *bottom) { @@ -2062,18 +1984,14 @@ static void prt_build_cid_fontname(int font, char_u *name, int name_len) prt_ps_mb_font.ps_fontname[font] = fontname; } -/* - * Get number of lines of text that fit on a page (excluding the header). - */ +// Get number of lines of text that fit on a page (excluding the header). static int prt_get_lpp(void) { int lpp; - /* - * Calculate offset to lower left corner of background rect based on actual - * font height (based on its bounding box) and the line height, handling the - * case where the font height can exceed the line height. - */ + // Calculate offset to lower left corner of background rect based on actual + // font height (based on its bounding box) and the line height, handling the + // case where the font height can exceed the line height. prt_bgcol_offset = PRT_PS_FONT_TO_USER(prt_line_height, prt_ps_font->bbox_min_y); if ((prt_ps_font->bbox_max_y - prt_ps_font->bbox_min_y) < 1000.0) { @@ -2270,9 +2188,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) prt_ps_font = &prt_ps_courier_font; } - /* - * Find the size of the paper and set the margins. - */ + // Find the size of the paper and set the margins. prt_portrait = (!printer_opts[OPT_PRINT_PORTRAIT].present || TOLOWER_ASC(printer_opts[OPT_PRINT_PORTRAIT].string[0]) == 'y'); @@ -2295,13 +2211,11 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) } prt_media = i; - /* - * Set PS pagesize based on media dimensions and print orientation. - * Note: Media and page sizes have defined meanings in PostScript and should - * be kept distinct. Media is the paper (or transparency, or ...) that is - * printed on, whereas the page size is the area that the PostScript - * interpreter renders into. - */ + // Set PS pagesize based on media dimensions and print orientation. + // Note: Media and page sizes have defined meanings in PostScript and should + // be kept distinct. Media is the paper (or transparency, or ...) that is + // printed on, whereas the page size is the area that the PostScript + // interpreter renders into. if (prt_portrait) { prt_page_width = prt_mediasize[i].width; prt_page_height = prt_mediasize[i].height; @@ -2320,9 +2234,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) prt_top_margin = top; prt_bottom_margin = bottom; - /* - * Set up the font size. - */ + // Set up the font size. fontsize = PRT_PS_DEFAULT_FONTSIZE; for (p = (char_u *)p_pfn; (p = (char_u *)vim_strchr((char *)p, ':')) != NULL; p++) { if (p[1] == 'h' && ascii_isdigit(p[2])) { @@ -2331,10 +2243,8 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) } prt_font_metrics(fontsize); - /* - * Return the number of characters per line, and lines per page for the - * generic print code. - */ + // Return the number of characters per line, and lines per page for the + // generic print code. psettings->chars_per_line = prt_get_cpl(); psettings->lines_per_page = prt_get_lpp(); @@ -2343,12 +2253,10 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) return FAIL; } - /* - * Sort out the number of copies to be printed. PS by default will do - * uncollated copies for you, so once we know how many uncollated copies are - * wanted cache it away and lie to the generic code that we only want one - * uncollated copy. - */ + // Sort out the number of copies to be printed. PS by default will do + // uncollated copies for you, so once we know how many uncollated copies are + // wanted cache it away and lie to the generic code that we only want one + // uncollated copy. psettings->n_collated_copies = 1; psettings->n_uncollated_copies = 1; prt_num_copies = 1; @@ -2364,10 +2272,8 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) psettings->jobname = jobname; - /* - * Set up printer duplex and tumble based on Duplex option setting - default - * is long sided duplex printing (i.e. no tumble). - */ + // Set up printer duplex and tumble based on Duplex option setting - default + // is long sided duplex printing (i.e. no tumble). prt_duplex = true; prt_tumble = false; psettings->duplex = 1; @@ -2491,9 +2397,7 @@ bool mch_print_begin(prt_settings_T *psettings) struct prt_ps_resource_S res_cidfont; struct prt_ps_resource_S res_cmap; - /* - * PS DSC Header comments - no PS code! - */ + // PS DSC Header comments - no PS code! prt_dsc_start(); prt_dsc_textline("Title", (char *)psettings->jobname); if (os_get_username(buffer, 256) == FAIL) { @@ -2685,9 +2589,7 @@ bool mch_print_begin(prt_settings_T *psettings) prt_num_copies); prt_dsc_noarg("EndComments"); - /* - * PS Document page defaults - */ + // PS Document page defaults prt_dsc_noarg("BeginDefaults"); // List font resources most likely common to all pages @@ -2707,9 +2609,7 @@ bool mch_print_begin(prt_settings_T *psettings) prt_dsc_noarg("EndDefaults"); - /* - * PS Document prolog inclusion - all required procsets. - */ + // PS Document prolog inclusion - all required procsets. prt_dsc_noarg("BeginProlog"); // Add required procsets - NOTE: order is important! @@ -2736,9 +2636,7 @@ bool mch_print_begin(prt_settings_T *psettings) prt_dsc_noarg("EndProlog"); - /* - * PS Document setup - must appear after the prolog - */ + // PS Document setup - must appear after the prolog prt_dsc_noarg("BeginSetup"); // Device setup - page size and number of uncollated copies @@ -2847,9 +2745,7 @@ void mch_print_end(prt_settings_T *psettings) { prt_dsc_noarg("Trailer"); - /* - * Output any info we don't know in toto until we finish - */ + // Output any info we don't know in toto until we finish prt_dsc_ints("Pages", 1, &prt_page_num); prt_dsc_noarg("EOF"); diff --git a/src/nvim/hardcopy.h b/src/nvim/hardcopy.h index 9ef4eb0074..ce562cd3e6 100644 --- a/src/nvim/hardcopy.h +++ b/src/nvim/hardcopy.h @@ -8,9 +8,7 @@ #include "nvim/globals.h" // for TriState #include "nvim/types.h" // for char_u -/* - * Structure to hold printing color and font attributes. - */ +// Structure to hold printing color and font attributes. typedef struct { uint32_t fg_color; uint32_t bg_color; @@ -23,9 +21,7 @@ typedef struct { int underdashed; } prt_text_attr_T; -/* - * Structure passed back to the generic printer code. - */ +// Structure passed back to the generic printer code. typedef struct { int n_collated_copies; int n_uncollated_copies; @@ -42,9 +38,7 @@ typedef struct { char_u *arguments; } prt_settings_T; -/* - * Generic option table item, only used for printer at the moment. - */ +// Generic option table item, only used for printer at the moment. typedef struct { const char *name; int hasnum; diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index e54bffb587..85534ebcff 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -1,13 +1,11 @@ // 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 -/* - * CSCOPE support for Vim added by Andy Kahn - * Ported to Win32 by Sergey Khorev - * - * The basic idea/structure of cscope for Vim was borrowed from Nvi. There - * might be a few lines of code that look similar to what Nvi has. - */ +// CSCOPE support for Vim added by Andy Kahn +// Ported to Win32 by Sergey Khorev +// +// The basic idea/structure of cscope for Vim was borrowed from Nvi. There +// might be a few lines of code that look similar to what Nvi has. #include #include @@ -78,10 +76,8 @@ static enum { EXP_CSCOPE_KILL, // expand ":cscope kill" arguments } expand_what; -/* - * Function given to ExpandGeneric() to obtain the cscope command - * expansion. - */ +// Function given to ExpandGeneric() to obtain the cscope command +// expansion. char *get_cscope_name(expand_T *xp, int idx) { int current_idx; @@ -140,9 +136,7 @@ char *get_cscope_name(expand_T *xp, int idx) } } -/* - * Handle command line completion for :cscope command. - */ +// Handle command line completion for :cscope command. void set_context_in_cscope_cmd(expand_T *xp, const char *arg, cmdidx_T cmdidx) { // Default: expand subcommands. @@ -304,33 +298,31 @@ void cs_print_tags(void) cs_manage_matches(NULL, NULL, 0, Print); } -/* - * "cscope_connection([{num} , {dbpath} [, {prepend}]])" function - * - * Checks for the existence of a |cscope| connection. If no - * parameters are specified, then the function returns: - * - * 0, if cscope was not available (not compiled in), or if there - * are no cscope connections; or - * 1, if there is at least one cscope connection. - * - * If parameters are specified, then the value of {num} - * determines how existence of a cscope connection is checked: - * - * {num} Description of existence check - * ----- ------------------------------ - * 0 Same as no parameters (e.g., "cscope_connection()"). - * 1 Ignore {prepend}, and use partial string matches for - * {dbpath}. - * 2 Ignore {prepend}, and use exact string matches for - * {dbpath}. - * 3 Use {prepend}, use partial string matches for both - * {dbpath} and {prepend}. - * 4 Use {prepend}, use exact string matches for both - * {dbpath} and {prepend}. - * - * Note: All string comparisons are case sensitive! - */ +// "cscope_connection([{num} , {dbpath} [, {prepend}]])" function +// +// Checks for the existence of a |cscope| connection. If no +// parameters are specified, then the function returns: +// +// 0, if cscope was not available (not compiled in), or if there +// are no cscope connections; or +// 1, if there is at least one cscope connection. +// +// If parameters are specified, then the value of {num} +// determines how existence of a cscope connection is checked: +// +// {num} Description of existence check +// ----- ------------------------------ +// 0 Same as no parameters (e.g., "cscope_connection()"). +// 1 Ignore {prepend}, and use partial string matches for +// {dbpath}. +// 2 Ignore {prepend}, and use exact string matches for +// {dbpath}. +// 3 Use {prepend}, use partial string matches for both +// {dbpath} and {prepend}. +// 4 Use {prepend}, use exact string matches for both +// {dbpath} and {prepend}. +// +// Note: All string comparisons are case sensitive! bool cs_connection(int num, char_u *dbpath, char_u *ppath) { if (num < 0 || num > 4 || (num > 0 && !dbpath)) { @@ -379,9 +371,8 @@ bool cs_connection(int num, char_u *dbpath, char_u *ppath) return false; } // cs_connection -/* - * PRIVATE functions - ****************************************************************************/ +// PRIVATE functions +// ************************************************************************** /// Add cscope database or a directory name (to look for cscope.out) /// to the cscope connection list. @@ -684,10 +675,8 @@ static int cs_create_connection(size_t i) char *prog, *cmd, *ppath = NULL; #if defined(UNIX) - /* - * Cscope reads from to_cs[0] and writes to from_cs[1]; vi reads from - * from_cs[0] and writes to to_cs[1]. - */ + // Cscope reads from to_cs[0] and writes to from_cs[1]; vi reads from + // from_cs[0] and writes to to_cs[1]. to_cs[0] = to_cs[1] = from_cs[0] = from_cs[1] = -1; if (pipe(to_cs) < 0 || pipe(from_cs) < 0) { (void)emsg(_("E566: Could not create cscope pipes")); @@ -896,10 +885,8 @@ static int cs_find(exarg_T *eap) return false; } - /* - * Let's replace the NULs written by strtok() with spaces - we need the - * spaces to correctly display the quickfix/location list window's title. - */ + // Let's replace the NULs written by strtok() with spaces - we need the + // spaces to correctly display the quickfix/location list window's title. for (int i = 0; i < eap_arg_len; i++) { if (NUL == eap->arg[i]) { eap->arg[i] = ' '; @@ -1041,10 +1028,8 @@ static bool cs_find_common(char *opt, char *pat, int forceit, int verbose, bool apply_autocmds(EVENT_QUICKFIXCMDPOST, "cscope", curbuf->b_fname, true, curbuf); if (use_ll) { - /* - * In the location list window, use the displayed location - * list. Otherwise, use the location list for the window. - */ + // In the location list window, use the displayed location + // list. Otherwise, use the location list for the window. qi = (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL) ? wp->w_llist_ref : wp->w_llist; } @@ -1431,11 +1416,9 @@ retry: } *p = '\0'; - /* - * cscope output is in the following format: - * - * - */ + // cscope output is in the following format: + // + // char *saveptr = NULL; if ((name = os_strtok(buf, (const char *)" ", &saveptr)) == NULL) { return NULL; @@ -1786,9 +1769,7 @@ static int cs_read_prompt(size_t i) } #if defined(UNIX) && defined(SIGALRM) -/* - * Used to catch and ignore SIGALRM below. - */ +// Used to catch and ignore SIGALRM below. static void sig_handler(int s) { // do nothing @@ -1847,25 +1828,21 @@ static void cs_release_csp(size_t i, bool freefnpp) os_delay(50L, false); // sleep 50 ms } # endif - /* - * If the cscope process is still running: kill it. - * Safety check: If the PID would be zero here, the entire X session - * would be killed. -1 and 1 are dangerous as well. - */ + // If the cscope process is still running: kill it. + // Safety check: If the PID would be zero here, the entire X session + // would be killed. -1 and 1 are dangerous as well. if (pid < 0 && csinfo[i].pid > 1) { # ifdef ECHILD bool alive = true; if (waitpid_errno == ECHILD) { - /* - * When using 'vim -g', vim is forked and cscope process is - * no longer a child process but a sibling. So waitpid() - * fails with errno being ECHILD (No child processes). - * Don't send SIGKILL to cscope immediately but wait - * (polling) for it to exit normally as result of sending - * the "q" command, hence giving it a chance to clean up - * its temporary files. - */ + // When using 'vim -g', vim is forked and cscope process is + // no longer a child process but a sibling. So waitpid() + // fails with errno being ECHILD (No child processes). + // Don't send SIGKILL to cscope immediately but wait + // (polling) for it to exit normally as result of sending + // the "q" command, hence giving it a chance to clean up + // its temporary files. int waited; sleep(0); @@ -1974,11 +1951,9 @@ static char *cs_resolve_file(size_t i, char *name) char *fullname; char_u *csdir = NULL; - /* - * Ppath is freed when we destroy the cscope connection. - * Fullname is freed after cs_make_vim_style_matches, after it's been - * copied into the tag buffer used by Vim. - */ + // Ppath is freed when we destroy the cscope connection. + // Fullname is freed after cs_make_vim_style_matches, after it's been + // copied into the tag buffer used by Vim. size_t len = strlen(name) + 2; if (csinfo[i].ppath != NULL) { len += strlen(csinfo[i].ppath); diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 7dcc9e3c27..5941473825 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -27,11 +27,9 @@ typedef struct { #ifdef INCLUDE_GENERATED_DECLARATIONS # include "indent_c.c.generated.h" #endif -/* - * Find the start of a comment, not knowing if we are in a comment right now. - * Search starts at w_cursor.lnum and goes backwards. - * Return NULL when not inside a comment. - */ +// Find the start of a comment, not knowing if we are in a comment right now. +// Search starts at w_cursor.lnum and goes backwards. +// Return NULL when not inside a comment. static pos_T *ind_find_start_comment(void) // XXX { return find_start_comment(curbuf->b_ind_maxcomment); @@ -48,10 +46,8 @@ pos_T *find_start_comment(int ind_maxcomment) // XXX break; } - /* - * Check if the comment start we found is inside a string. - * If it is then restrict the search to below this line and try again. - */ + // Check if the comment start we found is inside a string. + // If it is then restrict the search to below this line and try again. if (!is_pos_in_string((char_u *)ml_get(pos->lnum), pos->col)) { break; } @@ -97,11 +93,9 @@ static pos_T *ind_find_start_CORS(linenr_T *is_raw) return comment_pos; } -/* - * Find the start of a raw string, not knowing if we are in one right now. - * Search starts at w_cursor.lnum and goes backwards. - * Return NULL when not inside a raw string. - */ +// Find the start of a raw string, not knowing if we are in one right now. +// Search starts at w_cursor.lnum and goes backwards. +// Return NULL when not inside a raw string. static pos_T *find_start_rawstring(int ind_maxcomment) // XXX { pos_T *pos; @@ -127,17 +121,13 @@ static pos_T *find_start_rawstring(int ind_maxcomment) // XXX return pos; } -/* - * Skip to the end of a "string" and a 'c' character. - * If there is no string or character, return argument unmodified. - */ +// Skip to the end of a "string" and a 'c' character. +// If there is no string or character, return argument unmodified. static const char_u *skip_string(const char_u *p) { int i; - /* - * We loop, because strings may be concatenated: "date""time". - */ + // We loop, because strings may be concatenated: "date""time". for (;; p++) { if (p[0] == '\'') { // 'c' or '\n' or '\000' if (p[1] == NUL) { // ' at end of line @@ -204,13 +194,10 @@ int is_pos_in_string(const char_u *line, colnr_T col) return !((colnr_T)(p - line) <= col); } -/* - * Functions for C-indenting. - * Most of this originally comes from Eric Fischer. - */ -/* - * Below "XXX" means that this function may unlock the current line. - */ +// Functions for C-indenting. +// Most of this originally comes from Eric Fischer. + +// Below "XXX" means that this function may unlock the current line. /// @return true if the string "line" starts with a word from 'cinwords'. bool cin_is_cinword(const char *line) @@ -235,10 +222,8 @@ bool cin_is_cinword(const char *line) return retval; } -/* - * Skip over white space and C comments within the line. - * Also skip over Perl/shell comments if desired. - */ +// Skip over white space and C comments within the line. +// Also skip over Perl/shell comments if desired. static const char_u *cin_skipcomment(const char_u *s) { while (*s) { @@ -246,8 +231,8 @@ static const char_u *cin_skipcomment(const char_u *s) s = (char_u *)skipwhite((char *)s); - /* Perl/shell # comment comment continues until eol. Require a space - * before # to avoid recognizing $#array. */ + // Perl/shell # comment comment continues until eol. Require a space + // before # to avoid recognizing $#array. if (curbuf->b_ind_hash_comment != 0 && s != prev_s && *s == '#') { s += STRLEN(s); break; @@ -280,9 +265,7 @@ static int cin_nocode(const char_u *s) return *cin_skipcomment(s) == NUL; } -/* - * Check previous lines for a "//" line comment, skipping over blank lines. - */ +// Check previous lines for a "//" line comment, skipping over blank lines. static pos_T *find_line_comment(void) // XXX { static pos_T pos; @@ -369,10 +352,8 @@ bool cin_islabel(void) // XXX return false; } - /* - * Only accept a label if the previous line is terminated or is a case - * label. - */ + // Only accept a label if the previous line is terminated or is a case + // label. pos_T cursor_save; pos_T *trypos; const char_u *line; @@ -381,10 +362,8 @@ bool cin_islabel(void) // XXX while (curwin->w_cursor.lnum > 1) { curwin->w_cursor.lnum--; - /* - * If we're in a comment or raw string now, skip to the start of - * it. - */ + // If we're in a comment or raw string now, skip to the start of + // it. curwin->w_cursor.col = 0; if ((trypos = ind_find_start_CORS(NULL)) != NULL) { // XXX curwin->w_cursor = *trypos; @@ -411,11 +390,9 @@ bool cin_islabel(void) // XXX return true; // label at start of file??? } -/* - * Recognize structure initialization and enumerations: - * "[typedef] [static|public|protected|private] enum" - * "[typedef] [static|public|protected|private] = {" - */ +// Recognize structure initialization and enumerations: +// "[typedef] [static|public|protected|private] enum" +// "[typedef] [static|public|protected|private] = {" static int cin_isinit(void) { const char_u *s; @@ -495,9 +472,7 @@ bool cin_iscase(const char_u *s, bool strict) return false; } -/* - * Recognize a "default" switch label. - */ +// Recognize a "default" switch label. static int cin_isdefault(const char_u *s) { return STRNCMP(s, "default", 7) == 0 @@ -576,12 +551,10 @@ static bool cin_is_cpp_namespace(const char_u *s) return false; } -/* - * Return a pointer to the first non-empty non-comment character after a ':'. - * Return NULL if not found. - * case 234: a = b; - * ^ - */ +// Return a pointer to the first non-empty non-comment character after a ':'. +// Return NULL if not found. +// case 234: a = b; +// ^ static const char_u *after_label(const char_u *l) { for (; *l; l++) { @@ -605,10 +578,8 @@ static const char_u *after_label(const char_u *l) return l; } -/* - * Get indent of line "lnum", skipping a label. - * Return 0 if there is nothing after the label. - */ +// Get indent of line "lnum", skipping a label. +// Return 0 if there is nothing after the label. static int get_indent_nolabel(linenr_T lnum) // XXX { const char_u *l; @@ -628,12 +599,10 @@ static int get_indent_nolabel(linenr_T lnum) // XXX return (int)col; } -/* - * Find indent for line "lnum", ignoring any case or jump label. - * Also return a pointer to the text (after the label) in "pp". - * label: if (asdf && asdfasdf) - * ^ - */ +// Find indent for line "lnum", ignoring any case or jump label. +// Also return a pointer to the text (after the label) in "pp". +// label: if (asdf && asdfasdf) +// ^ static int skip_label(linenr_T lnum, const char_u **pp) { const char_u *l; @@ -660,13 +629,11 @@ static int skip_label(linenr_T lnum, const char_u **pp) return amount; } -/* - * Return the indent of the first variable name after a type in a declaration. - * int a, indent of "a" - * static struct foo b, indent of "b" - * enum bla c, indent of "c" - * Returns zero when it doesn't look like a declaration. - */ +// Return the indent of the first variable name after a type in a declaration. +// int a, indent of "a" +// static struct foo b, indent of "b" +// enum bla c, indent of "c" +// Returns zero when it doesn't look like a declaration. static int cin_first_id_amount(void) { char_u *line, *p, *s; @@ -707,15 +674,13 @@ static int cin_first_id_amount(void) return (int)col; } -/* - * Return the indent of the first non-blank after an equal sign. - * char *foo = "here"; - * Return zero if no (useful) equal sign found. - * Return -1 if the line above "lnum" ends in a backslash. - * foo = "asdf\ - * asdf\ - * here"; - */ +// Return the indent of the first non-blank after an equal sign. +// char *foo = "here"; +// Return zero if no (useful) equal sign found. +// Return -1 if the line above "lnum" ends in a backslash. +// foo = "asdf{backslash} +// asdf{backslash} +// here"; static int cin_get_equal_amount(linenr_T lnum) { const char_u *line; @@ -758,9 +723,7 @@ static int cin_get_equal_amount(linenr_T lnum) return (int)col; } -/* - * Recognize a preprocessor statement: Any line that starts with '#'. - */ +// Recognize a preprocessor statement: Any line that starts with '#'. static int cin_ispreproc(const char_u *s) { if (*skipwhite((char *)s) == '#') { @@ -808,17 +771,13 @@ static int cin_ispreproc_cont(const char_u **pp, linenr_T *lnump, int *amount) return retval; } -/* - * Recognize the start of a C or C++ comment. - */ +// Recognize the start of a C or C++ comment. static int cin_iscomment(const char_u *p) { return p[0] == '/' && (p[1] == '*' || p[1] == '/'); } -/* - * Recognize the start of a "//" comment. - */ +// Recognize the start of a "//" comment. static int cin_islinecomment(const char_u *p) { return p[0] == '/' && p[1] == '/'; @@ -957,10 +916,10 @@ static int cin_isfuncdecl(const char_u **sp, linenr_T first_lnum, linenr_T min_l if ((*s == ',' && cin_nocode(s + 1)) || s[1] == NUL || cin_nocode(s)) { int comma = (*s == ','); - /* ',' at the end: continue looking in the next line. - * At the end: check for ',' in the next line, for this style: - * func(arg1 - * , arg2) */ + // ',' at the end: continue looking in the next line. + // At the end: check for ',' in the next line, for this style: + // func(arg1 + // , arg2) for (;;) { if (lnum >= curbuf->b_ml.ml_line_count) { break; @@ -1014,11 +973,9 @@ static int cin_isdo(const char_u *p) return STRNCMP(p, "do", 2) == 0 && !vim_isIDc(p[2]); } -/* - * Check if this is a "while" that should have a matching "do". - * We only accept a "while (condition) ;", with only white space between the - * ')' and ';'. The condition may be spread over several lines. - */ +// Check if this is a "while" that should have a matching "do". +// We only accept a "while (condition) ;", with only white space between the +// ')' and ';'. The condition may be spread over several lines. static int cin_iswhileofdo(const char_u *p, linenr_T lnum) // XXX { pos_T cursor_save; @@ -1047,12 +1004,10 @@ static int cin_iswhileofdo(const char_u *p, linenr_T lnum) // XXX return retval; } -/* - * Check whether in "p" there is an "if", "for" or "while" before "*poffset". - * Return 0 if there is none. - * Otherwise return !0 and update "*poffset" to point to the place where the - * string was found. - */ +// Check whether in "p" there is an "if", "for" or "while" before "*poffset". +// Return 0 if there is none. +// Otherwise return !0 and update "*poffset" to point to the place where the +// string was found. static int cin_is_if_for_while_before_offset(const char_u *line, int *poffset) { int offset = *poffset; @@ -1116,8 +1071,8 @@ static int cin_iswhileofdo_end(int terminated) if (*p == ')') { s = (char_u *)skipwhite((char *)p + 1); if (*s == ';' && cin_nocode(s + 1)) { - /* Found ");" at end of the line, now check there is "while" - * before the matching '('. XXX */ + // Found ");" at end of the line, now check there is "while" + // before the matching '('. XXX i = (int)(p - line); curwin->w_cursor.col = i; trypos = find_match_paren(curbuf->b_ind_maxparen); @@ -1149,19 +1104,17 @@ static int cin_isbreak(const char_u *p) return STRNCMP(p, "break", 5) == 0 && !vim_isIDc(p[5]); } -/* - * Find the position of a C++ base-class declaration or - * constructor-initialization. eg: - * - * class MyClass : - * baseClass <-- here - * class MyClass : public baseClass, - * anotherBaseClass <-- here (should probably lineup ??) - * MyClass::MyClass(...) : - * baseClass(...) <-- here (constructor-initialization) - * - * This is a lot of guessing. Watch out for "cond ? func() : foo". - */ +// Find the position of a C++ base-class declaration or +// constructor-initialization. eg: +// +// class MyClass : +// baseClass <-- here +// class MyClass : public baseClass, +// anotherBaseClass <-- here (should probably lineup ??) +// MyClass::MyClass(...) : +// baseClass(...) <-- here (constructor-initialization) +// +// This is a lot of guessing. Watch out for "cond ? func() : foo". static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) { lpos_T *pos = &cached->lpos; // find position @@ -1187,19 +1140,18 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) cpp_base_class = lookfor_ctor_init = class_or_struct = false; - /* Search for a line starting with '#', empty, ending in ';' or containing - * '{' or '}' and start below it. This handles the following situations: - * a = cond ? - * func() : - * asdf; - * func::foo() - * : something - * {} - * Foo::Foo (int one, int two) - * : something(4), - * somethingelse(3) - * {} - */ + // Search for a line starting with '#', empty, ending in ';' or containing + // '{' or '}' and start below it. This handles the following situations: + // a = cond ? + // func() : + // asdf; + // func::foo() + // : something + // {} + // Foo::Foo (int one, int two) + // : something(4), + // somethingelse(3) + // {} while (lnum > 1) { line = (char_u *)ml_get(lnum - 1); s = (char_u *)skipwhite((char *)line); @@ -1249,13 +1201,13 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) s = skip_string(s) + 1; } else if (s[0] == ':') { if (s[1] == ':') { - /* skip double colon. It can't be a constructor - * initialization any more */ + // skip double colon. It can't be a constructor + // initialization any more lookfor_ctor_init = false; s = cin_skipcomment(s + 2); } else if (lookfor_ctor_init || class_or_struct) { - /* we have something found, that looks like the start of - * cpp-base-class-declaration or constructor-initialization */ + // we have something found, that looks like the start of + // cpp-base-class-declaration or constructor-initialization cpp_base_class = true; lookfor_ctor_init = class_or_struct = false; pos->col = 0; @@ -1277,8 +1229,8 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) if (s[0] == '{' || s[0] == '}' || s[0] == ';') { cpp_base_class = lookfor_ctor_init = class_or_struct = false; } else if (s[0] == ')') { - /* Constructor-initialization is assumed if we come across - * something like "):" */ + // Constructor-initialization is assumed if we come across + // something like "):" class_or_struct = false; lookfor_ctor_init = true; } else if (s[0] == '?') { @@ -1411,10 +1363,8 @@ static int cin_is_cpp_extern_c(const char_u *s) return false; } -/* - * Skip strings, chars and comments until at or past "trypos". - * Return the column found. - */ +// Skip strings, chars and comments until at or past "trypos". +// Return the column found. static int cin_skip2pos(pos_T *trypos) { const char_u *line; @@ -1438,11 +1388,10 @@ static int cin_skip2pos(pos_T *trypos) return (int)(p - line); } -/* - * Find the '{' at the start of the block we are in. - * Return NULL if no match found. - * Ignore a '{' that is in a comment, makes indenting the next three lines - * work. */ +// Find the '{' at the start of the block we are in. +// Return NULL if no match found. +// Ignore a '{' that is in a comment, makes indenting the next three lines +// work. // foo() // { // } @@ -1542,12 +1491,10 @@ static pos_T *find_match_paren_after_brace(int ind_maxparen) return trypos; } -/* - * Return ind_maxparen corrected for the difference in line number between the - * cursor position and "startpos". This makes sure that searching for a - * matching paren above the cursor line doesn't find a match because of - * looking a few lines further. - */ +// Return ind_maxparen corrected for the difference in line number between the +// cursor position and "startpos". This makes sure that searching for a +// matching paren above the cursor line doesn't find a match because of +// looking a few lines further. static int corr_ind_maxparen(pos_T *startpos) { long n = (long)startpos->lnum - (long)curwin->w_cursor.lnum; @@ -1558,10 +1505,8 @@ static int corr_ind_maxparen(pos_T *startpos) return curbuf->b_ind_maxparen; } -/* - * Set w_cursor.col to the column number of the last unmatched ')' or '{' in - * line "l". "l" must point to the start of the line. - */ +// Set w_cursor.col to the column number of the last unmatched ')' or '{' in +// line "l". "l" must point to the start of the line. static int find_last_paren(const char_u *l, int start, int end) { int i; @@ -1587,10 +1532,8 @@ static int find_last_paren(const char_u *l, int start, int end) return retval; } -/* - * Parse 'cinoptions' and set the values in "curbuf". - * Must be called when 'cinoptions', 'shiftwidth' and/or 'tabstop' changes. - */ +// Parse 'cinoptions' and set the values in "curbuf". +// Must be called when 'cinoptions', 'shiftwidth' and/or 'tabstop' changes. void parse_cino(buf_T *buf) { char *p; @@ -1599,39 +1542,37 @@ void parse_cino(buf_T *buf) int fraction = 0; int sw = get_sw_value(buf); - /* - * Set the default values. - */ - /* Spaces from a block's opening brace the prevailing indent for that - * block should be. */ + // Set the default values. + // Spaces from a block's opening brace the prevailing indent for that + // block should be. buf->b_ind_level = sw; - /* Spaces from the edge of the line an open brace that's at the end of a - * line is imagined to be. */ + // Spaces from the edge of the line an open brace that's at the end of a + // line is imagined to be. buf->b_ind_open_imag = 0; - /* Spaces from the prevailing indent for a line that is not preceded by - * an opening brace. */ + // Spaces from the prevailing indent for a line that is not preceded by + // an opening brace. buf->b_ind_no_brace = 0; // Column where the first { of a function should be located }. buf->b_ind_first_open = 0; - /* Spaces from the prevailing indent a leftmost open brace should be - * located. */ + // Spaces from the prevailing indent a leftmost open brace should be + // located. buf->b_ind_open_extra = 0; - /* Spaces from the matching open brace (real location for one at the left - * edge; imaginary location from one that ends a line) the matching close - * brace should be located. */ + // Spaces from the matching open brace (real location for one at the left + // edge; imaginary location from one that ends a line) the matching close + // brace should be located. buf->b_ind_close_extra = 0; - /* Spaces from the edge of the line an open brace sitting in the leftmost - * column is imagined to be. */ + // Spaces from the edge of the line an open brace sitting in the leftmost + // column is imagined to be. buf->b_ind_open_left_imag = 0; - /* Spaces jump labels should be shifted to the left if N is non-negative, - * otherwise the jump label will be put to column 1. */ + // Spaces jump labels should be shifted to the left if N is non-negative, + // otherwise the jump label will be put to column 1. buf->b_ind_jump_label = -1; // Spaces from the switch() indent a "case xx" label should be located. @@ -1643,8 +1584,8 @@ void parse_cino(buf_T *buf) // Lineup break at end of case in switch() with case label. buf->b_ind_case_break = 0; - /* Spaces from the class declaration indent a scope declaration label - * should be located. */ + // Spaces from the class declaration indent a scope declaration label + // should be located. buf->b_ind_scopedecl = sw; // Spaces from the scope declaration label code should be located. @@ -1656,32 +1597,32 @@ void parse_cino(buf_T *buf) // Amount a function type spec should be indented. buf->b_ind_func_type = sw; - /* Amount a cpp base class declaration or constructor initialization - * should be indented. */ + // Amount a cpp base class declaration or constructor initialization + // should be indented. buf->b_ind_cpp_baseclass = sw; - /* additional spaces beyond the prevailing indent a continuation line - * should be located. */ + // additional spaces beyond the prevailing indent a continuation line + // should be located. buf->b_ind_continuation = sw; // Spaces from the indent of the line with an unclosed parentheses. buf->b_ind_unclosed = sw * 2; - /* Spaces from the indent of the line with an unclosed parentheses, which - * itself is also unclosed. */ + // Spaces from the indent of the line with an unclosed parentheses, which + // itself is also unclosed. buf->b_ind_unclosed2 = sw; // Suppress ignoring spaces from the indent of a line starting with an // unclosed parenthesis. buf->b_ind_unclosed_noignore = 0; - /* If the opening paren is the last nonwhite character on the line, and - * b_ind_unclosed_wrapped is nonzero, use this indent relative to the outer - * context (for very long lines). */ + // If the opening paren is the last nonwhite character on the line, and + // b_ind_unclosed_wrapped is nonzero, use this indent relative to the outer + // context (for very long lines). buf->b_ind_unclosed_wrapped = 0; - /* Suppress ignoring white space when lining up with the character after - * an unclosed parentheses. */ + // Suppress ignoring white space when lining up with the character after + // an unclosed parentheses. buf->b_ind_unclosed_whiteok = 0; // Indent a closing parenthesis under the line start of the matching @@ -1697,8 +1638,8 @@ void parse_cino(buf_T *buf) // Spaces from the comment opener when there is nothing after it. buf->b_ind_in_comment = 3; - /* Boolean: if non-zero, use b_ind_in_comment even if there is something - * after the comment opener. */ + // Boolean: if non-zero, use b_ind_in_comment even if there is something + // after the comment opener. buf->b_ind_in_comment2 = 0; // Max lines to search for an open paren. @@ -1719,8 +1660,8 @@ void parse_cino(buf_T *buf) // Handle C++ namespace. buf->b_ind_cpp_namespace = 0; - /* Handle continuation lines containing conditions of if(), for() and - * while(). */ + // Handle continuation lines containing conditions of if(), for() and + // while(). buf->b_ind_if_for_while = 0; // indentation for # comments @@ -1766,8 +1707,8 @@ void parse_cino(buf_T *buf) n = -n; } - /* When adding an entry here, also update the default 'cinoptions' in - * doc/indent.txt, and add explanation for it! */ + // When adding an entry here, also update the default 'cinoptions' in + // doc/indent.txt, and add explanation for it! switch (*l) { case '>': buf->b_ind_level = n; @@ -1887,10 +1828,8 @@ void parse_cino(buf_T *buf) } } -/* - * Return the desired indent for C code. - * Return -1 if the indent should be left alone (inside a raw string). - */ +// Return the desired indent for C code. +// Return -1 if the indent should be left alone (inside a raw string). int get_c_indent(void) { pos_T cur_curpos; @@ -1951,18 +1890,16 @@ int get_c_indent(void) return 0; } - /* Get a copy of the current contents of the line. - * This is required, because only the most recent line obtained with - * ml_get is valid! */ + // Get a copy of the current contents of the line. + // This is required, because only the most recent line obtained with + // ml_get is valid! linecopy = vim_strsave((char_u *)ml_get(cur_curpos.lnum)); - /* - * In insert mode and the cursor is on a ')' truncate the line at the - * cursor position. We don't want to line up with the matching '(' when - * inserting new stuff. - * For unknown reasons the cursor might be past the end of the line, thus - * check for that. - */ + // In insert mode and the cursor is on a ')' truncate the line at the + // cursor position. We don't want to line up with the matching '(' when + // inserting new stuff. + // For unknown reasons the cursor might be past the end of the line, thus + // check for that. if ((State & MODE_INSERT) && curwin->w_cursor.col < (colnr_T)STRLEN(linecopy) && linecopy[curwin->w_cursor.col] == ')') { @@ -1977,10 +1914,8 @@ int get_c_indent(void) original_line_islabel = cin_islabel(); // XXX - /* - * If we are inside a raw string don't change the indent. - * Ignore a raw string inside a comment. - */ + // If we are inside a raw string don't change the indent. + // Ignore a raw string inside a comment. comment_pos = ind_find_start_comment(); if (comment_pos != NULL) { // findmatchlimit() static pos is overwritten, make a copy @@ -2010,10 +1945,8 @@ int get_c_indent(void) amount = 0; goto theend; } - /* - * If we're inside a "//" comment and there is a "//" comment in a - * previous line, lineup with that one. - */ + // If we're inside a "//" comment and there is a "//" comment in a + // previous line, lineup with that one. if (cin_islinecomment(theline)) { pos_T linecomment_pos; @@ -2034,10 +1967,8 @@ int get_c_indent(void) goto theend; } } - /* - * If we're inside a comment and not looking at the start of the - * comment, try using the 'comments' option. - */ + // If we're inside a comment and not looking at the start of the + // comment, try using the 'comments' option. if (!cin_iscomment(theline) && comment_pos != NULL) { // XXX int lead_start_len = 2; int lead_middle_len = 1; @@ -2086,16 +2017,16 @@ int get_c_indent(void) STRCPY(lead_middle, lead_end); lead_middle_len = (int)STRLEN(lead_middle); } else if (what == COM_END) { - /* If our line starts with the middle comment string, line it - * up with the comment opener per the 'comments' option. */ + // If our line starts with the middle comment string, line it + // up with the comment opener per the 'comments' option. if (STRNCMP(theline, lead_middle, lead_middle_len) == 0 && STRNCMP(theline, lead_end, STRLEN(lead_end)) != 0) { done = true; if (curwin->w_cursor.lnum > 1) { - /* If the start comment string matches in the previous - * line, use the indent of that line plus offset. If - * the middle comment string matches in the previous - * line, use the indent of that line. XXX */ + // If the start comment string matches in the previous + // line, use the indent of that line plus offset. If + // the middle comment string matches in the previous + // line, use the indent of that line. XXX look = (char_u *)skipwhite(ml_get(curwin->w_cursor.lnum - 1)); if (STRNCMP(look, lead_start, lead_start_len) == 0) { amount = get_indent_lnum(curwin->w_cursor.lnum - 1); @@ -2117,8 +2048,8 @@ int get_c_indent(void) break; } - /* If our line starts with the end comment string, line it up - * with the middle comment */ + // If our line starts with the end comment string, line it up + // with the middle comment if (STRNCMP(theline, lead_middle, lead_middle_len) != 0 && STRNCMP(theline, lead_end, STRLEN(lead_end)) == 0) { amount = get_indent_lnum(curwin->w_cursor.lnum - 1); @@ -2134,10 +2065,9 @@ int get_c_indent(void) } } - /* If our line starts with an asterisk, line up with the - * asterisk in the comment opener; otherwise, line up - * with the first character of the comment text. - */ + // If our line starts with an asterisk, line up with the + // asterisk in the comment opener; otherwise, line up + // with the first character of the comment text. if (done) { // skip } else if (theline[0] == '*') { @@ -2187,8 +2117,8 @@ int get_c_indent(void) || (tryposBrace = find_start_brace()) != NULL || trypos != NULL) { if (trypos != NULL && tryposBrace != NULL) { - /* Both an unmatched '(' and '{' is found. Use the one which is - * closer to the current cursor position, set the other to NULL. */ + // Both an unmatched '(' and '{' is found. Use the one which is + // closer to the current cursor position, set the other to NULL. if (trypos->lnum != tryposBrace->lnum ? trypos->lnum < tryposBrace->lnum : trypos->col < tryposBrace->col) { @@ -2200,10 +2130,8 @@ int get_c_indent(void) if (trypos != NULL) { our_paren_pos = *trypos; - /* - * If the matching paren is more than one line away, use the indent of - * a previous non-empty line that matches the same paren. - */ + // If the matching paren is more than one line away, use the indent of + // a previous non-empty line that matches the same paren. if (theline[0] == ')' && curbuf->b_ind_paren_prev) { // Line up with the start of the matching paren line. amount = get_indent_lnum(curwin->w_cursor.lnum - 1); // XXX @@ -2243,18 +2171,16 @@ int get_c_indent(void) } } - /* - * Line up with line where the matching paren is. XXX - * If the line starts with a '(' or the indent for unclosed - * parentheses is zero, line up with the unclosed parentheses. - */ + // Line up with line where the matching paren is. XXX + // If the line starts with a '(' or the indent for unclosed + // parentheses is zero, line up with the unclosed parentheses. if (amount == -1) { int ignore_paren_col = 0; int is_if_for_while = 0; if (curbuf->b_ind_if_for_while) { - /* Look for the outermost opening parenthesis on this line - * and check whether it belongs to an "if", "for" or "while". */ + // Look for the outermost opening parenthesis on this line + // and check whether it belongs to an "if", "for" or "while". pos_T cursor_save = curwin->w_cursor; pos_T outermost; @@ -2284,8 +2210,8 @@ int get_c_indent(void) char_u *line; int look_col; - /* Ignore a '(' in front of the line that has a match before - * our matching '('. */ + // Ignore a '(' in front of the line that has a match before + // our matching '('. curwin->w_cursor.lnum = our_paren_pos.lnum; line = (char_u *)get_cursor_line_ptr(); look_col = (int)(look - line); @@ -2305,22 +2231,20 @@ int get_c_indent(void) && is_if_for_while == 0) || (!curbuf->b_ind_unclosed_noignore && *look == '(' && ignore_paren_col == 0)) { - /* - * If we're looking at a close paren, line up right there; - * otherwise, line up with the next (non-white) character. - * When b_ind_unclosed_wrapped is set and the matching paren is - * the last nonwhite character of the line, use either the - * indent of the current line or the indentation of the next - * outer paren and add b_ind_unclosed_wrapped (for very long - * lines). - */ + // If we're looking at a close paren, line up right there; + // otherwise, line up with the next (non-white) character. + // When b_ind_unclosed_wrapped is set and the matching paren is + // the last nonwhite character of the line, use either the + // indent of the current line or the indentation of the next + // outer paren and add b_ind_unclosed_wrapped (for very long + // lines). if (theline[0] != ')') { cur_amount = MAXCOL; l = (char_u *)ml_get(our_paren_pos.lnum); if (curbuf->b_ind_unclosed_wrapped && cin_ends_in(l, (char_u *)"(", NULL)) { - /* look for opening unmatched paren, indent one level - * for each additional level */ + // look for opening unmatched paren, indent one level + // for each additional level n = 1; for (col = 0; col < our_paren_pos.col; col++) { switch (l[col]) { @@ -2355,10 +2279,8 @@ int get_c_indent(void) } } - /* - * Find how indented the paren is, or the character after it - * if we did the above "if". - */ + // Find how indented the paren is, or the character after it + // if we did the above "if". if (our_paren_pos.col > 0) { getvcol(curwin, &our_paren_pos, &col, NULL, NULL); if (cur_amount > (int)col) { @@ -2376,8 +2298,8 @@ int get_c_indent(void) amount = cur_amount; } } else { - /* Add b_ind_unclosed2 for each '(' before our matching one, - * but ignore (void) before the line (ignore_paren_col). */ + // Add b_ind_unclosed2 for each '(' before our matching one, + // but ignore (void) before the line (ignore_paren_col). col = our_paren_pos.col; while ((int)our_paren_pos.col > ignore_paren_col) { our_paren_pos.col--; @@ -2393,8 +2315,8 @@ int get_c_indent(void) } } - /* Use b_ind_unclosed once, when the first '(' is not inside - * braces */ + // Use b_ind_unclosed once, when the first '(' is not inside + // braces if (col == MAXCOL) { amount += curbuf->b_ind_unclosed; } else { @@ -2410,14 +2332,12 @@ int get_c_indent(void) } } } - /* - * For a line starting with ')' use the minimum of the two - * positions, to avoid giving it more indent than the previous - * lines: - * func_long_name( if (x - * arg && yy - * ) ^ not here ) ^ not here - */ + // For a line starting with ')' use the minimum of the two + // positions, to avoid giving it more indent than the previous + // lines: + // func_long_name( if (x + // arg && yy + // ) ^ not here ) ^ not here if (cur_amount < amount) { amount = cur_amount; } @@ -2439,12 +2359,10 @@ int get_c_indent(void) ourscope = trypos->lnum; start = (char_u *)ml_get(ourscope); - /* - * Now figure out how indented the line is in general. - * If the brace was at the start of the line, we use that; - * otherwise, check out the indentation of the line as - * a whole and then add the "imaginary indent" to that. - */ + // Now figure out how indented the line is in general. + // If the brace was at the start of the line, we use that; + // otherwise, check out the indentation of the line as + // a whole and then add the "imaginary indent" to that. look = (char_u *)skipwhite((char *)start); if (*look == '{') { getvcol(curwin, trypos, &col, NULL, NULL); @@ -2490,18 +2408,14 @@ int get_c_indent(void) // we want to be. Otherwise, add the amount of room // that an indent is supposed to be. if (theline[0] == '}') { - /* - * they may want closing braces to line up with something - * other than the open brace. indulge them, if so. - */ + // they may want closing braces to line up with something + // other than the open brace. indulge them, if so. amount += curbuf->b_ind_close_extra; } else { - /* - * If we're looking at an "else", try to find an "if" - * to match it with. - * If we're looking at a "while", try to find a "do" - * to match it with. - */ + // If we're looking at an "else", try to find an "if" + // to match it with. + // If we're looking at a "while", try to find a "do" + // to match it with. lookfor = LOOKFOR_INITIAL; if (cin_iselse(theline)) { lookfor = LOOKFOR_IF; @@ -2516,18 +2430,14 @@ int get_c_indent(void) } } - /* - * We get here if we are not on an "while-of-do" or "else" (or - * failed to find a matching "if"). - * Search backwards for something to line up with. - * First set amount for when we don't find anything. - */ + // We get here if we are not on an "while-of-do" or "else" (or + // failed to find a matching "if"). + // Search backwards for something to line up with. + // First set amount for when we don't find anything. - /* - * if the '{' is _really_ at the left margin, use the imaginary - * location of a left-margin brace. Otherwise, correct the - * location for b_ind_open_extra. - */ + // if the '{' is _really_ at the left margin, use the imaginary + // location of a left-margin brace. Otherwise, correct the + // location for b_ind_open_extra. if (start_brace == BRACE_IN_COL0) { // '{' is in column 0 amount = curbuf->b_ind_open_left_imag; @@ -2586,10 +2496,8 @@ int get_c_indent(void) curwin->w_cursor.lnum--; curwin->w_cursor.col = 0; - /* - * If we went all the way back to the start of our scope, line - * up with it. - */ + // If we went all the way back to the start of our scope, line + // up with it. if (curwin->w_cursor.lnum <= ourscope) { // We reached end of scope: // If looking for a enum or structure initialization @@ -2603,9 +2511,9 @@ int get_c_indent(void) if (curwin->w_cursor.lnum == 0 || curwin->w_cursor.lnum < ourscope - curbuf->b_ind_maxparen) { - /* nothing found (abuse curbuf->b_ind_maxparen as - * limit) assume terminated line (i.e. a variable - * initialization) */ + // nothing found (abuse curbuf->b_ind_maxparen as + // limit) assume terminated line (i.e. a variable + // initialization) if (cont_amount > 0) { amount = cont_amount; } else if (!curbuf->b_ind_js) { @@ -2616,10 +2524,8 @@ int get_c_indent(void) l = (char_u *)get_cursor_line_ptr(); - /* - * If we're in a comment or raw string now, skip to - * the start of it. - */ + // If we're in a comment or raw string now, skip to + // the start of it. trypos = ind_find_start_CORS(NULL); if (trypos != NULL) { curwin->w_cursor.lnum = trypos->lnum + 1; @@ -2640,27 +2546,23 @@ int get_c_indent(void) terminated = cin_isterminated(l, false, true); - /* - * If we are at top level and the line looks like a - * function declaration, we are done - * (it's a variable declaration). - */ + // If we are at top level and the line looks like a + // function declaration, we are done + // (it's a variable declaration). if (start_brace != BRACE_IN_COL0 || !cin_isfuncdecl(&l, curwin->w_cursor.lnum, 0)) { - /* if the line is terminated with another ',' - * it is a continued variable initialization. - * don't add extra indent. - * TODO: does not work, if a function - * declaration is split over multiple lines: - * cin_isfuncdecl returns false then. - */ + // if the line is terminated with another ',' + // it is a continued variable initialization. + // don't add extra indent. + // TODO(vim): does not work, if a function + // declaration is split over multiple lines: + // cin_isfuncdecl returns false then. if (terminated == ',') { break; } - /* if it is an enum declaration or an assignment, - * we are done. - */ + // if it is an enum declaration or an assignment, + // we are done. if (terminated != ';' && cin_isinit()) { break; } @@ -2692,11 +2594,10 @@ int get_c_indent(void) } } - /* it's a variable declaration, add indentation - * like in - * int a, - * b; - */ + // it's a variable declaration, add indentation + // like in + // int a, + // b; if (cont_amount > 0) { amount = cont_amount; } else { @@ -2720,10 +2621,8 @@ int get_c_indent(void) } if (lookfor_cpp_namespace) { - /* - * Looking for C++ namespace, need to look further - * back. - */ + // Looking for C++ namespace, need to look further + // back. if (curwin->w_cursor.lnum == ourscope) { continue; } @@ -2736,8 +2635,8 @@ int get_c_indent(void) l = (char_u *)get_cursor_line_ptr(); - /* If we're in a comment or raw string now, skip - * to the start of it. */ + // If we're in a comment or raw string now, skip + // to the start of it. trypos = ind_find_start_CORS(NULL); if (trypos != NULL) { curwin->w_cursor.lnum = trypos->lnum + 1; @@ -2779,20 +2678,18 @@ int get_c_indent(void) l = (char_u *)get_cursor_line_ptr(); - /* - * If this is a switch() label, may line up relative to that. - * If this is a C++ scope declaration, do the same. - */ + // If this is a switch() label, may line up relative to that. + // If this is a C++ scope declaration, do the same. bool iscase = cin_iscase(l, false); if (iscase || cin_isscopedecl(l)) { - /* we are only looking for cpp base class - * declaration/initialization any longer */ + // we are only looking for cpp base class + // declaration/initialization any longer if (lookfor == LOOKFOR_CPP_BASECLASS) { break; } - /* When looking for a "do" we are not interested in - * labels. */ + // When looking for a "do" we are not interested in + // labels. if (whilelevel > 0) { continue; } @@ -2865,14 +2762,12 @@ int get_c_indent(void) break; } - /* - * Try to get the indent of a statement before the switch - * label. If nothing is found, line up relative to the - * switch label. - * break; <- may line up with this line - * case xx: - * -> y = 1; - */ + // Try to get the indent of a statement before the switch + // label. If nothing is found, line up relative to the + // switch label. + // break; <- may line up with this line + // case xx: + // -> y = 1; scope_amount = get_indent() + (iscase // XXX ? curbuf->b_ind_case_code : curbuf->b_ind_scopedecl_code); @@ -2881,10 +2776,8 @@ int get_c_indent(void) continue; } - /* - * Looking for a switch() label or C++ scope declaration, - * ignore other lines, skip {}-blocks. - */ + // Looking for a switch() label or C++ scope declaration, + // ignore other lines, skip {}-blocks. if (lookfor == LOOKFOR_CASE || lookfor == LOOKFOR_SCOPEDECL) { if (find_last_paren(l, '{', '}') && (trypos = find_start_brace()) != NULL) { @@ -2894,9 +2787,7 @@ int get_c_indent(void) continue; } - /* - * Ignore jump labels with nothing after them. - */ + // Ignore jump labels with nothing after them. if (!curbuf->b_ind_js && cin_islabel()) { l = after_label((char_u *)get_cursor_line_ptr()); if (l == NULL || cin_nocode(l)) { @@ -2904,12 +2795,10 @@ int get_c_indent(void) } } - /* - * Ignore #defines, #if, etc. - * Ignore comment and empty lines. - * (need to get the line again, cin_islabel() may have - * unlocked it) - */ + // Ignore #defines, #if, etc. + // Ignore comment and empty lines. + // (need to get the line again, cin_islabel() may have + // unlocked it) l = (char_u *)get_cursor_line_ptr(); if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount) || cin_nocode(l)) { @@ -2942,9 +2831,8 @@ int get_c_indent(void) } break; } else if (lookfor == LOOKFOR_CPP_BASECLASS) { - /* only look, whether there is a cpp base class - * declaration or initialization before the opening brace. - */ + // only look, whether there is a cpp base class + // declaration or initialization before the opening brace. if (cin_isterminated(l, true, false)) { break; } else { @@ -2952,17 +2840,15 @@ int get_c_indent(void) } } - /* - * What happens next depends on the line being terminated. - * If terminated with a ',' only consider it terminating if - * there is another unterminated statement behind, eg: - * 123, - * sizeof - * here - * Otherwise check whether it is an enumeration or structure - * initialisation (not indented) or a variable declaration - * (indented). - */ + // What happens next depends on the line being terminated. + // If terminated with a ',' only consider it terminating if + // there is another unterminated statement behind, eg: + // 123, + // sizeof + // here + // Otherwise check whether it is an enumeration or structure + // initialisation (not indented) or a variable declaration + // (indented). terminated = cin_isterminated(l, false, true); if (js_cur_has_key) { @@ -3032,12 +2918,10 @@ int get_c_indent(void) } if (trypos != NULL) { - /* - * Check if we are on a case label now. This is - * handled above. - * case xx: if ( asdf && - * asdf) - */ + // Check if we are on a case label now. This is + // handled above. + // case xx: if ( asdf && + // asdf) curwin->w_cursor = *trypos; l = (char_u *)get_cursor_line_ptr(); if (cin_iscase(l, false) || cin_isscopedecl(l)) { @@ -3047,13 +2931,11 @@ int get_c_indent(void) } } - /* - * Skip over continuation lines to find the one to get the - * indent from - * char *usethis = "bla\ - * bla", - * here; - */ + // Skip over continuation lines to find the one to get the + // indent from + // char *usethis = "bla{backslash} + // bla", + // here; if (terminated == ',') { while (curwin->w_cursor.lnum > 1) { l = (char_u *)ml_get(curwin->w_cursor.lnum - 1); @@ -3065,49 +2947,41 @@ int get_c_indent(void) } } - /* - * Get indent and pointer to text for current line, - * ignoring any jump label. XXX - */ + // Get indent and pointer to text for current line, + // ignoring any jump label. XXX if (curbuf->b_ind_js) { cur_amount = get_indent(); } else { cur_amount = skip_label(curwin->w_cursor.lnum, &l); } - /* - * If this is just above the line we are indenting, and it - * starts with a '{', line it up with this line. - * while (not) - * -> { - * } - */ + // If this is just above the line we are indenting, and it + // starts with a '{', line it up with this line. + // while (not) + // -> { + // } if (terminated != ',' && lookfor != LOOKFOR_TERM && theline[0] == '{') { amount = cur_amount; - /* - * Only add b_ind_open_extra when the current line - * doesn't start with a '{', which must have a match - * in the same line (scope is the same). Probably: - * { 1, 2 }, - * -> { 3, 4 } - */ + // Only add b_ind_open_extra when the current line + // doesn't start with a '{', which must have a match + // in the same line (scope is the same). Probably: + // { 1, 2 }, + // -> { 3, 4 } if (*skipwhite((char *)l) != '{') { amount += curbuf->b_ind_open_extra; } if (curbuf->b_ind_cpp_baseclass && !curbuf->b_ind_js) { - /* have to look back, whether it is a cpp base - * class declaration or initialization */ + // have to look back, whether it is a cpp base + // class declaration or initialization lookfor = LOOKFOR_CPP_BASECLASS; continue; } break; } - /* - * Check if we are after an "if", "while", etc. - * Also allow " } else". - */ + // Check if we are after an "if", "while", etc. + // Also allow " } else". if (cin_is_cinword((char *)l) || cin_iselse((char_u *)skipwhite((char *)l))) { // Found an unterminated line after an if (), line up // with the last one. @@ -3124,19 +2998,17 @@ int get_c_indent(void) break; } - /* - * If this is just above the line we are indenting, we - * are finished. - * while (not) - * -> here; - * Otherwise this indent can be used when the line - * before this is terminated. - * yyy; - * if (stat) - * while (not) - * xxx; - * -> here; - */ + // If this is just above the line we are indenting, we + // are finished. + // while (not) + // -> here; + // Otherwise this indent can be used when the line + // before this is terminated. + // yyy; + // if (stat) + // while (not) + // xxx; + // -> here; amount = cur_amount; if (theline[0] == '{') { amount += curbuf->b_ind_open_extra; @@ -3147,13 +3019,11 @@ int get_c_indent(void) break; } - /* - * Special trick: when expecting the while () after a - * do, line up with the while() - * do - * x = 1; - * -> here - */ + // Special trick: when expecting the while () after a + // do, line up with the while() + // do + // x = 1; + // -> here l = (char_u *)skipwhite(get_cursor_line_ptr()); if (cin_isdo(l)) { if (whilelevel == 0) { @@ -3162,16 +3032,14 @@ int get_c_indent(void) whilelevel--; } - /* - * When searching for a terminated line, don't use the - * one between the "if" and the matching "else". - * Need to use the scope of this "else". XXX - * If whilelevel != 0 continue looking for a "do {". - */ + // When searching for a terminated line, don't use the + // one between the "if" and the matching "else". + // Need to use the scope of this "else". XXX + // If whilelevel != 0 continue looking for a "do {". if (cin_iselse(l) && whilelevel == 0) { - /* If we're looking at "} else", let's make sure we - * find the opening brace of the enclosing scope, - * not the one from "if () {". */ + // If we're looking at "} else", let's make sure we + // find the opening brace of the enclosing scope, + // not the one from "if () {". if (*l == '}') { curwin->w_cursor.col = (colnr_T)(l - (char_u *)get_cursor_line_ptr()) + 1; @@ -3183,21 +3051,17 @@ int get_c_indent(void) break; } } - } - /* - * If we're below an unterminated line that is not an - * "if" or something, we may line up with this line or - * add something for a continuation line, depending on - * the line before this one. - */ - else { - /* - * Found two unterminated lines on a row, line up with - * the last one. - * c = 99 + - * 100 + - * -> here; - */ + } else { + // If we're below an unterminated line that is not an + // "if" or something, we may line up with this line or + // add something for a continuation line, depending on + // the line before this one. + + // Found two unterminated lines on a row, line up with + // the last one. + // c = 99 + + // 100 + + // -> here; if (lookfor == LOOKFOR_UNTERM) { // When line ends in a comma add extra indent if (terminated == ',') { @@ -3207,11 +3071,11 @@ int get_c_indent(void) } if (lookfor == LOOKFOR_ENUM_OR_INIT) { - /* Found two lines ending in ',', lineup with the - * lowest one, but check for cpp base class - * declaration/initialization, if it is an - * opening brace or we are looking just for - * enumerations/initializations. */ + // Found two lines ending in ',', lineup with the + // lowest one, but check for cpp base class + // declaration/initialization, if it is an + // opening brace or we are looking just for + // enumerations/initializations. if (terminated == ',') { if (curbuf->b_ind_cpp_baseclass == 0) { break; @@ -3296,19 +3160,14 @@ int get_c_indent(void) } } } - } - /* - * Check if we are after a while (cond); - * If so: Ignore until the matching "do". - */ - else if (cin_iswhileofdo_end(terminated)) { // XXX - /* - * Found an unterminated line after a while ();, line up - * with the last one. - * while (cond); - * 100 + <- line up with this one - * -> here; - */ + // Check if we are after a while (cond); + // If so: Ignore until the matching "do". + } else if (cin_iswhileofdo_end(terminated)) { // XXX + // Found an unterminated line after a while ();, line up + // with the last one. + // while (cond); + // 100 + <- line up with this one + // -> here; if (lookfor == LOOKFOR_UNTERM || lookfor == LOOKFOR_ENUM_OR_INIT) { if (cont_amount > 0) { @@ -3327,28 +3186,22 @@ int get_c_indent(void) } } whilelevel++; - } - /* - * We are after a "normal" statement. - * If we had another statement we can stop now and use the - * indent of that other statement. - * Otherwise the indent of the current statement may be used, - * search backwards for the next "normal" statement. - */ - else { - /* - * Skip single break line, if before a switch label. It - * may be lined up with the case label. - */ + } else { + // We are after a "normal" statement. + // If we had another statement we can stop now and use the + // indent of that other statement. + // Otherwise the indent of the current statement may be used, + // search backwards for the next "normal" statement. + + // Skip single break line, if before a switch label. It + // may be lined up with the case label. if (lookfor == LOOKFOR_NOBREAK && cin_isbreak((char_u *)skipwhite(get_cursor_line_ptr()))) { lookfor = LOOKFOR_ANY; continue; } - /* - * Handle "do {" line. - */ + // Handle "do {" line. if (whilelevel > 0) { l = cin_skipcomment((char_u *)get_cursor_line_ptr()); if (cin_isdo(l)) { @@ -3358,17 +3211,15 @@ int get_c_indent(void) } } - /* - * Found a terminated line above an unterminated line. Add - * the amount for a continuation line. - * x = 1; - * y = foo + - * -> here; - * or - * int x = 1; - * int foo, - * -> here; - */ + // Found a terminated line above an unterminated line. Add + // the amount for a continuation line. + // x = 1; + // y = foo + + // -> here; + // or + // int x = 1; + // int foo, + // -> here; if (lookfor == LOOKFOR_UNTERM || lookfor == LOOKFOR_ENUM_OR_INIT) { if (cont_amount > 0) { @@ -3379,34 +3230,28 @@ int get_c_indent(void) break; } - /* - * Found a terminated line above a terminated line or "if" - * etc. line. Use the amount of the line below us. - * x = 1; x = 1; - * if (asdf) y = 2; - * while (asdf) ->here; - * here; - * ->foo; - */ + // Found a terminated line above a terminated line or "if" + // etc. line. Use the amount of the line below us. + // x = 1; x = 1; + // if (asdf) y = 2; + // while (asdf) ->here; + // here; + // ->foo; if (lookfor == LOOKFOR_TERM) { if (!lookfor_break && whilelevel == 0) { break; } - } - /* - * First line above the one we're indenting is terminated. - * To know what needs to be done look further backward for - * a terminated line. - */ - else { - /* - * position the cursor over the rightmost paren, so - * that matching it will take us back to the start of - * the line. Helps for: - * func(asdr, - * asdfasdf); - * here; - */ + } else { + // First line above the one we're indenting is terminated. + // To know what needs to be done look further backward for + // a terminated line. + + // position the cursor over the rightmost paren, so + // that matching it will take us back to the start of + // the line. Helps for: + // func(asdr, + // asdfasdf); + // here; term_again: l = (char_u *)get_cursor_line_ptr(); if (find_last_paren(l, '(', ')') @@ -3424,21 +3269,18 @@ term_again: } } - /* When aligning with the case statement, don't align - * with a statement after it. - * case 1: { <-- don't use this { position - * stat; - * } - * case 2: - * stat; - * } - */ + // When aligning with the case statement, don't align + // with a statement after it. + // case 1: { <-- don't use this { position + // stat; + // } + // case 2: + // stat; + // } iscase = curbuf->b_ind_keep_case_label && cin_iscase(l, false); - /* - * Get indent and pointer to text for current line, - * ignoring any jump label. - */ + // Get indent and pointer to text for current line, + // ignoring any jump label. amount = skip_label(curwin->w_cursor.lnum, &l); if (theline[0] == '{') { @@ -3451,14 +3293,12 @@ term_again: } lookfor = iscase ? LOOKFOR_ANY : LOOKFOR_TERM; - /* - * When a terminated line starts with "else" skip to - * the matching "if": - * else 3; - * indent this; - * Need to use the scope of this "else". XXX - * If whilelevel != 0 continue looking for a "do {". - */ + // When a terminated line starts with "else" skip to + // the matching "if": + // else 3; + // indent this; + // Need to use the scope of this "else". XXX + // If whilelevel != 0 continue looking for a "do {". if (lookfor == LOOKFOR_TERM && *l != '}' && cin_iselse(l) @@ -3471,10 +3311,8 @@ term_again: continue; } - /* - * If we're at the end of a block, skip to the start of - * that block. - */ + // If we're at the end of a block, skip to the start of + // that block. l = (char_u *)get_cursor_line_ptr(); if (find_last_paren(l, '{', '}') // XXX && (trypos = find_start_brace()) != NULL) { @@ -3521,13 +3359,11 @@ term_again: amount = curbuf->b_ind_first_open; goto theend; } - /* - * If the NEXT line is a function declaration, the current - * line needs to be indented as a function type spec. - * Don't do this if the current line looks like a comment or if the - * current line is terminated, ie. ends in ';', or if the current line - * contains { or }: "void f() {\n if (1)" - */ + // If the NEXT line is a function declaration, the current + // line needs to be indented as a function type spec. + // Don't do this if the current line looks like a comment or if the + // current line is terminated, ie. ends in ';', or if the current line + // contains { or }: "void f() {\n if (1)" if (cur_curpos.lnum < curbuf->b_ml.ml_line_count && !cin_nocode(theline) && vim_strchr((char *)theline, '{') == NULL @@ -3582,18 +3418,16 @@ term_again: continue; } - /* - * If the previous line ends in ',', use one level of - * indentation: - * int foo, - * bar; - * do this before checking for '}' in case of eg. - * enum foobar - * { - * ... - * } foo, - * bar; - */ + // If the previous line ends in ',', use one level of + // indentation: + // int foo, + // bar; + // do this before checking for '}' in case of eg. + // enum foobar + // { + // ... + // } foo, + // bar; if (cin_ends_in(l, (char_u *)",", NULL) || (*l != NUL && (n = l[STRLEN(l) - 1]) == '\\')) { // take us back to opening paren @@ -3602,12 +3436,11 @@ term_again: curwin->w_cursor = *trypos; } - /* For a line ending in ',' that is a continuation line go - * back to the first line with a backslash: - * char *foo = "bla\ - * bla", - * here; - */ + // For a line ending in ',' that is a continuation line go + // back to the first line with a backslash: + // char *foo = "bla{backslash} + // bla", + // here; while (n == 0 && curwin->w_cursor.lnum > 1) { l = (char_u *)ml_get(curwin->w_cursor.lnum - 1); if (*l == NUL || l[STRLEN(l) - 1] != '\\') { @@ -3628,19 +3461,15 @@ term_again: break; } - /* - * If the line looks like a function declaration, and we're - * not in a comment, put it the left margin. - */ + // If the line looks like a function declaration, and we're + // not in a comment, put it the left margin. if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0)) { // XXX break; } l = (char_u *)get_cursor_line_ptr(); - /* - * Finding the closing '}' of a previous function. Put - * current line at the left margin. For when 'cino' has "fs". - */ + // Finding the closing '}' of a previous function. Put + // current line at the left margin. For when 'cino' has "fs". if (*skipwhite((char *)l) == '}') { break; } @@ -3663,11 +3492,9 @@ term_again: break; } - /* - * Find a line only has a semicolon that belongs to a previous - * line ending in '}', e.g. before an #endif. Don't increase - * indent then. - */ + // Find a line only has a semicolon that belongs to a previous + // line ending in '}', e.g. before an #endif. Don't increase + // indent then. if (*(look = (char_u *)skipwhite((char *)l)) == ';' && cin_nocode(look + 1)) { pos_T curpos_save = curwin->w_cursor; @@ -3686,23 +3513,19 @@ term_again: curwin->w_cursor = curpos_save; } - /* - * If the PREVIOUS line is a function declaration, the current - * line (and the ones that follow) needs to be indented as - * parameters. - */ + // If the PREVIOUS line is a function declaration, the current + // line (and the ones that follow) needs to be indented as + // parameters. if (cin_isfuncdecl(&l, curwin->w_cursor.lnum, 0)) { amount = curbuf->b_ind_param; break; } - /* - * If the previous line ends in ';' and the line before the - * previous line ends in ',' or '\', ident to column zero: - * int foo, - * bar; - * indent_to_0 here; - */ + // If the previous line ends in ';' and the line before the + // previous line ends in ',' or '\', ident to column zero: + // int foo, + // bar; + // indent_to_0 here; if (cin_ends_in(l, (char_u *)";", NULL)) { l = (char_u *)ml_get(curwin->w_cursor.lnum - 1); if (cin_ends_in(l, (char_u *)",", NULL) @@ -3712,13 +3535,11 @@ term_again: l = (char_u *)get_cursor_line_ptr(); } - /* - * Doesn't look like anything interesting -- so just - * use the indent of this line. - * - * Position the cursor over the rightmost paren, so that - * matching it will take us back to the start of the line. - */ + // Doesn't look like anything interesting -- so just + // use the indent of this line. + // + // Position the cursor over the rightmost paren, so that + // matching it will take us back to the start of the line. (void)find_last_paren(l, '(', ')'); if ((trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) { @@ -3794,38 +3615,30 @@ static int find_match(int lookfor, linenr_T ourscope) continue; } - /* - * if we've gone outside the braces entirely, - * we must be out of scope... - */ + // if we've gone outside the braces entirely, + // we must be out of scope... theirscope = find_start_brace(); // XXX if (theirscope == NULL) { break; } - /* - * and if the brace enclosing this is further - * back than the one enclosing the else, we're - * out of luck too. - */ + // and if the brace enclosing this is further + // back than the one enclosing the else, we're + // out of luck too. if (theirscope->lnum < ourscope) { break; } - /* - * and if they're enclosed in a *deeper* brace, - * then we can ignore it because it's in a - * different scope... - */ + // and if they're enclosed in a *deeper* brace, + // then we can ignore it because it's in a + // different scope... if (theirscope->lnum > ourscope) { continue; } - /* - * if it was an "else" (that's not an "else if") - * then we need to go back to another if, so - * increment elselevel - */ + // if it was an "else" (that's not an "else if") + // then we need to go back to another if, so + // increment elselevel look = cin_skipcomment((char_u *)get_cursor_line_ptr()); if (cin_iselse(look)) { mightbeif = cin_skipcomment(look + 4); @@ -3835,10 +3648,8 @@ static int find_match(int lookfor, linenr_T ourscope) continue; } - /* - * if it was a "while" then we need to go back to - * another "do", so increment whilelevel. XXX - */ + // if it was a "while" then we need to go back to + // another "do", so increment whilelevel. XXX if (cin_iswhileofdo(look, curwin->w_cursor.lnum)) { whilelevel++; continue; @@ -3847,11 +3658,9 @@ static int find_match(int lookfor, linenr_T ourscope) // If it's an "if" decrement elselevel look = cin_skipcomment((char_u *)get_cursor_line_ptr()); if (cin_isif(look)) { - elselevel--; - /* - * When looking for an "if" ignore "while"s that - * get in the way. - */ + elselevel--; // NOLINT(readability/braces) + // When looking for an "if" ignore "while"s that + // get in the way. if (elselevel == 0 && lookfor == LOOKFOR_IF) { whilelevel = 0; } @@ -3862,11 +3671,9 @@ static int find_match(int lookfor, linenr_T ourscope) whilelevel--; } - /* - * if we've used up all the elses, then - * this must be the if that we want! - * match the indent level of that if. - */ + // if we've used up all the elses, then + // this must be the if that we want! + // match the indent level of that if. if (elselevel <= 0 && whilelevel <= 0) { return OK; } @@ -3874,9 +3681,7 @@ static int find_match(int lookfor, linenr_T ourscope) return FAIL; } -/* - * Do C or expression indenting on the current line. - */ +// Do C or expression indenting on the current line. void do_c_expr_indent(void) { if (*curbuf->b_p_inde != NUL) { diff --git a/src/nvim/main.c b/src/nvim/main.c index 1c7cfea768..a73c465042 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1390,10 +1390,9 @@ scripterror: TIME_MSG("parsing arguments"); } -/* - * Many variables are in "params" so that we can pass them to invoked - * functions without a lot of arguments. "argc" and "argv" are also - * copied, so that they can be changed. */ +// Many variables are in "params" so that we can pass them to invoked +// functions without a lot of arguments. "argc" and "argv" are also +// copied, so that they can be changed. static void init_params(mparm_T *paramp, int argc, char **argv) { CLEAR_POINTER(paramp); @@ -1465,9 +1464,7 @@ static char_u *get_fname(mparm_T *parmp, char_u *cwd) return (char_u *)alist_name(&GARGLIST[0]); } -/* - * Decide about window layout for diff mode after reading vimrc. - */ +// Decide about window layout for diff mode after reading vimrc. static void set_window_layout(mparm_T *paramp) { if (paramp->diff_mode && paramp->window_layout == 0) { @@ -1479,10 +1476,8 @@ static void set_window_layout(mparm_T *paramp) } } -/* - * "-q errorfile": Load the error file now. - * If the error file can't be read, exit before doing anything else. - */ +// "-q errorfile": Load the error file now. +// If the error file can't be read, exit before doing anything else. static void handle_quickfix(mparm_T *paramp) { if (paramp->edit_type == EDIT_QF) { @@ -1498,10 +1493,8 @@ static void handle_quickfix(mparm_T *paramp) } } -/* - * Need to jump to the tag before executing the '-c command'. - * Makes "vim -c '/return' -t main" work. - */ +// Need to jump to the tag before executing the '-c command'. +// Makes "vim -c '/return' -t main" work. static void handle_tag(char_u *tagname) { if (tagname != NULL) { @@ -1540,18 +1533,14 @@ static void read_stdin(void) check_swap_exists_action(); } -/* - * Create the requested number of windows and edit buffers in them. - * Also does recovery if "recoverymode" set. - */ +// Create the requested number of windows and edit buffers in them. +// Also does recovery if "recoverymode" set. static void create_windows(mparm_T *parmp) { int dorewind; int done = 0; - /* - * Create the number of windows that was requested. - */ + // Create the number of windows that was requested. if (parmp->window_count == -1) { // was not set parmp->window_count = 1; } @@ -1670,9 +1659,7 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd) win_T *win; char *p_shm_save = NULL; - /* - * Don't execute Win/Buf Enter/Leave autocommands here - */ + // Don't execute Win/Buf Enter/Leave autocommands here autocmd_no_enter++; autocmd_no_leave++; @@ -1781,9 +1768,7 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd) } } -/* - * Execute the commands from --cmd arguments "cmds[cnt]". - */ +// Execute the commands from --cmd arguments "cmds[cnt]". static void exe_pre_commands(mparm_T *parmp) { char **cmds = parmp->pre_commands; @@ -1803,18 +1788,14 @@ static void exe_pre_commands(mparm_T *parmp) } } -/* - * Execute "+", "-c" and "-S" arguments. - */ +// Execute "+", "-c" and "-S" arguments. static void exe_commands(mparm_T *parmp) { int i; - /* - * We start commands on line 0, make "vim +/pat file" match a - * pattern on line 1. But don't move the cursor when an autocommand - * with g`" was used. - */ + // We start commands on line 0, make "vim +/pat file" match a + // pattern on line 1. But don't move the cursor when an autocommand + // with g`" was used. msg_scroll = true; if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1) { curwin->w_cursor.lnum = 0; @@ -2137,11 +2118,9 @@ static void usage(void) mch_msg(_("\nSee \":help startup-options\" for all options.\n")); } -/* - * Check the result of the ATTENTION dialog: - * When "Quit" selected, exit Vim. - * When "Recover" selected, recover the file. - */ +// Check the result of the ATTENTION dialog: +// When "Quit" selected, exit Vim. +// When "Recover" selected, recover the file. static void check_swap_exists_action(void) { if (swap_exists_action == SEA_QUIT) { diff --git a/src/nvim/mark.c b/src/nvim/mark.c index c6d08eb689..7838986edd 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1,9 +1,7 @@ // 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 -/* - * mark.c: functions for setting marks and jumping to them - */ +// mark.c: functions for setting marks and jumping to them #include #include @@ -39,17 +37,13 @@ #include "nvim/ui.h" #include "nvim/vim.h" -/* - * This file contains routines to maintain and manipulate marks. - */ +// This file contains routines to maintain and manipulate marks. -/* - * If a named file mark's lnum is non-zero, it is valid. - * If a named file mark's fnum is non-zero, it is for an existing buffer, - * otherwise it is from .shada and namedfm[n].fname is the file name. - * There are marks 'A - 'Z (set by user) and '0 to '9 (set when writing - * shada). - */ +// If a named file mark's lnum is non-zero, it is valid. +// If a named file mark's fnum is non-zero, it is for an existing buffer, +// otherwise it is from .shada and namedfm[n].fname is the file name. +// There are marks 'A - 'Z (set by user) and '0 to '9 (set when writing +// shada). /// Global marks (marks with file number or name) static xfmark_T namedfm[NGLOBALMARKS]; @@ -57,10 +51,9 @@ static xfmark_T namedfm[NGLOBALMARKS]; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "mark.c.generated.h" #endif -/* - * Set named mark "c" at current cursor position. - * Returns OK on success, FAIL if bad name given. - */ + +// Set named mark "c" at current cursor position. +// Returns OK on success, FAIL if bad name given. int setmark(int c) { fmarkv_T view = mark_view_make(curwin->w_topline, curwin->w_cursor); @@ -88,11 +81,9 @@ void clear_fmark(fmark_T *fm) CLEAR_POINTER(fm); } -/* - * Set named mark "c" to position "pos". - * When "c" is upper case use file "fnum". - * Returns OK on success, FAIL if bad name given. - */ +// Set named mark "c" to position "pos". +// When "c" is upper case use file "fnum". +// Returns OK on success, FAIL if bad name given. int setmark_pos(int c, pos_T *pos, int fnum, fmarkv_T *view_pt) { int i; @@ -166,10 +157,8 @@ int setmark_pos(int c, pos_T *pos, int fnum, fmarkv_T *view_pt) return FAIL; } -/* - * Set the previous context mark to the current position and add it to the - * jump list. - */ +// Set the previous context mark to the current position and add it to the +// jump list. void setpcmark(void) { xfmark_T *fm; @@ -210,12 +199,10 @@ void setpcmark(void) SET_XFMARK(fm, curwin->w_pcmark, curbuf->b_fnum, view, NULL); } -/* - * To change context, call setpcmark(), then move the current position to - * where ever, then call checkpcmark(). This ensures that the previous - * context will only be changed if the cursor moved to a different line. - * If pcmark was deleted (with "dG") the previous mark is restored. - */ +// To change context, call setpcmark(), then move the current position to +// where ever, then call checkpcmark(). This ensures that the previous +// context will only be changed if the cursor moved to a different line. +// If pcmark was deleted (with "dG") the previous mark is restored. void checkpcmark(void) { if (curwin->w_prev_pcmark.lnum != 0 @@ -653,20 +640,16 @@ fmark_T *getnextmark(pos_T *startpos, int dir, int begin_line) return result; } -/* - * For an xtended filemark: set the fnum from the fname. - * This is used for marks obtained from the .shada file. It's postponed - * until the mark is used to avoid a long startup delay. - */ +// For an xtended filemark: set the fnum from the fname. +// This is used for marks obtained from the .shada file. It's postponed +// until the mark is used to avoid a long startup delay. static void fname2fnum(xfmark_T *fm) { char_u *p; if (fm->fname != NULL) { - /* - * First expand "~/" in the file name to the home directory. - * Don't expand the whole name, it may contain other '~' chars. - */ + // First expand "~/" in the file name to the home directory. + // Don't expand the whole name, it may contain other '~' chars. if (fm->fname[0] == '~' && (fm->fname[1] == '/' #ifdef BACKSLASH_IN_FILENAME || fm->fname[1] == '\\' @@ -690,11 +673,9 @@ static void fname2fnum(xfmark_T *fm) } } -/* - * Check all file marks for a name that matches the file name in buf. - * May replace the name with an fnum. - * Used for marks that come from the .shada file. - */ +// Check all file marks for a name that matches the file name in buf. +// May replace the name with an fnum. +// Used for marks that come from the .shada file. void fmarks_check_names(buf_T *buf) { char_u *name = (char_u *)buf->b_ffname; @@ -792,11 +773,9 @@ void clrallmarks(buf_T *const buf) buf->b_changelistlen = 0; } -/* - * Get name of file from a filemark. - * When it's in the current buffer, return the text at the mark. - * Returns an allocated string. - */ +// Get name of file from a filemark. +// When it's in the current buffer, return the text at the mark. +// Returns an allocated string. char_u *fm_getname(fmark_T *fmark, int lead_len) { if (fmark->fnum == curbuf->b_fnum) { // current buffer @@ -831,9 +810,7 @@ static char *mark_line(pos_T *mp, int lead_len) return s; } -/* - * print the marks - */ +// print the marks void ex_marks(exarg_T *eap) { char_u *arg = (char_u *)eap->arg; @@ -930,9 +907,7 @@ static void show_one_mark(int c, char_u *arg, pos_T *p, char_u *name_arg, int cu } } -/* - * ":delmarks[!] [marks]" - */ +// ":delmarks[!] [marks]" void ex_delmarks(exarg_T *eap) { char_u *p; @@ -1013,9 +988,7 @@ void ex_delmarks(exarg_T *eap) } } -/* - * print the jumplist - */ +// print the jumplist void ex_jumps(exarg_T *eap) { int i; @@ -1068,9 +1041,7 @@ void ex_clearjumps(exarg_T *eap) curwin->w_jumplistidx = 0; } -/* - * print the changelist - */ +// print the changelist void ex_changes(exarg_T *eap) { int i; @@ -1132,17 +1103,15 @@ void ex_changes(exarg_T *eap) *lp += amount_after; \ } -/* - * Adjust marks between line1 and line2 (inclusive) to move 'amount' lines. - * Must be called before changed_*(), appended_lines() or deleted_lines(). - * May be called before or after changing the text. - * When deleting lines line1 to line2, use an 'amount' of MAXLNUM: The marks - * within this range are made invalid. - * If 'amount_after' is non-zero adjust marks after line2. - * Example: Delete lines 34 and 35: mark_adjust(34, 35, MAXLNUM, -2); - * Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0); - * or: mark_adjust(56, 55, MAXLNUM, 2); - */ +// Adjust marks between line1 and line2 (inclusive) to move 'amount' lines. +// Must be called before changed_*(), appended_lines() or deleted_lines(). +// May be called before or after changing the text. +// When deleting lines line1 to line2, use an 'amount' of MAXLNUM: The marks +// within this range are made invalid. +// If 'amount_after' is non-zero adjust marks after line2. +// Example: Delete lines 34 and 35: mark_adjust(34, 35, MAXLNUM, -2); +// Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0); +// or: mark_adjust(56, 55, MAXLNUM, 2); void mark_adjust(linenr_T line1, linenr_T line2, linenr_T amount, linenr_T amount_after, ExtmarkOp op) { @@ -1237,9 +1206,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, linenr_T amount ONE_ADJUST_NODEL(&(saved_cursor.lnum)); } - /* - * Adjust items in all windows related to the current buffer. - */ + // Adjust items in all windows related to the current buffer. FOR_ALL_TAB_WINDOWS(tab, win) { if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // Marks in the jumplist. When deleting lines, this may create @@ -1381,9 +1348,7 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, linenr_T lnum_amount, long c // saved cursor for formatting COL_ADJUST(&saved_cursor); - /* - * Adjust items in all windows related to the current buffer. - */ + // Adjust items in all windows related to the current buffer. FOR_ALL_WINDOWS_IN_TAB(win, curtab) { // marks in the jumplist for (i = 0; i < win->w_jumplistlen; i++) { @@ -1481,9 +1446,7 @@ void cleanup_jumplist(win_T *wp, bool checktail) } } -/* - * Copy the jumplist from window "from" to window "to". - */ +// Copy the jumplist from window "from" to window "to". void copy_jumplist(win_T *from, win_T *to) { int i; @@ -1705,9 +1668,7 @@ bool mark_set_local(const char name, buf_T *const buf, const fmark_T fm, const b return true; } -/* - * Free items in the jumplist of window "wp". - */ +// Free items in the jumplist of window "wp". void free_jumplist(win_T *wp) { int i; diff --git a/src/nvim/mark_defs.h b/src/nvim/mark_defs.h index a78056c5f9..3e3a46cd20 100644 --- a/src/nvim/mark_defs.h +++ b/src/nvim/mark_defs.h @@ -5,10 +5,8 @@ #include "nvim/os/time.h" #include "nvim/pos.h" -/* - * marks: positions in a file - * (a normal mark is a lnum/col pair, the same as a file position) - */ +// marks: positions in a file +// (a normal mark is a lnum/col pair, the same as a file position) /// Flags for outcomes when moving to a mark. typedef enum { diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 0a4182a892..116a66e773 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -132,10 +132,8 @@ const uint8_t utf8len_tab_zero[] = { 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0, // F? }; -/* - * Canonical encoding names and their properties. - * "iso-8859-n" is handled by enc_canonize() directly. - */ +// Canonical encoding names and their properties. +// "iso-8859-n" is handled by enc_canonize() directly. static struct { const char *name; int prop; int codepage; } enc_canon_table[] = @@ -269,9 +267,7 @@ enc_canon_table[] = #define IDX_COUNT 59 }; -/* - * Aliases for encoding names. - */ +// Aliases for encoding names. static struct { const char *name; int canon; } enc_alias_table[] = @@ -342,10 +338,8 @@ enc_alias_table[] = { NULL, 0 } }; -/* - * Find encoding "name" in the list of canonical encoding names. - * Returns -1 if not found. - */ +// Find encoding "name" in the list of canonical encoding names. +// Returns -1 if not found. static int enc_canon_search(const char_u *name) FUNC_ATTR_PURE { @@ -357,10 +351,8 @@ static int enc_canon_search(const char_u *name) return -1; } -/* - * Find canonical encoding "name" in the list and return its properties. - * Returns 0 if not found. - */ +// Find canonical encoding "name" in the list and return its properties. +// Returns 0 if not found. int enc_canon_props(const char_u *name) FUNC_ATTR_PURE { @@ -375,13 +367,11 @@ int enc_canon_props(const char_u *name) return 0; } -/* - * Return the size of the BOM for the current buffer: - * 0 - no BOM - * 2 - UCS-2 or UTF-16 BOM - * 4 - UCS-4 BOM - * 3 - UTF-8 BOM - */ +// Return the size of the BOM for the current buffer: +// 0 - no BOM +// 2 - UCS-2 or UTF-16 BOM +// 4 - UCS-4 BOM +// 3 - UTF-8 BOM int bomb_size(void) FUNC_ATTR_PURE { @@ -401,9 +391,7 @@ int bomb_size(void) return n; } -/* - * Remove all BOM from "s" by moving remaining text. - */ +// Remove all BOM from "s" by moving remaining text. void remove_bom(char_u *s) { char *p = (char *)s; @@ -417,13 +405,11 @@ void remove_bom(char_u *s) } } -/* - * Get class of pointer: - * 0 for blank or NUL - * 1 for punctuation - * 2 for an (ASCII) word character - * >2 for other word characters - */ +// Get class of pointer: +// 0 for blank or NUL +// 1 for punctuation +// 2 for an (ASCII) word character +// >2 for other word characters int mb_get_class(const char_u *p) FUNC_ATTR_PURE { @@ -445,9 +431,7 @@ int mb_get_class_tab(const char_u *p, const uint64_t *const chartab) return utf_class_tab(utf_ptr2char((char *)p), chartab); } -/* - * Return true if "c" is in "table". - */ +// Return true if "c" is in "table". static bool intable(const struct interval *table, size_t n_items, int c) FUNC_ATTR_PURE { @@ -646,22 +630,20 @@ int utf_ptr2char(const char *const p_in) return p[0]; } -/* - * Convert a UTF-8 byte sequence to a wide character. - * String is assumed to be terminated by NUL or after "n" bytes, whichever - * comes first. - * The function is safe in the sense that it never accesses memory beyond the - * first "n" bytes of "s". - * - * On success, returns decoded codepoint, advances "s" to the beginning of - * next character and decreases "n" accordingly. - * - * If end of string was reached, returns 0 and, if "n" > 0, advances "s" past - * NUL byte. - * - * If byte sequence is illegal or incomplete, returns -1 and does not advance - * "s". - */ +// Convert a UTF-8 byte sequence to a wide character. +// String is assumed to be terminated by NUL or after "n" bytes, whichever +// comes first. +// The function is safe in the sense that it never accesses memory beyond the +// first "n" bytes of "s". +// +// On success, returns decoded codepoint, advances "s" to the beginning of +// next character and decreases "n" accordingly. +// +// If end of string was reached, returns 0 and, if "n" > 0, advances "s" past +// NUL byte. +// +// If byte sequence is illegal or incomplete, returns -1 and does not advance +// "s". static int utf_safe_read_char_adv(const char_u **s, size_t *n) { int c; @@ -701,10 +683,8 @@ static int utf_safe_read_char_adv(const char_u **s, size_t *n) return -1; } -/* - * Get character at **pp and advance *pp to the next character. - * Note: composing characters are skipped! - */ +// Get character at **pp and advance *pp to the next character. +// Note: composing characters are skipped! int mb_ptr2char_adv(const char_u **const pp) { int c; @@ -714,10 +694,8 @@ int mb_ptr2char_adv(const char_u **const pp) return c; } -/* - * Get character at **pp and advance *pp to the next character. - * Note: composing characters are returned as separate characters. - */ +// Get character at **pp and advance *pp to the next character. +// Note: composing characters are returned as separate characters. int mb_cptr2char_adv(const char_u **pp) { int c; @@ -784,12 +762,10 @@ int utfc_ptr2char(const char *p_in, int *pcc) return c; } -/* - * Convert a UTF-8 byte string to a wide character. Also get up to MAX_MCO - * composing characters. Use no more than p[maxlen]. - * - * @param [out] pcc: composing chars, last one is 0 - */ +// Convert a UTF-8 byte string to a wide character. Also get up to MAX_MCO +// composing characters. Use no more than p[maxlen]. +// +// @param [out] pcc: composing chars, last one is 0 int utfc_ptr2char_len(const char_u *p, int *pcc, int maxlen) { assert(maxlen > 0); @@ -845,24 +821,20 @@ int utf_ptr2len(const char *const p_in) return len; } -/* - * Return length of UTF-8 character, obtained from the first byte. - * "b" must be between 0 and 255! - * Returns 1 for an invalid first byte value. - */ +// Return length of UTF-8 character, obtained from the first byte. +// "b" must be between 0 and 255! +// Returns 1 for an invalid first byte value. int utf_byte2len(int b) { return utf8len_tab[b]; } -/* - * Get the length of UTF-8 byte sequence "p[size]". Does not include any - * following composing characters. - * Returns 1 for "". - * Returns 1 for an illegal byte sequence (also in incomplete byte seq.). - * Returns number > "size" for an incomplete byte sequence. - * Never returns zero. - */ +// Get the length of UTF-8 byte sequence "p[size]". Does not include any +// following composing characters. +// Returns 1 for "". +// Returns 1 for an illegal byte sequence (also in incomplete byte seq.). +// Returns number > "size" for an incomplete byte sequence. +// Never returns zero. int utf_ptr2len_len(const char_u *p, int size) { int len; @@ -948,10 +920,8 @@ int utfc_ptr2len_len(const char *p, int size) return 1; } - /* - * Check for composing characters. We can handle only the first six, but - * skip all of them (otherwise the cursor would get stuck). - */ + // Check for composing characters. We can handle only the first six, but + // skip all of them (otherwise the cursor would get stuck). prevlen = 0; while (len < size) { int len_next_char; @@ -960,10 +930,8 @@ int utfc_ptr2len_len(const char *p, int size) break; } - /* - * Next character length should not go beyond size to ensure that - * utf_composinglike(...) does not read beyond size. - */ + // Next character length should not go beyond size to ensure that + // utf_composinglike(...) does not read beyond size. len_next_char = utf_ptr2len_len((char_u *)p + len, size - len); if (len_next_char > size - len) { break; @@ -1042,20 +1010,16 @@ int utf_char2bytes(const int c, char *const buf) } } -/* - * Return true if "c" is a composing UTF-8 character. This means it will be - * drawn on top of the preceding character. - * Based on code from Markus Kuhn. - */ +// Return true if "c" is a composing UTF-8 character. This means it will be +// drawn on top of the preceding character. +// Based on code from Markus Kuhn. bool utf_iscomposing(int c) { return intable(combining, ARRAY_SIZE(combining), c); } -/* - * Return true for characters that can be displayed in a normal way. - * Only for characters of 0x100 and above! - */ +// Return true for characters that can be displayed in a normal way. +// Only for characters of 0x100 and above! bool utf_printable(int c) { // Sorted list of non-overlapping intervals. @@ -1070,12 +1034,10 @@ bool utf_printable(int c) return !intable(nonprint, ARRAY_SIZE(nonprint), c); } -/* - * Get class of a Unicode character. - * 0: white space - * 1: punctuation - * 2 or bigger: some class of word character. - */ +// Get class of a Unicode character. +// 0: white space +// 1: punctuation +// 2 or bigger: some class of word character. int utf_class(const int c) { return utf_class_tab(c, curbuf->b_chartab); @@ -1204,11 +1166,9 @@ bool utf_ambiguous_width(int c) || intable(emoji_all, ARRAY_SIZE(emoji_all), c)); } -/* - * Generic conversion function for case operations. - * Return the converted equivalent of "a", which is a UCS-4 character. Use - * the given conversion "table". Uses binary search on "table". - */ +// Generic conversion function for case operations. +// Return the converted equivalent of "a", which is a UCS-4 character. Use +// the given conversion "table". Uses binary search on "table". static int utf_convert(int a, const convertStruct *const table, size_t n_items) { size_t start, mid, end; // indices into table @@ -1234,10 +1194,8 @@ static int utf_convert(int a, const convertStruct *const table, size_t n_items) } } -/* - * Return the folded-case equivalent of "a", which is a UCS-4 character. Uses - * simple case folding. - */ +// Return the folded-case equivalent of "a", which is a UCS-4 character. Uses +// simple case folding. int utf_fold(int a) { if (a < 0x80) { @@ -1566,10 +1524,8 @@ int mb_stricmp(const char *s1, const char *s2) return mb_strnicmp(s1, s2, MAXCOL); } -/* - * "g8": show bytes of the UTF-8 char under the cursor. Doesn't matter what - * 'encoding' has been set to. - */ +// "g8": show bytes of the UTF-8 char under the cursor. Doesn't matter what +// 'encoding' has been set to. void show_utf8(void) { int len; @@ -1916,9 +1872,7 @@ int utf_cp_head_off(const char_u *base, const char_u *p) return i; } -/* - * Find the next illegal byte sequence. - */ +// Find the next illegal byte sequence. void utf_find_illegal(void) { pos_T pos = curwin->w_cursor; @@ -2008,10 +1962,8 @@ bool utf_valid_string(const char_u *s, const char_u *end) return true; } -/* - * If the cursor moves on an trail byte, set the cursor on the lead byte. - * Thus it moves left if necessary. - */ +// If the cursor moves on an trail byte, set the cursor on the lead byte. +// Thus it moves left if necessary. void mb_adjust_cursor(void) { mark_mb_adjustpos(curbuf, &curwin->w_cursor); @@ -2238,10 +2190,8 @@ static int enc_alias_search(const char_u *name) # include #endif -/* - * Get the canonicalized encoding of the current locale. - * Returns an allocated string when successful, NULL when not. - */ +// Get the canonicalized encoding of the current locale. +// Returns an allocated string when successful, NULL when not. char_u *enc_locale(void) { int i; @@ -2307,12 +2257,10 @@ enc_locale_copy_enc: #if defined(HAVE_ICONV) -/* - * Call iconv_open() with a check if iconv() works properly (there are broken - * versions). - * Returns (void *)-1 if failed. - * (should return iconv_t, but that causes problems with prototypes). - */ +// Call iconv_open() with a check if iconv() works properly (there are broken +// versions). +// Returns (void *)-1 if failed. +// (should return iconv_t, but that causes problems with prototypes). void *my_iconv_open(char_u *to, char_u *from) { iconv_t fd; @@ -2328,13 +2276,11 @@ void *my_iconv_open(char_u *to, char_u *from) fd = iconv_open(enc_skip((char *)to), enc_skip((char *)from)); if (fd != (iconv_t)-1 && iconv_working == kUnknown) { - /* - * Do a dummy iconv() call to check if it actually works. There is a - * version of iconv() on Linux that is broken. We can't ignore it, - * because it's wide-spread. The symptoms are that after outputting - * the initial shift state the "to" pointer is NULL and conversion - * stops for no apparent reason after about 8160 characters. - */ + // Do a dummy iconv() call to check if it actually works. There is a + // version of iconv() on Linux that is broken. We can't ignore it, + // because it's wide-spread. The symptoms are that after outputting + // the initial shift state the "to" pointer is NULL and conversion + // stops for no apparent reason after about 8160 characters. p = (char *)tobuf; tolen = ICONV_TESTLEN; (void)iconv(fd, NULL, NULL, &p, &tolen); @@ -2350,13 +2296,11 @@ void *my_iconv_open(char_u *to, char_u *from) return (void *)fd; } -/* - * Convert the string "str[slen]" with iconv(). - * If "unconvlenp" is not NULL handle the string ending in an incomplete - * sequence and set "*unconvlenp" to the length of it. - * Returns the converted string in allocated memory. NULL for an error. - * If resultlenp is not NULL, sets it to the result length in bytes. - */ +// Convert the string "str[slen]" with iconv(). +// If "unconvlenp" is not NULL handle the string ending in an incomplete +// sequence and set "*unconvlenp" to the length of it. +// Returns the converted string in allocated memory. NULL for an error. +// If resultlenp is not NULL, sets it to the result length in bytes. static char_u *iconv_string(const vimconv_T *const vcp, char_u *str, size_t slen, size_t *unconvlenp, size_t *resultlenp) { @@ -2529,11 +2473,9 @@ char *string_convert(const vimconv_T *const vcp, char *ptr, size_t *lenp) return (char *)string_convert_ext(vcp, (char_u *)ptr, lenp, NULL); } -/* - * Like string_convert(), but when "unconvlenp" is not NULL and there are is - * an incomplete sequence at the end it is not converted and "*unconvlenp" is - * set to the number of remaining bytes. - */ +// Like string_convert(), but when "unconvlenp" is not NULL and there are is +// an incomplete sequence at the end it is not converted and "*unconvlenp" is +// set to the number of remaining bytes. char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp, size_t *unconvlenp) { diff --git a/src/nvim/mbyte.h b/src/nvim/mbyte.h index 2a9afcbd03..b499f33cc6 100644 --- a/src/nvim/mbyte.h +++ b/src/nvim/mbyte.h @@ -11,12 +11,10 @@ #include "nvim/os/os_defs.h" // For indirect #include "nvim/types.h" // for char_u -/* - * Return byte length of character that starts with byte "b". - * Returns 1 for a single-byte character. - * MB_BYTE2LEN_CHECK() can be used to count a special key as one byte. - * Don't call MB_BYTE2LEN(b) with b < 0 or b > 255! - */ +// Return byte length of character that starts with byte "b". +// Returns 1 for a single-byte character. +// MB_BYTE2LEN_CHECK() can be used to count a special key as one byte. +// Don't call MB_BYTE2LEN(b) with b < 0 or b > 255! #define MB_BYTE2LEN(b) utf8len_tab[b] #define MB_BYTE2LEN_CHECK(b) (((b) < 0 || (b) > 255) ? 1 : utf8len_tab[b]) diff --git a/src/nvim/memline.c b/src/nvim/memline.c index cd143bd52c..35650755b4 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -5,36 +5,34 @@ // #define CHECK(c, s) do { if (c) emsg(s); } while (0) #define CHECK(c, s) do {} while (0) -/* - * memline.c: Contains the functions for appending, deleting and changing the - * text lines. The memfile functions are used to store the information in - * blocks of memory, backed up by a file. The structure of the information is - * a tree. The root of the tree is a pointer block. The leaves of the tree - * are data blocks. In between may be several layers of pointer blocks, - * forming branches. - * - * Three types of blocks are used: - * - Block nr 0 contains information for recovery - * - Pointer blocks contain list of pointers to other blocks. - * - Data blocks contain the actual text. - * - * Block nr 0 contains the block0 structure (see below). - * - * Block nr 1 is the first pointer block. It is the root of the tree. - * Other pointer blocks are branches. - * - * If a line is too big to fit in a single page, the block containing that - * line is made big enough to hold the line. It may span several pages. - * Otherwise all blocks are one page. - * - * A data block that was filled when starting to edit a file and was not - * changed since then, can have a negative block number. This means that it - * has not yet been assigned a place in the file. When recovering, the lines - * in this data block can be read from the original file. When the block is - * changed (lines appended/deleted/changed) or when it is flushed it gets a - * positive number. Use mf_trans_del() to get the new number, before calling - * mf_get(). - */ +// memline.c: Contains the functions for appending, deleting and changing the +// text lines. The memfile functions are used to store the information in +// blocks of memory, backed up by a file. The structure of the information is +// a tree. The root of the tree is a pointer block. The leaves of the tree +// are data blocks. In between may be several layers of pointer blocks, +// forming branches. +// +// Three types of blocks are used: +// - Block nr 0 contains information for recovery +// - Pointer blocks contain list of pointers to other blocks. +// - Data blocks contain the actual text. +// +// Block nr 0 contains the block0 structure (see below). +// +// Block nr 1 is the first pointer block. It is the root of the tree. +// Other pointer blocks are branches. +// +// If a line is too big to fit in a single page, the block containing that +// line is made big enough to hold the line. It may span several pages. +// Otherwise all blocks are one page. +// +// A data block that was filled when starting to edit a file and was not +// changed since then, can have a negative block number. This means that it +// has not yet been assigned a place in the file. When recovering, the lines +// in this data block can be read from the original file. When the block is +// changed (lines appended/deleted/changed) or when it is flushed it gets a +// positive number. Use mf_trans_del() to get the new number, before calling +// mf_get(). #include #include @@ -90,9 +88,7 @@ typedef struct pointer_entry PTR_EN; // block/line-count pair #define BLOCK0_ID0 'b' // block 0 id 0 #define BLOCK0_ID1 '0' // block 0 id 1 -/* - * pointer to a block, used in a pointer block - */ +// pointer to a block, used in a pointer block struct pointer_entry { blocknr_T pe_bnum; // block number linenr_T pe_line_count; // number of lines in this branch @@ -100,9 +96,7 @@ struct pointer_entry { int pe_page_count; // number of pages in block pe_bnum }; -/* - * A pointer block contains a list of branches in the tree. - */ +// A pointer block contains a list of branches in the tree. struct pointer_block { uint16_t pb_id; // ID for pointer block: PTR_ID uint16_t pb_count; // number of pointers in this block @@ -111,13 +105,11 @@ struct pointer_block { // followed by empty space until end of page }; -/* - * A data block is a leaf in the tree. - * - * The text of the lines is at the end of the block. The text of the first line - * in the block is put at the end, the text of the second line in front of it, - * etc. Thus the order of the lines is the opposite of the line number. - */ +// A data block is a leaf in the tree. +// +// The text of the lines is at the end of the block. The text of the first line +// in the block is put at the end, the text of the second line in front of it, +// etc. Thus the order of the lines is the opposite of the line number. struct data_block { uint16_t db_id; // ID for data block: DATA_ID unsigned db_free; // free space available @@ -130,14 +122,12 @@ struct data_block { // end of page }; -/* - * The low bits of db_index hold the actual index. The topmost bit is - * used for the global command to be able to mark a line. - * This method is not clean, but otherwise there would be at least one extra - * byte used for each line. - * The mark has to be in this place to keep it with the correct line when other - * lines are inserted or deleted. - */ +// The low bits of db_index hold the actual index. The topmost bit is +// used for the global command to be able to mark a line. +// This method is not clean, but otherwise there would be at least one extra +// byte used for each line. +// The mark has to be in this place to keep it with the correct line when other +// lines are inserted or deleted. #define DB_MARKED ((unsigned)1 << ((sizeof(unsigned) * 8) - 1)) #define DB_INDEX_MASK (~DB_MARKED) @@ -149,28 +139,24 @@ struct data_block { #define B0_FNAME_SIZE_CRYPT 890 // 10 bytes used for other things #define B0_UNAME_SIZE 40 #define B0_HNAME_SIZE 40 -/* - * Restrict the numbers to 32 bits, otherwise most compilers will complain. - * This won't detect a 64 bit machine that only swaps a byte in the top 32 - * bits, but that is crazy anyway. - */ +// Restrict the numbers to 32 bits, otherwise most compilers will complain. +// This won't detect a 64 bit machine that only swaps a byte in the top 32 +// bits, but that is crazy anyway. #define B0_MAGIC_LONG 0x30313233L #define B0_MAGIC_INT 0x20212223L #define B0_MAGIC_SHORT 0x10111213L #define B0_MAGIC_CHAR 0x55 -/* - * Block zero holds all info about the swap file. - * - * NOTE: DEFINITION OF BLOCK 0 SHOULD NOT CHANGE! It would make all existing - * swap files unusable! - * - * If size of block0 changes anyway, adjust MIN_SWAP_PAGE_SIZE in vim.h!! - * - * This block is built up of single bytes, to make it portable across - * different machines. b0_magic_* is used to check the byte order and size of - * variables, because the rest of the swap file is not portable. - */ +// Block zero holds all info about the swap file. +// +// NOTE: DEFINITION OF BLOCK 0 SHOULD NOT CHANGE! It would make all existing +// swap files unusable! +// +// If size of block0 changes anyway, adjust MIN_SWAP_PAGE_SIZE in vim.h!! +// +// This block is built up of single bytes, to make it portable across +// different machines. b0_magic_* is used to check the byte order and size of +// variables, because the rest of the swap file is not portable. struct block0 { char_u b0_id[2]; ///< ID for block 0: BLOCK0_ID0 and BLOCK0_ID1. char_u b0_version[10]; // Vim version string @@ -187,18 +173,14 @@ struct block0 { char_u b0_magic_char; // check for last char }; -/* - * Note: b0_dirty and b0_flags are put at the end of the file name. For very - * long file names in older versions of Vim they are invalid. - * The 'fileencoding' comes before b0_flags, with a NUL in front. But only - * when there is room, for very long file names it's omitted. - */ +// Note: b0_dirty and b0_flags are put at the end of the file name. For very +// long file names in older versions of Vim they are invalid. +// The 'fileencoding' comes before b0_flags, with a NUL in front. But only +// when there is room, for very long file names it's omitted. #define B0_DIRTY 0x55 #define b0_dirty b0_fname[B0_FNAME_SIZE_ORG - 1] -/* - * The b0_flags field is new in Vim 7.0. - */ +// The b0_flags field is new in Vim 7.0. #define b0_flags b0_fname[B0_FNAME_SIZE_ORG - 2] // The lowest two bits contain the fileformat. Zero means it's not set @@ -216,17 +198,13 @@ struct block0 { #define STACK_INCR 5 // nr of entries added to ml_stack at a time -/* - * The line number where the first mark may be is remembered. - * If it is 0 there are no marks at all. - * (always used for the current buffer only, no buffer change possible while - * executing a global command). - */ +// The line number where the first mark may be is remembered. +// If it is 0 there are no marks at all. +// (always used for the current buffer only, no buffer change possible while +// executing a global command). static linenr_T lowest_marked = 0; -/* - * arguments for ml_find_line() - */ +// arguments for ml_find_line() #define ML_DELETE 0x11 // delete line #define ML_INSERT 0x12 // insert line #define ML_FIND 0x13 // just find the line @@ -253,9 +231,7 @@ int ml_open(buf_T *buf) PTR_BL *pp; DATA_BL *dp; - /* - * init fields in memline struct - */ + // init fields in memline struct buf->b_ml.ml_stack_size = 0; // no stack yet buf->b_ml.ml_stack = NULL; // no stack yet buf->b_ml.ml_stack_top = 0; // nothing in the stack @@ -269,9 +245,7 @@ int ml_open(buf_T *buf) buf->b_p_swf = false; } - /* - * When 'updatecount' is non-zero swap file may be opened later. - */ + // When 'updatecount' is non-zero swap file may be opened later. if (!buf->terminal && p_uc && buf->b_p_swf) { buf->b_may_swap = true; } else { @@ -289,9 +263,7 @@ int ml_open(buf_T *buf) buf->b_ml.ml_line_count = 1; curwin->w_nrwidth_line_count = 0; - /* - * fill block0 struct and write page 0 - */ + // fill block0 struct and write page 0 hp = mf_new(mfp, false, 1); if (hp->bh_bnum != 0) { iemsg(_("E298: Didn't get block nr 0?")); @@ -319,21 +291,17 @@ int ml_open(buf_T *buf) long_to_char(os_get_pid(), b0p->b0_pid); } - /* - * Always sync block number 0 to disk, so we can check the file name in - * the swap file in findswapname(). Don't do this for a help files or - * a spell buffer though. - * Only works when there's a swapfile, otherwise it's done when the file - * is created. - */ + // Always sync block number 0 to disk, so we can check the file name in + // the swap file in findswapname(). Don't do this for a help files or + // a spell buffer though. + // Only works when there's a swapfile, otherwise it's done when the file + // is created. mf_put(mfp, hp, true, false); if (!buf->b_help && !B_SPELL(buf)) { (void)mf_sync(mfp, 0); } - /* - * Fill in root pointer block and write page 1. - */ + // Fill in root pointer block and write page 1. if ((hp = ml_new_ptr(mfp)) == NULL) { goto error; } @@ -349,9 +317,7 @@ int ml_open(buf_T *buf) pp->pb_pointer[0].pe_line_count = 1; // line count after insertion mf_put(mfp, hp, true, false); - /* - * Allocate first data block and create an empty line 1. - */ + // Allocate first data block and create an empty line 1. hp = ml_new_data(mfp, false, 1); if (hp->bh_bnum != 2) { iemsg(_("E298: Didn't get block nr 2?")); @@ -388,10 +354,8 @@ void ml_setname(buf_T *buf) mfp = buf->b_ml.ml_mfp; if (mfp->mf_fd < 0) { // there is no swap file yet - /* - * When 'updatecount' is 0 and 'noswapfile' there is no swap file. - * For help files we will make a swap file now. - */ + // When 'updatecount' is 0 and 'noswapfile' there is no swap file. + // For help files we will make a swap file now. if (p_uc != 0 && (cmdmod.cmod_flags & CMOD_NOSWAPFILE) == 0) { ml_open_file(buf); // create a swap file } @@ -653,13 +617,11 @@ static void set_b0_fname(ZERO_BL *b0p, buf_T *buf) } else { char uname[B0_UNAME_SIZE]; - /* - * For a file under the home directory of the current user, we try to - * replace the home directory path with "~user". This helps when - * editing the same file on different machines over a network. - * First replace home dir path with "~/" with home_replace(). - * Then insert the user name to get "~user/". - */ + // For a file under the home directory of the current user, we try to + // replace the home directory path with "~user". This helps when + // editing the same file on different machines over a network. + // First replace home dir path with "~/" with home_replace(). + // Then insert the user name to get "~user/". home_replace(NULL, buf->b_ffname, (char *)b0p->b0_fname, B0_FNAME_SIZE_CRYPT, true); if (b0p->b0_fname[0] == '~') { @@ -813,15 +775,11 @@ void ml_recover(bool checkext) getout(1); } - /* - * Allocate a buffer structure for the swap file that is used for recovery. - * Only the memline in it is really used. - */ + // Allocate a buffer structure for the swap file that is used for recovery. + // Only the memline in it is really used. buf = xmalloc(sizeof(buf_T)); - /* - * init fields in memline struct - */ + // init fields in memline struct buf->b_ml.ml_stack_size = 0; // no stack yet buf->b_ml.ml_stack = NULL; // no stack yet buf->b_ml.ml_stack_top = 0; // nothing in the stack @@ -830,9 +788,7 @@ void ml_recover(bool checkext) buf->b_ml.ml_locked = NULL; // no locked block buf->b_ml.ml_flags = 0; - /* - * open the memfile from the old swap file - */ + // open the memfile from the old swap file p = xstrdup(fname_used); // save "fname_used" for the message: // mf_open() will consume "fname_used"! mfp = mf_open(fname_used, O_RDONLY); @@ -843,17 +799,13 @@ void ml_recover(bool checkext) } buf->b_ml.ml_mfp = mfp; - /* - * The page size set in mf_open() might be different from the page size - * used in the swap file, we must get it from block 0. But to read block - * 0 we need a page size. Use the minimal size for block 0 here, it will - * be set to the real value below. - */ + // The page size set in mf_open() might be different from the page size + // used in the swap file, we must get it from block 0. But to read block + // 0 we need a page size. Use the minimal size for block 0 here, it will + // be set to the real value below. mfp->mf_page_size = MIN_SWAP_PAGE_SIZE; - /* - * try to read block 0 - */ + // try to read block 0 if ((hp = mf_get(mfp, 0, 1)) == NULL) { msg_start(); msg_puts_attr(_("Unable to read block 0 from "), attr | MSG_HIST); @@ -891,10 +843,8 @@ void ml_recover(bool checkext) goto theend; } - /* - * If we guessed the wrong page size, we have to recalculate the - * highest block number in the file. - */ + // If we guessed the wrong page size, we have to recalculate the + // highest block number in the file. if (mfp->mf_page_size != (unsigned)char_to_long(b0p->b0_page_size)) { unsigned previous_page_size = mfp->mf_page_size; @@ -941,9 +891,7 @@ void ml_recover(bool checkext) smsg(_("Original file \"%s\""), NameBuff); msg_putchar('\n'); - /* - * check date of swap file and original file - */ + // check date of swap file and original file FileInfo org_file_info; FileInfo swp_file_info; mtime = char_to_long(b0p->b0_mtime); @@ -969,18 +917,14 @@ void ml_recover(bool checkext) mf_put(mfp, hp, false, false); // release block 0 hp = NULL; - /* - * Now that we are sure that the file is going to be recovered, clear the - * contents of the current buffer. - */ + // Now that we are sure that the file is going to be recovered, clear the + // contents of the current buffer. while (!(curbuf->b_ml.ml_flags & ML_EMPTY)) { ml_delete((linenr_T)1, false); } - /* - * Try reading the original file to obtain the values of 'fileformat', - * 'fileencoding', etc. Ignore errors. The text itself is not used. - */ + // Try reading the original file to obtain the values of 'fileformat', + // 'fileencoding', etc. Ignore errors. The text itself is not used. if (curbuf->b_ffname != NULL) { orig_file_status = readfile(curbuf->b_ffname, NULL, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW, false); @@ -1017,9 +961,7 @@ void ml_recover(bool checkext) if (hp != NULL) { mf_put(mfp, hp, false, false); // release previous block } - /* - * get block - */ + // get block if ((hp = mf_get(mfp, bnum, page_count)) == NULL) { if (bnum == 1) { semsg(_("E309: Unable to read block 1 from %s"), mfp->mf_fname); @@ -1049,11 +991,9 @@ void ml_recover(bool checkext) error++; } else if (idx < (int)pp->pb_count) { // go a block deeper if (pp->pb_pointer[idx].pe_bnum < 0) { - /* - * Data block with negative block number. - * Try to read lines from the original file. - * This is slow, but it works. - */ + // Data block with negative block number. + // Try to read lines from the original file. + // This is slow, but it works. if (!cannot_open) { line_count = pp->pb_pointer[idx].pe_line_count; if (readfile(curbuf->b_ffname, NULL, lnum, @@ -1073,9 +1013,7 @@ void ml_recover(bool checkext) continue; } - /* - * going one block deeper in the tree - */ + // going one block deeper in the tree top = ml_add_stack(buf); // new entry in stack ip = &(buf->b_ml.ml_stack[top]); ip->ip_bnum = bnum; @@ -1116,10 +1054,8 @@ void ml_recover(bool checkext) // make sure there is a NUL at the end of the block *((char_u *)dp + dp->db_txt_end - 1) = NUL; - /* - * check number of lines in block - * if wrong, use count in data block - */ + // check number of lines in block + // if wrong, use count in data block if (line_count != dp->db_line_count) { ml_append(lnum++, _("??? from here until ???END lines" @@ -1151,22 +1087,18 @@ void ml_recover(bool checkext) break; } - /* - * go one block up in the tree - */ + // go one block up in the tree ip = &(buf->b_ml.ml_stack[--(buf->b_ml.ml_stack_top)]); bnum = ip->ip_bnum; idx = ip->ip_index + 1; // go to next index page_count = 1; } - /* - * Compare the buffer contents with the original file. When they differ - * set the 'modified' flag. - * Lines 1 - lnum are the new contents. - * Lines lnum + 1 to ml_line_count are the original contents. - * Line ml_line_count + 1 in the dummy empty line. - */ + // Compare the buffer contents with the original file. When they differ + // set the 'modified' flag. + // Lines 1 - lnum are the new contents. + // Lines lnum + 1 to ml_line_count are the original contents. + // Line ml_line_count + 1 in the dummy empty line. if (orig_file_status != OK || curbuf->b_ml.ml_line_count != lnum * 2 + 1) { // Recovering an empty file results in two lines and the first line is // empty. Don't set the modified flag then. @@ -1188,10 +1120,8 @@ void ml_recover(bool checkext) } } - /* - * Delete the lines from the original file and the dummy line from the - * empty buffer. These will now be after the last line in the buffer. - */ + // Delete the lines from the original file and the dummy line from the + // empty buffer. These will now be after the last line in the buffer. while (curbuf->b_ml.ml_line_count > lnum && !(curbuf->b_ml.ml_flags & ML_EMPTY)) { ml_delete(curbuf->b_ml.ml_line_count, false); @@ -1343,11 +1273,9 @@ int recover_names(char_u *fname, int list, int nr, char_u **fname_out) num_files = 0; } - /* - * When no swap file found, wildcard expansion might have failed (e.g. - * not able to execute the shell). - * Try finding a swap file by simply adding ".swp" to the file name. - */ + // When no swap file found, wildcard expansion might have failed (e.g. + // not able to execute the shell). + // Try finding a swap file by simply adding ".swp" to the file name. if (*dirp == NUL && file_count + num_files == 0 && fname != NULL) { char_u *swapname = (char_u *)modname((char *)fname_res, ".swp", true); if (swapname != NULL) { @@ -1361,9 +1289,7 @@ int recover_names(char_u *fname, int list, int nr, char_u **fname_out) } } - /* - * remove swapfile name of the current buffer, it must be ignored - */ + // remove swapfile name of the current buffer, it must be ignored if (curbuf->b_ml.ml_mfp != NULL && (p = curbuf->b_ml.ml_mfp->mf_fname) != NULL) { for (int i = 0; i < num_files; i++) { @@ -1522,9 +1448,7 @@ static time_t swapfile_info(char_u *fname) msg_puts(os_ctime_r(&x, ctime_buf, sizeof(ctime_buf))); } - /* - * print the original file name - */ + // print the original file name fd = os_open((char *)fname, O_RDONLY, 0); if (fd >= 0) { if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0)) { @@ -1681,10 +1605,8 @@ void ml_sync_all(int check_file, int check_char, bool do_fsync) (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); if (bufIsChanged(buf) && check_file && mf_need_trans(buf->b_ml.ml_mfp) && buf->b_ffname != NULL) { - /* - * If the original file does not exist anymore or has been changed - * call ml_preserve() to get rid of all negative numbered blocks. - */ + // If the original file does not exist anymore or has been changed + // call ml_preserve() to get rid of all negative numbered blocks. FileInfo file_info; if (!os_fileinfo(buf->b_ffname, &file_info) || file_info.stat.st_mtim.tv_sec != buf->b_mtime_read @@ -1739,18 +1661,16 @@ void ml_preserve(buf_T *buf, int message, bool do_fsync) // stack is invalid after mf_sync(.., MFS_ALL) buf->b_ml.ml_stack_top = 0; - /* - * Some of the data blocks may have been changed from negative to - * positive block number. In that case the pointer blocks need to be - * updated. - * - * We don't know in which pointer block the references are, so we visit - * all data blocks until there are no more translations to be done (or - * we hit the end of the file, which can only happen in case a write fails, - * e.g. when file system if full). - * ml_find_line() does the work by translating the negative block numbers - * when getting the first line of each data block. - */ + // Some of the data blocks may have been changed from negative to + // positive block number. In that case the pointer blocks need to be + // updated. + // + // We don't know in which pointer block the references are, so we visit + // all data blocks until there are no more translations to be done (or + // we hit the end of the file, which can only happen in case a write fails, + // e.g. when file system if full). + // ml_find_line() does the work by translating the negative block numbers + // when getting the first line of each data block. if (mf_need_trans(mfp) && !got_int) { lnum = 1; while (mf_need_trans(mfp) && lnum <= buf->b_ml.ml_line_count) { @@ -1781,13 +1701,11 @@ theend: } } -/* - * NOTE: The pointer returned by the ml_get_*() functions only remains valid - * until the next call! - * line1 = ml_get(1); - * line2 = ml_get(2); // line1 is now invalid! - * Make a copy of the line if necessary. - */ +// NOTE: The pointer returned by the ml_get_*() functions only remains valid +// until the next call! +// line1 = ml_get(1); +// line2 = ml_get(2); // line1 is now invalid! +// Make a copy of the line if necessary. /// @return a pointer to a (read-only copy of a) line. /// @@ -1851,20 +1769,16 @@ errorret: return (char_u *)""; } - /* - * See if it is the same line as requested last time. - * Otherwise may need to flush last used line. - * Don't use the last used line when 'swapfile' is reset, need to load all - * blocks. - */ + // See if it is the same line as requested last time. + // Otherwise may need to flush last used line. + // Don't use the last used line when 'swapfile' is reset, need to load all + // blocks. if (buf->b_ml.ml_line_lnum != lnum) { ml_flush_line(buf); - /* - * Find the data block containing the line. - * This also fills the stack with the blocks from the root to the data - * block and releases any locked block. - */ + // Find the data block containing the line. + // This also fills the stack with the blocks from the root to the data + // block and releases any locked block. if ((hp = ml_find_line(buf, lnum, ML_FIND)) == NULL) { if (recursive == 0) { // Avoid giving this message for a recursive call, may happen @@ -1986,11 +1900,9 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b memfile_T *mfp = buf->b_ml.ml_mfp; int page_size = (int)mfp->mf_page_size; - /* - * find the data block containing the previous line - * This also fills the stack with the blocks from the root to the data block - * This also releases any locked block. - */ + // find the data block containing the previous line + // This also fills the stack with the blocks from the root to the data block + // This also releases any locked block. if ((hp = ml_find_line(buf, lnum == 0 ? (linenr_T)1 : lnum, ML_INSERT)) == NULL) { return FAIL; @@ -2008,22 +1920,18 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b dp = hp->bh_data; - /* - * If - * - there is not enough room in the current block - * - appending to the last line in the block - * - not appending to the last line in the file - * insert in front of the next block. - */ + // If + // - there is not enough room in the current block + // - appending to the last line in the block + // - not appending to the last line in the file + // insert in front of the next block. if ((int)dp->db_free < space_needed && db_idx == line_count - 1 && lnum < buf->b_ml.ml_line_count) { - /* - * Now that the line is not going to be inserted in the block that we - * expected, the line count has to be adjusted in the pointer blocks - * by using ml_locked_lineadd. - */ - --(buf->b_ml.ml_locked_lineadd); - --(buf->b_ml.ml_locked_high); + // Now that the line is not going to be inserted in the block that we + // expected, the line count has to be adjusted in the pointer blocks + // by using ml_locked_lineadd. + (buf->b_ml.ml_locked_lineadd)--; + (buf->b_ml.ml_locked_high)--; if ((hp = ml_find_line(buf, lnum + 1, ML_INSERT)) == NULL) { return FAIL; } @@ -2039,22 +1947,16 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b buf->b_ml.ml_line_count++; if ((int)dp->db_free >= space_needed) { // enough room in data block - /* - * Insert new line in existing data block, or in data block allocated above. - */ + // Insert new line in existing data block, or in data block allocated above. dp->db_txt_start -= (unsigned)len; dp->db_free -= (unsigned)space_needed; dp->db_line_count++; - /* - * move the text of the lines that follow to the front - * adjust the indexes of the lines that follow - */ + // move the text of the lines that follow to the front + // adjust the indexes of the lines that follow if (line_count > db_idx + 1) { // if there are following lines - /* - * Offset is the start of the previous line. - * This will become the character just after the new line. - */ + // Offset is the start of the previous line. + // This will become the character just after the new line. if (db_idx < 0) { offset = (int)dp->db_txt_end; } else { @@ -2071,31 +1973,25 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b dp->db_index[db_idx + 1] = dp->db_txt_start; } - /* - * copy the text into the block - */ + // copy the text into the block memmove((char *)dp + dp->db_index[db_idx + 1], line, (size_t)len); if (mark) { dp->db_index[db_idx + 1] |= DB_MARKED; } - /* - * Mark the block dirty. - */ + // Mark the block dirty. buf->b_ml.ml_flags |= ML_LOCKED_DIRTY; if (!newfile) { buf->b_ml.ml_flags |= ML_LOCKED_POS; } } else { // not enough space in data block - /* - * If there is not enough room we have to create a new data block and copy some - * lines into it. - * Then we have to insert an entry in the pointer block. - * If this pointer block also is full, we go up another block, and so on, up - * to the root if necessary. - * The line counts in the pointer blocks have already been adjusted by - * ml_find_line(). - */ + // If there is not enough room we have to create a new data block and copy some + // lines into it. + // Then we have to insert an entry in the pointer block. + // If this pointer block also is full, we go up another block, and so on, up + // to the root if necessary. + // The line counts in the pointer blocks have already been adjusted by + // ml_find_line(). int line_count_left, line_count_right; int page_count_left, page_count_right; bhdr_T *hp_left; @@ -2113,14 +2009,12 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b int pb_idx; PTR_BL *pp_new; - /* - * We are going to allocate a new data block. Depending on the - * situation it will be put to the left or right of the existing - * block. If possible we put the new line in the left block and move - * the lines after it to the right block. Otherwise the new line is - * also put in the right block. This method is more efficient when - * inserting a lot of lines at one place. - */ + // We are going to allocate a new data block. Depending on the + // situation it will be put to the left or right of the existing + // block. If possible we put the new line in the left block and move + // the lines after it to the right block. Otherwise the new line is + // also put in the right block. This method is more efficient when + // inserting a lot of lines at one place. if (db_idx < 0) { // left block is new, right block is existing lines_moved = 0; in_left = true; @@ -2164,9 +2058,7 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b page_count_left = (int)hp_left->bh_page_count; page_count_right = (int)hp_right->bh_page_count; - /* - * May move the new line into the right/new block. - */ + // May move the new line into the right/new block. if (!in_left) { dp_right->db_txt_start -= (unsigned)len; dp_right->db_free -= (unsigned)len + (unsigned)INDEX_SIZE; @@ -2179,12 +2071,8 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b line, (size_t)len); line_count_right++; } - /* - * may move lines from the left/old block to the right/new one. - */ + // may move lines from the left/old block to the right/new one. if (lines_moved) { - /* - */ dp_right->db_txt_start -= (unsigned)data_moved; dp_right->db_free -= (unsigned)total_moved; memmove((char *)dp_right + dp_right->db_txt_start, @@ -2194,9 +2082,7 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b dp_left->db_txt_start += (unsigned)data_moved; dp_left->db_free += (unsigned)total_moved; - /* - * update indexes in the new block - */ + // update indexes in the new block for (to = line_count_right, from = db_idx + 1; from < line_count_left; from++, to++) { dp_right->db_index[to] = dp->db_index[from] + (unsigned)offset; @@ -2205,9 +2091,7 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b line_count_left -= lines_moved; } - /* - * May move the new line into the left (old or new) block. - */ + // May move the new line into the left (old or new) block. if (in_left) { dp_left->db_txt_start -= (unsigned)len; dp_left->db_free -= (unsigned)len + (unsigned)INDEX_SIZE; @@ -2234,12 +2118,10 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b dp_left->db_line_count = line_count_left; dp_right->db_line_count = line_count_right; - /* - * release the two data blocks - * The new one (hp_new) already has a correct blocknumber. - * The old one (hp, in ml_locked) gets a positive blocknumber if - * we changed it and we are not editing a new file. - */ + // release the two data blocks + // The new one (hp_new) already has a correct blocknumber. + // The old one (hp, in ml_locked) gets a positive blocknumber if + // we changed it and we are not editing a new file. if (lines_moved || in_left) { buf->b_ml.ml_flags |= ML_LOCKED_DIRTY; } @@ -2248,18 +2130,14 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b } mf_put(mfp, hp_new, true, false); - /* - * flush the old data block - * set ml_locked_lineadd to 0, because the updating of the - * pointer blocks is done below - */ + // flush the old data block + // set ml_locked_lineadd to 0, because the updating of the + // pointer blocks is done below lineadd = buf->b_ml.ml_locked_lineadd; buf->b_ml.ml_locked_lineadd = 0; (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); // flush data block - /* - * update pointer blocks for the new data block - */ + // update pointer blocks for the new data block for (stack_idx = buf->b_ml.ml_stack_top - 1; stack_idx >= 0; --stack_idx) { ip = &(buf->b_ml.ml_stack[stack_idx]); @@ -2273,10 +2151,8 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b mf_put(mfp, hp, false, false); return FAIL; } - /* - * TODO: If the pointer block is full and we are adding at the end - * try to insert in front of the next block - */ + // TODO(vim): If the pointer block is full and we are adding at the end + // try to insert in front of the next block // block not full, add one entry if (pp->pb_count < pp->pb_count_max) { if (pb_idx + 1 < (int)pp->pb_count) { @@ -2312,9 +2188,7 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b ++(buf->b_ml.ml_stack_top); } - /* - * We are finished, break the loop here. - */ + // We are finished, break the loop here. break; } // pointer block full @@ -2400,9 +2274,7 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b mf_put(mfp, hp_new, true, false); } - /* - * Safety check: fallen out of for loop? - */ + // Safety check: fallen out of for loop? if (stack_idx < 0) { iemsg(_("E318: Updated too many blocks?")); buf->b_ml.ml_stack_top = 0; // invalidate stack @@ -2526,9 +2398,7 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message) lowest_marked--; } - /* - * If the file becomes empty the last line is replaced by an empty line. - */ + // If the file becomes empty the last line is replaced by an empty line. if (buf->b_ml.ml_line_count == 1) { // file becomes empty if (message) { set_keep_msg(_(no_lines_msg), 0); @@ -2540,11 +2410,9 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message) return i; } - /* - * find the data block containing the line - * This also fills the stack with the blocks from the root to the data block - * This also releases any locked block. - */ + // find the data block containing the line + // This also fills the stack with the blocks from the root to the data block + // This also releases any locked block. mfp = buf->b_ml.ml_mfp; if (mfp == NULL) { return FAIL; @@ -2573,14 +2441,12 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message) assert(line_size >= 1); ml_add_deleted_len_buf(buf, (char_u *)dp + line_start, line_size - 1); - /* - * special case: If there is only one line in the data block it becomes empty. - * Then we have to remove the entry, pointing to this data block, from the - * pointer block. If this pointer block also becomes empty, we go up another - * block, and so on, up to the root if necessary. - * The line counts in the pointer blocks have already been adjusted by - * ml_find_line(). - */ + // special case: If there is only one line in the data block it becomes empty. + // Then we have to remove the entry, pointing to this data block, from the + // pointer block. If this pointer block also becomes empty, we go up another + // block, and so on, up to the root if necessary. + // The line counts in the pointer blocks have already been adjusted by + // ml_find_line(). if (count == 1) { mf_free(mfp, hp); // free the data block buf->b_ml.ml_locked = NULL; @@ -2638,9 +2504,7 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message) dp->db_txt_start += (unsigned)line_size; dp->db_line_count--; - /* - * mark the block dirty and make sure it is in the file (for recovery) - */ + // mark the block dirty and make sure it is in the file (for recovery) buf->b_ml.ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS); } @@ -2662,11 +2526,9 @@ void ml_setmarked(linenr_T lnum) lowest_marked = lnum; } - /* - * find the data block containing the line - * This also fills the stack with the blocks from the root to the data block - * This also releases any locked block. - */ + // find the data block containing the line + // This also fills the stack with the blocks from the root to the data block + // This also releases any locked block. if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) { return; // give error message? } @@ -2687,16 +2549,12 @@ linenr_T ml_firstmarked(void) return (linenr_T)0; } - /* - * The search starts with lowest_marked line. This is the last line where - * a mark was found, adjusted by inserting/deleting lines. - */ + // The search starts with lowest_marked line. This is the last line where + // a mark was found, adjusted by inserting/deleting lines. for (lnum = lowest_marked; lnum <= curbuf->b_ml.ml_line_count;) { - /* - * Find the data block containing the line. - * This also fills the stack with the blocks from the root to the data - * block This also releases any locked block. - */ + // Find the data block containing the line. + // This also fills the stack with the blocks from the root to the data + // block This also releases any locked block. if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) { return (linenr_T)0; // give error message? } @@ -2728,15 +2586,11 @@ void ml_clearmarked(void) return; } - /* - * The search starts with line lowest_marked. - */ + // The search starts with line lowest_marked. for (lnum = lowest_marked; lnum <= curbuf->b_ml.ml_line_count;) { - /* - * Find the data block containing the line. - * This also fills the stack with the blocks from the root to the data - * block and releases any locked block. - */ + // Find the data block containing the line. + // This also fills the stack with the blocks from the root to the data + // block and releases any locked block. if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) { return; // give error message? } @@ -2813,9 +2667,7 @@ static void ml_flush_line(buf_T *buf) new_len = (colnr_T)STRLEN(new_line) + 1; extra = new_len - old_len; // negative if lines gets smaller - /* - * if new line fits in data block, replace directly - */ + // if new line fits in data block, replace directly if ((int)dp->db_free >= extra) { // if the length changes and there are following lines count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1; @@ -2918,13 +2770,11 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action) mfp = buf->b_ml.ml_mfp; - /* - * If there is a locked block check if the wanted line is in it. - * If not, flush and release the locked block. - * Don't do this for ML_INSERT_SAME, because the stack need to be updated. - * Don't do this for ML_FLUSH, because we want to flush the locked block. - * Don't do this when 'swapfile' is reset, we want to load all the blocks. - */ + // If there is a locked block check if the wanted line is in it. + // If not, flush and release the locked block. + // Don't do this for ML_INSERT_SAME, because the stack need to be updated. + // Don't do this for ML_FLUSH, because we want to flush the locked block. + // Don't do this when 'swapfile' is reset, we want to load all the blocks. if (buf->b_ml.ml_locked) { if (ML_SIMPLE(action) && buf->b_ml.ml_locked_low <= lnum @@ -2944,10 +2794,8 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action) buf->b_ml.ml_flags & ML_LOCKED_POS); buf->b_ml.ml_locked = NULL; - /* - * If lines have been added or deleted in the locked block, need to - * update the line count in pointer blocks. - */ + // If lines have been added or deleted in the locked block, need to + // update the line count in pointer blocks. if (buf->b_ml.ml_locked_lineadd != 0) { ml_lineadd(buf, buf->b_ml.ml_locked_lineadd); } @@ -2979,17 +2827,13 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action) } else { // ML_DELETE or ML_INSERT buf->b_ml.ml_stack_top = 0; // start at the root } - /* - * search downwards in the tree until a data block is found - */ + // search downwards in the tree until a data block is found for (;;) { if ((hp = mf_get(mfp, bnum, (unsigned)page_count)) == NULL) { goto error_noblock; } - /* - * update high for insert/delete - */ + // update high for insert/delete if (action == ML_INSERT) { high++; } else if (action == ML_DELETE) { @@ -3030,9 +2874,7 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action) high = low - 1; low -= t; - /* - * a negative block number may have been changed - */ + // a negative block number may have been changed if (bnum < 0) { bnum2 = mf_trans_del(mfp, bnum); if (bnum != bnum2) { @@ -3067,11 +2909,9 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action) error_block: mf_put(mfp, hp, false, false); error_noblock: - /* - * If action is ML_DELETE or ML_INSERT we have to correct the tree for - * the incremented/decremented line counts, because there won't be a line - * inserted/deleted after all. - */ + // If action is ML_DELETE or ML_INSERT we have to correct the tree for + // the incremented/decremented line counts, because there won't be a line + // inserted/deleted after all. if (action == ML_DELETE) { ml_lineadd(buf, 1); } else if (action == ML_INSERT) { @@ -3196,11 +3036,9 @@ int resolve_symlink(const char *fname, char *buf) } } - /* - * Try to resolve the full name of the file so that the swapfile name will - * be consistent even when opening a relative symlink from different - * working directories. - */ + // Try to resolve the full name of the file so that the swapfile name will + // be consistent even when opening a relative symlink from different + // working directories. return vim_FullName(tmp, buf, MAXPATHL, true); } #endif @@ -3407,17 +3245,13 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ char *dir_name; char *buf_fname = buf->b_fname; - /* - * Isolate a directory name from *dirp and put it in dir_name. - * First allocate some memory to put the directory name in. - */ + // Isolate a directory name from *dirp and put it in dir_name. + // First allocate some memory to put the directory name in. const size_t dir_len = strlen(*dirp) + 1; dir_name = xmalloc(dir_len); (void)copy_option_part(dirp, dir_name, dir_len, ","); - /* - * we try different names until we find one that does not exist yet - */ + // we try different names until we find one that does not exist yet fname = (char *)makeswapname((char_u *)buf_fname, (char_u *)buf->b_ffname, buf, (char_u *)dir_name); @@ -3596,12 +3430,10 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ } } - /* - * Change the ".swp" extension to find another file that can be used. - * First decrement the last char: ".swo", ".swn", etc. - * If that still isn't enough decrement the last but one char: ".svz" - * Can happen when editing many "No Name" buffers. - */ + // Change the ".swp" extension to find another file that can be used. + // First decrement the last char: ".swo", ".swn", etc. + // If that still isn't enough decrement the last but one char: ".svz" + // Can happen when editing many "No Name" buffers. if (fname[n - 1] == 'a') { // ".s?a" if (fname[n - 2] == 'a') { // ".saa": tried enough, give up emsg(_("E326: Too many swap files found")); @@ -3701,11 +3533,9 @@ static bool fnamecmp_ino(char_u *fname_c, char_u *fname_s, long ino_block0) ino_c = os_fileinfo_inode(&file_info); } - /* - * First we try to get the inode from the file name, because the inode in - * the swap file may be outdated. If that fails (e.g. this path is not - * valid on this machine), use the inode from block 0. - */ + // First we try to get the inode from the file name, because the inode in + // the swap file may be outdated. If that fails (e.g. this path is not + // valid on this machine), use the inode from block 0. if (os_fileinfo((char *)fname_s, &file_info)) { ino_s = os_fileinfo_inode(&file_info); } else { @@ -3716,21 +3546,17 @@ static bool fnamecmp_ino(char_u *fname_c, char_u *fname_s, long ino_block0) return ino_c != ino_s; } - /* - * One of the inode numbers is unknown, try a forced vim_FullName() and - * compare the file names. - */ + // One of the inode numbers is unknown, try a forced vim_FullName() and + // compare the file names. retval_c = vim_FullName((char *)fname_c, (char *)buf_c, MAXPATHL, true); retval_s = vim_FullName((char *)fname_s, (char *)buf_s, MAXPATHL, true); if (retval_c == OK && retval_s == OK) { return STRCMP(buf_c, buf_s) != 0; } - /* - * Can't compare inodes or file names, guess that the files are different, - * unless both appear not to exist at all, then compare with the file name - * in the swap file. - */ + // Can't compare inodes or file names, guess that the files are different, + // unless both appear not to exist at all, then compare with the file name + // in the swap file. if (ino_s == 0 && ino_c == 0 && retval_c == FAIL && retval_s == FAIL) { return STRCMP(fname_c, fname_s) != 0; } @@ -3827,9 +3653,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype) } if (updtype == ML_CHNK_UPDLINE && buf->b_ml.ml_line_count == 1) { - /* - * First line in empty buffer from ml_flush_line() -- reset - */ + // First line in empty buffer from ml_flush_line() -- reset buf->b_ml.ml_usedchunks = 1; buf->b_ml.ml_chunksize[0].mlcs_numlines = 1; buf->b_ml.ml_chunksize[0].mlcs_totalsize = @@ -3837,10 +3661,8 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype) return; } - /* - * Find chunk that our line belongs to, curline will be at start of the - * chunk. - */ + // Find chunk that our line belongs to, curline will be at start of the + // chunk. if (buf != ml_upd_lastbuf || line != ml_upd_lastline + 1 || updtype != ML_CHNK_ADDLINE) { for (curline = 1, curix = 0; @@ -3928,10 +3750,8 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype) curchnk->mlcs_numlines = 0; curchnk->mlcs_totalsize = 0; } else { - /* - * Line is just prior to last, move count for last - * This is the common case when loading a new file - */ + // Line is just prior to last, move count for last + // This is the common case when loading a new file hp = ml_find_line(buf, buf->b_ml.ml_line_count, ML_FIND); if (hp == NULL) { buf->b_ml.ml_usedchunks = -1; @@ -4044,10 +3864,8 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff) if (lnum == 0 && offset <= 0) { return 1; // Not a "find offset" and offset 0 _must_ be in line 1 } - /* - * Find the last chunk before the one containing our line. Last chunk is - * special because it will never qualify - */ + // Find the last chunk before the one containing our line. Last chunk is + // special because it will never qualify curline = 1; curix = 0; size = 0; diff --git a/src/nvim/memory.c b/src/nvim/memory.c index acd2478c81..e5fea027cb 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -502,10 +502,8 @@ bool striequal(const char *a, const char *b) return (a == NULL && b == NULL) || (a && b && STRICMP(a, b) == 0); } -/* - * Avoid repeating the error message many times (they take 1 second each). - * Did_outofmem_msg is reset when a character is read. - */ +// Avoid repeating the error message many times (they take 1 second each). +// Did_outofmem_msg is reset when a character is read. void do_outofmem_msg(size_t size) { if (!did_outofmem_msg) { @@ -675,13 +673,11 @@ char *arena_memdupz(Arena *arena, const char *buf, size_t size) # include "nvim/tag.h" # include "nvim/window.h" -/* - * Free everything that we allocated. - * Can be used to detect memory leaks, e.g., with ccmalloc. - * NOTE: This is tricky! Things are freed that functions depend on. Don't be - * surprised if Vim crashes... - * Some things can't be freed, esp. things local to a library function. - */ +// Free everything that we allocated. +// Can be used to detect memory leaks, e.g., with ccmalloc. +// NOTE: This is tricky! Things are freed that functions depend on. Don't be +// surprised if Vim crashes... +// Some things can't be freed, esp. things local to a library function. void free_all_mem(void) { buf_T *buf, *nextbuf; diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 84a1defbe0..7a08a4d6f6 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -1,10 +1,8 @@ // 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 -/* - * Code for menus. Used for the GUI and 'wildmenu'. - * GUI/Motif support by Robert Webb - */ +// Code for menus. Used for the GUI and 'wildmenu'. +// GUI/Motif support by Robert Webb #include #include @@ -141,9 +139,7 @@ void ex_menu(exarg_T *eap) } pri_tab[MENUDEPTH] = -1; // mark end of the table - /* - * Check for "disable" or "enable" argument. - */ + // Check for "disable" or "enable" argument. if (STRNCMP(arg, "enable", 6) == 0 && ascii_iswhite(arg[6])) { enable = kTrue; arg = skipwhite(arg + 6); @@ -152,9 +148,7 @@ void ex_menu(exarg_T *eap) arg = skipwhite(arg + 7); } - /* - * If there is no argument, display all menus. - */ + // If there is no argument, display all menus. if (*arg == NUL) { show_menus(arg, modes); return; @@ -168,9 +162,7 @@ void ex_menu(exarg_T *eap) map_to = menu_translate_tab_and_shift(arg); - /* - * If there is only a menu name, display menus with that name. - */ + // If there is only a menu name, display menus with that name. if (*map_to == NUL && !unmenu && enable == kNone) { show_menus(menu_path, modes); goto theend; @@ -200,16 +192,12 @@ void ex_menu(exarg_T *eap) } menu_enable_recurse(*root_menu_ptr, menu_path, modes, enable); } else if (unmenu) { - /* - * Delete menu(s). - */ + // Delete menu(s). if (STRCMP(menu_path, "*") == 0) { // meaning: remove all menus menu_path = ""; } - /* - * For the PopUp menu, remove a menu for each mode separately. - */ + // For the PopUp menu, remove a menu for each mode separately. if (menu_is_popup(menu_path)) { for (i = 0; i < MENU_INDEX_TIP; i++) { if (modes & (1 << i)) { @@ -223,10 +211,8 @@ void ex_menu(exarg_T *eap) // Careful: remove_menu() changes menu_path remove_menu(root_menu_ptr, menu_path, modes, false); } else { - /* - * Add menu(s). - * Replace special key codes. - */ + // Add menu(s). + // Replace special key codes. if (STRICMP(map_to, "") == 0) { // "" means nothing map_to = ""; map_buf = NULL; @@ -242,9 +228,7 @@ void ex_menu(exarg_T *eap) menuarg.silent[0] = silent; add_menu_path(menu_path, &menuarg, pri_tab, map_to); - /* - * For the PopUp menu, add a menu for each mode separately. - */ + // For the PopUp menu, add a menu for each mode separately. if (menu_is_popup(menu_path)) { for (i = 0; i < MENU_INDEX_TIP; i++) { if (modes & (1 << i)) { @@ -384,11 +368,9 @@ static int add_menu_path(const char *const menu_path, vimmenu_T *menuarg, const } else { old_modes = menu->modes; - /* - * If this menu option was previously only available in other - * modes, then make sure it's available for this one now - * Also enable a menu when it's created or changed. - */ + // If this menu option was previously only available in other + // modes, then make sure it's available for this one now + // Also enable a menu when it's created or changed. { menu->modes |= modes; menu->enabled |= modes; @@ -405,10 +387,8 @@ static int add_menu_path(const char *const menu_path, vimmenu_T *menuarg, const } xfree(path_name); - /* - * Only add system menu items which have not been defined yet. - * First check if this was an ":amenu". - */ + // Only add system menu items which have not been defined yet. + // First check if this was an ":amenu". amenu = ((modes & (MENU_NORMAL_MODE | MENU_INSERT_MODE)) == (MENU_NORMAL_MODE | MENU_INSERT_MODE)); if (sys_menu) { @@ -491,10 +471,8 @@ erret: return FAIL; } -/* - * Set the (sub)menu with the given name to enabled or disabled. - * Called recursively. - */ +// Set the (sub)menu with the given name to enabled or disabled. +// Called recursively. static int menu_enable_recurse(vimmenu_T *menu, char *name, int modes, int enable) { char *p; @@ -522,11 +500,9 @@ static int menu_enable_recurse(vimmenu_T *menu, char *name, int modes, int enabl menu->enabled &= ~modes; } - /* - * When name is empty, we are doing all menu items for the given - * modes, so keep looping, otherwise we are just doing the named - * menu item (which has been found) so break here. - */ + // When name is empty, we are doing all menu items for the given + // modes, so keep looping, otherwise we are just doing the named + // menu item (which has been found) so break here. if (*name != NUL && *name != '*') { break; } @@ -577,11 +553,9 @@ static int remove_menu(vimmenu_T **menup, char *name, int modes, bool silent) return FAIL; } - /* - * When name is empty, we are removing all menu items for the given - * modes, so keep looping, otherwise we are just removing the named - * menu item (which has been found) so break here. - */ + // When name is empty, we are removing all menu items for the given + // modes, so keep looping, otherwise we are just removing the named + // menu item (which has been found) so break here. if (*name != NUL) { break; } @@ -628,9 +602,7 @@ static int remove_menu(vimmenu_T **menup, char *name, int modes, bool silent) return OK; } -/* - * Free the given menu structure and remove it from the linked list. - */ +// Free the given menu structure and remove it from the linked list. static void free_menu(vimmenu_T **menup) { int i; @@ -652,9 +624,7 @@ static void free_menu(vimmenu_T **menup) xfree(menu); } -/* - * Free the menu->string with the given index. - */ +// Free the menu->string with the given index. static void free_menu_string(vimmenu_T *menu, int idx) { int count = 0; @@ -909,16 +879,12 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth) } } -/* - * Used when expanding menu names. - */ +// Used when expanding menu names. static vimmenu_T *expand_menu = NULL; static int expand_modes = 0x0; static int expand_emenu; // true for ":emenu" command -/* - * Work out what to complete when doing command line completion of menu names. - */ +// Work out what to complete when doing command line completion of menu names. char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool forceit) FUNC_ATTR_NONNULL_ALL { @@ -994,10 +960,8 @@ char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool for // Found menu if ((*p != NUL && menu->children == NULL) || ((menu->modes & expand_modes) == 0x0)) { - /* - * Menu path continues, but we have reached a leaf. - * Or menu exists only in another mode. - */ + // Menu path continues, but we have reached a leaf. + // Or menu exists only in another mode. xfree(path_name); return NULL; } @@ -1024,10 +988,8 @@ char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool for return NULL; } -/* - * Function given to ExpandGeneric() to obtain the list of (sub)menus (not - * entries). - */ +// Function given to ExpandGeneric() to obtain the list of (sub)menus (not +// entries). char *get_menu_name(expand_T *xp, int idx) { static vimmenu_T *menu = NULL; @@ -1073,10 +1035,8 @@ char *get_menu_name(expand_T *xp, int idx) return str; } -/* - * Function given to ExpandGeneric() to obtain the list of menus and menu - * entries. - */ +// Function given to ExpandGeneric() to obtain the list of menus and menu +// entries. char *get_menu_names(expand_T *xp, int idx) { static vimmenu_T *menu = NULL; @@ -1312,10 +1272,8 @@ static char *get_menu_mode_str(int modes) return ""; } -/* - * Modify a menu name starting with "PopUp" to include the mode character. - * Returns the name in allocated memory. - */ +// Modify a menu name starting with "PopUp" to include the mode character. +// Returns the name in allocated memory. static char *popup_mode_name(char *name, int idx) { size_t len = STRLEN(name); @@ -1730,9 +1688,7 @@ theend: return menu; } -/* - * Translation of menu names. Just a simple lookup table. - */ +// Translation of menu names. Just a simple lookup table. typedef struct { char *from; // English name @@ -1748,11 +1704,9 @@ static garray_T menutrans_ga = GA_EMPTY_INIT_VALUE; xfree(_mt->from_noamp); \ xfree(_mt->to) -/* - * ":menutrans". - * This function is also defined without the +multi_lang feature, in which - * case the commands are ignored. - */ +// ":menutrans". +// This function is also defined without the +multi_lang feature, in which +// case the commands are ignored. void ex_menutranslate(exarg_T *eap) { char *arg = eap->arg; @@ -1762,9 +1716,7 @@ void ex_menutranslate(exarg_T *eap) ga_init(&menutrans_ga, (int)sizeof(menutrans_T), 5); } - /* - * ":menutrans clear": clear all translations. - */ + // ":menutrans clear": clear all translations. if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) { GA_DEEP_CLEAR(&menutrans_ga, menutrans_T, FREE_MENUTRANS); @@ -1796,9 +1748,7 @@ void ex_menutranslate(exarg_T *eap) } } -/* - * Find the character just after one part of a menu name. - */ +// Find the character just after one part of a menu name. static char *menu_skip_part(char *p) { while (*p != NUL && *p != '.' && !ascii_iswhite(*p)) { @@ -1810,10 +1760,8 @@ static char *menu_skip_part(char *p) return p; } -/* - * Lookup part of a menu name in the translations. - * Return a pointer to the translation or NULL if not found. - */ +// Lookup part of a menu name in the translations. +// Return a pointer to the translation or NULL if not found. static char *menutrans_lookup(char *name, int len) { menutrans_T *tp = (menutrans_T *)menutrans_ga.ga_data; @@ -1841,9 +1789,7 @@ static char *menutrans_lookup(char *name, int len) return NULL; } -/* - * Unescape the name in the translate dictionary table. - */ +// Unescape the name in the translate dictionary table. static void menu_unescape_name(char *name) { char *p; @@ -1855,10 +1801,8 @@ static void menu_unescape_name(char *name) } } -/* - * Isolate the menu name. - * Skip the menu name, and translate into a real TAB. - */ +// Isolate the menu name. +// Skip the menu name, and translate into a real TAB. static char *menu_translate_tab_and_shift(char *arg_start) { char *arg = arg_start; diff --git a/src/nvim/message.c b/src/nvim/message.c index 87cfe06edc..d43c04b652 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1,9 +1,7 @@ // 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 -/* - * message.c: functions for displaying messages on the command line - */ +// message.c: functions for displaying messages on the command line #include #include @@ -48,10 +46,8 @@ #include "nvim/ui_compositor.h" #include "nvim/vim.h" -/* - * To be able to scroll back at the "more" and "hit-enter" prompts we need to - * store the displayed text and remember where screen lines start. - */ +// To be able to scroll back at the "more" and "hit-enter" prompts we need to +// store the displayed text and remember where screen lines start. typedef struct msgchunk_S msgchunk_T; struct msgchunk_S { msgchunk_T *sb_next; @@ -82,41 +78,39 @@ static int verbose_did_open = false; bool keep_msg_more = false; // keep_msg was set by msgmore() -/* - * When writing messages to the screen, there are many different situations. - * A number of variables is used to remember the current state: - * msg_didany true when messages were written since the last time the - * user reacted to a prompt. - * Reset: After hitting a key for the hit-return prompt, - * hitting for the command line or input(). - * Set: When any message is written to the screen. - * msg_didout true when something was written to the current line. - * Reset: When advancing to the next line, when the current - * text can be overwritten. - * Set: When any message is written to the screen. - * msg_nowait No extra delay for the last drawn message. - * Used in normal_cmd() before the mode message is drawn. - * emsg_on_display There was an error message recently. Indicates that there - * should be a delay before redrawing. - * msg_scroll The next message should not overwrite the current one. - * msg_scrolled How many lines the screen has been scrolled (because of - * messages). Used in update_screen() to scroll the screen - * back. Incremented each time the screen scrolls a line. - * msg_scrolled_ign true when msg_scrolled is non-zero and msg_puts_attr() - * writes something without scrolling should not make - * need_wait_return to be set. This is a hack to make ":ts" - * work without an extra prompt. - * lines_left Number of lines available for messages before the - * more-prompt is to be given. -1 when not set. - * need_wait_return true when the hit-return prompt is needed. - * Reset: After giving the hit-return prompt, when the user - * has answered some other prompt. - * Set: When the ruler or typeahead display is overwritten, - * scrolling the screen for some message. - * keep_msg Message to be displayed after redrawing the screen, in - * main_loop(). - * This is an allocated string or NULL when not used. - */ +// When writing messages to the screen, there are many different situations. +// A number of variables is used to remember the current state: +// msg_didany true when messages were written since the last time the +// user reacted to a prompt. +// Reset: After hitting a key for the hit-return prompt, +// hitting for the command line or input(). +// Set: When any message is written to the screen. +// msg_didout true when something was written to the current line. +// Reset: When advancing to the next line, when the current +// text can be overwritten. +// Set: When any message is written to the screen. +// msg_nowait No extra delay for the last drawn message. +// Used in normal_cmd() before the mode message is drawn. +// emsg_on_display There was an error message recently. Indicates that there +// should be a delay before redrawing. +// msg_scroll The next message should not overwrite the current one. +// msg_scrolled How many lines the screen has been scrolled (because of +// messages). Used in update_screen() to scroll the screen +// back. Incremented each time the screen scrolls a line. +// msg_scrolled_ign true when msg_scrolled is non-zero and msg_puts_attr() +// writes something without scrolling should not make +// need_wait_return to be set. This is a hack to make ":ts" +// work without an extra prompt. +// lines_left Number of lines available for messages before the +// more-prompt is to be given. -1 when not set. +// need_wait_return true when the hit-return prompt is needed. +// Reset: After giving the hit-return prompt, when the user +// has answered some other prompt. +// Set: When the ruler or typeahead display is overwritten, +// scrolling the screen for some message. +// keep_msg Message to be displayed after redrawing the screen, in +// main_loop(). +// This is an allocated string or NULL when not used. // Extended msg state, currently used for external UIs with ext_messages static const char *msg_ext_kind = NULL; @@ -313,11 +307,9 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) set_vim_var_string(VV_STATUSMSG, s, -1); } - /* - * It is possible that displaying a messages causes a problem (e.g., - * when redrawing the window), which causes another message, etc.. To - * break this loop, limit the recursiveness to 3 levels. - */ + // It is possible that displaying a messages causes a problem (e.g., + // when redrawing the window), which causes another message, etc.. To + // break this loop, limit the recursiveness to 3 levels. if (entered >= 3) { return true; } @@ -483,10 +475,8 @@ void trunc_string(char *s, char *buf, int room_in, int buflen) } } -/* - * Note: Caller of smsg() and smsg_attr() must check the resulting string is - * shorter than IOSIZE!!! - */ +// Note: Caller of smsg() and smsg_attr() must check the resulting string is +// shorter than IOSIZE!!! int smsg(const char *s, ...) FUNC_ATTR_PRINTF(1, 2) @@ -522,10 +512,8 @@ int smsg_attr_keep(int attr, const char *s, ...) return msg_attr_keep((const char *)IObuff, attr, true, false); } -/* - * Remember the last sourcing name/lnum used in an error message, so that it - * isn't printed each time when it didn't change. - */ +// Remember the last sourcing name/lnum used in an error message, so that it +// isn't printed each time when it didn't change. static int last_sourcing_lnum = 0; static char *last_sourcing_name = NULL; @@ -681,10 +669,8 @@ static bool emsg_multiline(const char *s, bool multiline) // set "v:errmsg", also when using ":silent! cmd" set_vim_var_string(VV_ERRMSG, s, -1); - /* - * When using ":silent! cmd" ignore error messages. - * But do write it to the redirection file. - */ + // When using ":silent! cmd" ignore error messages. + // But do write it to the redirection file. if (emsg_silent != 0) { if (!emsg_noredir) { msg_start(); @@ -1156,12 +1142,10 @@ void wait_return(int redraw) return; } - /* - * When inside vgetc(), we can't wait for a typed character at all. - * With the global command (and some others) we only need one return at - * the end. Adjust cmdline_row to avoid the next message overwriting the - * last one. - */ + // When inside vgetc(), we can't wait for a typed character at all. + // With the global command (and some others) we only need one return at + // the end. Adjust cmdline_row to avoid the next message overwriting the + // last one. if (vgetc_busy > 0) { return; } @@ -1226,12 +1210,10 @@ void wait_return(int redraw) reg_recording = save_reg_recording; scriptout = save_scriptout; - /* - * Allow scrolling back in the messages. - * Also accept scroll-down commands when messages fill the screen, - * to avoid that typing one 'j' too many makes the messages - * disappear. - */ + // Allow scrolling back in the messages. + // Also accept scroll-down commands when messages fill the screen, + // to avoid that typing one 'j' too many makes the messages + // disappear. if (p_more) { if (c == 'b' || c == 'k' || c == 'u' || c == 'g' || c == K_UP || c == K_PAGEUP) { @@ -1268,9 +1250,7 @@ void wait_return(int redraw) || c == K_MOUSEDOWN || c == K_MOUSEUP || c == K_MOUSEMOVE); os_breakcheck(); - /* - * Avoid that the mouse-up event causes visual mode to start. - */ + // Avoid that the mouse-up event causes visual mode to start. if (c == K_LEFTMOUSE || c == K_MIDDLEMOUSE || c == K_RIGHTMOUSE || c == K_X1MOUSE || c == K_X2MOUSE) { (void)jump_to_mouse(MOUSE_SETPOS, NULL, 0); @@ -1575,10 +1555,8 @@ int msg_outtrans_len_attr(const char *msgstr, int len, int attr) msg_puts_attr(" ", attr); } - /* - * Go over the string. Special characters are translated and printed. - * Normal characters are printed several at a time. - */ + // Go over the string. Special characters are translated and printed. + // Normal characters are printed several at a time. while (--len >= 0 && !got_int) { // Don't include composing chars after the end. mb_l = utfc_ptr2len_len(str, len + 1); @@ -2250,10 +2228,8 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse) cmdline_row--; } - /* - * If screen is completely filled and 'more' is set then wait - * for a character. - */ + // If screen is completely filled and 'more' is set then wait + // for a character. if (lines_left > 0) { lines_left--; } @@ -2828,9 +2804,7 @@ static int do_more_prompt(int typed_char) msg_moremsg(false); } for (;;) { - /* - * Get a typed character directly from the user. - */ + // Get a typed character directly from the user. if (used_typed_char != NUL) { c = used_typed_char; // was typed at hit-enter prompt used_typed_char = NUL; @@ -3170,12 +3144,10 @@ void msg_clr_cmdline(void) /// @return true if wait_return() not called. int msg_end(void) { - /* - * If the string is larger than the window, - * or the ruler option is set and we run into it, - * we have to redraw the window. - * Do not do this if we are abandoning the file or editing the command line. - */ + // If the string is larger than the window, + // or the ruler option is set and we run into it, + // we have to redraw the window. + // Do not do this if we are abandoning the file or editing the command line. if (!exiting && need_wait_return && !(State & MODE_CMDLINE)) { wait_return(false); return false; @@ -3545,10 +3517,8 @@ int do_dialog(int type, char *title, char *message, char *buttons, int dfltbutto State = MODE_CONFIRM; setmouse(); - /* - * Since we wait for a keypress, don't make the - * user press RETURN as well afterwards. - */ + // Since we wait for a keypress, don't make the + // user press RETURN as well afterwards. no_wait_return++; hotkeys = msg_show_console_dialog(message, buttons, dfltbutton); diff --git a/src/nvim/message.h b/src/nvim/message.h index 2de2890213..4dba26f958 100644 --- a/src/nvim/message.h +++ b/src/nvim/message.h @@ -11,9 +11,7 @@ #include "nvim/macros.h" #include "nvim/types.h" -/* - * Types of dialogs passed to do_dialog(). - */ +// Types of dialogs passed to do_dialog(). #define VIM_GENERIC 0 #define VIM_ERROR 1 #define VIM_WARNING 2 @@ -21,9 +19,7 @@ #define VIM_QUESTION 4 #define VIM_LAST_TYPE 4 // sentinel value -/* - * Return values for functions like vim_dialogyesno() - */ +// Return values for functions like vim_dialogyesno() #define VIM_YES 2 #define VIM_NO 3 #define VIM_CANCEL 4 diff --git a/src/nvim/move.c b/src/nvim/move.c index b3ec3a8e7a..0e2550352d 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -1,16 +1,14 @@ // 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 -/* - * move.c: Functions for moving the cursor and scrolling text. - * - * There are two ways to move the cursor: - * 1. Move the cursor directly, the text is scrolled to keep the cursor in the - * window. - * 2. Scroll the text, the cursor is moved into the text visible in the - * window. - * The 'scrolloff' option makes this a bit complicated. - */ +// move.c: Functions for moving the cursor and scrolling text. +// +// There are two ways to move the cursor: +// 1. Move the cursor directly, the text is scrolled to keep the cursor in the +// window. +// 2. Scroll the text, the cursor is moved into the text visible in the +// window. +// The 'scrolloff' option makes this a bit complicated. #include #include @@ -47,19 +45,15 @@ typedef struct { # include "move.c.generated.h" #endif -/* - * Compute wp->w_botline for the current wp->w_topline. Can be called after - * wp->w_topline changed. - */ +// Compute wp->w_botline for the current wp->w_topline. Can be called after +// wp->w_topline changed. static void comp_botline(win_T *wp) { linenr_T lnum; int done; - /* - * If w_cline_row is valid, start there. - * Otherwise have to start at w_topline. - */ + // If w_cline_row is valid, start there. + // Otherwise have to start at w_topline. check_cursor_moved(wp); if (wp->w_valid & VALID_CROW) { lnum = wp->w_cursor.lnum; @@ -133,10 +127,8 @@ static void redraw_for_cursorcolumn(win_T *wp) } } -/* - * Update curwin->w_topline and redraw if necessary. - * Used to update the screen before printing a message. - */ +// Update curwin->w_topline and redraw if necessary. +// Used to update the screen before printing a message. void update_topline_redraw(void) { update_topline(curwin); @@ -145,9 +137,7 @@ void update_topline_redraw(void) } } -/* - * Update curwin->w_topline to move the cursor onto the screen. - */ +// Update curwin->w_topline to move the cursor onto the screen. void update_topline(win_T *wp) { linenr_T old_topline; @@ -250,14 +240,12 @@ void update_topline(win_T *wp) } } - /* - * If the cursor is below the bottom of the window, scroll the window - * to put the cursor on the window. - * When w_botline is invalid, recompute it first, to avoid a redraw later. - * If w_botline was approximated, we might need a redraw later in a few - * cases, but we don't want to spend (a lot of) time recomputing w_botline - * for every small change. - */ + // If the cursor is below the bottom of the window, scroll the window + // to put the cursor on the window. + // When w_botline is invalid, recompute it first, to avoid a redraw later. + // If w_botline was approximated, we might need a redraw later in a few + // cases, but we don't want to spend (a lot of) time recomputing w_botline + // for every small change. if (check_botline) { if (!(wp->w_valid & VALID_BOTLINE_AP)) { validate_botline(wp); @@ -328,9 +316,7 @@ void update_topline(win_T *wp) wp->w_viewport_invalid = true; win_check_anchored_floats(wp); - /* - * Need to redraw when topline changed. - */ + // Need to redraw when topline changed. if (wp->w_topline != old_topline || wp->w_topfill != old_topfill) { dollar_vcol = -1; @@ -349,9 +335,7 @@ void update_topline(win_T *wp) *so_ptr = save_so; } -/* - * Update win->w_topline to move the cursor onto the screen. - */ +// Update win->w_topline to move the cursor onto the screen. void update_topline_win(win_T *win) { switchwin_T switchwin; @@ -360,11 +344,9 @@ void update_topline_win(win_T *win) restore_win(&switchwin, true); } -/* - * Return the scrolljump value to use for the current window. - * When 'scrolljump' is positive use it as-is. - * When 'scrolljump' is negative use it as a percentage of the window height. - */ +// Return the scrolljump value to use for the current window. +// When 'scrolljump' is positive use it as-is. +// When 'scrolljump' is negative use it as a percentage of the window height. static int scrolljump_value(void) { long result = p_sj >= 0 ? p_sj : (curwin->w_height_inner * -p_sj) / 100; @@ -372,10 +354,8 @@ static int scrolljump_value(void) return (int)result; } -/* - * Return true when there are not 'scrolloff' lines above the cursor for the - * current window. - */ +// Return true when there are not 'scrolloff' lines above the cursor for the +// current window. static bool check_top_offset(void) { long so = get_scrolloff_value(curwin); @@ -412,9 +392,7 @@ void update_curswant(void) } } -/* - * Check if the cursor has moved. Set the w_valid flag accordingly. - */ +// Check if the cursor has moved. Set the w_valid flag accordingly. void check_cursor_moved(win_T *wp) { if (wp->w_cursor.lnum != wp->w_valid_cursor.lnum) { @@ -435,11 +413,9 @@ void check_cursor_moved(win_T *wp) } } -/* - * Call this function when some window settings have changed, which require - * the cursor position, botline and topline to be recomputed and the window to - * be redrawn. E.g, when changing the 'wrap' option or folding. - */ +// Call this function when some window settings have changed, which require +// the cursor position, botline and topline to be recomputed and the window to +// be redrawn. E.g, when changing the 'wrap' option or folding. void changed_window_setting(void) { changed_window_setting_win(curwin); @@ -453,9 +429,7 @@ void changed_window_setting_win(win_T *wp) redraw_later(wp, UPD_NOT_VALID); } -/* - * Set wp->w_topline to a certain number. - */ +// Set wp->w_topline to a certain number. void set_topline(win_T *wp, linenr_T lnum) { linenr_T prev_topline = wp->w_topline; @@ -475,11 +449,9 @@ void set_topline(win_T *wp, linenr_T lnum) redraw_later(wp, UPD_VALID); } -/* - * Call this function when the length of the cursor line (in screen - * characters) has changed, and the change is before the cursor. - * Need to take care of w_botline separately! - */ +// Call this function when the length of the cursor line (in screen +// characters) has changed, and the change is before the cursor. +// Need to take care of w_botline separately! void changed_cline_bef_curs(void) { curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL @@ -492,11 +464,9 @@ void changed_cline_bef_curs_win(win_T *wp) |VALID_CHEIGHT|VALID_TOPLINE); } -/* - * Call this function when the length of a line (in screen characters) above - * the cursor have changed. - * Need to take care of w_botline separately! - */ +// Call this function when the length of a line (in screen characters) above +// the cursor have changed. +// Need to take care of w_botline separately! void changed_line_abv_curs(void) { curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL|VALID_CROW @@ -509,9 +479,7 @@ void changed_line_abv_curs_win(win_T *wp) |VALID_CHEIGHT|VALID_TOPLINE); } -/* - * Make sure the value of curwin->w_botline is valid. - */ +// Make sure the value of curwin->w_botline is valid. void validate_botline(win_T *wp) { if (!(wp->w_valid & VALID_BOTLINE)) { @@ -519,9 +487,7 @@ void validate_botline(win_T *wp) } } -/* - * Mark curwin->w_botline as invalid (because of some change in the buffer). - */ +// Mark curwin->w_botline as invalid (because of some change in the buffer). void invalidate_botline(void) { curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP); @@ -537,9 +503,7 @@ void approximate_botline_win(win_T *wp) wp->w_valid &= ~VALID_BOTLINE; } -/* - * Return true if curwin->w_wrow and curwin->w_wcol are valid. - */ +// Return true if curwin->w_wrow and curwin->w_wcol are valid. int cursor_valid(void) { check_cursor_moved(curwin); @@ -547,10 +511,8 @@ int cursor_valid(void) (VALID_WROW|VALID_WCOL); } -/* - * Validate cursor position. Makes sure w_wrow and w_wcol are valid. - * w_topline must be valid, you may need to call update_topline() first! - */ +// Validate cursor position. Makes sure w_wrow and w_wcol are valid. +// w_topline must be valid, you may need to call update_topline() first! void validate_cursor(void) { check_cursor_moved(curwin); @@ -559,10 +521,8 @@ void validate_cursor(void) } } -/* - * Compute wp->w_cline_row and wp->w_cline_height, based on the current value - * of wp->w_topline. - */ +// Compute wp->w_cline_row and wp->w_cline_height, based on the current value +// of wp->w_topline. static void curs_rows(win_T *wp) { // Check if wp->w_lines[].wl_size is invalid @@ -633,17 +593,13 @@ static void curs_rows(win_T *wp) wp->w_valid |= VALID_CROW|VALID_CHEIGHT; } -/* - * Validate curwin->w_virtcol only. - */ +// Validate curwin->w_virtcol only. void validate_virtcol(void) { validate_virtcol_win(curwin); } -/* - * Validate wp->w_virtcol only. - */ +// Validate wp->w_virtcol only. void validate_virtcol_win(win_T *wp) { check_cursor_moved(wp); @@ -654,9 +610,7 @@ void validate_virtcol_win(win_T *wp) } } -/* - * Validate curwin->w_cline_height only. - */ +// Validate curwin->w_cline_height only. void validate_cheight(void) { check_cursor_moved(curwin); @@ -668,9 +622,7 @@ void validate_cheight(void) } } -/* - * Validate w_wcol and w_virtcol only. - */ +// Validate w_wcol and w_virtcol only. void validate_cursor_col(void) { validate_virtcol(); @@ -697,10 +649,8 @@ void validate_cursor_col(void) } } -/* - * Compute offset of a window, occupied by absolute or relative line number, - * fold column and sign column (these don't move when scrolling horizontally). - */ +// Compute offset of a window, occupied by absolute or relative line number, +// fold column and sign column (these don't move when scrolling horizontally). int win_col_off(win_T *wp) { return ((wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) + 1 : 0) @@ -714,11 +664,9 @@ int curwin_col_off(void) return win_col_off(curwin); } -/* - * Return the difference in column offset for the second screen line of a - * wrapped line. It's 8 if 'number' or 'relativenumber' is on and 'n' is in - * 'cpoptions'. - */ +// Return the difference in column offset for the second screen line of a +// wrapped line. It's 8 if 'number' or 'relativenumber' is on and 'n' is in +// 'cpoptions'. int win_col_off2(win_T *wp) { if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL) { @@ -746,9 +694,7 @@ void curs_columns(win_T *wp, int may_scroll) long so = get_scrolloff_value(wp); long siso = get_sidescrolloff_value(wp); - /* - * First make sure that w_topline is valid (after moving the cursor). - */ + // First make sure that w_topline is valid (after moving the cursor). update_topline(wp); // Next make sure that w_cline_row is valid. @@ -756,9 +702,7 @@ void curs_columns(win_T *wp, int may_scroll) curs_rows(wp); } - /* - * Compute the number of virtual columns. - */ + // Compute the number of virtual columns. if (wp->w_cline_folded) { // In a folded line the cursor is always in the first column startcol = wp->w_virtcol = endcol = wp->w_leftcol; @@ -1079,10 +1023,8 @@ bool scrolldown(long line_count, int byfold) } check_topfill(curwin, true); - /* - * Compute the row number of the last row of the cursor line - * and move the cursor onto the displayed part of the window. - */ + // Compute the row number of the last row of the cursor line + // and move the cursor onto the displayed part of the window. int wrow = curwin->w_wrow; if (curwin->w_p_wrap && curwin->w_width_inner != 0) { validate_virtcol(); @@ -1200,10 +1142,8 @@ void check_topfill(win_T *wp, bool down) win_check_anchored_floats(curwin); } -/* - * Use as many filler lines as possible for w_topline. Make sure w_topline - * is still visible. - */ +// Use as many filler lines as possible for w_topline. Make sure w_topline +// is still visible. static void max_topfill(void) { int n = plines_win_nofill(curwin, curwin->w_topline, true); @@ -1217,10 +1157,8 @@ static void max_topfill(void) } } -/* - * Scroll the screen one line down, but don't do it if it would move the - * cursor off the screen. - */ +// Scroll the screen one line down, but don't do it if it would move the +// cursor off the screen. void scrolldown_clamp(void) { int can_fill = (curwin->w_topfill < win_get_fill(curwin, curwin->w_topline)); @@ -1261,10 +1199,8 @@ void scrolldown_clamp(void) } } -/* - * Scroll the screen one line up, but don't do it if it would move the cursor - * off the screen. - */ +// Scroll the screen one line up, but don't do it if it would move the cursor +// off the screen. void scrollup_clamp(void) { if (curwin->w_topline == curbuf->b_ml.ml_line_count @@ -1296,12 +1232,10 @@ void scrollup_clamp(void) } } -/* - * Add one line above "lp->lnum". This can be a filler line, a closed fold or - * a (wrapped) text line. Uses and sets "lp->fill". - * Returns the height of the added line in "lp->height". - * Lines above the first one are incredibly high: MAXCOL. - */ +// Add one line above "lp->lnum". This can be a filler line, a closed fold or +// a (wrapped) text line. Uses and sets "lp->fill". +// Returns the height of the added line in "lp->height". +// Lines above the first one are incredibly high: MAXCOL. static void topline_back(win_T *wp, lineoff_T *lp) { if (lp->fill < win_get_fill(wp, lp->lnum)) { @@ -1322,12 +1256,10 @@ static void topline_back(win_T *wp, lineoff_T *lp) } } -/* - * Add one line below "lp->lnum". This can be a filler line, a closed fold or - * a (wrapped) text line. Uses and sets "lp->fill". - * Returns the height of the added line in "lp->height". - * Lines below the last one are incredibly high. - */ +// Add one line below "lp->lnum". This can be a filler line, a closed fold or +// a (wrapped) text line. Uses and sets "lp->fill". +// Returns the height of the added line in "lp->height". +// Lines below the last one are incredibly high. static void botline_forw(win_T *wp, lineoff_T *lp) { if (lp->fill < win_get_fill(wp, lp->lnum + 1)) { @@ -1349,11 +1281,9 @@ static void botline_forw(win_T *wp, lineoff_T *lp) } } -/* - * Switch from including filler lines below lp->lnum to including filler - * lines above loff.lnum + 1. This keeps pointing to the same line. - * When there are no filler lines nothing changes. - */ +// Switch from including filler lines below lp->lnum to including filler +// lines above loff.lnum + 1. This keeps pointing to the same line. +// When there are no filler lines nothing changes. static void botline_topline(lineoff_T *lp) { if (lp->fill > 0) { @@ -1362,11 +1292,9 @@ static void botline_topline(lineoff_T *lp) } } -/* - * Switch from including filler lines above lp->lnum to including filler - * lines below loff.lnum - 1. This keeps pointing to the same line. - * When there are no filler lines nothing changes. - */ +// Switch from including filler lines above lp->lnum to including filler +// lines below loff.lnum - 1. This keeps pointing to the same line. +// When there are no filler lines nothing changes. static void topline_botline(lineoff_T *lp) { if (lp->fill > 0) { @@ -1375,11 +1303,9 @@ static void topline_botline(lineoff_T *lp) } } -/* - * Recompute topline to put the cursor at the top of the window. - * Scroll at least "min_scroll" lines. - * If "always" is true, always set topline (for "zt"). - */ +// Recompute topline to put the cursor at the top of the window. +// Scroll at least "min_scroll" lines. +// If "always" is true, always set topline (for "zt"). void scroll_cursor_top(int min_scroll, int always) { int scrolled = 0; @@ -1394,13 +1320,11 @@ void scroll_cursor_top(int min_scroll, int always) off = mouse_dragging - 1; } - /* - * Decrease topline until: - * - it has become 1 - * - (part of) the cursor line is moved off the screen or - * - moved at least 'scrolljump' lines and - * - at least 'scrolloff' lines above and below the cursor - */ + // Decrease topline until: + // - it has become 1 + // - (part of) the cursor line is moved off the screen or + // - moved at least 'scrolljump' lines and + // - at least 'scrolloff' lines above and below the cursor validate_cheight(); int used = curwin->w_cline_height; // includes filler lines above if (curwin->w_cursor.lnum < curwin->w_topline) { @@ -1421,10 +1345,8 @@ void scroll_cursor_top(int min_scroll, int always) // Hide filler lines above cursor line by adding them to "extra". int extra = win_get_fill(curwin, curwin->w_cursor.lnum); - /* - * Check if the lines from "top" to "bot" fit in the window. If they do, - * set new_topline and advance "top" and "bot" to include more lines. - */ + // Check if the lines from "top" to "bot" fit in the window. If they do, + // set new_topline and advance "top" and "bot" to include more lines. while (top > 0) { int i = hasFolding(top, &top, NULL) ? 1 // count one logical line for a sequence of folded lines @@ -1445,9 +1367,7 @@ void scroll_cursor_top(int min_scroll, int always) scrolled += i; } - /* - * If scrolling is needed, scroll at least 'sj' lines. - */ + // If scrolling is needed, scroll at least 'sj' lines. if ((new_topline >= curwin->w_topline || scrolled > min_scroll) && extra >= off) { break; @@ -1459,18 +1379,14 @@ void scroll_cursor_top(int min_scroll, int always) bot++; } - /* - * If we don't have enough space, put cursor in the middle. - * This makes sure we get the same position when using "k" and "j" - * in a small window. - */ + // If we don't have enough space, put cursor in the middle. + // This makes sure we get the same position when using "k" and "j" + // in a small window. if (used > curwin->w_height_inner) { scroll_cursor_halfway(false); } else { - /* - * If "always" is false, only adjust topline to a lower value, higher - * value may happen with wrapping lines - */ + // If "always" is false, only adjust topline to a lower value, higher + // value may happen with wrapping lines if (new_topline < curwin->w_topline || always) { curwin->w_topline = new_topline; } @@ -1495,10 +1411,8 @@ void scroll_cursor_top(int min_scroll, int always) } } -/* - * Set w_empty_rows and w_filler_rows for window "wp", having used up "used" - * screen lines for text lines. - */ +// Set w_empty_rows and w_filler_rows for window "wp", having used up "used" +// screen lines for text lines. void set_empty_rows(win_T *wp, int used) { wp->w_filler_rows = 0; @@ -1577,13 +1491,11 @@ void scroll_cursor_bot(int min_scroll, int set_topbot) } } - /* - * Stop counting lines to scroll when - * - hitting start of the file - * - scrolled nothing or at least 'sj' lines - * - at least 'so' lines below the cursor - * - lines between botline and cursor have been counted - */ + // Stop counting lines to scroll when + // - hitting start of the file + // - scrolled nothing or at least 'sj' lines + // - at least 'so' lines below the cursor + // - lines between botline and cursor have been counted if (!hasFolding(curwin->w_cursor.lnum, &loff.lnum, &boff.lnum)) { loff.lnum = cln; boff.lnum = cln; @@ -1673,21 +1585,17 @@ void scroll_cursor_bot(int min_scroll, int set_topbot) } } - /* - * Scroll up if the cursor is off the bottom of the screen a bit. - * Otherwise put it at 1/2 of the screen. - */ + // Scroll up if the cursor is off the bottom of the screen a bit. + // Otherwise put it at 1/2 of the screen. if (line_count >= curwin->w_height_inner && line_count > min_scroll) { scroll_cursor_halfway(false); } else { scrollup(line_count, true); } - /* - * If topline didn't change we need to restore w_botline and w_empty_rows - * (we changed them). - * If topline did change, update_screen() will set botline. - */ + // If topline didn't change we need to restore w_botline and w_empty_rows + // (we changed them). + // If topline did change, update_screen() will set botline. if (curwin->w_topline == old_topline && set_topbot) { curwin->w_botline = old_botline; curwin->w_empty_rows = old_empty_rows; @@ -1760,18 +1668,14 @@ void scroll_cursor_halfway(int atend) curwin->w_valid |= VALID_TOPLINE; } -/* - * Correct the cursor position so that it is in a part of the screen at least - * 'so' lines from the top and bottom, if possible. - * If not possible, put it at the same position as scroll_cursor_halfway(). - * When called topline must be valid! - */ +// Correct the cursor position so that it is in a part of the screen at least +// 'so' lines from the top and bottom, if possible. +// If not possible, put it at the same position as scroll_cursor_halfway(). +// When called topline must be valid! void cursor_correct(void) { - /* - * How many lines we would like to have above/below the cursor depends on - * whether the first/last line of the file is on screen. - */ + // How many lines we would like to have above/below the cursor depends on + // whether the first/last line of the file is on screen. int above_wanted = (int)get_scrolloff_value(curwin); int below_wanted = (int)get_scrolloff_value(curwin); if (mouse_dragging > 0) { @@ -1795,10 +1699,8 @@ void cursor_correct(void) } } - /* - * If there are sufficient file-lines above and below the cursor, we can - * return now. - */ + // If there are sufficient file-lines above and below the cursor, we can + // return now. linenr_T cln = curwin->w_cursor.lnum; // Cursor Line Number if (cln >= curwin->w_topline + above_wanted && cln < curwin->w_botline - below_wanted @@ -1806,12 +1708,10 @@ void cursor_correct(void) return; } - /* - * Narrow down the area where the cursor can be put by taking lines from - * the top and the bottom until: - * - the desired context lines are found - * - the lines from the top is past the lines from the bottom - */ + // Narrow down the area where the cursor can be put by taking lines from + // the top and the bottom until: + // - the desired context lines are found + // - the lines from the top is past the lines from the bottom linenr_T topline = curwin->w_topline; linenr_T botline = curwin->w_botline - 1; // count filler lines as context @@ -1860,11 +1760,9 @@ void cursor_correct(void) curwin->w_viewport_invalid = true; } -/* - * move screen 'count' pages up or down and update screen - * - * return FAIL for failure, OK otherwise - */ +// move screen 'count' pages up or down and update screen +// +// return FAIL for failure, OK otherwise int onepage(Direction dir, long count) { long n; @@ -2044,18 +1942,16 @@ int onepage(Direction dir, long count) return retval; } -/* - * Decide how much overlap to use for page-up or page-down scrolling. - * This is symmetric, so that doing both keeps the same lines displayed. - * Three lines are examined: - * - * before CTRL-F after CTRL-F / before CTRL-B - * etc. l1 - * l1 last but one line ------------ - * l2 last text line l2 top text line - * ------------- l3 second text line - * l3 etc. - */ +// Decide how much overlap to use for page-up or page-down scrolling. +// This is symmetric, so that doing both keeps the same lines displayed. +// Three lines are examined: +// +// before CTRL-F after CTRL-F / before CTRL-B +// etc. l1 +// l1 last but one line ------------ +// l2 last text line l2 top text line +// ------------- l3 second text line +// l3 etc. static void get_scroll_overlap(lineoff_T *lp, int dir) { int min_height = curwin->w_height_inner - 2; @@ -2125,9 +2021,7 @@ void halfpage(bool flag, linenr_T Prenum) validate_botline(curwin); int room = curwin->w_empty_rows + curwin->w_filler_rows; if (flag) { - /* - * scroll the text up - */ + // scroll the text up while (n > 0 && curwin->w_botline <= curbuf->b_ml.ml_line_count) { if (curwin->w_topfill > 0) { i = 1; @@ -2185,9 +2079,7 @@ void halfpage(bool flag, linenr_T Prenum) check_cursor_lnum(); } } else { - /* - * scroll the text down - */ + // scroll the text down while (n > 0 && curwin->w_topline > 1) { if (curwin->w_topfill < win_get_fill(curwin, curwin->w_topline)) { i = 1; @@ -2247,9 +2139,7 @@ void do_check_cursorbind(void) int old_VIsual_select = VIsual_select; int old_VIsual_active = VIsual_active; - /* - * loop through the cursorbound windows - */ + // loop through the cursorbound windows VIsual_select = VIsual_active = 0; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { curwin = wp; @@ -2294,9 +2184,7 @@ void do_check_cursorbind(void) } } - /* - * reset current-window - */ + // reset current-window VIsual_select = old_VIsual_select; VIsual_active = old_VIsual_active; curwin = old_curwin; diff --git a/src/nvim/normal.h b/src/nvim/normal.h index 13ea233658..0317080f4f 100644 --- a/src/nvim/normal.h +++ b/src/nvim/normal.h @@ -22,9 +22,7 @@ typedef enum { kMTUnknown = -1, ///< Unknown or invalid motion type } MotionType; -/* - * Arguments for operators. - */ +// Arguments for operators. typedef struct oparg_S { int op_type; // current pending operator type int regname; // register to use for the operator @@ -53,9 +51,7 @@ typedef struct oparg_S { // block } oparg_T; -/* - * Arguments for Normal mode commands. - */ +// Arguments for Normal mode commands. typedef struct cmdarg_S { oparg_T *oap; // Operator arguments int prechar; // prefix character (optional, always 'g') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 01fd4bb9a7..25b957e3b9 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1,10 +1,8 @@ // 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 -/* - * ops.c: implementation of various operators: op_shift, op_delete, op_tilde, - * op_change, op_yank, do_put, do_join - */ +// ops.c: implementation of various operators: op_shift, op_delete, op_tilde, +// op_change, op_yank, do_put, do_join #include #include @@ -67,10 +65,8 @@ static bool clipboard_delay_update = false; // delay clipboard update static bool clipboard_needs_update = false; // clipboard was updated static bool clipboard_didwarn = false; -/* - * structure used by block_prep, op_delete and op_yank for blockwise operators - * also op_change, op_shift, op_insert, op_replace - AKelly - */ +// structure used by block_prep, op_delete and op_yank for blockwise operators +// also op_change, op_shift, op_insert, op_replace - AKelly struct block_def { int startspaces; // 'extra' cols before first char int endspaces; // 'extra' cols after last char @@ -96,11 +92,9 @@ struct block_def { #define OPF_LINES 1 // operator always works on lines #define OPF_CHANGE 2 // operator changes text -/* - * The names of operators. - * IMPORTANT: Index must correspond with defines in vim.h!!! - * The third field indicates whether the operator always works on lines. - */ +// The names of operators. +// IMPORTANT: Index must correspond with defines in vim.h!!! +// The third field indicates whether the operator always works on lines. static char opchars[][3] = { { NUL, NUL, 0 }, // OP_NOP @@ -361,12 +355,10 @@ static void shift_block(oparg_T *oap, int amount) int startcol, oldlen, newlen; if (!left) { - /* - * 1. Get start vcol - * 2. Total ws vcols - * 3. Divvy into TABs & spp - * 4. Construct new string - */ + // 1. Get start vcol + // 2. Total ws vcols + // 3. Divvy into TABs & spp + // 4. Construct new string total += bd.pre_whitesp; // all virtual WS up to & incl a split TAB colnr_T ws_vcol = bd.start_vcol - bd.pre_whitesp; char_u *old_textstart = bd.textstart; @@ -428,13 +420,11 @@ static void shift_block(oparg_T *oap, int amount) // block shift char_u *non_white = bd.textstart; - /* - * Firstly, let's find the first non-whitespace character that is - * displayed after the block's start column and the character's column - * number. Also, let's calculate the width of all the whitespace - * characters that are displayed in the block and precede the searched - * non-whitespace character. - */ + // Firstly, let's find the first non-whitespace character that is + // displayed after the block's start column and the character's column + // number. Also, let's calculate the width of all the whitespace + // characters that are displayed in the block and precede the searched + // non-whitespace character. // If "bd.startspaces" is set, "bd.textstart" points to the character, // the part of which is displayed at the block's beginning. Let's start @@ -715,9 +705,7 @@ void op_reindent(oparg_T *oap, Indenter how) } } -/* - * Keep the last expression line here, for repeating. - */ +// Keep the last expression line here, for repeating. static char_u *expr_line = NULL; /// Get an expression for the "\"=expr1" or "CTRL-R =expr1" @@ -1165,9 +1153,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) // Disallow remapping for ":@r". int remap = colon ? REMAP_NONE : REMAP_YES; - /* - * Insert lines into typeahead buffer, from last one to first one. - */ + // Insert lines into typeahead buffer, from last one to first one. put_reedit_in_typebuf(silent); char *escaped; for (size_t i = reg->y_size; i-- > 0;) { // from y_size - 1 to 0 included @@ -1277,11 +1263,9 @@ int insert_reg(int regname, bool literally_arg) bool allocated; const bool literally = literally_arg || is_literal_register(regname); - /* - * It is possible to get into an endless loop by having CTRL-R a in - * register a and then, in insert mode, doing CTRL-R a. - * If you hit CTRL-C, the loop will be broken here. - */ + // It is possible to get into an endless loop by having CTRL-R a in + // register a and then, in insert mode, doing CTRL-R a. + // If you hit CTRL-C, the loop will be broken here. os_breakcheck(); if (got_int) { return FAIL; @@ -1503,11 +1487,9 @@ int op_delete(oparg_T *oap) mb_adjust_opend(oap); - /* - * Imitate the strange Vi behaviour: If the delete spans more than one - * line and motion_type == kMTCharWise and the result is a blank line, make the - * delete linewise. Don't do this for the change command or Visual mode. - */ + // Imitate the strange Vi behaviour: If the delete spans more than one + // line and motion_type == kMTCharWise and the result is a blank line, make the + // delete linewise. Don't do this for the change command or Visual mode. if (oap->motion_type == kMTCharWise && !oap->is_VIsual && oap->line_count > 1 @@ -1523,10 +1505,8 @@ int op_delete(oparg_T *oap) } } - /* - * Check for trying to delete (e.g. "D") in an empty line. - * Note: For the change operator it is ok. - */ + // Check for trying to delete (e.g. "D") in an empty line. + // Note: For the change operator it is ok. if (oap->motion_type != kMTLineWise && oap->line_count == 1 && oap->op_type == OP_DELETE @@ -1544,11 +1524,9 @@ int op_delete(oparg_T *oap) return OK; } - /* - * Do a yank of whatever we're about to delete. - * If a yank register was specified, put the deleted text into that - * register. For the black hole register '_' don't yank anything. - */ + // Do a yank of whatever we're about to delete. + // If a yank register was specified, put the deleted text into that + // register. For the black hole register '_' don't yank anything. if (oap->regname != '_') { yankreg_T *reg = NULL; int did_yank = false; @@ -1592,9 +1570,7 @@ int op_delete(oparg_T *oap) } } - /* - * block mode delete - */ + // block mode delete if (oap->motion_type == kMTBlockWise) { if (u_save((linenr_T)(oap->start.lnum - 1), (linenr_T)(oap->end.lnum + 1)) == FAIL) { @@ -1873,9 +1849,7 @@ static int op_replace(oparg_T *oap, int c) return FAIL; } - /* - * block mode replace - */ + // block mode replace if (oap->motion_type == kMTBlockWise) { bd.is_MAX = (curwin->w_curswant == MAXCOL); for (; curwin->w_cursor.lnum <= oap->end.lnum; curwin->w_cursor.lnum++) { @@ -2409,10 +2383,8 @@ void op_insert(oparg_T *oap, long count1) bd.textlen = bd2.textlen; } - /* - * Subsequent calls to ml_get() flush the firstline data - take a - * copy of the required string. - */ + // Subsequent calls to ml_get() flush the firstline data - take a + // copy of the required string. firstline = ml_get(oap->start.lnum); const size_t len = STRLEN(firstline); colnr_T add = bd.textcol; @@ -2510,11 +2482,9 @@ int op_change(oparg_T *oap) retval = edit(NUL, false, (linenr_T)1); - /* - * In Visual block mode, handle copying the new text to all lines of the - * block. - * Don't repeat the insert when Insert mode ended with CTRL-C. - */ + // In Visual block mode, handle copying the new text to all lines of the + // block. + // Don't repeat the insert when Insert mode ended with CTRL-C. if (oap->motion_type == kMTBlockWise && oap->start.lnum != oap->end.lnum && !got_int) { // Auto-indenting may have changed the indent. If the cursor was past @@ -2973,10 +2943,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) curbuf->b_op_start = curwin->w_cursor; // default for '[ mark curbuf->b_op_end = curwin->w_cursor; // default for '] mark - /* - * Using inserted text works differently, because the register includes - * special characters (newlines, etc.). - */ + // Using inserted text works differently, because the register includes + // special characters (newlines, etc.). if (regname == '.' && !reg) { bool non_linewise_vis = (VIsual_active && VIsual_mode != 'V'); @@ -3056,10 +3024,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) return; } - /* - * For special registers '%' (file name), '#' (alternate file name) and - * ':' (last command line), etc. we have to create a fake yank register. - */ + // For special registers '%' (file name), '#' (alternate file name) and + // ':' (last command line), etc. we have to create a fake yank register. if (!reg && get_spec_reg(regname, &insert_string, &allocated, true)) { if (insert_string == NULL) { return; @@ -3232,9 +3198,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) lnum = curwin->w_cursor.lnum; col = curwin->w_cursor.col; - /* - * Block mode - */ + // Block mode if (y_type == kMTBlockWise) { int c = gchar_cursor(); colnr_T endcol2 = 0; @@ -4129,13 +4093,11 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions cend = newp + sumsize; *cend = 0; - /* - * Move affected lines to the new long one. - * - * Move marks from each deleted line to the joined line, adjusting the - * column. This is not Vi compatible, but Vi deletes the marks, thus that - * should not really be a problem. - */ + // Move affected lines to the new long one. + // + // Move marks from each deleted line to the joined line, adjusting the + // column. This is not Vi compatible, but Vi deletes the marks, thus that + // should not really be a problem. curbuf_splice_pending++; @@ -4185,11 +4147,9 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions changed_lines(curwin->w_cursor.lnum, currsize, curwin->w_cursor.lnum + 1, 0L, true); - /* - * Delete following lines. To do this we move the cursor there - * briefly, and then move it back. After del_lines() the cursor may - * have moved up (last line deleted), so the current lnum is kept in t. - */ + // Delete following lines. To do this we move the cursor there + // briefly, and then move it back. After del_lines() the cursor may + // have moved up (last line deleted), so the current lnum is kept in t. t = curwin->w_cursor.lnum; curwin->w_cursor.lnum++; del_lines((long)count - 1, false); @@ -4197,11 +4157,9 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions curbuf_splice_pending--; curbuf->deleted_bytes2 = 0; - /* - * Set the cursor column: - * Vi compatible: use the column of the first join - * vim: use the column of the last join - */ + // Set the cursor column: + // Vi compatible: use the column of the first join + // vim: use the column of the last join curwin->w_cursor.col = (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); check_cursor_col(); @@ -4963,16 +4921,12 @@ void *get_reg_contents(int regname, int flags) return list; } - /* - * Compute length of resulting string. - */ + // Compute length of resulting string. size_t len = 0; for (size_t i = 0; i < reg->y_size; i++) { len += STRLEN(reg->y_array[i]); - /* - * Insert a newline between lines and after last line if - * y_type is kMTLineWise. - */ + // Insert a newline between lines and after last line if + // y_type is kMTLineWise. if (reg->y_type == kMTLineWise || i < reg->y_size - 1) { len++; } @@ -4980,18 +4934,14 @@ void *get_reg_contents(int regname, int flags) retval = xmalloc(len + 1); - /* - * Copy the lines of the yank register into the string. - */ + // Copy the lines of the yank register into the string. len = 0; for (size_t i = 0; i < reg->y_size; i++) { STRCPY(retval + len, reg->y_array[i]); len += STRLEN(retval + len); - /* - * Insert a NL between lines and after the last line if y_type is - * kMTLineWise. - */ + // Insert a NL between lines and after the last line if y_type is + // kMTLineWise. if (reg->y_type == kMTLineWise || i < reg->y_size - 1) { retval[len++] = '\n'; } diff --git a/src/nvim/ops.h b/src/nvim/ops.h index 05893c9940..840e33a48c 100644 --- a/src/nvim/ops.h +++ b/src/nvim/ops.h @@ -23,15 +23,13 @@ typedef int (*Indenter)(void); #define PUT_LINE_FORWARD 32 // put linewise register below Visual sel. #define PUT_BLOCK_INNER 64 // in block mode, do not add trailing spaces -/* - * Registers: - * 0 = register for latest (unnamed) yank - * 1..9 = registers '1' to '9', for deletes - * 10..35 = registers 'a' to 'z' - * 36 = delete register '-' - * 37 = selection register '*' - * 38 = clipboard register '+' - */ +// Registers: +// 0 = register for latest (unnamed) yank +// 1..9 = registers '1' to '9', for deletes +// 10..35 = registers 'a' to 'z' +// 36 = delete register '-' +// 37 = selection register '*' +// 38 = clipboard register '+' #define DELETION_REGISTER 36 #define NUM_SAVED_REGISTERS 37 // The following registers should not be saved in ShaDa file: diff --git a/src/nvim/option.c b/src/nvim/option.c index f8b7d96305..12c2888f5c 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -106,14 +106,12 @@ static char e_number_required_after_equal[] static char e_preview_window_already_exists[] = N_("E590: A preview window already exists"); -/* - * The options that are local to a window or buffer have "indir" set to one of - * these values. Special values: - * PV_NONE: global option. - * PV_WIN is added: window-local option - * PV_BUF is added: buffer-local option - * PV_BOTH is added: global option which also has a local value. - */ +// The options that are local to a window or buffer have "indir" set to one of +// these values. Special values: +// PV_NONE: global option. +// PV_WIN is added: window-local option +// PV_BUF is added: buffer-local option +// PV_BOTH is added: global option which also has a local value. #define PV_BOTH 0x1000 #define PV_WIN 0x2000 #define PV_BUF 0x4000 @@ -128,10 +126,8 @@ typedef enum { PV_MAXVAL = 0xffff, // to avoid warnings for value out of range } idopt_T; -/* - * Options local to a window have a value local to a buffer and global to all - * buffers. Indicate this by setting "var" to VAR_WIN. - */ +// Options local to a window have a value local to a buffer and global to all +// buffers. Indicate this by setting "var" to VAR_WIN. #define VAR_WIN ((char_u *)-1) static char *p_term = NULL; @@ -164,14 +160,12 @@ typedef struct vimoption { LastSet last_set; // script in which the option was last set } vimoption_T; -/* - * options[] is initialized here. - * The order of the options MUST be alphabetic for ":set all" and findoption(). - * All option names MUST start with a lowercase letter (for findoption()). - * Exception: "t_" options are at the end. - * The options with a NULL variable are 'hidden': a set command for them is - * ignored and they are not printed. - */ +// options[] is initialized here. +// The order of the options MUST be alphabetic for ":set all" and findoption(). +// All option names MUST start with a lowercase letter (for findoption()). +// Exception: "t_" options are at the end. +// The options with a NULL variable are 'hidden': a set command for them is +// ignored and they are not printed. #ifdef INCLUDE_GENERATED_DECLARATIONS # include "options.generated.h" @@ -197,10 +191,8 @@ void set_init_1(bool clean_arg) langmap_init(); - /* - * Find default value for 'shell' option. - * Don't use it if it is empty. - */ + // Find default value for 'shell' option. + // Don't use it if it is empty. { const char *shell = os_getenv("SHELL"); if (shell != NULL) { @@ -215,10 +207,8 @@ void set_init_1(bool clean_arg) } } - /* - * Set the default for 'backupskip' to include environment variables for - * temp files. - */ + // Set the default for 'backupskip' to include environment variables for + // temp files. { #ifdef UNIX static char *(names[4]) = { "", "TMPDIR", "TEMP", "TMP" }; @@ -354,10 +344,8 @@ void set_init_1(bool clean_arg) rtp = NULL; // ownership taken } - /* - * Set all the options (except the terminal options) to their default - * value. Also set the global value for local options. - */ + // Set all the options (except the terminal options) to their default + // value. Also set the global value for local options. set_options_default(0); curbuf->b_p_initialized = true; @@ -380,15 +368,13 @@ void set_init_1(bool clean_arg) // didset_options() because it only depends on 'encoding'. init_spell_chartab(); - /* - * Expand environment variables and things like "~" for the defaults. - * If option_expand() returns non-NULL the variable is expanded. This can - * only happen for non-indirect options. - * Also set the default to the expanded value, so ":set" does not list - * them. - * Don't set the P_ALLOCED flag, because we don't want to free the - * default. - */ + // Expand environment variables and things like "~" for the defaults. + // If option_expand() returns non-NULL the variable is expanded. This can + // only happen for non-indirect options. + // Also set the default to the expanded value, so ":set" does not list + // them. + // Don't set the P_ALLOCED flag, because we don't want to free the + // default. for (opt_idx = 0; options[opt_idx].fullname; opt_idx++) { if (options[opt_idx].flags & P_NO_DEF_EXP) { continue; @@ -635,10 +621,8 @@ void set_init_2(bool headless) } comp_col(); - /* - * 'window' is only for backwards compatibility with Vi. - * Default is Rows - 1. - */ + // 'window' is only for backwards compatibility with Vi. + // Default is Rows - 1. if (!option_was_set("window")) { p_window = Rows - 1; } @@ -758,11 +742,9 @@ void set_title_defaults(void) { int idx1; - /* - * If GUI is (going to be) used, we can always set the window title and - * icon name. Saves a bit of time, because the X11 display server does - * not need to be contacted. - */ + // If GUI is (going to be) used, we can always set the window title and + // icon name. Saves a bit of time, because the X11 display server does + // not need to be contacted. idx1 = findoption("title"); if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) { options[idx1].def_val = (char_u *)(intptr_t)0; @@ -837,10 +819,8 @@ int do_set(char *arg, int opt_flags) if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]) && !(opt_flags & OPT_MODELINE)) { - /* - * ":set all" show all options. - * ":set all&" set all options to their default value. - */ + // ":set all" show all options. + // ":set all&" set all options to their default value. arg += 3; if (*arg == '&') { arg++; @@ -1016,9 +996,7 @@ int do_set(char *arg, int opt_flags) || (prefix == 1 && vim_strchr("=:&<", nextchar) == NULL && !(flags & P_BOOL))) { - /* - * print value - */ + // print value if (did_show) { msg_putchar('\n'); // cursor below last one } else { @@ -1057,11 +1035,9 @@ int do_set(char *arg, int opt_flags) goto skip; } - /* - * ":set opt!": invert - * ":set opt&": reset to default value - * ":set opt<": reset to global value - */ + // ":set opt!": invert + // ":set opt&": reset to default value + // ":set opt<": reset to global value if (nextchar == '!') { value = *(int *)(varp) ^ 1; } else if (nextchar == '&') { @@ -1076,10 +1052,8 @@ int do_set(char *arg, int opt_flags) OPT_GLOBAL); } } else { - /* - * ":set invopt": invert - * ":set opt" or ":set noopt": set or reset - */ + // ":set invopt": invert + // ":set opt" or ":set noopt": set or reset if (nextchar != NUL && !ascii_iswhite(afterchar)) { errmsg = e_trailing; goto skip; @@ -1289,11 +1263,10 @@ int do_set(char *arg, int opt_flags) arg++; } - /* - * Copy the new string into allocated memory. - * Can't use set_string_option_direct(), because - * we need to remove the backslashes. - */ + // Copy the new string into allocated memory. + // Can't use set_string_option_direct(), because + // we need to remove the backslashes. + // get a bit too much newlen = (unsigned)STRLEN(arg) + 1; if (adding || prepending || removing) { @@ -1302,14 +1275,12 @@ int do_set(char *arg, int opt_flags) newval = xmalloc(newlen); s = newval; - /* - * Copy the string, skip over escaped chars. - * For WIN32 backslashes before normal - * file name characters are not removed, and keep - * backslash at start, for "\\machine\path", but - * do remove it for "\\\\machine\\path". - * The reverse is found in ExpandOldSetting(). - */ + // Copy the string, skip over escaped chars. + // For WIN32 backslashes before normal + // file name characters are not removed, and keep + // backslash at start, for "\\machine\path", but + // do remove it for "\\\\machine\\path". + // The reverse is found in ExpandOldSetting(). while (*arg && !ascii_iswhite(*arg)) { if (*arg == '\\' && arg[1] != NUL #ifdef BACKSLASH_IN_FILENAME @@ -1335,11 +1306,9 @@ int do_set(char *arg, int opt_flags) } *s = NUL; - /* - * Expand environment variables and ~. - * Don't do it when adding without inserting a - * comma. - */ + // Expand environment variables and ~. + // Don't do it when adding without inserting a + // comma. if (!(adding || prepending || removing) || (flags & P_COMMA)) { s = option_expand(opt_idx, newval); @@ -1521,12 +1490,10 @@ int do_set(char *arg, int opt_flags) } skip: - /* - * Advance to next argument. - * - skip until a blank found, taking care of backslashes - * - skip blanks - * - skip one "=val" argument (for hidden options ":set gfn =xx") - */ + // Advance to next argument. + // - skip until a blank found, taking care of backslashes + // - skip blanks + // - skip one "=val" argument (for hidden options ":set gfn =xx") for (i = 0; i < 2; i++) { while (*arg != NUL && !ascii_iswhite(*arg)) { if (*arg++ == '\\' && *arg != NUL) { @@ -1629,10 +1596,8 @@ void did_set_title(void) /// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL void set_options_bin(int oldval, int newval, int opt_flags) { - /* - * The option values that are changed when 'bin' changes are - * copied when 'bin is set and restored when 'bin' is reset. - */ + // The option values that are changed when 'bin' changes are + // copied when 'bin is set and restored when 'bin' is reset. if (newval) { if (!oldval) { // switched on if (!(opt_flags & OPT_GLOBAL)) { @@ -1735,12 +1700,10 @@ static char_u *option_expand(int opt_idx, char_u *val) return NULL; } - /* - * Expanding this with NameBuff, expand_env() must not be passed IObuff. - * Escape spaces when expanding 'tags', they are used to separate file - * names. - * For 'spellsuggest' expand after "file:". - */ + // Expanding this with NameBuff, expand_env() must not be passed IObuff. + // Escape spaces when expanding 'tags', they are used to separate file + // names. + // For 'spellsuggest' expand after "file:". expand_env_esc(val, (char_u *)NameBuff, MAXPATHL, (char_u **)options[opt_idx].var == &p_tags, false, (char_u **)options[opt_idx].var == (char_u **)&p_sps ? (char_u *)"file:" : @@ -2153,9 +2116,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va if ((int *)varp == &curwin->w_p_arab) { if (curwin->w_p_arab) { - /* - * 'arabic' is set, handle various sub-settings. - */ + // 'arabic' is set, handle various sub-settings. if (!p_tbidi) { // set rightleft mode if (!curwin->w_p_rl) { @@ -2186,9 +2147,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va // Force-set the necessary keymap for arabic. errmsg = set_option_value("keymap", 0L, "arabic", OPT_LOCAL); } else { - /* - * 'arabic' is reset, handle various sub-settings. - */ + // 'arabic' is reset, handle various sub-settings. if (!p_tbidi) { // reset rightleft mode if (curwin->w_p_rl) { @@ -2209,9 +2168,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va } } - /* - * End of handling side effects for bool options. - */ + // End of handling side effects for bool options. // after handling side effects, call autocommand @@ -3328,9 +3285,7 @@ static void showoptions(int all, int opt_flags) } } - /* - * display the items - */ + // display the items if (run == 1) { assert(Columns <= INT_MAX - GAP && Columns + GAP >= INT_MIN + 3 @@ -3467,15 +3422,13 @@ int makeset(FILE *fd, int opt_flags, int local_only) int round; int pri; - /* - * Some options are never written: - * - Options that don't have a default (terminal name, columns, lines). - * - Terminal options. - * - Hidden options. - * - * Do the loop over "options[]" twice: once for options with the - * P_PRI_MKRC flag and once without. - */ + // Some options are never written: + // - Options that don't have a default (terminal name, columns, lines). + // - Terminal options. + // - Hidden options. + // + // Do the loop over "options[]" twice: once for options with the + // P_PRI_MKRC flag and once without. for (pri = 1; pri >= 0; pri--) { for (p = &options[0]; p->fullname; p++) { if (!(p->flags & P_NO_MKRC) @@ -4400,10 +4353,8 @@ void buf_copy_options(buf_T *buf, int flags) int dont_do_help; int did_isk = false; - /* - * Skip this when the option defaults have not been set yet. Happens when - * main() allocates the first buffer. - */ + // Skip this when the option defaults have not been set yet. Happens when + // main() allocates the first buffer. if (p_cpo != NULL) { // // Always copy when entering and 'cpo' contains 'S'. @@ -4617,12 +4568,10 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_lw = empty_option; buf->b_p_menc = empty_option; - /* - * Don't copy the options set by ex_help(), use the saved values, - * when going from a help buffer to a non-help buffer. - * Don't touch these at all when BCO_NOHELP is used and going from - * or to a help buffer. - */ + // Don't copy the options set by ex_help(), use the saved values, + // when going from a help buffer to a non-help buffer. + // Don't touch these at all when BCO_NOHELP is used and going from + // or to a help buffer. if (dont_do_help) { buf->b_p_isk = (char *)save_p_isk; if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { @@ -4652,10 +4601,8 @@ void buf_copy_options(buf_T *buf, int flags) } } - /* - * When the options should be copied (ignoring BCO_ALWAYS), set the - * flag that indicates that the options have been initialized. - */ + // When the options should be copied (ignoring BCO_ALWAYS), set the + // flag that indicates that the options have been initialized. if (should_copy) { buf->b_p_initialized = true; } @@ -4947,9 +4894,7 @@ void ExpandOldSetting(int *num_file, char ***file) *num_file = 0; *file = xmalloc(sizeof(char_u *)); - /* - * For a terminal key code expand_option_idx is < 0. - */ + // For a terminal key code expand_option_idx is < 0. if (expand_option_idx < 0) { expand_option_idx = findoption((const char *)expand_option_name); } @@ -5055,10 +5000,8 @@ static void paste_option_changed(void) static int save_hkmap = 0; if (p_paste) { - /* - * Paste switched from off to on. - * Save the current values, so they can be restored later. - */ + // Paste switched from off to on. + // Save the current values, so they can be restored later. if (!old_p_paste) { // save options for each buffer FOR_ALL_BUFFERS(buf) { diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 6af6b16e86..bfac0cff87 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -379,9 +379,7 @@ enum { #define LISPWORD_VALUE \ "defun,define,defmacro,set!,lambda,if,case,let,flet,let*,letrec,do,do*,define-syntax,let-syntax,letrec-syntax,destructuring-bind,defpackage,defparameter,defstruct,deftype,defvar,do-all-symbols,do-external-symbols,do-symbols,dolist,dotimes,ecase,etypecase,eval-when,labels,macrolet,multiple-value-bind,multiple-value-call,multiple-value-prog1,multiple-value-setq,prog1,progv,typecase,unless,unwind-protect,when,with-input-from-string,with-open-file,with-open-stream,with-output-to-string,with-package-iterator,define-condition,handler-bind,handler-case,restart-bind,restart-case,with-simple-restart,store-value,use-value,muffle-warning,abort,continue,with-slots,with-slots*,with-accessors,with-accessors*,defclass,defmethod,print-unreadable-object" -/* - * The following are actual variables for the options - */ +// The following are actual variables for the options EXTERN long p_aleph; // 'aleph' EXTERN char *p_ambw; ///< 'ambiwidth' @@ -924,11 +922,9 @@ enum { BV_COUNT, // must be the last one }; -/* - * "indir" values for window-local options. - * These need to be defined globally, so that the WV_COUNT can be used in the - * window structure. - */ +// "indir" values for window-local options. +// These need to be defined globally, so that the WV_COUNT can be used in the +// window structure. enum { WV_LIST = 0, WV_ARAB, diff --git a/src/nvim/path.c b/src/nvim/path.c index e6de5388e0..607f1fc09a 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -248,9 +248,7 @@ int vim_ispathsep(int c) #endif } -/* - * Like vim_ispathsep(c), but exclude the colon for MS-Windows. - */ +// Like vim_ispathsep(c), but exclude the colon for MS-Windows. int vim_ispathsep_nocolon(int c) { return vim_ispathsep(c) @@ -532,9 +530,7 @@ bool path_has_wildcard(const char *p) return false; } -/* - * Unix style wildcard expansion code. - */ +// Unix style wildcard expansion code. static int pstrcmp(const void *a, const void *b) { return pathcmp(*(char **)a, *(char **)b, -1); @@ -779,10 +775,8 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, return matches; } -/* - * Moves "*psep" back to the previous path separator in "path". - * Returns FAIL is "*psep" ends up at the beginning of "path". - */ +// Moves "*psep" back to the previous path separator in "path". +// Returns FAIL is "*psep" ends up at the beginning of "path". static int find_previous_pathsep(char_u *path, char_u **psep) { // skip the current separator @@ -825,15 +819,13 @@ static bool is_unique(char_u *maybe_unique, garray_T *gap, int i) return true; // no match found } -/* - * Split the 'path' option into an array of strings in garray_T. Relative - * paths are expanded to their equivalent fullpath. This includes the "." - * (relative to current buffer directory) and empty path (relative to current - * directory) notations. - * - * TODO: handle upward search (;) and path limiter (**N) notations by - * expanding each into their equivalent path(s). - */ +// Split the 'path' option into an array of strings in garray_T. Relative +// paths are expanded to their equivalent fullpath. This includes the "." +// (relative to current buffer directory) and empty path (relative to current +// directory) notations. +// +// TODO(vim): handle upward search (;) and path limiter (**N) notations by +// expanding each into their equivalent path(s). static void expand_path_option(char_u *curdir, garray_T *gap) { char_u *path_option = *curbuf->b_p_path == NUL ? p_path : (char_u *)curbuf->b_p_path; @@ -883,14 +875,12 @@ static void expand_path_option(char_u *curdir, garray_T *gap) xfree(buf); } -/* - * Returns a pointer to the file or directory name in "fname" that matches the - * longest path in "ga"p, or NULL if there is no match. For example: - * - * path: /foo/bar/baz - * fname: /foo/bar/baz/quux.txt - * returns: ^this - */ +// Returns a pointer to the file or directory name in "fname" that matches the +// longest path in "ga"p, or NULL if there is no match. For example: +// +// path: /foo/bar/baz +// fname: /foo/bar/baz/quux.txt +// returns: ^this static char_u *get_path_cutoff(char_u *fname, garray_T *gap) { int maxlen = 0; @@ -924,11 +914,9 @@ static char_u *get_path_cutoff(char_u *fname, garray_T *gap) return cutoff; } -/* - * Sorts, removes duplicates and modifies all the fullpath names in "gap" so - * that they are unique with respect to each other while conserving the part - * that matches the pattern. Beware, this is at least O(n^2) wrt "gap->ga_len". - */ +// Sorts, removes duplicates and modifies all the fullpath names in "gap" so +// that they are unique with respect to each other while conserving the part +// that matches the pattern. Beware, this is at least O(n^2) wrt "gap->ga_len". static void uniquefy_paths(garray_T *gap, char_u *pattern) { char_u **fnames = (char_u **)gap->ga_data; @@ -1212,26 +1200,23 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i int add_pat; bool did_expand_in_path = false; - /* - * expand_env() is called to expand things like "~user". If this fails, - * it calls ExpandOne(), which brings us back here. In this case, always - * call the machine specific expansion function, if possible. Otherwise, - * return FAIL. - */ - if (recursive) + // expand_env() is called to expand things like "~user". If this fails, + // it calls ExpandOne(), which brings us back here. In this case, always + // call the machine specific expansion function, if possible. Otherwise, + // return FAIL. + if (recursive) { #ifdef SPECIAL_WILDCHAR - { return os_expand_wildcards(num_pat, pat, num_file, file, flags); } + return os_expand_wildcards(num_pat, pat, num_file, file, flags); #else - { return FAIL; } + return FAIL; #endif + } #ifdef SPECIAL_WILDCHAR - /* - * If there are any special wildcard characters which we cannot handle - * here, call machine specific function for all the expansion. This - * avoids starting the shell for each argument separately. - * For `=expr` do use the internal function. - */ + // If there are any special wildcard characters which we cannot handle + // here, call machine specific function for all the expansion. This + // avoids starting the shell for each argument separately. + // For `=expr` do use the internal function. for (int i = 0; i < num_pat; i++) { if (has_special_wildchar((char_u *)pat[i]) && !(vim_backtick((char_u *)pat[i]) && pat[i][1] == '=')) { @@ -1242,9 +1227,7 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i recursive = true; - /* - * The matching file names are stored in a growarray. Init it empty. - */ + // The matching file names are stored in a growarray. Init it empty. ga_init(&ga, (int)sizeof(char_u *), 30); for (int i = 0; i < num_pat && !got_int; i++) { @@ -1266,31 +1249,28 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i p = expand_env_save_opt(p, true); if (p == NULL) { p = (char_u *)pat[i]; - } + } else { #ifdef UNIX - /* - * On Unix, if expand_env() can't expand an environment - * variable, use the shell to do that. Discard previously - * found file names and start all over again. - */ - else if (has_env_var(p) || *p == '~') { - xfree(p); - ga_clear_strings(&ga); - i = os_expand_wildcards(num_pat, pat, num_file, file, - flags | EW_KEEPDOLLAR); - recursive = false; - return i; - } + // On Unix, if expand_env() can't expand an environment + // variable, use the shell to do that. Discard previously + // found file names and start all over again. + if (has_env_var(p) || *p == '~') { + xfree(p); + ga_clear_strings(&ga); + i = os_expand_wildcards(num_pat, pat, num_file, file, + flags | EW_KEEPDOLLAR); + recursive = false; + return i; + } #endif + } } - /* - * If there are wildcards: Expand file names and add each match to - * the list. If there is no match, and EW_NOTFOUND is given, add - * the pattern. - * If there are no wildcards: Add the file name if it exists or - * when EW_NOTFOUND is given. - */ + // If there are wildcards: Expand file names and add each match to + // the list. If there is no match, and EW_NOTFOUND is given, add + // the pattern. + // If there are no wildcards: Add the file name if it exists or + // when EW_NOTFOUND is given. if (path_has_exp_wildcard(p)) { if ((flags & EW_PATH) && !path_is_absolute(p) @@ -1491,21 +1471,17 @@ void addfile(garray_T *gap, char_u *f, int flags) #ifdef BACKSLASH_IN_FILENAME slash_adjust(p); #endif - /* - * Append a slash or backslash after directory names if none is present. - */ + // Append a slash or backslash after directory names if none is present. if (isdir && (flags & EW_ADDSLASH)) { add_pathsep((char *)p); } GA_APPEND(char_u *, gap, p); } -/* - * Converts a file name into a canonical form. It simplifies a file name into - * its simplest form by stripping out unneeded components, if any. The - * resulting file name is simplified in place and will either be the same - * length as that supplied, or shorter. - */ +// Converts a file name into a canonical form. It simplifies a file name into +// its simplest form by stripping out unneeded components, if any. The +// resulting file name is simplified in place and will either be the same +// length as that supplied, or shorter. void simplify_filename(char_u *filename) { int components = 0; @@ -1704,10 +1680,8 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha file_name = (char *)find_file_in_path((char_u *)ptr, len, options & ~FNAME_MESS, true, (char_u *)rel_fname); - /* - * If the file could not be found in a normal way, try applying - * 'includeexpr' (unless done already). - */ + // If the file could not be found in a normal way, try applying + // 'includeexpr' (unless done already). if (file_name == NULL && !(options & FNAME_INCL) && *curbuf->b_p_inex != NUL) { tofree = eval_includeexpr(ptr, len); @@ -1976,11 +1950,9 @@ bool same_directory(char_u *f1, char_u *f2) && pathcmp((char *)ffname, (char *)f2, (int)(t1 - ffname)) == 0; } -/* - * Compare path "p[]" to "q[]". - * If "maxlen" >= 0 compare "p[maxlen]" to "q[maxlen]" - * Return value like strcmp(p, q), but consider path separators. - */ +// Compare path "p[]" to "q[]". +// If "maxlen" >= 0 compare "p[maxlen]" to "q[maxlen]" +// Return value like strcmp(p, q), but consider path separators. int pathcmp(const char *p, const char *q, int maxlen) { int i, j; @@ -2185,9 +2157,7 @@ int expand_wildcards(int num_pat, char **pat, int *num_files, char ***files, int return retval; } - /* - * Remove names that match 'wildignore'. - */ + // Remove names that match 'wildignore'. if (*p_wig) { char_u *ffname; diff --git a/src/nvim/path.h b/src/nvim/path.h index 1006ef9ffb..37a0883c7f 100644 --- a/src/nvim/path.h +++ b/src/nvim/path.h @@ -18,8 +18,8 @@ #define EW_NOERROR 0x200 // no error for bad regexp #define EW_NOTWILD 0x400 // add match with literal name if exists #define EW_KEEPDOLLAR 0x800 // do not escape $, $var is expanded -/* Note: mostly EW_NOTFOUND and EW_SILENT are mutually exclusive: EW_NOTFOUND -* is used when executing commands and EW_SILENT for interactive expanding. */ +// Note: mostly EW_NOTFOUND and EW_SILENT are mutually exclusive: EW_NOTFOUND +// is used when executing commands and EW_SILENT for interactive expanding. #define EW_ALLLINKS 0x1000 // also links not pointing to existing file #define EW_SHELLCMD 0x2000 // called from expand_shellcmd(), don't check // if executable is in $PATH diff --git a/src/nvim/search.c b/src/nvim/search.c index 5c1fe3a657..490e79ebb0 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1,9 +1,7 @@ // 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 -/* - * search.c: code for normal mode searching commands - */ +// search.c: code for normal mode searching commands #include #include @@ -106,10 +104,8 @@ static bool saved_spats_no_hlsearch = false; static char_u *mr_pattern = NULL; // pattern used by search_regcomp() static bool mr_pattern_alloced = false; // mr_pattern was allocated -/* - * Type used by find_pattern_in_path() to remember which included files have - * been searched already. - */ +// Type used by find_pattern_in_path() to remember which included files have +// been searched already. typedef struct SearchedFile { FILE *fp; // File pointer char_u *name; // Full name of file @@ -139,9 +135,7 @@ int search_regcomp(char_u *pat, int pat_save, int pat_use, int options, regmmatc rc_did_emsg = false; magic = p_magic; - /* - * If no pattern given, use a previously defined pattern. - */ + // If no pattern given, use a previously defined pattern. if (pat == NULL || *pat == NUL) { if (pat_use == RE_LAST) { i = last_idx; @@ -176,10 +170,8 @@ int search_regcomp(char_u *pat, int pat_save, int pat_use, int options, regmmatc mr_pattern = pat; } - /* - * Save the currently used pattern in the appropriate place, - * unless the pattern should not be remembered. - */ + // Save the currently used pattern in the appropriate place, + // unless the pattern should not be remembered. if (!(options & SEARCH_KEEP) && (cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0) { // search or global command if (pat_save == RE_SEARCH || pat_save == RE_BOTH) { @@ -200,9 +192,7 @@ int search_regcomp(char_u *pat, int pat_save, int pat_use, int options, regmmatc return OK; } -/* - * Get search pattern used by search_regcomp(). - */ +// Get search pattern used by search_regcomp(). char_u *get_search_pat(void) { return mr_pattern; @@ -226,10 +216,8 @@ void save_re_pat(int idx, char_u *pat, int magic) } } -/* - * Save the search patterns, so they can be restored later. - * Used before/after executing autocommands and user functions. - */ +// Save the search patterns, so they can be restored later. +// Used before/after executing autocommands and user functions. static int save_level = 0; void save_search_patterns(void) @@ -450,19 +438,15 @@ char_u *last_search_pat(void) return spats[last_idx].pat; } -/* - * Reset search direction to forward. For "gd" and "gD" commands. - */ +// Reset search direction to forward. For "gd" and "gD" commands. void reset_search_dir(void) { spats[0].off.dir = '/'; set_vv_searchforward(); } -/* - * Set the last search pattern. For ":let @/ =" and ShaDa file. - * Also set the saved search pattern, so that this works in an autocommand. - */ +// Set the last search pattern. For ":let @/ =" and ShaDa file. +// Also set the saved search pattern, so that this works in an autocommand. void set_last_search_pat(const char_u *s, int idx, int magic, int setlast) { free_spat(&spats[idx]); @@ -500,11 +484,9 @@ void set_last_search_pat(const char_u *s, int idx, int magic, int setlast) } } -/* - * Get a regexp program for the last used search pattern. - * This is used for highlighting all matches in a window. - * Values returned in regmatch->regprog and regmatch->rmm_ic. - */ +// Get a regexp program for the last used search pattern. +// This is used for highlighting all matches in a window. +// Values returned in regmatch->regprog and regmatch->rmm_ic. void last_pat_prog(regmmatch_T *regmatch) { if (spats[last_idx].pat == NULL) { @@ -578,9 +560,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, return FAIL; } - /* - * find the string - */ + // find the string do { // loop for count // When not accepting a match at the start position set "extra_col" to a // non-zero value. Don't do that when starting at MAXCOL, since MAXCOL + 1 @@ -615,13 +595,11 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, at_first_line = false; // not in first line now } - /* - * Start searching in current line, unless searching backwards and - * we're in column 0. - * If we are searching backwards, in column 0, and not including the - * current position, gain some efficiency by skipping back a line. - * Otherwise begin the search in the current line. - */ + // Start searching in current line, unless searching backwards and + // we're in column 0. + // If we are searching backwards, in column 0, and not including the + // current position, gain some efficiency by skipping back a line. + // Otherwise begin the search in the current line. if (dir == BACKWARD && start_pos.col == 0 && (options & SEARCH_START) == 0) { lnum = pos->lnum - 1; @@ -667,11 +645,9 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, ptr = ml_get_buf(buf, lnum + matchpos.lnum, false); } - /* - * Forward search in the first line: match should be after - * the start position. If not, continue at the end of the - * match (this is vi compatible) or on the next char. - */ + // Forward search in the first line: match should be after + // the start position. If not, continue at the end of the + // match (this is vi compatible) or on the next char. if (dir == FORWARD && at_first_line) { match_ok = true; // When the match starts in a next line it's certainly @@ -687,11 +663,9 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, : ((int)matchpos.col - (ptr[matchpos.col] == NUL) < (int)start_pos.col + extra_col))) { - /* - * If vi-compatible searching, continue at the end - * of the match, otherwise continue one position - * forward. - */ + // If vi-compatible searching, continue at the end + // of the match, otherwise continue one position + // forward. if (vim_strchr(p_cpo, CPO_SEARCH) != NULL) { if (nmatched > 1) { // end is in next line, thus no match in @@ -744,13 +718,11 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, } } if (dir == BACKWARD) { - /* - * Now, if there are multiple matches on this line, - * we have to get the last one. Or the last one before - * the cursor, if we're on that line. - * When putting the new cursor at the end, compare - * relative to the end of the match. - */ + // Now, if there are multiple matches on this line, + // we have to get the last one. Or the last one before + // the cursor, if we're on that line. + // When putting the new cursor at the end, compare + // relative to the end of the match. match_ok = false; for (;;) { // Remember a position that is before the start @@ -825,10 +797,8 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, ptr = ml_get_buf(buf, lnum + matchpos.lnum, false); } - /* - * If there is only a match after the cursor, skip - * this match. - */ + // If there is only a match after the cursor, skip + // this match. if (!match_ok) { continue; } @@ -1042,25 +1012,19 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, size_t len; bool has_offset = false; - /* - * A line offset is not remembered, this is vi compatible. - */ + // A line offset is not remembered, this is vi compatible. if (spats[0].off.line && vim_strchr(p_cpo, CPO_LINEOFF) != NULL) { spats[0].off.line = false; spats[0].off.off = 0; } - /* - * Save the values for when (options & SEARCH_KEEP) is used. - * (there is no "if ()" around this because gcc wants them initialized) - */ + // Save the values for when (options & SEARCH_KEEP) is used. + // (there is no "if ()" around this because gcc wants them initialized) old_off = spats[0].off; pos = curwin->w_cursor; // start searching at the cursor position - /* - * Find out the direction of the search. - */ + // Find out the direction of the search. if (dirc == 0) { dirc = (char_u)spats[0].off.dir; } else { @@ -1087,17 +1051,13 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, } } - /* - * Turn 'hlsearch' highlighting back on. - */ + // Turn 'hlsearch' highlighting back on. if (no_hlsearch && !(options & SEARCH_KEEP)) { redraw_all_later(UPD_SOME_VALID); set_no_hlsearch(false); } - /* - * Repeat the search when pattern followed by ';', e.g. "/foo/;?bar". - */ + // Repeat the search when pattern followed by ';', e.g. "/foo/;?bar". for (;;) { bool show_top_bot_msg = false; @@ -1119,10 +1079,8 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, } if (pat != NULL && *pat != NUL) { // look for (new) offset - /* - * Find end of regular expression. - * If there is a matching '/' or '?', toss it. - */ + // Find end of regular expression. + // If there is a matching '/' or '?', toss it. ps = (char_u *)strcopy; p = (char_u *)skip_regexp((char *)pat, search_delim, p_magic, &strcopy); if (strcopy != (char *)ps) { @@ -1287,13 +1245,11 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, } } - /* - * If there is a character offset, subtract it from the current - * position, so we don't get stuck at "?pat?e+2" or "/pat/s-2". - * Skip this if pos.col is near MAXCOL (closed fold). - * This is not done for a line offset, because then we would not be vi - * compatible. - */ + // If there is a character offset, subtract it from the current + // position, so we don't get stuck at "?pat?e+2" or "/pat/s-2". + // Skip this if pos.col is near MAXCOL (closed fold). + // This is not done for a line offset, because then we would not be vi + // compatible. if (!spats[0].off.line && spats[0].off.off && pos.col < MAXCOL - 2) { if (spats[0].off.off > 0) { for (c = spats[0].off.off; c; c--) { @@ -1350,9 +1306,7 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, apply_autocmds(EVENT_SEARCHWRAPPED, NULL, NULL, false, NULL); } - /* - * Add character and/or line offset - */ + // Add character and/or line offset if (!(options & SEARCH_NOOF) || (pat != NULL && *pat == ';')) { pos_T org_pos = pos; @@ -1444,15 +1398,13 @@ end_do_search: return retval; } -/* - * search_for_exact_line(buf, pos, dir, pat) - * - * Search for a line starting with the given pattern (ignoring leading - * white-space), starting from pos and going in direction "dir". "pos" will - * contain the position of the match found. Blank lines match only if - * ADDING is set. If p_ic is set then the pattern must be in lowercase. - * Return OK for success, or FAIL if no line found. - */ +// search_for_exact_line(buf, pos, dir, pat) +// +// Search for a line starting with the given pattern (ignoring leading +// white-space), starting from pos and going in direction "dir". "pos" will +// contain the position of the match found. Blank lines match only if +// ADDING is set. If p_ic is set then the pattern must be in lowercase. +// Return OK for success, or FAIL if no line found. int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char_u *pat) { linenr_T start = 0; @@ -1513,9 +1465,7 @@ int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char_u *pat) return FAIL; } -/* - * Character Searches - */ +// Character Searches /// Search for a character in a line. If "t_cmd" is false, move to the /// position of the character, otherwise move to just before the char. @@ -1618,15 +1568,11 @@ int searchc(cmdarg_T *cap, int t_cmd) return OK; } -/* - * "Other" Searches - */ +// "Other" Searches -/* - * findmatch - find the matching paren or brace - * - * Improvement over vi: Braces inside quotes are ignored. - */ +// findmatch - find the matching paren or brace +// +// Improvement over vi: Braces inside quotes are ignored. pos_T *findmatch(oparg_T *oap, int initc) { return findmatchlimit(oap, initc, 0, 0); @@ -1725,27 +1671,24 @@ static void find_mps_values(int *initc, int *findc, bool *backwards, bool switch } } -/* - * findmatchlimit -- find the matching paren or brace, if it exists within - * maxtravel lines of the cursor. A maxtravel of 0 means search until falling - * off the edge of the file. - * - * "initc" is the character to find a match for. NUL means to find the - * character at or after the cursor. Special values: - * '*' look for C-style comment / * - * '/' look for C-style comment / *, ignoring comment-end - * '#' look for preprocessor directives - * 'R' look for raw string start: R"delim(text)delim" (only backwards) - * - * flags: FM_BACKWARD search backwards (when initc is '/', '*' or '#') - * FM_FORWARD search forwards (when initc is '/', '*' or '#') - * FM_BLOCKSTOP stop at start/end of block ({ or } in column 0) - * FM_SKIPCOMM skip comments (not implemented yet!) - * - * "oap" is only used to set oap->motion_type for a linewise motion, it can be - * NULL - */ - +// findmatchlimit -- find the matching paren or brace, if it exists within +// maxtravel lines of the cursor. A maxtravel of 0 means search until falling +// off the edge of the file. +// +// "initc" is the character to find a match for. NUL means to find the +// character at or after the cursor. Special values: +// '*' look for C-style comment / * +// '/' look for C-style comment / *, ignoring comment-end +// '#' look for preprocessor directives +// 'R' look for raw string start: R"delim(text)delim" (only backwards) +// +// flags: FM_BACKWARD search backwards (when initc is '/', '*' or '#') +// FM_FORWARD search forwards (when initc is '/', '*' or '#') +// FM_BLOCKSTOP stop at start/end of block ({ or } in column 0) +// FM_SKIPCOMM skip comments (not implemented yet!) +// +// "oap" is only used to set oap->motion_type for a linewise motion, it can be +// NULL pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) { static pos_T pos; // current search position @@ -1783,12 +1726,10 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) dir = 0; } - /* - * if initc given, look in the table for the matching character - * '/' and '*' are special cases: look for start or end of comment. - * When '/' is used, we ignore running backwards into a star-slash, for - * "[*" command, we just want to find any comment. - */ + // if initc given, look in the table for the matching character + // '/' and '*' are special cases: look for start or end of comment. + // When '/' is used, we ignore running backwards into a star-slash, for + // "[*" command, we just want to find any comment. if (initc == '/' || initc == '*' || initc == 'R') { comment_dir = dir; if (initc == '/') { @@ -1806,18 +1747,14 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) return NULL; } } else { - /* - * Either initc is '#', or no initc was given and we need to look - * under the cursor. - */ + // Either initc is '#', or no initc was given and we need to look + // under the cursor. if (initc == '#') { hash_dir = dir; } else { - /* - * initc was not given, must look for something to match under - * or near the cursor. - * Only check for special things when 'cpo' doesn't have '%'. - */ + // initc was not given, must look for something to match under + // or near the cursor. + // Only check for special things when 'cpo' doesn't have '%'. if (!cpo_match) { // Are we before or at #if, #else etc.? ptr = (char_u *)skipwhite((char *)linep); @@ -1851,16 +1788,12 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) } } - /* - * If we are not on a comment or the # at the start of a line, then - * look for brace anywhere on this line after the cursor. - */ + // If we are not on a comment or the # at the start of a line, then + // look for brace anywhere on this line after the cursor. if (!hash_dir && !comment_dir) { - /* - * Find the brace under or after the cursor. - * If beyond the end of the line, use the last character in - * the line. - */ + // Find the brace under or after the cursor. + // If beyond the end of the line, use the last character in + // the line. if (linep[pos.col] == NUL && pos.col) { pos.col--; } @@ -1896,9 +1829,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) } } if (hash_dir) { - /* - * Look for matching #if, #else, #elif, or #endif - */ + // Look for matching #if, #else, #elif, or #endif if (oap != NULL) { oap->motion_type = kMTLineWise; // Linewise for this case only } @@ -1983,10 +1914,8 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) } while (!got_int) { - /* - * Go to the next position, forward or backward. We could use - * inc() and dec() here, but that is much slower - */ + // Go to the next position, forward or backward. We could use + // inc() and dec() here, but that is much slower if (backwards) { // char to match is inside of comment, don't search outside if (lispcomm && pos.col < (colnr_T)comment_col) { @@ -2067,10 +1996,8 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) return &pos; } } else { // Searching backwards - /* - * A comment may contain / * or / /, it may also start or end - * with / * /. Ignore a / * after / / and after *. - */ + // A comment may contain / * or / /, it may also start or end + // with / * /. Ignore a / * after / / and after *. if (pos.col == 0) { continue; } else if (raw_string) { @@ -2113,18 +2040,14 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) continue; } - /* - * If smart matching ('cpoptions' does not contain '%'), braces inside - * of quotes are ignored, but only if there is an even number of - * quotes in the line. - */ + // If smart matching ('cpoptions' does not contain '%'), braces inside + // of quotes are ignored, but only if there is an even number of + // quotes in the line. if (cpo_match) { do_quotes = 0; } else if (do_quotes == -1) { - /* - * Count the number of quotes in the line, skipping \" and '"'. - * Watch out for "\\". - */ + // Count the number of quotes in the line, skipping \" and '"'. + // Watch out for "\\". at_start = do_quotes; for (ptr = linep; *ptr; ptr++) { if (ptr == linep + pos.col + backwards) { @@ -2140,10 +2063,8 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) } do_quotes &= 1; // result is 1 with even number of quotes - /* - * If we find an uneven count, check current line and previous - * one for a '\' at the end. - */ + // If we find an uneven count, check current line and previous + // one for a '\' at the end. if (!do_quotes) { inquote = false; if (ptr[-1] == '\\') { @@ -2179,17 +2100,15 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) start_in_quotes = kFalse; } - /* - * If 'smartmatch' is set: - * Things inside quotes are ignored by setting 'inquote'. If we - * find a quote without a preceding '\' invert 'inquote'. At the - * end of a line not ending in '\' we reset 'inquote'. - * - * In lines with an uneven number of quotes (without preceding '\') - * we do not know which part to ignore. Therefore we only set - * inquote if the number of quotes in a line is even, unless this - * line or the previous one ends in a '\'. Complicated, isn't it? - */ + // If 'smartmatch' is set: + // Things inside quotes are ignored by setting 'inquote'. If we + // find a quote without a preceding '\' invert 'inquote'. At the + // end of a line not ending in '\' we reset 'inquote'. + // + // In lines with an uneven number of quotes (without preceding '\') + // we do not know which part to ignore. Therefore we only set + // inquote if the number of quotes in a line is even, unless this + // line or the previous one ends in a '\'. Complicated, isn't it? const int c = utf_ptr2char((char *)linep + pos.col); switch (c) { case NUL: @@ -2218,13 +2137,11 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) } break; - /* - * If smart matching ('cpoptions' does not contain '%'): - * Skip things in single quotes: 'x' or '\x'. Be careful for single - * single quotes, eg jon's. Things like '\233' or '\x3f' are not - * skipped, there is never a brace in them. - * Ignore this when finding matches for `'. - */ + // If smart matching ('cpoptions' does not contain '%'): + // Skip things in single quotes: 'x' or '\x'. Be careful for single + // single quotes, eg jon's. Things like '\233' or '\x3f' are not + // skipped, there is never a brace in them. + // Ignore this when finding matches for `'. case '\'': if (!cpo_match && initc != '\'' && findc != '\'') { if (backwards) { @@ -2252,10 +2169,8 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) FALLTHROUGH; default: - /* - * For Lisp skip over backslashed (), {} and []. - * (actually, we skip #\( et al) - */ + // For Lisp skip over backslashed (), {} and []. + // (actually, we skip #\( et al) if (curbuf->b_p_lisp && vim_strchr("(){}[]", c) != NULL && pos.col > 1 @@ -2367,9 +2282,7 @@ void showmatch(int c) colnr_T save_dollar_vcol; char_u *p; - /* - * Only show match for chars in the 'matchpairs' option. - */ + // Only show match for chars in the 'matchpairs' option. // 'matchpairs' is "x:y,x:y" for (p = (char_u *)curbuf->b_p_mps; *p != NUL; p++) { if (utf_ptr2char((char *)p) == c && (curwin->w_p_rl ^ p_ri)) { @@ -2425,10 +2338,8 @@ void showmatch(int c) // and has a higher column number. dollar_vcol = save_dollar_vcol; - /* - * brief pause, unless 'm' is present in 'cpo' and a character is - * available. - */ + // brief pause, unless 'm' is present in 'cpo' and a character is + // available. if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL) { os_delay((uint64_t)p_mat * 100L + 8, true); } else if (!char_avail()) { @@ -3667,10 +3578,8 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo // 'includeexpr' is set. msg_outtrans_attr((char *)new_fname, HL_ATTR(HLF_D)); } else { - /* - * Isolate the file name. - * Include the surrounding "" or <> if present. - */ + // Isolate the file name. + // Include the surrounding "" or <> if present. if (inc_opt != NULL && strstr(inc_opt, "\\zs") != NULL) { // pattern contains \zs, use the match @@ -3763,9 +3672,7 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo } } } else { - /* - * Check if the line is a define (type == FIND_DEFINE) - */ + // Check if the line is a define (type == FIND_DEFINE) p = line; search_line: define_matched = false; @@ -3781,10 +3688,8 @@ search_line: define_matched = true; } - /* - * Look for a match. Don't do this if we are looking for a - * define and this line didn't match define_prog above. - */ + // Look for a match. Don't do this if we are looking for a + // define and this line didn't match define_prog above. if (def_regmatch.regprog == NULL || define_matched) { if (define_matched || compl_status_sol()) { // compare the first "len" chars from "ptr" @@ -3812,12 +3717,10 @@ search_line: matched = false; } - /* - * Also check for a "/ *" or "/ /" before the match. - * Skips lines like "int backwards; / * normal index - * * /" when looking for "normal". - * Note: Doesn't skip "/ *" in comments. - */ + // Also check for a "/ *" or "/ /" before the match. + // Skips lines like "int backwards; / * normal index + // * /" when looking for "normal". + // Note: Doesn't skip "/ *" in comments. p = (char_u *)skipwhite((char *)line); if (matched || (p[0] == '/' && p[1] == '*') || p[0] == '*') { @@ -4033,11 +3936,9 @@ exit_matched: break; } - /* - * Read the next line. When reading an included file and encountering - * end-of-file, close the file and continue in the file that included - * it. - */ + // Read the next line. When reading an included file and encountering + // end-of-file, close the file and continue in the file that included + // it. while (depth >= 0 && !already && vim_fgets(line = file_line, LSIZE, files[depth].fp)) { fclose(files[depth].fp); diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 423436eccc..12bfa35dd6 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -65,28 +65,22 @@ char *xstrnsave(const char *string, size_t len) return strncpy(xmallocz(len), string, len); // NOLINT(runtime/printf) } -/* - * Same as vim_strsave(), but any characters found in esc_chars are preceded - * by a backslash. - */ +// Same as vim_strsave(), but any characters found in esc_chars are preceded +// by a backslash. char_u *vim_strsave_escaped(const char_u *string, const char_u *esc_chars) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { return vim_strsave_escaped_ext(string, esc_chars, '\\', false); } -/* - * Same as vim_strsave_escaped(), but when "bsl" is true also escape - * characters where rem_backslash() would remove the backslash. - * Escape the characters with "cc". - */ +// Same as vim_strsave_escaped(), but when "bsl" is true also escape +// characters where rem_backslash() would remove the backslash. +// Escape the characters with "cc". char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars, char_u cc, bool bsl) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { - /* - * First count the number of backslashes required. - * Then allocate the memory and insert them. - */ + // First count the number of backslashes required. + // Then allocate the memory and insert them. size_t length = 1; // count the trailing NUL for (const char_u *p = string; *p; p++) { const size_t l = (size_t)(utfc_ptr2len((char *)p)); @@ -169,16 +163,14 @@ char *vim_strnsave_unquoted(const char *const string, const size_t length) return ret; } -/* - * Escape "string" for use as a shell argument with system(). - * This uses single quotes, except when we know we need to use double quotes - * (MS-Windows without 'shellslash' set). - * Escape a newline, depending on the 'shell' option. - * When "do_special" is true also replace "!", "%", "#" and things starting - * with "<" like "". - * When "do_newline" is false do not escape newline unless it is csh shell. - * Returns the result in allocated memory. - */ +// Escape "string" for use as a shell argument with system(). +// This uses single quotes, except when we know we need to use double quotes +// (MS-Windows without 'shellslash' set). +// Escape a newline, depending on the 'shell' option. +// When "do_special" is true also replace "!", "%", "#" and things starting +// with "<" like "". +// When "do_newline" is false do not escape newline unless it is csh shell. +// Returns the result in allocated memory. char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_newline) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { @@ -295,10 +287,8 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n return escaped_string; } -/* - * Like vim_strsave(), but make all characters uppercase. - * This uses ASCII lower-to-upper case translation, language independent. - */ +// Like vim_strsave(), but make all characters uppercase. +// This uses ASCII lower-to-upper case translation, language independent. char_u *vim_strsave_up(const char_u *string) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { @@ -319,9 +309,7 @@ char *vim_strnsave_up(const char *string, size_t len) return p1; } -/* - * ASCII lower-to-upper case translation, language independent. - */ +// ASCII lower-to-upper case translation, language independent. void vim_strup(char_u *p) FUNC_ATTR_NONNULL_ALL { @@ -375,9 +363,7 @@ char *strcase_save(const char *const orig, bool upper) return res; } -/* - * delete spaces at the end of a string - */ +// delete spaces at the end of a string void del_trailing_spaces(char_u *ptr) FUNC_ATTR_NONNULL_ALL { @@ -402,11 +388,9 @@ size_t xstrnlen(const char *s, size_t n) #endif #if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) -/* - * Compare two strings, ignoring case, using current locale. - * Doesn't work for multi-byte characters. - * return 0 for match, < 0 for smaller, > 0 for bigger - */ +// Compare two strings, ignoring case, using current locale. +// Doesn't work for multi-byte characters. +// return 0 for match, < 0 for smaller, > 0 for bigger int vim_stricmp(const char *s1, const char *s2) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE { @@ -428,11 +412,9 @@ int vim_stricmp(const char *s1, const char *s2) #endif #if (!defined(HAVE_STRNCASECMP) && !defined(HAVE_STRNICMP)) -/* - * Compare two strings, for length "len", ignoring case, using current locale. - * Doesn't work for multi-byte characters. - * return 0 for match, < 0 for smaller, > 0 for bigger - */ +// Compare two strings, for length "len", ignoring case, using current locale. +// Doesn't work for multi-byte characters. +// return 0 for match, < 0 for smaller, > 0 for bigger int vim_strnicmp(const char *s1, const char *s2, size_t len) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE { @@ -477,9 +459,7 @@ char *vim_strchr(const char *const string, const int c) } } -/* - * Sort an array of strings. - */ +// Sort an array of strings. #ifdef INCLUDE_GENERATED_DECLARATIONS # include "strings.c.generated.h" @@ -495,10 +475,8 @@ void sort_strings(char **files, int count) qsort((void *)files, (size_t)count, sizeof(char *), sort_compare); } -/* - * Return true if string "s" contains a non-ASCII character (128 or higher). - * When "s" is NULL false is returned. - */ +// Return true if string "s" contains a non-ASCII character (128 or higher). +// When "s" is NULL false is returned. bool has_non_ascii(const char_u *s) FUNC_ATTR_PURE { diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 9eb412b803..fedd053e88 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -1,9 +1,7 @@ // 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 - */ +// syntax.c: code for syntax highlighting #include #include @@ -104,11 +102,9 @@ typedef struct syn_cluster_S { int16_t *scl_list; // IDs in this syntax cluster } syn_cluster_T; -/* - * For the current state we need to remember more than just the idx. - * When si_m_endpos.lnum is 0, the items other than si_idx are unknown. - * (The end positions have the column number of the next char) - */ +// For the current state we need to remember more than just the idx. +// When si_m_endpos.lnum is 0, the items other than si_idx are unknown. +// (The end positions have the column number of the next char) typedef struct state_item { int si_idx; // index of syntax pattern or // KEYWORD_IDX @@ -133,10 +129,8 @@ typedef struct state_item { // pattern } stateitem_T; -/* - * Struct to reduce the number of arguments to get_syn_options(), it's used - * very often. - */ +// Struct to reduce the number of arguments to get_syn_options(), it's used +// very often. typedef struct { int flags; // flags for contained and transparent bool keyword; // true for ":syn keyword" @@ -184,9 +178,7 @@ static char *(spo_name_tab[SPO_COUNT]) = #define NONE_IDX (-2) // value of sp_sync_idx for "NONE" -/* - * Flags for b_syn_sync_flags: - */ +// Flags for b_syn_sync_flags: #define SF_CCOMMENT 0x01 // sync on a C-style comment #define SF_MATCH 0x02 // sync by matching a pattern @@ -194,9 +186,7 @@ static char *(spo_name_tab[SPO_COUNT]) = #define MAXKEYWLEN 80 // maximum length of a keyword -/* - * The attributes of the syntax item that has been recognized. - */ +// The attributes of the syntax item that has been recognized. static int current_attr = 0; // attr of current syntax word static int current_id = 0; // ID of current char for syn_get_id() static int current_trans_id = 0; // idem, transparency removed @@ -204,23 +194,19 @@ static int current_flags = 0; static int current_seqnr = 0; static int current_sub_char = 0; -/* - * Methods of combining two clusters - */ +// Methods of combining two clusters #define CLUSTER_REPLACE 1 // replace first list with second #define CLUSTER_ADD 2 // add second list to first #define CLUSTER_SUBTRACT 3 // subtract second list from first #define SYN_CLSTR(buf) ((syn_cluster_T *)((buf)->b_syn_clusters.ga_data)) -/* - * Syntax group IDs have different types: - * 0 - 19999 normal syntax groups - * 20000 - 20999 ALLBUT indicator (current_syn_inc_tag added) - * 21000 - 21999 TOP indicator (current_syn_inc_tag added) - * 22000 - 22999 CONTAINED indicator (current_syn_inc_tag added) - * 23000 - 32767 cluster IDs (subtract SYNID_CLUSTER for the cluster ID) - */ +// Syntax group IDs have different types: +// 0 - 19999 normal syntax groups +// 20000 - 20999 ALLBUT indicator (current_syn_inc_tag added) +// 21000 - 21999 TOP indicator (current_syn_inc_tag added) +// 22000 - 22999 CONTAINED indicator (current_syn_inc_tag added) +// 23000 - 32767 cluster IDs (subtract SYNID_CLUSTER for the cluster ID) #define SYNID_ALLBUT MAX_HL_ID // syntax group ID for contains=ALLBUT #define SYNID_TOP 21000 // syntax group ID for contains=TOP #define SYNID_CONTAINED 22000 // syntax group ID for contains=CONTAINED @@ -234,21 +220,17 @@ static int current_sub_char = 0; // instead of passing it to them, we stow it here. static char **syn_cmdlinep; -/* - * Another Annoying Hack(TM): To prevent rules from other ":syn include"'d - * files from leaking into ALLBUT lists, we assign a unique ID to the - * rules in each ":syn include"'d file. - */ +// Another Annoying Hack(TM): To prevent rules from other ":syn include"'d +// files from leaking into ALLBUT lists, we assign a unique ID to the +// rules in each ":syn include"'d file. static int current_syn_inc_tag = 0; static int running_syn_inc_tag = 0; -/* - * In a hashtable item "hi_key" points to "keyword" in a keyentry. - * This avoids adding a pointer to the hashtable item. - * KE2HIKEY() converts a var pointer to a hashitem key pointer. - * HIKEY2KE() converts a hashitem key pointer to a var pointer. - * HI2KE() converts a hashitem pointer to a var pointer. - */ +// In a hashtable item "hi_key" points to "keyword" in a keyentry. +// This avoids adding a pointer to the hashtable item. +// KE2HIKEY() converts a var pointer to a hashitem key pointer. +// HIKEY2KE() converts a hashitem key pointer to a var pointer. +// HI2KE() converts a hashitem pointer to a var pointer. static keyentry_T dumkey; #define KE2HIKEY(kp) ((kp)->keyword) #define HIKEY2KE(p) ((keyentry_T *)((p) - (dumkey.keyword - (char_u *)&dumkey))) @@ -256,11 +238,9 @@ static keyentry_T dumkey; // -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. - */ +// 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. static int keepend_level = -1; static char msg_no_items[] = N_("No Syntax items defined for this buffer"); @@ -272,13 +252,11 @@ static char msg_no_items[] = N_("No Syntax items defined for this buffer"); static int next_seqnr = 1; // value to use for si_seqnr -/* - * The next possible match in the current line for any pattern is remembered, - * to avoid having to try for a match in each column. - * If next_match_idx == -1, not tried (in this line) yet. - * If next_match_col == MAXCOL, no match found in this line. - * (All end positions have the column of the char after the end) - */ +// The next possible match in the current line for any pattern is remembered, +// to avoid having to try for a match in each column. +// If next_match_idx == -1, not tried (in this line) yet. +// If next_match_col == MAXCOL, no match found in this line. +// (All end positions have the column of the char after the end) static int next_match_col; // column for start of next match 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 @@ -290,17 +268,13 @@ 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 static reg_extmatch_T *next_match_extmatch = NULL; -/* - * A state stack is an array of integers or stateitem_T, stored in a - * garray_T. A state stack is invalid if its itemsize entry is zero. - */ +// A state stack is an array of integers or stateitem_T, stored in a +// garray_T. A state stack is invalid if its itemsize entry is zero. #define INVALID_STATE(ssp) ((ssp)->ga_itemsize == 0) #define VALID_STATE(ssp) ((ssp)->ga_itemsize != 0) -/* - * The current state (within the line) of the recognition engine. - * When current_state.ga_itemsize is 0 the current state is invalid. - */ +// The current state (within the line) of the recognition engine. +// When current_state.ga_itemsize is 0 the current state is invalid. static win_T *syn_win; // current window for highlighting static buf_T *syn_buf; // current buffer for highlighting static synblock_T *syn_block; // current buffer for highlighting @@ -328,13 +302,11 @@ void syn_set_timeout(proftime_T *tm) syn_tm = tm; } -/* - * Start the syntax recognition for a line. This function is normally called - * from the screen updating, once for each displayed line. - * The buffer is remembered in syn_buf, because get_syntax_attr() doesn't get - * it. Careful: curbuf and curwin are likely to point to another buffer and - * window. - */ +// Start the syntax recognition for a line. This function is normally called +// from the screen updating, once for each displayed line. +// The buffer is remembered in syn_buf, because get_syntax_attr() doesn't get +// it. Careful: curbuf and curwin are likely to point to another buffer and +// window. void syntax_start(win_T *wp, linenr_T lnum) { synstate_T *p; @@ -348,11 +320,9 @@ void syntax_start(win_T *wp, linenr_T lnum) current_sub_char = NUL; - /* - * After switching buffers, invalidate current_state. - * Also do this when a change was made, the current state may be invalid - * then. - */ + // After switching buffers, invalidate current_state. + // Also do this when a change was made, the current state may be invalid + // then. if (syn_block != wp->w_s || syn_buf != wp->w_buffer || changedtick != buf_get_changedtick(syn_buf)) { @@ -363,18 +333,14 @@ void syntax_start(win_T *wp, linenr_T lnum) changedtick = buf_get_changedtick(syn_buf); syn_win = wp; - /* - * Allocate syntax stack when needed. - */ + // Allocate syntax stack when needed. syn_stack_alloc(); if (syn_block->b_sst_array == NULL) { return; // out of memory } syn_block->b_sst_lasttick = display_tick; - /* - * If the state of the end of the previous line is useful, store it. - */ + // If the state of the end of the previous line is useful, store it. if (VALID_STATE(¤t_state) && current_lnum < lnum && current_lnum < syn_buf->b_ml.ml_line_count) { @@ -384,11 +350,9 @@ void syntax_start(win_T *wp, linenr_T lnum) (void)store_current_state(); } - /* - * If the current_lnum is now the same as "lnum", keep the current - * state (this happens very often!). Otherwise invalidate - * current_state and figure it out below. - */ + // If the current_lnum is now the same as "lnum", keep the current + // state (this happens very often!). Otherwise invalidate + // current_state and figure it out below. if (current_lnum != lnum) { invalidate_current_state(); } @@ -396,10 +360,8 @@ void syntax_start(win_T *wp, linenr_T lnum) invalidate_current_state(); } - /* - * Try to synchronize from a saved state in b_sst_array[]. - * Only do this if lnum is not before and not to far beyond a saved state. - */ + // Try to synchronize from a saved state in b_sst_array[]. + // Only do this if lnum is not before and not to far beyond a saved state. if (INVALID_STATE(¤t_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) { @@ -418,10 +380,8 @@ void syntax_start(win_T *wp, linenr_T lnum) } } - /* - * If "lnum" is before or far beyond a line with a saved state, need to - * re-synchronize. - */ + // If "lnum" is before or far beyond a line with a saved state, need to + // re-synchronize. if (INVALID_STATE(¤t_state)) { syn_sync(wp, lnum, last_valid); if (current_lnum == 1) { @@ -436,10 +396,8 @@ void syntax_start(win_T *wp, linenr_T lnum) first_stored = current_lnum; } - /* - * Advance from the sync point or saved state until the current line. - * Save some entries for syncing with later on. - */ + // Advance from the sync point or saved state until the current line. + // Save some entries for syncing with later on. if (syn_block->b_sst_len <= Rows) { dist = 999999; } else { @@ -506,10 +464,8 @@ void syntax_start(win_T *wp, linenr_T lnum) syn_start_line(); } -/* - * We cannot simply discard growarrays full of state_items or buf_states; we - * have to manually release their extmatch pointers first. - */ +// We cannot simply discard growarrays full of state_items or buf_states; we +// have to manually release their extmatch pointers first. static void clear_syn_state(synstate_T *p) { if (p->sst_stacksize > SST_FIX_STATES) { @@ -522,24 +478,20 @@ static void clear_syn_state(synstate_T *p) } } -/* - * Cleanup the current_state stack. - */ +// Cleanup the current_state stack. static void clear_current_state(void) { #define UNREF_STATEITEM_EXTMATCH(si) unref_extmatch((si)->si_extmatch) GA_DEEP_CLEAR(¤t_state, stateitem_T, UNREF_STATEITEM_EXTMATCH); } -/* - * Try to find a synchronisation point for line "lnum". - * - * This sets current_lnum and the current state. One of three methods is - * used: - * 1. Search backwards for the end of a C-comment. - * 2. Search backwards for given sync patterns. - * 3. Simply start on a given number of lines above "lnum". - */ +// Try to find a synchronisation point for line "lnum". +// +// This sets current_lnum and the current state. One of three methods is +// used: +// 1. Search backwards for the end of a C-comment. +// 2. Search backwards for given sync patterns. +// 3. Simply start on a given number of lines above "lnum". static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) { buf_T *curbuf_save; @@ -560,19 +512,15 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) lpos_T found_m_endpos; colnr_T prev_current_col; - /* - * Clear any current state that might be hanging around. - */ + // Clear any current state that might be hanging around. invalidate_current_state(); - /* - * Start at least "minlines" back. Default starting point for parsing is - * there. - * Start further back, to avoid that scrolling backwards will result in - * resyncing for every line. Now it resyncs only one out of N lines, - * where N is minlines * 1.5, or minlines * 2 if minlines is small. - * Watch out for overflow when minlines is MAXLNUM. - */ + // Start at least "minlines" back. Default starting point for parsing is + // there. + // Start further back, to avoid that scrolling backwards will result in + // resyncing for every line. Now it resyncs only one out of N lines, + // where N is minlines * 1.5, or minlines * 2 if minlines is small. + // Watch out for overflow when minlines is MAXLNUM. if (syn_block->b_syn_sync_minlines > start_lnum) { start_lnum = 1; } else { @@ -595,9 +543,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) } current_lnum = start_lnum; - /* - * 1. Search backwards for the end of a C-style comment. - */ + // 1. Search backwards for the end of a C-style comment. if (syn_block->b_syn_sync_flags & SF_CCOMMENT) { // Need to make syn_buf the current buffer for a moment, to be able to // use find_start_comment(). @@ -606,9 +552,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) curbuf_save = curbuf; curbuf = syn_buf; - /* - * Skip lines that end in a backslash. - */ + // Skip lines that end in a backslash. for (; start_lnum > 1; start_lnum--) { line = (char_u *)ml_get(start_lnum - 1); if (*line == NUL || *(line + STRLEN(line) - 1) != '\\') { @@ -622,11 +566,9 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) wp->w_cursor.lnum = start_lnum; wp->w_cursor.col = 0; - /* - * If the line is inside a comment, need to find the syntax item that - * defines the comment. - * Restrict the search for the end of a comment to b_syn_sync_maxlines. - */ + // If the line is inside a comment, need to find the syntax item that + // defines the comment. + // Restrict the search for the end of a comment to b_syn_sync_maxlines. if (find_start_comment((int)syn_block->b_syn_sync_maxlines) != NULL) { for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0;) { if (SYN_ITEMS(syn_block)[idx].sp_syn.id @@ -644,11 +586,8 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) wp->w_cursor = cursor_save; curwin = curwin_save; curbuf = curbuf_save; - } - /* - * 2. Search backwards for given sync patterns. - */ - else if (syn_block->b_syn_sync_flags & SF_MATCH) { + } else if (syn_block->b_syn_sync_flags & SF_MATCH) { + // 2. Search backwards for given sync patterns. if (syn_block->b_syn_sync_maxlines != 0 && start_lnum > syn_block->b_syn_sync_maxlines) { break_lnum = start_lnum - syn_block->b_syn_sync_maxlines; @@ -675,16 +614,12 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) break; } - /* - * Check if the previous line has the line-continuation pattern. - */ + // Check if the previous line has the line-continuation pattern. if (lnum > 1 && syn_match_linecont(lnum - 1)) { continue; } - /* - * Start with nothing on the state stack - */ + // Start with nothing on the state stack validate_current_state(); for (current_lnum = lnum; current_lnum < end_lnum; current_lnum++) { @@ -712,10 +647,8 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) found_current_lnum = current_lnum; found_current_col = current_col; found_m_endpos = cur_si->si_m_endpos; - /* - * Continue after the match (be aware of a zero-length - * match). - */ + // Continue after the match (be aware of a zero-length + // match). if (found_m_endpos.lnum > current_lnum) { current_lnum = found_m_endpos.lnum; current_col = found_m_endpos.col; @@ -743,27 +676,21 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) } } - /* - * If a sync point was encountered, break here. - */ + // If a sync point was encountered, break here. if (found_flags) { - /* - * Put the item that was specified by the sync point on the - * state stack. If there was no item specified, make the - * state stack empty. - */ + // Put the item that was specified by the sync point on the + // state stack. If there was no item specified, make the + // state stack empty. clear_current_state(); if (found_match_idx >= 0) { push_current_state(found_match_idx); update_si_attr(current_state.ga_len - 1); } - /* - * When using "grouphere", continue from the sync point - * match, until the end of the line. Parsing starts at - * the next line. - * For "groupthere" the parsing starts at start_lnum. - */ + // When using "grouphere", continue from the sync point + // match, until the end of the line. Parsing starts at + // the next line. + // For "groupthere" the parsing starts at start_lnum. if (found_flags & HL_SYNC_HERE) { if (!GA_EMPTY(¤t_state)) { cur_si = &CUR_STATE(current_state.ga_len - 1); @@ -833,18 +760,14 @@ static int syn_match_linecont(linenr_T lnum) return false; } -/* - * Prepare the current state for the start of a line. - */ +// Prepare the current state for the start of a line. static void syn_start_line(void) { current_finished = false; current_col = 0; - /* - * Need to update the end of a start/skip/end that continues from the - * previous line and regions that have "keepend". - */ + // Need to update the end of a start/skip/end that continues from the + // previous line and regions that have "keepend". if (!GA_EMPTY(¤t_state)) { syn_update_ends(true); check_state_ends(); @@ -881,15 +804,13 @@ static void syn_update_ends(bool startofline) } } - /* - * Need to update the end of a start/skip/end that continues from the - * previous line. And regions that have "keepend", because they may - * influence contained items. If we've just removed "extend" - * (startofline == 0) then we should update ends of normal regions - * contained inside "keepend" because "extend" could have extended - * these "keepend" regions as well as contained normal regions. - * Then check for items ending in column 0. - */ + // Need to update the end of a start/skip/end that continues from the + // previous line. And regions that have "keepend", because they may + // influence contained items. If we've just removed "extend" + // (startofline == 0) then we should update ends of normal regions + // contained inside "keepend" because "extend" could have extended + // these "keepend" regions as well as contained normal regions. + // Then check for items ending in column 0. int i = current_state.ga_len - 1; if (keepend_level >= 0) { for (; i > keepend_level; i--) { @@ -923,37 +844,35 @@ static void syn_update_ends(bool startofline) ///////////////////////////////////////// // Handling of the state stack cache. -/* - * EXPLANATION OF THE SYNTAX STATE STACK CACHE - * - * To speed up syntax highlighting, the state stack for the start of some - * lines is cached. These entries can be used to start parsing at that point. - * - * The stack is kept in b_sst_array[] for each buffer. There is a list of - * valid entries. b_sst_first points to the first one, then follow sst_next. - * The entries are sorted on line number. The first entry is often for line 2 - * (line 1 always starts with an empty stack). - * There is also a list for free entries. This construction is used to avoid - * having to allocate and free memory blocks too often. - * - * When making changes to the buffer, this is logged in b_mod_*. When calling - * update_screen() to update the display, it will call - * syn_stack_apply_changes() for each displayed buffer to adjust the cached - * entries. The entries which are inside the changed area are removed, - * because they must be recomputed. Entries below the changed have their line - * number adjusted for deleted/inserted lines, and have their sst_change_lnum - * set to indicate that a check must be made if the changed lines would change - * the cached entry. - * - * When later displaying lines, an entry is stored for each line. Displayed - * lines are likely to be displayed again, in which case the state at the - * start of the line is needed. - * For not displayed lines, an entry is stored for every so many lines. These - * entries will be used e.g., when scrolling backwards. The distance between - * entries depends on the number of lines in the buffer. For small buffers - * the distance is fixed at SST_DIST, for large buffers there is a fixed - * number of entries SST_MAX_ENTRIES, and the distance is computed. - */ +// EXPLANATION OF THE SYNTAX STATE STACK CACHE +// +// To speed up syntax highlighting, the state stack for the start of some +// lines is cached. These entries can be used to start parsing at that point. +// +// The stack is kept in b_sst_array[] for each buffer. There is a list of +// valid entries. b_sst_first points to the first one, then follow sst_next. +// The entries are sorted on line number. The first entry is often for line 2 +// (line 1 always starts with an empty stack). +// There is also a list for free entries. This construction is used to avoid +// having to allocate and free memory blocks too often. +// +// When making changes to the buffer, this is logged in b_mod_*. When calling +// update_screen() to update the display, it will call +// syn_stack_apply_changes() for each displayed buffer to adjust the cached +// entries. The entries which are inside the changed area are removed, +// because they must be recomputed. Entries below the changed have their line +// number adjusted for deleted/inserted lines, and have their sst_change_lnum +// set to indicate that a check must be made if the changed lines would change +// the cached entry. +// +// When later displaying lines, an entry is stored for each line. Displayed +// lines are likely to be displayed again, in which case the state at the +// start of the line is needed. +// For not displayed lines, an entry is stored for every so many lines. These +// entries will be used e.g., when scrolling backwards. The distance between +// entries depends on the number of lines in the buffer. For small buffers +// the distance is fixed at SST_DIST, for large buffers there is a fixed +// number of entries SST_MAX_ENTRIES, and the distance is computed. static void syn_stack_free_block(synblock_T *block) { @@ -968,10 +887,8 @@ static void syn_stack_free_block(synblock_T *block) block->b_sst_len = 0; } } -/* - * Free b_sst_array[] for buffer "buf". - * Used when syntax items changed to force resyncing everywhere. - */ +// Free b_sst_array[] for buffer "buf". +// Used when syntax items changed to force resyncing everywhere. void syn_stack_free_all(synblock_T *block) { syn_stack_free_block(block); @@ -984,12 +901,10 @@ void syn_stack_free_all(synblock_T *block) } } -/* - * Allocate the syntax state stack for syn_buf when needed. - * If the number of entries in b_sst_array[] is much too big or a bit too - * small, reallocate it. - * Also used to allocate b_sst_array[] for the first time. - */ +// Allocate the syntax state stack for syn_buf when needed. +// If the number of entries in b_sst_array[] is much too big or a bit too +// small, reallocate it. +// Also used to allocate b_sst_array[] for the first time. static void syn_stack_alloc(void) { synstate_T *to, *from; @@ -1056,12 +971,10 @@ static void syn_stack_alloc(void) } } -/* - * Check for changes in a buffer to affect stored syntax states. Uses the - * b_mod_* fields. - * Called from update_screen(), before screen is being updated, once for each - * displayed buffer. - */ +// Check for changes in a buffer to affect stored syntax states. Uses the +// b_mod_* fields. +// Called from update_screen(), before screen is being updated, once for each +// displayed buffer. void syn_stack_apply_changes(buf_T *buf) { syn_stack_apply_changes_block(&buf->b_s, buf); @@ -1137,11 +1050,9 @@ static bool syn_stack_cleanup(void) dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; } - /* - * Go through the list to find the "tick" for the oldest entry that can - * be removed. Set "above" when the "tick" for the oldest entry is above - * "b_sst_lasttick" (the display tick wraps around). - */ + // Go through the list to find the "tick" for the oldest entry that can + // be removed. Set "above" when the "tick" for the oldest entry is above + // "b_sst_lasttick" (the display tick wraps around). tick = syn_block->b_sst_lasttick; bool above = false; prev = syn_block->b_sst_first; @@ -1158,10 +1069,8 @@ static bool syn_stack_cleanup(void) } } - /* - * Go through the list to make the entries for the oldest tick at an - * interval of several lines. - */ + // 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) { if (p->sst_tick == tick && prev->sst_lnum + dist > p->sst_lnum) { @@ -1175,10 +1084,8 @@ static bool syn_stack_cleanup(void) return retval; } -/* - * Free the allocated memory for a syn_state item. - * Move the entry into the free list. - */ +// Free the allocated memory for a syn_state item. +// Move the entry into the free list. static void syn_stack_free_entry(synblock_T *block, synstate_T *p) { clear_syn_state(p); @@ -1187,10 +1094,8 @@ static void syn_stack_free_entry(synblock_T *block, synstate_T *p) block->b_sst_freecount++; } -/* - * Find an entry in the list of state stacks at or before "lnum". - * Returns NULL when there is no entry or the first entry is after "lnum". - */ +// Find an entry in the list of state stacks at or before "lnum". +// 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; @@ -1207,10 +1112,8 @@ static synstate_T *syn_stack_find_entry(linenr_T lnum) return prev; } -/* - * Try saving the current state in b_sst_array[]. - * The current state must be valid for the start of the current_lnum line! - */ +// Try saving the current state in b_sst_array[]. +// The current state must be valid for the start of the current_lnum line! static synstate_T *store_current_state(void) { int i; @@ -1219,10 +1122,8 @@ static synstate_T *store_current_state(void) stateitem_T *cur_si; synstate_T *sp = syn_stack_find_entry(current_lnum); - /* - * If the current state contains a start or end pattern that continues - * from the previous line, we can't use it. Don't store it then. - */ + // If the current state contains a start or end pattern that continues + // from the previous line, we can't use it. Don't store it then. for (i = current_state.ga_len - 1; i >= 0; i--) { cur_si = &CUR_STATE(i); if (cur_si->si_h_startpos.lnum >= current_lnum @@ -1254,9 +1155,7 @@ static synstate_T *store_current_state(void) sp = NULL; } } else if (sp == NULL || sp->sst_lnum != current_lnum) { - /* - * Add a new entry - */ + // Add a new entry // If no free items, cleanup the array first. if (syn_block->b_sst_freecount == 0) { (void)syn_stack_cleanup(); @@ -1316,9 +1215,7 @@ static synstate_T *store_current_state(void) return sp; } -/* - * Copy a state stack from "from" in b_sst_array[] to current_state; - */ +// Copy a state stack from "from" in b_sst_array[] to current_state; static void load_current_state(synstate_T *from) { int i; @@ -1422,16 +1319,14 @@ static bool syn_stack_equal(synstate_T *sp) return i < 0 ? true : false; } -/* - * We stop parsing syntax above line "lnum". If the stored state at or below - * this line depended on a change before it, it now depends on the line below - * the last parsed line. - * The window looks like this: - * line which changed - * displayed line - * displayed line - * lnum -> line below window - */ +// We stop parsing syntax above line "lnum". If the stored state at or below +// this line depended on a change before it, it now depends on the line below +// the last parsed line. +// The window looks like this: +// line which changed +// displayed line +// displayed line +// lnum -> line below window void syntax_end_parsing(linenr_T lnum) { synstate_T *sp; @@ -1446,9 +1341,8 @@ void syntax_end_parsing(linenr_T lnum) } } -/* - * End of handling of the state stack. - ****************************************/ +// End of handling of the state stack. +// ************************************** static void invalidate_current_state(void) { @@ -1473,33 +1367,25 @@ bool syntax_check_changed(linenr_T lnum) bool retval = true; synstate_T *sp; - /* - * Check the state stack when: - * - lnum is just below the previously syntaxed line. - * - lnum is not before the lines with saved states. - * - lnum is not past the lines with saved states. - * - lnum is at or before the last changed line. - */ + // Check the state stack when: + // - lnum is just below the previously syntaxed line. + // - lnum is not before the lines with saved states. + // - lnum is not past the lines with saved states. + // - lnum is at or before the last changed line. if (VALID_STATE(¤t_state) && lnum == current_lnum + 1) { sp = syn_stack_find_entry(lnum); if (sp != NULL && sp->sst_lnum == lnum) { - /* - * finish the previous line (needed when not all of the line was - * drawn) - */ + // finish the previous line (needed when not all of the line was + // drawn) (void)syn_finish_line(false); - /* - * Compare the current state with the previously saved state of - * the line. - */ + // Compare the current state with the previously saved state of + // the line. if (syn_stack_equal(sp)) { retval = false; } - /* - * Store the current state in b_sst_array[] for later use. - */ + // Store the current state in b_sst_array[] for later use. current_lnum++; (void)store_current_state(); } @@ -1587,9 +1473,7 @@ int get_syntax_attr(const colnr_T col, bool *const can_spell, const bool keep_st validate_current_state(); } - /* - * Skip from the current column to "col", get the attributes for "col". - */ + // Skip from the current column to "col", get the attributes for "col". while (current_col <= col) { attr = syn_current_attr(false, true, can_spell, current_col == col ? keep_state : false); @@ -1638,9 +1522,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con // Do try matching with an empty line (could be the start of a region). line = (char_u *)syn_getcurline(); if (line[current_col] == NUL && current_col != 0) { - /* - * If we found a match after the last column, use it. - */ + // If we found a match after the last column, use it. if (next_match_idx >= 0 && next_match_col >= (int)current_col && next_match_col != MAXCOL) { (void)push_next_match(); @@ -1657,11 +1539,9 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con current_state_stored = false; } - /* - * When in the previous column there was a match but it could not be used - * (empty match or already matched in this column) need to try again in - * the next column. - */ + // When in the previous column there was a match but it could not be used + // (empty match or already matched in this column) need to try again in + // the next column. if (try_next_column) { next_match_idx = -1; try_next_column = false; @@ -1679,23 +1559,19 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con // use syntax iskeyword option save_chartab((char *)buf_chartab); - /* - * Repeat matching keywords and patterns, to find contained items at the - * same column. This stops when there are no extra matches at the current - * column. - */ + // Repeat matching keywords and patterns, to find contained items at the + // same column. This stops when there are no extra matches at the current + // column. do { found_match = false; keep_next_list = false; int syn_id = 0; - /* - * 1. Check for a current state. - * Only when there is no current state, or if the current state may - * contain other things, we need to check for keywords and patterns. - * Always need to check for contained items if some item has the - * "containedin" argument (takes extra time!). - */ + // 1. Check for a current state. + // Only when there is no current state, or if the current state may + // contain other things, we need to check for keywords and patterns. + // Always need to check for contained items if some item has the + // "containedin" argument (takes extra time!). if (current_state.ga_len) { cur_si = &CUR_STATE(current_state.ga_len - 1); } else { @@ -1758,21 +1634,15 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con } } - /* - * 3. Check for patterns (only if no keyword found). - */ + // 3. Check for patterns (only if no keyword found). if (syn_id == 0 && syn_block->b_syn_patterns.ga_len) { - /* - * If we didn't check for a match yet, or we are past it, check - * for any match with a pattern. - */ + // If we didn't check for a match yet, or we are past it, check + // for any match with a pattern. if (next_match_idx < 0 || next_match_col < (int)current_col) { - /* - * Check all relevant patterns for a match at this - * position. This is complicated, because matching with a - * pattern takes quite a bit of time, thus we want to - * avoid doing it when it's not needed. - */ + // Check all relevant patterns for a match at this + // position. This is complicated, because matching with a + // pattern takes quite a bit of time, thus we want to + // avoid doing it when it's not needed. next_match_idx = 0; // no match in this line yet next_match_col = MAXCOL; for (int idx = syn_block->b_syn_patterns.ga_len; --idx >= 0;) { @@ -1814,9 +1684,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con continue; } - /* - * Compute the first column of the match. - */ + // Compute the first column of the match. syn_add_start_off(&pos, ®match, spp, SPO_MS_OFF, -1); if (pos.lnum > current_lnum) { @@ -1831,19 +1699,15 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con // matches in the current line spp->sp_startcol = startcol; - /* - * If a previously found match starts at a lower - * column number, don't use this one. - */ + // If a previously found match starts at a lower + // column number, don't use this one. if (startcol >= next_match_col) { continue; } - /* - * If we matched this pattern at this position - * before, skip it. Must retry in the next - * column, because it may match from there. - */ + // If we matched this pattern at this position + // before, skip it. Must retry in the next + // column, because it may match from there. if (did_match_already(idx, &zero_width_next_ga)) { try_next_column = true; continue; @@ -1861,10 +1725,8 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con syn_add_end_off(&eos_pos, ®match, spp, SPO_RS_OFF, 0); - /* - * Grab the external submatches before they get - * overwritten. Reference count doesn't change. - */ + // Grab the external submatches before they get + // overwritten. Reference count doesn't change. unref_extmatch(cur_extmatch); cur_extmatch = re_extmatch_out; re_extmatch_out = NULL; @@ -1875,12 +1737,10 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con end_idx = 0; hl_endpos.lnum = 0; - /* - * For a "oneline" the end must be found in the - * same line too. Search for it after the end of - * the match with the start pattern. Set the - * resulting end positions at the same time. - */ + // For a "oneline" the end must be found in the + // same line too. Search for it after the end of + // the match with the start pattern. Set the + // resulting end positions at the same time. if (spp->sp_type == SPTYPE_START && (spp->sp_flags & HL_ONELINE)) { lpos_T startpos; @@ -1891,23 +1751,18 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con if (endpos.lnum == 0) { continue; // not found } - } - /* - * For a "match" the size must be > 0 after the - * end offset needs has been added. Except when - * syncing. - */ - else if (spp->sp_type == SPTYPE_MATCH) { + } else if (spp->sp_type == SPTYPE_MATCH) { + // For a "match" the size must be > 0 after the + // end offset needs has been added. Except when + // syncing. syn_add_end_off(&hl_endpos, ®match, spp, SPO_HE_OFF, 0); syn_add_end_off(&endpos, ®match, spp, SPO_ME_OFF, 0); if (endpos.lnum == current_lnum && (int)endpos.col + syncing < startcol) { - /* - * If an empty string is matched, may need - * to try matching again at next column. - */ + // If an empty string is matched, may need + // to try matching again at next column. if (regmatch.startpos[0].col == regmatch.endpos[0].col) { try_next_column = true; } @@ -1915,9 +1770,8 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con } } - /* - * keep the best match so far in next_match_* - */ + // keep the best match so far in next_match_* + // Highlighting must start after startpos and end // before endpos. if (hl_startpos.lnum == current_lnum @@ -1942,9 +1796,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con } } - /* - * If we found a match at the current column, use it. - */ + // If we found a match at the current column, use it. if (next_match_idx >= 0 && next_match_col == (int)current_col) { synpat_T *lspp; @@ -1972,9 +1824,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con } } - /* - * Handle searching for nextgroup match. - */ + // Handle searching for nextgroup match. if (current_next_list != NULL && !keep_next_list) { // If a nextgroup was not found, continue looking for one if: // - this is an empty line and the "skipempty" option was given @@ -1989,14 +1839,12 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con } } - /* - * If a nextgroup was found: Use it, and continue looking for - * contained matches. - * If a nextgroup was not found: Continue looking for a normal - * match. - * When did set current_next_list for a zero-width item and no - * match was found don't loop (would get stuck). - */ + // If a nextgroup was found: Use it, and continue looking for + // contained matches. + // If a nextgroup was not found: Continue looking for a normal + // match. + // When did set current_next_list for a zero-width item and no + // match was found don't loop (would get stuck). current_next_list = NULL; next_match_idx = -1; if (!zero_width_next_list) { @@ -2007,10 +1855,8 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con restore_chartab((char *)buf_chartab); - /* - * Use attributes from the current state, if within its highlighting. - * If not, use attributes from the current-but-one state, etc. - */ + // Use attributes from the current state, if within its highlighting. + // If not, use attributes from the current-but-one state, etc. current_attr = 0; current_id = 0; current_trans_id = 0; @@ -2076,14 +1922,12 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con } } - /* - * Check for end of current state (and the states before it) at the - * next column. Don't do this for syncing, because we would miss a - * single character match. - * First check if the current state ends at the current column. It - * may be for an empty match and a containing item might end in the - * current column. - */ + // Check for end of current state (and the states before it) at the + // next column. Don't do this for syncing, because we would miss a + // single character match. + // First check if the current state ends at the current column. It + // may be for an empty match and a containing item might end in the + // current column. if (!syncing && !keep_state) { check_state_ends(); if (!GA_EMPTY(¤t_state) @@ -2143,9 +1987,7 @@ static bool did_match_already(int idx, garray_T *gap) return false; } -/* - * Push the next match onto the stack. - */ +// Push the next match onto the stack. static stateitem_T *push_next_match(void) { stateitem_T *cur_si; @@ -2154,15 +1996,11 @@ static stateitem_T *push_next_match(void) spp = &(SYN_ITEMS(syn_block)[next_match_idx]); - /* - * Push the item in current_state stack; - */ + // Push the item in current_state stack; push_current_state(next_match_idx); { - /* - * If it's a start-skip-end type that crosses lines, figure out how - * much it continues in this line. Otherwise just fill in the length. - */ + // If it's a start-skip-end type that crosses lines, figure out how + // much it continues in this line. Otherwise just fill in the length. cur_si = &CUR_STATE(current_state.ga_len - 1); cur_si->si_h_startpos = next_match_h_startpos; cur_si->si_m_startcol = current_col; @@ -2195,10 +2033,8 @@ static stateitem_T *push_next_match(void) update_si_attr(current_state.ga_len - 1); save_flags = cur_si->si_flags & (HL_CONCEAL | HL_CONCEALENDS); - /* - * If the start pattern has another highlight group, push another item - * on the stack for the start pattern. - */ + // If the start pattern has another highlight group, push another item + // on the stack for the start pattern. if (spp->sp_type == SPTYPE_START && spp->sp_syn_match_id != 0) { push_current_state(next_match_idx); cur_si = &CUR_STATE(current_state.ga_len - 1); @@ -2226,9 +2062,7 @@ static stateitem_T *push_next_match(void) return cur_si; } -/* - * Check for end of current state (and the states before it). - */ +// Check for end of current state (and the states before it). static void check_state_ends(void) { stateitem_T *cur_si; @@ -2240,12 +2074,10 @@ static void check_state_ends(void) && (cur_si->si_m_endpos.lnum < current_lnum || (cur_si->si_m_endpos.lnum == current_lnum && cur_si->si_m_endpos.col <= current_col))) { - /* - * If there is an end pattern group ID, highlight the end pattern - * now. No need to pop the current item from the stack. - * Only do this if the end pattern continues beyond the current - * position. - */ + // If there is an end pattern group ID, highlight the end pattern + // now. No need to pop the current item from the stack. + // Only do this if the end pattern continues beyond the current + // position. if (cur_si->si_end_idx && (cur_si->si_eoe_pos.lnum > current_lnum || (cur_si->si_eoe_pos.lnum == current_lnum @@ -2322,10 +2154,8 @@ static void check_state_ends(void) } } -/* - * Update an entry in the current_state stack for a match or region. This - * fills in si_attr, si_next_list and si_cont_list. - */ +// Update an entry in the current_state stack for a match or region. This +// fills in si_attr, si_next_list and si_cont_list. static void update_si_attr(int idx) { stateitem_T *sip = &CUR_STATE(idx); @@ -2350,11 +2180,9 @@ static void update_si_attr(int idx) sip->si_cont_list = spp->sp_cont_list; } - /* - * For transparent items, take attr from outer item. - * Also take cont_list, if there is none. - * Don't do this for the matchgroup of a start or end pattern. - */ + // For transparent items, take attr from outer item. + // Also take cont_list, if there is none. + // Don't do this for the matchgroup of a start or end pattern. if ((spp->sp_flags & HL_TRANSP) && !(sip->si_flags & HL_MATCH)) { if (idx == 0) { sip->si_attr = 0; @@ -2373,10 +2201,8 @@ static void update_si_attr(int idx) } } -/* - * Check the current stack for patterns with "keepend" flag. - * Propagate the match-end to contained items, until a "skipend" item is found. - */ +// Check the current stack for patterns with "keepend" flag. +// Propagate the match-end to contained items, until a "skipend" item is found. static void check_keepend(void) { int i; @@ -2384,19 +2210,15 @@ static void check_keepend(void) lpos_T maxpos_h; stateitem_T *sip; - /* - * This check can consume a lot of time; only do it from the level where - * there really is a keepend. - */ + // This check can consume a lot of time; only do it from the level where + // there really is a keepend. if (keepend_level < 0) { return; } - /* - * Find the last index of an "extend" item. "keepend" items before that - * won't do anything. If there is no "extend" item "i" will be - * "keepend_level" and all "keepend" items will work normally. - */ + // Find the last index of an "extend" item. "keepend" items before that + // won't do anything. If there is no "extend" item "i" will be + // "keepend_level" and all "keepend" items will work normally. for (i = current_state.ga_len - 1; i > keepend_level; i--) { if (CUR_STATE(i).si_flags & HL_EXTEND) { break; @@ -2456,10 +2278,8 @@ static void update_si_end(stateitem_T *sip, int startcol, bool force) return; } - /* - * We need to find the end of the region. It may continue in the next - * line. - */ + // We need to find the end of the region. It may continue in the next + // line. int end_idx = 0; lpos_T startpos = { .lnum = current_lnum, @@ -2492,10 +2312,8 @@ static void update_si_end(stateitem_T *sip, int startcol, bool force) } } -/* - * Add a new state to the current state stack. - * It is cleared and the index set to "idx". - */ +// Add a new state to the current state stack. +// It is cleared and the index set to "idx". static void push_current_state(int idx) { stateitem_T *p = GA_APPEND_VIA_PTR(stateitem_T, ¤t_state); @@ -2503,9 +2321,7 @@ static void push_current_state(int idx) p->si_idx = idx; } -/* - * Remove a state from the current_state stack. - */ +// Remove a state from the current_state stack. static void pop_current_state(void) { if (!GA_EMPTY(¤t_state)) { @@ -2556,20 +2372,16 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ return; } - /* - * Check for being called with a START pattern. - * Can happen with a match that continues to the next line, because it - * contained a region. - */ + // 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]); if (spp->sp_type != SPTYPE_START) { *hl_endpos = *startpos; return; } - /* - * Find the SKIP or first END pattern after the last START pattern. - */ + // Find the SKIP or first END pattern after the last START pattern. for (;;) { spp = &(SYN_ITEMS(syn_block)[idx]); if (spp->sp_type != SPTYPE_START) { @@ -2578,9 +2390,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ idx++; } - /* - * Lookup the SKIP pattern (if present) - */ + // Lookup the SKIP pattern (if present) if (spp->sp_type == SPTYPE_SKIP) { spp_skip = spp; idx++; @@ -2600,9 +2410,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ save_chartab((char *)buf_chartab); for (;;) { - /* - * Find end pattern that matches first after "matchcol". - */ + // Find end pattern that matches first after "matchcol". best_idx = -1; for (idx = start_idx; idx < syn_block->b_syn_patterns.ga_len; idx++) { int lc_col = matchcol; @@ -2631,18 +2439,14 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ } } - /* - * If all end patterns have been tried, and there is no match, the - * item continues until end-of-line. - */ + // If all end patterns have been tried, and there is no match, the + // item continues until end-of-line. if (best_idx == -1) { break; } - /* - * If the skip pattern matches before the end pattern, - * continue searching after the skip pattern. - */ + // If the skip pattern matches before the end pattern, + // continue searching after the skip pattern. if (spp_skip != NULL) { int lc_col = matchcol - spp_skip->sp_offsets[SPO_LC_OFF]; @@ -2688,10 +2492,8 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ } } - /* - * Match from start pattern to end pattern. - * Correct for match and highlight offset of end pattern. - */ + // Match from start pattern to end pattern. + // Correct for match and highlight offset of end pattern. spp = &(SYN_ITEMS(syn_block)[best_idx]); syn_add_end_off(m_endpos, &best_regmatch, spp, SPO_ME_OFF, 1); // can't end before the start @@ -2708,9 +2510,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ // can't end after the match limit_pos(end_endpos, m_endpos); - /* - * If the end group is highlighted differently, adjust the pointers. - */ + // If the end group is highlighted differently, adjust the pointers. if (spp->sp_syn_match_id != spp->sp_syn.id && spp->sp_syn_match_id != 0) { *end_idx = best_idx; if (spp->sp_off_flags & (1 << (SPO_RE_OFF + SPO_COUNT))) { @@ -2755,9 +2555,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ re_extmatch_in = NULL; } -/* - * Limit "pos" not to be after "limit". - */ +// Limit "pos" not to be after "limit". static void limit_pos(lpos_T *pos, lpos_T *limit) { if (pos->lnum > limit->lnum) { @@ -2767,9 +2565,7 @@ static void limit_pos(lpos_T *pos, lpos_T *limit) } } -/* - * Limit "pos" not to be after "limit", unless pos->lnum is zero. - */ +// Limit "pos" not to be after "limit", unless pos->lnum is zero. static void limit_pos_zero(lpos_T *pos, lpos_T *limit) { if (pos->lnum == 0) { @@ -2875,10 +2671,8 @@ static char *syn_getcurline(void) return (char *)ml_get_buf(syn_buf, current_lnum, false); } -/* - * Call vim_regexec() to find a match with "rmp" in "syn_buf". - * Returns true when there is a match. - */ +// Call vim_regexec() to find a match with "rmp" in "syn_buf". +// Returns true when there is a match. static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T *st) { int timed_out = 0; @@ -3001,9 +2795,7 @@ static keyentry_T *match_keyword(char *keyword, hashtab_T *ht, stateitem_T *cur_ return NULL; } -/* - * Handle ":syntax conceal" command. - */ +// Handle ":syntax conceal" command. static void syn_cmd_conceal(exarg_T *eap, int syncing) { char_u *arg = (char_u *)eap->arg; @@ -3171,9 +2963,7 @@ static void syn_cmd_iskeyword(exarg_T *eap, int syncing) redraw_later(curwin, UPD_NOT_VALID); } -/* - * Clear all syntax info for one buffer. - */ +// Clear all syntax info for one buffer. void syntax_clear(synblock_T *block) { block->b_syn_error = false; // clear previous error @@ -3221,9 +3011,7 @@ void syntax_clear(synblock_T *block) running_syn_inc_tag = 0; } -/* - * Get rid of ownsyntax for window "wp". - */ +// Get rid of ownsyntax for window "wp". void reset_synblock(win_T *wp) { if (wp->w_s != &wp->w_buffer->b_s) { @@ -3233,9 +3021,7 @@ void reset_synblock(win_T *wp) } } -/* - * Clear syncing info for one buffer. - */ +// Clear syncing info for one buffer. static void syntax_sync_clear(void) { // free the syntax patterns @@ -3258,9 +3044,7 @@ static void syntax_sync_clear(void) syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. } -/* - * Remove one pattern from the buffer's pattern list. - */ +// Remove one pattern from the buffer's pattern list. static void syn_remove_pattern(synblock_T *block, int idx) { synpat_T *spp; @@ -3274,10 +3058,8 @@ static void syn_remove_pattern(synblock_T *block, int idx) block->b_syn_patterns.ga_len--; } -/* - * Clear and free one syntax pattern. When clearing all, must be called from - * last to first! - */ +// Clear and free one syntax pattern. When clearing all, must be called from +// last to first! static void syn_clear_pattern(synblock_T *block, int i) { xfree(SYN_ITEMS(block)[i].sp_pattern); @@ -3290,9 +3072,7 @@ static void syn_clear_pattern(synblock_T *block, int i) } } -/* - * Clear and free one syntax cluster. - */ +// Clear and free one syntax cluster. static void syn_clear_cluster(synblock_T *block, int i) { xfree(SYN_CLSTR(block)[i].scl_name); @@ -3312,20 +3092,16 @@ static void syn_cmd_clear(exarg_T *eap, int syncing) return; } - /* - * We have to disable this within ":syn include @group filename", - * because otherwise @group would get deleted. - * Only required for Vim 5.x syntax files, 6.0 ones don't contain ":syn - * clear". - */ + // We have to disable this within ":syn include @group filename", + // because otherwise @group would get deleted. + // Only required for Vim 5.x syntax files, 6.0 ones don't contain ":syn + // clear". if (curwin->w_s->b_syn_topgrp != 0) { return; } if (ends_excmd(*arg)) { - /* - * No argument: Clear all syntax items. - */ + // No argument: Clear all syntax items. if (syncing) { syntax_sync_clear(); } else { @@ -3336,9 +3112,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing) do_unlet(S_LEN("w:current_syntax"), true); } } else { - /* - * Clear the group IDs that are in the argument. - */ + // Clear the group IDs that are in the argument. while (!ends_excmd(*arg)) { arg_end = skiptowhite(arg); if (*arg == '@') { @@ -3370,9 +3144,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing) syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. } -/* - * Clear one syntax group for the current buffer. - */ +// Clear one syntax group for the current buffer. static void syn_clear_one(const int id, const bool syncing) { synpat_T *spp; @@ -3393,18 +3165,14 @@ static void syn_clear_one(const int id, const bool syncing) } } -/* - * Handle ":syntax on" command. - */ +// Handle ":syntax on" command. static void syn_cmd_on(exarg_T *eap, int syncing) { syn_cmd_onoff(eap, "syntax"); } -/* - * Handle ":syntax reset" command. - * It actually resets highlighting, not syntax. - */ +// Handle ":syntax reset" command. +// It actually resets highlighting, not syntax. static void syn_cmd_reset(exarg_T *eap, int syncing) { eap->nextcmd = check_nextcmd(eap->arg); @@ -3413,17 +3181,13 @@ static void syn_cmd_reset(exarg_T *eap, int syncing) } } -/* - * Handle ":syntax manual" command. - */ +// Handle ":syntax manual" command. static void syn_cmd_manual(exarg_T *eap, int syncing) { syn_cmd_onoff(eap, "manual"); } -/* - * Handle ":syntax off" command. - */ +// Handle ":syntax off" command. static void syn_cmd_off(exarg_T *eap, int syncing) { syn_cmd_onoff(eap, "nosyntax"); @@ -3503,9 +3267,7 @@ static void syn_cmd_list(exarg_T *eap, int syncing) msg_puts_title(_("\n--- Syntax items ---")); } if (ends_excmd(*arg)) { - /* - * No argument: List all group IDs and all syntax clusters. - */ + // No argument: List all group IDs and all syntax clusters. for (int id = 1; id <= highlight_num_groups() && !got_int; id++) { syn_list_one(id, syncing, false); } @@ -3513,9 +3275,7 @@ static void syn_cmd_list(exarg_T *eap, int syncing) syn_list_cluster(id); } } else { - /* - * List the group IDs and syntax clusters that are in the argument. - */ + // List the group IDs and syntax clusters that are in the argument. while (!ends_excmd(*arg) && !got_int) { arg_end = (char_u *)skiptowhite((char *)arg); if (*arg == '@') { @@ -3693,9 +3453,7 @@ static void syn_list_flags(struct name_list *nlist, int flags, int attr) } } -/* - * List one syntax cluster, for ":syntax" or "syntax list syntax_name". - */ +// List one syntax cluster, for ":syntax" or "syntax list syntax_name". static void syn_list_cluster(int id) { int endcol = 15; @@ -3939,9 +3697,7 @@ static void syn_clear_keyword(int id, hashtab_T *ht) hash_unlock(ht); } -/* - * Clear a whole keyword table. - */ +// Clear a whole keyword table. static void clear_keywtab(hashtab_T *ht) { hashitem_T *hi; @@ -4088,11 +3844,9 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i } for (;;) { - /* - * 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. - */ + // 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. if (strchr(first_letters, *arg) == NULL) { break; } @@ -4196,11 +3950,9 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i return arg; } -/* - * Adjustments to syntax item when declared in a ":syn include"'d file. - * Set the contained flag, and if the item is not already contained, add it - * to the specified top-level group, if any. - */ +// Adjustments to syntax item when declared in a ":syn include"'d file. +// Set the contained flag, and if the item is not already contained, add it +// to the specified top-level group, if any. static void syn_incl_toplevel(int id, int *flagsp) { if ((*flagsp & HL_CONTAINED) || curwin->w_s->b_syn_topgrp == 0) { @@ -4219,9 +3971,7 @@ static void syn_incl_toplevel(int id, int *flagsp) } } -/* - * Handle ":syntax include [@{group-name}] filename" command. - */ +// Handle ":syntax include [@{group-name}] filename" command. static void syn_cmd_include(exarg_T *eap, int syncing) { char *arg = eap->arg; @@ -4253,10 +4003,8 @@ static void syn_cmd_include(exarg_T *eap, int syncing) eap->arg = rest; } - /* - * Everything that's left, up to the next command, should be the - * filename to include. - */ + // Everything that's left, up to the next command, should be the + // filename to include. eap->argt |= (EX_XFILE | EX_NOSPC); separate_nextcmd(eap); if (*eap->arg == '<' || *eap->arg == '$' || path_is_absolute((char_u *)eap->arg)) { @@ -4272,10 +4020,8 @@ static void syn_cmd_include(exarg_T *eap, int syncing) } } - /* - * Save and restore the existing top-level grouplist id and ":syn - * include" tag around the actual inclusion. - */ + // Save and restore the existing top-level grouplist id and ":syn + // include" tag around the actual inclusion. if (running_syn_inc_tag >= MAX_SYN_INC_TAG) { emsg(_("E847: Too many syntax includes")); return; @@ -4293,9 +4039,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing) current_syn_inc_tag = prev_syn_inc_tag; } -/* - * Handle ":syntax keyword {group-name} [{option}] keyword .." command. - */ +// Handle ":syntax keyword {group-name} [{option}] keyword .." command. static void syn_cmd_keyword(exarg_T *eap, int syncing) { char *arg = eap->arg; @@ -4444,18 +4188,14 @@ static void syn_cmd_match(exarg_T *eap, int syncing) rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); if (rest != NULL) { // all arguments are valid - /* - * Check for trailing command and illegal trailing arguments. - */ + // Check for trailing command and illegal trailing arguments. eap->nextcmd = check_nextcmd(rest); if (!ends_excmd(*rest) || eap->skip) { rest = NULL; } else { if ((syn_id = syn_check_group(arg, (size_t)(group_name_end - arg))) != 0) { syn_incl_toplevel(syn_id, &syn_opt_arg.flags); - /* - * Store the pattern in the syn_items list - */ + // Store the pattern in the syn_items list synpat_T *spp = GA_APPEND_VIA_PTR(synpat_T, &curwin->w_s->b_syn_patterns); *spp = item; @@ -4488,9 +4228,7 @@ static void syn_cmd_match(exarg_T *eap, int syncing) } } - /* - * Something failed, free the allocated memory. - */ + // Something failed, free the allocated memory. vim_regfree(item.sp_prog); xfree(item.sp_pattern); xfree(syn_opt_arg.cont_list); @@ -4608,11 +4346,9 @@ static void syn_cmd_region(exarg_T *eap, int syncing) } rest = skipwhite(p); } else { - /* - * Allocate room for a syn_pattern, and link it in the list of - * syn_patterns for this item, at the start (because the list is - * used from end to start). - */ + // Allocate room for a syn_pattern, and link it in the list of + // syn_patterns for this item, at the start (because the list is + // used from end to start). ppp = xmalloc(sizeof(struct pat_ptr)); ppp->pp_next = pat_ptrs[item]; pat_ptrs[item] = ppp; @@ -4650,10 +4386,8 @@ static void syn_cmd_region(exarg_T *eap, int syncing) } if (rest != NULL) { - /* - * Check for trailing garbage or command. - * If OK, add the item. - */ + // Check for trailing garbage or command. + // If OK, add the item. eap->nextcmd = check_nextcmd(rest); if (!ends_excmd(*rest) || eap->skip) { rest = NULL; @@ -4661,9 +4395,7 @@ static void syn_cmd_region(exarg_T *eap, int syncing) ga_grow(&(curwin->w_s->b_syn_patterns), pat_count); if ((syn_id = syn_check_group(arg, (size_t)(group_name_end - arg))) != 0) { syn_incl_toplevel(syn_id, &syn_opt_arg.flags); - /* - * Store the start/skip/end in the syn_items list - */ + // Store the start/skip/end in the syn_items list int idx = curwin->w_s->b_syn_patterns.ga_len; for (item = ITEM_START; item <= ITEM_END; item++) { for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp->pp_next) { @@ -4704,9 +4436,7 @@ static void syn_cmd_region(exarg_T *eap, int syncing) } } - /* - * Free the allocated memory. - */ + // Free the allocated memory. for (item = ITEM_START; item <= ITEM_END; item++) { for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) { if (!success && ppp->pp_synp != NULL) { @@ -4750,9 +4480,7 @@ static void syn_combine_list(int16_t **const clstr1, int16_t **const clstr2, con const int16_t *g2; int16_t *clstr = NULL; - /* - * Handle degenerate cases. - */ + // Handle degenerate cases. if (*clstr2 == NULL) { return; } @@ -4788,13 +4516,9 @@ static void syn_combine_list(int16_t **const clstr1, int16_t **const clstr2, con g2 = *clstr2; int count = 0; - /* - * First, loop through the lists until one of them is empty. - */ + // First, loop through the lists until one of them is empty. while (*g1 && *g2) { - /* - * We always want to add from the first list. - */ + // We always want to add from the first list. if (*g1 < *g2) { if (round == 2) { clstr[count] = *g1; @@ -4803,10 +4527,8 @@ static void syn_combine_list(int16_t **const clstr1, int16_t **const clstr2, con g1++; continue; } - /* - * We only want to add from the second list if we're adding the - * lists. - */ + // We only want to add from the second list if we're adding the + // lists. if (list_op == CLUSTER_ADD) { if (round == 2) { clstr[count] = *g2; @@ -4819,11 +4541,9 @@ static void syn_combine_list(int16_t **const clstr1, int16_t **const clstr2, con g2++; } - /* - * Now add the leftovers from whichever list didn't get finished - * first. As before, we only want to add from the second list if - * we're adding the lists. - */ + // Now add the leftovers from whichever list didn't get finished + // first. As before, we only want to add from the second list if + // we're adding the lists. for (; *g1; g1++, count++) { if (round == 2) { clstr[count] = *g1; @@ -4838,10 +4558,8 @@ static void syn_combine_list(int16_t **const clstr1, int16_t **const clstr2, con } if (round == 1) { - /* - * If the group ended up empty, we don't need to allocate any - * space for it. - */ + // If the group ended up empty, we don't need to allocate any + // space for it. if (count == 0) { clstr = NULL; break; @@ -4851,9 +4569,7 @@ static void syn_combine_list(int16_t **const clstr1, int16_t **const clstr2, con } } - /* - * Finally, put the new list in place. - */ + // Finally, put the new list in place. xfree(*clstr1); xfree(*clstr2); *clstr1 = clstr; @@ -4909,9 +4625,7 @@ static int syn_check_cluster(char *pp, int len) /// @return 0 for failure. static int syn_add_cluster(char *name) { - /* - * First call for this growarray: init growing array. - */ + // First call for this growarray: init growing array. if (curwin->w_s->b_syn_clusters.ga_data == NULL) { curwin->w_s->b_syn_clusters.ga_itemsize = sizeof(syn_cluster_T); ga_set_growsize(&curwin->w_s->b_syn_clusters, 10); @@ -4941,10 +4655,8 @@ static int syn_add_cluster(char *name) return len + SYNID_CLUSTER; } -/* - * Handle ":syntax cluster {cluster-name} [contains={groupname},..] - * [add={groupname},..] [remove={groupname},..]". - */ +// Handle ":syntax cluster {cluster-name} [contains={groupname},..] +// [add={groupname},..] [remove={groupname},..]". static void syn_cmd_cluster(exarg_T *eap, int syncing) { char *arg = eap->arg; @@ -5013,9 +4725,7 @@ static void syn_cmd_cluster(exarg_T *eap, int syncing) } } -/* - * On first call for current buffer: Init growing array. - */ +// On first call for current buffer: Init growing array. static void init_syn_patterns(void) { curwin->w_s->b_syn_patterns.ga_itemsize = sizeof(synpat_T); @@ -5058,9 +4768,7 @@ static char *get_syn_pattern(char *arg, synpat_T *ci) ci->sp_ic = curwin->w_s->b_syn_ic; syn_clear_time(&ci->sp_time); - /* - * Check for a match, highlight or region offset. - */ + // Check for a match, highlight or region offset. end++; do { for (idx = SPO_COUNT; --idx >= 0;) { @@ -5324,9 +5032,7 @@ static int get_id_list(char **const arg, const int keylen, int16_t **const list, id = syn_check_cluster(name + 2, (int)(end - p - 1)); } } else { - /* - * Handle full group name. - */ + // Handle full group name. if (strpbrk(name + 1, "\\.*^$~[") == NULL) { id = syn_check_group((name + 1), (size_t)(end - p)); } else { @@ -5411,9 +5117,7 @@ static int get_id_list(char **const arg, const int keylen, int16_t **const list, return OK; } -/* - * Make a copy of an ID list. - */ +// Make a copy of an ID list. static int16_t *copy_id_list(const int16_t *const list) { if (list == NULL) { @@ -5470,10 +5174,8 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in return false; } - /* - * If list is ID_LIST_ALL, we are in a transparent item that isn't - * inside anything. Only allow not-contained groups. - */ + // If list is ID_LIST_ALL, we are in a transparent item that isn't + // inside anything. Only allow not-contained groups. if (list == ID_LIST_ALL) { return !contained; } @@ -5505,9 +5207,7 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in retval = true; } - /* - * Return "retval" if id is in the contains list. - */ + // Return "retval" if id is in the contains list. while (item != 0) { if (item == id) { return retval; @@ -5651,19 +5351,15 @@ static enum { EXP_CLUSTER, // expand ":syn list @cluster" arguments } expand_what; -/* - * Reset include_link, include_default, include_none to 0. - * Called when we are done expanding. - */ +// Reset include_link, include_default, include_none to 0. +// Called when we are done expanding. void reset_expand_highlight(void) { include_link = include_default = include_none = 0; } -/* - * Handle command line completion for :match and :echohl command: Add "None" - * as highlight group. - */ +// Handle command line completion for :match and :echohl command: Add "None" +// as highlight group. void set_context_in_echohl_cmd(expand_T *xp, const char *arg) { xp->xp_context = EXPAND_HIGHLIGHT; @@ -5671,9 +5367,7 @@ void set_context_in_echohl_cmd(expand_T *xp, const char *arg) include_none = 1; } -/* - * Handle command line completion for :syntax command. - */ +// Handle command line completion for :syntax command. void set_context_in_syntax_cmd(expand_T *xp, const char *arg) { // Default: expand subcommands. @@ -5714,10 +5408,8 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg) } } -/* - * Function given to ExpandGeneric() to obtain the list syntax names for - * expansion. - */ +// Function given to ExpandGeneric() to obtain the list syntax names for +// expansion. char *get_syntax_name(expand_T *xp, int idx) { switch (expand_what) { @@ -5773,12 +5465,10 @@ int syn_get_id(win_T *wp, linenr_T lnum, colnr_T col, int trans, bool *spellp, i return trans ? current_trans_id : current_id; } -/* - * Get extra information about the syntax item. Must be called right after - * get_syntax_attr(). - * Stores the current item sequence nr in "*seqnrp". - * Returns the current flags. - */ +// Get extra information about the syntax item. Must be called right after +// get_syntax_attr(). +// Stores the current item sequence nr in "*seqnrp". +// Returns the current flags. int get_syntax_info(int *seqnrp) { *seqnrp = current_seqnr; @@ -5802,19 +5492,15 @@ int syn_get_concealed_id(win_T *wp, linenr_T lnum, colnr_T col) return 0; } -/* - * Return conceal substitution character - */ +// Return conceal substitution character int syn_get_sub_char(void) { return current_sub_char; } -/* - * Return the syntax ID at position "i" in the current stack. - * The caller must have called syn_get_id() before to fill the stack. - * Returns -1 when "i" is out of range. - */ +// Return the syntax ID at position "i" in the current stack. +// The caller must have called syn_get_id() before to fill the stack. +// Returns -1 when "i" is out of range. int syn_get_stack_item(int i) { if (i >= current_state.ga_len) { @@ -5877,9 +5563,7 @@ int syn_get_foldlevel(win_T *wp, linenr_T lnum) return level; } -/* - * ":syntime". - */ +// ":syntime". void ex_syntime(exarg_T *eap) { if (STRCMP(eap->arg, "on") == 0) { @@ -5903,9 +5587,7 @@ static void syn_clear_time(syn_time_T *st) st->match = 0; } -/* - * Clear the syntax timing for the current buffer. - */ +// Clear the syntax timing for the current buffer. static void syntime_clear(void) { synpat_T *spp; @@ -5920,10 +5602,8 @@ static void syntime_clear(void) } } -/* - * Function given to ExpandGeneric() to obtain the possible arguments of the - * ":syntime {on,off,clear,report}" command. - */ +// Function given to ExpandGeneric() to obtain the possible arguments of the +// ":syntime {on,off,clear,report}" command. char *get_syntime_arg(expand_T *xp, int idx) { switch (idx) { @@ -5947,9 +5627,7 @@ static int syn_compare_syntime(const void *v1, const void *v2) return profile_cmp(s1->total, s2->total); } -/* - * Clear the syntax timing for the current buffer. - */ +// Clear the syntax timing for the current buffer. static void syntime_report(void) { if (!syntax_present(curwin)) { diff --git a/src/nvim/tag.c b/src/nvim/tag.c index d1d5514648..04154384af 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -1,9 +1,7 @@ // 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 -/* - * Code to handle tags and the tag stack - */ +// Code to handle tags and the tag stack #include #include @@ -51,9 +49,7 @@ #include "nvim/vim.h" #include "nvim/window.h" -/* - * Structure to hold pointers to various items in a tag line. - */ +// Structure to hold pointers to various items in a tag line. typedef struct tag_pointers { // filled in by parse_tag_line(): char_u *tagname; // start of tag name (skip "file:") @@ -73,9 +69,7 @@ typedef struct tag_pointers { linenr_T tagline; // "line:" value } tagptrs_T; -/* - * Structure to hold info about the tag pattern being used. - */ +// Structure to hold info about the tag pattern being used. typedef struct { char_u *pat; // the pattern int len; // length of pat[] @@ -117,10 +111,8 @@ static char_u *tfu_inv_ret_msg static char_u *tagmatchname = NULL; // name of last used tag -/* - * Tag for preview window is remembered separately, to avoid messing up the - * normal tagstack. - */ +// Tag for preview window is remembered separately, to avoid messing up the +// normal tagstack. static taggy_T ptag_entry = { NULL, INIT_FMARK, 0, 0, NULL }; static int tfu_in_use = false; // disallow recursive call of tagfunc @@ -243,10 +235,8 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) ptag_entry.tagname = (char *)vim_strsave(tag); } } else { - /* - * If the last used entry is not at the top, delete all tag - * stack entries above it. - */ + // If the last used entry is not at the top, delete all tag + // stack entries above it. while (tagstackidx < tagstacklen) { tagstack_clear_entry(&tagstack[--tagstacklen]); } @@ -300,10 +290,8 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) // tagstack before it's used. saved_fmark = tagstack[tagstackidx].fmark; if (saved_fmark.fnum != curbuf->b_fnum) { - /* - * Jump to other file. If this fails (e.g. because the - * file was changed) keep original position in tag stack. - */ + // Jump to other file. If this fails (e.g. because the + // file was changed) keep original position in tag stack. if (buflist_getfile(saved_fmark.fnum, saved_fmark.mark.lnum, GETF_SETMARK, forceit) == FAIL) { tagstackidx = oldtagstackidx; // back to old posn @@ -340,11 +328,9 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) // ":tag" (no argument): go to newer pattern save_pos = true; // save the cursor position below if ((tagstackidx += count - 1) >= tagstacklen) { - /* - * Beyond the last one, just give an error message and - * go to the last one. Don't store the cursor - * position. - */ + // Beyond the last one, just give an error message and + // go to the last one. Don't store the cursor + // position. tagstackidx = tagstacklen - 1; emsg(_(topmsg)); save_pos = false; @@ -401,9 +387,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) ptag_entry.cur_fnum = cur_fnum; } } else { - /* - * For ":tag [arg]" or ":tselect" remember position before the jump. - */ + // For ":tag [arg]" or ":tselect" remember position before the jump. saved_fmark = tagstack[tagstackidx].fmark; if (save_pos) { tagstack[tagstackidx].fmark.mark = curwin->w_cursor; @@ -432,9 +416,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) } } - /* - * Repeat searching for tags, when a file has not been found. - */ + // Repeat searching for tags, when a file has not been found. for (;;) { int other_name; char_u *name; @@ -598,10 +580,8 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) ptag_entry.cur_fnum = cur_fnum; } - /* - * Only when going to try the next match, report that the previous - * file didn't exist. Otherwise an emsg() is given below. - */ + // Only when going to try the next match, report that the previous + // file didn't exist. Otherwise an emsg() is given below. if (nofile_fname != NULL && error_cur_match != cur_match) { smsg(_("File \"%s\" does not exist"), nofile_fname); } @@ -640,9 +620,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) vim_snprintf((char *)IObuff, IOSIZE, ":ta %s\r", name); set_vim_var_string(VV_SWAPCOMMAND, (char *)IObuff, -1); - /* - * Jump to the desired match. - */ + // Jump to the desired match. i = jumpto_tag((char_u *)matches[cur_match], forceit, type != DT_CSCOPE); set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); @@ -1005,9 +983,7 @@ static int add_llist_tags(char_u *tag, int num_matches, char **matches) return OK; } -/* - * Free cached tags. - */ +// Free cached tags. void tag_freematch(void) { XFREE_CLEAR(tagmatchname); @@ -1023,9 +999,7 @@ static void taglen_advance(int l) } } -/* - * Print the tag stack - */ +// Print the tag stack void do_tags(exarg_T *eap) { int i; @@ -1061,11 +1035,9 @@ void do_tags(exarg_T *eap) } } -/* - * Compare two strings, for length "len", ignoring case the ASCII way. - * return 0 for match, < 0 for smaller, > 0 for bigger - * Make sure case is folded to uppercase in comparison (like for 'sort -f') - */ +// Compare two strings, for length "len", ignoring case the ASCII way. +// return 0 for match, < 0 for smaller, > 0 for bigger +// Make sure case is folded to uppercase in comparison (like for 'sort -f') static int tag_strnicmp(char_u *s1, char_u *s2, size_t len) { int i; @@ -1085,9 +1057,7 @@ static int tag_strnicmp(char_u *s1, char_u *s2, size_t len) return 0; // strings match } -/* - * Extract info from the tag search pattern "pats->pat". - */ +// Extract info from the tag search pattern "pats->pat". static void prepare_pats(pat_T *pats, int has_re) { pats->head = pats->pat; @@ -1472,9 +1442,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc orgpat.regmatch.regprog = NULL; vimconv.vc_type = CONV_NONE; - /* - * Allocate memory for the buffers that are used - */ + // Allocate memory for the buffers that are used lbuf = xmalloc((size_t)lbuf_size); tag_fname = xmalloc(MAXPATHL + 1); for (mtt = 0; mtt < MT_COUNT; mtt++) { @@ -1484,9 +1452,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc STRCPY(tag_fname, "from cscope"); // for error messages - /* - * Initialize a few variables - */ + // Initialize a few variables if (help_only) { // want tags from help file curbuf->b_help = true; // will be restored later } else if (use_cscope) { @@ -1534,16 +1500,15 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc } } - /* - * When finding a specified number of matches, first try with matching - * case, so binary search can be used, and try ignore-case matches in a - * second loop. - * When finding all matches, 'tagbsearch' is off, or there is no fixed - * string to look for, ignore case right away to avoid going though the - * tags files twice. - * When the tag file is case-fold sorted, it is either one or the other. - * Only ignore case when TAG_NOIC not used or 'ignorecase' set. - */ + // When finding a specified number of matches, first try with matching + // case, so binary search can be used, and try ignore-case matches in a + // second loop. + // When finding all matches, 'tagbsearch' is off, or there is no fixed + // string to look for, ignore case right away to avoid going though the + // tags files twice. + // When the tag file is case-fold sorted, it is either one or the other. + // Only ignore case when TAG_NOIC not used or 'ignorecase' set. + // Set a flag if the file extension is .txt if ((flags & TAG_KEEP_LANG) && help_lang_find == NULL @@ -1634,9 +1599,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc state = TS_START; // we're at the start of the file - /* - * Read and parse the lines in the file one by one - */ + // Read and parse the lines in the file one by one for (;;) { // check for CTRL-C typed, more often when jumping around if (state == TS_BINARY || state == TS_SKIP_BACK) { @@ -1661,9 +1624,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc if (get_it_again) { goto line_read_in; } - /* - * For binary search: compute the next offset to use. - */ + // For binary search: compute the next offset to use. if (state == TS_BINARY) { offset = search_info.low_offset + ((search_info.high_offset - search_info.low_offset) / 2); @@ -1682,10 +1643,8 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc } } - /* - * When jumping around in the file, first read a line to find the - * start of the next line. - */ + // When jumping around in the file, first read a line to find the + // start of the next line. if (state == TS_BINARY || state == TS_SKIP_BACK) { // Adjust the search file offset to the correct position search_info.curr_offset_used = search_info.curr_offset; @@ -1714,11 +1673,9 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc search_info.curr_offset = search_info.curr_offset_used; continue; } - } - /* - * Not jumping around in the file: Read the next line. - */ - else { + } else { + // Not jumping around in the file: Read the next line. + // skip empty and blank lines do { eof = use_cscope @@ -1754,10 +1711,8 @@ line_read_in: } } - /* - * When still at the start of the file, check for Emacs tags file - * format, and for "not sorted" flag. - */ + // When still at the start of the file, check for Emacs tags file + // format, and for "not sorted" flag. if (state == TS_START) { // The header ends when the line sorts below "!_TAG_". When // case is folded lower case letters sort before "_". @@ -1768,9 +1723,7 @@ line_read_in: goto parse_line; } - /* - * Read header line. - */ + // Read header line. if (STRNCMP(lbuf, "!_TAG_FILE_SORTED\t", 18) == 0) { tag_file_sorted = lbuf[18]; } @@ -1788,15 +1741,13 @@ line_read_in: // Headers ends. - /* - * When there is no tag head, or ignoring case, need to do a - * linear search. - * When no "!_TAG_" is found, default to binary search. If - * the tag file isn't sorted, the second loop will find it. - * When "!_TAG_FILE_SORTED" found: start binary search if - * flag set. - * For cscope, it's always linear. - */ + // When there is no tag head, or ignoring case, need to do a + // linear search. + // When no "!_TAG_" is found, default to binary search. If + // the tag file isn't sorted, the second loop will find it. + // When "!_TAG_FILE_SORTED" found: start binary search if + // flag set. + // For cscope, it's always linear. if (linear || use_cscope) { state = TS_LINEAR; } else if (tag_file_sorted == NUL) { @@ -1871,10 +1822,8 @@ parse_line: break; } - /* - * Skip this line if the length of the tag is different and - * there is no regexp, or the tag is too short. - */ + // Skip this line if the length of the tag is different and + // there is no regexp, or the tag is too short. cmplen = (int)(tagp.tagname_end - tagp.tagname); if (p_tl != 0 && cmplen > p_tl) { // adjust for 'taglength' cmplen = (int)p_tl; @@ -1886,9 +1835,7 @@ parse_line: } if (state == TS_BINARY) { - /* - * Simplistic check for unsorted tags file. - */ + // Simplistic check for unsorted tags file. i = (int)tagp.tagname[0]; if (sortic) { i = TOUPPER_ASC(tagp.tagname[0]); @@ -1897,9 +1844,7 @@ parse_line: sort_error = true; } - /* - * Compare the current tag with the searched tag. - */ + // Compare the current tag with the searched tag. if (sortic) { tagcmp = tag_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen); @@ -1907,10 +1852,8 @@ parse_line: tagcmp = STRNCMP(tagp.tagname, orgpat.head, cmplen); } - /* - * A match with a shorter tag means to search forward. - * A match with a longer tag means to search backward. - */ + // A match with a shorter tag means to search forward. + // A match with a longer tag means to search backward. if (tagcmp == 0) { if (cmplen < orgpat.headlen) { tagcmp = -1; @@ -1998,10 +1941,8 @@ parse_line: break; } - /* - * First try matching with the pattern literally (also when it is - * a regexp). - */ + // First try matching with the pattern literally (also when it is + // a regexp). cmplen = (int)(tagp.tagname_end - tagp.tagname); if (p_tl != 0 && cmplen > p_tl) { // adjust for 'taglength' cmplen = (int)p_tl; @@ -2022,9 +1963,7 @@ parse_line: } } - /* - * Has a regexp: Also find tags matching regexp. - */ + // Has a regexp: Also find tags matching regexp. match_re = false; if (!match && orgpat.regmatch.regprog != NULL) { int cc; @@ -2211,9 +2150,7 @@ parse_line: sort_error = false; } - /* - * Stop searching if sufficient tags have been found. - */ + // Stop searching if sufficient tags have been found. if (match_count >= mincount) { retval = OK; stop_searching = true; @@ -2251,10 +2188,8 @@ findtag_end: vim_regfree(orgpat.regmatch.regprog); xfree(tag_fname); - /* - * Move the matches from the ga_match[] arrays into one list of - * matches. When retval == FAIL, free the matches. - */ + // Move the matches from the ga_match[] arrays into one list of + // matches. When retval == FAIL, free the matches. if (retval == FAIL) { match_count = 0; } @@ -2303,10 +2238,8 @@ findtag_end: static garray_T tag_fnames = GA_EMPTY_INIT_VALUE; -/* - * Callback function for finding all "tags" and "tags-??" files in - * 'runtimepath' doc directories. - */ +// Callback function for finding all "tags" and "tags-??" files in +// 'runtimepath' doc directories. static void found_tagfile_cb(char *fname, void *cookie) { char_u *const tag_fname = vim_strsave((char_u *)fname); @@ -2348,11 +2281,9 @@ int get_tagfname(tagname_T *tnp, int first, char *buf) } if (curbuf->b_help) { - /* - * For help files it's done in a completely different way: - * Find "doc/tags" and "doc/tags-??" in all directories in - * 'runtimepath'. - */ + // For help files it's done in a completely different way: + // Find "doc/tags" and "doc/tags-??" in all directories in + // 'runtimepath'. if (first) { ga_clear_strings(&tag_fnames); ga_init(&tag_fnames, (int)sizeof(char *), 10); @@ -2392,12 +2323,10 @@ int get_tagfname(tagname_T *tnp, int first, char *buf) tnp->tn_np = (char *)tnp->tn_tags; } - /* - * Loop until we have found a file name that can be used. - * There are two states: - * tnp->tn_did_filefind_init == false: setup for next part in 'tags'. - * tnp->tn_did_filefind_init == true: find next file in this part. - */ + // Loop until we have found a file name that can be used. + // There are two states: + // tnp->tn_did_filefind_init == false: setup for next part in 'tags'. + // tnp->tn_did_filefind_init == true: find next file in this part. for (;;) { if (tnp->tn_did_filefind_init) { fname = (char *)vim_findfile(tnp->tn_search_ctx); @@ -2416,9 +2345,7 @@ int get_tagfname(tagname_T *tnp, int first, char *buf) return FAIL; } - /* - * Copy next file name into buf. - */ + // Copy next file name into buf. buf[0] = NUL; (void)copy_option_part(&tnp->tn_np, buf, MAXPATHL - 1, " ,"); @@ -2445,9 +2372,7 @@ int get_tagfname(tagname_T *tnp, int first, char *buf) return OK; } -/* - * Free the contents of a tagname_T that was filled by get_tagfname(). - */ +// Free the contents of a tagname_T that was filled by get_tagfname(). void tagname_free(tagname_T *tnp) { xfree(tnp->tn_tags); @@ -2499,20 +2424,18 @@ static int parse_tag_line(char_u *lbuf, tagptrs_T *tagp) return OK; } -/* - * Check if tagname is a static tag - * - * Static tags produced by the older ctags program have the format: - * 'file:tag file /pattern'. - * This is only recognized when both occurrence of 'file' are the same, to - * avoid recognizing "string::string" or ":exit". - * - * Static tags produced by the new ctags program have the format: - * 'tag file /pattern/;"file:' " - * - * Return true if it is a static tag and adjust *tagname to the real tag. - * Return false if it is not a static tag. - */ +// Check if tagname is a static tag +// +// Static tags produced by the older ctags program have the format: +// 'file:tag file /pattern'. +// This is only recognized when both occurrence of 'file' are the same, to +// avoid recognizing "string::string" or ":exit". +// +// Static tags produced by the new ctags program have the format: +// 'tag file /pattern/;"file:' " +// +// Return true if it is a static tag and adjust *tagname to the real tag. +// Return false if it is not a static tag. static bool test_for_static(tagptrs_T *tagp) { char_u *p; @@ -2620,11 +2543,9 @@ static int parse_match(char *lbuf, tagptrs_T *tagp) return retval; } -/* - * Find out the actual file name of a tag. Concatenate the tags file name - * with the matching tag file name. - * Returns an allocated string. - */ +// Find out the actual file name of a tag. Concatenate the tags file name +// with the matching tag file name. +// Returns an allocated string. static char_u *tag_full_fname(tagptrs_T *tagp) { int c = *tagp->fname_end; @@ -2688,9 +2609,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) *pbuf_end = NUL; { - /* - * Remove the "fieldname:value" stuff; we don't need it here. - */ + // Remove the "fieldname:value" stuff; we don't need it here. str = pbuf; if (find_extra(&str) == OK) { pbuf_end = str; @@ -2698,18 +2617,14 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) } } - /* - * Expand file name, when needed (for environment variables). - * If 'tagrelative' option set, may change file name. - */ + // Expand file name, when needed (for environment variables). + // If 'tagrelative' option set, may change file name. fname = expand_tag_fname(fname, tagp.tag_fname, true); tofree_fname = fname; // free() it later - /* - * Check if the file with the tag exists before abandoning the current - * file. Also accept a file name for which there is a matching BufReadCmd - * autocommand event (e.g., http://sys/file). - */ + // Check if the file with the tag exists before abandoning the current + // file. Also accept a file name for which there is a matching BufReadCmd + // autocommand event (e.g., http://sys/file). if (!os_path_exists((char *)fname) && !has_autocmd(EVENT_BUFREADCMD, (char *)fname, NULL)) { @@ -2725,19 +2640,15 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) postponed_split = 0; // don't split again below curwin_save = curwin; // Save current window - /* - * If we are reusing a window, we may change dir when - * entering it (autocommands) so turn the tag filename - * into a fullpath - */ + // If we are reusing a window, we may change dir when + // entering it (autocommands) so turn the tag filename + // into a fullpath if (!curwin->w_p_pvw) { full_fname = (char_u *)FullName_save((char *)fname, false); fname = full_fname; - /* - * Make the preview window the current window. - * Open a preview window when needed. - */ + // Make the preview window the current window. + // Open a preview window when needed. prepare_tagpreview(true); } } @@ -2803,25 +2714,21 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) // Save value of no_hlsearch, jumping to a tag is not a real search const bool save_no_hlsearch = no_hlsearch; - /* - * If 'cpoptions' contains 't', store the search pattern for the "n" - * command. If 'cpoptions' does not contain 't', the search pattern - * is not stored. - */ + // If 'cpoptions' contains 't', store the search pattern for the "n" + // command. If 'cpoptions' does not contain 't', the search pattern + // is not stored. if (vim_strchr(p_cpo, CPO_TAGPAT) != NULL) { search_options = 0; } else { search_options = SEARCH_KEEP; } - /* - * If the command is a search, try here. - * - * Reset 'smartcase' for the search, since the search pattern was not - * typed by the user. - * Only use do_search() when there is a full search command, without - * anything following. - */ + // If the command is a search, try here. + // + // Reset 'smartcase' for the search, since the search pattern was not + // typed by the user. + // Only use do_search() when there is a full search command, without + // anything following. str = pbuf; if (pbuf[0] == '/' || pbuf[0] == '?') { str = (char_u *)skip_regexp((char *)pbuf + 1, pbuf[0], false, NULL) + 1; @@ -2848,9 +2755,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) int found = 1; int cc; - /* - * try again, ignore case now - */ + // try again, ignore case now p_ic = true; if (!do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, (long)1, search_options, NULL)) { @@ -2875,10 +2780,8 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) emsg(_("E434: Can't find tag pattern")); curwin->w_cursor.lnum = save_lnum; } else { - /* - * Only give a message when really guessed, not when 'ic' - * is set and match found while ignoring case. - */ + // Only give a message when really guessed, not when 'ic' + // is set and match found while ignoring case. if (found == 2 || !save_p_ic) { msg(_("E435: Couldn't find tag, just guessing!")); if (!msg_scrolled && msg_silent == 0) { @@ -2927,10 +2830,8 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) } if (retval == OK) { - /* - * For a help buffer: Put the cursor line at the top of the window, - * the help subject will be below it. - */ + // For a help buffer: Put the cursor line at the top of the window, + // the help subject will be below it. if (curbuf->b_help) { set_topline(curwin, curwin->w_cursor.lnum); } @@ -2976,9 +2877,7 @@ static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, const bo char_u *expanded_fname = NULL; expand_T xpc; - /* - * Expand file name (for environment variables) when needed. - */ + // Expand file name (for environment variables) when needed. if (expand && path_has_wildcard((char *)fname)) { ExpandInit(&xpc); xpc.xp_context = EXPAND_FILES; @@ -2997,9 +2896,7 @@ static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, const bo STRCPY(retval, tag_fname); STRLCPY(retval + (p - tag_fname), fname, MAXPATHL - (p - tag_fname)); - /* - * Translate names like "src/a/../b/file.c" into "src/b/file.c". - */ + // Translate names like "src/a/../b/file.c" into "src/b/file.c". simplify_filename(retval); } else { retval = vim_strsave(fname); @@ -3034,10 +2931,8 @@ static int test_for_current(char *fname, char *fname_end, char *tag_fname, char return retval; } -/* - * Find the end of the tagaddress. - * Return OK if ";\"" is following, FAIL otherwise. - */ +// Find the end of the tagaddress. +// Return OK if ";\"" is following, FAIL otherwise. static int find_extra(char_u **pp) { char_u *str = *pp; diff --git a/src/nvim/window.c b/src/nvim/window.c index 6ee3820d95..530cbc0c7b 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -970,21 +970,19 @@ static int check_split_disallowed(void) return OK; } -/* - * split the current window, implements CTRL-W s and :split - * - * "size" is the height or width for the new window, 0 to use half of current - * height or width. - * - * "flags": - * WSP_ROOM: require enough room for new window - * WSP_VERT: vertical split. - * WSP_TOP: open window at the top-left of the screen (help window). - * WSP_BOT: open window at the bottom-right of the screen (quickfix window). - * WSP_HELP: creating the help window, keep layout snapshot - * - * return FAIL for failure, OK otherwise - */ +// split the current window, implements CTRL-W s and :split +// +// "size" is the height or width for the new window, 0 to use half of current +// height or width. +// +// "flags": +// WSP_ROOM: require enough room for new window +// WSP_VERT: vertical split. +// WSP_TOP: open window at the top-left of the screen (help window). +// WSP_BOT: open window at the bottom-right of the screen (quickfix window). +// WSP_HELP: creating the help window, keep layout snapshot +// +// return FAIL for failure, OK otherwise int win_split(int size, int flags) { if (check_split_disallowed() == FAIL) { @@ -1014,12 +1012,10 @@ int win_split(int size, int flags) return win_split_ins(size, flags, NULL, 0); } -/* - * When "new_wp" is NULL: split the current window in two. - * When "new_wp" is not NULL: insert this window at the far - * top/left/right/bottom. - * return FAIL for failure, OK otherwise - */ +// When "new_wp" is NULL: split the current window in two. +// When "new_wp" is not NULL: insert this window at the far +// top/left/right/bottom. +// return FAIL for failure, OK otherwise int win_split_ins(int size, int flags, win_T *new_wp, int dir) { win_T *wp = new_wp; @@ -1069,10 +1065,8 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) layout = FR_ROW; - /* - * Check if we are able to split the current window and compute its - * width. - */ + // Check if we are able to split the current window and compute its + // width. // Current window requires at least 1 space. wmw1 = (p_wmw == 0 ? 1 : (int)p_wmw); needed = wmw1 + 1; @@ -1243,9 +1237,7 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) } } - /* - * allocate new window structure and link it in the window list - */ + // allocate new window structure and link it in the window list if ((flags & WSP_TOP) == 0 && ((flags & WSP_BOT) || (flags & WSP_BELOW) @@ -1282,9 +1274,7 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) CLEAR_FIELD(wp->w_border_adj); } - /* - * Reorganise the tree of frames to insert the new window. - */ + // Reorganise the tree of frames to insert the new window. if (flags & (WSP_TOP | WSP_BOT)) { if ((topframe->fr_layout == FR_COL && (flags & WSP_VERT) == 0) || (topframe->fr_layout == FR_ROW && (flags & WSP_VERT) != 0)) { @@ -1489,9 +1479,7 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) msg_col = 0; // put position back at start of line } - /* - * equalize the window sizes. - */ + // equalize the window sizes. if (do_equal || dir != 0) { win_equal(wp, true, (flags & WSP_VERT) ? (dir == 'v' ? 'b' : 'h') : (dir == 'h' ? 'b' : 'v')); } @@ -1527,13 +1515,11 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) return OK; } -/* - * Initialize window "newp" from window "oldp". - * Used when splitting a window and when creating a new tab page. - * The windows will both edit the same buffer. - * WSP_NEWLOC may be specified in flags to prevent the location list from - * being copied. - */ +// Initialize window "newp" from window "oldp". +// Used when splitting a window and when creating a new tab page. +// The windows will both edit the same buffer. +// WSP_NEWLOC may be specified in flags to prevent the location list from +// being copied. static void win_init(win_T *newp, win_T *oldp, int flags) { int i; @@ -1591,10 +1577,8 @@ static void win_init(win_T *newp, win_T *oldp, int flags) newp->w_winbar_height = oldp->w_winbar_height; } -/* - * Initialize window "newp" from window "old". - * Only the essential things are copied. - */ +// Initialize window "newp" from window "old". +// Only the essential things are copied. static void win_init_some(win_T *newp, win_T *oldp) { // Use the same argument list. @@ -1671,9 +1655,7 @@ bool win_valid_any_tab(win_T *win) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT return false; } -/* - * Return the number of windows. - */ +// Return the number of windows. int win_count(void) { int count = 0; @@ -1746,9 +1728,7 @@ int make_windows(int count, bool vertical) return count - todo; } -/* - * Exchange current and next window - */ +// Exchange current and next window static void win_exchange(long Prenum) { frame_T *frp; @@ -1768,9 +1748,7 @@ static void win_exchange(long Prenum) return; } - /* - * find window to exchange with - */ + // find window to exchange with if (Prenum) { frp = curwin->w_frame->fr_parent->fr_child; while (frp != NULL && --Prenum > 0) { @@ -1789,14 +1767,12 @@ static void win_exchange(long Prenum) } wp = frp->fr_win; - /* - * 1. remove curwin from the list. Remember after which window it was in wp2 - * 2. insert curwin before wp in the list - * if wp != wp2 - * 3. remove wp from the list - * 4. insert wp after wp2 - * 5. exchange the status line height, winbar height, hsep height and vsep width. - */ + // 1. remove curwin from the list. Remember after which window it was in wp2 + // 2. insert curwin before wp in the list + // if wp != wp2 + // 3. remove wp from the list + // 4. insert wp after wp2 + // 5. exchange the status line height, winbar height, hsep height and vsep width. wp2 = curwin->w_prev; frp2 = curwin->w_frame->fr_prev; if (wp->w_prev != curwin) { @@ -1927,9 +1903,7 @@ static void win_rotate(bool upwards, int count) redraw_all_later(UPD_NOT_VALID); } -/* - * Move the current window to the very top/bottom/left/right of the screen. - */ +// Move the current window to the very top/bottom/left/right of the screen. static void win_totop(int size, int flags) { int dir = 0; @@ -1973,10 +1947,8 @@ static void win_totop(int size, int flags) } } -/* - * Move window "win1" to below/right of "win2" and make "win1" the current - * window. Only works within the same frame! - */ +// Move window "win1" to below/right of "win2" and make "win1" the current +// window. Only works within the same frame! void win_move_after(win_T *win1, win_T *win2) { int height; @@ -2146,11 +2118,9 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int totwincount = (n + extra_sep) / ((int)p_wmw + 1); has_next_curwin = frame_has_win(topfr, next_curwin); - /* - * Compute width for "next_curwin" window and room available for - * other windows. - * "m" is the minimal width when counting p_wiw for "next_curwin". - */ + // Compute width for "next_curwin" window and room available for + // other windows. + // "m" is the minimal width when counting p_wiw for "next_curwin". m = frame_minwidth(topfr, next_curwin); room = width - m; if (room < 0) { @@ -2274,11 +2244,9 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int totwincount = get_maximum_wincount(topfr, n + extra_sep); has_next_curwin = frame_has_win(topfr, next_curwin); - /* - * Compute height for "next_curwin" window and room available for - * other windows. - * "m" is the minimal height when counting p_wh for "next_curwin". - */ + // Compute height for "next_curwin" window and room available for + // other windows. + // "m" is the minimal height when counting p_wh for "next_curwin". m = frame_minheight(topfr, next_curwin); room = height - m; if (room < 0) { @@ -2594,14 +2562,12 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf, tabpage_T *prev free_buf = false; } - /* - * Closing the last window in a tab page. First go to another tab - * page and then close the window and the tab page. This avoids that - * curwin and curtab are invalid while we are freeing memory, they may - * be used in GUI events. - * Don't trigger autocommands yet, they may use wrong values, so do - * that below. - */ + // Closing the last window in a tab page. First go to another tab + // page and then close the window and the tab page. This avoids that + // curwin and curtab are invalid while we are freeing memory, they may + // be used in GUI events. + // Don't trigger autocommands yet, they may use wrong values, so do + // that below. goto_tabpage_tp(alt_tabpage(), false, true); redraw_tabline = true; @@ -2745,10 +2711,8 @@ int win_close(win_T *win, bool free_buf, bool force) } } - /* - * Be careful: If autocommands delete the window or cause this window - * to be the last one left, return now. - */ + // Be careful: If autocommands delete the window or cause this window + // to be the last one left, return now. if (wp->w_buffer != curbuf) { reset_VIsual_and_resel(); // stop Visual mode @@ -2860,10 +2824,8 @@ int win_close(win_T *win, bool free_buf, bool force) if (win == curwin) { curwin = wp; if (wp->w_p_pvw || bt_quickfix(wp->w_buffer)) { - /* - * If the cursor goes to the preview or the quickfix window, try - * finding another window to go to. - */ + // If the cursor goes to the preview or the quickfix window, try + // finding another window to go to. for (;;) { if (wp->w_next == NULL) { wp = firstwin; @@ -2908,10 +2870,8 @@ int win_close(win_T *win, bool free_buf, bool force) split_disallowed--; - /* - * If last window has a status line now and we don't want one, - * remove the status line. - */ + // If last window has a status line now and we don't want one, + // remove the status line. last_status(false); // After closing the help window, try restoring the window layout from @@ -2955,13 +2915,11 @@ static void do_autocmd_winclosed(win_T *win) recursive = false; } -/* - * Close window "win" in tab page "tp", which is not the current tab page. - * This may be the last window in that tab page and result in closing the tab, - * thus "tp" may become invalid! - * Caller must check if buffer is hidden and whether the tabline needs to be - * updated. - */ +// Close window "win" in tab page "tp", which is not the current tab page. +// This may be the last window in that tab page and result in closing the tab, +// thus "tp" may become invalid! +// Caller must check if buffer is hidden and whether the tabline needs to be +// updated. void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp) { int dir; @@ -3138,16 +3096,12 @@ win_T *winframe_remove(win_T *win, int *dirp, tabpage_T *tp) frame_T *frp_close = win->w_frame; win_T *wp; - /* - * If there is only one window there is nothing to remove. - */ + // If there is only one window there is nothing to remove. if (tp == NULL ? ONE_WINDOW : tp->tp_firstwin == tp->tp_lastwin) { return NULL; } - /* - * Remove the window from its frame. - */ + // Remove the window from its frame. frp2 = win_altframe(win, tp); wp = frame2win(frp2); @@ -3334,9 +3288,7 @@ static frame_T *win_altframe(win_T *win, tabpage_T *tp) return target_fr; } -/* - * Return the tabpage that will be used if the current one is closed. - */ +// Return the tabpage that will be used if the current one is closed. static tabpage_T *alt_tabpage(void) { tabpage_T *tp; @@ -3351,9 +3303,7 @@ static tabpage_T *alt_tabpage(void) return tp; } -/* - * Find the left-upper window in frame "frp". - */ +// Find the left-upper window in frame "frp". win_T *frame2win(frame_T *frp) { while (frp->fr_win == NULL) { @@ -3557,10 +3507,8 @@ static bool frame_fixed_width(frame_T *frp) return true; } -/* - * Add a status line to windows at the bottom of "frp". - * Note: Does not check if there is room! - */ +// Add a status line to windows at the bottom of "frp". +// Note: Does not check if there is room! static void frame_add_statusline(frame_T *frp) { win_T *wp; @@ -3748,17 +3696,13 @@ static void frame_add_hsep(const frame_T *frp) } } -/* - * Set frame width from the window it contains. - */ +// Set frame width from the window it contains. static void frame_fix_width(win_T *wp) { wp->w_frame->fr_width = wp->w_width + wp->w_vsep_width; } -/* - * Set frame height from the window it contains. - */ +// Set frame height from the window it contains. static void frame_fix_height(win_T *wp) FUNC_ATTR_NONNULL_ALL { @@ -3913,12 +3857,10 @@ void close_others(int message, int forceit) } } -/* - * Allocate the first window and put an empty buffer in it. - * Called from main(). - * - * Return FAIL when something goes wrong. - */ +// Allocate the first window and put an empty buffer in it. +// Called from main(). +// +// Return FAIL when something goes wrong. int win_alloc_first(void) { if (win_alloc_firstwin(NULL) == FAIL) { @@ -3949,12 +3891,10 @@ void win_alloc_aucmd_win(void) RESET_BINDING(aucmd_win); } -/* - * Allocate the first window or the first window in a new tab page. - * When "oldwin" is NULL create an empty buffer for it. - * When "oldwin" is not NULL copy info from it to the new window. - * Return FAIL when something goes wrong (out of memory). - */ +// Allocate the first window or the first window in a new tab page. +// When "oldwin" is NULL create an empty buffer for it. +// When "oldwin" is not NULL copy info from it to the new window. +// Return FAIL when something goes wrong (out of memory). static int win_alloc_firstwin(win_T *oldwin) { curwin = win_alloc(NULL, false); @@ -3986,9 +3926,7 @@ static int win_alloc_firstwin(win_T *oldwin) return OK; } -/* - * Create a frame for window "wp". - */ +// Create a frame for window "wp". static void new_frame(win_T *wp) { frame_T *frp = xcalloc(1, sizeof(frame_T)); @@ -3998,9 +3936,7 @@ static void new_frame(win_T *wp) frp->fr_win = wp; } -/* - * Initialize the window and frame size to the maximum. - */ +// Initialize the window and frame size to the maximum. void win_init_size(void) { firstwin->w_height = (int)ROWS_AVAIL; @@ -4014,9 +3950,7 @@ void win_init_size(void) topframe->fr_width = Columns; } -/* - * Allocate a new tabpage_T and init the values. - */ +// Allocate a new tabpage_T and init the values. static tabpage_T *alloc_tabpage(void) { static int last_tp_handle = 0; @@ -4138,11 +4072,9 @@ int win_new_tabpage(int after, char_u *filename) return FAIL; } -/* - * Open a new tab page if ":tab cmd" was used. It will edit the same buffer, - * like with ":split". - * Returns OK if a new tab page was created, FAIL otherwise. - */ +// Open a new tab page if ":tab cmd" was used. It will edit the same buffer, +// like with ":split". +// Returns OK if a new tab page was created, FAIL otherwise. int may_open_tabpage(void) { int n = (cmdmod.cmod_tab == 0) ? postponed_split_tab : cmdmod.cmod_tab; @@ -4155,10 +4087,8 @@ int may_open_tabpage(void) return FAIL; } -/* - * Create up to "maxcount" tabpages with empty windows. - * Returns the number of resulting tab pages. - */ +// Create up to "maxcount" tabpages with empty windows. +// Returns the number of resulting tab pages. int make_tabpages(int maxcount) { int count = maxcount; @@ -4169,10 +4099,8 @@ int make_tabpages(int maxcount) count = (int)p_tpm; } - /* - * Don't execute autocommands while creating the tab pages. Must do that - * when putting the buffers in the windows. - */ + // Don't execute autocommands while creating the tab pages. Must do that + // when putting the buffers in the windows. block_autocmds(); for (todo = count - 1; todo > 0; todo--) { @@ -4239,9 +4167,7 @@ void close_tabpage(tabpage_T *tab) free_tabpage(tab); } -/* - * Find tab page "n" (first one is 1). Returns NULL when not found. - */ +// Find tab page "n" (first one is 1). Returns NULL when not found. tabpage_T *find_tabpage(int n) { tabpage_T *tp; @@ -4253,10 +4179,8 @@ tabpage_T *find_tabpage(int n) return tp; } -/* - * Get index of tab page "tp". First one has index 1. - * When not found returns number of tab pages plus one. - */ +// Get index of tab page "tp". First one has index 1. +// When not found returns number of tab pages plus one. int tabpage_index(tabpage_T *ftp) { int i = 1; @@ -4412,10 +4336,8 @@ static void tabpage_check_windows(tabpage_T *old_curtab) } } -/* - * Go to tab page "n". For ":tab N" and "Ngt". - * When "n" is 9999 go to the last tab page. - */ +// Go to tab page "n". For ":tab N" and "Ngt". +// When "n" is 9999 go to the last tab page. void goto_tabpage(int n) { tabpage_T *tp = NULL; // shut up compiler @@ -4504,10 +4426,8 @@ bool goto_tabpage_lastused(void) return false; } -/* - * Enter window "wp" in tab page "tp". - * Also updates the GUI tab. - */ +// Enter window "wp" in tab page "tp". +// Also updates the GUI tab. void goto_tabpage_win(tabpage_T *tp, win_T *wp) { goto_tabpage_tp(tp, true, true); @@ -4570,13 +4490,11 @@ void tabpage_move(int nr) redraw_tabline = true; } -/* - * Go to another window. - * When jumping to another buffer, stop Visual mode. Do this before - * changing windows so we can yank the selection into the '*' register. - * When jumping to another window on the same buffer, adjust its cursor - * position to keep the same Visual area. - */ +// Go to another window. +// When jumping to another buffer, stop Visual mode. Do this before +// changing windows so we can yank the selection into the '*' register. +// When jumping to another window on the same buffer, adjust its cursor +// position to keep the same Visual area. void win_goto(win_T *wp) { win_T *owp = curwin; @@ -4603,9 +4521,7 @@ void win_goto(win_T *wp) } } -/* - * Find the tabpage for window "win". - */ +// Find the tabpage for window "win". tabpage_T *win_find_tabpage(win_T *win) { FOR_ALL_TAB_WINDOWS(tp, wp) { @@ -4638,10 +4554,8 @@ win_T *win_vert_neighbor(tabpage_T *tp, win_T *wp, bool up, long count) } while (count--) { - /* - * First go upwards in the tree of frames until we find an upwards or - * downwards neighbor. - */ + // First go upwards in the tree of frames until we find an upwards or + // downwards neighbor. fr = foundfr; for (;;) { if (fr == tp->tp_topframe) { @@ -4658,9 +4572,7 @@ win_T *win_vert_neighbor(tabpage_T *tp, win_T *wp, bool up, long count) fr = fr->fr_parent; } - /* - * Now go downwards to find the bottom or top frame in it. - */ + // Now go downwards to find the bottom or top frame in it. for (;;) { if (nfr->fr_layout == FR_LEAF) { foundfr = nfr; @@ -4721,10 +4633,8 @@ win_T *win_horz_neighbor(tabpage_T *tp, win_T *wp, bool left, long count) } while (count--) { - /* - * First go upwards in the tree of frames until we find a left or - * right neighbor. - */ + // First go upwards in the tree of frames until we find a left or + // right neighbor. fr = foundfr; for (;;) { if (fr == tp->tp_topframe) { @@ -4741,9 +4651,7 @@ win_T *win_horz_neighbor(tabpage_T *tp, win_T *wp, bool left, long count) fr = fr->fr_parent; } - /* - * Now go downwards to find the leftmost or rightmost frame in it. - */ + // Now go downwards to find the leftmost or rightmost frame in it. for (;;) { if (nfr->fr_layout == FR_LEAF) { foundfr = nfr; @@ -5036,9 +4944,7 @@ static win_T *win_alloc(win_T *after, bool hidden) // initialized yet. gui_create_scrollbar() may trigger a FocusGained // event. block_autocmds(); - /* - * link the window in the window list - */ + // link the window in the window list if (!hidden) { win_append(after, new_wp); } @@ -5202,9 +5108,7 @@ void win_free_grid(win_T *wp, bool reinit) } } -/* - * Append window "wp" in the window list after window "after". - */ +// Append window "wp" in the window list after window "after". void win_append(win_T *after, win_T *wp) { win_T *before; @@ -5250,9 +5154,7 @@ void win_remove(win_T *wp, tabpage_T *tp) } } -/* - * Append frame "frp" in a frame list after frame "after". - */ +// Append frame "frp" in a frame list after frame "after". static void frame_append(frame_T *after, frame_T *frp) { frp->fr_next = after->fr_next; @@ -5263,9 +5165,7 @@ static void frame_append(frame_T *after, frame_T *frp) frp->fr_prev = after; } -/* - * Insert frame "frp" in a frame list before frame "before". - */ +// Insert frame "frp" in a frame list before frame "before". static void frame_insert(frame_T *before, frame_T *frp) { frp->fr_next = before; @@ -5278,9 +5178,7 @@ static void frame_insert(frame_T *before, frame_T *frp) } } -/* - * Remove a frame from a frame list. - */ +// Remove a frame from a frame list. static void frame_remove(frame_T *frp) { if (frp->fr_prev != NULL) { @@ -5390,9 +5288,7 @@ void may_trigger_winscrolled(void) } } -/* - * Save the size of all windows in "gap". - */ +// Save the size of all windows in "gap". void win_size_save(garray_T *gap) { ga_init(gap, (int)sizeof(int), 1); @@ -5459,12 +5355,10 @@ void win_reconfig_floats(void) } } -/* - * Update the position of the windows in frame "topfrp", using the width and - * height of the frames. - * "*row" and "*col" are the top-left position of the frame. They are updated - * to the bottom-right position plus one. - */ +// Update the position of the windows in frame "topfrp", using the width and +// height of the frames. +// "*row" and "*col" are the top-left position of the frame. They are updated +// to the bottom-right position plus one. static void frame_comp_pos(frame_T *topfrp, int *row, int *col) { win_T *wp; @@ -5500,19 +5394,15 @@ static void frame_comp_pos(frame_T *topfrp, int *row, int *col) } } -/* - * Set current window height and take care of repositioning other windows to - * fit around it. - */ +// Set current window height and take care of repositioning other windows to +// fit around it. void win_setheight(int height) { win_setheight_win(height, curwin); } -/* - * Set the window height of window "win" and take care of repositioning other - * windows to fit around it. - */ +// Set the window height of window "win" and take care of repositioning other +// windows to fit around it. void win_setheight_win(int height, win_T *win) { // Always keep current window at least one line high, even when 'winminheight' is zero. @@ -5547,19 +5437,17 @@ void win_setheight_win(int height, win_T *win) } } -/* - * Set the height of a frame to "height" and take care that all frames and - * windows inside it are resized. Also resize frames on the left and right if - * the are in the same FR_ROW frame. - * - * Strategy: - * If the frame is part of a FR_COL frame, try fitting the frame in that - * frame. If that doesn't work (the FR_COL frame is too small), recursively - * go to containing frames to resize them and make room. - * If the frame is part of a FR_ROW frame, all frames must be resized as well. - * Check for the minimal height of the FR_ROW frame. - * At the top level we can also use change the command line height. - */ +// Set the height of a frame to "height" and take care that all frames and +// windows inside it are resized. Also resize frames on the left and right if +// the are in the same FR_ROW frame. +// +// Strategy: +// If the frame is part of a FR_COL frame, try fitting the frame in that +// frame. If that doesn't work (the FR_COL frame is too small), recursively +// go to containing frames to resize them and make room. +// If the frame is part of a FR_ROW frame, all frames must be resized as well. +// Check for the minimal height of the FR_ROW frame. +// At the top level we can also use change the command line height. static void frame_setheight(frame_T *curfrp, int height) { int room; // total number of lines available @@ -5595,16 +5483,13 @@ static void frame_setheight(frame_T *curfrp, int height) } frame_setheight(curfrp->fr_parent, height); } else { - /* - * Column of frames: try to change only frames in this column. - */ - /* - * Do this twice: - * 1: compute room available, if it's not enough try resizing the - * containing frame. - * 2: compute the room available and adjust the height to it. - * Try not to reduce the height of a window with 'winfixheight' set. - */ + // Column of frames: try to change only frames in this column. + + // Do this twice: + // 1: compute room available, if it's not enough try resizing the + // containing frame. + // 2: compute the room available and adjust the height to it. + // Try not to reduce the height of a window with 'winfixheight' set. for (run = 1; run <= 2; run++) { room = 0; room_reserved = 0; @@ -5642,10 +5527,8 @@ static void frame_setheight(frame_T *curfrp, int height) //NOTREACHED } - /* - * Compute the number of lines we will take from others frames (can be - * negative!). - */ + // Compute the number of lines we will take from others frames (can be + // negative!). take = height - curfrp->fr_height; // If there is not enough room, also reduce the height of a window @@ -5668,16 +5551,12 @@ static void frame_setheight(frame_T *curfrp, int height) topframe->fr_height += room_cmdline; } - /* - * set the current frame to the new height - */ + // set the current frame to the new height frame_new_height(curfrp, height, false, false); - /* - * First take lines from the frames after the current frame. If - * that is not enough, takes lines from frames above the current - * frame. - */ + // First take lines from the frames after the current frame. If + // that is not enough, takes lines from frames above the current + // frame. for (run = 0; run < 2; run++) { if (run == 0) { frp = curfrp->fr_next; // 1st run: start with next window @@ -5718,10 +5597,8 @@ static void frame_setheight(frame_T *curfrp, int height) } } -/* - * Set current window width and take care of repositioning other windows to - * fit around it. - */ +// Set current window width and take care of repositioning other windows to +// fit around it. void win_setwidth(int width) { win_setwidth_win(width, curwin); @@ -5754,13 +5631,11 @@ void win_setwidth_win(int width, win_T *wp) } } -/* - * Set the width of a frame to "width" and take care that all frames and - * windows inside it are resized. Also resize frames above and below if the - * are in the same FR_ROW frame. - * - * Strategy is similar to frame_setheight(). - */ +// Set the width of a frame to "width" and take care that all frames and +// windows inside it are resized. Also resize frames above and below if the +// are in the same FR_ROW frame. +// +// Strategy is similar to frame_setheight(). static void frame_setwidth(frame_T *curfrp, int width) { int room; // total number of lines available @@ -5789,14 +5664,12 @@ static void frame_setwidth(frame_T *curfrp, int width) } frame_setwidth(curfrp->fr_parent, width); } else { - /* - * Row of frames: try to change only frames in this row. - * - * Do this twice: - * 1: compute room available, if it's not enough try resizing the - * containing frame. - * 2: compute the room available and adjust the width to it. - */ + // Row of frames: try to change only frames in this row. + // + // Do this twice: + // 1: compute room available, if it's not enough try resizing the + // containing frame. + // 2: compute the room available and adjust the width to it. for (run = 1; run <= 2; run++) { room = 0; room_reserved = 0; @@ -5823,10 +5696,8 @@ static void frame_setwidth(frame_T *curfrp, int width) + frame_minwidth(curfrp->fr_parent, NOWIN) - (int)p_wmw - 1); } - /* - * Compute the number of lines we will take from others frames (can be - * negative!). - */ + // Compute the number of lines we will take from others frames (can be + // negative!). take = width - curfrp->fr_width; // If there is not enough room, also reduce the width of a window @@ -5840,16 +5711,12 @@ static void frame_setwidth(frame_T *curfrp, int width) room_reserved = 0; } - /* - * set the current frame to the new width - */ + // set the current frame to the new width frame_new_width(curfrp, width, false, false); - /* - * First take lines from the frames right of the current frame. If - * that is not enough, takes lines from frames left of the current - * frame. - */ + // First take lines from the frames right of the current frame. If + // that is not enough, takes lines from frames left of the current + // frame. for (run = 0; run < 2; run++) { if (run == 0) { frp = curfrp->fr_next; // 1st run: start with next window @@ -6016,10 +5883,8 @@ void win_drag_status_line(win_T *dragwin, int offset) return; } - /* - * Grow frame fr by "offset" lines. - * Doesn't happen when dragging the last status line up. - */ + // Grow frame fr by "offset" lines. + // Doesn't happen when dragging the last status line up. if (fr != NULL) { frame_new_height(fr, fr->fr_height + offset, up, false); } @@ -6029,9 +5894,7 @@ void win_drag_status_line(win_T *dragwin, int offset) } else { fr = curfr->fr_next; // next frame gets smaller } - /* - * Now make the other frames smaller. - */ + // Now make the other frames smaller. while (fr != NULL && offset > 0) { n = frame_minheight(fr, NULL); if (fr->fr_height - offset <= n) { @@ -6059,9 +5922,7 @@ void win_drag_status_line(win_T *dragwin, int offset) showmode(); } -/* - * Separator line of dragwin is dragged "offset" lines right (negative is left). - */ +// Separator line of dragwin is dragged "offset" lines right (negative is left). void win_drag_vsep_line(win_T *dragwin, int offset) { frame_T *curfr; @@ -6214,10 +6075,8 @@ void scroll_to_fraction(win_T *wp, int prev_height) && (!wp->w_p_scb || wp == curwin) && (height < wp->w_buffer->b_ml.ml_line_count || wp->w_topline > 1)) { - /* - * Find a value for w_topline that shows the cursor at the same - * relative position in the window as before (more or less). - */ + // Find a value for w_topline that shows the cursor at the same + // relative position in the window as before (more or less). lnum = wp->w_cursor.lnum; if (lnum < 1) { // can happen when starting up lnum = 1; @@ -6237,11 +6096,9 @@ void scroll_to_fraction(win_T *wp, int prev_height) } if (sline < 0) { - /* - * Cursor line would go off top of screen if w_wrow was this high. - * Make cursor line the first line in the window. If not enough - * room use w_skipcol; - */ + // Cursor line would go off top of screen if w_wrow was this high. + // Make cursor line the first line in the window. If not enough + // room use w_skipcol; wp->w_wrow = line_size; if (wp->w_wrow >= wp->w_height_inner && (wp->w_width_inner - win_col_off(wp)) > 0) { @@ -6273,10 +6130,8 @@ void scroll_to_fraction(win_T *wp, int prev_height) } if (sline < 0) { - /* - * Line we want at top would go off top of screen. Use next - * line instead. - */ + // Line we want at top would go off top of screen. Use next + // line instead. (void)hasFoldingWin(wp, lnum, NULL, &lnum, true, NULL); lnum++; wp->w_wrow -= line_size + sline; @@ -6403,9 +6258,7 @@ void win_comp_scroll(win_T *wp) } } -/* - * command_height: called whenever p_ch has been changed - */ +// command_height: called whenever p_ch has been changed void command_height(void) { int h; @@ -6488,10 +6341,8 @@ void command_height(void) } } -/* - * Resize frame "frp" to be "n" lines higher (negative for less high). - * Also resize the frames it is contained in. - */ +// Resize frame "frp" to be "n" lines higher (negative for less high). +// Also resize the frames it is contained in. static void frame_add_height(frame_T *frp, int n) { frame_new_height(frp, frp->fr_height + n, false, false); @@ -6504,11 +6355,9 @@ static void frame_add_height(frame_T *frp, int n) } } -/* - * Get the file name at the cursor. - * If Visual mode is active, use the selected text if it's in one line. - * Returns the name in allocated memory, NULL for failure. - */ +// Get the file name at the cursor. +// If Visual mode is active, use the selected text if it's in one line. +// Returns the name in allocated memory, NULL for failure. char_u *grab_file_name(long count, linenr_T *file_lnum) { int options = FNAME_MESS | FNAME_EXP | FNAME_REL | FNAME_UNESC; @@ -6529,19 +6378,17 @@ char_u *grab_file_name(long count, linenr_T *file_lnum) return file_name_at_cursor(options | FNAME_HYP, count, file_lnum); } -/* - * Return the file name under or after the cursor. - * - * The 'path' option is searched if the file name is not absolute. - * The string returned has been alloc'ed and should be freed by the caller. - * NULL is returned if the file name or file is not found. - * - * options: - * FNAME_MESS give error messages - * FNAME_EXP expand to path - * FNAME_HYP check for hypertext link - * FNAME_INCL apply "includeexpr" - */ +// Return the file name under or after the cursor. +// +// The 'path' option is searched if the file name is not absolute. +// The string returned has been alloc'ed and should be freed by the caller. +// NULL is returned if the file name or file is not found. +// +// options: +// FNAME_MESS give error messages +// FNAME_EXP expand to path +// FNAME_HYP check for hypertext link +// FNAME_INCL apply "includeexpr" char_u *file_name_at_cursor(int options, long count, linenr_T *file_lnum) { return file_name_in_line((char_u *)get_cursor_line_ptr(), @@ -6561,9 +6408,7 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u bool in_type = true; bool is_url = false; - /* - * search forward for what could be the start of a file name - */ + // search forward for what could be the start of a file name ptr = (char *)line + col; while (*ptr != NUL && !vim_isfilec(*ptr)) { MB_PTR_ADV(ptr); @@ -6575,10 +6420,8 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u return NULL; } - /* - * Search backward for first char of the file name. - * Go one char back to ":" before "//" even when ':' is not in 'isfname'. - */ + // Search backward for first char of the file name. + // Go one char back to ":" before "//" even when ':' is not in 'isfname'. while ((char_u *)ptr > line) { if ((len = (size_t)(utf_head_off((char *)line, ptr - 1))) > 0) { ptr -= len + 1; @@ -6589,10 +6432,8 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u } } - /* - * Search forward for the last char of the file name. - * Also allow ":/" when ':' is not in 'isfname'. - */ + // Search forward for the last char of the file name. + // Also allow ":/" when ':' is not in 'isfname'. len = 0; while (vim_isfilec(ptr[len]) || (ptr[len] == '\\' && ptr[len + 1] == ' ') || ((options & FNAME_HYP) && path_is_url(ptr + len)) @@ -6615,10 +6456,8 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u len += (size_t)(utfc_ptr2len(ptr + len)); } - /* - * If there is trailing punctuation, remove it. - * But don't remove "..", could be a directory name. - */ + // If there is trailing punctuation, remove it. + // But don't remove "..", could be a directory name. if (len > 2 && vim_strchr(".,:;!", ptr[len - 1]) != NULL && ptr[len - 2] != '.') { len--; @@ -6972,21 +6811,17 @@ void reset_lnums(void) } } -/* - * A snapshot of the window sizes, to restore them after closing the help - * window. - * Only these fields are used: - * fr_layout - * fr_width - * fr_height - * fr_next - * fr_child - * fr_win (only valid for the old curwin, NULL otherwise) - */ +// A snapshot of the window sizes, to restore them after closing the help +// window. +// Only these fields are used: +// fr_layout +// fr_width +// fr_height +// fr_next +// fr_child +// fr_win (only valid for the old curwin, NULL otherwise) -/* - * Create a snapshot of the current frame sizes. - */ +// Create a snapshot of the current frame sizes. void make_snapshot(int idx) { clear_snapshot(curtab, idx); @@ -7010,9 +6845,7 @@ static void make_snapshot_rec(frame_T *fr, frame_T **frp) } } -/* - * Remove any existing snapshot. - */ +// Remove any existing snapshot. static void clear_snapshot(tabpage_T *tp, int idx) { clear_snapshot_rec(tp->tp_snapshot[idx]); @@ -7097,11 +6930,9 @@ static int check_snapshot_rec(frame_T *sn, frame_T *fr) return OK; } -/* - * Copy the size of snapshot frame "sn" to frame "fr". Do the same for all - * following frames and children. - * Returns a pointer to the old current window, or NULL. - */ +// Copy the size of snapshot frame "sn" to frame "fr". Do the same for all +// following frames and children. +// Returns a pointer to the old current window, or NULL. static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr) { win_T *wp = NULL; -- cgit From 05b49ef975664ccdfea4e7b5a0fc09c8ed2cf11a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Sep 2022 06:50:11 +0800 Subject: vim-patch:8.2.1505: not all file read and writecode is tested MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Not all file read and writecode is tested. Solution: Add a few tests. (Dominique Pellé, closes vim/vim#6764) https://github.com/vim/vim/commit/1b04ce2d400fda97410a961288c496bd8f445a9c Cherry-pick Test_glob() from patch 8.2.0634. --- src/nvim/testdir/test_eval_stuff.vim | 25 +++++++++++++++++++------ src/nvim/testdir/test_fnamemodify.vim | 6 ++++++ src/nvim/testdir/test_functions.vim | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_eval_stuff.vim b/src/nvim/testdir/test_eval_stuff.vim index eff1376d3c..351120bf11 100644 --- a/src/nvim/testdir/test_eval_stuff.vim +++ b/src/nvim/testdir/test_eval_stuff.vim @@ -91,18 +91,31 @@ func Test_readfile_binary() new call setline(1, ['one', 'two', 'three']) setlocal ff=dos - silent write XReadfile - let lines = readfile('XReadfile') + silent write XReadfile_bin + let lines = 'XReadfile_bin'->readfile() call assert_equal(['one', 'two', 'three'], lines) - let lines = readfile('XReadfile', '', 2) + let lines = readfile('XReadfile_bin', '', 2) call assert_equal(['one', 'two'], lines) - let lines = readfile('XReadfile', 'b') + let lines = readfile('XReadfile_bin', 'b') call assert_equal(["one\r", "two\r", "three\r", ""], lines) - let lines = readfile('XReadfile', 'b', 2) + let lines = readfile('XReadfile_bin', 'b', 2) call assert_equal(["one\r", "two\r"], lines) bwipe! - call delete('XReadfile') + call delete('XReadfile_bin') +endfunc + +func Test_readfile_bom() + call writefile(["\ufeffFOO", "FOO\ufeffBAR"], 'XReadfile_bom') + call assert_equal(['FOO', 'FOOBAR'], readfile('XReadfile_bom')) + call delete('XReadfile_bom') +endfunc + +func Test_readfile_max() + call writefile(range(1, 4), 'XReadfile_max') + call assert_equal(['1', '2'], readfile('XReadfile_max', '', 2)) + call assert_equal(['3', '4'], readfile('XReadfile_max', '', -2)) + call delete('XReadfile_max') endfunc func Test_let_errmsg() diff --git a/src/nvim/testdir/test_fnamemodify.vim b/src/nvim/testdir/test_fnamemodify.vim index 5ae2a5ee17..258a2093bd 100644 --- a/src/nvim/testdir/test_fnamemodify.vim +++ b/src/nvim/testdir/test_fnamemodify.vim @@ -11,6 +11,7 @@ func Test_fnamemodify() call assert_equal('/', fnamemodify('.', ':p')[-1:]) call assert_equal('r', fnamemodify('.', ':p:h')[-1:]) call assert_equal('t', fnamemodify('test.out', ':p')[-1:]) + call assert_equal($HOME .. "/foo" , fnamemodify('~/foo', ':p')) call assert_equal('test.out', fnamemodify('test.out', ':.')) call assert_equal('a', fnamemodify('../testdir/a', ':.')) call assert_equal('~/testdir/test.out', fnamemodify('test.out', ':~')) @@ -95,4 +96,9 @@ func Test_fnamemodify_er() call assert_equal('', fnamemodify(v:_null_string, v:_null_string)) endfunc +func Test_fnamemodify_fail() + call assert_fails('call fnamemodify({}, ":p")', 'E731:') + call assert_fails('call fnamemodify("x", {})', 'E731:') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 147eda5b0a..99ac6ae32c 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2015,6 +2015,25 @@ func Test_getmousepos() bwipe! endfunc +" Test for glob() +func Test_glob() + call assert_equal('', glob(v:_null_string)) + call assert_equal('', globpath(v:_null_string, v:_null_string)) + + call writefile([], 'Xglob1') + call writefile([], 'XGLOB2') + set wildignorecase + " Sort output of glob() otherwise we end up with different + " ordering depending on whether file system is case-sensitive. + call assert_equal(['XGLOB2', 'Xglob1'], sort(glob('Xglob[12]', 0, 1))) + set wildignorecase& + + call delete('Xglob1') + call delete('XGLOB2') + + call assert_fails("call glob('*', 0, {})", 'E728:') +endfunc + func HasDefault(msg = 'msg') return a:msg endfunc -- cgit From 7243b1cbde8a08deab6bf29b452b3383fa4f6d8d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Sep 2022 06:46:30 +0800 Subject: vim-patch:9.0.0360: crash when invalid line number on :for is ignored Problem: Crash when invalid line number on :for is ignored. Solution: Do not check breakpoint for non-existing line. https://github.com/vim/vim/commit/35d21c6830fc2d68aca838424a0e786821c5891c Test does not fail without the fix in Nvim as Nvim uses 0 when line number overflows. If it is changed to MAXLNUM then the test does fail without the fix, but using 0 seems better as E481 is still given. --- src/nvim/ex_docmd.c | 2 +- src/nvim/testdir/test_eval_stuff.vim | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index c2c5bb90ce..6517ebd081 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -642,7 +642,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) // Check for the next breakpoint at or after the ":while" // or ":for". - if (breakpoint != NULL) { + if (breakpoint != NULL && lines_ga.ga_len > current_line) { *breakpoint = dbg_find_breakpoint(getline_equal(fgetline, cookie, getsourceline), fname, ((wcmd_T *)lines_ga.ga_data)[current_line].lnum - 1); *dbg_tick = debug_tick; diff --git a/src/nvim/testdir/test_eval_stuff.vim b/src/nvim/testdir/test_eval_stuff.vim index 351120bf11..dc110af356 100644 --- a/src/nvim/testdir/test_eval_stuff.vim +++ b/src/nvim/testdir/test_eval_stuff.vim @@ -1,5 +1,8 @@ " Tests for various eval things. +source view_util.vim +source shared.vim + function s:foo() abort try return [] == 0 @@ -87,6 +90,18 @@ func Test_for_over_null_string() let &enc = save_enc endfunc +func Test_for_invalid_line_count() + let lines =<< trim END + 111111111111111111111111 for line in ['one'] + endfor + END + call writefile(lines, 'XinvalidFor') + " only test that this doesn't crash + call RunVim([], [], '-u NONE -e -s -S XinvalidFor -c qa') + + call delete('XinvalidFor') +endfunc + func Test_readfile_binary() new call setline(1, ['one', 'two', 'three']) -- cgit From c62e5b50795d38db68f198a3d1230c047fc0ccfa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Sep 2022 07:51:51 +0800 Subject: vim-patch:9.0.0362: expanding ":e %" does not work for remote files Problem: Expanding ":e %" does not work for remote files. Solution: If the "%" or "#" file does not exist add the expansion anyway. https://github.com/vim/vim/commit/f5724376ab7362b5a98eaa8a331d663ef722c2a2 --- src/nvim/path.c | 15 ++++++++++++++- src/nvim/testdir/test_cmdline.vim | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/path.c b/src/nvim/path.c index 607f1fc09a..1e5fa49ad6 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2106,13 +2106,16 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char ***file, int flags) char *exp_pat = (char *)(*pat); char *ignored_msg; size_t usedlen; + const bool is_cur_alt_file = *exp_pat == '%' || *exp_pat == '#'; + bool star_follows = false; - if (*exp_pat == '%' || *exp_pat == '#' || *exp_pat == '<') { + if (is_cur_alt_file || *exp_pat == '<') { emsg_off++; eval_pat = eval_vars((char_u *)exp_pat, (char_u *)exp_pat, &usedlen, NULL, &ignored_msg, NULL, true); emsg_off--; if (eval_pat != NULL) { + star_follows = strcmp(exp_pat + usedlen, "*") == 0; exp_pat = concat_str((char *)eval_pat, exp_pat + usedlen); } } @@ -2122,6 +2125,16 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char ***file, int flags) } if (eval_pat != NULL) { + if (*num_file == 0 && is_cur_alt_file && star_follows) { + // Expanding "%" or "#" and the file does not exist: Add the + // pattern anyway (without the star) so that this works for remote + // files and non-file buffer names. + *file = xmalloc(sizeof(char *)); + **file = (char *)eval_pat; + eval_pat = NULL; + *num_file = 1; + ret = OK; + } xfree(exp_pat); xfree(eval_pat); } diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index bc06e70ff4..e40ff65051 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1055,6 +1055,18 @@ func Test_cmdline_write_alternatefile() bw! endfunc +func Test_cmdline_expand_cur_alt_file() + enew + file http://some.com/file.txt + call feedkeys(":e %\\\"\", 'xt') + call assert_equal('"e http://some.com/file.txt', @:) + edit another + call feedkeys(":e #\\\"\", 'xt') + call assert_equal('"e http://some.com/file.txt', @:) + bwipe + bwipe http://some.com/file.txt +endfunc + " using a leading backslash here set cpo+=C -- cgit From ea611c7122470af0e03f4b0a5ae99c0878da2712 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 3 Sep 2022 12:00:00 +0200 Subject: ci(clint): remove "Inner expression indentation should be 4" rule (#20047) It completely breaks down in shada.c and is generally useless. --- src/clint.py | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src') diff --git a/src/clint.py b/src/clint.py index 28f6031a57..0556f53372 100755 --- a/src/clint.py +++ b/src/clint.py @@ -1941,13 +1941,6 @@ def CheckExpressionAlignment(filename, clean_lines, linenum, error, startpos=0): error(filename, linenum, 'whitespace/indent', 2, 'End of the inner expression should have ' 'the same indent as start') - else: - if (pos != depth_line_starts[depth][0] + 4 - and not (depth_line_starts[depth][1] == '{' - and pos == depth_line_starts[depth][0] + 2)): - if depth not in ignore_error_levels: - error(filename, linenum, 'whitespace/indent', 2, - 'Inner expression indentation should be 4') else: if (pos != level_starts[depth][0] + 1 + (level_starts[depth][2] == '{')): -- cgit From c50460cf3b02f8e684d038a1ea37e6fdc2d13a09 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 3 Sep 2022 07:02:58 -0700 Subject: feat(treesitter): include language in invalid query error (#14053) --- src/nvim/lua/treesitter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 7ff4fbbff4..65e024b707 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -1276,8 +1276,8 @@ int tslua_parse_query(lua_State *L) TSQuery *query = ts_query_new(lang, src, (uint32_t)len, &error_offset, &error_type); if (!query) { - return luaL_error(L, "query: %s at position %d", - query_err_string(error_type), (int)error_offset); + return luaL_error(L, "query: %s at position %d for language %s", + query_err_string(error_type), (int)error_offset, lang_name); } TSQuery **ud = lua_newuserdata(L, sizeof(TSQuery *)); // [udata] -- cgit From 00b49dd8dd638c5fe1b664273aea5c843d69f36d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 11:20:23 +0800 Subject: vim-patch:8.2.4674: cannot force getting MouseMove events Problem: Cannot force getting MouseMove events. Solution: Add the 'mousemoveevent' option with implementaiton for the GUI. (Ernie Rael, closes vim/vim#10044) https://github.com/vim/vim/commit/c4cb544cd5beaa864b3893e4b8d0085393c7dbce This only ports the docs and the option variable. The following commits will actually implement it as a UI option. --- src/nvim/option_defs.h | 1 + src/nvim/options.lua | 7 +++++++ 2 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index bfac0cff87..64b3f69df4 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -616,6 +616,7 @@ EXTERN int p_ma; ///< 'modifiable' EXTERN int p_mod; ///< 'modified' EXTERN char *p_mouse; // 'mouse' EXTERN char *p_mousem; // 'mousemodel' +EXTERN int p_mousemev; ///< 'mousemoveevent' EXTERN int p_mousef; // 'mousefocus' EXTERN char *p_mousescroll; // 'mousescroll' EXTERN long p_mousescroll_vert INIT(= MOUSESCROLL_VERT_DFLT); diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 2f941f5d0c..9f540e6005 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1621,6 +1621,13 @@ return { varname='p_mousem', defaults={if_true="popup_setpos"} }, + { + full_name='mousemoveevent', abbreviation='mousemev', + short_desc=N_("deliver mouse move events to input queue"), + type='bool', scope={'global'}, + varname='p_mousemev', + defaults={if_true=false} + }, { full_name='mousescroll', short_desc=N_("amount to scroll by when scrolling with a mouse"), -- cgit From a5fe7940c8b9436b78ae408eae8345266423f2c8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 11:32:56 +0800 Subject: feat(ui-ext): make 'mousemoveevent' a ui_option --- src/nvim/options.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 9f540e6005..717ca6747b 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1625,6 +1625,7 @@ return { full_name='mousemoveevent', abbreviation='mousemev', short_desc=N_("deliver mouse move events to input queue"), type='bool', scope={'global'}, + redraw={'ui_option'}, varname='p_mousemev', defaults={if_true=false} }, -- cgit From 04bd700ac3bc2bdea0e0d8747de95dab2034aa11 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 11:26:54 +0800 Subject: feat(tui): support 'mousemoveevent' --- src/nvim/os/input.c | 6 ++++-- src/nvim/tui/input.c | 7 ++++--- src/nvim/tui/tui.c | 27 +++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index bfe6d59dc6..ea9f31d776 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -293,7 +293,8 @@ static uint8_t check_multiclick(int code, int grid, int row, int col) || code == KE_MOUSEDOWN || code == KE_MOUSEUP || code == KE_MOUSELEFT - || code == KE_MOUSERIGHT) { + || code == KE_MOUSERIGHT + || code == KE_MOUSEMOVE) { return 0; } uint64_t mouse_time = os_hrtime(); // time of current mouse click (ns) @@ -347,7 +348,8 @@ static unsigned int handle_mouse_event(char **ptr, uint8_t *buf, unsigned int bu if (type != KS_EXTRA || !((mouse_code >= KE_LEFTMOUSE && mouse_code <= KE_RIGHTRELEASE) - || (mouse_code >= KE_MOUSEDOWN && mouse_code <= KE_MOUSERIGHT))) { + || (mouse_code >= KE_MOUSEDOWN && mouse_code <= KE_MOUSERIGHT) + || mouse_code == KE_MOUSEMOVE)) { return bufsize; } diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index d269878f46..728520c20c 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -406,8 +406,8 @@ static void forward_mouse_event(TermInput *input, TermKeyKey *key) } } - if (button == 0 || (ev != TERMKEY_MOUSE_PRESS && ev != TERMKEY_MOUSE_DRAG - && ev != TERMKEY_MOUSE_RELEASE)) { + if ((button == 0 && ev != TERMKEY_MOUSE_RELEASE) + || (ev != TERMKEY_MOUSE_PRESS && ev != TERMKEY_MOUSE_DRAG && ev != TERMKEY_MOUSE_RELEASE)) { return; } @@ -453,7 +453,8 @@ static void forward_mouse_event(TermInput *input, TermKeyKey *key) len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Drag"); break; case TERMKEY_MOUSE_RELEASE: - len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Release"); + len += (size_t)snprintf(buf + len, sizeof(buf) - len, button ? "Release" : "MouseMove"); + last_pressed_button = 0; break; case TERMKEY_MOUSE_UNKNOWN: abort(); diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 38e8c15762..471a3fb859 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -103,6 +103,7 @@ struct TUIData { bool immediate_wrap_after_last_column; bool bce; bool mouse_enabled; + bool mouse_move_enabled; bool busy, is_invisible, want_invisible; bool cork, overflow; bool cursor_color_changed; @@ -117,6 +118,7 @@ struct TUIData { ModeShape showing_mode; struct { int enable_mouse, disable_mouse; + int enable_mouse_move, disable_mouse_move; int enable_bracketed_paste, disable_bracketed_paste; int enable_lr_margin, disable_lr_margin; int enter_strikethrough_mode; @@ -236,6 +238,8 @@ static void terminfo_start(UI *ui) data->showing_mode = SHAPE_IDX_N; data->unibi_ext.enable_mouse = -1; data->unibi_ext.disable_mouse = -1; + data->unibi_ext.enable_mouse_move = -1; + data->unibi_ext.disable_mouse_move = -1; data->unibi_ext.set_cursor_color = -1; data->unibi_ext.reset_cursor_color = -1; data->unibi_ext.enable_bracketed_paste = -1; @@ -1138,6 +1142,9 @@ static void tui_mouse_on(UI *ui) TUIData *data = ui->data; if (!data->mouse_enabled) { unibi_out_ext(ui, data->unibi_ext.enable_mouse); + if (data->mouse_move_enabled) { + unibi_out_ext(ui, data->unibi_ext.enable_mouse_move); + } data->mouse_enabled = true; } } @@ -1146,6 +1153,9 @@ static void tui_mouse_off(UI *ui) { TUIData *data = ui->data; if (data->mouse_enabled) { + if (data->mouse_move_enabled) { + unibi_out_ext(ui, data->unibi_ext.disable_mouse_move); + } unibi_out_ext(ui, data->unibi_ext.disable_mouse); data->mouse_enabled = false; } @@ -1457,9 +1467,18 @@ static void tui_screenshot(UI *ui, String path) static void tui_option_set(UI *ui, String name, Object value) { TUIData *data = ui->data; - if (strequal(name.data, "termguicolors")) { + if (strequal(name.data, "mousemoveevent")) { + if (data->mouse_move_enabled != value.data.boolean) { + if (data->mouse_enabled) { + tui_mouse_off(ui); + data->mouse_move_enabled = value.data.boolean; + tui_mouse_on(ui); + } else { + data->mouse_move_enabled = value.data.boolean; + } + } + } else if (strequal(name.data, "termguicolors")) { ui->rgb = value.data.boolean; - data->print_attr_id = -1; invalidate(ui, 0, data->grid.height, 0, data->grid.width); } else if (strequal(name.data, "ttimeout")) { @@ -2135,6 +2154,10 @@ static void augment_terminfo(TUIData *data, const char *term, long vte_version, "\x1b[?1002h\x1b[?1006h"); data->unibi_ext.disable_mouse = (int)unibi_add_ext_str(ut, "ext.disable_mouse", "\x1b[?1002l\x1b[?1006l"); + data->unibi_ext.enable_mouse_move = (int)unibi_add_ext_str(ut, "ext.enable_mouse_move", + "\x1b[?1003h"); + data->unibi_ext.disable_mouse_move = (int)unibi_add_ext_str(ut, "ext.disable_mouse_move", + "\x1b[?1003l"); // Extended underline. // terminfo will have Smulx for this (but no support for colors yet). -- cgit From ceb09701f29dcabcf219f458fffbb64f5adced9b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 13:58:29 +0800 Subject: feat(api): add "move" to nvim_input_mouse --- src/nvim/api/vim.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 83d6ba8dc7..95c9919522 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -336,9 +336,9 @@ Integer nvim_input(String keys) /// mouse input in a GUI. The deprecated pseudokey form /// ("") of |nvim_input()| has the same limitation. /// -/// @param button Mouse button: one of "left", "right", "middle", "wheel". +/// @param button Mouse button: one of "left", "right", "middle", "wheel", "move". /// @param action For ordinary buttons, one of "press", "drag", "release". -/// For the wheel, one of "up", "down", "left", "right". +/// For the wheel, one of "up", "down", "left", "right". Ignored for "move". /// @param modifier String of modifiers each represented by a single char. /// The same specifiers are used as for a key press, except /// that the "-" separator is optional, so "C-A-", "c-a" @@ -365,6 +365,8 @@ void nvim_input_mouse(String button, String action, String modifier, Integer gri code = KE_RIGHTMOUSE; } else if (strequal(button.data, "wheel")) { code = KE_MOUSEDOWN; + } else if (strequal(button.data, "move")) { + code = KE_MOUSEMOVE; } else { goto error; } @@ -381,7 +383,7 @@ void nvim_input_mouse(String button, String action, String modifier, Integer gri } else { goto error; } - } else { + } else if (code != KE_MOUSEMOVE) { if (strequal(action.data, "press")) { // pass } else if (strequal(action.data, "drag")) { -- cgit From 82d128405aaeb619a0c04353449f5717da126249 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 15:24:15 +0800 Subject: feat(pum): pretend 'mousemoveevent' is set when showing right-click menu --- src/nvim/popupmenu.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 0d9080ceb7..2265334a45 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -1042,6 +1042,10 @@ void pum_show_popupmenu(vimmenu_T *menu) pum_scrollbar = 0; pum_height = pum_size; pum_position_at_mouse(20); + if (!p_mousemev) { + // Pretend 'mousemoveevent' is set. + ui_call_option_set(STATIC_CSTR_AS_STRING("mousemoveevent"), BOOLEAN_OBJ(true)); + } pum_selected = -1; pum_first = 0; @@ -1102,6 +1106,9 @@ void pum_show_popupmenu(vimmenu_T *menu) xfree(array); pum_undisplay(true); + if (!p_mousemev) { + ui_call_option_set(STATIC_CSTR_AS_STRING("mousemoveevent"), BOOLEAN_OBJ(false)); + } } void pum_make_popup(const char *path_name, int use_mouse_pos) -- cgit From fc7a64291a5ed074eafff47b21b411bfe9d4a19e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Sep 2022 21:54:23 +0800 Subject: vim-patch:9.0.0386: some code blocks are nested too deep Problem: Some code blocks are nested too deep. Solution: Bail out earlier. (Yegappan Lakshmanan, closes vim/vim#11058) https://github.com/vim/vim/commit/b1f471ee20b0fa783ecd6e29aa69067e6c821376 --- src/nvim/arglist.c | 167 ++++++++++++++++++++++++++++------------------------- src/nvim/memory.c | 18 +++--- 2 files changed, 99 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index 70b2e71949..e6ac1f6247 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -79,11 +79,12 @@ void alist_expand(int *fnum_list, int fnum_len) { char *save_p_su = p_su; + char **old_arg_files = xmalloc(sizeof(*old_arg_files) * GARGCOUNT); + // Don't use 'suffixes' here. This should work like the shell did the // expansion. Also, the vimrc file isn't read yet, thus the user // can't set the options. p_su = empty_option; - char **old_arg_files = xmalloc(sizeof(*old_arg_files) * GARGCOUNT); for (int i = 0; i < GARGCOUNT; i++) { old_arg_files[i] = vim_strsave(GARGLIST[i].ae_fname); } @@ -308,6 +309,50 @@ static void alist_add_list(int count, char **files, int after, bool will_edit) } } +/// Delete the file names in "alist_ga" from the argument list. +static void arglist_del_files(garray_T *alist_ga) +{ + regmatch_T regmatch; + + // Delete the items: use each item as a regexp and find a match in the + // argument list. + regmatch.rm_ic = p_fic; // ignore case when 'fileignorecase' is set + for (int i = 0; i < alist_ga->ga_len && !got_int; i++) { + char *p = ((char **)alist_ga->ga_data)[i]; + p = file_pat_to_reg_pat(p, NULL, NULL, false); + if (p == NULL) { + break; + } + regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); + if (regmatch.regprog == NULL) { + xfree(p); + break; + } + + bool didone = false; + for (int match = 0; match < ARGCOUNT; match++) { + if (vim_regexec(®match, alist_name(&ARGLIST[match]), (colnr_T)0)) { + didone = true; + xfree(ARGLIST[match].ae_fname); + memmove(ARGLIST + match, ARGLIST + match + 1, + (size_t)(ARGCOUNT - match - 1) * sizeof(aentry_T)); + ALIST(curwin)->al_ga.ga_len--; + if (curwin->w_arg_idx > match) { + curwin->w_arg_idx--; + } + match--; + } + } + + vim_regfree(regmatch.regprog); + xfree(p); + if (!didone) { + semsg(_(e_nomatch2), ((char **)alist_ga->ga_data)[i]); + } + } + ga_clear(alist_ga); +} + /// @param str /// @param what /// AL_SET: Redefine the argument list to 'str'. @@ -324,8 +369,6 @@ static int do_arglist(char *str, int what, int after, bool will_edit) garray_T new_ga; int exp_count; char **exp_files; - char *p; - int match; int arg_escaped = true; // Set default argument for ":argadd" command. @@ -341,46 +384,7 @@ static int do_arglist(char *str, int what, int after, bool will_edit) get_arglist(&new_ga, str, arg_escaped); if (what == AL_DEL) { - regmatch_T regmatch; - bool didone; - - // Delete the items: use each item as a regexp and find a match in the - // argument list. - regmatch.rm_ic = p_fic; // ignore case when 'fileignorecase' is set - for (int i = 0; i < new_ga.ga_len && !got_int; i++) { - p = ((char **)new_ga.ga_data)[i]; - p = file_pat_to_reg_pat(p, NULL, NULL, false); - if (p == NULL) { - break; - } - regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); - if (regmatch.regprog == NULL) { - xfree(p); - break; - } - - didone = false; - for (match = 0; match < ARGCOUNT; match++) { - if (vim_regexec(®match, alist_name(&ARGLIST[match]), (colnr_T)0)) { - didone = true; - xfree(ARGLIST[match].ae_fname); - memmove(ARGLIST + match, ARGLIST + match + 1, - (size_t)(ARGCOUNT - match - 1) * sizeof(aentry_T)); - ALIST(curwin)->al_ga.ga_len--; - if (curwin->w_arg_idx > match) { - curwin->w_arg_idx--; - } - match--; - } - } - - vim_regfree(regmatch.regprog); - xfree(p); - if (!didone) { - semsg(_(e_nomatch2), ((char **)new_ga.ga_data)[i]); - } - } - ga_clear(&new_ga); + arglist_del_files(&new_ga); } else { int i = expand_wildcards(new_ga.ga_len, new_ga.ga_data, &exp_count, &exp_files, @@ -471,22 +475,27 @@ void ex_args(exarg_T *eap) ex_next(eap); } else if (eap->cmdidx == CMD_args) { // ":args": list arguments. - if (ARGCOUNT > 0) { - char **items = xmalloc(sizeof(char *) * (size_t)ARGCOUNT); - // Overwrite the command, for a short list there is no scrolling - // required and no wait_return(). - gotocmdline(true); - for (int i = 0; i < ARGCOUNT; i++) { - items[i] = alist_name(&ARGLIST[i]); - } - list_in_columns(items, ARGCOUNT, curwin->w_arg_idx); - xfree(items); + if (ARGCOUNT <= 0) { + return; } + + char **items = xmalloc(sizeof(char *) * (size_t)ARGCOUNT); + + // Overwrite the command, for a short list there is no scrolling + // required and no wait_return(). + gotocmdline(true); + + for (int i = 0; i < ARGCOUNT; i++) { + items[i] = alist_name(&ARGLIST[i]); + } + list_in_columns(items, ARGCOUNT, curwin->w_arg_idx); + xfree(items); } else if (eap->cmdidx == CMD_arglocal) { garray_T *gap = &curwin->w_alist->al_ga; // ":argslocal": make a local copy of the global argument list. ga_grow(gap, GARGCOUNT); + for (int i = 0; i < GARGCOUNT; i++) { if (GARGLIST[i].ae_fname != NULL) { AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname = xstrdup(GARGLIST[i].ae_fname); @@ -1126,31 +1135,33 @@ void f_argv(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) aentry_T *arglist = NULL; int argcount = -1; - if (argvars[0].v_type != VAR_UNKNOWN) { - if (argvars[1].v_type == VAR_UNKNOWN) { - arglist = ARGLIST; - argcount = ARGCOUNT; - } else if (argvars[1].v_type == VAR_NUMBER - && tv_get_number(&argvars[1]) == -1) { - arglist = GARGLIST; - argcount = GARGCOUNT; - } else { - win_T *wp = find_win_by_nr_or_id(&argvars[1]); - if (wp != NULL) { - // Use the argument list of the specified window - arglist = WARGLIST(wp); - argcount = WARGCOUNT(wp); - } - } - rettv->v_type = VAR_STRING; - rettv->vval.v_string = NULL; - int idx = (int)tv_get_number_chk(&argvars[0], NULL); - if (arglist != NULL && idx >= 0 && idx < argcount) { - rettv->vval.v_string = xstrdup((const char *)alist_name(&arglist[idx])); - } else if (idx == -1) { - get_arglist_as_rettv(arglist, argcount, rettv); - } - } else { + if (argvars[0].v_type == VAR_UNKNOWN) { get_arglist_as_rettv(ARGLIST, ARGCOUNT, rettv); + return; + } + + if (argvars[1].v_type == VAR_UNKNOWN) { + arglist = ARGLIST; + argcount = ARGCOUNT; + } else if (argvars[1].v_type == VAR_NUMBER + && tv_get_number(&argvars[1]) == -1) { + arglist = GARGLIST; + argcount = GARGCOUNT; + } else { + win_T *wp = find_win_by_nr_or_id(&argvars[1]); + if (wp != NULL) { + // Use the argument list of the specified window + arglist = WARGLIST(wp); + argcount = WARGCOUNT(wp); + } + } + + rettv->v_type = VAR_STRING; + rettv->vval.v_string = NULL; + int idx = (int)tv_get_number_chk(&argvars[0], NULL); + if (arglist != NULL && idx >= 0 && idx < argcount) { + rettv->vval.v_string = xstrdup((const char *)alist_name(&arglist[idx])); + } else if (idx == -1) { + get_arglist_as_rettv(arglist, argcount, rettv); } } diff --git a/src/nvim/memory.c b/src/nvim/memory.c index e5fea027cb..03cfde6160 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -506,16 +506,18 @@ bool striequal(const char *a, const char *b) // Did_outofmem_msg is reset when a character is read. void do_outofmem_msg(size_t size) { - if (!did_outofmem_msg) { - // Don't hide this message - emsg_silent = 0; + if (did_outofmem_msg) { + return; + } - /* Must come first to avoid coming back here when printing the error - * message fails, e.g. when setting v:errmsg. */ - did_outofmem_msg = true; + // Don't hide this message + emsg_silent = 0; - semsg(_("E342: Out of memory! (allocating %" PRIu64 " bytes)"), (uint64_t)size); - } + // Must come first to avoid coming back here when printing the error + // message fails, e.g. when setting v:errmsg. + did_outofmem_msg = true; + + semsg(_("E342: Out of memory! (allocating %" PRIu64 " bytes)"), (uint64_t)size); } /// Writes time_t to "buf[8]". -- cgit From f6a8d395a72da61c9305cd242f38bd8137c4f5b0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Sep 2022 22:10:14 +0800 Subject: refactor(ex_cd): add an early return to fix clint warning The popupmenu.c change is unrelated. --- src/nvim/ex_docmd.c | 39 +++++++++++++++++++-------------------- src/nvim/popupmenu.c | 6 +++--- 2 files changed, 22 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 6517ebd081..8fb166d2c9 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -5544,27 +5544,26 @@ void ex_cd(exarg_T *eap) // for non-UNIX ":cd" means: print current directory unless 'cdhome' is set if (*new_dir == NUL && !p_cdh) { ex_pwd(NULL); - } else + return; + } #endif - { - CdScope scope = kCdScopeGlobal; - switch (eap->cmdidx) { - case CMD_tcd: - case CMD_tchdir: - scope = kCdScopeTabpage; - break; - case CMD_lcd: - case CMD_lchdir: - scope = kCdScopeWindow; - break; - default: - break; - } - if (changedir_func(new_dir, scope)) { - // Echo the new current directory if the command was typed. - if (KeyTyped || p_verbose >= 5) { - ex_pwd(eap); - } + CdScope scope = kCdScopeGlobal; + switch (eap->cmdidx) { + case CMD_tcd: + case CMD_tchdir: + scope = kCdScopeTabpage; + break; + case CMD_lcd: + case CMD_lchdir: + scope = kCdScopeWindow; + break; + default: + break; + } + if (changedir_func(new_dir, scope)) { + // Echo the new current directory if the command was typed. + if (KeyTyped || p_verbose >= 5) { + ex_pwd(eap); } } } diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 2265334a45..4de3713f4f 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -1042,14 +1042,14 @@ void pum_show_popupmenu(vimmenu_T *menu) pum_scrollbar = 0; pum_height = pum_size; pum_position_at_mouse(20); + + pum_selected = -1; + pum_first = 0; if (!p_mousemev) { // Pretend 'mousemoveevent' is set. ui_call_option_set(STATIC_CSTR_AS_STRING("mousemoveevent"), BOOLEAN_OBJ(true)); } - pum_selected = -1; - pum_first = 0; - for (;;) { pum_is_visible = true; pum_is_drawn = true; -- cgit From da34833fdfde14287843e9354b63d9cebc052eef Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Sun, 22 May 2022 21:44:50 +0200 Subject: fix: assertion failure when requiring missing module in autocmd Closes https://github.com/neovim/neovim/issues/15348 --- src/nvim/ex_getln.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index da99a03c38..aee06d7045 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -870,7 +870,8 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init if (!tl_ret && ERROR_SET(&err)) { msg_putchar('\n'); - msg_printf_attr(HL_ATTR(HLF_E)|MSG_HIST, (char *)e_autocmd_err, err.msg); + semsg(e_autocmd_err, err.msg); + did_emsg = false; api_clear_error(&err); } -- cgit From 97f38f0a9bbae4969f672746a62caa6cba136b45 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 4 Sep 2022 17:58:33 +0200 Subject: fix(treesitter): do not link @error by default The @error capture is used for tree-sitter's ERROR node, which indicates a parsing error -- which can be quite frequent (and jarring) while typing. Users can still manually `hi link @error Error` in their config. --- src/nvim/highlight_group.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 5c07784db3..412fe3509d 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -186,7 +186,6 @@ static const char *highlight_init_both[] = { "default link DiagnosticSignInfo DiagnosticInfo", "default link DiagnosticSignHint DiagnosticHint", - "default link @error Error", "default link @text.underline Underlined", "default link @todo Todo", "default link @debug Debug", -- cgit From 75adfefc85bcf0d62d2c0f51a951e6003b595cea Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Mon, 18 Jul 2022 14:21:40 +0200 Subject: feat(extmarks,ts,spell): full support for spelling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added 'spell' option to extmarks: Extmarks with this set will have the region spellchecked. - Added 'noplainbuffer' option to 'spelloptions': This is used to tell Neovim not to spellcheck the buffer. The old behaviour was to spell check the whole buffer unless :syntax was set. - Added spelling support to the treesitter highlighter: @spell captures in highlights.scm are used to define regions which should be spell checked. - Added support for navigating spell errors for extmarks: Works for both ephemeral and static extmarks - Added '_on_spell_nav' callback for decoration providers: Since ephemeral callbacks are only drawn for the visible screen, providers must implement this callback to instruct Neovim which regions in the buffer need can be spell checked. The callback takes a start position and an end position. Note: this callback is subject to change hence the _ prefix. - Added spell captures for built-in support languages Co-authored-by: Lewis Russell Co-authored-by: Björn Linse --- src/nvim/api/extmark.c | 65 ++++++++++++++++---------------- src/nvim/api/keysets.lua | 10 +++++ src/nvim/buffer_defs.h | 3 ++ src/nvim/decoration.c | 12 +++++- src/nvim/decoration.h | 7 +++- src/nvim/decoration_provider.c | 33 ++++++++++++++--- src/nvim/decoration_provider.h | 1 + src/nvim/drawline.c | 53 ++++++++++++++------------ src/nvim/drawscreen.c | 2 +- src/nvim/extmark.c | 3 +- src/nvim/option_defs.h | 1 + src/nvim/options.lua | 1 + src/nvim/optionstr.c | 4 +- src/nvim/spell.c | 84 +++++++++++++++++++++++++++++++----------- 14 files changed, 193 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index 6ff0a2ed21..ae051d8cab 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -473,6 +473,8 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e /// When a character is supplied it is used as |:syn-cchar|. /// "hl_group" is used as highlight for the cchar if provided, /// otherwise it defaults to |hl-Conceal|. +/// - spell: boolean indicating that spell checking should be +/// performed within this extmark /// - ui_watched: boolean that indicates the mark should be drawn /// by a UI. When set, the UI will receive win_extmark events. /// Note: the mark is positioned by virt_text attributes. Can be @@ -719,6 +721,11 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer bool ephemeral = false; OPTION_TO_BOOL(ephemeral, ephemeral, false); + OPTION_TO_BOOL(decor.spell, spell, false); + if (decor.spell) { + has_decor = true; + } + OPTION_TO_BOOL(decor.ui_watched, ui_watched, false); if (decor.ui_watched) { has_decor = true; @@ -972,20 +979,21 @@ void nvim_buf_clear_namespace(Buffer buffer, Integer ns_id, Integer line_start, /// for the moment. /// /// @param ns_id Namespace id from |nvim_create_namespace()| -/// @param opts Callbacks invoked during redraw: +/// @param opts Table of callbacks: /// - on_start: called first on each screen redraw /// ["start", tick] -/// - on_buf: called for each buffer being redrawn (before window -/// callbacks) +/// - on_buf: called for each buffer being redrawn (before +/// window callbacks) /// ["buf", bufnr, tick] -/// - on_win: called when starting to redraw a specific window. +/// - on_win: called when starting to redraw a +/// specific window. /// ["win", winid, bufnr, topline, botline_guess] -/// - on_line: called for each buffer line being redrawn. (The -/// interaction with fold lines is subject to change) +/// - on_line: called for each buffer line being redrawn. +/// (The interaction with fold lines is subject to change) /// ["win", winid, bufnr, row] /// - on_end: called at the end of a redraw cycle /// ["end", tick] -void nvim_set_decoration_provider(Integer ns_id, DictionaryOf(LuaRef) opts, Error *err) +void nvim_set_decoration_provider(Integer ns_id, Dict(set_decoration_provider) *opts, Error *err) FUNC_API_SINCE(7) FUNC_API_LUA_ONLY { DecorProvider *p = get_decor_provider((NS)ns_id, true); @@ -997,37 +1005,32 @@ void nvim_set_decoration_provider(Integer ns_id, DictionaryOf(LuaRef) opts, Erro struct { const char *name; + Object *source; LuaRef *dest; } cbs[] = { - { "on_start", &p->redraw_start }, - { "on_buf", &p->redraw_buf }, - { "on_win", &p->redraw_win }, - { "on_line", &p->redraw_line }, - { "on_end", &p->redraw_end }, - { "_on_hl_def", &p->hl_def }, - { NULL, NULL }, + { "on_start", &opts->on_start, &p->redraw_start }, + { "on_buf", &opts->on_buf, &p->redraw_buf }, + { "on_win", &opts->on_win, &p->redraw_win }, + { "on_line", &opts->on_line, &p->redraw_line }, + { "on_end", &opts->on_end, &p->redraw_end }, + { "_on_hl_def", &opts->_on_hl_def, &p->hl_def }, + { "_on_spell_nav", &opts->_on_spell_nav, &p->spell_nav }, + { NULL, NULL, NULL }, }; - for (size_t i = 0; i < opts.size; i++) { - String k = opts.items[i].key; - Object *v = &opts.items[i].value; - size_t j; - for (j = 0; cbs[j].name && cbs[j].dest; j++) { - if (strequal(cbs[j].name, k.data)) { - if (v->type != kObjectTypeLuaRef) { - api_set_error(err, kErrorTypeValidation, - "%s is not a function", cbs[j].name); - goto error; - } - *(cbs[j].dest) = v->data.luaref; - v->data.luaref = LUA_NOREF; - break; - } + for (size_t i = 0; cbs[i].source && cbs[i].dest && cbs[i].name; i++) { + Object *v = cbs[i].source; + if (v->type == kObjectTypeNil) { + continue; } - if (!cbs[j].name) { - api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); + + if (v->type != kObjectTypeLuaRef) { + api_set_error(err, kErrorTypeValidation, + "%s is not a function", cbs[i].name); goto error; } + *(cbs[i].dest) = v->data.luaref; + v->data.luaref = LUA_NOREF; } p->active = true; diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua index af3dc24f51..ea8949bd2c 100644 --- a/src/nvim/api/keysets.lua +++ b/src/nvim/api/keysets.lua @@ -2,6 +2,15 @@ return { context = { "types"; }; + set_decoration_provider = { + "on_start"; + "on_buf"; + "on_win"; + "on_line"; + "on_end"; + "_on_hl_def"; + "_on_spell_nav"; + }; set_extmark = { "id"; "end_line"; @@ -28,6 +37,7 @@ return { "line_hl_group"; "cursorline_hl_group"; "conceal"; + "spell"; "ui_watched"; }; keymap = { diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index c26b18a7e7..a520f3c0e7 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -462,6 +462,9 @@ typedef struct { char *b_p_spf; // 'spellfile' char *b_p_spl; // 'spelllang' char *b_p_spo; // 'spelloptions' +#define SPO_CAMEL 0x1 +#define SPO_NPBUFFER 0x2 + unsigned b_p_spo_flags; // 'spelloptions' flags int b_cjk; // all CJK letters as OK uint8_t b_syn_chartab[32]; // syntax iskeyword option char *b_syn_isk; // iskeyword option diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c index 8955048f45..778f9293fb 100644 --- a/src/nvim/decoration.c +++ b/src/nvim/decoration.c @@ -69,7 +69,7 @@ void bufhl_add_hl_pos_offset(buf_T *buf, int src_id, int hl_id, lpos_T pos_start void decor_redraw(buf_T *buf, int row1, int row2, Decoration *decor) { if (row2 >= row1) { - if (!decor || decor->hl_id || decor_has_sign(decor) || decor->conceal) { + if (!decor || decor->hl_id || decor_has_sign(decor) || decor->conceal || decor->spell) { redraw_buf_range_later(buf, row1 + 1, row2 + 1); } } @@ -116,6 +116,11 @@ void decor_free(Decoration *decor) } } +void decor_state_free(DecorState *state) +{ + xfree(state->active.items); +} + void clear_virttext(VirtText *text) { for (size_t i = 0; i < kv_size(*text); i++) { @@ -306,6 +311,7 @@ next_mark: bool conceal = 0; int conceal_char = 0; int conceal_attr = 0; + bool spell = false; for (size_t i = 0; i < kv_size(state->active); i++) { DecorRange item = kv_A(state->active, i); @@ -339,6 +345,9 @@ next_mark: conceal_attr = item.attr_id; } } + if (active && item.decor.spell) { + spell = true; + } if ((item.start_row == state->row && item.start_col <= col) && decor_virt_pos(item.decor) && item.decor.virt_text_pos == kVTOverlay && item.win_col == -1) { @@ -355,6 +364,7 @@ next_mark: state->conceal = conceal; state->conceal_char = conceal_char; state->conceal_attr = conceal_attr; + state->spell = spell; return attr; } diff --git a/src/nvim/decoration.h b/src/nvim/decoration.h index 8f28442d41..bdbfd72a81 100644 --- a/src/nvim/decoration.h +++ b/src/nvim/decoration.h @@ -46,6 +46,7 @@ struct Decoration { bool hl_eol; bool virt_lines_above; bool conceal; + bool spell; // TODO(bfredl): style, etc DecorPriority priority; int col; // fixed col value, like win_col @@ -61,8 +62,8 @@ struct Decoration { bool ui_watched; // watched for win_extmark }; #define DECORATION_INIT { KV_INITIAL_VALUE, KV_INITIAL_VALUE, 0, kVTEndOfLine, \ - kHlModeUnknown, false, false, false, false, DECOR_PRIORITY_BASE, \ - 0, 0, NULL, 0, 0, 0, 0, 0, false } + kHlModeUnknown, false, false, false, false, false, \ + DECOR_PRIORITY_BASE, 0, 0, NULL, 0, 0, 0, 0, 0, false } typedef struct { int start_row; @@ -90,6 +91,8 @@ typedef struct { bool conceal; int conceal_char; int conceal_attr; + + bool spell; } DecorState; EXTERN DecorState decor_state INIT(= { 0 }); diff --git a/src/nvim/decoration_provider.c b/src/nvim/decoration_provider.c index 14c1238fa4..a11a4d2b04 100644 --- a/src/nvim/decoration_provider.c +++ b/src/nvim/decoration_provider.c @@ -7,6 +7,7 @@ #include "nvim/decoration.h" #include "nvim/decoration_provider.h" #include "nvim/highlight.h" +#include "nvim/lib/kvec.h" #include "nvim/lua/executor.h" static kvec_t(DecorProvider) decor_providers = KV_INITIAL_VALUE; @@ -14,7 +15,7 @@ static kvec_t(DecorProvider) decor_providers = KV_INITIAL_VALUE; #define DECORATION_PROVIDER_INIT(ns_id) (DecorProvider) \ { ns_id, false, LUA_NOREF, LUA_NOREF, \ LUA_NOREF, LUA_NOREF, LUA_NOREF, \ - LUA_NOREF, -1, false } + LUA_NOREF, -1, false, false } static bool decor_provider_invoke(NS ns_id, const char *name, LuaRef ref, Array args, bool default_true, char **perr) @@ -47,11 +48,33 @@ static bool decor_provider_invoke(NS ns_id, const char *name, LuaRef ref, Array return false; } +void decor_providers_invoke_spell(win_T *wp, int start_row, int start_col, int end_row, int end_col, + char **err) +{ + for (size_t i = 0; i < kv_size(decor_providers); i++) { + DecorProvider *p = &kv_A(decor_providers, i); + if (!p->active) { + continue; + } + + if (p->spell_nav != LUA_NOREF) { + MAXSIZE_TEMP_ARRAY(args, 6); + ADD_C(args, INTEGER_OBJ(wp->handle)); + ADD_C(args, INTEGER_OBJ(wp->w_buffer->handle)); + ADD_C(args, INTEGER_OBJ(start_row)); + ADD_C(args, INTEGER_OBJ(start_col)); + ADD_C(args, INTEGER_OBJ(end_row)); + ADD_C(args, INTEGER_OBJ(end_col)); + decor_provider_invoke(p->ns_id, "spell", p->spell_nav, args, true, err); + } + } +} + /// For each provider invoke the 'start' callback /// /// @param[out] providers Decoration providers /// @param[out] err Provider err -void decor_providers_start(DecorProviders *providers, int type, char **err) +void decor_providers_start(DecorProviders *providers, char **err) { kvi_init(*providers); @@ -65,7 +88,6 @@ void decor_providers_start(DecorProviders *providers, int type, char **err) if (p->redraw_start != LUA_NOREF) { MAXSIZE_TEMP_ARRAY(args, 2); ADD_C(args, INTEGER_OBJ((int)display_tick)); - ADD_C(args, INTEGER_OBJ(type)); active = decor_provider_invoke(p->ns_id, "start", p->redraw_start, args, true, err); } else { active = true; @@ -116,8 +138,8 @@ void decor_providers_invoke_win(win_T *wp, DecorProviders *providers, /// @param row Row to invoke line callback for /// @param[out] has_decor Set when at least one provider invokes a line callback /// @param[out] err Provider error -void providers_invoke_line(win_T *wp, DecorProviders *providers, int row, bool *has_decor, - char **err) +void decor_providers_invoke_line(win_T *wp, DecorProviders *providers, int row, bool *has_decor, + char **err) { for (size_t k = 0; k < kv_size(*providers); k++) { DecorProvider *p = kv_A(*providers, k); @@ -215,6 +237,7 @@ void decor_provider_clear(DecorProvider *p) NLUA_CLEAR_REF(p->redraw_win); NLUA_CLEAR_REF(p->redraw_line); NLUA_CLEAR_REF(p->redraw_end); + NLUA_CLEAR_REF(p->spell_nav); p->active = false; } diff --git a/src/nvim/decoration_provider.h b/src/nvim/decoration_provider.h index dd1ed6c581..852b1583b9 100644 --- a/src/nvim/decoration_provider.h +++ b/src/nvim/decoration_provider.h @@ -12,6 +12,7 @@ typedef struct { LuaRef redraw_line; LuaRef redraw_end; LuaRef hl_def; + LuaRef spell_nav; int hl_valid; bool hl_cached; } DecorProvider; diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 85a0bf2f5f..7846510ad9 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -11,9 +11,11 @@ #include "nvim/arabic.h" #include "nvim/buffer.h" +#include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/cursor_shape.h" +#include "nvim/decoration.h" #include "nvim/diff.h" #include "nvim/drawline.h" #include "nvim/fold.h" @@ -654,7 +656,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, has_decor = decor_redraw_line(buf, lnum - 1, &decor_state); - providers_invoke_line(wp, providers, lnum - 1, &has_decor, provider_err); + decor_providers_invoke_line(wp, providers, lnum - 1, &has_decor, provider_err); if (*provider_err) { provider_err_virt_text(lnum, *provider_err); @@ -1646,7 +1648,8 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, ptr++; if (extra_check) { - bool can_spell = true; + bool no_plain_buffer = (wp->w_s->b_p_spo_flags & SPO_NPBUFFER) != 0; + bool can_spell = !no_plain_buffer; // Get syntax attribute, unless still at the start of the line // (double-wide char that doesn't fit). @@ -1698,6 +1701,29 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, char_attr = 0; } + if (has_decor && v > 0) { + bool selected = (area_active || (area_highlighting && noinvcur + && (colnr_T)vcol == wp->w_virtcol)); + int extmark_attr = decor_redraw_col(wp->w_buffer, (colnr_T)v - 1, off, + selected, &decor_state); + if (extmark_attr != 0) { + if (!attr_pri) { + char_attr = hl_combine_attr(char_attr, extmark_attr); + } else { + char_attr = hl_combine_attr(extmark_attr, char_attr); + } + } + + decor_conceal = decor_state.conceal; + if (decor_conceal && decor_state.conceal_char) { + decor_conceal = 2; // really?? + } + + if (decor_state.spell) { + can_spell = true; + } + } + // Check spelling (unless at the end of the line). // Only do this when there is no syntax highlighting, the // @Spell cluster is not used or the current syntax item @@ -1706,9 +1732,9 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (has_spell && v >= word_end && v > cur_checked_col) { spell_attr = 0; if (!attr_pri) { - char_attr = syntax_attr; + char_attr = hl_combine_attr(char_attr, syntax_attr); } - if (c != 0 && (!has_syntax || can_spell)) { + if (c != 0 && ((!has_syntax && !no_plain_buffer) || can_spell)) { char_u *prev_ptr; char_u *p; int len; @@ -1781,25 +1807,6 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, char_attr = hl_combine_attr(term_attrs[vcol], char_attr); } - if (has_decor && v > 0) { - bool selected = (area_active || (area_highlighting && noinvcur - && (colnr_T)vcol == wp->w_virtcol)); - int extmark_attr = decor_redraw_col(wp->w_buffer, (colnr_T)v - 1, off, - selected, &decor_state); - if (extmark_attr != 0) { - if (!attr_pri) { - char_attr = hl_combine_attr(char_attr, extmark_attr); - } else { - char_attr = hl_combine_attr(extmark_attr, char_attr); - } - } - - decor_conceal = decor_state.conceal; - if (decor_conceal && decor_state.conceal_char) { - decor_conceal = 2; // really?? - } - } - // Found last space before word: check for line break. if (wp->w_p_lbr && c0 == c && vim_isbreak(c) && !vim_isbreak((int)(*ptr))) { diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 29ff261461..5b83821927 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -539,7 +539,7 @@ int update_screen(int type) ui_comp_set_screen_valid(true); DecorProviders providers; - decor_providers_start(&providers, type, &provider_err); + decor_providers_start(&providers, &provider_err); // "start" callback could have changed highlights for global elements if (win_check_ns_hl(NULL)) { diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index 8e780f4aaa..290d20b749 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -70,7 +70,8 @@ void extmark_set(buf_T *buf, uint32_t ns_id, uint32_t *idp, int row, colnr_T col || kv_size(decor->virt_lines) || decor->conceal || decor_has_sign(decor) - || decor->ui_watched) { + || decor->ui_watched + || decor->spell) { decor_full = true; decor = xmemdup(decor, sizeof *decor); } diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 64b3f69df4..0684db39ba 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -731,6 +731,7 @@ EXTERN char *p_spc; ///< 'spellcapcheck' EXTERN char *p_spf; ///< 'spellfile' EXTERN char *p_spl; ///< 'spelllang' EXTERN char *p_spo; // 'spelloptions' +EXTERN unsigned int spo_flags; EXTERN char *p_sps; // 'spellsuggest' EXTERN int p_spr; // 'splitright' EXTERN int p_sol; // 'startofline' diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 717ca6747b..49adf03aa0 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -2355,6 +2355,7 @@ return { secure=true, expand=true, varname='p_spo', + redraw={'current_buffer'}, defaults={if_true=""} }, { diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 1bdfcbecb9..c226966ef6 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -107,6 +107,7 @@ static char *(p_fdc_values[]) = { "auto", "auto:1", "auto:2", "auto:3", "auto:4" "auto:6", "auto:7", "auto:8", "auto:9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; static char *(p_cb_values[]) = { "unnamed", "unnamedplus", NULL }; +static char *(p_spo_values[]) = { "camel", "noplainbuffer", NULL }; static char *(p_icm_values[]) = { "nosplit", "split", NULL }; static char *(p_jop_values[]) = { "stack", "view", NULL }; static char *(p_tpf_values[]) = { "BS", "HT", "FF", "ESC", "DEL", "C0", "C1", NULL }; @@ -1125,7 +1126,8 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf // When 'spellcapcheck' is set compile the regexp program. errmsg = compile_cap_prog(curwin->w_s); } else if (varp == &(curwin->w_s->b_p_spo)) { // 'spelloptions' - if (**varp != NUL && STRCMP("camel", *varp) != 0) { + if (opt_strings_flags(curwin->w_s->b_p_spo, p_spo_values, &(curwin->w_s->b_p_spo_flags), + true) != OK) { errmsg = e_invarg; } } else if (varp == &p_sps) { // 'spellsuggest' diff --git a/src/nvim/spell.c b/src/nvim/spell.c index c0d05eb799..30e256b37a 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -71,6 +71,7 @@ #include "nvim/change.h" // for changed_bytes #include "nvim/charset.h" // for skipwhite, getwhitecols, skipbin #include "nvim/cursor.h" // for get_cursor_line_ptr +#include "nvim/decoration.h" #include "nvim/drawscreen.h" // for NOT_VALID, redraw_later #include "nvim/eval/typval.h" // for semsg #include "nvim/ex_cmds.h" // for do_sub_msg @@ -220,7 +221,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou size_t nrlen = 0; // found a number first size_t wrongcaplen = 0; bool count_word = docount; - bool use_camel_case = *wp->w_s->b_p_spo != NUL; + bool use_camel_case = (wp->w_s->b_p_spo_flags & SPO_CAMEL) != 0; bool camel_case = false; // A word never starts at a space or a control character. Return quickly @@ -1198,6 +1199,24 @@ bool no_spell_checking(win_T *wp) return false; } +static void decor_spell_nav_start(win_T *wp) +{ + decor_state = (DecorState){ 0 }; + decor_redraw_reset(wp->w_buffer, &decor_state); +} + +static bool decor_spell_nav_col(win_T *wp, linenr_T lnum, linenr_T *decor_lnum, int col, + char **decor_error) +{ + if (*decor_lnum != lnum) { + decor_providers_invoke_spell(wp, lnum - 1, col, lnum - 1, -1, decor_error); + decor_redraw_line(wp->w_buffer, lnum - 1, &decor_state); + *decor_lnum = lnum; + } + decor_redraw_col(wp->w_buffer, col, col, false, &decor_state); + return decor_state.spell; +} + /// Moves to the next spell error. /// "curline" is false for "[s", "]s", "[S" and "]S". /// "curline" is true to find word under/after cursor in the same line. @@ -1216,11 +1235,11 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att hlf_T attr = HLF_COUNT; size_t len; int has_syntax = syntax_present(wp); - int col; + colnr_T col; char_u *buf = NULL; size_t buflen = 0; int skip = 0; - int capcol = -1; + colnr_T capcol = -1; bool found_one = false; bool wrapped = false; @@ -1228,6 +1247,8 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att return 0; } + size_t ret = 0; + // Start looking for bad word at the start of the line, because we can't // start halfway through a word, we don't know where it starts or ends. // @@ -1240,6 +1261,19 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att linenr_T lnum = wp->w_cursor.lnum; clearpos(&found_pos); + char *decor_error = NULL; + // Ephemeral extmarks are currently stored in the global decor_state. + // When looking for spell errors, we need to: + // - temporarily reset decor_state + // - run the _on_spell_nav decor callback for each line we look at + // - detect if any spell marks are present + // - restore decor_state to the value saved here. + // TODO(lewis6991): un-globalize decor_state and allow ephemeral marks to be stored into a + // temporary DecorState. + DecorState saved_decor_start = decor_state; + linenr_T decor_lnum = -1; + decor_spell_nav_start(wp); + while (!got_int) { char_u *line = ml_get_buf(wp->w_buffer, lnum, false); @@ -1258,10 +1292,10 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att // For checking first word with a capital skip white space. if (capcol == 0) { - capcol = (int)getwhitecols((char *)line); + capcol = (colnr_T)getwhitecols((char *)line); } else if (curline && wp == curwin) { // For spellbadword(): check if first word needs a capital. - col = (int)getwhitecols((char *)line); + col = (colnr_T)getwhitecols((char *)line); if (check_need_cap(lnum, col)) { capcol = col; } @@ -1308,33 +1342,37 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att || ((colnr_T)(curline ? p - buf + (ptrdiff_t)len : p - buf) > wp->w_cursor.col)) { - bool can_spell; - if (has_syntax) { - col = (int)(p - buf); - (void)syn_get_id(wp, lnum, (colnr_T)col, - false, &can_spell, false); - if (!can_spell) { - attr = HLF_COUNT; - } - } else { - can_spell = true; + col = (colnr_T)(p - buf); + + bool can_spell = (wp->w_s->b_p_spo_flags & SPO_NPBUFFER) == 0; + + if (!can_spell) { + can_spell = decor_spell_nav_col(wp, lnum, &decor_lnum, col, &decor_error); + } + + if (!can_spell && has_syntax) { + (void)syn_get_id(wp, lnum, col, false, &can_spell, false); + } + + if (!can_spell) { + attr = HLF_COUNT; } if (can_spell) { found_one = true; found_pos = (pos_T) { .lnum = lnum, - .col = (int)(p - buf), + .col = col, .coladd = 0 }; if (dir == FORWARD) { // No need to search further. wp->w_cursor = found_pos; - xfree(buf); if (attrp != NULL) { *attrp = attr; } - return len; + ret = len; + goto theend; } else if (curline) { // Insert mode completion: put cursor after // the bad word. @@ -1358,8 +1396,8 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att if (dir == BACKWARD && found_pos.lnum != 0) { // Use the last match in the line (before the cursor). wp->w_cursor = found_pos; - xfree(buf); - return found_len; + ret = found_len; + goto theend; } if (curline) { @@ -1429,8 +1467,12 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att line_breakcheck(); } +theend: + decor_state_free(&decor_state); + xfree(decor_error); + decor_state = saved_decor_start; xfree(buf); - return 0; + return ret; } // For spell checking: concatenate the start of the following line "line" into -- cgit From 74db632c978cc391c70d13673b468f80c452d932 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 8 Feb 2022 18:58:36 +0100 Subject: refactor(term): use const for title and add len to buf_set_term_title() --- src/nvim/terminal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 90966bcfad..125e4cb586 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -230,7 +230,7 @@ Terminal *terminal_open(buf_T *buf, TerminalOptions opts) set_option_value("wrap", false, NULL, OPT_LOCAL); set_option_value("list", false, NULL, OPT_LOCAL); if (buf->b_ffname != NULL) { - buf_set_term_title(buf, buf->b_ffname); + buf_set_term_title(buf, buf->b_ffname, strlen((char *)buf->b_ffname)); } RESET_BINDING(curwin); // Reset cursor in current window. @@ -858,13 +858,13 @@ static int term_movecursor(VTermPos new, VTermPos old, int visible, void *data) return 1; } -static void buf_set_term_title(buf_T *buf, char *title) +static void buf_set_term_title(buf_T *buf, const char *title, size_t len) FUNC_ATTR_NONNULL_ALL { Error err = ERROR_INIT; dict_set_var(buf->b_vars, STATIC_CSTR_AS_STRING("term_title"), - STRING_OBJ(cstr_as_string(title)), + STRING_OBJ(((String){ .data = (char *)title, .size = len })), false, false, &err); @@ -887,7 +887,7 @@ static int term_settermprop(VTermProp prop, VTermValue *val, void *data) case VTERM_PROP_TITLE: { buf_T *buf = handle_get_buffer(term->buf_handle); - buf_set_term_title(buf, val->string); + buf_set_term_title(buf, val->string, strlen(val->string)); break; } -- cgit From 12afc344deb2df3973904fe55813d700da985dbf Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 6 Sep 2022 16:23:00 +0200 Subject: refactor: migrate comment style 2 #20080 --- src/nvim/buffer_defs.h | 16 +++---- src/nvim/edit.c | 12 ++--- src/nvim/file_search.c | 92 +++++++++++++++++--------------------- src/nvim/fileio.c | 83 +++++++++++++++++------------------ src/nvim/hardcopy.c | 36 +++++++-------- src/nvim/mark_defs.h | 2 +- src/nvim/memline.c | 2 +- src/nvim/memline_defs.h | 2 +- src/nvim/ops.c | 33 +++++++------- src/nvim/option_defs.h | 2 +- src/nvim/path.c | 114 ++++++++++++++++++++++++------------------------ src/nvim/sign_defs.h | 2 +- src/nvim/spellfile.c | 2 +- src/nvim/strings.c | 8 ++-- src/nvim/window.c | 4 +- 15 files changed, 196 insertions(+), 214 deletions(-) (limited to 'src') diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index a520f3c0e7..3019a1323c 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -789,8 +789,8 @@ struct file_buffer { int b_ind_cpp_extern_c; int b_ind_pragma; - linenr_T b_no_eol_lnum; /* non-zero lnum when last line of next binary - * write should not have an end-of-line */ + linenr_T b_no_eol_lnum; // non-zero lnum when last line of next binary + // write should not have an end-of-line int b_start_eol; // last line had eol when it was read int b_start_ffc; // first char of 'ff' when edit started @@ -805,8 +805,8 @@ struct file_buffer { // then set to indicate that a swap file may be opened later. It is reset // if a swap file could not be opened. bool b_may_swap; - bool b_did_warn; /* Set to true if user has been warned on first - change of a read-only file */ + bool b_did_warn; // Set to true if user has been warned on first + // change of a read-only file // Two special kinds of buffers: // help buffer - used for help files, won't use a swap file. @@ -1237,8 +1237,7 @@ struct window_S { // w_valid is a bitfield of flags, which indicate if specific values are // valid or need to be recomputed. int w_valid; - pos_T w_valid_cursor; /* last known position of w_cursor, used - to adjust w_valid */ + pos_T w_valid_cursor; // last known position of w_cursor, used to adjust w_valid colnr_T w_valid_leftcol; // last known w_leftcol bool w_viewport_invalid; @@ -1383,8 +1382,7 @@ struct window_S { int w_fraction; int w_prev_fraction_row; - linenr_T w_nrwidth_line_count; /* line count when ml_nrwidth_width - * was computed. */ + linenr_T w_nrwidth_line_count; // line count when ml_nrwidth_width was computed. int w_nrwidth_width; // nr of chars to print line count. qf_info_T *w_llist; // Location list for this window @@ -1407,4 +1405,4 @@ struct window_S { #define CHANGEDTICK(buf) \ (=== Include buffer.h & use buf_(get|set|inc) _changedtick ===) -#endif // NVIM_BUFFER_DEFS_H +#endif // NVIM_BUFFER_DEFS_H diff --git a/src/nvim/edit.c b/src/nvim/edit.c index b85d349726..b20fc7d44a 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2330,8 +2330,8 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove) if (gchar_cursor() != NUL) { inc_cursor(); } - /* If the cursor is still at the same character, also keep - * the "coladd". */ + // If the cursor is still at the same character, also keep + // the "coladd". if (gchar_cursor() == NUL && curwin->w_cursor.lnum == tpos.lnum && curwin->w_cursor.col == tpos.col) { @@ -3165,8 +3165,8 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) if (keytyped == KEY_COMPLETE) { char_u *n, *s; - /* Just completed a word, check if it starts with "look". - * search back for the start of a word. */ + // Just completed a word, check if it starts with "look". + // search back for the start of a word. line = (char_u *)get_cursor_line_ptr(); for (s = line + curwin->w_cursor.col; s > line; s = n) { n = mb_prevptr(line, s); @@ -3198,8 +3198,8 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) } } if (match && try_match_word && !try_match) { - /* "0=word": Check if there are only blanks before the - * word. */ + // "0=word": Check if there are only blanks before the + // word. if (getwhitecols_curline() != (int)(curwin->w_cursor.col - (p - look))) { match = false; diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index a604c5ff3e..76a429b5ef 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -75,9 +75,8 @@ static char_u *ff_expand_buffer = NULL; // used for expanding filenames typedef struct ff_stack { struct ff_stack *ffs_prev; - /* the fix part (no wildcards) and the part containing the wildcards - * of the search path - */ + // the fix part (no wildcards) and the part containing the wildcards + // of the search path char_u *ffs_fix_path; char_u *ffs_wc_path; @@ -87,15 +86,13 @@ typedef struct ff_stack { int ffs_filearray_size; int ffs_filearray_cur; // needed for partly handled dirs - /* to store status of partly handled directories - * 0: we work on this directory for the first time - * 1: this directory was partly searched in an earlier step - */ + // to store status of partly handled directories + // 0: we work on this directory for the first time + // 1: this directory was partly searched in an earlier step int ffs_stage; - /* How deep are we in the directory tree? - * Counts backward from value of level parameter to vim_findfile_init - */ + // How deep are we in the directory tree? + // Counts backward from value of level parameter to vim_findfile_init int ffs_level; // Did we already expand '**' to an empty string? @@ -242,9 +239,8 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i ff_stack_T *sptr; ff_search_ctx_T *search_ctx; - /* If a search context is given by the caller, reuse it, else allocate a - * new one. - */ + // If a search context is given by the caller, reuse it, else allocate a + // new one. if (search_ctx_arg != NULL) { search_ctx = search_ctx_arg; } else { @@ -260,9 +256,9 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i if (free_visited == true) { vim_findfile_free_visited(search_ctx); } else { - /* Reuse old visited lists. Get the visited list for the given - * filename. If no list for the current filename exists, creates a new - * one. */ + // Reuse old visited lists. Get the visited list for the given + // filename. If no list for the current filename exists, creates a new + // one. search_ctx->ffsc_visited_list = ff_get_visited_list((char_u *)filename, &search_ctx->ffsc_visited_lists_list); if (search_ctx->ffsc_visited_list == NULL) { @@ -279,8 +275,8 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i ff_expand_buffer = xmalloc(MAXPATHL); } - /* Store information on starting dir now if path is relative. - * If path is absolute, we do that later. */ + // Store information on starting dir now if path is relative. + // If path is absolute, we do that later. if (path[0] == '.' && (vim_ispathsep(path[1]) || path[1] == NUL) && (!tagfile || vim_strchr(p_cpo, CPO_DOTTAG) == NULL) @@ -321,8 +317,8 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i search_ctx->ffsc_start_dir = (char *)vim_strsave(ff_expand_buffer); #ifdef BACKSLASH_IN_FILENAME - /* A path that starts with "/dir" is relative to the drive, not to the - * directory (but not for "//machine/dir"). Only use the drive name. */ + // A path that starts with "/dir" is relative to the drive, not to the + // directory (but not for "//machine/dir"). Only use the drive name. if ((*path == '/' || *path == '\\') && path[1] != path[0] && search_ctx->ffsc_start_dir[1] == ':') { @@ -362,9 +358,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i search_ctx->ffsc_stopdirs_v[dircount - 1] = xstrnsave(helper, (size_t)(walker - helper)); walker++; } else { - /* this might be "", which means ascent till top - * of directory tree. - */ + // this might be "", which means ascent till top of directory tree. search_ctx->ffsc_stopdirs_v[dircount - 1] = xstrdup(helper); } @@ -375,10 +369,9 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i search_ctx->ffsc_level = level; - /* split into: - * -fix path - * -wildcard_stuff (might be NULL) - */ + // split into: + // -fix path + // -wildcard_stuff (might be NULL) wc_part = vim_strchr(path, '*'); if (wc_part != NULL) { int64_t llevel; @@ -433,9 +426,8 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i } if (search_ctx->ffsc_start_dir == NULL) { - /* store the fix part as startdir. - * This is needed if the parameter path is fully qualified. - */ + // store the fix part as startdir. + // This is needed if the parameter path is fully qualified. search_ctx->ffsc_start_dir = xstrdup(search_ctx->ffsc_fix_path); search_ctx->ffsc_fix_path[0] = NUL; } @@ -513,8 +505,8 @@ char_u *vim_findfile_stopdir(char_u *buf) while (*r_ptr != NUL && *r_ptr != ';') { if (r_ptr[0] == '\\' && r_ptr[1] == ';') { - /* Overwrite the escape char, - * use STRLEN(r_ptr) to move the trailing '\0'. */ + // Overwrite the escape char, + // use STRLEN(r_ptr) to move the trailing '\0'. STRMOVE(r_ptr, r_ptr + 1); r_ptr++; } @@ -653,9 +645,7 @@ char_u *vim_findfile(void *search_ctx_arg) if (stackp->ffs_filearray == NULL) { char *dirptrs[2]; - /* we use filepath to build the path expand_wildcards() should - * expand. - */ + // we use filepath to build the path expand_wildcards() should expand. dirptrs[0] = (char *)file_path; dirptrs[1] = NULL; @@ -742,9 +732,9 @@ char_u *vim_findfile(void *search_ctx_arg) stackp->ffs_filearray[0] = xstrdup(dirptrs[0]); stackp->ffs_filearray_size = 1; } else { - /* Add EW_NOTWILD because the expanded path may contain - * wildcard characters that are to be taken literally. - * This is a bit of a hack. */ + // Add EW_NOTWILD because the expanded path may contain + // wildcard characters that are to be taken literally. + // This is a bit of a hack. expand_wildcards((dirptrs[1] == NULL) ? 1 : 2, dirptrs, &stackp->ffs_filearray_size, &stackp->ffs_filearray, @@ -886,9 +876,8 @@ char_u *vim_findfile(void *search_ctx_arg) ff_free_stack_element(stackp); } - /* If we reached this, we didn't find anything downwards. - * Let's check if we should do an upward search. - */ + // If we reached this, we didn't find anything downwards. + // Let's check if we should do an upward search. if (search_ctx->ffsc_start_dir && search_ctx->ffsc_stopdirs_v != NULL && !got_int) { ff_stack_T *sptr; @@ -1157,8 +1146,8 @@ static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, in /// Push a dir on the directory stack. static void ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr) { - /* check for NULL pointer, not to return an error to the user, but - * to prevent a crash */ + // check for NULL pointer, not to return an error to the user, but + // to prevent a crash if (stack_ptr != NULL) { stack_ptr->ffs_prev = search_ctx->ffsc_stack_ptr; search_ctx->ffsc_stack_ptr = stack_ptr; @@ -1251,10 +1240,9 @@ static int ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v) for (i = 0; stopdirs_v[i] != NULL; i++) { if ((int)STRLEN(stopdirs_v[i]) > path_len) { - /* match for parent directory. So '/home' also matches - * '/home/rks'. Check for PATHSEP in stopdirs_v[i], else - * '/home/r' would also match '/home/rks' - */ + // match for parent directory. So '/home' also matches + // '/home/rks'. Check for PATHSEP in stopdirs_v[i], else + // '/home/r' would also match '/home/rks' if (FNAMENCMP(stopdirs_v[i], path, path_len) == 0 && vim_ispathsep(stopdirs_v[i][path_len])) { return true; @@ -1407,8 +1395,8 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first goto theend; } - /* When FNAME_REL flag given first use the directory of the file. - * Otherwise or when this fails use the current directory. */ + // When FNAME_REL flag given first use the directory of the file. + // Otherwise or when this fails use the current directory. for (int run = 1; run <= 2; run++) { size_t l = STRLEN(ff_file_to_find); if (run == 1 @@ -1424,8 +1412,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first run = 2; } - /* When the file doesn't exist, try adding parts of - * 'suffixesadd'. */ + // When the file doesn't exist, try adding parts of 'suffixesadd'. buf = (char *)suffixes; for (;;) { if ( @@ -1467,8 +1454,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first char_u *r_ptr; if (dir == NULL || *dir == NUL) { - /* We searched all paths of the option, now we can - * free the search context. */ + // We searched all paths of the option, now we can free the search context. vim_findfile_cleanup(fdip_search_ctx); fdip_search_ctx = NULL; break; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index a29a0efe40..b399885095 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -82,12 +82,12 @@ #define FIO_UCSBOM 0x4000 // check for BOM at start of file #define FIO_ALL (-1) // allow all formats -/* When converting, a read() or write() may leave some bytes to be converted - * for the next call. The value is guessed... */ +// When converting, a read() or write() may leave some bytes to be converted +// for the next call. The value is guessed... #define CONV_RESTLEN 30 -/* We have to guess how much a sequence of bytes may expand when converting - * with iconv() to be able to allocate a buffer. */ +// We have to guess how much a sequence of bytes may expand when converting +// with iconv() to be able to allocate a buffer. #define ICONV_MULT 8 // Structure to pass arguments from buf_write() to buf_write_bytes(). @@ -2091,8 +2091,8 @@ static void check_marks_read(void) shada_read_marks(); } - /* Always set b_marks_read; needed when 'shada' is changed to include - * the ' parameter after opening a buffer. */ + // Always set b_marks_read; needed when 'shada' is changed to include + // the ' parameter after opening a buffer. curbuf->b_marks_read = true; } @@ -2177,8 +2177,8 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en int wb_flags = 0; #endif #ifdef HAVE_ACL - vim_acl_T acl = NULL; /* ACL copied from original file to - backup or new file */ + vim_acl_T acl = NULL; // ACL copied from original file to + // backup or new file #endif int write_undo_file = false; context_sha256_T sha_ctx; @@ -2190,8 +2190,8 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en return FAIL; } if (buf->b_ml.ml_mfp == NULL) { - /* This can happen during startup when there is a stray "w" in the - * vimrc file. */ + // This can happen during startup when there is a stray "w" in the + // vimrc file. emsg(_(e_emptybuf)); return FAIL; } @@ -2217,8 +2217,8 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en write_info.bw_iconv_fd = (iconv_t)-1; #endif - /* After writing a file changedtick changes but we don't want to display - * the line. */ + // After writing a file changedtick changes but we don't want to display + // the line. ex_no_reprint = true; // If there is no file name yet, use the one for the written file. @@ -2318,9 +2318,9 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en sfname, sfname, false, curbuf, eap); if (did_cmd) { if (was_changed && !curbufIsChanged()) { - /* Written everything correctly and BufWriteCmd has reset - * 'modified': Correct the undo information so that an - * undo now sets 'modified'. */ + // Written everything correctly and BufWriteCmd has reset + // 'modified': Correct the undo information so that an + // undo now sets 'modified'. u_unchanged(curbuf); u_update_save_nr(curbuf); } @@ -2371,14 +2371,14 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en if (nofile_err || aborting()) { - /* An aborting error, interrupt or exception in the - * autocommands. */ + // An aborting error, interrupt or exception in the + // autocommands. return FAIL; } if (did_cmd) { if (buf == NULL) { - /* The buffer was deleted. We assume it was written - * (can't retry anyway). */ + // The buffer was deleted. We assume it was written + // (can't retry anyway). return OK; } if (overwriting) { @@ -2488,8 +2488,8 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en SET_ERRMSG_NUM("E503", _("is not a file or writable device")); goto fail; } - /* It's a device of some kind (or a fifo) which we can write to - * but for which we can't make a backup. */ + // It's a device of some kind (or a fifo) which we can write to + // but for which we can't make a backup. device = true; newfile = true; perm = -1; @@ -2616,8 +2616,8 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en backup_copy = true; } #endif - /* Close the file before removing it, on MS-Windows we - * can't delete an open file. */ + // Close the file before removing it, on MS-Windows we + // can't delete an open file. close(fd); os_remove((char *)IObuff); } @@ -3433,8 +3433,8 @@ restore_backup: set_keep_msg(msg_trunc_attr((char *)IObuff, false, 0), 0); } - /* When written everything correctly: reset 'modified'. Unless not - * writing to the original file and '+' is not in 'cpoptions'. */ + // When written everything correctly: reset 'modified'. Unless not + // writing to the original file and '+' is not in 'cpoptions'. if (reset_changed && whole && !append && !write_info.bw_conv_error && (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL)) { @@ -3815,9 +3815,9 @@ static int buf_write_bytes(struct bw_info *ip) if (wlen == 0 && ip->bw_restlen != 0) { int l; - /* Use remainder of previous call. Append the start of - * buf[] to get a full sequence. Might still be too - * short! */ + // Use remainder of previous call. Append the start of + // buf[] to get a full sequence. Might still be too + // short! l = CONV_RESTLEN - ip->bw_restlen; if (l > len) { l = len; @@ -3825,9 +3825,9 @@ static int buf_write_bytes(struct bw_info *ip) memmove(ip->bw_rest + ip->bw_restlen, buf, (size_t)l); n = utf_ptr2len_len(ip->bw_rest, ip->bw_restlen + l); if (n > ip->bw_restlen + len) { - /* We have an incomplete byte sequence at the end to - * be written. We can't convert it without the - * remaining bytes. Keep them for the next call. */ + // We have an incomplete byte sequence at the end to + // be written. We can't convert it without the + // remaining bytes. Keep them for the next call. if (ip->bw_restlen + len > CONV_RESTLEN) { return FAIL; } @@ -3851,9 +3851,9 @@ static int buf_write_bytes(struct bw_info *ip) } else { n = utf_ptr2len_len(buf + wlen, len - wlen); if (n > len - wlen) { - /* We have an incomplete byte sequence at the end to - * be written. We can't convert it without the - * remaining bytes. Keep them for the next call. */ + // We have an incomplete byte sequence at the end to + // be written. We can't convert it without the + // remaining bytes. Keep them for the next call. if (len - wlen > CONV_RESTLEN) { return FAIL; } @@ -3896,9 +3896,9 @@ static int buf_write_bytes(struct bw_info *ip) if (ip->bw_restlen > 0) { char *fp; - /* Need to concatenate the remainder of the previous call and - * the bytes of the current call. Use the end of the - * conversion buffer for this. */ + // Need to concatenate the remainder of the previous call and + // the bytes of the current call. Use the end of the + // conversion buffer for this. fromlen = (size_t)len + (size_t)ip->bw_restlen; fp = (char *)ip->bw_conv_buf + ip->bw_conv_buflen - fromlen; memmove(fp, ip->bw_rest, (size_t)ip->bw_restlen); @@ -3918,9 +3918,8 @@ static int buf_write_bytes(struct bw_info *ip) // output the initial shift state sequence (void)iconv(ip->bw_iconv_fd, NULL, NULL, &to, &tolen); - /* There is a bug in iconv() on Linux (which appears to be - * wide-spread) which sets "to" to NULL and messes up "tolen". - */ + // There is a bug in iconv() on Linux (which appears to be + // wide-spread) which sets "to" to NULL and messes up "tolen". if (to == NULL) { to = (char *)ip->bw_conv_buf; tolen = save_len; @@ -3984,8 +3983,8 @@ static bool ucs2bytes(unsigned c, char_u **pp, int flags) FUNC_ATTR_NONNULL_ALL } else if (flags & (FIO_UCS2 | FIO_UTF16)) { if (c >= 0x10000) { if (flags & FIO_UTF16) { - /* Make two words, ten bits of the character in each. First - * word is 0xd800 - 0xdbff, second one 0xdc00 - 0xdfff */ + // Make two words, ten bits of the character in each. First + // word is 0xd800 - 0xdbff, second one 0xdc00 - 0xdfff c -= 0x10000; if (c >= 0x100000) { error = true; diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index e280648fd2..85f59f39de 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -176,8 +176,8 @@ struct prt_ps_font_S { char *(ps_fontname[4]); }; -/* Structures to map user named encoding and mapping to PS equivalents for - * building CID font name */ +// Structures to map user named encoding and mapping to PS equivalents for +// building CID font name struct prt_ps_encoding_S { char *encoding; char *cmap_encoding; @@ -235,8 +235,8 @@ struct prt_dsc_line_S { int len; }; -/* Static buffer to read initial comments in a resource file, some can have a - * couple of KB of comments! */ +// Static buffer to read initial comments in a resource file, some can have a +// couple of KB of comments! #define PRT_FILE_BUFFER_LEN (2048) struct prt_resfile_buffer_S { char_u buffer[PRT_FILE_BUFFER_LEN]; @@ -1162,16 +1162,15 @@ static struct prt_ps_mbfont_S prt_ps_mbfonts[] = } }; -/* The PS prolog file version number has to match - if the prolog file is - * updated, increment the number in the file and here. Version checking was - * added as of VIM 6.2. - * The CID prolog file version number behaves as per PS prolog. - * Table of VIM and prolog versions: - * - * VIM Prolog CIDProlog - * 6.2 1.3 - * 7.0 1.4 1.0 - */ +// The PS prolog file version number has to match - if the prolog file is +// updated, increment the number in the file and here. Version checking was +// added as of VIM 6.2. +// The CID prolog file version number behaves as per PS prolog. +// Table of VIM and prolog versions: +// +// VIM Prolog CIDProlog +// 6.2 1.3 +// 7.0 1.4 1.0 #define PRT_PROLOG_VERSION ((char_u *)"1.4") #define PRT_CID_PROLOG_VERSION ((char_u *)"1.0") @@ -1182,8 +1181,8 @@ static struct prt_ps_mbfont_S prt_ps_mbfonts[] = #define PRT_RESOURCE_ENCODING "Encoding" #define PRT_RESOURCE_CMAP "CMap" -/* Data for table based DSC comment recognition, easy to extend if VIM needs to - * read more comments. */ +// Data for table based DSC comment recognition, easy to extend if VIM needs to +// read more comments. #define PRT_DSC_MISC_TYPE (-1) #define PRT_DSC_TITLE_TYPE (1) #define PRT_DSC_VERSION_TYPE (2) @@ -1573,8 +1572,9 @@ static int prt_resfile_skip_ws(int offset) return -1; } -/* prt_next_dsc() - returns detail on next DSC comment line found. Returns true - * if a DSC comment is found, else false */ +/// Returns detail on next DSC comment line found. +/// +/// @return true if a DSC comment is found, else false static bool prt_next_dsc(struct prt_dsc_line_S *p_dsc_line) FUNC_ATTR_NONNULL_ALL { diff --git a/src/nvim/mark_defs.h b/src/nvim/mark_defs.h index 3e3a46cd20..f9df0028db 100644 --- a/src/nvim/mark_defs.h +++ b/src/nvim/mark_defs.h @@ -86,4 +86,4 @@ typedef struct xfilemark { #define INIT_XFMARK { INIT_FMARK, NULL } -#endif // NVIM_MARK_DEFS_H +#endif // NVIM_MARK_DEFS_H diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 35650755b4..c5e8e3da07 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1161,7 +1161,7 @@ theend: } mf_close(mfp, false); // will also xfree(mfp->mf_fname) } - if (buf != NULL) { //may be NULL if swap file not found. + if (buf != NULL) { // may be NULL if swap file not found. xfree(buf->b_ml.ml_stack); xfree(buf); } diff --git a/src/nvim/memline_defs.h b/src/nvim/memline_defs.h index 922a2c98d1..552ec1e3a9 100644 --- a/src/nvim/memline_defs.h +++ b/src/nvim/memline_defs.h @@ -69,4 +69,4 @@ typedef struct memline { int ml_usedchunks; } memline_T; -#endif // NVIM_MEMLINE_DEFS_H +#endif // NVIM_MEMLINE_DEFS_H diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 25b957e3b9..5d505f41a2 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -681,9 +681,9 @@ void op_reindent(oparg_T *oap, Indenter how) curwin->w_cursor.lnum = start_lnum; beginline(BL_SOL | BL_FIX); - /* Mark changed lines so that they will be redrawn. When Visual - * highlighting was present, need to continue until the last line. When - * there is no change still need to remove the Visual highlighting. */ + // Mark changed lines so that they will be redrawn. When Visual + // highlighting was present, need to continue until the last line. When + // there is no change still need to remove the Visual highlighting. if (last_changed != 0) { changed_lines(first_changed, 0, oap->is_VIsual ? start_lnum + (linenr_T)oap->line_count : @@ -748,12 +748,12 @@ char_u *get_expr_line(void) return NULL; } - /* Make a copy of the expression, because evaluating it may cause it to be - * changed. */ + // Make a copy of the expression, because evaluating it may cause it to be + // changed. expr_copy = vim_strsave(expr_line); - /* When we are invoked recursively limit the evaluation to 10 levels. - * Then return the string as-is. */ + // When we are invoked recursively limit the evaluation to 10 levels. + // Then return the string as-is. if (nested >= 10) { return expr_copy; } @@ -1431,8 +1431,8 @@ bool cmdline_paste_reg(int regname, bool literally_arg, bool remcr) cmdline_paste_str((char_u *)"\r", literally); } - /* Check for CTRL-C, in case someone tries to paste a few thousand - * lines and gets bored. */ + // Check for CTRL-C, in case someone tries to paste a few thousand + // lines and gets bored. os_breakcheck(); if (got_int) { return FAIL; @@ -2677,8 +2677,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) if (virtual_op) { getvcol(curwin, &oap->start, &cs, NULL, &ce); if (ce != cs && oap->start.coladd > 0) { - /* Part of a tab selected -- but don't - * double-count it. */ + // Part of a tab selected -- but don't double-count it. bd.startspaces = (ce - cs + 1) - oap->start.coladd; startcol++; @@ -3043,9 +3042,9 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (insert_string != NULL) { y_type = kMTCharWise; if (regname == '=') { - /* For the = register we need to split the string at NL - * characters. - * Loop twice: count the number of lines and save them. */ + // For the = register we need to split the string at NL + // characters. + // Loop twice: count the number of lines and save them. for (;;) { y_size = 0; ptr = insert_string; @@ -3285,9 +3284,9 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) delcount = 1; bd.textcol -= utf_head_off(oldp, oldp + bd.textcol); if (oldp[bd.textcol] != TAB) { - /* Only a Tab can be split into spaces. Other - * characters will have to be moved to after the - * block, causing misalignment. */ + // Only a Tab can be split into spaces. Other + // characters will have to be moved to after the + // block, causing misalignment. delcount = 0; bd.endspaces = 0; } diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 0684db39ba..031a853c0c 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -990,4 +990,4 @@ typedef struct { uint64_t channel_id; /// Only used when script_id is SID_API_CLIENT. } LastSet; -#endif // NVIM_OPTION_DEFS_H +#endif // NVIM_OPTION_DEFS_H diff --git a/src/nvim/path.c b/src/nvim/path.c index 1e5fa49ad6..2646b9e75e 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -625,8 +625,8 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, char_u *e = NULL; const char_u *path_end = path; while (*path_end != NUL) { - /* May ignore a wildcard that has a backslash before it; it will - * be removed by rem_backslash() or file_pat_to_reg_pat() below. */ + // May ignore a wildcard that has a backslash before it; it will + // be removed by rem_backslash() or file_pat_to_reg_pat() below. if (path_end >= path + wildoff && rem_backslash((char *)path_end)) { *p++ = *path_end++; } else if (vim_ispathsep_nocolon(*path_end)) { @@ -651,8 +651,8 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, *e = NUL; // Now we have one wildcard component between "s" and "e". - /* Remove backslashes between "wildoff" and the start of the wildcard - * component. */ + // Remove backslashes between "wildoff" and the start of the wildcard + // component. for (p = buf + wildoff; p < s; p++) { if (rem_backslash((char *)p)) { STRMOVE(p, p + 1); @@ -698,8 +698,8 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, return 0; } - /* If "**" is by itself, this is the first time we encounter it and more - * is following then find matches without any directory. */ + // If "**" is by itself, this is the first time we encounter it and more + // is following then find matches without any directory. if (!didstar && stardepth < 100 && starstar && e - s == 2 && *path_end == '/') { STRCPY(s, path_end + 1); @@ -728,9 +728,9 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, len = STRLEN(buf); if (starstar && stardepth < 100) { - /* For "**" in the pattern first go deeper in the tree to - * find matches. */ - STRCPY(buf + len, "/**"); + // For "**" in the pattern first go deeper in the tree to + // find matches. + STRCPY(buf + len, "/**"); // NOLINT STRCPY(buf + len + 3, path_end); stardepth++; (void)do_path_expand(gap, buf, len + 1, flags, true); @@ -835,9 +835,9 @@ static void expand_path_option(char_u *curdir, garray_T *gap) copy_option_part((char **)&path_option, (char *)buf, MAXPATHL, " ,"); if (buf[0] == '.' && (buf[1] == NUL || vim_ispathsep(buf[1]))) { - /* Relative to current buffer: - * "/path/file" + "." -> "/path/" - * "/path/file" + "./subdir" -> "/path/subdir" */ + // Relative to current buffer: + // "/path/file" + "." -> "/path/" + // "/path/file" + "./subdir" -> "/path/subdir" if (curbuf->b_ffname == NULL) { continue; } @@ -1028,8 +1028,8 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) continue; } - /* If the {filename} is not unique, change it to ./{filename}. - * Else reduce it to {filename} */ + // If the {filename} is not unique, change it to ./{filename}. + // Else reduce it to {filename} short_name = path_shorten_fname(path, curdir); if (short_name == NULL) { short_name = path; @@ -1278,8 +1278,8 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i && (vim_ispathsep(p[1]) || (p[1] == '.' && vim_ispathsep(p[2]))))) { - /* :find completion where 'path' is used. - * Recursiveness is OK here. */ + // :find completion where 'path' is used. + // Recursiveness is OK here. recursive = false; add_pat = expand_in_path(&ga, p, flags); recursive = true; @@ -1295,8 +1295,8 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i if (add_pat == -1 || (add_pat == 0 && (flags & EW_NOTFOUND))) { char_u *t = (char_u *)backslash_halve_save((char *)p); - /* When EW_NOTFOUND is used, always add files and dirs. Makes - * "vim c:/" work. */ + // When EW_NOTFOUND is used, always add files and dirs. Makes + // "vim c:/" work. if (flags & EW_NOTFOUND) { addfile(&ga, t, flags | EW_DIR | EW_FILE); } else { @@ -1505,8 +1505,8 @@ void simplify_filename(char_u *filename) start = p; // remember start after "c:/" or "/" or "///" do { - /* At this point "p" is pointing to the char following a single "/" - * or "p" is at the "start" of the (absolute or relative) path name. */ + // At this point "p" is pointing to the char following a single "/" + // or "p" is at the "start" of the (absolute or relative) path name. if (vim_ispathsep(*p)) { STRMOVE(p, p + 1); // remove duplicate "/" } else if (p[0] == '.' @@ -1514,10 +1514,10 @@ void simplify_filename(char_u *filename) if (p == start && relative) { p += 1 + (p[1] != NUL); // keep single "." or leading "./" } else { - /* Strip "./" or ".///". If we are at the end of the file name - * and there is no trailing path separator, either strip "/." if - * we are after "start", or strip "." if we are at the beginning - * of an absolute path name . */ + // Strip "./" or ".///". If we are at the end of the file name + // and there is no trailing path separator, either strip "/." if + // we are after "start", or strip "." if we are at the beginning + // of an absolute path name. tail = p + 1; if (p[1] != NUL) { while (vim_ispathsep(*tail)) { @@ -1542,9 +1542,9 @@ void simplify_filename(char_u *filename) // Don't strip for an erroneous file name. if (!stripping_disabled) { - /* If the preceding component does not exist in the file - * system, we strip it. On Unix, we don't accept a symbolic - * link that refers to a non-existent file. */ + // If the preceding component does not exist in the file + // system, we strip it. On Unix, we don't accept a symbolic + // link that refers to a non-existent file. saved_char = p[-1]; p[-1] = NUL; FileInfo file_info; @@ -1560,16 +1560,16 @@ void simplify_filename(char_u *filename) } if (!do_strip) { - /* If the component exists in the file system, check - * that stripping it won't change the meaning of the - * file name. First get information about the - * unstripped file name. This may fail if the component - * to strip is not a searchable directory (but a regular - * file, for instance), since the trailing "/.." cannot - * be applied then. We don't strip it then since we - * don't want to replace an erroneous file name by - * a valid one, and we disable stripping of later - * components. */ + // If the component exists in the file system, check + // that stripping it won't change the meaning of the + // file name. First get information about the + // unstripped file name. This may fail if the component + // to strip is not a searchable directory (but a regular + // file, for instance), since the trailing "/.." cannot + // be applied then. We don't strip it then since we + // don't want to replace an erroneous file name by + // a valid one, and we disable stripping of later + // components. saved_char = *tail; *tail = NUL; if (os_fileinfo((char *)filename, &file_info)) { @@ -1579,13 +1579,13 @@ void simplify_filename(char_u *filename) } *tail = saved_char; if (do_strip) { - /* The check for the unstripped file name - * above works also for a symbolic link pointing to - * a searchable directory. But then the parent of - * the directory pointed to by the link must be the - * same as the stripped file name. (The latter - * exists in the file system since it is the - * component's parent directory.) */ + // The check for the unstripped file name + // above works also for a symbolic link pointing to + // a searchable directory. But then the parent of + // the directory pointed to by the link must be the + // same as the stripped file name. (The latter + // exists in the file system since it is the + // component's parent directory.) FileInfo new_file_info; if (p == start && relative) { os_fileinfo(".", &new_file_info); @@ -1598,26 +1598,26 @@ void simplify_filename(char_u *filename) if (!os_fileinfo_id_equal(&file_info, &new_file_info)) { do_strip = false; - /* We don't disable stripping of later - * components since the unstripped path name is - * still valid. */ + // We don't disable stripping of later + // components since the unstripped path name is + // still valid. } } } } if (!do_strip) { - /* Skip the ".." or "../" and reset the counter for the - * components that might be stripped later on. */ + // Skip the ".." or "../" and reset the counter for the + // components that might be stripped later on. p = tail; components = 0; } else { - /* Strip previous component. If the result would get empty - * and there is no trailing path separator, leave a single - * "." instead. If we are at the end of the file name and - * there is no trailing path separator and a preceding - * component is left after stripping, strip its trailing - * path separator as well. */ + // Strip previous component. If the result would get empty + // and there is no trailing path separator, leave a single + // "." instead. If we are at the end of the file name and + // there is no trailing path separator and a preceding + // component is left after stripping, strip its trailing + // path separator as well. if (p == start && relative && tail[-1] == '.') { *p++ = '.'; *p = NUL; @@ -1699,8 +1699,8 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha ptr[len] = c; } - /* Repeat finding the file "count" times. This matters when it - * appears several times in the path. */ + // Repeat finding the file "count" times. This matters when it + // appears several times in the path. while (file_name != NULL && --count > 0) { xfree(file_name); file_name = diff --git a/src/nvim/sign_defs.h b/src/nvim/sign_defs.h index 1efde30008..f1184202e7 100644 --- a/src/nvim/sign_defs.h +++ b/src/nvim/sign_defs.h @@ -51,4 +51,4 @@ typedef enum { SIGN_TEXT, } SignType; -#endif // NVIM_SIGN_DEFS_H +#endif // NVIM_SIGN_DEFS_H diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index c472cac27d..661ca54fad 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1994,7 +1994,7 @@ static void spell_print_tree(wordnode_T *root) } } -#endif // SPELL_PRINTTREE +#endif // SPELL_PRINTTREE // Reads the affix file "fname". // Returns an afffile_T, NULL for complete failure. diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 12bfa35dd6..d7a0472cbf 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -180,10 +180,10 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n int csh_like; bool fish_like; - /* Only csh and similar shells expand '!' within single quotes. For sh and - * the like we must not put a backslash before it, it will be taken - * literally. If do_special is set the '!' will be escaped twice. - * Csh also needs to have "\n" escaped twice when do_special is set. */ + // Only csh and similar shells expand '!' within single quotes. For sh and + // the like we must not put a backslash before it, it will be taken + // literally. If do_special is set the '!' will be escaped twice. + // Csh also needs to have "\n" escaped twice when do_special is set. csh_like = csh_like_shell(); // Fish shell uses '\' as an escape character within single quotes, so '\' diff --git a/src/nvim/window.c b/src/nvim/window.c index 530cbc0c7b..ca97ae6184 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2048,7 +2048,7 @@ static int get_maximum_wincount(frame_T *fr, int height) } /// Make all windows the same height. -///'next_curwin' will soon be the current window, make sure it has enough rows. +/// 'next_curwin' will soon be the current window, make sure it has enough rows. /// /// @param next_curwin pointer to current window to be or NULL /// @param current do only frame with current window @@ -5524,7 +5524,7 @@ static void frame_setheight(frame_T *curfrp, int height) } frame_setheight(curfrp->fr_parent, height + frame_minheight(curfrp->fr_parent, NOWIN) - (int)p_wmh - 1); - //NOTREACHED + // NOTREACHED } // Compute the number of lines we will take from others frames (can be -- cgit From 87e037e26cfd53c3c34ac9029a8833023af60a56 Mon Sep 17 00:00:00 2001 From: Shougo Date: Tue, 6 Sep 2022 23:33:25 +0900 Subject: fix(cmdheight=0): various issues part3 #19816 And fixed in https://github.com/neovim/neovim/pull/19801 regression. Fix #19834 Fix #19184 --- src/nvim/getchar.c | 1 + src/nvim/message.c | 2 +- src/nvim/window.c | 6 ------ 3 files changed, 2 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 22c350d36b..e125d88395 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1698,6 +1698,7 @@ static void getchar_common(typval_T *argvars, typval_T *rettv) if (!ui_has_messages()) { // redraw the screen after getchar() update_screen(UPD_NOT_VALID); + clear_cmdline = true; } set_vim_var_nr(VV_MOUSE_WIN, 0); diff --git a/src/nvim/message.c b/src/nvim/message.c index d43c04b652..63012900df 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -2350,7 +2350,7 @@ bool msg_use_msgsep(void) { // the full-screen scroll behavior doesn't really make sense with // 'ext_multigrid' - return ((dy_flags & DY_MSGSEP) || ui_has(kUIMultigrid)); + return (dy_flags & DY_MSGSEP) || ui_has(kUIMultigrid); } bool msg_do_throttle(void) diff --git a/src/nvim/window.c b/src/nvim/window.c index ca97ae6184..a6cc53080b 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6270,12 +6270,6 @@ void command_height(void) // p_ch was changed in another tab page. curtab->tp_ch_used = p_ch; - // If the space for the command line is already more than 'cmdheight' there - // is nothing to do (window size must have decreased). - if (p_ch > old_p_ch && cmdline_row <= Rows - p_ch) { - return; - } - // If cmdline_row is smaller than what it is supposed to be for 'cmdheight' // then set old_p_ch to what it would be, so that the windows get resized // properly for the new value. -- cgit From 73207cae611a1efb8cd17139e8228772daeb9866 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/api/buffer.c | 6 +- src/nvim/api/private/helpers.c | 4 +- src/nvim/arglist.c | 2 +- src/nvim/autocmd.c | 2 +- src/nvim/change.c | 4 +- src/nvim/charset.c | 4 +- src/nvim/cmdexpand.c | 81 +++++++++++------------ src/nvim/cmdhist.c | 8 +-- src/nvim/cursor.c | 15 ++--- src/nvim/diff.c | 39 ++++++----- src/nvim/digraph.c | 6 +- src/nvim/drawline.c | 10 +-- src/nvim/edit.c | 68 ++++++++++---------- src/nvim/eval.c | 18 +++--- src/nvim/eval/funcs.c | 54 ++++++++-------- src/nvim/eval/typval.c | 2 +- src/nvim/eval/typval.h | 15 ++--- src/nvim/eval/userfunc.c | 48 +++++++------- src/nvim/ex_cmds.c | 14 ++-- src/nvim/ex_docmd.c | 10 +-- src/nvim/ex_eval.c | 2 +- src/nvim/ex_getln.c | 16 ++--- src/nvim/file_search.c | 100 ++++++++++++++-------------- src/nvim/fileio.c | 24 +++---- src/nvim/fold.c | 8 +-- src/nvim/getchar.c | 44 ++++++------- src/nvim/globals.h | 2 +- src/nvim/hardcopy.c | 2 +- src/nvim/help.c | 15 ++--- src/nvim/highlight_group.c | 6 +- src/nvim/if_cscope.c | 10 +-- src/nvim/indent.c | 8 +-- src/nvim/indent_c.c | 6 +- src/nvim/insexpand.c | 94 +++++++++++++-------------- src/nvim/lua/converter.c | 8 +-- src/nvim/lua/stdlib.c | 2 +- src/nvim/lua/treesitter.c | 2 +- src/nvim/macros.h | 2 +- src/nvim/mapping.c | 74 ++++++++++----------- src/nvim/mapping.h | 2 +- src/nvim/mark.c | 12 ++-- src/nvim/match.c | 6 +- src/nvim/mbyte.c | 32 ++++----- src/nvim/memfile.c | 12 ++-- src/nvim/memfile_defs.h | 2 +- src/nvim/memline.c | 76 +++++++++++----------- src/nvim/mouse.c | 2 +- src/nvim/normal.c | 26 ++++---- src/nvim/ops.c | 54 ++++++++-------- src/nvim/option.c | 62 +++++++++--------- src/nvim/optionstr.c | 2 +- src/nvim/os/env.c | 6 +- src/nvim/os/shell.c | 10 +-- src/nvim/path.c | 77 +++++++++++----------- src/nvim/plines.c | 4 +- src/nvim/quickfix.c | 12 ++-- src/nvim/regexp.c | 64 +++++++++--------- src/nvim/regexp_bt.c | 4 +- src/nvim/regexp_defs.h | 2 +- src/nvim/regexp_nfa.c | 6 +- src/nvim/screen.c | 2 +- src/nvim/search.c | 36 +++++------ src/nvim/shada.c | 2 +- src/nvim/spell.c | 30 ++++----- src/nvim/spell_defs.h | 6 +- src/nvim/spellfile.c | 143 ++++++++++++++++++++--------------------- src/nvim/spellsuggest.c | 32 ++++----- src/nvim/statusline.c | 22 +++---- src/nvim/strings.c | 15 ++--- src/nvim/syntax.c | 8 +-- src/nvim/tag.c | 99 ++++++++++++++-------------- src/nvim/tag.h | 2 +- src/nvim/textformat.c | 28 ++++---- src/nvim/textobject.c | 4 +- src/nvim/undo.c | 12 ++-- 75 files changed, 867 insertions(+), 882 deletions(-) (limited to 'src') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 16f574f46d..6f8cad3e33 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -570,7 +570,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In char *str_at_end = NULL; // Another call to ml_get_buf() may free the line, so make a copy. - str_at_start = xstrdup((char *)ml_get_buf(buf, (linenr_T)start_row, false)); + str_at_start = xstrdup(ml_get_buf(buf, (linenr_T)start_row, false)); size_t len_at_start = strlen(str_at_start); if (start_col < 0 || (size_t)start_col > len_at_start) { api_set_error(err, kErrorTypeValidation, "start_col out of bounds"); @@ -578,7 +578,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In } // Another call to ml_get_buf() may free the line, so make a copy. - str_at_end = xstrdup((char *)ml_get_buf(buf, (linenr_T)end_row, false)); + str_at_end = xstrdup(ml_get_buf(buf, (linenr_T)end_row, false)); size_t len_at_end = strlen(str_at_end); if (end_col < 0 || (size_t)end_col > len_at_end) { api_set_error(err, kErrorTypeValidation, "end_col out of bounds"); @@ -608,7 +608,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In for (int64_t i = 1; i < end_row - start_row; i++) { int64_t lnum = start_row + i; - const char *bufline = (char *)ml_get_buf(buf, (linenr_T)lnum, false); + const char *bufline = ml_get_buf(buf, (linenr_T)lnum, false); old_byte += (bcount_t)(strlen(bufline)) + 1; } old_byte += (bcount_t)end_col + 1; diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index ebcf6cca6d..22d2ffbaf1 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -466,7 +466,7 @@ bool buf_collect_lines(buf_T *buf, size_t n, int64_t start, bool replace_nl, Arr return false; } - const char *bufstr = (char *)ml_get_buf(buf, (linenr_T)lnum, false); + const char *bufstr = ml_get_buf(buf, (linenr_T)lnum, false); Object str = STRING_OBJ(cstr_to_string(bufstr)); if (replace_nl) { @@ -499,7 +499,7 @@ String buf_get_text(buf_T *buf, int64_t lnum, int64_t start_col, int64_t end_col return rv; } - const char *bufstr = (char *)ml_get_buf(buf, (linenr_T)lnum, false); + const char *bufstr = ml_get_buf(buf, (linenr_T)lnum, false); size_t line_length = strlen(bufstr); start_col = start_col < 0 ? (int64_t)line_length + start_col + 1 : start_col; diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index e6ac1f6247..0000636417 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -86,7 +86,7 @@ void alist_expand(int *fnum_list, int fnum_len) // can't set the options. p_su = empty_option; for (int i = 0; i < GARGCOUNT; i++) { - old_arg_files[i] = vim_strsave(GARGLIST[i].ae_fname); + old_arg_files[i] = xstrdup(GARGLIST[i].ae_fname); } int old_arg_count = GARGCOUNT; char **new_arg_files; diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 1c1de214cd..635875b16f 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -2214,7 +2214,7 @@ bool has_autocmd(event_T event, char *sfname, buf_T *buf) #ifdef BACKSLASH_IN_FILENAME // Replace all backslashes with forward slashes. This makes the // autocommand patterns portable between Unix and Windows. - sfname = vim_strsave(sfname); + sfname = xstrdup(sfname); forward_slash(sfname); forward_slash(fname); #endif diff --git a/src/nvim/change.c b/src/nvim/change.c index 5e9edac4f2..f4568fc617 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -774,7 +774,7 @@ int del_char(bool fixpos) int del_chars(long count, int fixpos) { int bytes = 0; - char *p = (char *)get_cursor_pos_ptr(); + char *p = get_cursor_pos_ptr(); for (long i = 0; i < count && *p != NUL; i++) { int l = utfc_ptr2len(p); bytes += l; @@ -1036,7 +1036,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) colnr_T mincol = curwin->w_cursor.col + 1; // make a copy of the current line so we can mess with it - char *saved_line = (char *)vim_strsave((char_u *)get_cursor_line_ptr()); + char *saved_line = xstrdup(get_cursor_line_ptr()); if (State & VREPLACE_FLAG) { // With MODE_VREPLACE we make a copy of the next line, which we will be diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 3396e2de41..693ff90179 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -913,7 +913,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en int ts = (int)wp->w_buffer->b_p_ts; colnr_T vcol = 0; - char *line = ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line + char *line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line if (pos->col == MAXCOL) { // continue until the NUL @@ -1076,7 +1076,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *e colnr_T endadd = 0; // Cannot put the cursor on part of a wide character. - char *ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false); + char *ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); if (pos->col < (colnr_T)STRLEN(ptr)) { int c = utf_ptr2char(ptr + pos->col); diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 30e734b93f..3f624c77f3 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -183,7 +183,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) if (type == WILD_NEXT || type == WILD_PREV) { // Get next/previous match for a previous expanded pattern. - p2 = ExpandOne(xp, NULL, NULL, 0, type); + p2 = (char_u *)ExpandOne(xp, NULL, NULL, 0, type); } else { // Translate string into pattern and expand it. p1 = (char_u *)addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); @@ -193,8 +193,8 @@ int nextwild(expand_T *xp, int type, int options, bool escape) | WILD_SILENT | (escape ? WILD_ESCAPE : 0) | (p_wic ? WILD_ICASE : 0)); - p2 = ExpandOne(xp, p1, (char_u *)xstrnsave(&ccline->cmdbuff[i], xp->xp_pattern_len), - use_options, type); + p2 = (char_u *)ExpandOne(xp, (char *)p1, xstrnsave(&ccline->cmdbuff[i], xp->xp_pattern_len), + use_options, type); xfree(p1); // xp->xp_pattern might have been modified by ExpandOne (for example, @@ -278,7 +278,7 @@ void cmdline_pum_cleanup(CmdlineInfo *cclp) /// Get the next or prev cmdline completion match. The index of the match is set /// in "p_findex" -static char_u *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, char_u *orig_save) +static char *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, char *orig_save) { if (xp->xp_numfiles <= 0) { return NULL; @@ -318,17 +318,17 @@ static char_u *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, cha } *p_findex = findex; - return vim_strsave(findex == -1 ? orig_save : (char_u *)xp->xp_files[findex]); + return xstrdup(findex == -1 ? orig_save : xp->xp_files[findex]); } /// Start the command-line expansion and get the matches. -static char_u *ExpandOne_start(int mode, expand_T *xp, char_u *str, int options) +static char *ExpandOne_start(int mode, expand_T *xp, char *str, int options) { int non_suf_match; // number without matching suffix - char_u *ss = NULL; + char *ss = NULL; // Do the expansion. - if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, options) == FAIL) { + if (ExpandFromContext(xp, (char_u *)str, &xp->xp_numfiles, &xp->xp_files, options) == FAIL) { #ifdef FNAME_ILLEGAL // Illegal file name has been silently skipped. But when there // are wildcards, the real problem is that there was no match, @@ -343,7 +343,7 @@ static char_u *ExpandOne_start(int mode, expand_T *xp, char_u *str, int options) } } else { // Escape the matches for use on the command line. - ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options); + ExpandEscape(xp, (char_u *)str, xp->xp_numfiles, xp->xp_files, options); // Check for matching suffixes in file names. if (mode != WILD_ALL && mode != WILD_ALL_KEEP @@ -378,7 +378,7 @@ static char_u *ExpandOne_start(int mode, expand_T *xp, char_u *str, int options) } } if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) { - ss = vim_strsave((char_u *)xp->xp_files[0]); + ss = xstrdup(xp->xp_files[0]); } } } @@ -458,11 +458,11 @@ static char *find_longest_match(expand_T *xp, int options) /// The variables xp->xp_context and xp->xp_backslash must have been set! /// /// @param orig allocated copy of original of expanded string -char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode) +char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) { - char_u *ss = NULL; + char *ss = NULL; static int findex; - static char_u *orig_save = NULL; // kept value of orig + static char *orig_save = NULL; // kept value of orig int orig_saved = false; int i; @@ -472,10 +472,11 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode } if (mode == WILD_CANCEL) { - ss = vim_strsave(orig_save ? orig_save : (char_u *)""); + ss = xstrdup(orig_save ? orig_save : ""); } else if (mode == WILD_APPLY) { - ss = vim_strsave(findex == -1 ? (orig_save ? orig_save : (char_u *)"") - : (char_u *)xp->xp_files[findex]); + ss = xstrdup(findex == -1 + ? (orig_save ? orig_save : "") + : xp->xp_files[findex]); } // free old names @@ -500,7 +501,7 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode // Find longest common part if (mode == WILD_LONGEST && xp->xp_numfiles > 0) { - ss = (char_u *)find_longest_match(xp, options); + ss = find_longest_match(xp, options); findex = -1; // next p_wc gets first one } @@ -1915,7 +1916,7 @@ int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, char *** } /// Expand file or directory names. -static int expand_files_and_dirs(expand_T *xp, char_u *pat, char ***file, int *num_file, int flags, +static int expand_files_and_dirs(expand_T *xp, char *pat, char ***file, int *num_file, int flags, int options) { bool free_pat = false; @@ -1923,7 +1924,7 @@ static int expand_files_and_dirs(expand_T *xp, char_u *pat, char ***file, int *n // for ":set path=" and ":set tags=" halve backslashes for escaped space if (xp->xp_backslash != XP_BS_NONE) { free_pat = true; - pat = vim_strsave(pat); + pat = xstrdup(pat); for (int i = 0; pat[i]; i++) { if (pat[i] == '\\') { if (xp->xp_backslash == XP_BS_THREE @@ -2124,7 +2125,7 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char ***f if (xp->xp_context == EXPAND_FILES || xp->xp_context == EXPAND_DIRECTORIES || xp->xp_context == EXPAND_FILES_IN_PATH) { - return expand_files_and_dirs(xp, pat, file, num_file, flags, options); + return expand_files_and_dirs(xp, (char *)pat, file, num_file, flags, options); } *file = NULL; @@ -2142,7 +2143,7 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char ***f if (xp->xp_context == EXPAND_SHELLCMD) { *file = NULL; - expand_shellcmd(pat, num_file, file, flags); + expand_shellcmd((char *)pat, num_file, file, flags); return OK; } if (xp->xp_context == EXPAND_OLD_SETTING) { @@ -2238,18 +2239,18 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha { int i; size_t count = 0; - char_u *str; + char *str; // count the number of matching names for (i = 0;; i++) { - str = (char_u *)(*func)(xp, i); + str = (*func)(xp, i); if (str == NULL) { // end of list break; } if (*str == NUL) { // skip empty strings continue; } - if (vim_regexec(regmatch, (char *)str, (colnr_T)0)) { + if (vim_regexec(regmatch, str, (colnr_T)0)) { count++; } } @@ -2263,20 +2264,20 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha // copy the matching names into allocated memory count = 0; for (i = 0;; i++) { - str = (char_u *)(*func)(xp, i); + str = (*func)(xp, i); if (str == NULL) { // End of list. break; } if (*str == NUL) { // Skip empty strings. continue; } - if (vim_regexec(regmatch, (char *)str, (colnr_T)0)) { + if (vim_regexec(regmatch, str, (colnr_T)0)) { if (escaped) { - str = vim_strsave_escaped(str, (char_u *)" \t\\."); + str = (char *)vim_strsave_escaped((char_u *)str, (char_u *)" \t\\."); } else { - str = vim_strsave(str); + str = xstrdup(str); } - (*file)[count++] = (char *)str; + (*file)[count++] = str; if (func == get_menu_names) { // Test for separator added by get_menu_names(). str += STRLEN(str) - 1; @@ -2313,22 +2314,22 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha /// *file will either be set to NULL or point to /// allocated memory. /// @param flagsarg is a combination of EW_* flags. -static void expand_shellcmd(char_u *filepat, int *num_file, char ***file, int flagsarg) +static void expand_shellcmd(char *filepat, int *num_file, char ***file, int flagsarg) FUNC_ATTR_NONNULL_ALL { - char_u *pat; + char *pat; int i; - char_u *path = NULL; + char *path = NULL; garray_T ga; char *buf = xmalloc(MAXPATHL); size_t l; - char_u *s, *e; + char *s, *e; int flags = flagsarg; int ret; bool did_curdir = false; // for ":set path=" and ":set tags=" halve backslashes for escaped space - pat = vim_strsave(filepat); + pat = xstrdup(filepat); for (i = 0; pat[i]; i++) { if (pat[i] == '\\' && pat[i + 1] == ' ') { STRMOVE(pat + i, pat + i + 1); @@ -2340,14 +2341,14 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char ***file, int fl bool mustfree = false; // Track memory allocation for *path. if (pat[0] == '.' && (vim_ispathsep(pat[1]) || (pat[1] == '.' && vim_ispathsep(pat[2])))) { - path = (char_u *)"."; + path = "."; } else { // For an absolute name we don't use $PATH. - if (!path_is_absolute(pat)) { - path = (char_u *)vim_getenv("PATH"); + if (!path_is_absolute((char_u *)pat)) { + path = vim_getenv("PATH"); } if (path == NULL) { - path = (char_u *)""; + path = ""; } else { mustfree = true; } @@ -2360,7 +2361,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char ***file, int fl hashtab_T found_ht; hash_init(&found_ht); for (s = path;; s = e) { - e = (char_u *)vim_strchr((char *)s, ENV_SEPCHAR); + e = vim_strchr(s, ENV_SEPCHAR); if (e == NULL) { e = s + STRLEN(s); } @@ -2895,7 +2896,7 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) theend: pat = (char_u *)addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context); - ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP); + ExpandOne(&xpc, (char *)pat, NULL, options, WILD_ALL_KEEP); tv_list_alloc_ret(rettv, xpc.xp_numfiles); for (int i = 0; i < xpc.xp_numfiles; i++) { diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c index 629c47f24a..38353f44b5 100644 --- a/src/nvim/cmdhist.c +++ b/src/nvim/cmdhist.c @@ -382,13 +382,13 @@ static int calc_hist_idx(int histype, int num) /// Get a history entry by its index. /// /// @param histype may be one of the HIST_ values. -static char_u *get_history_entry(int histype, int idx) +static char *get_history_entry(int histype, int idx) { idx = calc_hist_idx(histype, idx); if (idx >= 0) { - return (char_u *)history[histype][idx].hisstr; + return history[histype][idx].hisstr; } else { - return (char_u *)""; + return ""; } } @@ -556,7 +556,7 @@ void f_histget(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) idx = (int)tv_get_number_chk(&argvars[1], NULL); } // -1 on type error - rettv->vval.v_string = (char *)vim_strsave(get_history_entry(type, idx)); + rettv->vval.v_string = xstrdup(get_history_entry(type, idx)); } rettv->v_type = VAR_STRING; } diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 2a3fe9701c..cd651fcf4c 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -101,7 +101,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a || (VIsual_active && *p_sel != 'o') || ((get_ve_flags() & VE_ONEMORE) && wcol < MAXCOL); - char_u *line = ml_get_buf(curbuf, pos->lnum, false); + char_u *line = (char_u *)ml_get_buf(curbuf, pos->lnum, false); if (wcol >= MAXCOL) { idx = (int)STRLEN(line) - 1 + one_more; @@ -308,7 +308,7 @@ void check_pos(buf_T *buf, pos_T *pos) } if (pos->col > 0) { - char_u *line = ml_get_buf(buf, pos->lnum, false); + char_u *line = (char_u *)ml_get_buf(buf, pos->lnum, false); colnr_T len = (colnr_T)STRLEN(line); if (pos->col > len) { pos->col = len; @@ -481,7 +481,7 @@ bool leftcol_changed(void) int gchar_cursor(void) { - return utf_ptr2char((char *)get_cursor_pos_ptr()); + return utf_ptr2char(get_cursor_pos_ptr()); } /// Write a character at the current cursor position. @@ -489,18 +489,17 @@ int gchar_cursor(void) void pchar_cursor(char_u c) { *(ml_get_buf(curbuf, curwin->w_cursor.lnum, true) - + curwin->w_cursor.col) = c; + + curwin->w_cursor.col) = (char)c; } /// @return pointer to cursor line. char *get_cursor_line_ptr(void) { - return (char *)ml_get_buf(curbuf, curwin->w_cursor.lnum, false); + return ml_get_buf(curbuf, curwin->w_cursor.lnum, false); } /// @return pointer to cursor position. -char_u *get_cursor_pos_ptr(void) +char *get_cursor_pos_ptr(void) { - return ml_get_buf(curbuf, curwin->w_cursor.lnum, false) + - curwin->w_cursor.col; + return ml_get_buf(curbuf, curwin->w_cursor.lnum, false) + curwin->w_cursor.col; } diff --git a/src/nvim/diff.c b/src/nvim/diff.c index a3046bb7d7..69883966ab 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -573,9 +573,9 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) if (dir == BACKWARD) { off_org = dp->df_count[i_org] - 1; } - char *line_org = (char *)vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], - dp->df_lnum[i_org] + off_org, - false)); + char *line_org = xstrdup(ml_get_buf(tp->tp_diffbuf[i_org], + dp->df_lnum[i_org] + off_org, + false)); int i_new; for (i_new = i_org + 1; i_new < DB_COUNT; i_new++) { @@ -592,9 +592,9 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) break; } - if (diff_cmp((char_u *)line_org, ml_get_buf(tp->tp_diffbuf[i_new], - dp->df_lnum[i_new] + off_new, - false)) != 0) { + if (diff_cmp((char_u *)line_org, (char_u *)ml_get_buf(tp->tp_diffbuf[i_new], + dp->df_lnum[i_new] + off_new, + false)) != 0) { break; } } @@ -750,7 +750,7 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din) len = 0; for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { - for (char_u *s = ml_get_buf(buf, lnum, false); *s != NUL;) { + for (char_u *s = (char_u *)ml_get_buf(buf, lnum, false); *s != NUL;) { if (diff_flags & DIFF_ICASE) { int c; char cbuf[MB_MAXBYTES + 1]; @@ -824,9 +824,9 @@ static void diff_try_update(diffio_T *dio, int idx_orig, exarg_T *eap) ga_init(&dio->dio_diff.dout_ga, sizeof(char *), 1000); } else { // We need three temp file names. - dio->dio_orig.din_fname = vim_tempname(); - dio->dio_new.din_fname = vim_tempname(); - dio->dio_diff.dout_fname = vim_tempname(); + dio->dio_orig.din_fname = (char_u *)vim_tempname(); + dio->dio_new.din_fname = (char_u *)vim_tempname(); + dio->dio_diff.dout_fname = (char_u *)vim_tempname(); if (dio->dio_orig.din_fname == NULL || dio->dio_new.din_fname == NULL || dio->dio_diff.dout_fname == NULL) { @@ -1178,9 +1178,9 @@ void ex_diffpatch(exarg_T *eap) // We need two temp file names. // Name of original temp file. - char_u *tmp_orig = vim_tempname(); + char_u *tmp_orig = (char_u *)vim_tempname(); // Name of patched temp file. - char_u *tmp_new = vim_tempname(); + char_u *tmp_new = (char_u *)vim_tempname(); if ((tmp_orig == NULL) || (tmp_new == NULL)) { goto theend; @@ -1920,11 +1920,11 @@ static bool diff_equal_entry(diff_T *dp, int idx1, int idx2) } for (int i = 0; i < dp->df_count[idx1]; i++) { - char *line = (char *)vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1], - dp->df_lnum[idx1] + i, false)); + char *line = xstrdup(ml_get_buf(curtab->tp_diffbuf[idx1], + dp->df_lnum[idx1] + i, false)); - int cmp = diff_cmp((char_u *)line, ml_get_buf(curtab->tp_diffbuf[idx2], - dp->df_lnum[idx2] + i, false)); + int cmp = diff_cmp((char_u *)line, (char_u *)ml_get_buf(curtab->tp_diffbuf[idx2], + dp->df_lnum[idx2] + i, false)); xfree(line); if (cmp != 0) { @@ -2290,7 +2290,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) int l; // Make a copy of the line, the next ml_get() will invalidate it. - char *line_org = (char *)vim_strsave(ml_get_buf(wp->w_buffer, lnum, false)); + char *line_org = xstrdup(ml_get_buf(wp->w_buffer, lnum, false)); int idx = diff_buf_idx(wp->w_buffer); if (idx == DB_COUNT) { @@ -2322,8 +2322,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) continue; } added = false; - line_new = (char *)ml_get_buf(curtab->tp_diffbuf[i], - dp->df_lnum[i] + off, false); + line_new = ml_get_buf(curtab->tp_diffbuf[i], dp->df_lnum[i] + off, false); // Search for start of difference si_org = si_new = 0; @@ -2718,7 +2717,7 @@ void ex_diffgetput(exarg_T *eap) if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count) { break; } - p = (char *)vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, false)); + p = xstrdup(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, false)); ml_append(lnum + i - 1, p, 0, false); xfree(p); added++; diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 53b6c66c46..8e31d3feab 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1932,9 +1932,9 @@ void f_digraph_get(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } int code = digraph_get(digraphs[0], digraphs[1], false); - char_u buf[NUMBUFLEN]; - buf[utf_char2bytes(code, (char *)buf)] = NUL; - rettv->vval.v_string = (char *)vim_strsave(buf); + char buf[NUMBUFLEN]; + buf[utf_char2bytes(code, buf)] = NUL; + rettv->vval.v_string = xstrdup(buf); } /// "digraph_getlist()" function diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 7846510ad9..9de8b9996a 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -689,7 +689,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, // Trick: skip a few chars for C/shell/Vim comments nextline[SPWORDLEN] = NUL; if (lnum < wp->w_buffer->b_ml.ml_line_count) { - line = ml_get_buf(wp->w_buffer, lnum + 1, false); + line = (char_u *)ml_get_buf(wp->w_buffer, lnum + 1, false); spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); } @@ -866,7 +866,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, line_attr_lowprio_save = line_attr_lowprio; } - line = end_fill ? (char_u *)"" : ml_get_buf(wp->w_buffer, lnum, false); + line = end_fill ? (char_u *)"" : (char_u *)ml_get_buf(wp->w_buffer, lnum, false); ptr = line; if (has_spell && !number_only) { @@ -1006,7 +1006,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, len = spell_move_to(wp, FORWARD, true, true, &spell_hlf); // spell_move_to() may call ml_get() and make "line" invalid - line = ml_get_buf(wp->w_buffer, lnum, false); + line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false); ptr = line + linecol; if (len == 0 || (int)wp->w_cursor.col > ptr - line) { @@ -1224,7 +1224,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, c_extra = ' '; c_final = NUL; n_extra = - get_breakindent_win(wp, ml_get_buf(wp->w_buffer, lnum, false)); + get_breakindent_win(wp, (char_u *)ml_get_buf(wp->w_buffer, lnum, false)); if (row == startrow) { n_extra -= win_col_off2(wp); if (n_extra < 0) { @@ -1676,7 +1676,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, // Need to get the line again, a multi-line regexp may // have made it invalid. - line = ml_get_buf(wp->w_buffer, lnum, false); + line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false); ptr = line + v; if (!attr_pri) { diff --git a/src/nvim/edit.c b/src/nvim/edit.c index b20fc7d44a..f7a16abfb2 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1439,21 +1439,21 @@ void edit_putchar(int c, bool highlight) } } -/// Return the effective prompt for the specified buffer. -char_u *buf_prompt_text(const buf_T *const buf) +/// @return the effective prompt for the specified buffer. +char *buf_prompt_text(const buf_T *const buf) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { if (buf->b_prompt_text == NULL) { - return (char_u *)"% "; + return "% "; } - return (char_u *)buf->b_prompt_text; + return buf->b_prompt_text; } // Return the effective prompt for the current buffer. char_u *prompt_text(void) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { - return buf_prompt_text(curbuf); + return (char_u *)buf_prompt_text(curbuf); } // Prepare for prompt mode: Make sure the last line has the prompt text. @@ -1574,11 +1574,11 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang int start_col; colnr_T vc; colnr_T orig_col = 0; // init for GCC - char_u *new_line, *orig_line = NULL; // init for GCC + char *new_line, *orig_line = NULL; // init for GCC // MODE_VREPLACE state needs to know what the line was like before changing if (State & VREPLACE_FLAG) { - orig_line = vim_strsave((char_u *)get_cursor_line_ptr()); // Deal with NULL below + orig_line = xstrdup(get_cursor_line_ptr()); // Deal with NULL below orig_col = curwin->w_cursor.col; } @@ -1733,14 +1733,14 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang // then put it back again the way we wanted it. if (State & VREPLACE_FLAG) { // Save new line - new_line = vim_strsave((char_u *)get_cursor_line_ptr()); + new_line = xstrdup(get_cursor_line_ptr()); // We only put back the new line up to the cursor new_line[curwin->w_cursor.col] = NUL; int new_col = curwin->w_cursor.col; // Put back original line - ml_replace(curwin->w_cursor.lnum, (char *)orig_line, false); + ml_replace(curwin->w_cursor.lnum, orig_line, false); curwin->w_cursor.col = orig_col; curbuf_splice_pending++; @@ -1749,7 +1749,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang backspace_until_column(0); // Insert new stuff into line again - ins_bytes((char *)new_line); + ins_bytes(new_line); xfree(new_line); @@ -1813,7 +1813,7 @@ static bool del_char_after_col(int limit_col) // composing character. mb_adjust_cursor(); while (curwin->w_cursor.col < (colnr_T)limit_col) { - int l = utf_ptr2len((char *)get_cursor_pos_ptr()); + int l = utf_ptr2len(get_cursor_pos_ptr()); if (l == 0) { // end of line break; @@ -2466,7 +2466,7 @@ int oneright(void) pos_T prevpos = curwin->w_cursor; // Adjust for multi-wide char (excluding TAB) - ptr = (char *)get_cursor_pos_ptr(); + ptr = get_cursor_pos_ptr(); coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(utf_ptr2char(ptr))) ? ptr2cells(ptr) : 1)); curwin->w_set_curswant = true; @@ -2475,7 +2475,7 @@ int oneright(void) || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL; } - ptr = (char *)get_cursor_pos_ptr(); + ptr = get_cursor_pos_ptr(); if (*ptr == NUL) { return FAIL; // already at the very end } @@ -2518,7 +2518,7 @@ int oneleft(void) if (curwin->w_cursor.coladd == 1) { // Adjust for multi-wide char (not a TAB) - char *ptr = (char *)get_cursor_pos_ptr(); + char *ptr = get_cursor_pos_ptr(); if (*ptr != TAB && vim_isprintc(utf_ptr2char(ptr)) && ptr2cells(ptr) > 1) { curwin->w_cursor.coladd = 0; } @@ -2720,19 +2720,19 @@ char_u *get_last_insert(void) // Returns pointer to allocated memory (must be freed) or NULL. char_u *get_last_insert_save(void) { - char_u *s; + char *s; int len; if (last_insert == NULL) { return NULL; } - s = vim_strsave(last_insert + last_insert_skip); + s = xstrdup((char *)last_insert + last_insert_skip); len = (int)STRLEN(s); if (len > 0 && s[len - 1] == ESC) { // remove trailing ESC s[len - 1] = NUL; } - return s; + return (char_u *)s; } /// Check the word in front of the cursor for an abbreviation. @@ -2934,7 +2934,7 @@ static void replace_do_bs(int limit_col) // Get the number of screen cells used by the character we are // going to delete. getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL); - orig_vcols = win_chartabsize(curwin, (char *)get_cursor_pos_ptr(), start_vcol); + orig_vcols = win_chartabsize(curwin, get_cursor_pos_ptr(), start_vcol); } (void)del_char_after_col(limit_col); if (l_State & VREPLACE_FLAG) { @@ -2945,7 +2945,7 @@ static void replace_do_bs(int limit_col) if (l_State & VREPLACE_FLAG) { // Get the number of screen cells used by the inserted characters - p = get_cursor_pos_ptr(); + p = (char_u *)get_cursor_pos_ptr(); ins_len = (int)STRLEN(p) - orig_len; vcol = start_vcol; for (i = 0; i < ins_len; i++) { @@ -3186,7 +3186,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) if (keytyped == (int)p[-1] || (icase && keytyped < 256 && TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1]))) { - line = get_cursor_pos_ptr(); + line = (char_u *)get_cursor_pos_ptr(); assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX); if ((curwin->w_cursor.col == (colnr_T)(p - look) || !vim_iswordc(line[-(p - look) - 1])) @@ -3880,7 +3880,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) // again when auto-formatting. if (has_format_option(FO_AUTO) && has_format_option(FO_WHITE_PAR)) { - char_u *ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true); + char_u *ptr = (char_u *)ml_get_buf(curbuf, curwin->w_cursor.lnum, true); int len; len = (int)STRLEN(ptr); @@ -3974,7 +3974,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) // delete characters until we are at or before want_vcol while (vcol > want_vcol && curwin->w_cursor.col > 0 - && (cc = *(get_cursor_pos_ptr() - 1), ascii_iswhite(cc))) { + && (cc = (uint8_t)(*(get_cursor_pos_ptr() - 1)), ascii_iswhite(cc))) { ins_bs_one(&vcol); } @@ -4006,7 +4006,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) // Delete up to starting point, start of line or previous word. int prev_cclass = 0; - int cclass = mb_get_class(get_cursor_pos_ptr()); + int cclass = mb_get_class((char_u *)get_cursor_pos_ptr()); do { if (!revins_on) { // put cursor on char to be deleted dec_cursor(); @@ -4014,7 +4014,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) cc = gchar_cursor(); // look multi-byte character class prev_cclass = cclass; - cclass = mb_get_class(get_cursor_pos_ptr()); + cclass = mb_get_class((char_u *)get_cursor_pos_ptr()); if (mode == BACKSPACE_WORD && !ascii_isspace(cc)) { // start of word? mode = BACKSPACE_WORD_NOT_SPACE; temp = vim_iswordc(cc); @@ -4033,7 +4033,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) } else { const int l_p_deco = p_deco; if (l_p_deco) { - (void)utfc_ptr2char((char *)get_cursor_pos_ptr(), cpc); + (void)utfc_ptr2char(get_cursor_pos_ptr(), cpc); } (void)del_char(false); // If there are combining characters and 'delcombine' is set @@ -4286,7 +4286,7 @@ static void ins_right(void) if (virtual_active()) { oneright(); } else { - curwin->w_cursor.col += utfc_ptr2len((char *)get_cursor_pos_ptr()); + curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr()); } revins_legal++; @@ -4507,7 +4507,7 @@ static bool ins_tab(void) || get_sts_value() > 0 || (p_sta && ind))) { char_u *ptr; - char_u *saved_line = NULL; // init for GCC + char *saved_line = NULL; // init for GCC pos_T pos; pos_T fpos; pos_T *cursor; @@ -4520,10 +4520,10 @@ static bool ins_tab(void) if (State & VREPLACE_FLAG) { pos = curwin->w_cursor; cursor = &pos; - saved_line = vim_strsave((char_u *)get_cursor_line_ptr()); - ptr = saved_line + pos.col; + saved_line = xstrdup(get_cursor_line_ptr()); + ptr = (char_u *)saved_line + pos.col; } else { - ptr = get_cursor_pos_ptr(); + ptr = (char_u *)get_cursor_pos_ptr(); cursor = &curwin->w_cursor; } @@ -4627,7 +4627,7 @@ static bool ins_tab(void) // Insert each char in saved_line from changed_col to // ptr-cursor - ins_bytes_len((char *)saved_line + change_col, (size_t)(cursor->col - change_col)); + ins_bytes_len(saved_line + change_col, (size_t)(cursor->col - change_col)); } } @@ -4946,13 +4946,13 @@ static char_u *do_insert_char_pre(int c) textlock++; set_vim_var_string(VV_CHAR, buf, -1); - char_u *res = NULL; + char *res = NULL; if (ins_apply_autocmds(EVENT_INSERTCHARPRE)) { // Get the value of v:char. It may be empty or more than one // character. Only use it when changed, otherwise continue with the // original character to avoid breaking autoindent. if (STRCMP(buf, get_vim_var_str(VV_CHAR)) != 0) { - res = vim_strsave((char_u *)get_vim_var_str(VV_CHAR)); + res = xstrdup(get_vim_var_str(VV_CHAR)); } } @@ -4962,7 +4962,7 @@ static char_u *do_insert_char_pre(int c) // Restore the State, it may have been changed. State = save_State; - return res; + return (char_u *)res; } bool get_can_cindent(void) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 06ee4c8d81..0c41381313 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3909,7 +3909,7 @@ char *partial_name(partial_T *pt) FUNC_ATTR_PURE { if (pt->pt_name != NULL) { - return (char *)pt->pt_name; + return pt->pt_name; } return (char *)pt->pt_func->uf_name; } @@ -3924,7 +3924,7 @@ static void partial_free(partial_T *pt) xfree(pt->pt_argv); tv_dict_unref(pt->pt_dict); if (pt->pt_name != NULL) { - func_unref(pt->pt_name); + func_unref((char_u *)pt->pt_name); xfree(pt->pt_name); } else { func_ptr_unref(pt->pt_func); @@ -4478,7 +4478,7 @@ bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack // A partial does not have a copyID, because it cannot contain itself. if (pt != NULL) { - abort = set_ref_in_func(pt->pt_name, pt->pt_func, copyID); + abort = set_ref_in_func((char_u *)pt->pt_name, pt->pt_func, copyID); if (pt->pt_dict != NULL) { typval_T dtv; @@ -4846,7 +4846,7 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map) break; } - vimvars[VV_KEY].vv_str = (char *)vim_strsave(di->di_key); + vimvars[VV_KEY].vv_str = xstrdup((char *)di->di_key); int r = filter_map_one(&di->di_tv, expr, map, &rem); tv_clear(&vimvars[VV_KEY].vv_tv); if (r == FAIL || did_emsg) { @@ -5113,7 +5113,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref) func_ptr_ref(pt->pt_func); xfree(name); } else { - pt->pt_name = (char_u *)name; + pt->pt_name = name; func_ref((char_u *)name); } @@ -6208,7 +6208,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) buf_T *buf = buflist_findnr((int)tv->vval.v_number); if (buf) { for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { - for (char *p = (char *)ml_get_buf(buf, lnum, false); *p != NUL; p++) { + for (char *p = ml_get_buf(buf, lnum, false); *p != NUL; p++) { *len += 1; } *len += 1; @@ -6226,7 +6226,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl) char *ret = xmalloc((size_t)(*len) + 1); char *end = ret; for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { - for (char *p = (char *)ml_get_buf(buf, lnum, false); *p != NUL; p++) { + for (char *p = ml_get_buf(buf, lnum, false); *p != NUL; p++) { *end++ = (*p == '\n') ? NUL : *p; } *end++ = '\n'; @@ -6275,7 +6275,7 @@ int buf_byteidx_to_charidx(buf_T *buf, linenr_T lnum, int byteidx) lnum = buf->b_ml.ml_line_count; } - char *str = (char *)ml_get_buf(buf, lnum, false); + char *str = ml_get_buf(buf, lnum, false); if (*str == NUL) { return 0; @@ -6313,7 +6313,7 @@ int buf_charidx_to_byteidx(buf_T *buf, linenr_T lnum, int charidx) lnum = buf->b_ml.ml_line_count; } - char *str = (char *)ml_get_buf(buf, lnum, false); + char *str = ml_get_buf(buf, lnum, false); // Convert the character offset to a byte offset char *t = str; diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 60a6ec6201..408b6e6cb5 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -849,7 +849,7 @@ static void get_col(typval_T *argvars, typval_T *rettv, bool charcol) // col(".") when the cursor is on the NUL at the end of the line // because of "coladd" can be seen as an extra column. if (virtual_active() && fp == &curwin->w_cursor) { - char *p = (char *)get_cursor_pos_ptr(); + char *p = get_cursor_pos_ptr(); if (curwin->w_cursor.coladd >= (colnr_T)win_chartabsize(curwin, p, curwin->w_virtcol - curwin->w_cursor.coladd)) { @@ -930,12 +930,12 @@ static void f_chdir(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } // Return the current directory - char_u *cwd = xmalloc(MAXPATHL); - if (os_dirname(cwd, MAXPATHL) != FAIL) { + char *cwd = xmalloc(MAXPATHL); + if (os_dirname((char_u *)cwd, MAXPATHL) != FAIL) { #ifdef BACKSLASH_IN_FILENAME slash_adjust(cwd); #endif - rettv->vval.v_string = (char *)vim_strsave(cwd); + rettv->vval.v_string = xstrdup(cwd); } xfree(cwd); @@ -2016,10 +2016,9 @@ static void f_expand(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) options += WILD_ICASE; } if (rettv->v_type == VAR_STRING) { - rettv->vval.v_string = (char *)ExpandOne(&xpc, (char_u *)s, NULL, options, - WILD_ALL); + rettv->vval.v_string = ExpandOne(&xpc, (char *)s, NULL, options, WILD_ALL); } else { - ExpandOne(&xpc, (char_u *)s, NULL, options, WILD_ALL_KEEP); + ExpandOne(&xpc, (char *)s, NULL, options, WILD_ALL_KEEP); tv_list_alloc_ret(rettv, xpc.xp_numfiles); for (int i = 0; i < xpc.xp_numfiles; i++) { tv_list_append_string(rettv->vval.v_list, @@ -2437,7 +2436,7 @@ static void f_get(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) pt = argvars[0].vval.v_partial; } else { CLEAR_FIELD(fref_pt); - fref_pt.pt_name = (char_u *)argvars[0].vval.v_string; + fref_pt.pt_name = argvars[0].vval.v_string; pt = &fref_pt; } @@ -2579,9 +2578,8 @@ static void get_buffer_lines(buf_T *buf, linenr_T start, linenr_T end, int retli } } else { rettv->v_type = VAR_STRING; - rettv->vval.v_string = - (char *)((start >= 1 && start <= buf->b_ml.ml_line_count) - ? vim_strsave(ml_get_buf(buf, start, false)) : NULL); + rettv->vval.v_string = ((start >= 1 && start <= buf->b_ml.ml_line_count) + ? xstrdup(ml_get_buf(buf, start, false)) : NULL); } } @@ -2919,7 +2917,7 @@ static void f_getftime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "getftype({fname})" function static void f_getftype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - char_u *type = NULL; + char *type = NULL; char *t; const char *fname = tv_get_string(&argvars[0]); @@ -2945,9 +2943,9 @@ static void f_getftype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } else { t = "other"; } - type = vim_strsave((char_u *)t); + type = xstrdup(t); } - rettv->vval.v_string = (char *)type; + rettv->vval.v_string = type; } /// "getjumplist()" function @@ -3441,11 +3439,11 @@ static void f_glob(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) options += WILD_ICASE; } if (rettv->v_type == VAR_STRING) { - rettv->vval.v_string = (char *)ExpandOne(&xpc, (char_u *) - tv_get_string(&argvars[0]), NULL, options, - WILD_ALL); + rettv->vval.v_string = ExpandOne(&xpc, (char *) + tv_get_string(&argvars[0]), NULL, options, + WILD_ALL); } else { - ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options, + ExpandOne(&xpc, (char *)tv_get_string(&argvars[0]), NULL, options, WILD_ALL_KEEP); tv_list_alloc_ret(rettv, xpc.xp_numfiles); for (int i = 0; i < xpc.xp_numfiles; i++) { @@ -5443,11 +5441,11 @@ static void f_pathshorten(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } rettv->v_type = VAR_STRING; - const char_u *p = (char_u *)tv_get_string_chk(&argvars[0]); + const char *p = tv_get_string_chk(&argvars[0]); if (p == NULL) { rettv->vval.v_string = NULL; } else { - rettv->vval.v_string = (char *)vim_strsave(p); + rettv->vval.v_string = xstrdup(p); shorten_dir_len((char_u *)rettv->vval.v_string, trim_len); } } @@ -5565,7 +5563,7 @@ static void f_prompt_getprompt(typval_T *argvars, typval_T *rettv, EvalFuncData return; } - rettv->vval.v_string = (char *)vim_strsave(buf_prompt_text(buf)); + rettv->vval.v_string = xstrdup(buf_prompt_text(buf)); } /// "prompt_setprompt({buffer}, {text})" function @@ -7107,7 +7105,7 @@ static void f_screenstring(typval_T *argvars, typval_T *rettv, EvalFuncData fptr return; } - rettv->vval.v_string = (char *)vim_strsave(grid->chars[grid->line_offset[row] + (size_t)col]); + rettv->vval.v_string = xstrdup((char *)grid->chars[grid->line_offset[row] + (size_t)col]); } /// "search()" function @@ -8052,7 +8050,7 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv, EvalFuncData fptr // Find the start and length of the badly spelled word. len = spell_move_to(curwin, FORWARD, true, true, &attr); if (len != 0) { - word = (char *)get_cursor_pos_ptr(); + word = get_cursor_pos_ptr(); curwin->w_set_curswant = true; } } else if (*curbuf->b_s.b_p_spl != NUL) { @@ -8740,7 +8738,7 @@ static void f_swapname(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) || buf->b_ml.ml_mfp->mf_fname == NULL) { rettv->vval.v_string = NULL; } else { - rettv->vval.v_string = (char *)vim_strsave(buf->b_ml.ml_mfp->mf_fname); + rettv->vval.v_string = xstrdup(buf->b_ml.ml_mfp->mf_fname); } } @@ -9101,7 +9099,7 @@ static void f_taglist(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) static void f_tempname(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char *)vim_tempname(); + rettv->vval.v_string = vim_tempname(); } /// "termopen(cmd[, cwd])" function @@ -9595,12 +9593,12 @@ static void f_virtcol(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "visualmode()" function static void f_visualmode(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - char_u str[2]; + char str[2]; rettv->v_type = VAR_STRING; - str[0] = (char_u)curbuf->b_visual_mode_eval; + str[0] = (char)curbuf->b_visual_mode_eval; str[1] = NUL; - rettv->vval.v_string = (char *)vim_strsave(str); + rettv->vval.v_string = xstrdup(str); // A non-zero number or non-empty string argument: reset mode. if (non_zero_arg(&argvars[0])) { diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index a409271596..f6b97fe05b 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -2777,7 +2777,7 @@ static void tv_dict_list(typval_T *const tv, typval_T *const rettv, const DictLi switch (what) { case kDictListKeys: tv_item.v_type = VAR_STRING; - tv_item.vval.v_string = (char *)vim_strsave(di->di_key); + tv_item.vval.v_string = xstrdup((char *)di->di_key); break; case kDictListValues: tv_copy(&di->di_tv, &tv_item); diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h index 8177d01f90..cf7b04c8ce 100644 --- a/src/nvim/eval/typval.h +++ b/src/nvim/eval/typval.h @@ -360,15 +360,14 @@ struct ufunc { }; struct partial_S { - int pt_refcount; ///< Reference count. - char_u *pt_name; ///< Function name; when NULL use pt_func->name. - ufunc_T *pt_func; ///< Function pointer; when NULL lookup function with - ///< pt_name. - bool pt_auto; ///< When true the partial was created by using dict.member - ///< in handle_subscript(). - int pt_argc; ///< Number of arguments. + int pt_refcount; ///< Reference count. + char *pt_name; ///< Function name; when NULL use pt_func->name. + ufunc_T *pt_func; ///< Function pointer; when NULL lookup function with pt_name. + bool pt_auto; ///< When true the partial was created by using dict.member + ///< in handle_subscript(). + int pt_argc; ///< Number of arguments. typval_T *pt_argv; ///< Arguments in allocated array. - dict_T *pt_dict; ///< Dict for "self". + dict_T *pt_dict; ///< Dict for "self". }; /// Structure used for explicit stack while garbage collecting hash tables diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 3ab66c319f..36bc51179c 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -142,18 +142,18 @@ static int get_function_args(char **argp, char_u endchar, garray_T *newargs, int any_default = true; p = skipwhite(p) + 1; p = skipwhite(p); - char_u *expr = (char_u *)p; + char *expr = p; if (eval1(&p, &rettv, false) != FAIL) { ga_grow(default_args, 1); // trim trailing whitespace - while (p > (char *)expr && ascii_iswhite(p[-1])) { + while (p > expr && ascii_iswhite(p[-1])) { p--; } c = (char_u)(*p); *p = NUL; - expr = vim_strsave(expr); - ((char **)(default_args->ga_data))[default_args->ga_len] = (char *)expr; + expr = xstrdup(expr); + ((char **)(default_args->ga_data))[default_args->ga_len] = expr; default_args->ga_len++; *p = (char)c; } else { @@ -1680,7 +1680,7 @@ static void list_func_head(ufunc_T *fp, int indent, bool force) char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, partial_T **partial) FUNC_ATTR_NONNULL_ARG(1) { - char_u *name = NULL; + char *name = NULL; const char_u *start; const char_u *end; int lead; @@ -1739,7 +1739,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa fdp->fd_di = lv.ll_di; } if (lv.ll_tv->v_type == VAR_FUNC && lv.ll_tv->vval.v_string != NULL) { - name = vim_strsave((char_u *)lv.ll_tv->vval.v_string); + name = xstrdup(lv.ll_tv->vval.v_string); *pp = (char *)end; } else if (lv.ll_tv->v_type == VAR_PARTIAL && lv.ll_tv->vval.v_partial != NULL) { @@ -1753,7 +1753,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa memcpy(name, end + 1, (size_t)len); *pp = (char *)end + 1 + len; } else { - name = vim_strsave((char_u *)partial_name(lv.ll_tv->vval.v_partial)); + name = xstrdup(partial_name(lv.ll_tv->vval.v_partial)); *pp = (char *)end; } if (partial != NULL) { @@ -1781,28 +1781,28 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa // Check if the name is a Funcref. If so, use the value. if (lv.ll_exp_name != NULL) { len = (int)strlen(lv.ll_exp_name); - name = deref_func_name(lv.ll_exp_name, &len, partial, - flags & TFN_NO_AUTOLOAD); + name = (char *)deref_func_name(lv.ll_exp_name, &len, partial, + flags & TFN_NO_AUTOLOAD); if ((const char *)name == lv.ll_exp_name) { name = NULL; } } else if (!(flags & TFN_NO_DEREF)) { len = (int)(end - (char_u *)(*pp)); - name = deref_func_name((const char *)(*pp), &len, partial, - flags & TFN_NO_AUTOLOAD); - if (name == (char_u *)(*pp)) { + name = (char *)deref_func_name((const char *)(*pp), &len, partial, + flags & TFN_NO_AUTOLOAD); + if (name == *pp) { name = NULL; } } if (name != NULL) { - name = vim_strsave(name); + name = xstrdup(name); *pp = (char *)end; if (STRNCMP(name, "", 5) == 0) { // Change "" to the byte sequence. - name[0] = K_SPECIAL; - name[1] = KS_EXTRA; + name[0] = (char)K_SPECIAL; + name[1] = (char)KS_EXTRA; name[2] = KE_SNR; - memmove(name + 3, name + 5, strlen((char *)name + 5) + 1); + memmove(name + 3, name + 5, strlen(name + 5) + 1); } goto theend; } @@ -1865,8 +1865,8 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa name = xmalloc((size_t)len + (size_t)lead + 1); if (!skip && lead > 0) { - name[0] = K_SPECIAL; - name[1] = KS_EXTRA; + name[0] = (char)K_SPECIAL; + name[1] = (char)KS_EXTRA; name[2] = KE_SNR; if (sid_buf_len > 0) { // If it's "" memcpy(name + 3, sid_buf, sid_buf_len); @@ -1878,7 +1878,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa theend: clear_lval(&lv); - return name; + return (char_u *)name; } #define MAX_FUNC_NESTING 50 @@ -3104,7 +3104,7 @@ char *get_return_cmd(void *rettv) STRCPY(IObuff + IOSIZE - 4, "..."); } xfree(tofree); - return (char *)vim_strsave(IObuff); + return xstrdup((char *)IObuff); } /// Get next function line. @@ -3192,7 +3192,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) } else { fname = rettv->v_type == VAR_FUNC || rettv->v_type == VAR_STRING ? (char_u *)rettv->vval.v_string - : rettv->vval.v_partial->pt_name; + : (char_u *)rettv->vval.v_partial->pt_name; // Translate "s:func" to the stored function name. fname = (char_u *)fname_trans_sid((char *)fname, (char *)fname_buf, (char **)&tofree, &error); fp = find_func(fname); @@ -3208,7 +3208,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) pt->pt_auto = true; if (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_STRING) { // Just a function: Take over the function name and use selfdict. - pt->pt_name = (char_u *)rettv->vval.v_string; + pt->pt_name = rettv->vval.v_string; } else { partial_T *ret_pt = rettv->vval.v_partial; int i; @@ -3217,8 +3217,8 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) // args. Can't take over name or args, the partial might // be referenced elsewhere. if (ret_pt->pt_name != NULL) { - pt->pt_name = vim_strsave(ret_pt->pt_name); - func_ref(pt->pt_name); + pt->pt_name = xstrdup(ret_pt->pt_name); + func_ref((char_u *)pt->pt_name); } else { pt->pt_func = ret_pt->pt_func; func_ptr_ref(pt->pt_func); diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 8f256728e3..12920d932d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -118,7 +118,7 @@ void do_ascii(const exarg_T *const eap) { char *dig; int cc[MAX_MCO]; - int c = utfc_ptr2char((char *)get_cursor_pos_ptr(), cc); + int c = utfc_ptr2char(get_cursor_pos_ptr(), cc); if (c == NUL) { msg("NUL"); return; @@ -1068,7 +1068,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) curwin->w_cursor.lnum = n; while (line1 <= line2) { - // need to use vim_strsave() because the line will be unlocked within + // need to use xstrdup() because the line will be unlocked within // ml_append() p = xstrdup(ml_get(line1)); ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, false); @@ -1305,8 +1305,8 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b curbuf->b_op_start.lnum = line1; curbuf->b_op_end.lnum = line2; curwin->w_cursor.lnum = line2; - } else if ((do_in && (itmp = (char *)vim_tempname()) == NULL) - || (do_out && (otmp = (char *)vim_tempname()) == NULL)) { + } else if ((do_in && (itmp = vim_tempname()) == NULL) + || (do_out && (otmp = vim_tempname()) == NULL)) { emsg(_(e_notmp)); goto filterend; } @@ -3291,7 +3291,7 @@ static bool sub_joining_lines(exarg_T *eap, char *pat, char *sub, char *cmd, boo if (save) { if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0) { - save_re_pat(RE_SUBST, (char_u *)pat, p_magic); + save_re_pat(RE_SUBST, pat, p_magic); } // put pattern in history add_to_history(HIST_SEARCH, pat, true, NUL); @@ -3608,7 +3608,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T sub = xstrdup(sub); sub_copy = sub; } else { - char *newsub = (char *)regtilde((char_u *)sub, p_magic, cmdpreview); + char *newsub = regtilde(sub, p_magic, cmdpreview); if (newsub != sub) { // newsub was allocated, free it later. sub_copy = newsub; @@ -4782,7 +4782,7 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i if (next_linenr == orig_buf->b_ml.ml_line_count + 1) { line = ""; } else { - line = (char *)ml_get_buf(orig_buf, next_linenr, false); + line = ml_get_buf(orig_buf, next_linenr, false); line_size = strlen(line) + (size_t)col_width + 1; // Reallocate if line not long enough diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 8fb166d2c9..e32eb860ce 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -785,7 +785,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) vim_snprintf((char *)IObuff, IOSIZE, _("E605: Exception not caught: %s"), current_exception->value); - p = (char *)vim_strsave(IObuff); + p = xstrdup((char *)IObuff); break; case ET_ERROR: messages = current_exception->messages; @@ -1300,7 +1300,7 @@ static void parse_register(exarg_T *eap) // for '=' register: accept the rest of the line as an expression if (eap->arg[-1] == '=' && eap->arg[0] != NUL) { if (!eap->skip) { - set_expr_line(vim_strsave((char_u *)eap->arg)); + set_expr_line(xstrdup(eap->arg)); } eap->arg += STRLEN(eap->arg); } @@ -3829,7 +3829,7 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) if (p_wic) { options += WILD_ICASE; } - p = (char *)ExpandOne(&xpc, (char_u *)eap->arg, NULL, options, WILD_EXPAND_FREE); + p = ExpandOne(&xpc, eap->arg, NULL, options, WILD_EXPAND_FREE); if (p == NULL) { return FAIL; } @@ -5274,7 +5274,7 @@ static void ex_swapname(exarg_T *eap) if (curbuf->b_ml.ml_mfp == NULL || curbuf->b_ml.ml_mfp->mf_fname == NULL) { msg(_("No swap file")); } else { - msg((char *)curbuf->b_ml.ml_mfp->mf_fname); + msg(curbuf->b_ml.ml_mfp->mf_fname); } } @@ -6563,7 +6563,7 @@ static void ex_tag_cmd(exarg_T *eap, char *name) cmd = DT_LTAG; } - do_tag((char_u *)eap->arg, cmd, eap->addr_count > 0 ? (int)eap->line2 : 1, + do_tag(eap->arg, cmd, eap->addr_count > 0 ? (int)eap->line2 : 1, eap->forceit, true); } diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 20725b81ee..f40149d07a 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -529,7 +529,7 @@ static void discard_exception(except_T *excp, bool was_finished) if (p_verbose >= 13 || debug_break_level > 0) { int save_msg_silent = msg_silent; - saved_IObuff = (char *)vim_strsave(IObuff); + saved_IObuff = xstrdup((char *)IObuff); if (debug_break_level > 0) { msg_silent = false; // display messages } else { diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index da99a03c38..cf95287d61 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -105,7 +105,7 @@ typedef struct command_line_state { int c; int gotesc; // true when just typed int do_abbr; // when true check for abbr. - char_u *lookfor; // string to match + char *lookfor; // string to match int hiscnt; // current history line in use int save_hiscnt; // history line before attempting // to jump to next match @@ -116,7 +116,7 @@ typedef struct command_line_state { int res; int save_msg_scroll; int save_State; // remember State when called - char_u *save_p_icm; + char *save_p_icm; int some_key_typed; // one of the keys was typed // mouse drag and release events are ignored, unless they are // preceded with a mouse down event @@ -632,7 +632,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init .ignore_drag_release = true, }; CommandLineState *s = &state; - s->save_p_icm = vim_strsave((char_u *)p_icm); + s->save_p_icm = xstrdup(p_icm); init_incsearch_state(&s->is_state); CmdlineInfo save_ccline; bool did_save_ccline = false; @@ -879,7 +879,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init need_wait_return = false; } - set_string_option_direct("icm", -1, (char *)s->save_p_icm, OPT_FREE, SID_NONE); + set_string_option_direct("icm", -1, s->save_p_icm, OPT_FREE, SID_NONE); State = s->save_State; if (cmdpreview != save_cmdpreview) { cmdpreview = save_cmdpreview; // restore preview state @@ -1087,7 +1087,7 @@ static int command_line_execute(VimState *state, int key) s->c = get_expr_register(); if (s->c == '=') { textlock++; - p = get_expr_line(); + p = (char_u *)get_expr_line(); textlock--; if (p != NULL) { @@ -1853,7 +1853,7 @@ static int command_line_handle_key(CommandLineState *s) // save current command string so it can be restored later if (s->lookfor == NULL) { - s->lookfor = vim_strsave((char_u *)ccline.cmdbuff); + s->lookfor = xstrdup(ccline.cmdbuff); s->lookfor[ccline.cmdpos] = NUL; } @@ -1870,13 +1870,13 @@ static int command_line_handle_key(CommandLineState *s) XFREE_CLEAR(ccline.cmdbuff); s->xpc.xp_context = EXPAND_NOTHING; if (s->hiscnt == get_hislen()) { - p = s->lookfor; // back to the old one + p = (char_u *)s->lookfor; // back to the old one } else { p = (char_u *)get_histentry(s->histype)[s->hiscnt].hisstr; } if (s->histype == HIST_SEARCH - && p != s->lookfor + && p != (char_u *)s->lookfor && (old_firstc = p[STRLEN(p) + 1]) != s->firstc) { // Correct for the separator character used when // adding the history entry vs the one used now. diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 76a429b5ef..5416be651d 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -69,7 +69,7 @@ #include "nvim/vim.h" #include "nvim/window.h" -static char_u *ff_expand_buffer = NULL; // used for expanding filenames +static char *ff_expand_buffer = NULL; // used for expanding filenames // type for the directory search stack typedef struct ff_stack { @@ -105,7 +105,7 @@ typedef struct ff_visited { // Visited directories are different if the wildcard string are // different. So we have to save it. - char_u *ffv_wc_path; + char *ffv_wc_path; // use FileID for comparison (needed because of links), else use filename. bool file_id_valid; @@ -131,7 +131,7 @@ typedef struct ff_visited_list_hdr { struct ff_visited_list_hdr *ffvl_next; // the filename the attached visited list is for - char_u *ffvl_filename; + char *ffvl_filename; ff_visited_T *ffvl_visited_list; } ff_visited_list_hdr_T; @@ -259,12 +259,12 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i // Reuse old visited lists. Get the visited list for the given // filename. If no list for the current filename exists, creates a new // one. - search_ctx->ffsc_visited_list = ff_get_visited_list((char_u *)filename, + search_ctx->ffsc_visited_list = ff_get_visited_list(filename, &search_ctx->ffsc_visited_lists_list); if (search_ctx->ffsc_visited_list == NULL) { goto error_return; } - search_ctx->ffsc_dir_visited_list = ff_get_visited_list((char_u *)filename, + search_ctx->ffsc_dir_visited_list = ff_get_visited_list(filename, &search_ctx->ffsc_dir_visited_lists_list); if (search_ctx->ffsc_dir_visited_list == NULL) { goto error_return; @@ -286,7 +286,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i if (!vim_isAbsName((char_u *)rel_fname) && len + 1 < MAXPATHL) { // Make the start dir an absolute path name. STRLCPY(ff_expand_buffer, rel_fname, len + 1); - search_ctx->ffsc_start_dir = FullName_save((char *)ff_expand_buffer, false); + search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, false); } else { search_ctx->ffsc_start_dir = xstrnsave(rel_fname, len); } @@ -310,11 +310,11 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i path += 2; } else #endif - if (os_dirname(ff_expand_buffer, MAXPATHL) == FAIL) { + if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) == FAIL) { goto error_return; } - search_ctx->ffsc_start_dir = (char *)vim_strsave(ff_expand_buffer); + search_ctx->ffsc_start_dir = xstrdup(ff_expand_buffer); #ifdef BACKSLASH_IN_FILENAME // A path that starts with "/dir" is relative to the drive, not to the @@ -396,12 +396,12 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i break; } if (STRNCMP(wc_part, "**", 2) == 0) { - ff_expand_buffer[len++] = (char_u)(*wc_part++); - ff_expand_buffer[len++] = (char_u)(*wc_part++); + ff_expand_buffer[len++] = *wc_part++; + ff_expand_buffer[len++] = *wc_part++; llevel = strtol(wc_part, &errpt, 10); if (errpt != wc_part && llevel > 0 && llevel < 255) { - ff_expand_buffer[len++] = (char_u)llevel; + ff_expand_buffer[len++] = (char)llevel; } else if (errpt != wc_part && llevel == 0) { // restrict is 0 -> remove already added '**' len -= 2; @@ -416,11 +416,11 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i goto error_return; } } else { - ff_expand_buffer[len++] = (char_u)(*wc_part++); + ff_expand_buffer[len++] = *wc_part++; } } ff_expand_buffer[len] = NUL; - search_ctx->ffsc_wc_path = (char *)vim_strsave(ff_expand_buffer); + search_ctx->ffsc_wc_path = xstrdup(ff_expand_buffer); } else { search_ctx->ffsc_fix_path = xstrdup(path); } @@ -439,7 +439,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i goto error_return; } STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir); - add_pathsep((char *)ff_expand_buffer); + add_pathsep(ff_expand_buffer); { size_t eb_len = STRLEN(ff_expand_buffer); char_u *buf = xmalloc(eb_len + STRLEN(search_ctx->ffsc_fix_path) + 1); @@ -448,7 +448,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i STRCPY(buf + eb_len, search_ctx->ffsc_fix_path); if (os_isdir((char *)buf)) { STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path); - add_pathsep((char *)ff_expand_buffer); + add_pathsep(ff_expand_buffer); } else { char *p = path_tail(search_ctx->ffsc_fix_path); char *wc_path = NULL; @@ -464,7 +464,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i goto error_return; } STRLCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, eb_len + (size_t)len + 1); - add_pathsep((char *)ff_expand_buffer); + add_pathsep(ff_expand_buffer); } else { len = (int)STRLEN(search_ctx->ffsc_fix_path); } @@ -484,7 +484,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i xfree(buf); } - sptr = ff_create_stack_element(ff_expand_buffer, (char_u *)search_ctx->ffsc_wc_path, level, 0); + sptr = ff_create_stack_element(ff_expand_buffer, search_ctx->ffsc_wc_path, level, 0); ff_push(search_ctx, sptr); search_ctx->ffsc_file_to_search = xstrdup(filename); @@ -607,7 +607,7 @@ char_u *vim_findfile(void *search_ctx_arg) // first time (hence stackp->ff_filearray == NULL) if (stackp->ffs_filearray == NULL && ff_check_visited(&search_ctx->ffsc_dir_visited_list->ffvl_visited_list, - stackp->ffs_fix_path, stackp->ffs_wc_path) == FAIL) { + (char *)stackp->ffs_fix_path, (char *)stackp->ffs_wc_path) == FAIL) { #ifdef FF_VERBOSE if (p_verbose >= 5) { verbose_enter_scroll(); @@ -787,7 +787,7 @@ char_u *vim_findfile(void *search_ctx_arg) == os_isdir((char *)file_path))))) #ifndef FF_VERBOSE && (ff_check_visited(&search_ctx->ffsc_visited_list->ffvl_visited_list, - file_path, (char_u *)"") == OK) + (char *)file_path, "") == OK) #endif ) { #ifdef FF_VERBOSE @@ -811,10 +811,10 @@ char_u *vim_findfile(void *search_ctx_arg) if (!path_with_url((char *)file_path)) { simplify_filename(file_path); } - if (os_dirname(ff_expand_buffer, MAXPATHL) + if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) == OK) { p = path_shorten_fname(file_path, - ff_expand_buffer); + (char_u *)ff_expand_buffer); if (p != NULL) { STRMOVE(file_path, p); } @@ -845,8 +845,8 @@ char_u *vim_findfile(void *search_ctx_arg) continue; // not a directory } ff_push(search_ctx, - ff_create_stack_element((char_u *)stackp->ffs_filearray[i], - rest_of_wildcards, + ff_create_stack_element(stackp->ffs_filearray[i], + (char *)rest_of_wildcards, stackp->ffs_level - 1, 0)); } } @@ -867,8 +867,8 @@ char_u *vim_findfile(void *search_ctx_arg) continue; // not a directory } ff_push(search_ctx, - ff_create_stack_element((char_u *)stackp->ffs_filearray[i], - stackp->ffs_wc_path, stackp->ffs_level - 1, 1)); + ff_create_stack_element(stackp->ffs_filearray[i], + (char *)stackp->ffs_wc_path, stackp->ffs_level - 1, 1)); } } @@ -914,8 +914,8 @@ char_u *vim_findfile(void *search_ctx_arg) STRCAT(file_path, search_ctx->ffsc_fix_path); // create a new stack entry - sptr = ff_create_stack_element(file_path, - (char_u *)search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); + sptr = ff_create_stack_element((char *)file_path, + search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); ff_push(search_ctx, sptr); } else { break; @@ -972,7 +972,7 @@ static void ff_free_visited_list(ff_visited_T *vl) /// @return the already visited list for the given filename. If none is found it /// allocates a new one. -static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, +static ff_visited_list_hdr_T *ff_get_visited_list(char *filename, ff_visited_list_hdr_T **list_headp) { ff_visited_list_hdr_T *retptr = NULL; @@ -1009,7 +1009,7 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, retptr = xmalloc(sizeof(*retptr)); retptr->ffvl_visited_list = NULL; - retptr->ffvl_filename = vim_strsave(filename); + retptr->ffvl_filename = xstrdup(filename); retptr->ffvl_next = *list_headp; *list_headp = retptr; @@ -1060,7 +1060,7 @@ static bool ff_wc_equal(char_u *s1, char_u *s2) /// /// @return FAIL if the given file/dir is already in the list or, /// OK if it is newly added -static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *wc_path) +static int ff_check_visited(ff_visited_T **visited_list, char *fname, char *wc_path) { ff_visited_T *vp; bool url = false; @@ -1068,12 +1068,12 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * FileID file_id; // For a URL we only compare the name, otherwise we compare the // device/inode. - if (path_with_url((char *)fname)) { + if (path_with_url(fname)) { STRLCPY(ff_expand_buffer, fname, MAXPATHL); url = true; } else { ff_expand_buffer[0] = NUL; - if (!os_fileid((char *)fname, &file_id)) { + if (!os_fileid(fname, &file_id)) { return FAIL; } } @@ -1084,7 +1084,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * || (!url && vp->file_id_valid && os_fileid_equal(&(vp->file_id), &file_id))) { // are the wildcard parts equal - if (ff_wc_equal(vp->ffv_wc_path, wc_path)) { + if (ff_wc_equal((char_u *)vp->ffv_wc_path, (char_u *)wc_path)) { // already visited return FAIL; } @@ -1104,7 +1104,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * } if (wc_path != NULL) { - vp->ffv_wc_path = vim_strsave(wc_path); + vp->ffv_wc_path = xstrdup(wc_path); } else { vp->ffv_wc_path = NULL; } @@ -1116,7 +1116,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * } /// create stack element from given path pieces -static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, int level, +static ff_stack_T *ff_create_stack_element(char *fix_part, char *wc_part, int level, int star_star_empty) { ff_stack_T *new = xmalloc(sizeof(ff_stack_T)); @@ -1131,14 +1131,14 @@ static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, in // the following saves NULL pointer checks in vim_findfile if (fix_part == NULL) { - fix_part = (char_u *)""; + fix_part = ""; } - new->ffs_fix_path = vim_strsave(fix_part); + new->ffs_fix_path = (char_u *)xstrdup(fix_part); if (wc_part == NULL) { - wc_part = (char_u *)""; + wc_part = ""; } - new->ffs_wc_path = vim_strsave(wc_part); + new->ffs_wc_path = (char_u *)xstrdup(wc_part); return new; } @@ -1292,7 +1292,7 @@ char_u *find_file_in_path(char_u *ptr, size_t len, int options, int first, char_ FINDFILE_BOTH, rel_fname, (char_u *)curbuf->b_p_sua); } -static char_u *ff_file_to_find = NULL; +static char *ff_file_to_find = NULL; static void *fdip_search_ctx = NULL; #if defined(EXITFREE) @@ -1338,7 +1338,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first static char *dir; static int did_findfile_init = false; char_u save_char; - char_u *file_name = NULL; + char *file_name = NULL; char *buf = NULL; int rel_to_curdir; @@ -1359,10 +1359,10 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first ptr[len] = save_char; xfree(ff_file_to_find); - ff_file_to_find = vim_strsave((char_u *)NameBuff); + ff_file_to_find = xstrdup(NameBuff); if (options & FNAME_UNESC) { // Change all "\ " to " ". - for (ptr = ff_file_to_find; *ptr != NUL; ptr++) { + for (ptr = (char_u *)ff_file_to_find; *ptr != NUL; ptr++) { if (ptr[0] == '\\' && ptr[1] == ' ') { memmove(ptr, ptr + 1, STRLEN(ptr)); } @@ -1376,7 +1376,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first || (ff_file_to_find[1] == '.' && (ff_file_to_find[2] == NUL || vim_ispathsep(ff_file_to_find[2]))))); - if (vim_isAbsName(ff_file_to_find) + if (vim_isAbsName((char_u *)ff_file_to_find) // "..", "../path", "." and "./path": don't use the path_option || rel_to_curdir #if defined(WIN32) @@ -1390,8 +1390,8 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first // If this is not a first call, return NULL. We already returned a // filename on the first call. if (first == true) { - if (path_with_url((char *)ff_file_to_find)) { - file_name = vim_strsave(ff_file_to_find); + if (path_with_url(ff_file_to_find)) { + file_name = xstrdup(ff_file_to_find); goto theend; } @@ -1420,7 +1420,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first && (find_what == FINDFILE_BOTH || ((find_what == FINDFILE_DIR) == os_isdir(NameBuff))))) { - file_name = vim_strsave((char_u *)NameBuff); + file_name = xstrdup(NameBuff); goto theend; } if (*buf == NUL) { @@ -1444,7 +1444,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first for (;;) { if (did_findfile_init) { - file_name = vim_findfile(fdip_search_ctx); + file_name = (char *)vim_findfile(fdip_search_ctx); if (file_name != NULL) { break; } @@ -1468,7 +1468,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first // get the stopdir string r_ptr = vim_findfile_stopdir((char_u *)buf); - fdip_search_ctx = vim_findfile_init(buf, (char *)ff_file_to_find, + fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find, (char *)r_ptr, 100, false, find_what, fdip_search_ctx, false, (char *)rel_fname); if (fdip_search_ctx != NULL) { @@ -1499,7 +1499,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first } theend: - return file_name; + return (char_u *)file_name; } void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause, bool pre) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index b399885095..0d8eec1023 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2049,7 +2049,7 @@ static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp) char_u *tmpname; char *errmsg = NULL; - tmpname = vim_tempname(); + tmpname = (char_u *)vim_tempname(); if (tmpname == NULL) { errmsg = _("Can't find temp file for conversion"); } else { @@ -2697,7 +2697,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en } } - rootname = (char *)get_file_in_dir((char_u *)fname, IObuff); + rootname = get_file_in_dir(fname, (char *)IObuff); if (rootname == NULL) { some_error = true; // out of memory goto nobackup; @@ -2847,7 +2847,7 @@ nobackup: } if (backup == NULL) { - rootname = (char *)get_file_in_dir((char_u *)fname, IObuff); + rootname = get_file_in_dir(fname, (char *)IObuff); if (rootname == NULL) { backup = NULL; } else { @@ -2993,7 +2993,7 @@ nobackup: // writing, write to a temp file instead and let the conversion // overwrite the original file. if (*p_ccv != NUL) { - wfname = (char *)vim_tempname(); + wfname = vim_tempname(); if (wfname == NULL) { // Can't write without a tempfile! SET_ERRMSG(_("E214: Can't find temp file for writing")); goto restore_backup; @@ -3170,7 +3170,7 @@ restore_backup: for (lnum = start; lnum <= end; lnum++) { // The next while loop is done once for each character written. // Keep it fast! - ptr = (char *)ml_get_buf(buf, lnum, false) - 1; + ptr = ml_get_buf(buf, lnum, false) - 1; if (write_undo_file) { sha256_update(&sha_ctx, (char_u *)ptr + 1, (uint32_t)(STRLEN(ptr + 1) + 1)); } @@ -4704,13 +4704,13 @@ static int move_lines(buf_T *frombuf, buf_T *tobuf) buf_T *tbuf = curbuf; int retval = OK; linenr_T lnum; - char_u *p; + char *p; // Copy the lines in "frombuf" to "tobuf". curbuf = tobuf; for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; lnum++) { - p = vim_strsave(ml_get_buf(frombuf, lnum, false)); - if (ml_append(lnum - 1, (char *)p, 0, false) == FAIL) { + p = xstrdup(ml_get_buf(frombuf, lnum, false)); + if (ml_append(lnum - 1, p, 0, false) == FAIL) { xfree(p); retval = FAIL; break; @@ -5358,7 +5358,7 @@ static bool vim_settempdir(char *tempdir) /// /// @return pointer to the temp file name or NULL if Nvim can't create /// temporary directory for its own temporary files. -char_u *vim_tempname(void) +char *vim_tempname(void) { // Temp filename counter. static uint64_t temp_count; @@ -5370,10 +5370,10 @@ char_u *vim_tempname(void) // There is no need to check if the file exists, because we own the directory // and nobody else creates a file in it. - char_u template[TEMP_FILE_PATH_MAXLEN]; - snprintf((char *)template, TEMP_FILE_PATH_MAXLEN, + char template[TEMP_FILE_PATH_MAXLEN]; + snprintf(template, TEMP_FILE_PATH_MAXLEN, "%s%" PRIu64, tempdir, temp_count++); - return vim_strsave(template); + return xstrdup(template); } /// Tries matching a filename with a "pattern" ("prog" is NULL), or use the diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 0f085df3d0..2e8d282ede 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1582,7 +1582,7 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char *marker, size_t mark linenr_T lnum = pos.lnum; // Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end - char *line = (char *)ml_get_buf(buf, lnum, false); + char *line = ml_get_buf(buf, lnum, false); size_t line_len = STRLEN(line); size_t added = 0; @@ -1640,7 +1640,7 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char *marker, size_t marker } char *cms = buf->b_p_cms; - char *line = (char *)ml_get_buf(buf, lnum, false); + char *line = ml_get_buf(buf, lnum, false); for (char *p = line; *p != NUL; p++) { if (STRNCMP(p, marker, markerlen) != 0) { continue; @@ -2848,7 +2848,7 @@ static void foldlevelIndent(fline_T *flp) linenr_T lnum = flp->lnum + flp->off; buf_T *buf = flp->wp->w_buffer; - char *s = skipwhite((char *)ml_get_buf(buf, lnum, false)); + char *s = skipwhite(ml_get_buf(buf, lnum, false)); // empty line or lines starting with a character in 'foldignore': level // depends on surrounding lines @@ -3010,7 +3010,7 @@ static void foldlevelMarker(fline_T *flp) flp->start = 0; flp->lvl_next = flp->lvl; - char *s = (char *)ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false); + char *s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false); while (*s) { if (*s == cstart && STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0) { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index e125d88395..0f0e3aece1 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1708,26 +1708,26 @@ static void getchar_common(typval_T *argvars, typval_T *rettv) rettv->vval.v_number = n; if (n != 0 && (IS_SPECIAL(n) || mod_mask != 0)) { - char_u temp[10]; // modifier: 3, mbyte-char: 6, NUL: 1 + char temp[10]; // modifier: 3, mbyte-char: 6, NUL: 1 int i = 0; // Turn a special key into three bytes, plus modifier. if (mod_mask != 0) { - temp[i++] = K_SPECIAL; - temp[i++] = KS_MODIFIER; - temp[i++] = (char_u)mod_mask; + temp[i++] = (char)K_SPECIAL; + temp[i++] = (char)KS_MODIFIER; + temp[i++] = (char)mod_mask; } if (IS_SPECIAL(n)) { - temp[i++] = K_SPECIAL; - temp[i++] = (char_u)K_SECOND(n); - temp[i++] = K_THIRD(n); + temp[i++] = (char)K_SPECIAL; + temp[i++] = (char)K_SECOND(n); + temp[i++] = (char)K_THIRD(n); } else { - i += utf_char2bytes((int)n, (char *)temp + i); + i += utf_char2bytes((int)n, temp + i); } assert(i < 10); temp[i++] = NUL; rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char *)vim_strsave(temp); + rettv->vval.v_string = xstrdup(temp); if (is_mouse_key((int)n)) { int row = mouse_row; @@ -2135,7 +2135,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) // complete match if (keylen >= 0 && keylen <= typebuf.tb_len) { - char_u *map_str = NULL; + char *map_str = NULL; // Write chars to script file(s). // Note: :lmap mappings are written *after* being applied. #5658 @@ -2175,8 +2175,8 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) char save_m_expr = mp->m_expr; int save_m_noremap = mp->m_noremap; char save_m_silent = mp->m_silent; - char_u *save_m_keys = NULL; // only saved when needed - char_u *save_m_str = NULL; // only saved when needed + char *save_m_keys = NULL; // only saved when needed + char *save_m_str = NULL; // only saved when needed LuaRef save_m_luaref = mp->m_luaref; // Handle ":map ": evaluate the {rhs} as an @@ -2193,9 +2193,9 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) vgetc_busy = 0; may_garbage_collect = false; - save_m_keys = vim_strsave(mp->m_keys); + save_m_keys = xstrdup((char *)mp->m_keys); if (save_m_luaref == LUA_NOREF) { - save_m_str = vim_strsave((char_u *)mp->m_str); + save_m_str = xstrdup(mp->m_str); } map_str = eval_map_expr(mp, NUL); @@ -2207,13 +2207,13 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) // If an error was displayed and the expression returns an empty // string, generate a to allow for a redraw. if (prev_did_emsg != did_emsg && (map_str == NULL || *map_str == NUL)) { - char_u buf[4]; + char buf[4]; xfree(map_str); - buf[0] = K_SPECIAL; - buf[1] = KS_EXTRA; + buf[0] = (char)K_SPECIAL; + buf[1] = (char)KS_EXTRA; buf[2] = KE_IGNORE; buf[3] = NUL; - map_str = vim_strsave(buf); + map_str = xstrdup(buf); if (State & MODE_CMDLINE) { // redraw the command below the error msg_didout = true; @@ -2227,7 +2227,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) vgetc_busy = save_vgetc_busy; may_garbage_collect = save_may_garbage_collect; } else { - map_str = (char_u *)mp->m_str; + map_str = mp->m_str; } // Insert the 'to' part in the typebuf.tb_buf. @@ -2242,18 +2242,18 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) // If this is a LANGMAP mapping, then we didn't record the keys // at the start of the function and have to record them now. if (keylen > typebuf.tb_maplen && (mp->m_mode & MODE_LANGMAP) != 0) { - gotchars(map_str, STRLEN(map_str)); + gotchars((char_u *)map_str, STRLEN(map_str)); } if (save_m_noremap != REMAP_YES) { noremap = save_m_noremap; - } else if (STRNCMP(map_str, save_m_keys != NULL ? save_m_keys : mp->m_keys, + } else if (STRNCMP(map_str, save_m_keys != NULL ? save_m_keys : (char *)mp->m_keys, (size_t)keylen) != 0) { noremap = REMAP_YES; } else { noremap = REMAP_SKIP; } - i = ins_typebuf((char *)map_str, noremap, 0, true, cmd_silent || save_m_silent); + i = ins_typebuf(map_str, noremap, 0, true, cmd_silent || save_m_silent); if (save_m_expr) { xfree(map_str); } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 060db3b3b1..84c01e0140 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -599,7 +599,7 @@ EXTERN int inhibit_delete_count INIT(= 0); #define DBCS_DEBUG (-1) /// Encoding used when 'fencs' is set to "default" -EXTERN char_u *fenc_default INIT(= NULL); +EXTERN char *fenc_default INIT(= NULL); /// "State" is the main state of Vim. /// There are other variables that modify the state: diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 85f59f39de..903349dcae 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -2292,7 +2292,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) // If the user didn't specify a file name, use a temp file. if (psettings->outfile == NULL) { - prt_ps_file_name = vim_tempname(); + prt_ps_file_name = (char_u *)vim_tempname(); if (prt_ps_file_name == NULL) { emsg(_(e_notmp)); return FAIL; diff --git a/src/nvim/help.c b/src/nvim/help.c index 245d80489f..235f64744a 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -180,7 +180,7 @@ void ex_help(exarg_T *eap) // It is needed for do_tag top open folds under the cursor. KeyTyped = old_KeyTyped; - do_tag((char_u *)tag, DT_HELP, 1, false, true); + do_tag(tag, DT_HELP, 1, false, true); // Delete the empty buffer if we're not using it. Careful: autocommands // may have jumped to another window, check that the buffer is not in a @@ -658,13 +658,13 @@ void fix_help_buffer(void) if (!syntax_present(curwin)) { for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) { - line = (char *)ml_get_buf(curbuf, lnum, false); + line = ml_get_buf(curbuf, lnum, false); const size_t len = STRLEN(line); if (in_example && len > 0 && !ascii_iswhite(line[0])) { // End of example: non-white or '<' in first column. if (line[0] == '<') { // blank-out a '<' in the first column - line = (char *)ml_get_buf(curbuf, lnum, true); + line = ml_get_buf(curbuf, lnum, true); line[0] = ' '; } in_example = false; @@ -672,12 +672,12 @@ void fix_help_buffer(void) if (!in_example && len > 0) { if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) { // blank-out a '>' in the last column (start of example) - line = (char *)ml_get_buf(curbuf, lnum, true); + line = ml_get_buf(curbuf, lnum, true); line[len - 1] = ' '; in_example = true; } else if (line[len - 1] == '~') { // blank-out a '~' at the end of line (header marker) - line = (char *)ml_get_buf(curbuf, lnum, true); + line = ml_get_buf(curbuf, lnum, true); line[len - 1] = ' '; } } @@ -694,7 +694,7 @@ void fix_help_buffer(void) && TOLOWER_ASC(fname[7]) == 'x' && fname[8] == NUL)) { for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; lnum++) { - line = (char *)ml_get_buf(curbuf, lnum, false); + line = ml_get_buf(curbuf, lnum, false); if (strstr(line, "*local-additions*") == NULL) { continue; } @@ -1167,8 +1167,7 @@ void ex_helptags(exarg_T *eap) } else { ExpandInit(&xpc); xpc.xp_context = EXPAND_DIRECTORIES; - dirname = (char *)ExpandOne(&xpc, (char_u *)eap->arg, NULL, - WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); + dirname = ExpandOne(&xpc, eap->arg, NULL, WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); if (dirname == NULL || !os_isdir(dirname)) { semsg(_("E150: Not a directory: %s"), eap->arg); } else { diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 412fe3509d..7e5fd52243 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -553,12 +553,12 @@ void init_highlight(bool both, bool reset) // Try finding the color scheme file. Used when a color file was loaded // and 'background' or 't_Co' is changed. - char_u *p = get_var_value("g:colors_name"); + char *p = (char *)get_var_value("g:colors_name"); if (p != NULL) { // Value of g:colors_name could be freed in load_colors() and make // p invalid, so copy it. - char_u *copy_p = vim_strsave(p); - bool okay = load_colors(copy_p); + char *copy_p = xstrdup(p); + bool okay = load_colors((char_u *)copy_p); xfree(copy_p); if (okay) { return; diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 85534ebcff..719899d0b8 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -228,16 +228,16 @@ void ex_cstag(exarg_T *eap) } if (cs_check_for_tags()) { - ret = do_tag((char_u *)eap->arg, DT_JUMP, 0, eap->forceit, false); + ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, false); } } } else if (cs_check_for_tags()) { - ret = do_tag((char_u *)eap->arg, DT_JUMP, 0, eap->forceit, false); + ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, false); } break; case 1: if (cs_check_for_tags()) { - ret = do_tag((char_u *)eap->arg, DT_JUMP, 0, eap->forceit, false); + ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, false); if (ret == false) { if (msg_col) { msg_putchar('\n'); @@ -1003,7 +1003,7 @@ static bool cs_find_common(char *opt, char *pat, int forceit, int verbose, bool if (qfpos != NULL && *qfpos != '0') { // Fill error list. FILE *f; - char_u *tmp = vim_tempname(); + char_u *tmp = (char_u *)vim_tempname(); qf_info_T *qi = NULL; win_T *wp = NULL; @@ -1053,7 +1053,7 @@ static bool cs_find_common(char *opt, char *pat, int forceit, int verbose, bool (void)cs_manage_matches(matches, contexts, matched, Store); - return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose); + return do_tag(pat, DT_CSCOPE, 0, forceit, verbose); } } diff --git a/src/nvim/indent.c b/src/nvim/indent.c index a41a396abc..af5bcd7d2a 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -362,7 +362,7 @@ int get_indent_lnum(linenr_T lnum) // "buf". int get_indent_buf(buf_T *buf, linenr_T lnum) { - return get_indent_str_vtab((char *)ml_get_buf(buf, lnum, false), + return get_indent_str_vtab(ml_get_buf(buf, lnum, false), curbuf->b_p_ts, buf->b_p_vts_array, false); @@ -874,7 +874,7 @@ bool may_do_si(void) return curbuf->b_p_si && !curbuf->b_p_cin && *curbuf->b_p_inde == NUL && !p_paste; } -// Get indent level from 'indentexpr'. +/// Get indent level from 'indentexpr'. int get_expr_indent(void) { int indent = -1; @@ -898,8 +898,8 @@ int get_expr_indent(void) // Need to make a copy, the 'indentexpr' option could be changed while // evaluating it. - char_u *inde_copy = vim_strsave((char_u *)curbuf->b_p_inde); - indent = (int)eval_to_number((char *)inde_copy); + char *inde_copy = xstrdup(curbuf->b_p_inde); + indent = (int)eval_to_number(inde_copy); xfree(inde_copy); if (use_sandbox) { diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 5941473825..c7f37790b6 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1838,7 +1838,7 @@ int get_c_indent(void) int cur_amount = MAXCOL; colnr_T col; char_u *theline; - char_u *linecopy; + char *linecopy; pos_T *trypos; pos_T *comment_pos; pos_T *tryposBrace = NULL; @@ -1893,7 +1893,7 @@ int get_c_indent(void) // Get a copy of the current contents of the line. // This is required, because only the most recent line obtained with // ml_get is valid! - linecopy = vim_strsave((char_u *)ml_get(cur_curpos.lnum)); + linecopy = xstrdup(ml_get(cur_curpos.lnum)); // In insert mode and the cursor is on a ')' truncate the line at the // cursor position. We don't want to line up with the matching '(' when @@ -1906,7 +1906,7 @@ int get_c_indent(void) linecopy[curwin->w_cursor.col] = NUL; } - theline = (char_u *)skipwhite((char *)linecopy); + theline = (char_u *)skipwhite(linecopy); // move the cursor to the start of the line diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index dce72a2611..686461ce60 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -132,10 +132,10 @@ typedef struct compl_S compl_T; struct compl_S { compl_T *cp_next; compl_T *cp_prev; - char_u *cp_str; ///< matched text - char_u *(cp_text[CPT_COUNT]); ///< text for the menu + char *cp_str; ///< matched text + char *(cp_text[CPT_COUNT]); ///< text for the menu typval_T cp_user_data; - char_u *cp_fname; ///< file containing the match, allocated when + char *cp_fname; ///< file containing the match, allocated when ///< cp_flags has CP_FREE_FNAME int cp_flags; ///< CP_ values int cp_number; ///< sequence number @@ -191,7 +191,7 @@ static bool compl_enter_selects = false; /// When "compl_leader" is not NULL only matches that start with this string /// are used. -static char_u *compl_leader = NULL; +static char *compl_leader = NULL; static bool compl_get_longest = false; ///< put longest common string in compl_leader @@ -802,7 +802,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons if (flags & CP_ORIGINAL_TEXT) { match->cp_number = 0; } - match->cp_str = (char_u *)xstrnsave(str, (size_t)len); + match->cp_str = xstrnsave(str, (size_t)len); // match-fname is: // - compl_curr_match->cp_fname if it is a string equal to fname. @@ -814,7 +814,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons && STRCMP(fname, compl_curr_match->cp_fname) == 0) { match->cp_fname = compl_curr_match->cp_fname; } else if (fname != NULL) { - match->cp_fname = vim_strsave((char_u *)fname); + match->cp_fname = xstrdup(fname); flags |= CP_FREE_FNAME; } else { match->cp_fname = NULL; @@ -829,9 +829,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons continue; } if (*cptext[i] != NUL) { - match->cp_text[i] = (cptext_allocated - ? (char_u *)cptext[i] - : (char_u *)xstrdup(cptext[i])); + match->cp_text[i] = (cptext_allocated ? cptext[i] : xstrdup(cptext[i])); } else if (cptext_allocated) { xfree(cptext[i]); } @@ -898,11 +896,11 @@ static void ins_compl_longest_match(compl_T *match) if (compl_leader == NULL) { // First match, use it as a whole. - compl_leader = vim_strsave(match->cp_str); + compl_leader = xstrdup(match->cp_str); had_match = (curwin->w_cursor.col > compl_col); ins_compl_delete(); - ins_bytes((char *)compl_leader + get_compl_len()); + ins_bytes(compl_leader + get_compl_len()); ins_redraw(false); // When the match isn't there (to avoid matching itself) remove it @@ -916,8 +914,8 @@ static void ins_compl_longest_match(compl_T *match) } // Reduce the text if this match differs from compl_leader. - p = compl_leader; - s = match->cp_str; + p = (char_u *)compl_leader; + s = (char_u *)match->cp_str; while (*p != NUL) { c1 = utf_ptr2char((char *)p); c2 = utf_ptr2char((char *)s); @@ -936,7 +934,7 @@ static void ins_compl_longest_match(compl_T *match) *p = NUL; had_match = (curwin->w_cursor.col > compl_col); ins_compl_delete(); - ins_bytes((char *)compl_leader + get_compl_len()); + ins_bytes(compl_leader + get_compl_len()); ins_redraw(false); // When the match isn't there (to avoid matching itself) remove it @@ -1131,7 +1129,7 @@ static int ins_compl_build_pum(void) do { if (!match_at_original_text(compl) && (compl_leader == NULL - || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) { + || ins_compl_equal(compl, (char_u *)compl_leader, (size_t)lead_len))) { compl_match_arraysize++; } compl = compl->cp_next; @@ -1156,7 +1154,7 @@ static int ins_compl_build_pum(void) do { if (!match_at_original_text(compl) && (compl_leader == NULL - || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) { + || ins_compl_equal(compl, (char_u *)compl_leader, (size_t)lead_len))) { if (!shown_match_ok) { if (compl == compl_shown_match || did_find_shown_match) { // This item is the shown match or this is the @@ -1173,16 +1171,16 @@ static int ins_compl_build_pum(void) } if (compl->cp_text[CPT_ABBR] != NULL) { - compl_match_array[i].pum_text = compl->cp_text[CPT_ABBR]; + compl_match_array[i].pum_text = (char_u *)compl->cp_text[CPT_ABBR]; } else { - compl_match_array[i].pum_text = compl->cp_str; + compl_match_array[i].pum_text = (char_u *)compl->cp_str; } - compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND]; - compl_match_array[i].pum_info = compl->cp_text[CPT_INFO]; + compl_match_array[i].pum_kind = (char_u *)compl->cp_text[CPT_KIND]; + compl_match_array[i].pum_info = (char_u *)compl->cp_text[CPT_INFO]; if (compl->cp_text[CPT_MENU] != NULL) { - compl_match_array[i++].pum_extra = compl->cp_text[CPT_MENU]; + compl_match_array[i++].pum_extra = (char_u *)compl->cp_text[CPT_MENU]; } else { - compl_match_array[i++].pum_extra = compl->cp_fname; + compl_match_array[i++].pum_extra = (char_u *)compl->cp_fname; } } @@ -1236,8 +1234,8 @@ void ins_compl_show_pum(void) } else { // popup menu already exists, only need to find the current item. for (int i = 0; i < compl_match_arraysize; i++) { - if (compl_match_array[i].pum_text == compl_shown_match->cp_str - || compl_match_array[i].pum_text == compl_shown_match->cp_text[CPT_ABBR]) { + if (compl_match_array[i].pum_text == (char_u *)compl_shown_match->cp_str + || compl_match_array[i].pum_text == (char_u *)compl_shown_match->cp_text[CPT_ABBR]) { cur = i; break; } @@ -1649,7 +1647,7 @@ int ins_compl_bs(void) line = get_cursor_line_ptr(); xfree(compl_leader); - compl_leader = (char_u *)xstrnsave(line + compl_col, (size_t)(p_off - (ptrdiff_t)compl_col)); + compl_leader = xstrnsave(line + compl_col, (size_t)(p_off - (ptrdiff_t)compl_col)); ins_compl_new_leader(); if (compl_shown_match != NULL) { @@ -1678,7 +1676,7 @@ static void ins_compl_new_leader(void) { ins_compl_del_pum(); ins_compl_delete(); - ins_bytes((char *)compl_leader + get_compl_len()); + ins_bytes(compl_leader + get_compl_len()); compl_used_match = false; if (compl_started) { @@ -1743,8 +1741,8 @@ void ins_compl_addleader(int c) } xfree(compl_leader); - compl_leader = (char_u *)xstrnsave(get_cursor_line_ptr() + compl_col, - (size_t)(curwin->w_cursor.col - compl_col)); + compl_leader = xstrnsave(get_cursor_line_ptr() + compl_col, + (size_t)(curwin->w_cursor.col - compl_col)); ins_compl_new_leader(); } @@ -1764,7 +1762,7 @@ static void ins_compl_restart(void) } /// Set the first match, the original text. -static void ins_compl_set_original_text(char_u *str) +static void ins_compl_set_original_text(char *str) FUNC_ATTR_NONNULL_ALL { // Replace the original text entry. @@ -1772,11 +1770,11 @@ static void ins_compl_set_original_text(char_u *str) // be at the last item for backward completion if (match_at_original_text(compl_first_match)) { // safety check xfree(compl_first_match->cp_str); - compl_first_match->cp_str = vim_strsave(str); + compl_first_match->cp_str = xstrdup(str); } else if (compl_first_match->cp_prev != NULL && match_at_original_text(compl_first_match->cp_prev)) { xfree(compl_first_match->cp_prev->cp_str); - compl_first_match->cp_prev->cp_str = vim_strsave(str); + compl_first_match->cp_prev->cp_str = xstrdup(str); } } @@ -1789,7 +1787,7 @@ void ins_compl_addfrommatch(void) int c; compl_T *cp; assert(compl_shown_match != NULL); - p = compl_shown_match->cp_str; + p = (char_u *)compl_shown_match->cp_str; if ((int)STRLEN(p) <= len) { // the match is too short // When still at the original match use the first entry that matches // the leader. @@ -1801,8 +1799,8 @@ void ins_compl_addfrommatch(void) for (cp = compl_shown_match->cp_next; cp != NULL && !is_first_match(cp); cp = cp->cp_next) { if (compl_leader == NULL - || ins_compl_equal(cp, compl_leader, STRLEN(compl_leader))) { - p = cp->cp_str; + || ins_compl_equal(cp, (char_u *)compl_leader, STRLEN(compl_leader))) { + p = (char_u *)cp->cp_str; break; } } @@ -1955,7 +1953,7 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) // CTRL-E then don't use the current match. char_u *ptr; if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E) { - ptr = compl_curr_match->cp_str; + ptr = (char_u *)compl_curr_match->cp_str; } else { ptr = NULL; } @@ -2006,7 +2004,7 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval) ins_compl_delete(); char_u *p = NULL; if (compl_leader != NULL) { - p = compl_leader; + p = (char_u *)compl_leader; } else if (compl_first_match != NULL) { p = (char_u *)compl_orig_text; } @@ -2168,7 +2166,7 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) if (ptr == NULL) { if (compl_leader != NULL) { - ptr = compl_leader; + ptr = (char_u *)compl_leader; } else { return; // nothing to do } @@ -2919,14 +2917,14 @@ static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_p bool *cont_s_ipos) { *match_len = 0; - char_u *ptr = ml_get_buf(ins_buf, cur_match_pos->lnum, false) + cur_match_pos->col; + char_u *ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum, false) + cur_match_pos->col; int len; if (ctrl_x_mode_line_or_eval()) { if (compl_status_adding()) { if (cur_match_pos->lnum >= ins_buf->b_ml.ml_line_count) { return NULL; } - ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false); + ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false); if (!p_paste) { ptr = (char_u *)skipwhite((char *)ptr); } @@ -2954,7 +2952,7 @@ static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_p // normal command "J" was used. IOSIZE is always greater than // compl_length, so the next STRNCPY always works -- Acevedo STRNCPY(IObuff, ptr, len); // NOLINT(runtime/printf) - ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false); + ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false); tmp_ptr = ptr = (char_u *)skipwhite((char *)ptr); // Find start of next word. tmp_ptr = find_word_start(tmp_ptr); @@ -3275,7 +3273,7 @@ static int ins_compl_get_exp(pos_T *ini) static void ins_compl_update_shown_match(void) { while (!ins_compl_equal(compl_shown_match, - compl_leader, STRLEN(compl_leader)) + (char_u *)compl_leader, STRLEN(compl_leader)) && compl_shown_match->cp_next != NULL && !is_first_match(compl_shown_match->cp_next)) { compl_shown_match = compl_shown_match->cp_next; @@ -3284,10 +3282,10 @@ static void ins_compl_update_shown_match(void) // If we didn't find it searching forward, and compl_shows_dir is // backward, find the last match. if (compl_shows_dir_backward() - && !ins_compl_equal(compl_shown_match, compl_leader, STRLEN(compl_leader)) + && !ins_compl_equal(compl_shown_match, (char_u *)compl_leader, STRLEN(compl_leader)) && (compl_shown_match->cp_next == NULL || is_first_match(compl_shown_match->cp_next))) { - while (!ins_compl_equal(compl_shown_match, compl_leader, STRLEN(compl_leader)) + while (!ins_compl_equal(compl_shown_match, (char_u *)compl_leader, STRLEN(compl_leader)) && compl_shown_match->cp_prev != NULL && !is_first_match(compl_shown_match->cp_prev)) { compl_shown_match = compl_shown_match->cp_prev; @@ -3321,7 +3319,7 @@ void ins_compl_delete(void) /// "in_compl_func" is true when called from complete_check(). void ins_compl_insert(bool in_compl_func) { - ins_bytes((char *)compl_shown_match->cp_str + get_compl_len()); + ins_bytes(compl_shown_match->cp_str + get_compl_len()); compl_used_match = !match_at_original_text(compl_shown_match); dict_T *dict = ins_compl_dict_alloc(compl_shown_match); @@ -3346,7 +3344,7 @@ static void ins_compl_show_filename(void) // the text that fits in "space" between "s" and "e". char *s; char *e; - for (s = e = (char *)compl_shown_match->cp_fname; *e != NUL; MB_PTR_ADV(e)) { + for (s = e = compl_shown_match->cp_fname; *e != NUL; MB_PTR_ADV(e)) { space -= ptr2cells(e); while (space < 0) { space += ptr2cells(s); @@ -3355,7 +3353,7 @@ static void ins_compl_show_filename(void) } msg_hist_off = true; vim_snprintf((char *)IObuff, IOSIZE, "%s %s%s", lead, - (char_u *)s > compl_shown_match->cp_fname ? "<" : "", s); + s > compl_shown_match->cp_fname ? "<" : "", s); msg((char *)IObuff); msg_hist_off = false; redraw_cmdline = false; // don't overwrite! @@ -3432,7 +3430,7 @@ static int find_next_completion_match(bool allow_get_expansion, int todo, bool a if (!match_at_original_text(compl_shown_match) && compl_leader != NULL && !ins_compl_equal(compl_shown_match, - compl_leader, STRLEN(compl_leader))) { + (char_u *)compl_leader, STRLEN(compl_leader))) { todo++; } else { // Remember a matching item. @@ -3519,7 +3517,7 @@ static int ins_compl_next(bool allow_get_expansion, int count, bool insert_match if (!compl_get_longest || compl_used_match) { ins_compl_insert(in_compl_func); } else { - ins_bytes((char *)compl_leader + get_compl_len()); + ins_bytes(compl_leader + get_compl_len()); } } else { compl_used_match = false; diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c index 49d49f76b9..21dd5139d7 100644 --- a/src/nvim/lua/converter.c +++ b/src/nvim/lua/converter.c @@ -388,12 +388,12 @@ nlua_pop_typval_table_processing_end: LuaCFunctionState *state = xmalloc(sizeof(LuaCFunctionState)); state->lua_callable.func_ref = nlua_ref_global(lstate, -1); - char_u *name = register_cfunc(&nlua_CFunction_func_call, - &nlua_CFunction_func_free, - state); + char *name = (char *)register_cfunc(&nlua_CFunction_func_call, + &nlua_CFunction_func_free, + state); cur.tv->v_type = VAR_FUNC; - cur.tv->vval.v_string = (char *)vim_strsave(name); + cur.tv->vval.v_string = xstrdup(name); break; } case LUA_TUSERDATA: { diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 1b874e673a..e3d6a7eec8 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -111,7 +111,7 @@ static int regex_match_line(lua_State *lstate) return luaL_error(lstate, "invalid row"); } - char_u *line = ml_get_buf(buf, rownr + 1, false); + char_u *line = (char_u *)ml_get_buf(buf, rownr + 1, false); size_t len = STRLEN(line); if (start < 0 || (size_t)start > len) { diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 65e024b707..971a47f8c9 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -332,7 +332,7 @@ static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position *bytes_read = 0; return ""; } - char *line = (char *)ml_get_buf(bp, (linenr_T)position.row + 1, false); + char *line = ml_get_buf(bp, (linenr_T)position.row + 1, false); size_t len = STRLEN(line); if (position.column > len) { *bytes_read = 0; diff --git a/src/nvim/macros.h b/src/nvim/macros.h index b84539852f..1024ca5015 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -54,7 +54,7 @@ #define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || ascii_isdigit(c)) // Returns empty string if it is NULL. -#define EMPTY_IF_NULL(x) (char *)((x) ? (x) : (char_u *)"") +#define EMPTY_IF_NULL(x) ((x) ? (x) : "") /// Adjust chars in a language according to 'langmap' option. /// NOTE that there is no noticeable overhead if 'langmap' is not set. diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 923eea145c..94b432a553 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -303,7 +303,7 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len // NB: replace_termcodes may produce an empty string even if orig_rhs is non-empty // (e.g. a single ^V, see :h map-empty-rhs) mapargs->rhs_is_noop = orig_rhs_len != 0 && mapargs->rhs_len == 0; - mapargs->rhs = (char_u *)replaced; + mapargs->rhs = replaced; } } else { char tmp_buf[64]; @@ -313,7 +313,7 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len // stores ref_no in map_str mapargs->rhs_len = (size_t)vim_snprintf(S_LEN(tmp_buf), "%c%c%c%d\r", K_SPECIAL, (char_u)KS_EXTRA, KE_LUA, rhs_lua); - mapargs->rhs = vim_strsave((char_u *)tmp_buf); + mapargs->rhs = xstrdup(tmp_buf); } } @@ -439,7 +439,7 @@ static int str_to_mapargs(const char_u *strargs, bool is_unmap, MapArguments *ma /// and "desc" fields are used. /// "rhs", "rhs_lua", "orig_rhs" fields are cleared if "simplified" is false. /// @param sid -1 to use current_sctx -static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, const char_u *keys, +static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, const char *keys, MapArguments *args, int noremap, int mode, bool is_abbr, scid_T sid, linenr_T lnum, bool simplified) { @@ -454,8 +454,8 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, } } - mp->m_keys = vim_strsave(keys); - mp->m_str = (char *)args->rhs; + mp->m_keys = (uint8_t *)xstrdup(keys); + mp->m_str = args->rhs; mp->m_orig_str = (char *)args->orig_rhs; mp->m_luaref = args->rhs_lua; if (!simplified) { @@ -767,7 +767,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, XFREE_CLEAR(mp->m_str); XFREE_CLEAR(mp->m_orig_str); } - mp->m_str = (char *)args->rhs; + mp->m_str = args->rhs; mp->m_orig_str = (char *)args->orig_rhs; mp->m_luaref = args->rhs_lua; if (!keyround1_simplified) { @@ -846,7 +846,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, } // Get here when adding a new entry to the maphash[] list or abbrlist. - map_add(buf, map_table, abbr_table, lhs, args, noremap, mode, is_abbrev, + map_add(buf, map_table, abbr_table, (char *)lhs, args, noremap, mode, is_abbrev, -1, // sid 0, // lnum keyround1_simplified); @@ -1265,7 +1265,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char ***file) int hash; int count; int round; - char_u *p; + char *p; int i; *num_file = 0; // return values in case of FAIL @@ -1278,28 +1278,28 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char ***file) for (i = 0; i < 7; i++) { if (i == 0) { - p = (char_u *)""; + p = ""; } else if (i == 1) { - p = (char_u *)""; + p = ""; } else if (i == 2) { - p = (char_u *)"