From 30fefee684e641a0c6867446c6de30efa2f0a126 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 20 Sep 2021 15:53:38 +0200 Subject: refactor: format with uncrustify #15726 --- src/nvim/debugger.c | 64 +- src/nvim/decoration.c | 32 +- src/nvim/diff.c | 116 ++- src/nvim/digraph.c | 28 +- src/nvim/eval.c | 2086 +++++++++++++++++++++++++------------------------ src/nvim/ex_cmds2.c | 210 +++-- src/nvim/ex_eval.c | 413 +++++----- src/nvim/ex_getln.c | 1208 ++++++++++++++-------------- src/nvim/ex_session.c | 64 +- src/nvim/extmark.c | 91 +-- 10 files changed, 2203 insertions(+), 2109 deletions(-) (limited to 'src') diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index 73665009ff..a5dd4cd485 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -60,9 +60,9 @@ void do_debug(char_u *cmd) int save_ignore_script = 0; int save_ex_normal_busy; int n; - char_u *cmdline = NULL; - char_u *p; - char *tail = NULL; + char_u *cmdline = NULL; + char_u *p; + char *tail = NULL; static int last_cmd = 0; #define CMD_CONT 1 #define CMD_NEXT 2 @@ -145,13 +145,16 @@ void do_debug(char_u *cmd) p = skipwhite(cmdline); if (*p != NUL) { switch (*p) { - case 'c': last_cmd = CMD_CONT; + case 'c': + last_cmd = CMD_CONT; tail = "ont"; break; - case 'n': last_cmd = CMD_NEXT; + case 'n': + last_cmd = CMD_NEXT; tail = "ext"; break; - case 's': last_cmd = CMD_STEP; + case 's': + last_cmd = CMD_STEP; tail = "tep"; break; case 'f': @@ -164,10 +167,12 @@ void do_debug(char_u *cmd) tail = "inish"; } break; - case 'q': last_cmd = CMD_QUIT; + case 'q': + last_cmd = CMD_QUIT; tail = "uit"; break; - case 'i': last_cmd = CMD_INTERRUPT; + case 'i': + last_cmd = CMD_INTERRUPT; tail = "nterrupt"; break; case 'b': @@ -190,7 +195,8 @@ void do_debug(char_u *cmd) last_cmd = CMD_DOWN; tail = "own"; break; - default: last_cmd = 0; + default: + last_cmd = 0; } if (last_cmd != 0) { // Check that the tail matches. @@ -366,7 +372,7 @@ void ex_debug(exarg_T *eap) debug_break_level = debug_break_level_save; } -static char_u *debug_breakpoint_name = NULL; +static char_u *debug_breakpoint_name = NULL; static linenr_T debug_breakpoint_lnum; /// When debugging or a breakpoint is set on a skipped command, no debug prompt @@ -375,7 +381,7 @@ static linenr_T debug_breakpoint_lnum; /// a skipped command decides itself that a debug prompt should be displayed, it /// can do so by calling dbg_check_skipped(). static int debug_skipped; -static char_u *debug_skipped_name; +static char_u *debug_skipped_name; /// Go to debug mode when a breakpoint was encountered or "ex_nesting_level" is /// at or below the break level. But only when the line is actually @@ -384,7 +390,7 @@ static char_u *debug_skipped_name; /// Called from do_one_cmd() before executing a command. void dbg_check_breakpoint(exarg_T *eap) { - char_u *p; + char_u *p; debug_skipped = false; if (debug_breakpoint_name != NULL) { @@ -474,8 +480,8 @@ static typval_T *eval_expr_no_emsg(struct debuggy *const bp) /// @param gap either &dbg_breakp or &prof_ga static int dbg_parsearg(char_u *arg, garray_T *gap) { - char_u *p = arg; - char_u *q; + char_u *p = arg; + char_u *q; struct debuggy *bp; bool here = false; @@ -559,7 +565,7 @@ static int dbg_parsearg(char_u *arg, garray_T *gap) void ex_breakadd(exarg_T *eap) { struct debuggy *bp; - garray_T *gap; + garray_T *gap; gap = &dbg_breakp; if (eap->cmdidx == CMD_profile) { @@ -614,7 +620,7 @@ void ex_breakdel(exarg_T *eap) int todel = -1; bool del_all = false; linenr_T best_lnum = 0; - garray_T *gap; + garray_T *gap; gap = &dbg_breakp; if (eap->cmdidx == CMD_profdel) { @@ -712,12 +718,10 @@ void ex_breaklist(exarg_T *eap) /// Find a breakpoint for a function or sourced file. /// Returns line number at which to break; zero when no matching breakpoint. -linenr_T -dbg_find_breakpoint( - bool file, // true for a file, false for a function - char_u *fname, // file or function name - linenr_T after // after this line number -) +linenr_T dbg_find_breakpoint(bool file, // true for a file, false for a function + char_u *fname, // file or function name + linenr_T after // after this line number + ) { return debuggy_find(file, fname, after, &dbg_breakp, NULL); } @@ -734,18 +738,16 @@ bool has_profiling(bool file, char_u *fname, bool *fp) } /// Common code for dbg_find_breakpoint() and has_profiling(). -static linenr_T -debuggy_find( - bool file, // true for a file, false for a function - char_u *fname, // file or function name - linenr_T after, // after this line number - garray_T *gap, // either &dbg_breakp or &prof_ga - bool *fp // if not NULL: return forceit -) +static linenr_T debuggy_find(bool file, // true for a file, false for a function + char_u *fname, // file or function name + linenr_T after, // after this line number + garray_T *gap, // either &dbg_breakp or &prof_ga + bool *fp // if not NULL: return forceit + ) { struct debuggy *bp; linenr_T lnum = 0; - char_u *name = fname; + char_u *name = fname; int prev_got_int; // Return quickly when there are no breakpoints. diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c index 5168ed6d0f..0f21b47261 100644 --- a/src/nvim/decoration.c +++ b/src/nvim/decoration.c @@ -1,13 +1,13 @@ // 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 -#include "nvim/vim.h" -#include "nvim/lua/executor.h" -#include "nvim/extmark.h" #include "nvim/decoration.h" +#include "nvim/extmark.h" +#include "nvim/highlight.h" +#include "nvim/lua/executor.h" #include "nvim/screen.h" #include "nvim/syntax.h" -#include "nvim/highlight.h" +#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "decoration.c.generated.h" @@ -28,11 +28,7 @@ static PMap(uint64_t) hl_decors; /// @param pos_start Cursor position to start the highlighting at /// @param pos_end Cursor position to end the highlighting at /// @param offset Move the whole highlighting this many columns to the right -void bufhl_add_hl_pos_offset(buf_T *buf, - int src_id, - int hl_id, - lpos_T pos_start, - lpos_T pos_end, +void bufhl_add_hl_pos_offset(buf_T *buf, int src_id, int hl_id, lpos_T pos_start, lpos_T pos_end, colnr_T offset) { colnr_T hl_start = 0; @@ -172,7 +168,7 @@ bool decor_redraw_start(buf_T *buf, int top_row, DecorState *state) ExtmarkItem *item = map_ref(uint64_t, ExtmarkItem)(buf->b_extmark_index, start_id, false); if (!item || !item->decor) { - // TODO(bfredl): dedicated flag for being a decoration? + // TODO(bfredl): dedicated flag for being a decoration? goto next_mark; } Decoration *decor = item->decor; @@ -217,14 +213,14 @@ bool decor_redraw_line(buf_T *buf, int row, DecorState *state) return true; // TODO(bfredl): be more precise } -static void decor_add(DecorState *state, int start_row, int start_col, - int end_row, int end_col, Decoration *decor, bool owned) +static void decor_add(DecorState *state, int start_row, int start_col, int end_row, int end_col, + Decoration *decor, bool owned) { int attr_id = decor->hl_id > 0 ? syn_id2attr(decor->hl_id) : 0; DecorRange range = { start_row, start_col, end_row, end_col, *decor, attr_id, - kv_size(decor->virt_text) && owned, -1 }; + kv_size(decor->virt_text) && owned, -1 }; kv_pushp(state->active); size_t index; @@ -238,8 +234,7 @@ static void decor_add(DecorState *state, int start_row, int start_col, kv_A(state->active, index) = range; } -int decor_redraw_col(buf_T *buf, int col, int win_col, bool hidden, - DecorState *state) +int decor_redraw_col(buf_T *buf, int col, int win_col, bool hidden, DecorState *state) { if (col <= state->col_until) { return state->current; @@ -257,7 +252,7 @@ int decor_redraw_col(buf_T *buf, int col, int win_col, bool hidden, } if ((mark.id&MARKTREE_END_FLAG)) { - // TODO(bfredl): check decoration flag + // TODO(bfredl): check decoration flag goto next_mark; } mtpos_t endpos = marktree_lookup(buf->b_marktree, @@ -266,7 +261,7 @@ int decor_redraw_col(buf_T *buf, int col, int win_col, bool hidden, ExtmarkItem *item = map_ref(uint64_t, ExtmarkItem)(buf->b_extmark_index, mark.id, false); if (!item || !item->decor) { - // TODO(bfredl): dedicated flag for being a decoration? + // TODO(bfredl): dedicated flag for being a decoration? goto next_mark; } Decoration *decor = item->decor; @@ -355,8 +350,7 @@ bool decor_redraw_eol(buf_T *buf, DecorState *state, int *eol_attr, int eol_col) return has_virttext; } -void decor_add_ephemeral(int start_row, int start_col, int end_row, int end_col, - Decoration *decor) +void decor_add_ephemeral(int start_row, int start_col, int end_row, int end_col, Decoration *decor) { if (end_row == -1) { end_row = start_row; diff --git a/src/nvim/diff.c b/src/nvim/diff.c index fd5b2c6599..62af6a6393 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -13,14 +13,12 @@ #include #include -#include "nvim/vim.h" -#include "xdiff/xdiff.h" #include "nvim/ascii.h" -#include "nvim/diff.h" #include "nvim/buffer.h" #include "nvim/change.h" #include "nvim/charset.h" #include "nvim/cursor.h" +#include "nvim/diff.h" #include "nvim/eval.h" #include "nvim/ex_cmds.h" #include "nvim/ex_docmd.h" @@ -29,19 +27,21 @@ #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memline.h" +#include "nvim/memory.h" #include "nvim/message.h" #include "nvim/misc1.h" -#include "nvim/memory.h" #include "nvim/move.h" #include "nvim/normal.h" #include "nvim/option.h" +#include "nvim/os/os.h" +#include "nvim/os/shell.h" #include "nvim/path.h" #include "nvim/screen.h" #include "nvim/strings.h" #include "nvim/undo.h" +#include "nvim/vim.h" #include "nvim/window.h" -#include "nvim/os/os.h" -#include "nvim/os/shell.h" +#include "xdiff/xdiff.h" static int diff_busy = false; // using diff structs, don't change them static bool diff_need_update = false; // ex_diffupdate needs to be called @@ -72,22 +72,22 @@ static TriState diff_a_works = kNone; // used for diff input typedef struct { - char_u *din_fname; // used for external diff - mmfile_t din_mmfile; // used for internal diff + char_u *din_fname; // used for external diff + mmfile_t din_mmfile; // used for internal diff } diffin_T; // used for diff result typedef struct { - char_u *dout_fname; // used for external diff - garray_T dout_ga; // used for internal diff + char_u *dout_fname; // used for external diff + garray_T dout_ga; // used for internal diff } diffout_T; // two diff inputs and one result typedef struct { - diffin_T dio_orig; // original file input - diffin_T dio_new; // new file input - diffout_T dio_diff; // diff result - int dio_internal; // using internal diff + diffin_T dio_orig; // original file input + diffin_T dio_new; // new file input + diffout_T dio_diff; // diff result + int dio_internal; // using internal diff } diffio_T; #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -119,7 +119,6 @@ void diff_buf_delete(buf_T *buf) /// @param win void diff_buf_adjust(win_T *win) { - if (!win->w_p_diff) { // When there is no window showing a diff for this buffer, remove // it from the diffs. @@ -242,8 +241,7 @@ void diff_invalidate(buf_T *buf) /// @param line2 /// @param amount /// @param amount_after -void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount, - long amount_after) +void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after) { // Handle all tab pages that use the current buffer in a diff. FOR_ALL_TABS(tp) { @@ -267,8 +265,8 @@ void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount, /// @param line2 /// @param amount /// @amount_after -static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, - linenr_T line2, long amount, long amount_after) +static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T line2, long amount, + long amount_after) { if (diff_internal()) { // Will update diffs before redrawing. Set _invalid to update the @@ -299,7 +297,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, diff_T *dp = tp->tp_first_diff; linenr_T last; - linenr_T lnum_deleted = line1; // lnum of remaining deletion + linenr_T lnum_deleted = line1; // lnum of remaining deletion int n; int off; for (;;) { @@ -323,8 +321,8 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, dnext->df_lnum[i] = line1; } else { dnext->df_lnum[i] = line1 - + (dprev->df_lnum[i] + dprev->df_count[i]) - - (dprev->df_lnum[idx] + dprev->df_count[idx]); + + (dprev->df_lnum[i] + dprev->df_count[i]) + - (dprev->df_lnum[idx] + dprev->df_count[idx]); } dnext->df_count[i] = deleted; } @@ -509,7 +507,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, /// @param dp /// /// @return The new diff block. -static diff_T* diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp) +static diff_T * diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp) { diff_T *dnew = xmalloc(sizeof(*dnew)); @@ -705,9 +703,9 @@ static void clear_diffout(diffout_T *dout) static int diff_write_buffer(buf_T *buf, diffin_T *din) { linenr_T lnum; - char_u *s; + char_u *s; long len = 0; - char_u *ptr; + char_u *ptr; // xdiff requires one big block of memory with all the text. for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { @@ -789,9 +787,7 @@ static int diff_write(buf_T *buf, diffin_T *din) /// @param dio /// @param idx_orig /// @param eap can be NULL -static void diff_try_update(diffio_T *dio, - int idx_orig, - exarg_T *eap) +static void diff_try_update(diffio_T *dio, int idx_orig, exarg_T *eap) { buf_T *buf; int idx_new; @@ -1090,9 +1086,9 @@ static int diff_file_internal(diffio_T *diffio) /// @return OK or FAIL static int diff_file(diffio_T *dio) { - char *tmp_orig = (char *)dio->dio_orig.din_fname; - char *tmp_new = (char *)dio->dio_new.din_fname; - char *tmp_diff = (char *)dio->dio_diff.dout_fname; + char *tmp_orig = (char *)dio->dio_orig.din_fname; + char *tmp_new = (char *)dio->dio_new.din_fname; + char *tmp_diff = (char *)dio->dio_diff.dout_fname; if (*p_dex != NUL) { // Use 'diffexpr' to generate the diff file. eval_diff(tmp_orig, tmp_new, tmp_diff); @@ -1123,9 +1119,9 @@ 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, (char *)p_srr, tmp_diff); block_autocmds(); // Avoid ShellCmdPost stuff - (void)call_shell((char_u *) cmd, + (void)call_shell((char_u *)cmd, kShellOptFilter | kShellOptSilent | kShellOptDoOut, NULL); unblock_autocmds(); @@ -1171,8 +1167,8 @@ void ex_diffpatch(exarg_T *eap) #ifdef UNIX // Get the absolute path of the patchfile, changing directory below. fullname = FullName_save((char *)eap->arg, false); - esc_name = vim_strsave_shellescape( - (fullname != NULL ? (char_u *)fullname : eap->arg), true, true); + esc_name = + vim_strsave_shellescape((fullname != NULL ? (char_u *)fullname : eap->arg), true, true); #else esc_name = vim_strsave_shellescape(eap->arg, true, true); #endif @@ -1324,8 +1320,8 @@ void ex_diffsplit(exarg_T *eap) if (bufref_valid(&old_curbuf)) { // Move the cursor position to that of the old window. - curwin->w_cursor.lnum = diff_get_corresponding_line( - old_curbuf.br_buf, old_curwin->w_cursor.lnum); + curwin->w_cursor.lnum = diff_get_corresponding_line(old_curbuf.br_buf, + old_curwin->w_cursor.lnum); } } // Now that lines are folded scroll to show the cursor at the same @@ -1344,15 +1340,15 @@ void ex_diffthis(exarg_T *eap) static void set_diff_option(win_T *wp, int value) { - win_T *old_curwin = curwin; - - curwin = wp; - curbuf = curwin->w_buffer; - curbuf->b_ro_locked++; - set_option_value("diff", (long)value, NULL, OPT_LOCAL); - curbuf->b_ro_locked--; - curwin = old_curwin; - curbuf = curwin->w_buffer; + win_T *old_curwin = curwin; + + curwin = wp; + curbuf = curwin->w_buffer; + curbuf->b_ro_locked++; + set_option_value("diff", (long)value, NULL, OPT_LOCAL); + curbuf->b_ro_locked--; + curwin = old_curwin; + curbuf = curwin->w_buffer; } @@ -1724,8 +1720,7 @@ static void diff_read(int idx_orig, int idx_new, diffout_T *dout) /// @param dp /// @param idx_orig /// @param idx_new -static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, - int idx_new) +static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, int idx_new) { long off; @@ -1769,7 +1764,7 @@ void diff_clear(tabpage_T *tp) /// @return diff status. int diff_check(win_T *wp, linenr_T lnum) { - int idx; // index in tp_diffbuf[] for this buffer + int idx; // index in tp_diffbuf[] for this buffer diff_T *dp; int maxcount; int i; @@ -1912,8 +1907,7 @@ static bool diff_equal_entry(diff_T *dp, int idx1, int idx2) // Compare the characters at "p1" and "p2". If they are equal (possibly // ignoring case) return true and set "len" to the number of bytes. -static bool diff_equal_char(const char_u *const p1, const char_u *const p2, - int *const len) +static bool diff_equal_char(const char_u *const p1, const char_u *const p2, int *const len) { const int l = utfc_ptr2len(p1); @@ -2537,7 +2531,7 @@ void ex_diffgetput(exarg_T *eap) if ((curtab->tp_diffbuf[i] != curbuf) && (curtab->tp_diffbuf[i] != NULL) && ((eap->cmdidx != CMD_diffput) - || MODIFIABLE(curtab->tp_diffbuf[i]))) { + || MODIFIABLE(curtab->tp_diffbuf[i]))) { EMSG(_("E101: More than two buffers in diff mode, don't know " "which one to use")); return; @@ -2958,7 +2952,7 @@ static linenr_T diff_get_corresponding_line_int(buf_T *buf1, linenr_T lnum1) return curwin->w_cursor.lnum; } baseline = (dp->df_lnum[idx1] + dp->df_count[idx1]) - - (dp->df_lnum[idx2] + dp->df_count[idx2]); + - (dp->df_lnum[idx2] + dp->df_count[idx2]); } // If we get here then the cursor is after the last diff @@ -3035,11 +3029,8 @@ linenr_T diff_lnum_win(linenr_T lnum, win_T *wp) /// Handle an ED style diff line. /// Return FAIL if the line does not contain diff info. /// -static int parse_diff_ed(char_u *line, - linenr_T *lnum_orig, - long *count_orig, - linenr_T *lnum_new, - long *count_new) +static int parse_diff_ed(char_u *line, linenr_T *lnum_orig, long *count_orig, linenr_T *lnum_new, + long *count_new) { char_u *p; long f1, l1, f2, l2; @@ -3093,11 +3084,8 @@ static int parse_diff_ed(char_u *line, /// Parses unified diff with zero(!) context lines. /// Return FAIL if there is no diff information in "line". /// -static int parse_diff_unified(char_u *line, - linenr_T *lnum_orig, - long *count_orig, - linenr_T *lnum_new, - long *count_new) +static int parse_diff_unified(char_u *line, linenr_T *lnum_orig, long *count_orig, + linenr_T *lnum_new, long *count_new) { char_u *p; long oldline, oldcount, newline, newcount; @@ -3153,7 +3141,7 @@ static int parse_diff_unified(char_u *line, static int xdiff_out(void *priv, mmbuffer_t *mb, int nbuf) { diffout_T *dout = (diffout_T *)priv; - char_u *p; + char_u *p; // The header line always comes by itself, text lines in at least two // parts. We drop the text part. diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 07e484c178..abca7cb905 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -6,26 +6,26 @@ /// code for digraphs #include -#include #include +#include -#include "nvim/vim.h" #include "nvim/ascii.h" -#include "nvim/digraph.h" #include "nvim/charset.h" +#include "nvim/digraph.h" #include "nvim/ex_cmds2.h" #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" +#include "nvim/garray.h" #include "nvim/getchar.h" -#include "nvim/misc1.h" #include "nvim/mbyte.h" -#include "nvim/message.h" #include "nvim/memory.h" -#include "nvim/garray.h" +#include "nvim/message.h" +#include "nvim/misc1.h" #include "nvim/normal.h" +#include "nvim/os/input.h" #include "nvim/screen.h" #include "nvim/strings.h" -#include "nvim/os/input.h" +#include "nvim/vim.h" typedef int result_T; @@ -40,7 +40,7 @@ typedef struct digraph { # include "digraph.c.generated.h" #endif // digraphs added by the user -static garray_T user_digraphs = {0, 0, (int)sizeof(digr_T), 10, NULL}; +static garray_T user_digraphs = { 0, 0, (int)sizeof(digr_T), 10, NULL }; /// Note: Characters marked with XX are not included literally, because some /// compilers cannot handle them (Amiga SAS/C is the most picky one). @@ -49,7 +49,7 @@ static digr_T digraphdefault[] = // digraphs for Unicode from RFC1345 // (also work for ISO-8859-1 aka latin1) { - { 'N', 'U', 0x0a }, // LF for NUL + { 'N', 'U', 0x0a }, // LF for NUL { 'S', 'H', 0x01 }, { 'S', 'X', 0x02 }, { 'E', 'X', 0x03 }, @@ -1452,12 +1452,12 @@ static digr_T digraphdefault[] = /// @return The digraph. int do_digraph(int c) { - static int backspaced; // character before K_BS + static int backspaced; // character before K_BS static int lastchar; // last typed character if (c == -1) { // init values backspaced = -1; - } else if (p_dg) { + } else if (p_dg) { if (backspaced >= 0) { c = getdigraph(backspaced, c, false); } @@ -1557,7 +1557,7 @@ static int getexactdigraph(int char1, int char2, bool meta_char) // Search user digraphs first. digr_T *dp = (digr_T *)user_digraphs.ga_data; for (int i = 0; i < user_digraphs.ga_len; ++i) { - if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) { + if (((int)dp->char1 == char1) && ((int)dp->char2 == char2)) { retval = dp->result; break; } @@ -1569,7 +1569,7 @@ static int getexactdigraph(int char1, int char2, bool meta_char) dp = digraphdefault; for (int i = 0; dp->char1 != 0; ++i) { - if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) { + if (((int)dp->char1 == char1) && ((int)dp->char2 == char2)) { retval = dp->result; break; } @@ -1821,7 +1821,7 @@ typedef struct { /// @return NULL if OK, an error message for failure. This only needs to be /// used when setting the option, not later when the value has already /// been checked. -char_u* keymap_init(void) +char_u * keymap_init(void) { curbuf->b_kmap_state &= ~KEYMAP_INIT; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 2736e9a14f..1a9af639a3 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -20,12 +20,12 @@ #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/edit.h" -#include "nvim/eval/userfunc.h" #include "nvim/eval.h" #include "nvim/eval/encode.h" #include "nvim/eval/executor.h" #include "nvim/eval/gc.h" #include "nvim/eval/typval.h" +#include "nvim/eval/userfunc.h" #include "nvim/ex_cmds2.h" #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" @@ -66,7 +66,7 @@ static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary"); static char *e_illvar = N_("E461: Illegal variable name: %s"); static char *e_cannot_mod = N_("E995: Cannot modify existing variable"); static char *e_nowhitespace - = N_("E274: No white space allowed before parenthesis"); + = N_("E274: No white space allowed before parenthesis"); static char *e_invalwindow = N_("E957: Invalid window number"); static char *e_lock_unlock = N_("E940: Cannot lock or unlock variable %s"); static char *e_write2 = N_("E80: Error while writing: %s"); @@ -97,7 +97,7 @@ typedef struct { dict_T sv_dict; } scriptvar_T; -static garray_T ga_scripts = {0, 0, sizeof(scriptvar_T *), 4, NULL}; +static garray_T ga_scripts = { 0, 0, sizeof(scriptvar_T *), 4, NULL }; #define SCRIPT_SV(id) (((scriptvar_T **)ga_scripts.ga_data)[(id) - 1]) #define SCRIPT_VARS(id) (SCRIPT_SV(id)->sv_dict.dv_hashtab) @@ -113,7 +113,7 @@ typedef struct { int fi_semicolon; // TRUE if ending in '; var]' int fi_varcount; // nr of variables in the list listwatch_T fi_lw; // keep an eye on the item used. - list_T *fi_list; // list being used + list_T *fi_list; // list being used int fi_bi; // index of blob blob_T *fi_blob; // blob being used } forinfo_T; @@ -139,7 +139,7 @@ typedef struct { // The reason to use this table anyway is for very quick access to the // variables with the VV_ defines. static struct vimvar { - char *vv_name; ///< Name of the variable, without v:. + char *vv_name; ///< Name of the variable, without v:. TV_DICTITEM_STRUCT(17) vv_di; ///< Value and name for key (max 16 chars). char vv_flags; ///< Flags: #VV_COMPAT, #VV_RO, #VV_RO_SBX. } vimvars[] = @@ -334,7 +334,7 @@ void eval_init(void) { vimvars[VV_VERSION].vv_nr = VIM_VERSION_100; - struct vimvar *p; + struct vimvar *p; init_var_dict(&globvardict, &globvars_var, VAR_DEF_SCOPE); init_var_dict(&vimvardict, &vimvars_var, VAR_SCOPE); @@ -346,12 +346,13 @@ void eval_init(void) p = &vimvars[i]; assert(STRLEN(p->vv_name) <= 16); STRCPY(p->vv_di.di_key, p->vv_name); - if (p->vv_flags & VV_RO) + if (p->vv_flags & VV_RO) { p->vv_di.di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; - else if (p->vv_flags & VV_RO_SBX) + } else if (p->vv_flags & VV_RO_SBX) { p->vv_di.di_flags = DI_FLAGS_RO_SBX | DI_FLAGS_FIX; - else + } else { p->vv_di.di_flags = DI_FLAGS_FIX; + } // add to v: scope dict, unless the value is not always available if (p->vv_type != VAR_UNKNOWN) { @@ -424,7 +425,7 @@ void eval_init(void) #if defined(EXITFREE) void eval_clear(void) { - struct vimvar *p; + struct vimvar *p; for (size_t i = 0; i < ARRAY_SIZE(vimvars); i++) { p = &vimvars[i]; @@ -451,10 +452,12 @@ void eval_clear(void) /* Script-local variables. First clear all the variables and in a second * loop free the scriptvar_T, because a variable in one script might hold * a reference to the whole scope of another script. */ - for (int i = 1; i <= ga_scripts.ga_len; ++i) + for (int i = 1; i <= ga_scripts.ga_len; ++i) { vars_clear(&SCRIPT_VARS(i)); - for (int i = 1; i <= ga_scripts.ga_len; ++i) + } + for (int i = 1; i <= ga_scripts.ga_len; ++i) { xfree(SCRIPT_SV(i)); + } ga_clear(&ga_scripts); // unreferenced lists and dicts @@ -481,20 +484,16 @@ void set_internal_string_var(const char *name, char_u *value) set_var(name, strlen(name), &tv, true); } -static lval_T *redir_lval = NULL; +static lval_T *redir_lval = NULL; static garray_T redir_ga; // Only valid when redir_lval is not NULL. static char_u *redir_endp = NULL; -static char_u *redir_varname = NULL; +static char_u *redir_varname = NULL; -/* - * Start recording command output to a variable - * Returns OK if successfully completed the setup. FAIL otherwise. - */ -int -var_redir_start( - char_u *name, - int append // append to an existing variable -) +/// Start recording command output to a variable +/// Returns OK if successfully completed the setup. FAIL otherwise. +/// +/// @param append append to an existing variable +int var_redir_start(char_u *name, int append) { int save_emsg; int err; @@ -567,8 +566,9 @@ void var_redir_str(char_u *value, int value_len) { int len; - if (redir_lval == NULL) + if (redir_lval == NULL) { return; + } if (value_len == -1) { len = (int)STRLEN(value); // Append the entire string @@ -655,8 +655,7 @@ int eval_printexpr(const char *const fname, const char *const args) return OK; } -void eval_diff(const char *const origfile, const char *const newfile, - const char *const outfile) +void eval_diff(const char *const origfile, const char *const newfile, const char *const outfile) { bool err = false; @@ -669,8 +668,7 @@ void eval_diff(const char *const origfile, const char *const newfile, set_vim_var_string(VV_FNAME_OUT, NULL, -1); } -void eval_patch(const char *const origfile, const char *const difffile, - const char *const outfile) +void eval_patch(const char *const origfile, const char *const difffile, const char *const outfile) { bool err = false; @@ -683,18 +681,13 @@ void eval_patch(const char *const origfile, const char *const difffile, set_vim_var_string(VV_FNAME_OUT, NULL, -1); } -/* - * Top level evaluation function, returning a boolean. - * Sets "error" to TRUE if there was an error. - * Return TRUE or FALSE. - */ -int -eval_to_bool( - char_u *arg, - bool *error, - char_u **nextcmd, - int skip // only parse, don't execute -) +/// Top level evaluation function, returning a boolean. +/// Sets "error" to TRUE if there was an error. +/// +/// @param skip only parse, don't execute +/// +/// @return TRUE or FALSE. +int eval_to_bool(char_u *arg, bool *error, char_u **nextcmd, int skip) { typval_T tv; bool retval = false; @@ -741,8 +734,7 @@ static int eval1_emsg(char_u **arg, typval_T *rettv, bool evaluate) return ret; } -int eval_expr_typval(const typval_T *expr, typval_T *argv, - int argc, typval_T *rettv) +int eval_expr_typval(const typval_T *expr, typval_T *argv, int argc, typval_T *rettv) FUNC_ATTR_NONNULL_ARG(1, 2, 4) { funcexe_T funcexe = FUNCEXE_INIT; @@ -811,8 +803,7 @@ bool eval_expr_to_bool(const typval_T *expr, bool *error) /// /// @return [allocated] string result of evaluation or NULL in case of error or /// when skipping. -char *eval_to_string_skip(const char *arg, const char **nextcmd, - const bool skip) +char *eval_to_string_skip(const char *arg, const char **nextcmd, const bool skip) FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT { typval_T tv; @@ -890,7 +881,7 @@ char_u *eval_to_string(char_u *arg, char_u **nextcmd, bool convert) */ char_u *eval_to_string_safe(char_u *arg, char_u **nextcmd, int use_sandbox) { - char_u *retval; + char_u *retval; funccal_entry_T funccal_entry; save_funccal(&funccal_entry); @@ -916,7 +907,7 @@ varnumber_T eval_to_number(char_u *expr) { typval_T rettv; varnumber_T retval; - char_u *p = skipwhite(expr); + char_u *p = skipwhite(expr); ++emsg_off; @@ -951,8 +942,9 @@ typval_T *eval_expr(char_u *arg) void prepare_vimvar(int idx, typval_T *save_tv) { *save_tv = vimvars[idx].vv_tv; - if (vimvars[idx].vv_type == VAR_UNKNOWN) + if (vimvars[idx].vv_type == VAR_UNKNOWN) { hash_add(&vimvarht, vimvars[idx].vv_di.di_key); + } } /* @@ -961,7 +953,7 @@ void prepare_vimvar(int idx, typval_T *save_tv) */ void restore_vimvar(int idx, typval_T *save_tv) { - hashitem_T *hi; + hashitem_T *hi; vimvars[idx].vv_tv = *save_tv; if (vimvars[idx].vv_type == VAR_UNKNOWN) { @@ -994,15 +986,16 @@ list_T *eval_spell_expr(char_u *badword, char_u *expr) { typval_T save_val; typval_T rettv; - list_T *list = NULL; - char_u *p = skipwhite(expr); + list_T *list = NULL; + char_u *p = skipwhite(expr); // Set "v:val" to the bad word. prepare_vimvar(VV_VAL, &save_val); vimvars[VV_VAL].vv_type = VAR_STRING; vimvars[VV_VAL].vv_str = badword; - if (p_verbose == 0) + if (p_verbose == 0) { ++emsg_off; + } if (eval1(&p, &rettv, true) == OK) { if (rettv.v_type != VAR_LIST) { @@ -1012,8 +1005,9 @@ list_T *eval_spell_expr(char_u *badword, char_u *expr) } } - if (p_verbose == 0) + if (p_verbose == 0) { --emsg_off; + } restore_vimvar(VV_VAL, &save_val); return list; @@ -1052,12 +1046,7 @@ int get_spellword(list_T *const list, const char **ret_word) // should have type VAR_UNKNOWN. // // Return OK or FAIL. -int call_vim_function( - const char_u *func, - int argc, - typval_T *argv, - typval_T *rettv -) +int call_vim_function(const char_u *func, int argc, typval_T *argv, typval_T *rettv) FUNC_ATTR_NONNULL_ALL { int ret; @@ -1096,8 +1085,7 @@ fail: /// @param[in] argv Array with typval_T arguments. /// /// @return -1 when calling function fails, result of function otherwise. -varnumber_T call_func_retnr(const char_u *func, int argc, - typval_T *argv) +varnumber_T call_func_retnr(const char_u *func, int argc, typval_T *argv) FUNC_ATTR_NONNULL_ALL { typval_T rettv; @@ -1118,8 +1106,7 @@ varnumber_T call_func_retnr(const char_u *func, int argc, /// /// @return [allocated] NULL when calling function fails, allocated string /// otherwise. -char *call_func_retstr(const char *const func, int argc, - typval_T *argv) +char *call_func_retstr(const char *const func, int argc, typval_T *argv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC { typval_T rettv; @@ -1159,14 +1146,12 @@ void *call_func_retlist(const char_u *func, int argc, typval_T *argv) return rettv.vval.v_list; } -/* - * Prepare profiling for entering a child or something else that is not - * counted for the script/function itself. - * Should always be called in pair with prof_child_exit(). - */ -void prof_child_enter( - proftime_T *tm // place to store waittime -) +/// Prepare profiling for entering a child or something else that is not +/// counted for the script/function itself. +/// Should always be called in pair with prof_child_exit(). +/// +/// @param tm place to store waittime +void prof_child_enter(proftime_T *tm) { funccall_T *fc = get_current_funccal(); @@ -1177,13 +1162,11 @@ void prof_child_enter( script_prof_save(tm); } -/* - * Take care of time spent in a child. - * Should always be called after prof_child_enter(). - */ -void prof_child_exit( - proftime_T *tm // where waittime was stored -) +/// Take care of time spent in a child. +/// Should always be called after prof_child_enter(). +/// +/// @param tm where waittime was stored +void prof_child_exit(proftime_T *tm) { funccall_T *fc = get_current_funccal(); @@ -1211,8 +1194,9 @@ int eval_foldexpr(char_u *arg, int *cp) int use_sandbox = was_set_insecurely(curwin, (char_u *)"foldexpr", OPT_LOCAL); ++emsg_off; - if (use_sandbox) + if (use_sandbox) { ++sandbox; + } ++textlock; *cp = NUL; if (eval0(arg, &tv, NULL, true) == FAIL) { @@ -1235,8 +1219,9 @@ int eval_foldexpr(char_u *arg, int *cp) tv_clear(&tv); } --emsg_off; - if (use_sandbox) + if (use_sandbox) { --sandbox; + } --textlock; return (int)retval; @@ -1262,8 +1247,7 @@ void ex_const(exarg_T *eap) // marker, then the leading indentation before the lines (matching the // indentation in the 'cmd' line) is stripped. // Returns a List with {lines} or NULL. -static list_T * -heredoc_get(exarg_T *eap, char_u *cmd) +static list_T *heredoc_get(exarg_T *eap, char_u *cmd) { char_u *marker; char_u *p; @@ -1327,29 +1311,29 @@ heredoc_get(exarg_T *eap, char_u *cmd) // marker if (marker_indent_len > 0 && STRNCMP(theline, *eap->cmdlinep, marker_indent_len) == 0) { - mi = marker_indent_len; + mi = marker_indent_len; } if (STRCMP(marker, theline + mi) == 0) { xfree(theline); break; } if (text_indent_len == -1 && *theline != NUL) { - // set the text indent from the first line. - p = theline; - text_indent_len = 0; - while (ascii_iswhite(*p)) { - p++; - text_indent_len++; - } - text_indent = vim_strnsave(theline, text_indent_len); + // set the text indent from the first line. + p = theline; + text_indent_len = 0; + while (ascii_iswhite(*p)) { + p++; + text_indent_len++; + } + text_indent = vim_strnsave(theline, text_indent_len); } // with "trim": skip the indent matching the first line if (text_indent != NULL) { - for (ti = 0; ti < text_indent_len; ti++) { - if (theline[ti] != text_indent[ti]) { - break; - } + for (ti = 0; ti < text_indent_len; ti++) { + if (theline[ti] != text_indent[ti]) { + break; } + } } tv_list_append_string(l, (char *)(theline + ti), -1); @@ -1379,14 +1363,14 @@ void ex_let(exarg_T *eap) static void ex_let_const(exarg_T *eap, const bool is_const) { - char_u *arg = eap->arg; - char_u *expr = NULL; + char_u *arg = eap->arg; + char_u *expr = NULL; typval_T rettv; int i; int var_count = 0; int semicolon = 0; char_u op[2]; - char_u *argend; + char_u *argend; int first = TRUE; argend = (char_u *)skip_var_list(arg, &var_count, &semicolon); @@ -1444,8 +1428,9 @@ static void ex_let_const(exarg_T *eap, const bool is_const) expr = skipwhite(expr + 1); } - if (eap->skip) + if (eap->skip) { ++emsg_skip; + } i = eval0(expr, &rettv, &eap->nextcmd, !eap->skip); if (eap->skip) { if (i != FAIL) { @@ -1460,21 +1445,20 @@ static void ex_let_const(exarg_T *eap, const bool is_const) } } -/* - * Assign the typevalue "tv" to the variable or variables at "arg_start". - * Handles both "var" with any type and "[var, var; var]" with a list type. - * When "op" is not NULL it points to a string with characters that - * must appear after the variable(s). Use "+", "-" or "." for add, subtract - * or concatenate. - * Returns OK or FAIL; - */ -static int ex_let_vars(char_u *arg_start, - typval_T *tv, - int copy, // copy values from "tv", don't move - int semicolon, // from skip_var_list() - int var_count, // from skip_var_list() - int is_const, // lock variables for :const - char_u *op) +/// Assign the typevalue "tv" to the variable or variables at "arg_start". +/// Handles both "var" with any type and "[var, var; var]" with a list type. +/// When "op" is not NULL it points to a string with characters that +/// must appear after the variable(s). Use "+", "-" or "." for add, subtract +/// or concatenate. +/// +/// @param copy copy values from "tv", don't move +/// @param semicolon from skip_var_list() +/// @param var_count from skip_var_list() +/// @param is_const lock variables for :const +/// +/// @return OK or FAIL; +static int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, int var_count, + int is_const, char_u *op) { char_u *arg = arg_start; typval_T ltv; @@ -1559,8 +1543,7 @@ static int ex_let_vars(char_u *arg_start, * for "[var, var; var]" set "semicolon". * Return NULL for an error. */ -static const char_u *skip_var_list(const char_u *arg, int *var_count, - int *semicolon) +static const char_u *skip_var_list(const char_u *arg, int *var_count, int *semicolon) { const char_u *p; const char_u *s; @@ -1578,9 +1561,9 @@ static const char_u *skip_var_list(const char_u *arg, int *var_count, ++*var_count; p = skipwhite(s); - if (*p == ']') + if (*p == ']') { break; - else if (*p == ';') { + } else if (*p == ';') { if (*semicolon == 1) { EMSG(_("E452: Double ; in list of variables")); return NULL; @@ -1592,8 +1575,9 @@ static const char_u *skip_var_list(const char_u *arg, int *var_count, } } return p + 1; - } else + } else { return skip_var_one(arg); + } } /* @@ -1602,21 +1586,21 @@ static const char_u *skip_var_list(const char_u *arg, int *var_count, */ static const char_u *skip_var_one(const char_u *arg) { - if (*arg == '@' && arg[1] != NUL) + if (*arg == '@' && arg[1] != NUL) { return arg + 2; + } return find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, - NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); + NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); } /* * List variables for hashtab "ht" with prefix "prefix". * If "empty" is TRUE also list NULL strings as empty strings. */ -void list_hashtable_vars(hashtab_T *ht, const char *prefix, int empty, - int *first) +void list_hashtable_vars(hashtab_T *ht, const char *prefix, int empty, int *first) { - hashitem_T *hi; - dictitem_T *di; + hashitem_T *hi; + dictitem_T *di; int todo; todo = (int)ht->ht_used; @@ -1740,13 +1724,20 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first) } else { if (arg == arg_subsc && len == 2 && name[1] == ':') { switch (*name) { - case 'g': list_glob_vars(first); break; - case 'b': list_buf_vars(first); break; - case 'w': list_win_vars(first); break; - case 't': list_tab_vars(first); break; - case 'v': list_vim_vars(first); break; - case 's': list_script_vars(first); break; - case 'l': list_func_vars(first); break; + case 'g': + list_glob_vars(first); break; + case 'b': + list_buf_vars(first); break; + case 'w': + list_win_vars(first); break; + case 't': + list_tab_vars(first); break; + case 'v': + list_vim_vars(first); break; + case 's': + list_script_vars(first); break; + case 'l': + list_func_vars(first); break; default: EMSG2(_("E738: Can't list variables for %s"), name); } @@ -1789,8 +1780,7 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first) /// /// @return a pointer to the char just after the var name or NULL in case of /// error. -static char_u *ex_let_one(char_u *arg, typval_T *const tv, - const bool copy, const bool is_const, +static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, const bool is_const, const char_u *const endchars, const char_u *const op) FUNC_ATTR_NONNULL_ARG(1, 2) FUNC_ATTR_WARN_UNUSED_RESULT { @@ -1848,9 +1838,9 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, xfree(tofree); } } - // ":let &option = expr": Set option value. - // ":let &l:option = expr": Set local option value. - // ":let &g:option = expr": Set global option value. + // ":let &option = expr": Set option value. + // ":let &l:option = expr": Set local option value. + // ":let &g:option = expr": Set global option value. } else if (*arg == '&') { if (is_const) { EMSG(_("E996: Cannot lock an option")); @@ -1885,11 +1875,16 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, } else { if (opt_type == 1) { // number switch (*op) { - case '+': n = numval + n; break; - case '-': n = numval - n; break; - case '*': n = numval * n; break; - case '/': n = num_divide(numval, n); break; - case '%': n = num_modulus(numval, n); break; + case '+': + n = numval + n; break; + case '-': + n = numval - n; break; + case '*': + n = numval * n; break; + case '/': + n = num_divide(numval, n); break; + case '%': + n = num_modulus(numval, n); break; } } else if (opt_type == 0 && stringval != NULL) { // string char *const oldstringval = stringval; @@ -1908,7 +1903,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, *p = c1; xfree(stringval); } - // ":let @r = expr": Set register contents. + // ":let @r = expr": Set register contents. } else if (*arg == '@') { if (is_const) { EMSG(_("E996: Cannot lock a register")); @@ -1921,7 +1916,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, && vim_strchr(endchars, *skipwhite(arg + 1)) == NULL) { EMSG(_(e_letunexp)); } else { - char_u *s; + char_u *s; char_u *ptofree = NULL; const char *p = tv_get_string_chk(tv); @@ -1958,8 +1953,9 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, } } clear_lval(&lv); - } else + } else { EMSG2(_(e_invarg2), arg); + } return arg_end; } @@ -1989,16 +1985,15 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, /// /// @return A pointer to just after the name, including indexes. Returns NULL /// for a parsing error, but it is still needed to free items in lp. -char_u *get_lval(char_u *const name, typval_T *const rettv, - lval_T *const lp, const bool unlet, const bool skip, - const int flags, const int fne_flags) +char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, const bool unlet, + const bool skip, const int flags, const int fne_flags) FUNC_ATTR_NONNULL_ARG(1, 3) { - dictitem_T *v; + dictitem_T *v; typval_T var1; typval_T var2; int empty1 = FALSE; - listitem_T *ni; + listitem_T *ni; hashtab_T *ht = NULL; int quiet = flags & GLV_QUIET; @@ -2080,8 +2075,9 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, return NULL; } if (lp->ll_range) { - if (!quiet) + if (!quiet) { EMSG(_("E708: [:] must come last")); + } return NULL; } @@ -2233,7 +2229,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, } tv_clear(&var1); break; - // existing variable, need to check if it can be changed + // existing variable, need to check if it can be changed } else if (!(flags & GLV_READ_ONLY) && var_check_ro(lp->ll_di->di_flags, (const char *)name, (size_t)(p - name))) { @@ -2312,8 +2308,9 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, if (lp->ll_n2 < 0) { ni = tv_list_find(lp->ll_list, lp->ll_n2); if (ni == NULL) { - if (!quiet) + if (!quiet) { EMSGN(_(e_listidx), lp->ll_n2); + } return NULL; } lp->ll_n2 = tv_list_idx_of_item(lp->ll_list, ni); @@ -2358,12 +2355,12 @@ void clear_lval(lval_T *lp) * "op" is NULL, "+" for "+=", "-" for "-=", "*" for "*=", "/" for "/=", * "%" for "%=", "." for ".=" or "=" for "=". */ -static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, - int copy, const bool is_const, const char *op) +static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, const bool is_const, + const char *op) { int cc; - listitem_T *ri; - dictitem_T *di; + listitem_T *ri; + dictitem_T *di; if (lp->ll_tv == NULL) { cc = *endp; @@ -2568,16 +2565,17 @@ notify: */ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) { - forinfo_T *fi = xcalloc(1, sizeof(forinfo_T)); + forinfo_T *fi = xcalloc(1, sizeof(forinfo_T)); const char_u *expr; typval_T tv; - list_T *l; + list_T *l; *errp = true; // Default: there is an error. expr = skip_var_list(arg, &fi->fi_varcount, &fi->fi_semicolon); - if (expr == NULL) + if (expr == NULL) { return fi; + } expr = skipwhite(expr); if (expr[0] != 'i' || expr[1] != 'n' || !ascii_iswhite(expr[2])) { @@ -2585,8 +2583,9 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) return fi; } - if (skip) + if (skip) { ++emsg_skip; + } if (eval0(skipwhite(expr + 2), &tv, nextcmdp, !skip) == OK) { *errp = false; if (!skip) { @@ -2619,8 +2618,9 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) } } } - if (skip) + if (skip) { --emsg_skip; + } return fi; } @@ -2667,7 +2667,7 @@ bool next_for_item(void *fi_void, char_u *arg) */ void free_for_info(void *fi_void) { - forinfo_T *fi = (forinfo_T *)fi_void; + forinfo_T *fi = (forinfo_T *)fi_void; if (fi != NULL && fi->fi_list != NULL) { tv_list_watch_remove(fi->fi_list, &fi->fi_lw); @@ -2685,7 +2685,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) { int got_eq = FALSE; int c; - char_u *p; + char_u *p; if (cmdidx == CMD_let || cmdidx == CMD_const) { xp->xp_context = EXPAND_USER_VARS; @@ -2700,11 +2700,12 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) } return; } - } else + } else { xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS - : EXPAND_EXPRESSION; + : EXPAND_EXPRESSION; + } while ((xp->xp_pattern = vim_strpbrk(arg, - (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) { + (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) { c = *xp->xp_pattern; if (c == '&') { c = xp->xp_pattern[1]; @@ -2714,9 +2715,9 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) ? EXPAND_EXPRESSION : EXPAND_NOTHING; } else if (c != ' ') { xp->xp_context = EXPAND_SETTINGS; - if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':') + if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':') { xp->xp_pattern += 2; - + } } } else if (c == '$') { // environment variable @@ -2750,14 +2751,17 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) if (xp->xp_pattern[1] == '|') { ++xp->xp_pattern; xp->xp_context = EXPAND_EXPRESSION; - } else + } else { xp->xp_context = EXPAND_COMMANDS; - } else + } + } else { xp->xp_context = EXPAND_EXPRESSION; - } else + } + } else { /* Doesn't look like something valid, expand as an expression * anyway. */ xp->xp_context = EXPAND_EXPRESSION; + } arg = xp->xp_pattern; if (*arg != NUL) { while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) { @@ -2819,8 +2823,7 @@ void ex_lockvar(exarg_T *eap) /// @param[in] deep Levels to (un)lock for :(un)lockvar, -1 to (un)lock /// everything. /// @param[in] callback Appropriate handler for the command. -static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep, - ex_unletlock_callback callback) +static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep, ex_unletlock_callback callback) FUNC_ATTR_NONNULL_ALL { char_u *arg = argstart; @@ -2884,8 +2887,7 @@ static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep, /// @param[in] deep Unused. /// /// @return OK on success, or FAIL on failure. -static int do_unlet_var(lval_T *lp, char_u *name_end, exarg_T *eap, - int deep FUNC_ATTR_UNUSED) +static int do_unlet_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep FUNC_ATTR_UNUSED) FUNC_ATTR_NONNULL_ALL { int forceit = eap->forceit; @@ -2989,7 +2991,7 @@ int do_unlet(const char *const name, const size_t name_len, const bool forceit) if (ht == &globvarht) { d = &globvardict; } else if (ht == &compat_hashtab) { - d = &vimvardict; + d = &vimvardict; } else { dictitem_T *const di = find_var_in_ht(ht, *name, "", 0, false); d = di->di_tv.vval.v_dict; @@ -3032,8 +3034,9 @@ int do_unlet(const char *const name, const size_t name_len, const bool forceit) return OK; } } - if (forceit) + if (forceit) { return OK; + } EMSG2(_("E108: No such variable: \"%s\""), name); return FAIL; } @@ -3050,8 +3053,7 @@ int do_unlet(const char *const name, const size_t name_len, const bool forceit) /// @param[in] deep Levels to (un)lock, -1 to (un)lock everything. /// /// @return OK on success, or FAIL on failure. -static int do_lock_var(lval_T *lp, char_u *name_end FUNC_ATTR_UNUSED, - exarg_T *eap, int deep) +static int do_lock_var(lval_T *lp, char_u *name_end FUNC_ATTR_UNUSED, exarg_T *eap, int deep) FUNC_ATTR_NONNULL_ARG(1, 3) { bool lock = eap->cmdidx == CMD_lockvar; @@ -3067,9 +3069,8 @@ static int do_lock_var(lval_T *lp, char_u *name_end FUNC_ATTR_UNUSED, ret = FAIL; } else { // Normal name or expanded name. - dictitem_T *const di = find_var( - (const char *)lp->ll_name, lp->ll_name_len, NULL, - true); + dictitem_T *const di = find_var((const char *)lp->ll_name, lp->ll_name_len, NULL, + true); if (di == NULL) { ret = FAIL; } else if ((di->di_flags & DI_FLAGS_FIX) @@ -3089,7 +3090,7 @@ static int do_lock_var(lval_T *lp, char_u *name_end FUNC_ATTR_UNUSED, } } } else if (lp->ll_range) { - listitem_T *li = lp->ll_li; + listitem_T *li = lp->ll_li; // (un)lock a range of List items. while (li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1)) { @@ -3129,7 +3130,7 @@ void del_menutrans_vars(void) */ -static char_u *varnamebuf = NULL; +static char_u *varnamebuf = NULL; static size_t varnamebuflen = 0; /* @@ -3163,7 +3164,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) static size_t wdone; static size_t tdone; static size_t vidx; - static hashitem_T *hi; + static hashitem_T *hi; if (idx == 0) { gdone = bdone = wdone = vidx = 0; @@ -3172,14 +3173,17 @@ char_u *get_user_var_name(expand_T *xp, int idx) // Global variables if (gdone < globvarht.ht_used) { - if (gdone++ == 0) + if (gdone++ == 0) { hi = globvarht.ht_array; - else + } else { ++hi; - while (HASHITEM_EMPTY(hi)) + } + while (HASHITEM_EMPTY(hi)) { ++hi; - if (STRNCMP("g:", xp->xp_pattern, 2) == 0) + } + if (STRNCMP("g:", xp->xp_pattern, 2) == 0) { return cat_prefix_varname('g', hi->hi_key); + } return hi->hi_key; } @@ -3189,12 +3193,14 @@ char_u *get_user_var_name(expand_T *xp, int idx) ? &prevwin->w_buffer->b_vars->dv_hashtab : &curbuf->b_vars->dv_hashtab; if (bdone < ht->ht_used) { - if (bdone++ == 0) + if (bdone++ == 0) { hi = ht->ht_array; - else + } else { ++hi; - while (HASHITEM_EMPTY(hi)) + } + while (HASHITEM_EMPTY(hi)) { ++hi; + } return cat_prefix_varname('b', hi->hi_key); } @@ -3204,24 +3210,28 @@ char_u *get_user_var_name(expand_T *xp, int idx) ? &prevwin->w_vars->dv_hashtab : &curwin->w_vars->dv_hashtab; if (wdone < ht->ht_used) { - if (wdone++ == 0) + if (wdone++ == 0) { hi = ht->ht_array; - else + } else { ++hi; - while (HASHITEM_EMPTY(hi)) + } + while (HASHITEM_EMPTY(hi)) { ++hi; + } return cat_prefix_varname('w', hi->hi_key); } // t: variables ht = &curtab->tp_vars->dv_hashtab; if (tdone < ht->ht_used) { - if (tdone++ == 0) + if (tdone++ == 0) { hi = ht->ht_array; - else + } else { ++hi; - while (HASHITEM_EMPTY(hi)) + } + while (HASHITEM_EMPTY(hi)) { ++hi; + } return cat_prefix_varname('t', hi->hi_key); } @@ -3265,8 +3275,7 @@ static int pattern_match(char_u *pat, char_u *text, bool ic) // /// @return OK or FAIL. static int eval_func(char_u **const arg, char_u *const name, const int name_len, - typval_T *const rettv, const bool evaluate, - typval_T *const basetv) + typval_T *const rettv, const bool evaluate, typval_T *const basetv) FUNC_ATTR_NONNULL_ARG(1, 2, 4) { char_u *s = name; @@ -3334,7 +3343,7 @@ static int eval_func(char_u **const arg, char_u *const name, const int name_len, int eval0(char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate) { int ret; - char_u *p; + char_u *p; const int did_emsg_before = did_emsg; const int called_emsg_before = called_emsg; @@ -3354,8 +3363,9 @@ int eval0(char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate) } ret = FAIL; } - if (nextcmd != NULL) + if (nextcmd != NULL) { *nextcmd = check_nextcmd(p); + } return ret; } @@ -3364,7 +3374,7 @@ int eval0(char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate) /* * Handle top level expression: - * expr2 ? expr1 : expr1 + * expr2 ? expr1 : expr1 * * "arg" must point to the first non-white of the expression. * "arg" is advanced to the next non-white after the recognized expression. @@ -3381,8 +3391,9 @@ int eval1(char_u **arg, typval_T *rettv, int evaluate) /* * Get the first variable. */ - if (eval2(arg, rettv, evaluate) == FAIL) + if (eval2(arg, rettv, evaluate) == FAIL) { return FAIL; + } if ((*arg)[0] == '?') { result = FALSE; @@ -3427,8 +3438,9 @@ int eval1(char_u **arg, typval_T *rettv, int evaluate) } return FAIL; } - if (evaluate && !result) + if (evaluate && !result) { *rettv = var2; + } } return OK; @@ -3438,7 +3450,7 @@ int eval1(char_u **arg, typval_T *rettv, int evaluate) /* * Handle first level expression: - * expr2 || expr2 || expr2 logical OR + * expr2 || expr2 || expr2 logical OR * * "arg" must point to the first non-white of the expression. * "arg" is advanced to the next non-white after the recognized expression. @@ -3455,8 +3467,9 @@ static int eval2(char_u **arg, typval_T *rettv, int evaluate) /* * Get the first variable. */ - if (eval3(arg, rettv, evaluate) == FAIL) + if (eval3(arg, rettv, evaluate) == FAIL) { return FAIL; + } /* * Repeat until there is no following "||". @@ -3479,8 +3492,9 @@ static int eval2(char_u **arg, typval_T *rettv, int evaluate) * Get the second variable. */ *arg = skipwhite(*arg + 2); - if (eval3(arg, &var2, evaluate && !result) == FAIL) + if (eval3(arg, &var2, evaluate && !result) == FAIL) { return FAIL; + } /* * Compute the result. @@ -3507,7 +3521,7 @@ static int eval2(char_u **arg, typval_T *rettv, int evaluate) /* * Handle second level expression: - * expr3 && expr3 && expr3 logical AND + * expr3 && expr3 && expr3 logical AND * * "arg" must point to the first non-white of the expression. * "arg" is advanced to the next non-white after the recognized expression. @@ -3524,8 +3538,9 @@ static int eval3(char_u **arg, typval_T *rettv, int evaluate) /* * Get the first variable. */ - if (eval4(arg, rettv, evaluate) == FAIL) + if (eval4(arg, rettv, evaluate) == FAIL) { return FAIL; + } /* * Repeat until there is no following "&&". @@ -3548,8 +3563,9 @@ static int eval3(char_u **arg, typval_T *rettv, int evaluate) * Get the second variable. */ *arg = skipwhite(*arg + 2); - if (eval4(arg, &var2, evaluate && result) == FAIL) + if (eval4(arg, &var2, evaluate && result) == FAIL) { return FAIL; + } /* * Compute the result. @@ -3576,16 +3592,16 @@ static int eval3(char_u **arg, typval_T *rettv, int evaluate) /* * Handle third level expression: - * var1 == var2 - * var1 =~ var2 - * var1 != var2 - * var1 !~ var2 - * var1 > var2 - * var1 >= var2 - * var1 < var2 - * var1 <= var2 - * var1 is var2 - * var1 isnot var2 + * var1 == var2 + * var1 =~ var2 + * var1 != var2 + * var1 !~ var2 + * var1 > var2 + * var1 >= var2 + * var1 < var2 + * var1 <= var2 + * var1 is var2 + * var1 isnot var2 * * "arg" must point to the first non-white of the expression. * "arg" is advanced to the next non-white after the recognized expression. @@ -3595,7 +3611,7 @@ static int eval3(char_u **arg, typval_T *rettv, int evaluate) static int eval4(char_u **arg, typval_T *rettv, int evaluate) { typval_T var2; - char_u *p; + char_u *p; exprtype_T type = EXPR_UNKNOWN; int len = 2; bool ic; @@ -3603,8 +3619,9 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate) /* * Get the first variable. */ - if (eval5(arg, rettv, evaluate) == FAIL) + if (eval5(arg, rettv, evaluate) == FAIL) { return FAIL; + } p = *arg; switch (p[0]) { @@ -3638,14 +3655,15 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate) type = EXPR_SEQUAL; } break; - case 'i': if (p[1] == 's') { + case 'i': + if (p[1] == 's') { if (p[2] == 'n' && p[3] == 'o' && p[4] == 't') { len = 5; } if (!isalnum(p[len]) && p[len] != '_') { type = len == 2 ? EXPR_IS : EXPR_ISNOT; } - } + } break; } @@ -3685,10 +3703,10 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate) /* * Handle fourth level expression: - * + number addition - * - number subtraction - * . string concatenation - * .. string concatenation + * + number addition + * - number subtraction + * . string concatenation + * .. string concatenation * * "arg" must point to the first non-white of the expression. * "arg" is advanced to the next non-white after the recognized expression. @@ -3702,21 +3720,23 @@ static int eval5(char_u **arg, typval_T *rettv, int evaluate) int op; varnumber_T n1, n2; float_T f1 = 0, f2 = 0; - char_u *p; + char_u *p; /* * Get the first variable. */ - if (eval6(arg, rettv, evaluate, FALSE) == FAIL) + if (eval6(arg, rettv, evaluate, FALSE) == FAIL) { return FAIL; + } /* * Repeat computing, until no '+', '-' or '.' is following. */ for (;; ) { op = **arg; - if (op != '+' && op != '-' && op != '.') + if (op != '+' && op != '-' && op != '.') { break; + } if ((op != '+' || (rettv->v_type != VAR_LIST && rettv->v_type != VAR_BLOB)) && (op == '.' || rettv->v_type != VAR_FLOAT)) { @@ -3807,8 +3827,9 @@ static int eval5(char_u **arg, typval_T *rettv, int evaluate)