aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordundargoc <33953936+dundargoc@users.noreply.github.com>2021-09-20 15:53:38 +0200
committerGitHub <noreply@github.com>2021-09-20 06:53:38 -0700
commit30fefee684e641a0c6867446c6de30efa2f0a126 (patch)
tree4767168715527b32a6f030a2907be2b4af5b33b3
parent490e09c6d81b9bf52eac7aa146e62b3da2d86579 (diff)
downloadrneovim-30fefee684e641a0c6867446c6de30efa2f0a126.tar.gz
rneovim-30fefee684e641a0c6867446c6de30efa2f0a126.tar.bz2
rneovim-30fefee684e641a0c6867446c6de30efa2f0a126.zip
refactor: format with uncrustify #15726
-rw-r--r--src/nvim/debugger.c64
-rw-r--r--src/nvim/decoration.c32
-rw-r--r--src/nvim/diff.c116
-rw-r--r--src/nvim/digraph.c28
-rw-r--r--src/nvim/eval.c2086
-rw-r--r--src/nvim/ex_cmds2.c210
-rw-r--r--src/nvim/ex_eval.c413
-rw-r--r--src/nvim/ex_getln.c1208
-rw-r--r--src/nvim/ex_session.c64
-rw-r--r--src/nvim/extmark.c91
10 files changed, 2203 insertions, 2109 deletions
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 <inttypes.h>
#include <stdbool.h>
-#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 <assert.h>
-#include <stdbool.h>
#include <inttypes.h>
+#include <stdbool.h>
-#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)
tv_clear(&var2);
return FAIL;
}
- if (var2.v_type == VAR_FLOAT)
+ if (var2.v_type == VAR_FLOAT) {
f1 = n1;
+ }
}
if (var2.v_type == VAR_FLOAT) {
f2 = var2.vval.v_float;
@@ -3820,24 +3841,27 @@ static int eval5(char_u **arg, typval_T *rettv, int evaluate)
tv_clear(&var2);
return FAIL;
}
- if (rettv->v_type == VAR_FLOAT)
+ if (rettv->v_type == VAR_FLOAT) {
f2 = n2;
+ }
}
tv_clear(rettv);
// If there is a float on either side the result is a float.
if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT) {
- if (op == '+')
+ if (op == '+') {
f1 = f1 + f2;
- else
+ } else {
f1 = f1 - f2;
+ }
rettv->v_type = VAR_FLOAT;
rettv->vval.v_float = f1;
} else {
- if (op == '+')
+ if (op == '+') {
n1 = n1 + n2;
- else
+ } else {
n1 = n1 - n2;
+ }
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = n1;
}
@@ -3876,8 +3900,9 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string)
/*
* Get the first variable.
*/
- if (eval7(arg, rettv, evaluate, want_string) == FAIL)
+ if (eval7(arg, rettv, evaluate, want_string) == FAIL) {
return FAIL;
+ }
/*
* Repeat computing, until no '*', '/' or '%' is following.
@@ -3908,8 +3933,9 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string)
* Get the second variable.
*/
*arg = skipwhite(*arg + 1);
- if (eval7(arg, &var2, evaluate, FALSE) == FAIL)
+ if (eval7(arg, &var2, evaluate, FALSE) == FAIL) {
return FAIL;
+ }
if (evaluate) {
if (var2.v_type == VAR_FLOAT) {
@@ -3942,15 +3968,15 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string)
f1 = (f2 == 0
? (
#ifdef NAN
- f1 == 0
+ f1 == 0
? NAN
:
#endif
- (f1 > 0
+ (f1 > 0
? INFINITY
: -INFINITY)
- )
- : f1 / f2);
+ )
+ : f1 / f2);
} else {
EMSG(_("E804: Cannot use '%' with Float"));
return FAIL;
@@ -3976,39 +4002,36 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string)
// TODO(ZyX-I): move to eval/expressions
-// Handle sixth level expression:
-// number number constant
-// 0zFFFFFFFF Blob constant
-// "string" string constant
-// 'string' literal string constant
-// &option-name option value
-// @r register contents
-// identifier variable value
-// function() function call
-// $VAR environment variable
-// (expression) nested expression
-// [expr, expr] List
-// {key: val, key: val} Dictionary
-// #{key: val, key: val} Dictionary with literal keys
-//
-// Also handle:
-// ! in front logical NOT
-// - in front unary minus
-// + in front unary plus (ignored)
-// trailing [] subscript in String or List
-// trailing .name entry in Dictionary
-// trailing ->name() method call
-//
-// "arg" must point to the first non-white of the expression.
-// "arg" is advanced to the next non-white after the recognized expression.
-//
-// Return OK or FAIL.
-static int eval7(
- char_u **arg,
- typval_T *rettv,
- int evaluate,
- int want_string // after "." operator
-)
+/// Handle sixth level expression:
+/// number number constant
+/// 0zFFFFFFFF Blob constant
+/// "string" string constant
+/// 'string' literal string constant
+/// &option-name option value
+/// @r register contents
+/// identifier variable value
+/// function() function call
+/// $VAR environment variable
+/// (expression) nested expression
+/// [expr, expr] List
+/// {key: val, key: val} Dictionary
+/// #{key: val, key: val} Dictionary with literal keys
+///
+/// Also handle:
+/// ! in front logical NOT
+/// - in front unary minus
+/// + in front unary plus (ignored)
+/// trailing [] subscript in String or List
+/// trailing .name entry in Dictionary
+/// trailing ->name() method call
+///
+/// "arg" must point to the first non-white of the expression.
+/// "arg" is advanced to the next non-white after the recognized expression.
+///
+/// @param want_string after "." operator
+///
+/// @return OK or FAIL.
+static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string)
{
varnumber_T n;
int len;
@@ -4039,8 +4062,7 @@ static int eval7(
case '6':
case '7':
case '8':
- case '9':
- {
+ case '9': {
char_u *p = skipdigits(*arg + 1);
int get_float = false;
@@ -4070,7 +4092,7 @@ static int eval7(
if (get_float) {
float_T f;
- *arg += string2float((char *) *arg, &f);
+ *arg += string2float((char *)*arg, &f);
if (evaluate) {
rettv->v_type = VAR_FLOAT;
rettv->vval.v_float = f;
@@ -4122,15 +4144,18 @@ static int eval7(
}
// String constant: "string".
- case '"': ret = get_string_tv(arg, rettv, evaluate);
+ case '"':
+ ret = get_string_tv(arg, rettv, evaluate);
break;
// Literal string constant: 'str''ing'.
- case '\'': ret = get_lit_string_tv(arg, rettv, evaluate);
+ case '\'':
+ ret = get_lit_string_tv(arg, rettv, evaluate);
break;
// List: [expr, expr]
- case '[': ret = get_list_tv(arg, rettv, evaluate);
+ case '[':
+ ret = get_list_tv(arg, rettv, evaluate);
break;
// Dictionary: #{key: val, key: val}
@@ -4145,23 +4170,25 @@ static int eval7(
// Lambda: {arg, arg -> expr}
// Dictionary: {'key': val, 'key': val}
- case '{': ret = get_lambda_tv(arg, rettv, evaluate);
- if (ret == NOTDONE) {
- ret = dict_get_tv(arg, rettv, evaluate, false);
- }
+ case '{':
+ ret = get_lambda_tv(arg, rettv, evaluate);
+ if (ret == NOTDONE) {
+ ret = dict_get_tv(arg, rettv, evaluate, false);
+ }
break;
// Option value: &name
- case '&': {
+ case '&':
ret = get_option_tv((const char **)arg, rettv, evaluate);
break;
- }
// Environment variable: $VAR.
- case '$': ret = get_env_tv(arg, rettv, evaluate);
+ case '$':
+ ret = get_env_tv(arg, rettv, evaluate);
break;
// Register contents: @r.
- case '@': ++*arg;
+ case '@':
+ ++*arg;
if (evaluate) {
rettv->v_type = VAR_STRING;
rettv->vval.v_string = get_reg_contents(**arg, kGRegExprSrc);
@@ -4172,7 +4199,8 @@ static int eval7(
break;
// nested expression: (expression).
- case '(': *arg = skipwhite(*arg + 1);
+ case '(':
+ *arg = skipwhite(*arg + 1);
ret = eval1(arg, rettv, evaluate); // recursive!
if (**arg == ')') {
++*arg;
@@ -4183,7 +4211,8 @@ static int eval7(
}
break;
- default: ret = NOTDONE;
+ default:
+ ret = NOTDONE;
break;
}
@@ -4284,11 +4313,8 @@ static int eval7_leader(typval_T *const rettv, const char_u *const start_leader,
/// to the name of the Lua function to call (after the
/// "v:lua." prefix).
/// @return OK on success, FAIL on failure.
-static int call_func_rettv(char_u **const arg,
- typval_T *const rettv,
- const bool evaluate,
- dict_T *const selfdict,
- typval_T *const basetv,
+static int call_func_rettv(char_u **const arg, typval_T *const rettv, const bool evaluate,
+ dict_T *const selfdict, typval_T *const basetv,
const char_u *const lua_funcname)
FUNC_ATTR_NONNULL_ARG(1, 2)
{
@@ -4337,8 +4363,8 @@ static int call_func_rettv(char_u **const arg,
/// @param verbose if true, give error messages.
/// @note "*arg" points to the '-'.
/// @return FAIL or OK. @note "*arg" is advanced to after the ')'.
-static int eval_lambda(char_u **const arg, typval_T *const rettv,
- const bool evaluate, const bool verbose)
+static int eval_lambda(char_u **const arg, typval_T *const rettv, const bool evaluate,
+ const bool verbose)
FUNC_ATTR_NONNULL_ALL
{
// Skip over the ->.
@@ -4375,8 +4401,8 @@ static int eval_lambda(char_u **const arg, typval_T *const rettv,
/// Evaluate "->method()" or "->v:lua.method()".
/// @note "*arg" points to the '-'.
/// @return FAIL or OK. "*arg" is advanced to after the ')'.
-static int eval_method(char_u **const arg, typval_T *const rettv,
- const bool evaluate, const bool verbose)
+static int eval_method(char_u **const arg, typval_T *const rettv, const bool evaluate,
+ const bool verbose)
FUNC_ATTR_NONNULL_ALL
{
// Skip over the ->.
@@ -4445,60 +4471,49 @@ static int eval_method(char_u **const arg, typval_T *const rettv,
// TODO(ZyX-I): move to eval/expressions
-/*
- * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key".
- * "*arg" points to the '[' or '.'.
- * Returns FAIL or OK. "*arg" is advanced to after the ']'.
- */
-static int
-eval_index(
- char_u **arg,
- typval_T *rettv,
- int evaluate,
- int verbose // give error messages
-)
+/// Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key".
+/// "*arg" points to the '[' or '.'.
+/// Returns FAIL or OK. "*arg" is advanced to after the ']'.
+///
+/// @param verbose give error messages
+static int eval_index(char_u **arg, typval_T *rettv, int evaluate, int verbose)
{
bool empty1 = false;
bool empty2 = false;
long n1, n2 = 0;
ptrdiff_t len = -1;
int range = false;
- char_u *key = NULL;
+ char_u *key = NULL;
switch (rettv->v_type) {
- case VAR_FUNC:
- case VAR_PARTIAL: {
- if (verbose) {
- EMSG(_("E695: Cannot index a Funcref"));
- }
- return FAIL;
- }
- case VAR_FLOAT: {
- if (verbose) {
- EMSG(_(e_float_as_string));
- }
- return FAIL;
+ case VAR_FUNC:
+ case VAR_PARTIAL:
+ if (verbose) {
+ EMSG(_("E695: Cannot index a Funcref"));
}
- case VAR_BOOL:
- case VAR_SPECIAL: {
- if (verbose) {
- EMSG(_("E909: Cannot index a special variable"));
- }
- return FAIL;
+ return FAIL;
+ case VAR_FLOAT:
+ if (verbose) {
+ EMSG(_(e_float_as_string));
}
- case VAR_UNKNOWN: {
- if (evaluate) {
- return FAIL;
- }
- FALLTHROUGH;
+ return FAIL;
+ case VAR_BOOL:
+ case VAR_SPECIAL:
+ if (verbose) {
+ EMSG(_("E909: Cannot index a special variable"));
}
- case VAR_STRING:
- case VAR_NUMBER:
- case VAR_LIST:
- case VAR_DICT:
- case VAR_BLOB: {
- break;
+ return FAIL;
+ case VAR_UNKNOWN:
+ if (evaluate) {
+ return FAIL;
}
+ FALLTHROUGH;
+ case VAR_STRING:
+ case VAR_NUMBER:
+ case VAR_LIST:
+ case VAR_DICT:
+ case VAR_BLOB:
+ break;
}
typval_T var1 = TV_INITIAL_VALUE;
@@ -4508,10 +4523,12 @@ eval_index(
* dict.name
*/
key = *arg + 1;
- for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len)
+ for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) {
;
- if (len == 0)
+ }
+ if (len == 0) {
return FAIL;
+ }
*arg = skipwhite(key + len);
} else {
/*
@@ -4583,180 +4600,177 @@ eval_index(
}
switch (rettv->v_type) {
- case VAR_NUMBER:
- case VAR_STRING: {
- const char *const s = tv_get_string(rettv);
- char *v;
- len = (ptrdiff_t)strlen(s);
- if (range) {
- // The resulting variable is a substring. If the indexes
- // are out of range the result is empty.
+ case VAR_NUMBER:
+ case VAR_STRING: {
+ const char *const s = tv_get_string(rettv);
+ char *v;
+ len = (ptrdiff_t)strlen(s);
+ if (range) {
+ // The resulting variable is a substring. If the indexes
+ // are out of range the result is empty.
+ if (n1 < 0) {
+ n1 = len + n1;
if (n1 < 0) {
- n1 = len + n1;
- if (n1 < 0) {
- n1 = 0;
- }
- }
- if (n2 < 0) {
- n2 = len + n2;
- } else if (n2 >= len) {
- n2 = len;
- }
- if (n1 >= len || n2 < 0 || n1 > n2) {
- v = NULL;
- } else {
- v = xmemdupz(s + n1, (size_t)(n2 - n1 + 1));
+ n1 = 0;
}
+ }
+ if (n2 < 0) {
+ n2 = len + n2;
+ } else if (n2 >= len) {
+ n2 = len;
+ }
+ if (n1 >= len || n2 < 0 || n1 > n2) {
+ v = NULL;
} else {
- // The resulting variable is a string of a single
- // character. If the index is too big or negative the
- // result is empty.
- if (n1 >= len || n1 < 0) {
- v = NULL;
- } else {
- v = xmemdupz(s + n1, 1);
- }
+ v = xmemdupz(s + n1, (size_t)(n2 - n1 + 1));
+ }
+ } else {
+ // The resulting variable is a string of a single
+ // character. If the index is too big or negative the
+ // result is empty.
+ if (n1 >= len || n1 < 0) {
+ v = NULL;
+ } else {
+ v = xmemdupz(s + n1, 1);
}
- tv_clear(rettv);
- rettv->v_type = VAR_STRING;
- rettv->vval.v_string = (char_u *)v;
- break;
}
- case VAR_BLOB: {
- len = tv_blob_len(rettv->vval.v_blob);
- if (range) {
- // The resulting variable is a sub-blob. If the indexes
- // are out of range the result is empty.
+ tv_clear(rettv);
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = (char_u *)v;
+ break;
+ }
+ case VAR_BLOB:
+ len = tv_blob_len(rettv->vval.v_blob);
+ if (range) {
+ // The resulting variable is a sub-blob. If the indexes
+ // are out of range the result is empty.
+ if (n1 < 0) {
+ n1 = len + n1;
if (n1 < 0) {
- n1 = len + n1;
- if (n1 < 0) {
- n1 = 0;
- }
- }
- if (n2 < 0) {
- n2 = len + n2;
- } else if (n2 >= len) {
- n2 = len - 1;
- }
- if (n1 >= len || n2 < 0 || n1 > n2) {
- tv_clear(rettv);
- rettv->v_type = VAR_BLOB;
- rettv->vval.v_blob = NULL;
- } else {
- blob_T *const blob = tv_blob_alloc();
- ga_grow(&blob->bv_ga, n2 - n1 + 1);
- blob->bv_ga.ga_len = n2 - n1 + 1;
- for (long i = n1; i <= n2; i++) {
- tv_blob_set(blob, i - n1, tv_blob_get(rettv->vval.v_blob, i));
- }
- tv_clear(rettv);
- tv_blob_set_ret(rettv, blob);
+ n1 = 0;
}
+ }
+ if (n2 < 0) {
+ n2 = len + n2;
+ } else if (n2 >= len) {
+ n2 = len - 1;
+ }
+ if (n1 >= len || n2 < 0 || n1 > n2) {
+ tv_clear(rettv);
+ rettv->v_type = VAR_BLOB;
+ rettv->vval.v_blob = NULL;
} else {
- // The resulting variable is a byte value.
- // If the index is too big or negative that is an error.
- if (n1 < 0) {
- n1 = len + n1;
- }
- if (n1 < len && n1 >= 0) {
- const int v = (int)tv_blob_get(rettv->vval.v_blob, n1);
- tv_clear(rettv);
- rettv->v_type = VAR_NUMBER;
- rettv->vval.v_number = v;
- } else {
- EMSGN(_(e_blobidx), n1);
+ blob_T *const blob = tv_blob_alloc();
+ ga_grow(&blob->bv_ga, n2 - n1 + 1);
+ blob->bv_ga.ga_len = n2 - n1 + 1;
+ for (long i = n1; i <= n2; i++) {
+ tv_blob_set(blob, i - n1, tv_blob_get(rettv->vval.v_blob, i));
}
+ tv_clear(rettv);
+ tv_blob_set_ret(rettv, blob);
}
- break;
- }
- case VAR_LIST: {
- len = tv_list_len(rettv->vval.v_list);
+ } else {
+ // The resulting variable is a byte value.
+ // If the index is too big or negative that is an error.
if (n1 < 0) {
n1 = len + n1;
}
- if (!empty1 && (n1 < 0 || n1 >= len)) {
- // For a range we allow invalid values and return an empty
- // list. A list index out of range is an error.
- if (!range) {
- if (verbose) {
- EMSGN(_(e_listidx), n1);
- }
- return FAIL;
- }
- n1 = len;
- }
- if (range) {
- list_T *l;
- listitem_T *item;
-
- if (n2 < 0) {
- n2 = len + n2;
- } else if (n2 >= len) {
- n2 = len - 1;
- }
- if (!empty2 && (n2 < 0 || n2 + 1 < n1)) {
- n2 = -1;
- }
- l = tv_list_alloc(n2 - n1 + 1);
- item = tv_list_find(rettv->vval.v_list, n1);
- while (n1++ <= n2) {
- tv_list_append_tv(l, TV_LIST_ITEM_TV(item));
- item = TV_LIST_ITEM_NEXT(rettv->vval.v_list, item);
- }
+ if (n1 < len && n1 >= 0) {
+ const int v = (int)tv_blob_get(rettv->vval.v_blob, n1);
tv_clear(rettv);
- tv_list_set_ret(rettv, l);
+ rettv->v_type = VAR_NUMBER;
+ rettv->vval.v_number = v;
} else {
- tv_copy(TV_LIST_ITEM_TV(tv_list_find(rettv->vval.v_list, n1)), &var1);
- tv_clear(rettv);
- *rettv = var1;
+ EMSGN(_(e_blobidx), n1);
}
- break;
}
- case VAR_DICT: {
- if (range) {
+ break;
+ case VAR_LIST:
+ len = tv_list_len(rettv->vval.v_list);
+ if (n1 < 0) {
+ n1 = len + n1;
+ }
+ if (!empty1 && (n1 < 0 || n1 >= len)) {
+ // For a range we allow invalid values and return an empty
+ // list. A list index out of range is an error.
+ if (!range) {
if (verbose) {
- EMSG(_(e_dictrange));
- }
- if (len == -1) {
- tv_clear(&var1);
+ EMSGN(_(e_listidx), n1);
}
return FAIL;
}
+ n1 = len;
+ }
+ if (range) {
+ list_T *l;
+ listitem_T *item;
- if (len == -1) {
- key = (char_u *)tv_get_string_chk(&var1);
- if (key == NULL) {
- tv_clear(&var1);
- return FAIL;
- }
+ if (n2 < 0) {
+ n2 = len + n2;
+ } else if (n2 >= len) {
+ n2 = len - 1;
}
-
- dictitem_T *const item = tv_dict_find(rettv->vval.v_dict,
- (const char *)key, len);
-
- if (item == NULL && verbose) {
- emsgf(_(e_dictkey), key);
+ if (!empty2 && (n2 < 0 || n2 + 1 < n1)) {
+ n2 = -1;
+ }
+ l = tv_list_alloc(n2 - n1 + 1);
+ item = tv_list_find(rettv->vval.v_list, n1);
+ while (n1++ <= n2) {
+ tv_list_append_tv(l, TV_LIST_ITEM_TV(item));
+ item = TV_LIST_ITEM_NEXT(rettv->vval.v_list, item);
+ }
+ tv_clear(rettv);
+ tv_list_set_ret(rettv, l);
+ } else {
+ tv_copy(TV_LIST_ITEM_TV(tv_list_find(rettv->vval.v_list, n1)), &var1);
+ tv_clear(rettv);
+ *rettv = var1;
+ }
+ break;
+ case VAR_DICT: {
+ if (range) {
+ if (verbose) {
+ EMSG(_(e_dictrange));
}
if (len == -1) {
tv_clear(&var1);
}
- if (item == NULL || tv_is_luafunc(&item->di_tv)) {
+ return FAIL;
+ }
+
+ if (len == -1) {
+ key = (char_u *)tv_get_string_chk(&var1);
+ if (key == NULL) {
+ tv_clear(&var1);
return FAIL;
}
+ }
- tv_copy(&item->di_tv, &var1);
- tv_clear(rettv);
- *rettv = var1;
- break;
+ dictitem_T *const item = tv_dict_find(rettv->vval.v_dict,
+ (const char *)key, len);
+
+ if (item == NULL && verbose) {
+ emsgf(_(e_dictkey), key);
+ }
+ if (len == -1) {
+ tv_clear(&var1);
}
- case VAR_BOOL:
- case VAR_SPECIAL:
- case VAR_FUNC:
- case VAR_FLOAT:
- case VAR_PARTIAL:
- case VAR_UNKNOWN: {
- break; // Not evaluating, skipping over subscript
+ if (item == NULL || tv_is_luafunc(&item->di_tv)) {
+ return FAIL;
}
+
+ tv_copy(&item->di_tv, &var1);
+ tv_clear(rettv);
+ *rettv = var1;
+ break;
+ }
+ case VAR_BOOL:
+ case VAR_SPECIAL:
+ case VAR_FUNC:
+ case VAR_FLOAT:
+ case VAR_PARTIAL:
+ case VAR_UNKNOWN:
+ break; // Not evaluating, skipping over subscript
}
}
@@ -4773,12 +4787,11 @@ eval_index(
/// @param[in] evaluate If not true, rettv is not populated.
///
/// @return OK or FAIL.
-int get_option_tv(const char **const arg, typval_T *const rettv,
- const bool evaluate)
+int get_option_tv(const char **const arg, typval_T *const rettv, const bool evaluate)
FUNC_ATTR_NONNULL_ARG(1)
{
long numval;
- char_u *stringval;
+ char_u *stringval;
int opt_type;
int c;
bool working = (**arg == '+'); // has("+option")
@@ -4809,7 +4822,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv,
EMSG2(_("E113: Unknown option: %s"), *arg);
}
ret = FAIL;
- } else if (rettv != NULL) {
+ } else if (rettv != NULL) {
if (opt_type == -2) { // hidden string option
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
@@ -4823,8 +4836,9 @@ int get_option_tv(const char **const arg, typval_T *const rettv,
rettv->v_type = VAR_STRING;
rettv->vval.v_string = stringval;
}
- } else if (working && (opt_type == -2 || opt_type == -1))
+ } else if (working && (opt_type == -2 || opt_type == -1)) {
ret = FAIL;
+ }
*option_end = c; // put back for error messages
*arg = option_end;
@@ -4838,7 +4852,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv,
*/
static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
{
- char_u *p;
+ char_u *p;
unsigned int extra = 0;
/*
@@ -4880,12 +4894,18 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
for (p = *arg + 1; *p != NUL && *p != '"'; ) {
if (*p == '\\') {
switch (*++p) {
- case 'b': *name++ = BS; ++p; break;
- case 'e': *name++ = ESC; ++p; break;
- case 'f': *name++ = FF; ++p; break;
- case 'n': *name++ = NL; ++p; break;
- case 'r': *name++ = CAR; ++p; break;
- case 't': *name++ = TAB; ++p; break;
+ case 'b':
+ *name++ = BS; ++p; break;
+ case 'e':
+ *name++ = ESC; ++p; break;
+ case 'f':
+ *name++ = FF; ++p; break;
+ case 'n':
+ *name++ = NL; ++p; break;
+ case 'r':
+ *name++ = CAR; ++p; break;
+ case 't':
+ *name++ = TAB; ++p; break;
case 'X': // hex: "\x1", "\x12"
case 'x':
@@ -4926,11 +4946,13 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
case '4':
case '5':
case '6':
- case '7': *name = *p++ - '0';
+ case '7':
+ *name = *p++ - '0';
if (*p >= '0' && *p <= '7') {
*name = (*name << 3) + *p++ - '0';
- if (*p >= '0' && *p <= '7')
+ if (*p >= '0' && *p <= '7') {
*name = (*name << 3) + *p++ - '0';
+ }
}
++name;
break;
@@ -4947,12 +4969,13 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
}
FALLTHROUGH;
- default: MB_COPY_CHAR(p, name);
+ default:
+ MB_COPY_CHAR(p, name);
break;
}
- } else
+ } else {
MB_COPY_CHAR(p, name);
-
+ }
}
*name = NUL;
if (*p != NUL) { // just in case
@@ -4969,8 +4992,8 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
*/
static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate)
{
- char_u *p;
- char_u *str;
+ char_u *p;
+ char_u *str;
int reduce = 0;
/*
@@ -4978,8 +5001,9 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate)
*/
for (p = *arg + 1; *p != NUL; MB_PTR_ADV(p)) {
if (*p == '\'') {
- if (p[1] != '\'')
+ if (p[1] != '\'') {
break;
+ }
++reduce;
++p;
}
@@ -5005,8 +5029,9 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate)
for (p = *arg + 1; *p != NUL; ) {
if (*p == '\'') {
- if (p[1] != '\'')
+ if (p[1] != '\'') {
break;
+ }
++p;
}
MB_COPY_CHAR(p, str);
@@ -5059,7 +5084,7 @@ void partial_unref(partial_T *pt)
/// Return OK or FAIL.
static int get_list_tv(char_u **arg, typval_T *rettv, int evaluate)
{
- list_T *l = NULL;
+ list_T *l = NULL;
if (evaluate) {
l = tv_list_alloc(kListLenShouldKnow);
@@ -5103,23 +5128,20 @@ failret:
return OK;
}
-bool func_equal(
- typval_T *tv1,
- typval_T *tv2,
- bool ic // ignore case
-) {
+/// @param ic ignore case
+bool func_equal(typval_T *tv1, typval_T *tv2, bool ic) {
char_u *s1, *s2;
dict_T *d1, *d2;
int a1, a2;
// empty and NULL function name considered the same
s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string
- : partial_name(tv1->vval.v_partial);
+ : partial_name(tv1->vval.v_partial);
if (s1 != NULL && *s1 == NUL) {
s1 = NULL;
}
s2 = tv2->v_type == VAR_FUNC ? tv2->vval.v_string
- : partial_name(tv2->vval.v_partial);
+ : partial_name(tv2->vval.v_partial);
if (s2 != NULL && *s2 == NUL) {
s2 = NULL;
}
@@ -5180,9 +5202,9 @@ int get_copyID(void)
* are no longer used. But for composite items it's possible that it becomes
* unused while the reference count is > 0: When there is a recursive
* reference. Example:
- * :let l = [1, 2, 3]
- * :let d = {9: l}
- * :let l[1] = d
+ * :let l = [1, 2, 3]
+ * :let d = {9: l}
+ * :let l[1] = d
*
* Since this is quite unusual we handle this with garbage collection: every
* once in a while find out which lists and dicts are not referenced from any
@@ -5190,7 +5212,7 @@ int get_copyID(void)
*
* Here is a good reference text about garbage collection (refers to Python
* but it applies to all reference-counting mechanisms):
- * http://python.ca/nas/python/gc/
+ * http://python.ca/nas/python/gc/
*/
/// Do garbage collection for lists and dicts.
@@ -5366,8 +5388,7 @@ bool garbage_collect(bool testing)
// This may call us back recursively.
did_free = free_unref_funccal(copyID, testing) || did_free;
} else if (p_verbose > 0) {
- verb_msg(_(
- "Not enough memory to set references, garbage collection aborted!"));
+ verb_msg(_("Not enough memory to set references, garbage collection aborted!"));
}
#undef ABORTING
return did_free;
@@ -5461,8 +5482,7 @@ bool set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack)
// it is added to ht_stack, if it contains a list it is added to
// list_stack.
HASHTAB_ITER(cur_ht, hi, {
- abort = abort || set_ref_in_item(
- &TV_DICT_HI2DI(hi)->di_tv, copyID, &ht_stack, list_stack);
+ abort = abort || set_ref_in_item(&TV_DICT_HI2DI(hi)->di_tv, copyID, &ht_stack, list_stack);
});
}
@@ -5528,87 +5548,85 @@ bool set_ref_in_list(list_T *l, int copyID, ht_stack_T **ht_stack)
/// @param list_stack Used to add lists to be marked. Can be NULL.
///
/// @returns true if setting references failed somehow.
-bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack,
- list_stack_T **list_stack)
+bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack_T **list_stack)
FUNC_ATTR_WARN_UNUSED_RESULT
{
bool abort = false;
switch (tv->v_type) {
- case VAR_DICT: {
- dict_T *dd = tv->vval.v_dict;
- if (dd != NULL && dd->dv_copyID != copyID) {
- // Didn't see this dict yet.
- dd->dv_copyID = copyID;
- if (ht_stack == NULL) {
- abort = set_ref_in_ht(&dd->dv_hashtab, copyID, list_stack);
- } else {
- ht_stack_T *const newitem = xmalloc(sizeof(ht_stack_T));
- newitem->ht = &dd->dv_hashtab;
- newitem->prev = *ht_stack;
- *ht_stack = newitem;
- }
+ case VAR_DICT: {
+ dict_T *dd = tv->vval.v_dict;
+ if (dd != NULL && dd->dv_copyID != copyID) {
+ // Didn't see this dict yet.
+ dd->dv_copyID = copyID;
+ if (ht_stack == NULL) {
+ abort = set_ref_in_ht(&dd->dv_hashtab, copyID, list_stack);
+ } else {
+ ht_stack_T *const newitem = xmalloc(sizeof(ht_stack_T));
+ newitem->ht = &dd->dv_hashtab;
+ newitem->prev = *ht_stack;
+ *ht_stack = newitem;
+ }
- QUEUE *w = NULL;
- DictWatcher *watcher = NULL;
- QUEUE_FOREACH(w, &dd->watchers, {
+ QUEUE *w = NULL;
+ DictWatcher *watcher = NULL;
+ QUEUE_FOREACH(w, &dd->watchers, {
watcher = tv_dict_watcher_node_data(w);
set_ref_in_callback(&watcher->callback, copyID, ht_stack, list_stack);
})
- }
- break;
}
+ break;
+ }
- case VAR_LIST: {
- list_T *ll = tv->vval.v_list;
- if (ll != NULL && ll->lv_copyID != copyID) {
- // Didn't see this list yet.
- ll->lv_copyID = copyID;
- if (list_stack == NULL) {
- abort = set_ref_in_list(ll, copyID, ht_stack);
- } else {
- list_stack_T *const newitem = xmalloc(sizeof(list_stack_T));
- newitem->list = ll;
- newitem->prev = *list_stack;
- *list_stack = newitem;
- }
+ case VAR_LIST: {
+ list_T *ll = tv->vval.v_list;
+ if (ll != NULL && ll->lv_copyID != copyID) {
+ // Didn't see this list yet.
+ ll->lv_copyID = copyID;
+ if (list_stack == NULL) {
+ abort = set_ref_in_list(ll, copyID, ht_stack);
+ } else {
+ list_stack_T *const newitem = xmalloc(sizeof(list_stack_T));
+ newitem->list = ll;
+ newitem->prev = *list_stack;
+ *list_stack = newitem;
}
- break;
}
+ break;
+ }
- case VAR_PARTIAL: {
- partial_T *pt = tv->vval.v_partial;
+ case VAR_PARTIAL: {
+ partial_T *pt = tv->vval.v_partial;
- // 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);
- if (pt->pt_dict != NULL) {
- typval_T dtv;
+ // 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);
+ if (pt->pt_dict != NULL) {
+ typval_T dtv;
- dtv.v_type = VAR_DICT;
- dtv.vval.v_dict = pt->pt_dict;
- abort = abort || set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
- }
+ dtv.v_type = VAR_DICT;
+ dtv.vval.v_dict = pt->pt_dict;
+ abort = abort || set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
+ }
- for (int i = 0; i < pt->pt_argc; i++) {
- abort = abort || set_ref_in_item(&pt->pt_argv[i], copyID,
- ht_stack, list_stack);
- }
+ for (int i = 0; i < pt->pt_argc; i++) {
+ abort = abort || set_ref_in_item(&pt->pt_argv[i], copyID,
+ ht_stack, list_stack);
}
- break;
- }
- case VAR_FUNC:
- abort = set_ref_in_func(tv->vval.v_string, NULL, copyID);
- break;
- case VAR_UNKNOWN:
- case VAR_BOOL:
- case VAR_SPECIAL:
- case VAR_FLOAT:
- case VAR_NUMBER:
- case VAR_STRING:
- case VAR_BLOB: {
- break;
}
+ break;
+ }
+ case VAR_FUNC:
+ abort = set_ref_in_func(tv->vval.v_string, NULL, copyID);
+ break;
+ case VAR_UNKNOWN:
+ case VAR_BOOL:
+ case VAR_SPECIAL:
+ case VAR_FLOAT:
+ case VAR_NUMBER:
+ case VAR_STRING:
+ case VAR_BLOB:
+ break;
}
return abort;
}
@@ -5684,15 +5702,14 @@ static int get_literal_key(char_u **arg, typval_T *tv)
// Allocate a variable for a Dictionary and fill it from "*arg".
// "literal" is true for *{key: val}
// Return OK or FAIL. Returns NOTDONE for {expr}.
-static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate,
- bool literal)
+static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, bool literal)
{
- dict_T *d = NULL;
+ dict_T *d = NULL;
typval_T tvkey;
typval_T tv;
- char_u *key = NULL;
- dictitem_T *item;
- char_u *start = skipwhite(*arg + 1);
+ char_u *key = NULL;
+ dictitem_T *item;
+ char_u *start = skipwhite(*arg + 1);
char buf[NUMBUFLEN];
/*
@@ -5762,8 +5779,9 @@ static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate,
}
tv_clear(&tvkey);
- if (**arg == '}')
+ if (**arg == '}') {
break;
+ }
if (**arg != ',') {
EMSG2(_("E722: Missing comma in Dictionary: %s"), *arg);
goto failret;
@@ -5816,7 +5834,7 @@ size_t string2float(const char *const text, float_T *const ret_value)
return 3;
}
*ret_value = strtod(text, &s);
- return (size_t) (s - text);
+ return (size_t)(s - text);
}
/// Get the value of an environment variable.
@@ -5863,8 +5881,7 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate)
}
/// Get the argument list for a given window
-void get_arglist_as_rettv(aentry_T *arglist, int argcount,
- typval_T *rettv)
+void get_arglist_as_rettv(aentry_T *arglist, int argcount, typval_T *rettv)
{
tv_list_alloc_ret(rettv, argcount);
if (arglist != NULL) {
@@ -5909,21 +5926,28 @@ static void ga_concat_esc(garray_T *gap, const char_u *p, int clen)
ga_concat(gap, buf);
} else {
switch (*p) {
- case BS: ga_concat(gap, (char_u *)"\\b"); break;
- case ESC: ga_concat(gap, (char_u *)"\\e"); break;
- case FF: ga_concat(gap, (char_u *)"\\f"); break;
- case NL: ga_concat(gap, (char_u *)"\\n"); break;
- case TAB: ga_concat(gap, (char_u *)"\\t"); break;
- case CAR: ga_concat(gap, (char_u *)"\\r"); break;
- case '\\': ga_concat(gap, (char_u *)"\\\\"); break;
- default:
- if (*p < ' ') {
- vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p);
- ga_concat(gap, buf);
- } else {
- ga_append(gap, *p);
- }
- break;
+ case BS:
+ ga_concat(gap, (char_u *)"\\b"); break;
+ case ESC:
+ ga_concat(gap, (char_u *)"\\e"); break;
+ case FF:
+ ga_concat(gap, (char_u *)"\\f"); break;
+ case NL:
+ ga_concat(gap, (char_u *)"\\n"); break;
+ case TAB:
+ ga_concat(gap, (char_u *)"\\t"); break;
+ case CAR:
+ ga_concat(gap, (char_u *)"\\r"); break;
+ case '\\':
+ ga_concat(gap, (char_u *)"\\\\"); break;
+ default:
+ if (*p < ' ') {
+ vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p);
+ ga_concat(gap, buf);
+ } else {
+ ga_append(gap, *p);
+ }
+ break;
}
}
}
@@ -5964,8 +5988,7 @@ static void ga_concat_shorten_esc(garray_T *gap, const char_u *str)
}
// Fill "gap" with information about an assert error.
-void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv,
- char_u *exp_str, typval_T *exp_tv,
+void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_str, typval_T *exp_tv,
typval_T *got_tv, assert_type_T atype)
{
char_u *tofree;
@@ -6231,8 +6254,7 @@ int assert_exception(typval_T *argvars)
return 0;
}
-static void assert_append_cmd_or_arg(garray_T *gap, typval_T *argvars,
- const char *cmd)
+static void assert_append_cmd_or_arg(garray_T *gap, typval_T *argvars, const char *cmd)
FUNC_ATTR_NONNULL_ALL
{
if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) {
@@ -6361,12 +6383,12 @@ win_T * find_win_by_nr_or_id(typval_T *vp)
*/
void filter_map(typval_T *argvars, typval_T *rettv, int map)
{
- typval_T *expr;
- list_T *l = NULL;
- dictitem_T *di;
- hashtab_T *ht;
- hashitem_T *hi;
- dict_T *d = NULL;
+ typval_T *expr;
+ list_T *l = NULL;
+ dictitem_T *di;
+ hashtab_T *ht;
+ hashitem_T *hi;
+ dict_T *d = NULL;
typval_T save_val;
typval_T save_key;
blob_T *b = NULL;
@@ -6543,11 +6565,10 @@ theend:
return retval;
}
-void common_function(typval_T *argvars, typval_T *rettv,
- bool is_funcref, FunPtr fptr)
+void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr fptr)
{
- char_u *s;
- char_u *name;
+ char_u *s;
+ char_u *name;
bool use_string = false;
partial_T *arg_pt = NULL;
char_u *trans_name = NULL;
@@ -6584,7 +6605,7 @@ void common_function(typval_T *argvars, typval_T *rettv,
// Don't check an autoload name for existence here.
} else if (trans_name != NULL
&& (is_funcref ? find_func(trans_name) == NULL
- : !translated_function_exists((const char *)trans_name))) {
+ : !translated_function_exists((const char *)trans_name))) {
emsgf(_("E700: Unknown function: %s"), s);
} else {
int dict_idx = 0;
@@ -6760,8 +6781,7 @@ dict_T *get_buffer_info(buf_T *buf)
/// be NULL, in this case "$" results in zero return.
///
/// @return Line number or 0 in case of error.
-linenr_T tv_get_lnum_buf(const typval_T *const tv,
- const buf_T *const buf)
+linenr_T tv_get_lnum_buf(const typval_T *const tv, const buf_T *const buf)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT
{
if (tv->v_type == VAR_STRING
@@ -6773,8 +6793,7 @@ linenr_T tv_get_lnum_buf(const typval_T *const tv,
return tv_get_number_chk(tv, NULL);
}
-void get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg,
- typval_T *rettv)
+void get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg, typval_T *rettv)
{
if (what_arg->v_type == VAR_UNKNOWN) {
tv_list_alloc_ret(rettv, kListLenMayKnow);
@@ -6845,12 +6864,10 @@ dict_T *get_win_info(win_T *wp, int16_t tpnr, int16_t winnr)
return dict;
}
-// Find window specified by "vp" in tabpage "tp".
-win_T *
-find_win_by_nr(
- typval_T *vp,
- tabpage_T *tp // NULL for current tab page
-)
+/// Find window specified by "vp" in tabpage "tp".
+///
+/// @param tp NULL for current tab page
+win_T *find_win_by_nr(typval_T *vp, tabpage_T *tp)
{
int nr = (int)tv_get_number_chk(vp, NULL);
@@ -6864,7 +6881,7 @@ find_win_by_nr(
// This method accepts NULL as an alias for curtab.
if (tp == NULL) {
- tp = curtab;
+ tp = curtab;
}
FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
@@ -6905,15 +6922,10 @@ win_T *find_tabwin(typval_T *wvp, typval_T *tvp)
return wp;
}
-/*
- * getwinvar() and gettabwinvar()
- */
-void
-getwinvar(
- typval_T *argvars,
- typval_T *rettv,
- int off // 1 for gettabwinvar()
-)
+/// getwinvar() and gettabwinvar()
+///
+/// @param off 1 for gettabwinvar()
+void getwinvar(typval_T *argvars, typval_T *rettv, int off)
{
win_T *win, *oldcurwin;
dictitem_T *v;
@@ -6984,9 +6996,7 @@ getwinvar(
* prompt. The third argument to f_inputdialog() specifies the value to return
* when the user cancels the prompt.
*/
-void get_user_input(const typval_T *const argvars,
- typval_T *const rettv,
- const bool inputdialog,
+void get_user_input(const typval_T *const argvars, typval_T *const rettv, const bool inputdialog,
const bool secret)
FUNC_ATTR_NONNULL_ALL
{
@@ -7121,8 +7131,7 @@ void get_user_input(const typval_T *const argvars,
/// a dictionary, will give an error if not.
/// @param[out] rettv Location where result will be saved.
/// @param[in] what What to save in rettv.
-void dict_list(typval_T *const tv, typval_T *const rettv,
- const DictListType what)
+void dict_list(typval_T *const tv, typval_T *const rettv, const DictListType what)
{
if (tv->v_type != VAR_DICT) {
EMSG(_(e_dictreq));
@@ -7138,32 +7147,30 @@ void dict_list(typval_T *const tv, typval_T *const rettv,
typval_T tv_item = { .v_lock = VAR_UNLOCKED };
switch (what) {
- case kDictListKeys: {
- tv_item.v_type = VAR_STRING;
- tv_item.vval.v_string = vim_strsave(di->di_key);
- break;
- }
- case kDictListValues: {
- tv_copy(&di->di_tv, &tv_item);
- break;
- }
- case kDictListItems: {
- // items()
- list_T *const sub_l = tv_list_alloc(2);
- tv_item.v_type = VAR_LIST;
- tv_item.vval.v_list = sub_l;
- tv_list_ref(sub_l);
-
- tv_list_append_owned_tv(sub_l, (typval_T) {
+ case kDictListKeys:
+ tv_item.v_type = VAR_STRING;
+ tv_item.vval.v_string = vim_strsave(di->di_key);
+ break;
+ case kDictListValues:
+ tv_copy(&di->di_tv, &tv_item);
+ break;
+ case kDictListItems: {
+ // items()
+ list_T *const sub_l = tv_list_alloc(2);
+ tv_item.v_type = VAR_LIST;
+ tv_item.vval.v_list = sub_l;
+ tv_list_ref(sub_l);
+
+ tv_list_append_owned_tv(sub_l, (typval_T) {
.v_type = VAR_STRING,
.v_lock = VAR_UNLOCKED,
.vval.v_string = (char_u *)xstrdup((const char *)di->di_key),
});
- tv_list_append_tv(sub_l, &di->di_tv);
+ tv_list_append_tv(sub_l, &di->di_tv);
- break;
- }
+ break;
+ }
}
tv_list_append_owned_tv(rettv->vval.v_list, tv_item);
@@ -7244,9 +7251,7 @@ char **tv_to_argv(typval_T *cmd_tv, const char **cmd, bool *executable)
/// @param mp The maphash that contains the mapping information
/// @param buffer_value The "buffer" value
/// @param compatible True for compatible with old maparg() dict
-void mapblock_fill_dict(dict_T *const dict,
- const mapblock_T *const mp,
- long buffer_value,
+void mapblock_fill_dict(dict_T *const dict, const mapblock_T *const mp, long buffer_value,
bool compatible)
FUNC_ATTR_NONNULL_ALL
{
@@ -7284,8 +7289,7 @@ void mapblock_fill_dict(dict_T *const dict,
tv_dict_add_allocated_str(dict, S_LEN("mode"), mapmode);
}
-int matchadd_dict_arg(typval_T *tv, const char **conceal_char,
- win_T **win)
+int matchadd_dict_arg(typval_T *tv, const char **conceal_char, win_T **win)
{
dictitem_T *di;
@@ -7333,18 +7337,18 @@ void screenchar_adjust_grid(ScreenGrid **grid, int *row, int *col)
}
/// Set line or list of lines in buffer "buf".
-void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append,
- const typval_T *lines, typval_T *rettv)
+void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T *lines,
+ typval_T *rettv)
FUNC_ATTR_NONNULL_ARG(4, 5)
{
linenr_T lnum = lnum_arg + (append ? 1 : 0);
const char *line = NULL;
- list_T *l = NULL;
- listitem_T *li = NULL;
+ list_T *l = NULL;
+ listitem_T *li = NULL;
long added = 0;
linenr_T append_lnum;
- buf_T *curbuf_save = NULL;
- win_T *curwin_save = NULL;
+ buf_T *curbuf_save = NULL;
+ win_T *curwin_save = NULL;
const bool is_curbuf = buf == curbuf;
// When using the current buffer ml_mfp will be set if needed. Useful when
@@ -7444,8 +7448,8 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append,
}
if (!is_curbuf) {
- curbuf = curbuf_save;
- curwin = curwin_save;
+ curbuf = curbuf_save;
+ curwin = curwin_save;
}
}
@@ -7470,8 +7474,8 @@ void setwinvar(typval_T *argvars, typval_T *rettv, int off)
typval_T *varp = &argvars[off + 2];
if (win != NULL && varname != NULL && varp != NULL) {
- win_T *save_curwin;
- tabpage_T *save_curtab;
+ win_T *save_curwin;
+ tabpage_T *save_curtab;
bool need_switch_win = tp != curtab || win != curwin;
if (!need_switch_win
|| switch_win(&save_curwin, &save_curtab, win, tp, true) == OK) {
@@ -7539,8 +7543,7 @@ static list_T *string_to_list(const char *str, size_t len, const bool keepempty)
}
// os_system wrapper. Handles 'verbose', :profile, and v:shell_error.
-void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv,
- bool retlist)
+void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist)
{
proftime_T wait_time;
bool profiling = do_profiling == PROF_YES;
@@ -7595,14 +7598,14 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv,
xfree(input);
- set_vim_var_nr(VV_SHELL_ERROR, (long) status);
+ set_vim_var_nr(VV_SHELL_ERROR, (long)status);
if (res == NULL) {
if (retlist) {
// return an empty list when there's no output
tv_list_alloc_ret(rettv, 0);
} else {
- rettv->vval.v_string = (char_u *) xstrdup("");
+ rettv->vval.v_string = (char_u *)xstrdup("");
}
return;
}
@@ -7634,7 +7637,7 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv,
*d = NUL;
#endif
- rettv->vval.v_string = (char_u *) res;
+ rettv->vval.v_string = (char_u *)res;
}
}
@@ -7687,29 +7690,29 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg)
return true;
}
-bool callback_call(Callback *const callback, const int argcount_in,
- typval_T *const argvars_in, typval_T *const rettv)
+bool callback_call(Callback *const callback, const int argcount_in, typval_T *const argvars_in,
+ typval_T *const rettv)
FUNC_ATTR_NONNULL_ALL
{
partial_T *partial;
char_u *name;
switch (callback->type) {
- case kCallbackFuncref:
- name = callback->data.funcref;
- partial = NULL;
- break;
+ case kCallbackFuncref:
+ name = callback->data.funcref;
+ partial = NULL;
+ break;
- case kCallbackPartial:
- partial = callback->data.partial;
- name = partial_name(partial);
- break;
+ case kCallbackPartial:
+ partial = callback->data.partial;
+ name = partial_name(partial);
+ break;
- case kCallbackNone:
- return false;
- break;
+ case kCallbackNone:
+ return false;
+ break;
- default:
- abort();
+ default:
+ abort();
}
funcexe_T funcexe = FUNCEXE_INIT;
@@ -7720,31 +7723,29 @@ bool callback_call(Callback *const callback, const int argcount_in,
return call_func(name, -1, rettv, argcount_in, argvars_in, &funcexe);
}
-static bool set_ref_in_callback(Callback *callback, int copyID,
- ht_stack_T **ht_stack,
+static bool set_ref_in_callback(Callback *callback, int copyID, ht_stack_T **ht_stack,
list_stack_T **list_stack)
{
typval_T tv;
switch (callback->type) {
- case kCallbackFuncref:
- case kCallbackNone:
- break;
+ case kCallbackFuncref:
+ case kCallbackNone:
+ break;
- case kCallbackPartial:
- tv.v_type = VAR_PARTIAL;
- tv.vval.v_partial = callback->data.partial;
- return set_ref_in_item(&tv, copyID, ht_stack, list_stack);
- break;
+ case kCallbackPartial:
+ tv.v_type = VAR_PARTIAL;
+ tv.vval.v_partial = callback->data.partial;
+ return set_ref_in_item(&tv, copyID, ht_stack, list_stack);
+ break;
- default:
- abort();
+ default:
+ abort();
}
return false;
}
-static bool set_ref_in_callback_reader(CallbackReader *reader, int copyID,
- ht_stack_T **ht_stack,
+static bool set_ref_in_callback_reader(CallbackReader *reader, int copyID, ht_stack_T **ht_stack,
list_stack_T **list_stack)
{
if (set_ref_in_callback(&reader->cb, copyID, ht_stack, list_stack)) {
@@ -7762,7 +7763,7 @@ static bool set_ref_in_callback_reader(CallbackReader *reader, int copyID,
timer_T *find_timer_by_nr(varnumber_T xx)
{
- return pmap_get(uint64_t)(&timers, xx);
+ return pmap_get(uint64_t)(&timers, xx);
}
void add_timer_info(typval_T *rettv, timer_T *timer)
@@ -7851,9 +7852,7 @@ void timer_due_cb(TimeWatcher *tw, void *data)
timer_decref(timer);
}
-uint64_t timer_start(const long timeout,
- const int repeat_count,
- const Callback *const callback)
+uint64_t timer_start(const long timeout, const int repeat_count, const Callback *const callback)
{
timer_T *timer = xmalloc(sizeof *timer);
timer->refcount = 1;
@@ -7924,8 +7923,7 @@ void timer_teardown(void)
/// @param[in] binary Whether to write in binary mode.
///
/// @return true in case of success, false otherwise.
-bool write_list(FileDescriptor *const fp, const list_T *const list,
- const bool binary)
+bool write_list(FileDescriptor *const fp, const list_T *const list, const bool binary)
FUNC_ATTR_NONNULL_ARG(1)
{
int error = 0;
@@ -8123,16 +8121,15 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl)
/// @param[out] ret_fnum Set to fnum for marks.
///
/// @return Pointer to position or NULL in case of error (e.g. invalid type).
-pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum,
- int *const ret_fnum)
+pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret_fnum)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
static pos_T pos;
- pos_T *pp;
+ pos_T *pp;
// Argument can be [lnum, col, coladd].
if (tv->v_type == VAR_LIST) {
- list_T *l;
+ list_T *l;
int len;
bool error = false;
listitem_T *li;
@@ -8350,10 +8347,7 @@ int get_id_len(const char **const arg)
* If the name contains 'magic' {}'s, expand them and return the
* expanded name in an allocated string via 'alias' - caller must free.
*/
-int get_name_len(const char **const arg,
- char **alias,
- bool evaluate,
- bool verbose)
+int get_name_len(const char **const arg, char **alias, bool evaluate, bool verbose)
{
int len;
@@ -8372,8 +8366,8 @@ int get_name_len(const char **const arg,
}
// Find the end of the name; check for {} construction.
- char_u *expr_start;
- char_u *expr_end;
+ char_u *expr_start;
+ char_u *expr_end;
const char *p = (const char *)find_name_end((char_u *)(*arg),
(const char_u **)&expr_start,
(const char_u **)&expr_end,
@@ -8415,8 +8409,8 @@ int get_name_len(const char **const arg,
// "flags" can have FNE_INCL_BR and FNE_CHECK_START.
// Return a pointer to just after the name. Equal to "arg" if there is no
// valid name.
-const char_u *find_name_end(const char_u *arg, const char_u **expr_start,
- const char_u **expr_end, int flags)
+const char_u *find_name_end(const char_u *arg, const char_u **expr_start, const char_u **expr_end,
+ int flags)
{
int mb_nest = 0;
int br_nest = 0;
@@ -8497,24 +8491,25 @@ const char_u *find_name_end(const char_u *arg, const char_u **expr_start,
* Note that this can call itself recursively, to deal with
* constructs like foo{bar}{baz}{bam}
* The four pointer arguments point to "foo{expre}ss{ion}bar"
- * "in_start" ^
- * "expr_start" ^
- * "expr_end" ^
- * "in_end" ^
+ * "in_start" ^
+ * "expr_start" ^
+ * "expr_end" ^
+ * "in_end" ^
*
* Returns a new allocated string, which the caller must free.
* Returns NULL for failure.
*/
-static char_u *make_expanded_name(const char_u *in_start, char_u *expr_start,
- char_u *expr_end, char_u *in_end)
+static char_u *make_expanded_name(const char_u *in_start, char_u *expr_start, char_u *expr_end,
+ char_u *in_end)
{
char_u c1;
- char_u *retval = NULL;
- char_u *temp_result;
- char_u *nextcmd = NULL;
+ char_u *retval = NULL;
+ char_u *temp_result;
+ char_u *nextcmd = NULL;
- if (expr_end == NULL || in_end == NULL)
+ if (expr_end == NULL || in_end == NULL) {
return NULL;
+ }
*expr_start = NUL;
*expr_end = NUL;
c1 = *in_end;
@@ -8541,7 +8536,7 @@ static char_u *make_expanded_name(const char_u *in_start, char_u *expr_start,
if (expr_start != NULL) {
// Further expansion!
temp_result = make_expanded_name(retval, expr_start,
- expr_end, temp_result);
+ expr_end, temp_result);
xfree(retval);
retval = temp_result;
}
@@ -8617,8 +8612,9 @@ void set_vim_var_char(int c)
*/
void set_vcount(long count, long count1, int set_prevcount)
{
- if (set_prevcount)
+ if (set_prevcount) {
vimvars[VV_PREVCOUNT].vv_nr = vimvars[VV_COUNT].vv_nr;
+ }
vimvars[VV_COUNT].vv_nr = count;
vimvars[VV_COUNT1].vv_nr = count1;
}
@@ -8662,17 +8658,16 @@ void set_vim_var_special(const VimVarIndex idx, const SpecialVarValue val)
/// @param[in] val Value to set to. Will be copied.
/// @param[in] len Length of that value or -1 in which case strlen() will be
/// used.
-void set_vim_var_string(const VimVarIndex idx, const char *const val,
- const ptrdiff_t len)
+void set_vim_var_string(const VimVarIndex idx, const char *const val, const ptrdiff_t len)
{
tv_clear(&vimvars[idx].vv_di.di_tv);
vimvars[idx].vv_type = VAR_STRING;
if (val == NULL) {
vimvars[idx].vv_str = NULL;
} else if (len == -1) {
- vimvars[idx].vv_str = (char_u *) xstrdup(val);
+ vimvars[idx].vv_str = (char_u *)xstrdup(val);
} else {
- vimvars[idx].vv_str = (char_u *) xstrndup(val, (size_t) len);
+ vimvars[idx].vv_str = (char_u *)xstrndup(val, (size_t)len);
}
}
@@ -8748,8 +8743,9 @@ void set_reg_var(int c)
*/
char_u *v_exception(char_u *oldval)
{
- if (oldval == NULL)
+ if (oldval == NULL) {
return vimvars[VV_EXCEPTION].vv_str;
+ }
vimvars[VV_EXCEPTION].vv_str = oldval;
return NULL;
@@ -8763,8 +8759,9 @@ char_u *v_exception(char_u *oldval)
*/
char_u *v_throwpoint(char_u *oldval)
{
- if (oldval == NULL)
+ if (oldval == NULL) {
return vimvars[VV_THROWPOINT].vv_str;
+ }
vimvars[VV_THROWPOINT].vv_str = oldval;
return NULL;
@@ -8786,13 +8783,15 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
}
size_t len = 0;
- if (eap->force_bin == FORCE_BIN)
+ if (eap->force_bin == FORCE_BIN) {
len = 6;
- else if (eap->force_bin == FORCE_NOBIN)
+ } else if (eap->force_bin == FORCE_NOBIN) {
len = 8;
+ }
- if (eap->read_edit)
+ if (eap->read_edit) {
len += 7;
+ }
if (eap->force_ff != 0) {
len += 10; // " ++ff=unix"
@@ -8807,15 +8806,17 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
const size_t newval_len = len + 1;
char_u *newval = xmalloc(newval_len);
- if (eap->force_bin == FORCE_BIN)
+ if (eap->force_bin == FORCE_BIN) {
sprintf((char *)newval, " ++bin");
- else if (eap->force_bin == FORCE_NOBIN)
+ } else if (eap->force_bin == FORCE_NOBIN) {
sprintf((char *)newval, " ++nobin");
- else
+ } else {
*newval = NUL;
+ }
- if (eap->read_edit)
+ if (eap->read_edit) {
STRCAT(newval, " ++edit");
+ }
if (eap->force_ff != 0) {
snprintf((char *)newval + STRLEN(newval), newval_len, " ++ff=%s",
@@ -8838,20 +8839,20 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
return oldval;
}
-// Get the value of internal variable "name".
-// Return OK or FAIL. If OK is returned "rettv" must be cleared.
-int get_var_tv(
- const char *name,
- int len, // length of "name"
- typval_T *rettv, // NULL when only checking existence
- dictitem_T **dip, // non-NULL when typval's dict item is needed
- int verbose, // may give error message
- int no_autoload // do not use script autoloading
-)
+/// Get the value of internal variable "name".
+/// Return OK or FAIL. If OK is returned "rettv" must be cleared.
+///
+/// @param len length of "name"
+/// @param rettv NULL when only checking existence
+/// @param dip non-NULL when typval's dict item is needed
+/// @param verbose may give error message
+/// @param no_autoload do not use script autoloading
+int get_var_tv(const char *name, int len, typval_T *rettv, dictitem_T **dip, int verbose,
+ int no_autoload)
{
int ret = OK;
- typval_T *tv = NULL;
- dictitem_T *v;
+ typval_T *tv = NULL;
+ dictitem_T *v;
v = find_var(name, (size_t)len, NULL, no_autoload);
if (v != NULL) {
@@ -8934,15 +8935,13 @@ int check_luafunc_name(const char *const str, const bool paren)
/// - method call: var->method()
///
/// Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len()
-int
-handle_subscript(
- const char **const arg,
- typval_T *rettv,
- int evaluate, // do more than finding the end
- int verbose, // give error messages
- const char_u *const start_leader, // start of '!' and '-' prefixes
- const char_u **const end_leaderp // end of '!' and '-' prefixes
-)
+///
+/// @param evaluate do more than finding the end
+/// @param verbose give error messages
+/// @param start_leader start of '!' and '-' prefixes
+/// @param end_leaderp end of '!' and '-' prefixes
+int handle_subscript(const char **const arg, typval_T *rettv, int evaluate, int verbose,
+ const char_u *const start_leader, const char_u **const end_leaderp)
{
int ret = OK;
dict_T *selfdict = NULL;
@@ -9005,10 +9004,12 @@ handle_subscript(
tv_dict_unref(selfdict);
if (rettv->v_type == VAR_DICT) {
selfdict = rettv->vval.v_dict;
- if (selfdict != NULL)
+ if (selfdict != NULL) {
++selfdict->dv_refcount;
- } else
+ }
+ } else {
selfdict = NULL;
+ }
if (eval_index((char_u **)arg, rettv, evaluate, verbose) == FAIL) {
tv_clear(rettv);
ret = FAIL;
@@ -9041,8 +9042,8 @@ void set_selfdict(typval_T *const rettv, dict_T *const selfdict)
// Careful: "a:0" variables don't have a name.
// When "htp" is not NULL we are writing to the variable, set "htp" to the
// hashtab_T used.
-dictitem_T *find_var(const char *const name, const size_t name_len,
- hashtab_T **htp, int no_autoload)
+dictitem_T *find_var(const char *const name, const size_t name_len, hashtab_T **htp,
+ int no_autoload)
{
const char *varname;
hashtab_T *const ht = find_var_ht(name, name_len, &varname);
@@ -9076,26 +9077,31 @@ dictitem_T *find_var(const char *const name, const size_t name_len,
///
/// @return pointer to the dictionary item with the found variable or NULL if it
/// was not found.
-dictitem_T *find_var_in_ht(hashtab_T *const ht,
- int htname,
- const char *const varname,
- const size_t varname_len,
- int no_autoload)
+dictitem_T *find_var_in_ht(hashtab_T *const ht, int htname, const char *const varname,
+ const size_t varname_len, int no_autoload)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
- hashitem_T *hi;
+ hashitem_T *hi;
if (varname_len == 0) {
// Must be something like "s:", otherwise "ht" would be NULL.
switch (htname) {
- case 's': return (dictitem_T *)&SCRIPT_SV(current_sctx.sc_sid)->sv_var;
- case 'g': return (dictitem_T *)&globvars_var;
- case 'v': return (dictitem_T *)&vimvars_var;
- case 'b': return (dictitem_T *)&curbuf->b_bufvar;
- case 'w': return (dictitem_T *)&curwin->w_winvar;
- case 't': return (dictitem_T *)&curtab->tp_winvar;
- case 'l': return get_funccal_local_var();
- case 'a': return get_funccal_args_var();
+ case 's':
+ return (dictitem_T *)&SCRIPT_SV(current_sctx.sc_sid)->sv_var;
+ case 'g':
+ return (dictitem_T *)&globvars_var;
+ case 'v':
+ return (dictitem_T *)&vimvars_var;
+ case 'b':
+ return (dictitem_T *)&curbuf->b_bufvar;
+ case 'w':
+ return (dictitem_T *)&curwin->w_winvar;
+ case 't':
+ return (dictitem_T *)&curtab->tp_winvar;
+ case 'l':
+ return get_funccal_local_var();
+ case 'a':
+ return get_funccal_args_var();
}
return NULL;
}
@@ -9130,8 +9136,8 @@ dictitem_T *find_var_in_ht(hashtab_T *const ht,
/// @param[out] d Scope dictionary.
///
/// @return Scope hashtab, NULL if name is not valid.
-static hashtab_T *find_var_ht_dict(const char *name, const size_t name_len,
- const char **varname, dict_T **d)
+static hashtab_T *find_var_ht_dict(const char *name, const size_t name_len, const char **varname,
+ dict_T **d)
{
hashitem_T *hi;
funccall_T *funccal = get_funccal();
@@ -9202,8 +9208,7 @@ end:
/// prefix.
///
/// @return Scope hashtab, NULL if name is not valid.
-hashtab_T *find_var_ht(const char *name, const size_t name_len,
- const char **varname)
+hashtab_T *find_var_ht(const char *name, const size_t name_len, const char **varname)
{
dict_T *d;
return find_var_ht_dict(name, name_len, varname, &d);
@@ -9216,7 +9221,7 @@ hashtab_T *find_var_ht(const char *name, const size_t name_len,
*/
char_u *get_var_value(const char *const name)
{
- dictitem_T *v;
+ dictitem_T *v;
v = find_var(name, strlen(name), NULL, false);
if (v == NULL) {
@@ -9231,7 +9236,7 @@ char_u *get_var_value(const char *const name)
*/
void new_script_vars(scid_T id)
{
- hashtab_T *ht;
+ hashtab_T *ht;
scriptvar_T *sv;
ga_grow(&ga_scripts, (int)(id - ga_scripts.ga_len));
@@ -9241,8 +9246,9 @@ void new_script_vars(scid_T id)
* at its init value. Also reset "v_dict", it's always the same. */
for (int i = 1; i <= ga_scripts.ga_len; ++i) {
ht = &SCRIPT_VARS(i);
- if (ht->ht_mask == HT_INIT_SIZE - 1)
+ if (ht->ht_mask == HT_INIT_SIZE - 1) {
ht->ht_array = ht->ht_smallarray;
+ }
sv = SCRIPT_SV(i);
sv->sv_var.di_tv.vval.v_dict = &sv->sv_dict;
}
@@ -9301,8 +9307,8 @@ void vars_clear(hashtab_T *ht)
void vars_clear_ext(hashtab_T *ht, int free_val)
{
int todo;
- hashitem_T *hi;
- dictitem_T *v;
+ hashitem_T *hi;
+ dictitem_T *v;
hash_lock(ht);
todo = (int)ht->ht_used;
@@ -9332,7 +9338,7 @@ void vars_clear_ext(hashtab_T *ht, int free_val)
*/
static void delete_var(hashtab_T *ht, hashitem_T *hi)
{
- dictitem_T *di = TV_DICT_HI2DI(hi);
+ dictitem_T *di = TV_DICT_HI2DI(hi);
hash_remove(ht, hi);
tv_clear(&di->di_tv);
@@ -9353,9 +9359,8 @@ static void list_one_var(dictitem_T *v, const char *prefix, int *first)
/// @param[in] name_len Length of the name. May be -1, in this case strlen()
/// will be used.
/// @param[in,out] first When true clear rest of screen and set to false.
-static void list_one_var_a(const char *prefix, const char *name,
- const ptrdiff_t name_len, const int type,
- const char *string, int *first)
+static void list_one_var_a(const char *prefix, const char *name, const ptrdiff_t name_len,
+ const int type, const char *string, int *first)
{
// don't use msg() or msg_attr() to avoid overwriting "v:statusmsg"
msg_start();
@@ -9371,14 +9376,17 @@ static void list_one_var_a(const char *prefix, const char *name,
msg_putchar('*');
} else if (type == VAR_LIST) {
msg_putchar('[');
- if (*string == '[')
+ if (*string == '[') {
++string;
+ }
} else if (type == VAR_DICT) {
msg_putchar('{');
- if (*string == '{')
+ if (*string == '{') {
++string;
- } else
+ }
+ } else {
msg_putchar(' ');
+ }
msg_outtrans((char_u *)string);
@@ -9400,8 +9408,7 @@ static void list_one_var_a(const char *prefix, const char *name,
/// @param[in] name_len Length of the variable name.
/// @param tv Variable value.
/// @param[in] copy True if value in tv is to be copied.
-void set_var(const char *name, const size_t name_len, typval_T *const tv,
- const bool copy)
+void set_var(const char *name, const size_t name_len, typval_T *const tv, const bool copy)
FUNC_ATTR_NONNULL_ALL
{
set_var_const(name, name_len, tv, copy, false);
@@ -9417,13 +9424,12 @@ void set_var(const char *name, const size_t name_len, typval_T *const tv,
/// @param tv Variable value.
/// @param[in] copy True if value in tv is to be copied.
/// @param[in] is_const True if value in tv is to be locked.
-static void set_var_const(const char *name, const size_t name_len,
- typval_T *const tv, const bool copy,
- const bool is_const)
+static void set_var_const(const char *name, const size_t name_len, typval_T *const tv,
+ const bool copy, const bool is_const)
FUNC_ATTR_NONNULL_ALL
{
- dictitem_T *v;
- hashtab_T *ht;
+ dictitem_T *v;
+ hashtab_T *ht;
dict_T *dict;
const char *varname;
@@ -9567,8 +9573,7 @@ static void set_var_const(const char *name, const size_t name_len,
///
/// @return True if variable is read-only: either always or in sandbox when
/// sandbox is enabled, false otherwise.
-bool var_check_ro(const int flags, const char *name,
- size_t name_len)
+bool var_check_ro(const int flags, const char *name, size_t name_len)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
const char *error_message = NULL;
@@ -9611,8 +9616,7 @@ bool var_check_ro(const int flags, const char *name,
/// gettext.
///
/// @return True if variable is fixed, false otherwise.
-bool var_check_fixed(const int flags, const char *name,
- size_t name_len)
+bool var_check_fixed(const int flags, const char *name, size_t name_len)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
if (flags & DI_FLAGS_FIX) {
@@ -9696,11 +9700,8 @@ bool valid_varname(const char *varname)
/// a copy with (`copy[0] isnot copy[1]`), with non-zero it
/// will emit a copy with (`copy[0] is copy[1]`) like in the
/// original list. Not used when deep is false.
-int var_item_copy(const vimconv_T *const conv,
- typval_T *const from,
- typval_T *const to,
- const bool deep,
- const int copyID)
+int var_item_copy(const vimconv_T *const conv, typval_T *const from, typval_T *const to,
+ const bool deep, const int copyID)
FUNC_ATTR_NONNULL_ARG(2, 3)
{
static int recurse = 0;
@@ -9732,7 +9733,7 @@ int var_item_copy(const vimconv_T *const conv,
from->vval.v_string,
NULL))
== NULL) {
- to->vval.v_string = (char_u *) xstrdup((char *) from->vval.v_string);
+ to->vval.v_string = (char_u *)xstrdup((char *)from->vval.v_string);
}
}
break;
@@ -9780,21 +9781,22 @@ int var_item_copy(const vimconv_T *const conv,
}
/*
- * ":echo expr1 ..." print each argument separated with a space, add a
- * newline at the end.
- * ":echon expr1 ..." print each argument plain.
+ * ":echo expr1 ..." print each argument separated with a space, add a
+ * newline at the end.
+ * ":echon expr1 ..." print each argument plain.
*/
void ex_echo(exarg_T *eap)
{
- char_u *arg = eap->arg;
+ char_u *arg = eap->arg;
typval_T rettv;
bool atstart = true;
bool need_clear = true;
const int did_emsg_before = did_emsg;
const int called_emsg_before = called_emsg;
- if (eap->skip)
+ if (eap->skip) {
++emsg_skip;
+ }
while (*arg != NUL && *arg != '|' && *arg != '\n' && !got_int) {
// If eval1() causes an error message the text from the command may
// still need to be cleared. E.g., "echo 22,44".
@@ -9865,9 +9867,9 @@ void ex_echohl(exarg_T *eap)
}
/*
- * ":execute expr1 ..." execute the result of an expression.
- * ":echomsg expr1 ..." Print a message
- * ":echoerr expr1 ..." Print an error
+ * ":execute expr1 ..." execute the result of an expression.
+ * ":echomsg expr1 ..." Print a message
+ * ":echoerr expr1 ..." Print an error
* Each gets spaces around each argument and a newline at the end for
* echo commands
*/
@@ -9881,8 +9883,9 @@ void ex_execute(exarg_T *eap)
ga_init(&ga, 1, 80);
- if (eap->skip)
+ if (eap->skip) {
++emsg_skip;
+ }
while (*arg != NUL && *arg != '|' && *arg != '\n') {
ret = eval1_emsg(&arg, &rettv, !eap->skip);
if (ret == FAIL) {
@@ -9928,17 +9931,20 @@ void ex_execute(exarg_T *eap)
save_did_emsg = did_emsg;
msg_ext_set_kind("echoerr");
EMSG((char_u *)ga.ga_data);
- if (!force_abort)
+ if (!force_abort) {
did_emsg = save_did_emsg;
- } else if (eap->cmdidx == CMD_execute)
+ }
+ } else if (eap->cmdidx == CMD_execute) {
do_cmdline((char_u *)ga.ga_data,
- eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE);
+ eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE);
+ }
}
ga_clear(&ga);
- if (eap->skip)
+ if (eap->skip) {
--emsg_skip;
+ }
eap->nextcmd = check_nextcmd(arg);
}
@@ -10016,10 +10022,10 @@ void func_do_profile(ufunc_T *fp)
*/
void func_dump_profile(FILE *fd)
{
- hashitem_T *hi;
+ hashitem_T *hi;
int todo;
- ufunc_T *fp;
- ufunc_T **sorttab;
+ ufunc_T *fp;
+ ufunc_T **sorttab;
int st_len = 0;
todo = (int)func_hashtab.ht_used;
@@ -10045,7 +10051,7 @@ void func_dump_profile(FILE *fd)
bool should_free;
const LastSet last_set = (LastSet){
.script_ctx = fp->uf_script_ctx,
- .channel_id = 0,
+ .channel_id = 0,
};
char_u *p = get_scriptname(last_set, &should_free);
fprintf(fd, " Defined: %s:%" PRIdLINENR "\n",
@@ -10065,10 +10071,11 @@ void func_dump_profile(FILE *fd)
fprintf(fd, "count total (s) self (s)\n");
for (int i = 0; i < fp->uf_lines.ga_len; ++i) {
- if (FUNCLINE(fp, i) == NULL)
+ if (FUNCLINE(fp, i) == NULL) {
continue;
+ }
prof_func_line(fd, fp->uf_tml_count[i],
- &fp->uf_tml_total[i], &fp->uf_tml_self[i], TRUE);
+ &fp->uf_tml_total[i], &fp->uf_tml_self[i], TRUE);
fprintf(fd, "%s\n", FUNCLINE(fp, i));
}
fprintf(fd, "\n");
@@ -10078,65 +10085,58 @@ void func_dump_profile(FILE *fd)
if (st_len > 0) {
qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
- prof_total_cmp);
+ prof_total_cmp);
prof_sort_list(fd, sorttab, st_len, "TOTAL", FALSE);
qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
- prof_self_cmp);
+ prof_self_cmp);
prof_sort_list(fd, sorttab, st_len, "SELF", TRUE);
}
xfree(sorttab);
}
-static void
-prof_sort_list(
- FILE *fd,
- ufunc_T **sorttab,
- int st_len,
- char *title,
- int prefer_self // when equal print only self time
-)
+/// @param prefer_self when equal print only self time
+static void prof_sort_list(FILE *fd, ufunc_T **sorttab, int st_len, char *title, int prefer_self)
{
int i;
- ufunc_T *fp;
+ ufunc_T *fp;
fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title);
fprintf(fd, "count total (s) self (s) function\n");
for (i = 0; i < 20 && i < st_len; ++i) {
fp = sorttab[i];
prof_func_line(fd, fp->uf_tm_count, &fp->uf_tm_total, &fp->uf_tm_self,
- prefer_self);
- if (fp->uf_name[0] == K_SPECIAL)
+ prefer_self);
+ if (fp->uf_name[0] == K_SPECIAL) {
fprintf(fd, " <SNR>%s()\n", fp->uf_name + 3);
- else
+ } else {
fprintf(fd, " %s()\n", fp->uf_name);
+ }
}
fprintf(fd, "\n");
}
-/*
- * Print the count and times for one function or function line.
- */
-static void prof_func_line(
- FILE *fd,
- int count,
- proftime_T *total,
- proftime_T *self,
- int prefer_self // when equal print only self time
-)
+/// Print the count and times for one function or function line.
+///
+/// @param prefer_self when equal print only self time
+static void prof_func_line(FILE *fd, int count, proftime_T *total, proftime_T *self,
+ int prefer_self)
{
if (count > 0) {
fprintf(fd, "%5d ", count);
- if (prefer_self && profile_equal(*total, *self))
+ if (prefer_self && profile_equal(*total, *self)) {
fprintf(fd, " ");
- else
+ } else {
fprintf(fd, "%s ", profile_msg(*total));
- if (!prefer_self && profile_equal(*total, *self))
+ }
+ if (!prefer_self && profile_equal(*total, *self)) {
fprintf(fd, " ");
- else
+ } else {
fprintf(fd, "%s ", profile_msg(*self));
- } else
+ }
+ } else {
fprintf(fd, " ");
+ }
}
/*
@@ -10194,8 +10194,7 @@ char *autoload_name(const char *const name, const size_t name_len)
/// @param[in] reload If true, load script again when already loaded.
///
/// @return true if a package was loaded.
-bool script_autoload(const char *const name, const size_t name_len,
- const bool reload)
+bool script_autoload(const char *const name, const size_t name_len, const bool reload)
{
// If there is no '#' after name[0] there is no package name.
const char *p = memchr(name, AUTOLOAD_CHAR, name_len);
@@ -10242,8 +10241,8 @@ bool script_autoload(const char *const name, const size_t name_len,
*/
void func_line_start(void *cookie)
{
- funccall_T *fcp = (funccall_T *)cookie;
- ufunc_T *fp = fcp->func;
+ funccall_T *fcp = (funccall_T *)cookie;
+ ufunc_T *fp = fcp->func;
if (fp->uf_profiling && sourcing_lnum >= 1
&& sourcing_lnum <= fp->uf_lines.ga_len) {
@@ -10264,11 +10263,12 @@ void func_line_start(void *cookie)
*/
void func_line_exec(void *cookie)
{
- funccall_T *fcp = (funccall_T *)cookie;
- ufunc_T *fp = fcp->func;
+ funccall_T *fcp = (funccall_T *)cookie;
+ ufunc_T *fp = fcp->func;
- if (fp->uf_profiling && fp->uf_tml_idx >= 0)
+ if (fp->uf_profiling && fp->uf_tml_idx >= 0) {
fp->uf_tml_execed = TRUE;
+ }
}
/*
@@ -10276,8 +10276,8 @@ void func_line_exec(void *cookie)
*/
void func_line_end(void *cookie)
{
- funccall_T *fcp = (funccall_T *)cookie;
- ufunc_T *fp = fcp->func;
+ funccall_T *fcp = (funccall_T *)cookie;
+ ufunc_T *fp = fcp->func;
if (fp->uf_profiling && fp->uf_tml_idx >= 0) {
if (fp->uf_tml_execed) {
@@ -10288,7 +10288,7 @@ void func_line_end(void *cookie)
profile_add(fp->uf_tml_total[fp->uf_tml_idx], fp->uf_tml_start);
fp->uf_tml_self[fp->uf_tml_idx] =
profile_self(fp->uf_tml_self[fp->uf_tml_idx], fp->uf_tml_start,
- fp->uf_tml_children);
+ fp->uf_tml_children);
}
fp->uf_tml_idx = -1;
}
@@ -10299,10 +10299,11 @@ static var_flavour_T var_flavour(char_u *varname)
char_u *p = varname;
if (ASCII_ISUPPER(*p)) {
- while (*(++p))
+ while (*(++p)) {
if (ASCII_ISLOWER(*p)) {
return VAR_FLAVOUR_SESSION;
}
+ }
return VAR_FLAVOUR_SHADA;
} else {
return VAR_FLAVOUR_DEFAULT;
@@ -10320,26 +10321,26 @@ static var_flavour_T var_flavour(char_u *varname)
///
/// @return Pointer that needs to be passed to next `var_shada_iter` invocation
/// or NULL to indicate that iteration is over.
-const void *var_shada_iter(const void *const iter, const char **const name,
- typval_T *rettv, var_flavour_T flavour)
+const void *var_shada_iter(const void *const iter, const char **const name, typval_T *rettv,
+ var_flavour_T flavour)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(2, 3)
{
const hashitem_T *hi;
const hashitem_T *hifirst = globvarht.ht_array;
- const size_t hinum = (size_t) globvarht.ht_mask + 1;
+ const size_t hinum = (size_t)globvarht.ht_mask + 1;
*name = NULL;
if (iter == NULL) {
hi = globvarht.ht_array;
- while ((size_t) (hi - hifirst) < hinum
+ while ((size_t)(hi - hifirst) < hinum
&& (HASHITEM_EMPTY(hi)
|| !(var_flavour(hi->hi_key) & flavour))) {
hi++;
}
- if ((size_t) (hi - hifirst) == hinum) {
+ if ((size_t)(hi - hifirst) == hinum) {
return NULL;
}
} else {
- hi = (const hashitem_T *) iter;
+ hi = (const hashitem_T *)iter;
}
*name = (char *)TV_DICT_HI2DI(hi)->di_key;
tv_copy(&TV_DICT_HI2DI(hi)->di_tv, rettv);
@@ -10368,9 +10369,8 @@ int store_session_globals(FILE *fd)
&& var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) {
// Escape special characters with a backslash. Turn a LF and
// CR into \n and \r.
- char_u *const p = vim_strsave_escaped(
- (const char_u *)tv_get_string(&this_var->di_tv),
- (const char_u *)"\\\"\n\r");
+ char_u *const p = vim_strsave_escaped((const char_u *)tv_get_string(&this_var->di_tv),
+ (const char_u *)"\\\"\n\r");
for (char_u *t = p; *t != NUL; t++) {
if (*t == '\n') {
*t = 'n';
@@ -10381,10 +10381,10 @@ int store_session_globals(FILE *fd)
if ((fprintf(fd, "let %s = %c%s%c",
this_var->di_key,
((this_var->di_tv.v_type == VAR_STRING) ? '"'
- : ' '),
+ : ' '),
p,
((this_var->di_tv.v_type == VAR_STRING) ? '"'
- : ' ')) < 0)
+ : ' ')) < 0)
|| put_eol(fd) == FAIL) {
xfree(p);
return FAIL;
@@ -10451,26 +10451,24 @@ void reset_v_option_vars(void)
set_vim_var_string(VV_OPTION_TYPE, NULL, -1);
}
-/*
- * Adjust a filename, according to a string of modifiers.
- * *fnamep must be NUL terminated when called. When returning, the length is
- * determined by *fnamelen.
- * Returns VALID_ flags or -1 for failure.
- * When there is an error, *fnamep is set to NULL.
- */
-int
-modify_fname(
- char_u *src, // string with modifiers
- bool tilde_file, // "~" is a file name, not $HOME
- size_t *usedlen, // characters after src that are used
- char_u **fnamep, // file name so far
- char_u **bufp, // buffer for allocated file name or NULL
- size_t *fnamelen // length of fnamep
-)
+/// Adjust a filename, according to a string of modifiers.
+/// *fnamep must be NUL terminated when called. When returning, the length is
+/// determined by *fnamelen.
+/// Returns VALID_ flags or -1 for failure.
+/// When there is an error, *fnamep is set to NULL.
+///
+/// @param src string with modifiers
+/// @param tilde_file "~" is a file name, not $HOME
+/// @param usedlen characters after src that are used
+/// @param fnamep file name so far
+/// @param bufp buffer for allocated file name or NULL
+/// @param fnamelen length of fnamep
+int modify_fname(char_u *src, bool tilde_file, size_t *usedlen, char_u **fnamep, char_u **bufp,
+ size_t *fnamelen)
{
int valid = 0;
- char_u *tail;
- char_u *s, *p, *pbuf;
+ char_u *tail;
+ char_u *s, *p, *pbuf;
char_u dirname[MAXPATHL];
int c;
int has_fullname = 0;
@@ -10492,13 +10490,13 @@ repeat:
# endif
|| (*fnamep)[1] == NUL)
#endif
- && !(tilde_file && (*fnamep)[1] == NUL)
- ) {
+ && !(tilde_file && (*fnamep)[1] == NUL)) {
*fnamep = expand_env_save(*fnamep);
xfree(*bufp); // free any allocated file name
*bufp = *fnamep;
- if (*fnamep == NULL)
+ if (*fnamep == NULL) {
return -1;
+ }
}
// When "/." or "/.." is used: force expansion to get rid of it.
@@ -10518,8 +10516,9 @@ repeat:
*fnamep = (char_u *)FullName_save((char *)(*fnamep), *p != NUL);
xfree(*bufp); // free any allocated file name
*bufp = *fnamep;
- if (*fnamep == NULL)
+ if (*fnamep == NULL) {
return -1;
+ }
}
// Append a path separator to a directory.
@@ -10528,8 +10527,9 @@ repeat:
*fnamep = vim_strnsave(*fnamep, STRLEN(*fnamep) + 2);
xfree(*bufp); // free any allocated file name
*bufp = *fnamep;
- if (*fnamep == NULL)
+ if (*fnamep == NULL) {
return -1;
+ }
add_pathsep((char *)*fnamep);
}
}
@@ -10546,12 +10546,14 @@ repeat:
pbuf = NULL;
// Need full path first (use expand_env() to remove a "~/")
if (!has_fullname) {
- if (c == '.' && **fnamep == '~')
+ if (c == '.' && **fnamep == '~') {
p = pbuf = expand_env_save(*fnamep);
- else
+ } else {
p = pbuf = (char_u *)FullName_save((char *)*fnamep, FALSE);
- } else
+ }
+ } else {
p = *fnamep;
+ }
has_fullname = 0;
@@ -10678,7 +10680,7 @@ repeat:
&& (src[*usedlen + 1] == 's'
|| (src[*usedlen + 1] == 'g' && src[*usedlen + 2] == 's'))) {
int sep;
- char_u *flags;
+ char_u *flags;
int didit = FALSE;
flags = (char_u *)"";
@@ -10742,17 +10744,16 @@ repeat:
/// When "sub" is NULL "expr" is used, must be a VAR_FUNC or VAR_PARTIAL.
/// "flags" can be "g" to do a global substitute.
/// Returns an allocated string, NULL for error.
-char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub,
- typval_T *expr, char_u *flags)
+char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, typval_T *expr, char_u *flags)
{
int sublen;
regmatch_T regmatch;
int do_all;
- char_u *tail;
- char_u *end;
+ char_u *tail;
+ char_u *end;
garray_T ga;
- char_u *save_cpo;
- char_u *zero_width = NULL;
+ char_u *save_cpo;
+ char_u *zero_width = NULL;
// Make 'cpoptions' empty, so that the 'l' flag doesn't work here
save_cpo = p_cpo;
@@ -10788,7 +10789,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub,
// - The text after the match.
sublen = vim_regsub(&regmatch, sub, expr, tail, false, true, false);
ga_grow(&ga, (int)((end - tail) + sublen -
- (regmatch.endp[0] - regmatch.startp[0])));
+ (regmatch.endp[0] - regmatch.startp[0])));
// copy the text up to where the match is
int i = (int)(regmatch.startp[0] - tail);
@@ -10798,14 +10799,17 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub,
+ ga.ga_len + i, true, true, false);
ga.ga_len += i + sublen - 1;
tail = regmatch.endp[0];
- if (*tail == NUL)
+ if (*tail == NUL) {
break;
- if (!do_all)
+ }
+ if (!do_all) {
break;
+ }
}
- if (ga.ga_data != NULL)
+ if (ga.ga_data != NULL) {
STRCPY((char *)ga.ga_data + ga.ga_len, tail);
+ }
vim_regfree(regmatch.regprog);
}
@@ -10825,9 +10829,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub,
/// common code for getting job callbacks for jobstart, termopen and rpcstart
///
/// @return true/false on success/failure.
-bool common_job_callbacks(dict_T *vopts,
- CallbackReader *on_stdout,
- CallbackReader *on_stderr,
+bool common_job_callbacks(dict_T *vopts, CallbackReader *on_stdout, CallbackReader *on_stderr,
Callback *on_exit)
{
if (tv_dict_get_callback(vopts, S_LEN("on_stdout"), &on_stdout->cb)
@@ -10888,8 +10890,7 @@ void script_host_eval(char *name, typval_T *argvars, typval_T *rettv)
/// @param discard Clears the value returned by the provider and returns
/// an empty typval_T.
-typval_T eval_call_provider(char *provider, char *method, list_T *arguments,
- bool discard)
+typval_T eval_call_provider(char *provider, char *method, list_T *arguments, bool discard)
{
if (!eval_has_provider(provider)) {
emsgf("E319: No \"%s\" provider found. Run \":checkhealth provider\"",
@@ -11052,59 +11053,59 @@ void ex_checkhealth(exarg_T *eap)
void invoke_prompt_callback(void)
{
- typval_T rettv;
- typval_T argv[2];
- char_u *text;
- char_u *prompt;
- linenr_T lnum = curbuf->b_ml.ml_line_count;
-
- // Add a new line for the prompt before invoking the callback, so that
- // text can always be inserted above the last line.
- ml_append(lnum, (char_u *)"", 0, false);
- curwin->w_cursor.lnum = lnum + 1;
- curwin->w_cursor.col = 0;
-
- if (curbuf->b_prompt_callback.type == kCallbackNone) {
- return;
- }
- text = ml_get(lnum);
- prompt = prompt_text();
- if (STRLEN(text) >= STRLEN(prompt)) {
- text += STRLEN(prompt);
- }
- argv[0].v_type = VAR_STRING;
- argv[0].vval.v_string = vim_strsave(text);
- argv[1].v_type = VAR_UNKNOWN;
+ typval_T rettv;
+ typval_T argv[2];
+ char_u *text;
+ char_u *prompt;
+ linenr_T lnum = curbuf->b_ml.ml_line_count;
+
+ // Add a new line for the prompt before invoking the callback, so that
+ // text can always be inserted above the last line.
+ ml_append(lnum, (char_u *)"", 0, false);
+ curwin->w_cursor.lnum = lnum + 1;
+ curwin->w_cursor.col = 0;
+
+ if (curbuf->b_prompt_callback.type == kCallbackNone) {
+ return;
+ }
+ text = ml_get(lnum);
+ prompt = prompt_text();
+ if (STRLEN(text) >= STRLEN(prompt)) {
+ text += STRLEN(prompt);
+ }
+ argv[0].v_type = VAR_STRING;
+ argv[0].vval.v_string = vim_strsave(text);
+ argv[1].v_type = VAR_UNKNOWN;
- callback_call(&curbuf->b_prompt_callback, 1, argv, &rettv);
- tv_clear(&argv[0]);
- tv_clear(&rettv);
+ callback_call(&curbuf->b_prompt_callback, 1, argv, &rettv);
+ tv_clear(&argv[0]);
+ tv_clear(&rettv);
}
// Return true When the interrupt callback was invoked.
bool invoke_prompt_interrupt(void)
{
- typval_T rettv;
- typval_T argv[1];
+ typval_T rettv;
+ typval_T argv[1];
- if (curbuf->b_prompt_interrupt.type == kCallbackNone) {
- return false;
- }
- argv[0].v_type = VAR_UNKNOWN;
+ if (curbuf->b_prompt_interrupt.type == kCallbackNone) {
+ return false;
+ }
+ argv[0].v_type = VAR_UNKNOWN;
- got_int = false; // don't skip executing commands
- callback_call(&curbuf->b_prompt_interrupt, 0, argv, &rettv);
- tv_clear(&rettv);
- return true;
+ got_int = false; // don't skip executing commands
+ callback_call(&curbuf->b_prompt_interrupt, 0, argv, &rettv);
+ tv_clear(&rettv);
+ return true;
}
-// Compare "typ1" and "typ2". Put the result in "typ1".
-int typval_compare(
- typval_T *typ1, // first operand
- typval_T *typ2, // second operand
- exprtype_T type, // operator
- bool ic // ignore case
-)
+/// Compare "typ1" and "typ2". Put the result in "typ1".
+///
+/// @param typ1 first operand
+/// @param typ2 second operand
+/// @param type operator
+/// @param ic ignore case
+int typval_compare(typval_T *typ1, typval_T *typ2, exprtype_T type, bool ic)
FUNC_ATTR_NONNULL_ALL
{
varnumber_T n1, n2;
@@ -11140,7 +11141,7 @@ int typval_compare(
} else if (typ1->v_type == VAR_LIST || typ2->v_type == VAR_LIST) {
if (type_is) {
n1 = typ1->v_type == typ2->v_type
- && typ1->vval.v_list == typ2->vval.v_list;
+ && typ1->vval.v_list == typ2->vval.v_list;
if (type == EXPR_ISNOT) {
n1 = !n1;
}
@@ -11163,7 +11164,7 @@ int typval_compare(
} else if (typ1->v_type == VAR_DICT || typ2->v_type == VAR_DICT) {
if (type_is) {
n1 = typ1->v_type == typ2->v_type
- && typ1->vval.v_dict == typ2->vval.v_dict;
+ && typ1->vval.v_dict == typ2->vval.v_dict;
if (type == EXPR_ISNOT) {
n1 = !n1;
}
@@ -11218,17 +11219,24 @@ int typval_compare(
const float_T f2 = tv_get_float(typ2);
n1 = false;
switch (type) {
- case EXPR_IS:
- case EXPR_EQUAL: n1 = f1 == f2; break;
- case EXPR_ISNOT:
- case EXPR_NEQUAL: n1 = f1 != f2; break;
- case EXPR_GREATER: n1 = f1 > f2; break;
- case EXPR_GEQUAL: n1 = f1 >= f2; break;
- case EXPR_SMALLER: n1 = f1 < f2; break;
- case EXPR_SEQUAL: n1 = f1 <= f2; break;
- case EXPR_UNKNOWN:
- case EXPR_MATCH:
- case EXPR_NOMATCH: break; // avoid gcc warning
+ case EXPR_IS:
+ case EXPR_EQUAL:
+ n1 = f1 == f2; break;
+ case EXPR_ISNOT:
+ case EXPR_NEQUAL:
+ n1 = f1 != f2; break;
+ case EXPR_GREATER:
+ n1 = f1 > f2; break;
+ case EXPR_GEQUAL:
+ n1 = f1 >= f2; break;
+ case EXPR_SMALLER:
+ n1 = f1 < f2; break;
+ case EXPR_SEQUAL:
+ n1 = f1 <= f2; break;
+ case EXPR_UNKNOWN:
+ case EXPR_MATCH:
+ case EXPR_NOMATCH:
+ break; // avoid gcc warning
}
} else if ((typ1->v_type == VAR_NUMBER || typ2->v_type == VAR_NUMBER)
&& type != EXPR_MATCH && type != EXPR_NOMATCH) {
@@ -11237,17 +11245,24 @@ int typval_compare(
n1 = tv_get_number(typ1);
n2 = tv_get_number(typ2);
switch (type) {
- case EXPR_IS:
- case EXPR_EQUAL: n1 = n1 == n2; break;
- case EXPR_ISNOT:
- case EXPR_NEQUAL: n1 = n1 != n2; break;
- case EXPR_GREATER: n1 = n1 > n2; break;
- case EXPR_GEQUAL: n1 = n1 >= n2; break;
- case EXPR_SMALLER: n1 = n1 < n2; break;
- case EXPR_SEQUAL: n1 = n1 <= n2; break;
- case EXPR_UNKNOWN:
- case EXPR_MATCH:
- case EXPR_NOMATCH: break; // avoid gcc warning
+ case EXPR_IS:
+ case EXPR_EQUAL:
+ n1 = n1 == n2; break;
+ case EXPR_ISNOT:
+ case EXPR_NEQUAL:
+ n1 = n1 != n2; break;
+ case EXPR_GREATER:
+ n1 = n1 > n2; break;
+ case EXPR_GEQUAL:
+ n1 = n1 >= n2; break;
+ case EXPR_SMALLER:
+ n1 = n1 < n2; break;
+ case EXPR_SEQUAL:
+ n1 = n1 <= n2; break;
+ case EXPR_UNKNOWN:
+ case EXPR_MATCH:
+ case EXPR_NOMATCH:
+ break; // avoid gcc warning
}
} else {
char buf1[NUMBUFLEN];
@@ -11262,23 +11277,30 @@ int typval_compare(
}
n1 = false;
switch (type) {
- case EXPR_IS:
- case EXPR_EQUAL: n1 = i == 0; break;
- case EXPR_ISNOT:
- case EXPR_NEQUAL: n1 = i != 0; break;
- case EXPR_GREATER: n1 = i > 0; break;
- case EXPR_GEQUAL: n1 = i >= 0; break;
- case EXPR_SMALLER: n1 = i < 0; break;
- case EXPR_SEQUAL: n1 = i <= 0; break;
-
- case EXPR_MATCH:
- case EXPR_NOMATCH:
- n1 = pattern_match((char_u *)s2, (char_u *)s1, ic);
- if (type == EXPR_NOMATCH) {
- n1 = !n1;
- }
- break;
- case EXPR_UNKNOWN: break; // avoid gcc warning
+ case EXPR_IS:
+ case EXPR_EQUAL:
+ n1 = i == 0; break;
+ case EXPR_ISNOT:
+ case EXPR_NEQUAL:
+ n1 = i != 0; break;
+ case EXPR_GREATER:
+ n1 = i > 0; break;
+ case EXPR_GEQUAL:
+ n1 = i >= 0; break;
+ case EXPR_SMALLER:
+ n1 = i < 0; break;
+ case EXPR_SEQUAL:
+ n1 = i <= 0; break;
+
+ case EXPR_MATCH:
+ case EXPR_NOMATCH:
+ n1 = pattern_match((char_u *)s2, (char_u *)s1, ic);
+ if (type == EXPR_NOMATCH) {
+ n1 = !n1;
+ }
+ break;
+ case EXPR_UNKNOWN:
+ break; // avoid gcc warning
}
}
tv_clear(typ1);
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 575c5c9cbd..2c49f63333 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -6,58 +6,58 @@
/// Some more functions for command line commands
#include <assert.h>
+#include <fcntl.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
-#include <fcntl.h>
-#include "nvim/vim.h"
#include "nvim/ascii.h"
+#include "nvim/vim.h"
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
-#include "nvim/ex_cmds2.h"
+#include "nvim/api/private/defs.h"
+#include "nvim/api/private/helpers.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/debugger.h"
#include "nvim/eval/userfunc.h"
#include "nvim/ex_cmds.h"
+#include "nvim/ex_cmds2.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
+#include "nvim/garray.h"
+#include "nvim/lua/executor.h"
#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/garray.h"
-#include "nvim/memory.h"
#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/ops.h"
#include "nvim/option.h"
+#include "nvim/os/fs_defs.h"
+#include "nvim/os/shell.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
+#include "nvim/profile.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/strings.h"
#include "nvim/undo.h"
#include "nvim/version.h"
#include "nvim/window.h"
-#include "nvim/profile.h"
-#include "nvim/os/shell.h"
-#include "nvim/os/fs_defs.h"
-#include "nvim/api/private/helpers.h"
-#include "nvim/api/private/defs.h"
-#include "nvim/lua/executor.h"
/// Growarray to store info about already sourced scripts.
/// Also store the dev/ino, so that we don't have to stat() each
/// script when going through the list.
typedef struct scriptitem_S {
- char_u *sn_name;
+ char_u *sn_name;
bool file_id_valid;
FileID file_id;
bool sn_prof_on; ///< true when script is/was profiled
@@ -115,14 +115,14 @@ struct source_cookie {
# include "ex_cmds2.c.generated.h"
#endif
-static char_u *profile_fname = NULL;
+static char_u *profile_fname = NULL;
/// ":profile cmd args"
void ex_profile(exarg_T *eap)
{
static proftime_T pause_time;
- char_u *e;
+ char_u *e;
int len;
e = skiptowhite(eap->arg);
@@ -277,7 +277,7 @@ void set_context_in_profile_cmd(expand_T *xp, const char *arg)
/// Dump the profiling info.
void profile_dump(void)
{
- FILE *fd;
+ FILE *fd;
if (profile_fname != NULL) {
fd = os_fopen((char *)profile_fname, "w");
@@ -362,11 +362,11 @@ static void profile_init(scriptitem_T *si)
}
/// Save time when starting to invoke another script or function.
-void script_prof_save(
- proftime_T *tm // place to store wait time
-)
+///
+/// @param tm place to store wait time
+void script_prof_save(proftime_T *tm)
{
- scriptitem_T *si;
+ scriptitem_T *si;
if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= script_items.ga_len) {
si = &SCRIPT_ITEM(current_sctx.sc_sid);
@@ -380,7 +380,7 @@ void script_prof_save(
/// Count time spent in children after invoking another script or function.
void script_prof_restore(proftime_T *tm)
{
- scriptitem_T *si;
+ scriptitem_T *si;
if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= script_items.ga_len) {
si = &SCRIPT_ITEM(current_sctx.sc_sid);
@@ -412,9 +412,9 @@ void prof_inchar_exit(void)
/// Dump the profiling results for all scripts in file "fd".
static void script_dump_profile(FILE *fd)
{
- scriptitem_T *si;
- FILE *sfd;
- sn_prl_T *pp;
+ scriptitem_T *si;
+ FILE *sfd;
+ sn_prl_T *pp;
for (int id = 1; id <= script_items.ga_len; id++) {
si = &SCRIPT_ITEM(id);
@@ -699,7 +699,7 @@ bool check_changed_any(bool hidden, bool unload)
int i;
int bufnum = 0;
size_t bufcount = 0;
- int *bufnrs;
+ int *bufnrs;
// Make a list of all buffers, with the most important ones first.
FOR_ALL_BUFFERS(buf) {
@@ -829,7 +829,7 @@ int check_fname(void)
int buf_write_all(buf_T *buf, int forceit)
{
int retval;
- buf_T *old_curbuf = curbuf;
+ buf_T *old_curbuf = curbuf;
retval = (buf_write(buf, buf->b_ffname, buf->b_fname,
(linenr_T)1, buf->b_ml.ml_line_count, NULL,
@@ -852,7 +852,7 @@ int buf_write_all(buf_T *buf, int forceit)
/// Return a pointer to the start of the next argument.
static char_u *do_one_arg(char_u *str)
{
- char_u *p;
+ char_u *p;
bool inbacktick;
inbacktick = false;
@@ -936,8 +936,8 @@ static int do_arglist(char_u *str, int what, int after, bool will_edit)
{
garray_T new_ga;
int exp_count;
- char_u **exp_files;
- char_u *p;
+ char_u **exp_files;
+ char_u *p;
int match;
int arg_escaped = true;
@@ -1037,9 +1037,8 @@ static bool editing_arg_idx(win_T *win)
|| (win->w_buffer->b_fnum
!= WARGLIST(win)[win->w_arg_idx].ae_fnum
&& (win->w_buffer->b_ffname == NULL
- || !(path_full_compare(
- alist_name(&WARGLIST(win)[win->w_arg_idx]),
- win->w_buffer->b_ffname, true, true) & kEqualFiles))));
+ || !(path_full_compare(alist_name(&WARGLIST(win)[win->w_arg_idx]),
+ win->w_buffer->b_ffname, true, true) & kEqualFiles))));
}
/// Check if window "win" is editing the w_arg_idx file in its argument list.
@@ -1102,7 +1101,7 @@ void ex_args(exarg_T *eap)
xfree(items);
}
} else if (eap->cmdidx == CMD_arglocal) {
- garray_T *gap = &curwin->w_alist->al_ga;
+ garray_T *gap = &curwin->w_alist->al_ga;
// ":argslocal": make a local copy of the global argument list.
ga_grow(gap, GARGCOUNT);
@@ -1158,7 +1157,7 @@ void ex_argument(exarg_T *eap)
void do_argfile(exarg_T *eap, int argn)
{
int other;
- char_u *p;
+ char_u *p;
int old_arg_idx = curwin->w_arg_idx;
if (argn < 0 || argn >= ARGCOUNT) {
@@ -1310,9 +1309,9 @@ void ex_argdelete(exarg_T *eap)
curwin->w_arg_idx = (int)eap->line1;
}
if (ARGCOUNT == 0) {
- curwin->w_arg_idx = 0;
+ curwin->w_arg_idx = 0;
} else if (curwin->w_arg_idx >= ARGCOUNT) {
- curwin->w_arg_idx = ARGCOUNT - 1;
+ curwin->w_arg_idx = ARGCOUNT - 1;
}
}
} else {
@@ -1325,11 +1324,11 @@ void ex_argdelete(exarg_T *eap)
void ex_listdo(exarg_T *eap)
{
int i;
- win_T *wp;
- tabpage_T *tp;
+ win_T *wp;
+ tabpage_T *tp;
int next_fnum = 0;
- char_u *save_ei = NULL;
- char_u *p_shm_save;
+ char_u *save_ei = NULL;
+ char_u *p_shm_save;
if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) {
// Don't do syntax HL autocommands. Skipping the syntax file is a
@@ -1610,9 +1609,9 @@ char_u *get_arglist_name(expand_T *xp FUNC_ATTR_UNUSED, int idx)
/// ":compiler[!] {name}"
void ex_compiler(exarg_T *eap)
{
- char_u *buf;
- char_u *old_cur_comp = NULL;
- char_u *p;
+ char_u *buf;
+ char_u *old_cur_comp = NULL;
+ char_u *p;
if (*eap->arg == NUL) {
// List all compiler scripts.
@@ -1703,7 +1702,7 @@ void init_pyxversion(void)
// otherwise return 0.
static int requires_py_version(char_u *filename)
{
- FILE *file;
+ FILE *file;
int requires_py_version = 0;
int i, lines;
@@ -1940,9 +1939,7 @@ static char_u *get_str_line(int c, void *cookie, int indent, bool do_concat)
return ga.ga_data;
}
-static int source_using_linegetter(void *cookie,
- LineGetter fgetline,
- const char *traceback_name)
+static int source_using_linegetter(void *cookie, LineGetter fgetline, const char *traceback_name)
{
char_u *save_sourcing_name = sourcing_name;
linenr_T save_sourcing_lnum = sourcing_lnum;
@@ -1951,7 +1948,7 @@ static int source_using_linegetter(void *cookie,
sourcing_name = (char_u *)traceback_name;
} else {
snprintf((char *)sourcing_name_buf, sizeof(sourcing_name_buf),
- "%s called at %s:%"PRIdLINENR, traceback_name, save_sourcing_name,
+ "%s called at %s:%" PRIdLINENR, traceback_name, save_sourcing_name,
save_sourcing_lnum);
sourcing_name = sourcing_name_buf;
}
@@ -1992,8 +1989,8 @@ static void cmd_source_buffer(const exarg_T *const eap)
}
((char_u *)ga.ga_data)[ga.ga_len - 1] = NUL;
const GetStrLineCookie cookie = {
- .buf = ga.ga_data,
- .offset = 0,
+ .buf = ga.ga_data,
+ .offset = 0,
};
if (curbuf->b_fname
&& path_with_extension((const char *)curbuf->b_fname, "lua")) {
@@ -2012,8 +2009,8 @@ static void cmd_source_buffer(const exarg_T *const eap)
int do_source_str(const char *cmd, const char *traceback_name)
{
GetStrLineCookie cookie = {
- .buf = (char_u *)cmd,
- .offset = 0,
+ .buf = (char_u *)cmd,
+ .offset = 0,
};
return source_using_linegetter((void *)&cookie, get_str_line, traceback_name);
}
@@ -2033,16 +2030,16 @@ int do_source_str(const char *cmd, const char *traceback_name)
int do_source(char_u *fname, int check_other, int is_vimrc)
{
struct source_cookie cookie;
- char_u *save_sourcing_name;
+ char_u *save_sourcing_name;
linenr_T save_sourcing_lnum;
- char_u *p;
- char_u *fname_exp;
- char_u *firstline = NULL;
+ char_u *p;
+ char_u *fname_exp;
+ char_u *firstline = NULL;
int retval = FAIL;
static scid_T last_current_SID = 0;
static int last_current_SID_seq = 0;
int save_debug_break_level = debug_break_level;
- scriptitem_T *si = NULL;
+ scriptitem_T *si = NULL;
proftime_T wait_start;
bool trigger_source_post = false;
@@ -2363,31 +2360,31 @@ char_u *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");
- case SID_CMDARG:
- return (char_u *)_("--cmd argument");
- case SID_CARG:
- return (char_u *)_("-c argument");
- case SID_ENV:
- return (char_u *)_("environment variable");
- case SID_ERROR:
- return (char_u *)_("error handler");
- case SID_WINLAYOUT:
- return (char_u *)_("changed window size");
- case SID_LUA:
- return (char_u *)_("Lua");
- case SID_API_CLIENT:
- vim_snprintf((char *)IObuff, IOSIZE,
- _("API client (channel id %" PRIu64 ")"),
- last_set.channel_id);
- return IObuff;
- case SID_STR:
- return (char_u *)_("anonymous :source");
- default:
- *should_free = true;
- return home_replace_save(NULL,
- SCRIPT_ITEM(last_set.script_ctx.sc_sid).sn_name);
+ case SID_MODELINE:
+ return (char_u *)_("modeline");
+ case SID_CMDARG:
+ return (char_u *)_("--cmd argument");
+ case SID_CARG:
+ return (char_u *)_("-c argument");
+ case SID_ENV:
+ return (char_u *)_("environment variable");
+ case SID_ERROR:
+ return (char_u *)_("error handler");
+ case SID_WINLAYOUT:
+ return (char_u *)_("changed window size");
+ case SID_LUA:
+ return (char_u *)_("Lua");
+ case SID_API_CLIENT:
+ vim_snprintf((char *)IObuff, IOSIZE,
+ _("API client (channel id %" PRIu64 ")"),
+ last_set.channel_id);
+ return IObuff;
+ case SID_STR:
+ return (char_u *)_("anonymous :source");
+ default:
+ *should_free = true;
+ return home_replace_save(NULL,
+ SCRIPT_ITEM(last_set.script_ctx.sc_sid).sn_name);
}
}
@@ -2403,7 +2400,7 @@ void free_scriptnames(void)
linenr_T get_sourced_lnum(LineGetter fgetline, void *cookie)
{
- return fgetline == getsourceline
+ return fgetline == getsourceline
? ((struct source_cookie *)cookie)->sourcing_lnum
: sourcing_lnum;
}
@@ -2476,7 +2473,7 @@ char_u *getsourceline(int c, void *cookie, int indent, bool do_concat)
}
if (line != NULL && sp->conv.vc_type != CONV_NONE) {
- char_u *s;
+ char_u *s;
// Convert the encoding of the script line.
s = string_convert(&sp->conv, line, NULL);
@@ -2502,7 +2499,7 @@ static char_u *get_one_sourceline(struct source_cookie *sp)
garray_T ga;
int len;
int c;
- char_u *buf;
+ char_u *buf;
#ifdef USE_CRNL
int has_cr; // CR-LF found
#endif
@@ -2605,8 +2602,8 @@ retry:
/// until later and we need to store the time now.
void script_line_start(void)
{
- scriptitem_T *si;
- sn_prl_T *pp;
+ scriptitem_T *si;
+ sn_prl_T *pp;
if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) {
return;
@@ -2637,7 +2634,7 @@ void script_line_start(void)
/// Called when actually executing a function line.
void script_line_exec(void)
{
- scriptitem_T *si;
+ scriptitem_T *si;
if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) {
return;
@@ -2651,8 +2648,8 @@ void script_line_exec(void)
/// Called when done with a function line.
void script_line_end(void)
{
- scriptitem_T *si;
- sn_prl_T *pp;
+ scriptitem_T *si;
+ sn_prl_T *pp;
if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) {
return;
@@ -2677,8 +2674,8 @@ void script_line_end(void)
/// Without the multi-byte feature it's simply ignored.
void ex_scriptencoding(exarg_T *eap)
{
- struct source_cookie *sp;
- char_u *name;
+ struct source_cookie *sp;
+ char_u *name;
if (!getline_equal(eap->getline, eap->cookie, getsourceline)) {
EMSG(_("E167: :scriptencoding used outside of a sourced file"));
@@ -2743,14 +2740,13 @@ void do_finish(exarg_T *eap, int reanimate)
bool source_finished(LineGetter fgetline, void *cookie)
{
return getline_equal(fgetline, cookie, getsourceline)
- && ((struct source_cookie *)getline_cookie(
- fgetline, cookie))->finished;
+ && ((struct source_cookie *)getline_cookie(fgetline, cookie))->finished;
}
/// ":checktime [buffer]"
void ex_checktime(exarg_T *eap)
{
- buf_T *buf;
+ buf_T *buf;
int save_no_check_timestamps = no_check_timestamps;
no_check_timestamps = 0;
@@ -2817,7 +2813,7 @@ char *get_mess_lang(void)
/// Get the language used for messages from the environment.
static char_u *get_mess_env(void)
{
- char_u *p;
+ char_u *p;
p = (char_u *)os_getenv("LC_ALL");
if (p == NULL) {
@@ -2888,11 +2884,11 @@ void set_lang_var(void)
///
void ex_language(exarg_T *eap)
{
- char *loc;
- char_u *p;
- char_u *name;
+ char *loc;
+ char_u *p;
+ char_u *name;
int what = LC_ALL;
- char *whatstr = "";
+ char *whatstr = "";
#ifdef LC_MESSAGES
# define VIM_LC_MESSAGES LC_MESSAGES
#else
@@ -2931,9 +2927,9 @@ void ex_language(exarg_T *eap)
p = get_mess_env();
} else {
#endif
- p = (char_u *)setlocale(what, NULL);
+ p = (char_u *)setlocale(what, NULL);
#ifdef HAVE_WORKING_LIBINTL
- }
+ }
#endif
if (p == NULL || *p == NUL) {
p = (char_u *)"Unknown";
@@ -2945,13 +2941,13 @@ void ex_language(exarg_T *eap)
loc = "";
} else {
#endif
- loc = setlocale(what, (char *)name);
+ loc = setlocale(what, (char *)name);
#ifdef LC_NUMERIC
- // Make sure strtod() uses a decimal point, not a comma.
- setlocale(LC_NUMERIC, "C");
+ // Make sure strtod() uses a decimal point, not a comma.
+ setlocale(LC_NUMERIC, "C");
#endif
#ifndef LC_MESSAGES
- }
+ }
#endif
if (loc == NULL) {
EMSG2(_("E197: Cannot set language to \"%s\""), name);
@@ -2999,7 +2995,7 @@ static bool did_init_locales = false;
static char_u **find_locales(void)
{
garray_T locales_ga;
- char_u *loc;
+ char_u *loc;
char *saveptr = NULL;
// Find all available locales by running command "locale -a". If this
@@ -3137,7 +3133,7 @@ static void script_host_do_range(char *name, exarg_T *eap)
/// ":drop"
/// Opens the first argument in a window. When there are two or more arguments
/// the argument list is redefined.
-void ex_drop(exarg_T *eap)
+void ex_drop(exarg_T *eap)
{
bool split = false;
buf_T *buf;
diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c
index 54776c35e7..21ddf7399b 100644
--- a/src/nvim/ex_eval.c
+++ b/src/nvim/ex_eval.c
@@ -7,23 +7,23 @@
///
/// Functions for Ex command line for the +eval feature.
#include <assert.h>
-#include <stdbool.h>
#include <inttypes.h>
#include <limits.h>
+#include <stdbool.h>
-#include "nvim/vim.h"
#include "nvim/ascii.h"
-#include "nvim/debugger.h"
-#include "nvim/ex_eval.h"
#include "nvim/charset.h"
+#include "nvim/debugger.h"
#include "nvim/eval.h"
#include "nvim/eval/userfunc.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
-#include "nvim/message.h"
+#include "nvim/ex_eval.h"
#include "nvim/memory.h"
+#include "nvim/message.h"
#include "nvim/regexp.h"
#include "nvim/strings.h"
+#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "ex_eval.c.generated.h"
@@ -111,8 +111,9 @@ int aborting(void)
*/
void update_force_abort(void)
{
- if (cause_abort)
+ if (cause_abort) {
force_abort = TRUE;
+ }
}
/*
@@ -248,8 +249,9 @@ bool cause_errthrow(const char_u *mesg, bool severe, bool *ignore)
*/
if (msg_list != NULL) {
plist = msg_list;
- while (*plist != NULL)
+ while (*plist != NULL) {
plist = &(*plist)->next;
+ }
elem = xmalloc(sizeof(struct msglist));
elem->msg = vim_strsave(mesg);
@@ -257,19 +259,20 @@ bool cause_errthrow(const char_u *mesg, bool severe, bool *ignore)
elem->throw_msg = NULL;
*plist = elem;
if (plist == msg_list || severe) {
- char_u *tmsg;
+ char_u *tmsg;
- /* Skip the extra "Vim " prefix for message "E458". */
+ // Skip the extra "Vim " prefix for message "E458".
tmsg = elem->msg;
if (STRNCMP(tmsg, "Vim E", 5) == 0
&& ascii_isdigit(tmsg[5])
&& ascii_isdigit(tmsg[6])
&& ascii_isdigit(tmsg[7])
&& tmsg[8] == ':'
- && tmsg[9] == ' ')
+ && tmsg[9] == ' ') {
(*msg_list)->throw_msg = &tmsg[4];
- else
+ } else {
(*msg_list)->throw_msg = tmsg;
+ }
}
}
return true;
@@ -281,7 +284,7 @@ bool cause_errthrow(const char_u *mesg, bool severe, bool *ignore)
*/
static void free_msglist(struct msglist *l)
{
- struct msglist *messages, *next;
+ struct msglist *messages, *next;
messages = l;
while (messages != NULL) {
@@ -320,16 +323,18 @@ void do_errthrow(cstack_T *cstack, char_u *cmdname)
/* If no exception is to be thrown or the conversion should be done after
* returning to a previous invocation of do_one_cmd(), do nothing. */
- if (msg_list == NULL || *msg_list == NULL)
+ if (msg_list == NULL || *msg_list == NULL) {
return;
+ }
- if (throw_exception(*msg_list, ET_ERROR, cmdname) == FAIL)
+ if (throw_exception(*msg_list, ET_ERROR, cmdname) == FAIL) {
free_msglist(*msg_list);
- else {
- if (cstack != NULL)
+ } else {
+ if (cstack != NULL) {
do_throw(cstack);
- else
+ } else {
need_rethrow = TRUE;
+ }
}
*msg_list = NULL;
}
@@ -357,36 +362,35 @@ int do_intthrow(cstack_T *cstack)
}
} else {
#endif
- // Throw an interrupt exception, so that everything will be aborted
- // (except for executing finally clauses), until the interrupt exception
- // is caught; if still uncaught at the top level, the script processing
- // will be terminated then. - If an interrupt exception is already
- // being thrown, do nothing.
-
- if (current_exception) {
- if (current_exception->type == ET_INTERRUPT) {
- return false;
- }
+ // Throw an interrupt exception, so that everything will be aborted
+ // (except for executing finally clauses), until the interrupt exception
+ // is caught; if still uncaught at the top level, the script processing
+ // will be terminated then. - If an interrupt exception is already
+ // being thrown, do nothing.
- // An interrupt exception replaces any user or error exception.
- discard_current_exception();
- }
- if (throw_exception("Vim:Interrupt", ET_INTERRUPT, NULL) != FAIL) {
- do_throw(cstack);
+ if (current_exception) {
+ if (current_exception->type == ET_INTERRUPT) {
+ return false;
}
-#ifdef THROW_TEST
+
+ // An interrupt exception replaces any user or error exception.
+ discard_current_exception();
+ }
+ if (throw_exception("Vim:Interrupt", ET_INTERRUPT, NULL) != FAIL) {
+ do_throw(cstack);
}
+#ifdef THROW_TEST
+}
#endif
return true;
}
// Get an exception message that is to be stored in current_exception->value.
-char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname,
- int *should_free)
+char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname, int *should_free)
{
- char_u *ret, *mesg;
- char_u *p, *val;
+ char_u *ret, *mesg;
+ char_u *p, *val;
if (type == ET_ERROR) {
*should_free = true;
@@ -434,7 +438,7 @@ char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname,
}
} else {
*should_free = FALSE;
- ret = (char_u *) value;
+ ret = (char_u *)value;
}
return ret;
@@ -447,7 +451,7 @@ char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname,
// error exception.
static int throw_exception(void *value, except_type_T type, char_u *cmdname)
{
- except_T *excp;
+ except_T *excp;
int should_free;
/*
@@ -466,14 +470,16 @@ static int throw_exception(void *value, except_type_T type, char_u *cmdname)
excp = xmalloc(sizeof(except_T));
- if (type == ET_ERROR)
+ if (type == ET_ERROR) {
/* Store the original message and prefix the exception value with
* "Vim:" or, if a command name is given, "Vim(cmdname):". */
excp->messages = (struct msglist *)value;
+ }
excp->value = get_exception_string(value, type, cmdname, &should_free);
- if (excp->value == NULL && should_free)
+ if (excp->value == NULL && should_free) {
goto nomem;
+ }
excp->type = type;
excp->throw_name = vim_strsave(sourcing_name == NULL
@@ -483,24 +489,27 @@ static int throw_exception(void *value, except_type_T type, char_u *cmdname)
if (p_verbose >= 13 || debug_break_level > 0) {
int save_msg_silent = msg_silent;
- if (debug_break_level > 0)
- msg_silent = FALSE; /* display messages */
- else
+ if (debug_break_level > 0) {
+ msg_silent = FALSE; // display messages
+ } else {
verbose_enter();
+ }
++no_wait_return;
- if (debug_break_level > 0 || *p_vfile == NUL)
- msg_scroll = TRUE; /* always scroll up, don't overwrite */
-
+ if (debug_break_level > 0 || *p_vfile == NUL) {
+ msg_scroll = TRUE; // always scroll up, don't overwrite
+ }
smsg(_("Exception thrown: %s"), excp->value);
msg_puts("\n"); // don't overwrite this either
- if (debug_break_level > 0 || *p_vfile == NUL)
+ if (debug_break_level > 0 || *p_vfile == NUL) {
cmdline_row = msg_row;
+ }
--no_wait_return;
- if (debug_break_level > 0)
+ if (debug_break_level > 0) {
msg_silent = save_msg_silent;
- else
+ } else {
verbose_leave();
+ }
}
current_exception = excp;
@@ -521,7 +530,7 @@ fail:
*/
static void discard_exception(except_T *excp, bool was_finished)
{
- char_u *saved_IObuff;
+ char_u *saved_IObuff;
if (current_exception == excp) {
current_exception = NULL;
@@ -535,13 +544,15 @@ static void discard_exception(except_T *excp, bool was_finished)
int save_msg_silent = msg_silent;
saved_IObuff = vim_strsave(IObuff);
- if (debug_break_level > 0)
- msg_silent = FALSE; /* display messages */
- else
+ if (debug_break_level > 0) {
+ msg_silent = FALSE; // display messages
+ } else {
verbose_enter();
+ }
++no_wait_return;
- if (debug_break_level > 0 || *p_vfile == NUL)
- msg_scroll = TRUE; /* always scroll up, don't overwrite */
+ if (debug_break_level > 0 || *p_vfile == NUL) {
+ msg_scroll = TRUE; // always scroll up, don't overwrite
+ }
smsg(was_finished ? _("Exception finished: %s")
: _("Exception discarded: %s"),
excp->value);
@@ -558,10 +569,12 @@ static void discard_exception(except_T *excp, bool was_finished)
xstrlcpy((char *)IObuff, (const char *)saved_IObuff, IOSIZE);
xfree(saved_IObuff);
}
- if (excp->type != ET_INTERRUPT)
+ if (excp->type != ET_INTERRUPT) {
xfree(excp->value);
- if (excp->type == ET_ERROR)
+ }
+ if (excp->type == ET_ERROR) {
free_msglist(excp->messages);
+ }
xfree(excp->throw_name);
xfree(excp);
}
@@ -586,7 +599,7 @@ static void catch_exception(except_T *excp)
{
excp->caught = caught_stack;
caught_stack = excp;
- set_vim_var_string(VV_EXCEPTION, (char *) excp->value, -1);
+ set_vim_var_string(VV_EXCEPTION, (char *)excp->value, -1);
if (*excp->throw_name != NUL) {
if (excp->throw_lnum != 0) {
vim_snprintf((char *)IObuff, IOSIZE, _("%s, line %" PRId64),
@@ -594,7 +607,7 @@ static void catch_exception(except_T *excp)
} else {
vim_snprintf((char *)IObuff, IOSIZE, "%s", excp->throw_name);
}
- set_vim_var_string(VV_THROWPOINT, (char *) IObuff, -1);
+ set_vim_var_string(VV_THROWPOINT, (char *)IObuff, -1);
} else {
// throw_name not set on an exception from a command that was typed.
set_vim_var_string(VV_THROWPOINT, NULL, -1);
@@ -603,24 +616,27 @@ static void catch_exception(except_T *excp)
if (p_verbose >= 13 || debug_break_level > 0) {
int save_msg_silent = msg_silent;
- if (debug_break_level > 0)
- msg_silent = FALSE; /* display messages */
- else
+ if (debug_break_level > 0) {
+ msg_silent = FALSE; // display messages
+ } else {
verbose_enter();
+ }
++no_wait_return;
- if (debug_break_level > 0 || *p_vfile == NUL)
- msg_scroll = TRUE; /* always scroll up, don't overwrite */
-
+ if (debug_break_level > 0 || *p_vfile == NUL) {
+ msg_scroll = TRUE; // always scroll up, don't overwrite
+ }
smsg(_("Exception caught: %s"), excp->value);
msg_puts("\n"); // don't overwrite this either
- if (debug_break_level > 0 || *p_vfile == NUL)
+ if (debug_break_level > 0 || *p_vfile == NUL) {
cmdline_row = msg_row;
+ }
--no_wait_return;
- if (debug_break_level > 0)
+ if (debug_break_level > 0) {
msg_silent = save_msg_silent;
- else
+ } else {
verbose_leave();
+ }
}
}
@@ -634,7 +650,7 @@ static void finish_exception(except_T *excp)
}
caught_stack = caught_stack->caught;
if (caught_stack != NULL) {
- set_vim_var_string(VV_EXCEPTION, (char *) caught_stack->value, -1);
+ set_vim_var_string(VV_EXCEPTION, (char *)caught_stack->value, -1);
if (*caught_stack->throw_name != NUL) {
if (caught_stack->throw_lnum != 0) {
vim_snprintf((char *)IObuff, IOSIZE,
@@ -644,7 +660,7 @@ static void finish_exception(except_T *excp)
vim_snprintf((char *)IObuff, IOSIZE, "%s",
caught_stack->throw_name);
}
- set_vim_var_string(VV_THROWPOINT, (char *) IObuff, -1);
+ set_vim_var_string(VV_THROWPOINT, (char *)IObuff, -1);
} else {
// throw_name not set on an exception from a command that was
// typed.
@@ -688,7 +704,7 @@ static void report_pending(int action, int pending, void *value)
case RP_RESUME:
mesg = _("%s resumed");
break;
- /* case RP_DISCARD: */
+ // case RP_DISCARD:
default:
mesg = _("%s discarded");
break;
@@ -708,7 +724,7 @@ static void report_pending(int action, int pending, void *value)
s = ":finish";
break;
case CSTP_RETURN:
- /* ":return" command producing value, allocated */
+ // ":return" command producing value, allocated
s = (char *)get_return_cmd(value);
break;
@@ -718,30 +734,34 @@ static void report_pending(int action, int pending, void *value)
mesg, _("Exception"));
mesg = (char *)concat_str(IObuff, (char_u *)": %s");
s = (char *)((except_T *)value)->value;
- } else if ((pending & CSTP_ERROR) && (pending & CSTP_INTERRUPT))
+ } else if ((pending & CSTP_ERROR) && (pending & CSTP_INTERRUPT)) {
s = _("Error and interrupt");
- else if (pending & CSTP_ERROR)
+ } else if (pending & CSTP_ERROR) {
s = _("Error");
- else /* if (pending & CSTP_INTERRUPT) */
+ } else { // if (pending & CSTP_INTERRUPT)
s = _("Interrupt");
+ }
}
save_msg_silent = msg_silent;
- if (debug_break_level > 0)
- msg_silent = FALSE; /* display messages */
+ if (debug_break_level > 0) {
+ msg_silent = FALSE; // display messages
+ }
++no_wait_return;
- msg_scroll = TRUE; /* always scroll up, don't overwrite */
+ msg_scroll = TRUE; // always scroll up, don't overwrite
smsg(mesg, s);
msg_puts("\n"); // don't overwrite this either
cmdline_row = msg_row;
--no_wait_return;
- if (debug_break_level > 0)
+ if (debug_break_level > 0) {
msg_silent = save_msg_silent;
+ }
- if (pending == CSTP_RETURN)
+ if (pending == CSTP_RETURN) {
xfree(s);
- else if (pending & CSTP_THROW)
+ } else if (pending & CSTP_THROW) {
xfree(mesg);
+ }
}
/*
@@ -751,11 +771,13 @@ static void report_pending(int action, int pending, void *value)
void report_make_pending(int pending, void *value)
{
if (p_verbose >= 14 || debug_break_level > 0) {
- if (debug_break_level <= 0)
+ if (debug_break_level <= 0) {
verbose_enter();
+ }
report_pending(RP_MAKE, pending, value);
- if (debug_break_level <= 0)
+ if (debug_break_level <= 0) {
verbose_leave();
+ }
}
}
@@ -766,11 +788,13 @@ void report_make_pending(int pending, void *value)
void report_resume_pending(int pending, void *value)
{
if (p_verbose >= 14 || debug_break_level > 0) {
- if (debug_break_level <= 0)
+ if (debug_break_level <= 0) {
verbose_enter();
+ }
report_pending(RP_RESUME, pending, value);
- if (debug_break_level <= 0)
+ if (debug_break_level <= 0) {
verbose_leave();
+ }
}
}
@@ -781,11 +805,13 @@ void report_resume_pending(int pending, void *value)
void report_discard_pending(int pending, void *value)
{
if (p_verbose >= 14 || debug_break_level > 0) {
- if (debug_break_level <= 0)
+ if (debug_break_level <= 0) {
verbose_enter();
+ }
report_pending(RP_DISCARD, pending, value);
- if (debug_break_level <= 0)
+ if (debug_break_level <= 0) {
verbose_leave();
+ }
}
}
@@ -808,9 +834,9 @@ void ex_if(exarg_T *eap)
int result;
cstack_T *const cstack = eap->cstack;
- if (cstack->cs_idx == CSTACK_LEN - 1)
+ if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = (char_u *)N_("E579: :if nesting too deep");
- else {
+ } else {
++cstack->cs_idx;
cstack->cs_flags[cstack->cs_idx] = 0;
@@ -820,11 +846,13 @@ void ex_if(exarg_T *eap)
result = eval_to_bool(eap->arg, &error, &eap->nextcmd, skip);
if (!skip && !error) {
- if (result)
+ if (result) {
cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE | CSF_TRUE;
- } else
- /* set TRUE, so this conditional will never get active */
+ }
+ } else {
+ // set TRUE, so this conditional will never get active
cstack->cs_flags[cstack->cs_idx] = CSF_TRUE;
+ }
}
}
@@ -884,13 +912,15 @@ void ex_else(exarg_T *eap)
skip = TRUE;
}
- /* if skipping or the ":if" was TRUE, reset ACTIVE, otherwise set it */
+ // if skipping or the ":if" was TRUE, reset ACTIVE, otherwise set it
if (skip || cstack->cs_flags[cstack->cs_idx] & CSF_TRUE) {
- if (eap->errmsg == NULL)
+ if (eap->errmsg == NULL) {
cstack->cs_flags[cstack->cs_idx] = CSF_TRUE;
- skip = TRUE; /* don't evaluate an ":elseif" */
- } else
+ }
+ skip = TRUE; // don't evaluate an ":elseif"
+ } else {
cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE;
+ }
/*
* When debugging or a breakpoint was encountered, display the debug prompt
@@ -917,15 +947,18 @@ void ex_else(exarg_T *eap)
* case, the parsing error will be ignored by emsg(). */
if (!skip && !error) {
- if (result)
+ if (result) {
cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE | CSF_TRUE;
- else
+ } else {
cstack->cs_flags[cstack->cs_idx] = 0;
- } else if (eap->errmsg == NULL)
- /* set TRUE, so this conditional will never get active */
+ }
+ } else if (eap->errmsg == NULL) {
+ // set TRUE, so this conditional will never get active
cstack->cs_flags[cstack->cs_idx] = CSF_TRUE;
- } else
+ }
+ } else {
cstack->cs_flags[cstack->cs_idx] |= CSF_ELSE;
+ }
}
/*
@@ -938,9 +971,9 @@ void ex_while(exarg_T *eap)
int result;
cstack_T *const cstack = eap->cstack;
- if (cstack->cs_idx == CSTACK_LEN - 1)
+ if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = (char_u *)N_("E585: :while/:for nesting too deep");
- else {
+ } else {
/*
* The loop flag is set when we have jumped back from the matching
* ":endwhile" or ":endfor". When not set, need to initialise this
@@ -972,16 +1005,17 @@ void ex_while(exarg_T *eap)
fi = cstack->cs_forinfo[cstack->cs_idx];
error = FALSE;
} else {
- /* Evaluate the argument and get the info in a structure. */
+ // Evaluate the argument and get the info in a structure.
fi = eval_for_line(eap->arg, &error, &eap->nextcmd, skip);
cstack->cs_forinfo[cstack->cs_idx] = fi;
}
- /* use the element at the start of the list and advance */
- if (!error && fi != NULL && !skip)
+ // use the element at the start of the list and advance
+ if (!error && fi != NULL && !skip) {
result = next_for_item(fi, eap->arg);
- else
+ } else {
result = FALSE;
+ }
if (!result) {
free_for_info(fi);
@@ -1003,8 +1037,9 @@ void ex_while(exarg_T *eap)
* the list, show the debug prompt at the ":endwhile"/":endfor" as
* if there was a ":break" in a ":while"/":for" evaluating to
* TRUE. */
- if (!skip && !error)
+ if (!skip && !error) {
cstack->cs_flags[cstack->cs_idx] |= CSF_TRUE;
+ }
}
}
}
@@ -1017,9 +1052,9 @@ void ex_continue(exarg_T *eap)
int idx;
cstack_T *const cstack = eap->cstack;
- if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0)
+ if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = (char_u *)N_("E586: :continue without :while or :for");
- else {
+ } else {
/* Try to find the matching ":while". This might stop at a try
* conditional not in its finally clause (which is then to be executed
* next). Therefore, deactivate all conditionals except the ":while"
@@ -1033,7 +1068,7 @@ void ex_continue(exarg_T *eap)
* 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 */
+ cstack->cs_lflags |= CSL_HAD_CONT; // let do_cmdline() handle it
} else {
/* If a try conditional not in its finally clause is reached first,
* make the ":continue" pending for execution at the ":endtry". */
@@ -1073,7 +1108,7 @@ void ex_endwhile(exarg_T *eap)
{
cstack_T *const cstack = eap->cstack;
int idx;
- char_u *err;
+ char_u *err;
int csf;
int fl;
@@ -1085,24 +1120,26 @@ void ex_endwhile(exarg_T *eap)
csf = CSF_FOR;
}
- if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0)
+ if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = err;
- else {
+ } else {
fl = cstack->cs_flags[cstack->cs_idx];
if (!(fl & csf)) {
/* If we are in a ":while" or ":for" but used the wrong endloop
* command, do not rewind to the next enclosing ":for"/":while". */
- if (fl & CSF_WHILE)
+ if (fl & CSF_WHILE) {
eap->errmsg = (char_u *)_("E732: Using :endfor with :while");
- else if (fl & CSF_FOR)
+ } else if (fl & CSF_FOR) {
eap->errmsg = (char_u *)_("E733: Using :endwhile with :for");
+ }
}
if (!(fl & (CSF_WHILE | CSF_FOR))) {
- if (!(fl & CSF_TRY))
+ if (!(fl & CSF_TRY)) {
eap->errmsg = e_endif;
- else if (fl & CSF_FINALLY)
+ } else if (fl & CSF_FINALLY) {
eap->errmsg = e_endtry;
- /* Try to find the matching ":while" and report what's missing. */
+ }
+ // Try to find the matching ":while" and report what's missing.
for (idx = cstack->cs_idx; idx > 0; --idx) {
fl = cstack->cs_flags[idx];
if ((fl & CSF_TRY) && !(fl & CSF_FINALLY)) {
@@ -1111,10 +1148,11 @@ void ex_endwhile(exarg_T *eap)
eap->errmsg = err;
return;
}
- if (fl & csf)
+ if (fl & csf) {
break;
+ }
}
- /* Cleanup and rewind all contained (and unclosed) conditionals. */
+ // Cleanup and rewind all contained (and unclosed) conditionals.
(void)cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE);
rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel);
}
@@ -1130,8 +1168,9 @@ void ex_endwhile(exarg_T *eap)
*/
else if (cstack->cs_flags[cstack->cs_idx] & CSF_TRUE
&& !(cstack->cs_flags[cstack->cs_idx] & CSF_ACTIVE)
- && dbg_check_skipped(eap))
+ && dbg_check_skipped(eap)) {
(void)do_intthrow(cstack);
+ }
/*
* Set loop flag, so do_cmdline() will jump back to the matching
@@ -1216,13 +1255,14 @@ void do_throw(cstack_T *cstack)
* the matching catch clause or the finally clause.
*/
if (!(cstack->cs_flags[idx] & CSF_CAUGHT)) {
- if (cstack->cs_flags[idx] & CSF_ACTIVE)
+ if (cstack->cs_flags[idx] & CSF_ACTIVE) {
cstack->cs_flags[idx] |= CSF_THROWN;
- else
+ } else {
/* THROWN may have already been set for a catchable exception
* that has been discarded. Ensure it is reset for the new
* exception. */
cstack->cs_flags[idx] &= ~CSF_THROWN;
+ }
}
cstack->cs_flags[idx] &= ~CSF_ACTIVE;
cstack->cs_exception[idx] = current_exception;
@@ -1237,9 +1277,9 @@ void ex_try(exarg_T *eap)
int skip;
cstack_T *const cstack = eap->cstack;
- if (cstack->cs_idx == CSTACK_LEN - 1)
+ if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = (char_u *)N_("E601: :try nesting too deep");
- else {
+ } else {
++cstack->cs_idx;
++cstack->cs_trylevel;
cstack->cs_flags[cstack->cs_idx] = CSF_TRY;
@@ -1278,7 +1318,6 @@ void ex_try(exarg_T *eap)
emsg_silent = 0;
}
}
-
}
}
@@ -1291,13 +1330,13 @@ void ex_catch(exarg_T *eap)
int give_up = FALSE;
int skip = FALSE;
int caught = FALSE;
- char_u *end;
+ char_u *end;
char_u save_char = 0;
- char_u *save_cpo;
+ char_u *save_cpo;
regmatch_T regmatch;
int prev_got_int;
cstack_T *const cstack = eap->cstack;
- char_u *pat;
+ char_u *pat;
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = (char_u *)N_("E603: :catch without :try");
@@ -1309,20 +1348,23 @@ void ex_catch(exarg_T *eap)
eap->errmsg = get_end_emsg(cstack);
skip = TRUE;
}
- for (idx = cstack->cs_idx; idx > 0; --idx)
- if (cstack->cs_flags[idx] & CSF_TRY)
+ for (idx = cstack->cs_idx; idx > 0; --idx) {
+ if (cstack->cs_flags[idx] & CSF_TRY) {
break;
+ }
+ }
if (cstack->cs_flags[idx] & CSF_FINALLY) {
/* Give up for a ":catch" after ":finally" and ignore it.
* Just parse. */
eap->errmsg = (char_u *)N_("E604: :catch after :finally");
give_up = TRUE;
- } else
+ } else {
rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR,
- &cstack->cs_looplevel);
+ &cstack->cs_looplevel);
+ }
}
- if (ends_excmd(*eap->arg)) { /* no argument, catch all errors */
+ if (ends_excmd(*eap->arg)) { // no argument, catch all errors
pat = (char_u *)".*";
end = NULL;
eap->nextcmd = find_nextcmd(eap->arg);
@@ -1390,7 +1432,7 @@ void ex_catch(exarg_T *eap)
prev_got_int = got_int;
got_int = FALSE;
caught = vim_regexec_nl(&regmatch, current_exception->value,
- (colnr_T)0);
+ (colnr_T)0);
got_int |= prev_got_int;
vim_regfree(regmatch.regprog);
}
@@ -1430,8 +1472,9 @@ void ex_catch(exarg_T *eap)
}
}
- if (end != NULL)
+ if (end != NULL) {
eap->nextcmd = find_nextcmd(end);
+ }
}
/*
@@ -1444,28 +1487,31 @@ void ex_finally(exarg_T *eap)
int pending = CSTP_NONE;
cstack_T *const cstack = eap->cstack;
- if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0)
+ if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = (char_u *)N_("E606: :finally without :try");
- else {
+ } else {
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) {
eap->errmsg = get_end_emsg(cstack);
- for (idx = cstack->cs_idx - 1; idx > 0; --idx)
- if (cstack->cs_flags[idx] & CSF_TRY)
+ for (idx = cstack->cs_idx - 1; idx > 0; --idx) {
+ if (cstack->cs_flags[idx] & CSF_TRY) {
break;
+ }
+ }
/* Make this error pending, so that the commands in the following
* finally clause can be executed. This overrules also a pending
* ":continue", ":break", ":return", or ":finish". */
pending = CSTP_ERROR;
- } else
+ } else {
idx = cstack->cs_idx;
+ }
if (cstack->cs_flags[idx] & CSF_FINALLY) {
- /* Give up for a multiple ":finally" and ignore it. */
+ // Give up for a multiple ":finally" and ignore it.
eap->errmsg = (char_u *)N_("E607: multiple :finally");
return;
}
rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR,
- &cstack->cs_looplevel);
+ &cstack->cs_looplevel);
/*
* Don't do something when the corresponding try block never got active
@@ -1517,7 +1563,7 @@ void ex_finally(exarg_T *eap)
if (pending == CSTP_ERROR || did_emsg || got_int || current_exception) {
if (cstack->cs_pending[cstack->cs_idx] == CSTP_RETURN) {
report_discard_pending(CSTP_RETURN,
- cstack->cs_rettv[cstack->cs_idx]);
+ cstack->cs_rettv[cstack->cs_idx]);
discard_pending_return(cstack->cs_rettv[cstack->cs_idx]);
}
if (pending == CSTP_ERROR && !did_emsg) {
@@ -1564,7 +1610,7 @@ void ex_endtry(exarg_T *eap)
int skip;
int rethrow = FALSE;
int pending = CSTP_NONE;
- void *rettv = NULL;
+ void *rettv = NULL;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) {
@@ -1585,13 +1631,13 @@ void ex_endtry(exarg_T *eap)
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) {
eap->errmsg = get_end_emsg(cstack);
- /* Find the matching ":try" and report what's missing. */
+ // Find the matching ":try" and report what's missing.
idx = cstack->cs_idx;
do
--idx;
while (idx > 0 && !(cstack->cs_flags[idx] & CSF_TRY));
rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR,
- &cstack->cs_looplevel);
+ &cstack->cs_looplevel);
skip = TRUE;
/*
@@ -1656,10 +1702,11 @@ void ex_endtry(exarg_T *eap)
if (!skip) {
pending = cstack->cs_pending[idx];
cstack->cs_pending[idx] = CSTP_NONE;
- if (pending == CSTP_RETURN)
+ if (pending == CSTP_RETURN) {
rettv = cstack->cs_rettv[idx];
- else if (pending & CSTP_THROW)
+ } else if (pending & CSTP_THROW) {
current_exception = cstack->cs_exception[idx];
+ }
}
/*
@@ -1679,8 +1726,8 @@ void ex_endtry(exarg_T *eap)
if (!skip) {
report_resume_pending(pending,
- (pending == CSTP_RETURN) ? rettv :
- (pending & CSTP_THROW) ? (void *)current_exception : NULL);
+ (pending == CSTP_RETURN) ? rettv :
+ (pending & CSTP_THROW) ? (void *)current_exception : NULL);
switch (pending) {
case CSTP_NONE:
break;
@@ -1788,7 +1835,7 @@ void enter_cleanup(cleanup_T *csp)
did_emsg = got_int = need_rethrow = false;
current_exception = NULL;
- /* Report if required by the 'verbose' option or when debugging. */
+ // Report if required by the 'verbose' option or when debugging.
report_make_pending(pending, csp->exception);
} else {
csp->pending = CSTP_NONE;
@@ -1815,8 +1862,9 @@ void leave_cleanup(cleanup_T *csp)
{
int pending = csp->pending;
- if (pending == CSTP_NONE) /* nothing to do */
+ if (pending == CSTP_NONE) { // nothing to do
return;
+ }
/* If there was an aborting error, an interrupt, or an uncaught exception
* after the corresponding call to enter_cleanup(), discard what has been
@@ -1832,8 +1880,9 @@ void leave_cleanup(cleanup_T *csp)
/* If an error was about to be converted to an exception when
* enter_cleanup() was called, free the message list. */
- if (msg_list != NULL)
+ if (msg_list != NULL) {
free_global_msglist();
+ }
}
/*
* If there was no new error, interrupt, or throw between the calls
@@ -1846,9 +1895,9 @@ void leave_cleanup(cleanup_T *csp)
* called, we need to rethrow it. Make it the exception currently
* being thrown.
*/
- if (pending & CSTP_THROW)
+ if (pending & CSTP_THROW) {
current_exception = csp->exception;
-
+ }
/*
* If an error was about to be converted to an exception when
* enter_cleanup() was called, let "cause_abort" take the part of
@@ -1871,8 +1920,7 @@ void leave_cleanup(cleanup_T *csp)
}
// Report if required by the 'verbose' option or when debugging.
- report_resume_pending(
- pending, ((pending & CSTP_THROW) ? (void *)current_exception : NULL));
+ report_resume_pending(pending, ((pending & CSTP_THROW) ? (void *)current_exception : NULL));
}
}
@@ -1920,7 +1968,7 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
case CSTP_RETURN:
report_discard_pending(CSTP_RETURN,
- cstack->cs_rettv[idx]);
+ cstack->cs_rettv[idx]);
discard_pending_return(cstack->cs_rettv[idx]);
cstack->cs_pending[idx] = CSTP_NONE;
break;
@@ -1948,15 +1996,17 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
*/
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_CAUGHT)) {
finish_exception((except_T *)cstack->cs_exception[idx]);
+ }
/* Stop at this try conditional - except the try block never
* got active (because of an inactive surrounding conditional
* or when the ":try" appeared after an error or interrupt or
* throw). */
if (cstack->cs_flags[idx] & CSF_TRUE) {
- if (searched_cond == 0 && !inclusive)
+ if (searched_cond == 0 && !inclusive) {
break;
+ }
stop = TRUE;
}
}
@@ -1967,13 +2017,15 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
* If "inclusive" is TRUE and "searched_cond" is CSF_TRY|CSF_SILENT,
* check first whether "emsg_silent" needs to be restored. */
if (cstack->cs_flags[idx] & searched_cond) {
- if (!inclusive)
+ if (!inclusive) {
break;
+ }
stop = TRUE;
}
cstack->cs_flags[idx] &= ~CSF_ACTIVE;
- if (stop && searched_cond != (CSF_TRY | CSF_SILENT))
+ if (stop && searched_cond != (CSF_TRY | CSF_SILENT)) {
break;
+ }
/*
* When leaving a try conditional that reset "emsg_silent" on its
@@ -1982,7 +2034,7 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
*/
if ((cstack->cs_flags[idx] & CSF_TRY)
&& (cstack->cs_flags[idx] & CSF_SILENT)) {
- eslist_T *elem;
+ eslist_T *elem;
elem = cstack->cs_emsg_silent_list;
cstack->cs_emsg_silent_list = elem->next;
@@ -1990,8 +2042,9 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
xfree(elem);
cstack->cs_flags[idx] &= ~CSF_SILENT;
}
- if (stop)
+ if (stop) {
break;
+ }
}
return idx;
}
@@ -2001,10 +2054,12 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
*/
static char_u *get_end_emsg(cstack_T *cstack)
{
- if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE)
+ if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) {
return e_endwhile;
- if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR)
+ }
+ if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) {
return e_endfor;
+ }
return e_endif;
}
@@ -2016,14 +2071,15 @@ static char_u *get_end_emsg(cstack_T *cstack)
* type.
* Also free "for info" structures where needed.
*/
-void rewind_conditionals(cstack_T *cstack, int idx, int cond_type,
- int *cond_level)
+void rewind_conditionals(cstack_T *cstack, int idx, int cond_type, int *cond_level)
{
while (cstack->cs_idx > idx) {
- if (cstack->cs_flags[cstack->cs_idx] & cond_type)
+ if (cstack->cs_flags[cstack->cs_idx] & cond_type) {
--*cond_level;
- if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR)
+ }
+ if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) {
free_for_info(cstack->cs_forinfo[cstack->cs_idx]);
+ }
--cstack->cs_idx;
}
}
@@ -2043,18 +2099,21 @@ int has_loop_cmd(char_u *p)
{
int len;
- /* skip modifiers, white space and ':' */
+ // skip modifiers, white space and ':'
for (;; ) {
- while (*p == ' ' || *p == '\t' || *p == ':')
+ while (*p == ' ' || *p == '\t' || *p == ':') {
++p;
+ }
len = modifier_len(p);
- if (len == 0)
+ if (len == 0) {
break;
+ }
p += len;
}
if ((p[0] == 'w' && p[1] == 'h')
- || (p[0] == 'f' && p[1] == 'o' && p[2] == 'r'))
+ || (p[0] == 'f' && p[1] == 'o' && p[2] == 'r')) {
return TRUE;
+ }
return FALSE;
}
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index b90773ce83..ee96ec1c3b 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -6,49 +6,56 @@
*/
#include <assert.h>
+#include <inttypes.h>
#include <stdbool.h>
-#include <string.h>
#include <stdlib.h>
-#include <inttypes.h>
+#include <string.h>
-#include "nvim/assert.h"
-#include "nvim/log.h"
-#include "nvim/vim.h"
-#include "nvim/ascii.h"
+#include "nvim/api/private/helpers.h"
#include "nvim/arabic.h"
-#include "nvim/ex_getln.h"
+#include "nvim/ascii.h"
+#include "nvim/assert.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
+#include "nvim/cursor_shape.h"
#include "nvim/digraph.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/eval/userfunc.h"
+#include "nvim/event/loop.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
+#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/func_attr.h"
+#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/highlight.h"
+#include "nvim/highlight_defs.h"
#include "nvim/if_cscope.h"
#include "nvim/indent.h"
+#include "nvim/keymap.h"
+#include "nvim/lib/kvec.h"
+#include "nvim/log.h"
+#include "nvim/lua/executor.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
+#include "nvim/memory.h"
#include "nvim/menu.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/memory.h"
-#include "nvim/cursor_shape.h"
-#include "nvim/keymap.h"
-#include "nvim/garray.h"
-#include "nvim/move.h"
#include "nvim/mouse.h"
+#include "nvim/move.h"
#include "nvim/ops.h"
#include "nvim/option.h"
+#include "nvim/os/input.h"
+#include "nvim/os/os.h"
+#include "nvim/os/time.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/popupmnu.h"
@@ -56,22 +63,15 @@
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/sign.h"
-#include "nvim/strings.h"
#include "nvim/state.h"
+#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/tag.h"
-#include "nvim/window.h"
#include "nvim/ui.h"
-#include "nvim/os/input.h"
-#include "nvim/os/os.h"
-#include "nvim/event/loop.h"
-#include "nvim/os/time.h"
-#include "nvim/lib/kvec.h"
-#include "nvim/api/private/helpers.h"
-#include "nvim/highlight_defs.h"
-#include "nvim/lua/executor.h"
-#include "nvim/viml/parser/parser.h"
+#include "nvim/vim.h"
#include "nvim/viml/parser/expressions.h"
+#include "nvim/viml/parser/parser.h"
+#include "nvim/window.h"
/// Command-line colors: one chunk
///
@@ -110,21 +110,21 @@ typedef enum {
* structure.
*/
struct cmdline_info {
- char_u *cmdbuff; // pointer to command line buffer
+ char_u *cmdbuff; // pointer to command line buffer
int cmdbufflen; // length of cmdbuff
int cmdlen; // number of chars in command line
int cmdpos; // current cursor position
int cmdspos; // cursor column on screen
int cmdfirstc; // ':', '/', '?', '=', '>' or NUL
int cmdindent; // number of spaces before cmdline
- char_u *cmdprompt; // message in front of cmdline
+ char_u *cmdprompt; // message in front of cmdline
int cmdattr; // attributes for prompt
int overstrike; // Typing mode on the command line. Shared by
// getcmdline() and put_on_cmdline().
- expand_T *xpc; // struct being used for expansion, xp_pattern
- // may point into cmdbuff
+ expand_T *xpc; // struct being used for expansion, xp_pattern
+ // may point into cmdbuff
int xp_context; // type of expansion
- char_u *xp_arg; // user-defined expansion arg
+ char_u *xp_arg; // user-defined expansion arg
int input_fn; // when TRUE Invoked for input() function
unsigned prompt_id; ///< Prompt number, used to disable coloring on errors.
Callback highlight_callback; ///< Callback used for coloring user input.
@@ -180,7 +180,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_u *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
@@ -198,9 +198,9 @@ typedef struct cmdline_info CmdlineInfo;
* TODO: make it local to getcmdline() and pass it around. */
static struct cmdline_info ccline;
-static int cmd_showtail; /* Only show path tail in lists ? */
+static int cmd_showtail; // Only show path tail in lists ?
-static int new_cmdpos; /* position set by set_cmdline_pos() */
+static int new_cmdpos; // position set by set_cmdline_pos()
/// currently displayed block of context
static Array cmdline_block = ARRAY_DICT_INIT;
@@ -210,11 +210,11 @@ static Array cmdline_block = ARRAY_DICT_INIT;
*/
typedef void *(*user_expand_func_T)(const char_u *, int, typval_T *);
-static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL};
-static int hisidx[HIST_COUNT] = {-1, -1, -1, -1, -1}; /* lastused entry */
-static int hisnum[HIST_COUNT] = {0, 0, 0, 0, 0};
-/* identifying (unique) number of newest history entry */
-static int hislen = 0; /* actual length of history tables */
+static histentry_T *(history[HIST_COUNT]) = { NULL, NULL, NULL, NULL, NULL };
+static int hisidx[HIST_COUNT] = { -1, -1, -1, -1, -1 }; // lastused entry
+static int hisnum[HIST_COUNT] = { 0, 0, 0, 0, 0 };
+// identifying (unique) number of newest history entry
+static int hislen = 0; // actual length of history tables
/// Flag for command_line_handle_key to ignore <C-c>
///
@@ -275,9 +275,8 @@ static void init_incsearch_state(incsearch_state_T *s)
// Return true when 'incsearch' highlighting is to be done.
// Sets search_first_line and search_last_line to the address range.
-static bool do_incsearch_highlighting(int firstc, int *search_delim,
- incsearch_state_T *s, int *skiplen,
- int *patlen)
+static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_state_T *s,
+ int *skiplen, int *patlen)
FUNC_ATTR_NONNULL_ALL
{
char_u *cmd;
@@ -425,8 +424,7 @@ theend:
}
// May do 'incsearch' highlighting if desired.
-static void may_do_incsearch_highlighting(int firstc, long count,
- incsearch_state_T *s)
+static void may_do_incsearch_highlighting(int firstc, long count, incsearch_state_T *s)
{
pos_T end_pos;
proftime_T tm;
@@ -472,7 +470,7 @@ static void may_do_incsearch_highlighting(int firstc, long count,
// Use the previous pattern for ":s//".
next_char = ccline.cmdbuff[skiplen + patlen];
use_last_pat = patlen == 0 && skiplen > 0
- && ccline.cmdbuff[skiplen - 1] == next_char;
+ && ccline.cmdbuff[skiplen - 1] == next_char;
// If there is no pattern, don't do anything.
if (patlen == 0 && !use_last_pat) {
@@ -624,8 +622,7 @@ static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s)
return OK;
}
-static void finish_incsearch_highlighting(int gotesc, incsearch_state_T *s,
- bool call_update_screen)
+static void finish_incsearch_highlighting(int gotesc, incsearch_state_T *s, bool call_update_screen)
{
if (s->did_incsearch) {
s->did_incsearch = false;
@@ -872,7 +869,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent)
&& s->firstc != NUL
&& (s->some_key_typed || s->histype == HIST_SEARCH)) {
add_to_history(s->histype, ccline.cmdbuff, true,
- s->histype == HIST_SEARCH ? s->firstc : NUL);
+ s->histype == HIST_SEARCH ? s->firstc : NUL);
if (s->firstc == ':') {
xfree(new_last_cmdline);
new_last_cmdline = vim_strsave(ccline.cmdbuff);
@@ -973,12 +970,18 @@ static int command_line_execute(VimState *state, int key)
// typed by the user directly, not when the result of a
// mapping.
switch (s->c) {
- case K_RIGHT: s->c = K_LEFT; break;
- case K_S_RIGHT: s->c = K_S_LEFT; break;
- case K_C_RIGHT: s->c = K_C_LEFT; break;
- case K_LEFT: s->c = K_RIGHT; break;
- case K_S_LEFT: s->c = K_S_RIGHT; break;
- case K_C_LEFT: s->c = K_C_RIGHT; break;
+ case K_RIGHT:
+ s->c = K_LEFT; break;
+ case K_S_RIGHT:
+ s->c = K_S_LEFT; break;
+ case K_C_RIGHT:
+ s->c = K_C_LEFT; break;
+ case K_LEFT:
+ s->c = K_RIGHT; break;
+ case K_S_LEFT:
+ s->c = K_S_RIGHT; break;
+ case K_C_LEFT:
+ s->c = K_C_RIGHT; break;
}
}
}
@@ -1078,7 +1081,7 @@ static int command_line_execute(VimState *state, int key)
redrawcmd();
save_p_ls = -1;
wild_menu_showing = 0;
- // don't redraw statusline if WM_LIST is showing
+ // don't redraw statusline if WM_LIST is showing
} else if (wild_menu_showing != WM_LIST) {
win_redraw_last_status(topframe);
wild_menu_showing = 0; // must be before redraw_statuslines #8385
@@ -1155,7 +1158,7 @@ static int command_line_execute(VimState *state, int key)
s->c = (int)p_wc;
KeyTyped = true; // in case the key was mapped
} else if (STRNCMP(s->xpc.xp_pattern, upseg + 1, 3) == 0
- && s->c == K_DOWN) {
+ && s->c == K_DOWN) {
// If in a direct ancestor, strip off one ../ to go down
int found = false;
@@ -1242,7 +1245,7 @@ static int command_line_execute(VimState *state, int key)
vungetc(s->c);
s->c = Ctrl_BSL;
} else if (s->c == 'e') {
- char_u *p = NULL;
+ char_u *p = NULL;
int len;
// Replace the command line with the result of an expression.
@@ -1318,7 +1321,7 @@ static int command_line_execute(VimState *state, int key)
|| s->c == '\r'
|| s->c == K_KENTER
|| (s->c == ESC
- && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) {
+ && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) {
// In Ex mode a backslash escapes a newline.
if (exmode_active
&& s->c != ESC
@@ -1419,7 +1422,7 @@ static int command_line_execute(VimState *state, int key)
}
(void)showmatches(&s->xpc, p_wmnu
- && ((wim_flags[s->wim_index] & WIM_LIST) == 0));
+ && ((wim_flags[s->wim_index] & WIM_LIST) == 0));
redrawcmd();
s->did_wild_list = true;
@@ -1464,7 +1467,7 @@ static int command_line_execute(VimState *state, int key)
}
}
- if (s->c == NUL || s->c == K_ZERO) {
+ if (s->c == NUL || s->c == K_ZERO) {
// NUL is stored as NL
s->c = NL;
}
@@ -1476,8 +1479,7 @@ static int command_line_execute(VimState *state, int key)
// May adjust 'incsearch' highlighting for typing CTRL-G and CTRL-T, go to next
// or previous match.
// Returns FAIL when calling command_line_not_changed.
-static int may_do_command_line_next_incsearch(int firstc, long count,
- incsearch_state_T *s,
+static int may_do_command_line_next_incsearch(int firstc, long count, incsearch_state_T *s,
bool next_match)
FUNC_ATTR_NONNULL_ALL
{
@@ -1656,7 +1658,7 @@ 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.cmdbuff + ccline.cmdpos);
}
if (ccline.cmdpos > 0) {
@@ -1980,8 +1982,9 @@ static int command_line_handle_key(CommandLineState *s)
return command_line_not_changed(s);
case Ctrl_A: // all matches
- if (nextwild(&s->xpc, WILD_ALL, 0, s->firstc != '@') == FAIL)
+ if (nextwild(&s->xpc, WILD_ALL, 0, s->firstc != '@') == FAIL) {
break;
+ }
return command_line_changed(s);
case Ctrl_L:
@@ -1999,7 +2002,7 @@ static int command_line_handle_key(CommandLineState *s)
case Ctrl_P: // previous match
if (s->xpc.xp_numfiles > 0) {
if (nextwild(&s->xpc, (s->c == Ctrl_P) ? WILD_PREV : WILD_NEXT,
- 0, s->firstc != '@') == FAIL) {
+ 0, s->firstc != '@') == FAIL) {
break;
}
return command_line_not_changed(s);
@@ -2033,7 +2036,7 @@ static int command_line_handle_key(CommandLineState *s)
if (s->hiscnt != s->save_hiscnt) {
// jumped to other entry
- char_u *p;
+ char_u *p;
int len = 0;
int old_firstc;
@@ -2261,7 +2264,6 @@ static int command_line_changed(CommandLineState *s)
update_topline(curwin);
redrawcmdline();
-
} else if (State & CMDPREVIEW) {
State = (State & ~CMDPREVIEW);
close_preview_windows();
@@ -2298,32 +2300,27 @@ static void abandon_cmdline(void)
redraw_cmdline = true;
}
-/*
- * getcmdline() - accept a command line starting with firstc.
- *
- * firstc == ':' get ":" command line.
- * firstc == '/' or '?' get search pattern
- * firstc == '=' get expression
- * firstc == '@' get text for input() function
- * firstc == '>' get text for debug mode
- * firstc == NUL get text for :insert command
- * firstc == -1 like NUL, and break on CTRL-C
- *
- * The line is collected in ccline.cmdbuff, which is reallocated to fit the
- * command line.
- *
- * Careful: getcmdline() can be called recursively!
- *
- * Return pointer to allocated string if there is a commandline, NULL
- * otherwise.
- */
-char_u *
-getcmdline (
- int firstc,
- long count, // only used for incremental search
- int indent, // indent for inside conditionals
- bool do_concat FUNC_ATTR_UNUSED
-)
+/// getcmdline() - accept a command line starting with firstc.
+///
+/// firstc == ':' get ":" command line.
+/// firstc == '/' or '?' get search pattern
+/// firstc == '=' get expression
+/// firstc == '@' get text for input() function
+/// firstc == '>' get text for debug mode
+/// firstc == NUL get text for :insert command
+/// firstc == -1 like NUL, and break on CTRL-C
+///
+/// The line is collected in ccline.cmdbuff, which is reallocated to fit the
+/// command line.
+///
+/// Careful: getcmdline() can be called recursively!
+///
+/// Return pointer to allocated string if there is a commandline, NULL
+/// otherwise.
+///
+/// @param count only used for incremental search
+/// @param indent indent for inside conditionals
+char_u *getcmdline(int firstc, long count, int indent, bool do_concat FUNC_ATTR_UNUSED)
{
// Be prepared for situations where cmdline can be invoked recursively.
// That includes cmd mappings, event handlers, as well as update_screen()
@@ -2348,9 +2345,8 @@ getcmdline (
/// @param[in] highlight_callback Callback used for highlighting user input.
///
/// @return [allocated] Command line or NULL.
-char *getcmdline_prompt(const char firstc, const char *const prompt,
- const int attr, const int xp_context,
- const char *const xp_arg,
+char *getcmdline_prompt(const char firstc, const char *const prompt, const int attr,
+ const int xp_context, const char *const xp_arg,
const Callback highlight_callback)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
{
@@ -2390,8 +2386,9 @@ char *getcmdline_prompt(const char firstc, const char *const prompt,
* another window or buffer. Used when editing the command line etc.
*/
int text_locked(void) {
- if (cmdwin_type != 0)
+ if (cmdwin_type != 0) {
return TRUE;
+ }
return textlock != 0;
}
@@ -2438,8 +2435,9 @@ int allbuf_locked(void)
static int cmdline_charsize(int idx)
{
- if (cmdline_star > 0) /* showing '*', always 1 position */
+ if (cmdline_star > 0) { // showing '*', always 1 position
return 1;
+ }
return ptr2cells(ccline.cmdbuff + idx);
}
@@ -2459,8 +2457,9 @@ static int cmd_screencol(int bytepos)
int col = cmd_startcol();
if (KeyTyped) {
m = Columns * Rows;
- if (m < 0) /* overflow, Columns or Rows at weird value */
+ if (m < 0) { // overflow, Columns or Rows at weird value
m = MAXCOL;
+ }
} else {
m = MAXCOL;
}
@@ -2492,20 +2491,16 @@ static void correct_screencol(int idx, int cells, int *col)
}
}
-/*
- * Get an Ex command line for the ":" command.
- */
-char_u *
-getexline(
- int c, // normally ':', NUL for ":append"
- void *cookie,
- int indent, // indent for inside conditionals
- bool do_concat
-)
+/// Get an Ex command line for the ":" command.
+///
+/// @param c normally ':', NUL for ":append"
+/// @param indent indent for inside conditionals
+char_u *getexline(int c, void *cookie, int indent, bool do_concat)
{
- /* When executing a register, remove ':' that's in front of each line. */
- if (exec_from_reg && vpeekc() == ':')
+ // When executing a register, remove ':' that's in front of each line.
+ if (exec_from_reg && vpeekc() == ':') {
(void)vgetc();
+ }
return getcmdline(c, 1L, indent, do_concat);
}
@@ -2532,10 +2527,11 @@ static void alloc_cmdbuff(int len)
/*
* give some extra space to avoid having to allocate all the time
*/
- if (len < 80)
+ if (len < 80) {
len = 100;
- else
+ } else {
len += 20;
+ }
ccline.cmdbuff = xmalloc((size_t)len);
ccline.cmdbufflen = len;
@@ -2551,7 +2547,7 @@ static void realloc_cmdbuff(int len)
}
char_u *p = ccline.cmdbuff;
- alloc_cmdbuff(len); /* will get some more */
+ 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. */
memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen);
@@ -2566,12 +2562,13 @@ static 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)
+ if (i >= 0 && i <= ccline.cmdlen) {
ccline.xpc->xp_pattern = ccline.cmdbuff + i;
+ }
}
}
-static char_u *arshape_buf = NULL;
+static char_u *arshape_buf = NULL;
# if defined(EXITFREE)
void free_arshape_buf(void)
@@ -2605,8 +2602,7 @@ static void color_expr_cmdline(const CmdlineInfo *const colored_ccline,
ParserHighlight colors;
kvi_init(colors);
ParserState pstate;
- viml_parser_init(
- &pstate, parser_simple_get_line, &plines_p, &colors);
+ viml_parser_init(&pstate, parser_simple_get_line, &plines_p, &colors);
ExprAST east = viml_pexpr_parse(&pstate, kExprFlagsDisallowEOC);
viml_pexpr_free_ast(east);
viml_parser_destroy(&pstate);
@@ -2626,9 +2622,9 @@ static void color_expr_cmdline(const CmdlineInfo *const colored_ccline,
const int id = syn_name2id((const char_u *)chunk.group);
const int attr = (id == 0 ? 0 : syn_id2attr(id));
kv_push(ret_ccline_colors->colors, ((CmdlineColorChunk) {
- .start = (int)chunk.start.col,
- .end = (int)chunk.end_col,
- .attr = attr,
+ .start = (int)chunk.start.col,
+ .end = (int)chunk.end_col,
+ .attr = attr,
}));
prev_end = chunk.end_col;
}
@@ -2716,8 +2712,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline)
color_cb = colored_ccline->highlight_callback;
} else if (colored_ccline->cmdfirstc == ':') {
try_enter(&tstate);
- err_errmsg = N_(
- "E5408: Unable to get g:Nvim_color_cmdline callback: %s");
+ err_errmsg = N_("E5408: Unable to get g:Nvim_color_cmdline callback: %s");
dgc_ret = tv_dict_get_callback(&globvardict, S_LEN("Nvim_color_cmdline"),
&color_cb);
tl_ret = try_leave(&tstate, &err);
@@ -2785,7 +2780,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline)
}
bool error = false;
const varnumber_T start = (
- tv_get_number_chk(TV_LIST_ITEM_TV(tv_list_first(l)), &error));
+ tv_get_number_chk(TV_LIST_ITEM_TV(tv_list_first(l)), &error));
if (error) {
goto color_cmdline_error;
} else if (!(prev_end <= start && start < colored_ccline->cmdlen)) {
@@ -2805,8 +2800,8 @@ static bool color_cmdline(CmdlineInfo *colored_ccline)
.attr = 0,
}));
}
- const varnumber_T end = tv_get_number_chk(
- TV_LIST_ITEM_TV(TV_LIST_ITEM_NEXT(l, tv_list_first(l))), &error);
+ const varnumber_T end =
+ tv_get_number_chk(TV_LIST_ITEM_TV(TV_LIST_ITEM_NEXT(l, tv_list_first(l))), &error);
if (error) {
goto color_cmdline_error;
} else if (!(start < end && end <= colored_ccline->cmdlen)) {
@@ -2822,8 +2817,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline)
goto color_cmdline_error;
}
prev_end = end;
- const char *const group = tv_get_string_chk(
- TV_LIST_ITEM_TV(tv_list_last(l)));
+ const char *const group = tv_get_string_chk(TV_LIST_ITEM_TV(tv_list_last(l)));
if (group == NULL) {
goto color_cmdline_error;
}
@@ -3141,8 +3135,8 @@ void putcmdline(char c, int shift)
}
msg_no_more = false;
} else if (ccline.redraw_state != kCmdRedrawAll) {
- ui_call_cmdline_special_char(cchar_to_string((char)(c)), shift,
- ccline.level);
+ ui_call_cmdline_special_char(cchar_to_string((char)(c)), shift,
+ ccline.level);
}
cursorcmd();
ccline.special_char = c;
@@ -3182,15 +3176,16 @@ void put_on_cmdline(char_u *str, int len, int redraw)
int m;
int c;
- if (len < 0)
+ if (len < 0) {
len = (int)STRLEN(str);
+ }
realloc_cmdbuff(ccline.cmdlen + len + 1);
if (!ccline.overstrike) {
memmove(ccline.cmdbuff + ccline.cmdpos + len,
- ccline.cmdbuff + ccline.cmdpos,
- (size_t)(ccline.cmdlen - ccline.cmdpos));
+ ccline.cmdbuff + ccline.cmdpos,
+ (size_t)(ccline.cmdlen - ccline.cmdpos));
ccline.cmdlen += len;
} else {
// Count nr of characters in the new string.
@@ -3232,11 +3227,12 @@ void put_on_cmdline(char_u *str, int len, int redraw)
if (arabic_combine(utf_ptr2char(ccline.cmdbuff + ccline.cmdpos - i), c)) {
ccline.cmdpos -= i;
len += i;
- } else
+ } else {
i = 0;
+ }
}
if (i != 0) {
- /* Also backup the cursor position. */
+ // Also backup the cursor position.
i = ptr2cells(ccline.cmdbuff + ccline.cmdpos);
ccline.cmdspos -= i;
msg_col -= i;
@@ -3252,9 +3248,10 @@ void put_on_cmdline(char_u *str, int len, int redraw)
i = cmdline_row;
cursorcmd();
draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
- /* Avoid clearing the rest of the line too often. */
- if (cmdline_row != i || ccline.overstrike)
+ // Avoid clearing the rest of the line too often.
+ if (cmdline_row != i || ccline.overstrike) {
msg_clr_eos();
+ }
msg_no_more = FALSE;
}
if (KeyTyped) {
@@ -3348,8 +3345,8 @@ void restore_cmdline_alloc(char_u *p)
/// @returns FAIL for failure, OK otherwise
static bool cmdline_paste(int regname, bool literally, bool remcr)
{
- char_u *arg;
- char_u *p;
+ char_u *arg;
+ char_u *p;
bool allocated;
struct cmdline_info save_ccline;
@@ -3364,8 +3361,9 @@ static bool cmdline_paste(int regname, bool literally, bool remcr)
/* A register containing CTRL-R can cause an endless loop. Allow using
* CTRL-C to break the loop. */
line_breakcheck();
- if (got_int)
+ if (got_int) {
return FAIL;
+ }
/* Need to save and restore ccline. And set "textlock" to avoid nasty
@@ -3377,18 +3375,19 @@ static bool cmdline_paste(int regname, bool literally, bool remcr)
restore_cmdline(&save_ccline);
if (i) {
- /* Got the value of a special register in "arg". */
- if (arg == NULL)
+ // Got the value of a special register in "arg".
+ if (arg == NULL) {
return FAIL;
+ }
/* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate
* part of the word. */
p = arg;
if (p_is && regname == Ctrl_W) {
- char_u *w;
+ char_u *w;
int len;
- /* Locate start of last word in the cmd buffer. */
+ // 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;
if (!vim_iswordc(utf_ptr2char(w - len))) {
@@ -3397,13 +3396,15 @@ static bool cmdline_paste(int regname, bool literally, bool remcr)
w -= len;
}
len = (int)((ccline.cmdbuff + ccline.cmdpos) - w);
- if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0)
+ if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) {
p += len;
+ }
}
cmdline_paste_str(p, literally);
- if (allocated)
+ if (allocated) {
xfree(arg);
+ }
return OK;
}
@@ -3420,9 +3421,9 @@ void cmdline_paste_str(char_u *s, int literally)
{
int c, cv;
- if (literally)
+ if (literally) {
put_on_cmdline(s, -1, TRUE);
- else
+ } else {
while (*s != NUL) {
cv = *s;
if (cv == Ctrl_V && s[1]) {
@@ -3436,6 +3437,7 @@ void cmdline_paste_str(char_u *s, int literally)
}
stuffcharReadbuff(c);
}
+ }
}
/// Delete characters on the command line, from "from" to the current position.
@@ -3453,8 +3455,9 @@ static void cmdline_del(int from)
// overwritten.
void redrawcmdline(void)
{
- if (cmd_silent)
+ if (cmd_silent) {
return;
+ }
need_wait_return = false;
compute_cmdrow();
redrawcmd();
@@ -3466,8 +3469,9 @@ static void redrawcmdprompt(void)
{
int i;
- if (cmd_silent)
+ if (cmd_silent) {
return;
+ }
if (ui_has(kUICmdline)) {
ccline.redraw_state = kCmdRedrawAll;
return;
@@ -3494,15 +3498,16 @@ static void redrawcmdprompt(void)
*/
void redrawcmd(void)
{
- if (cmd_silent)
+ if (cmd_silent) {
return;
+ }
if (ui_has(kUICmdline)) {
draw_cmdline(0, ccline.cmdlen);
return;
}
- /* when 'incsearch' is set there may be no command line while redrawing */
+ // when 'incsearch' is set there may be no command line while redrawing
if (ccline.cmdbuff == NULL) {
cmd_cursor_goto(cmdline_row, 0);
msg_clr_eos();
@@ -3514,7 +3519,7 @@ void redrawcmd(void)
msg_start();
redrawcmdprompt();
- /* Don't use more prompt, truncate the cmdline if it doesn't fit. */
+ // Don't use more prompt, truncate the cmdline if it doesn't fit.
msg_no_more = TRUE;
draw_cmdline(0, ccline.cmdlen);
msg_clr_eos();
@@ -3530,7 +3535,7 @@ void redrawcmd(void)
* 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 */
+ msg_scroll = FALSE; // next message overwrites cmdline
// Typing ':' at the more prompt may set skip_redraw. We don't want this
// in cmdline mode.
@@ -3553,8 +3558,9 @@ void compute_cmdrow(void)
static void cursorcmd(void)
{
- if (cmd_silent)
+ if (cmd_silent) {
return;
+ }
if (ui_has(kUICmdline)) {
if (ccline.redraw_state < kCmdRedrawPos) {
@@ -3642,28 +3648,27 @@ static int sort_func_compare(const void *s1, const void *s2)
char_u *p1 = *(char_u **)s1;
char_u *p2 = *(char_u **)s2;
- if (*p1 != '<' && *p2 == '<') return -1;
- if (*p1 == '<' && *p2 != '<') return 1;
+ if (*p1 != '<' && *p2 == '<') {
+ return -1;
+ }
+ if (*p1 == '<' && *p2 != '<') {
+ return 1;
+ }
return STRCMP(p1, p2);
}
-/*
- * Return FAIL if this is not an appropriate context in which to do
- * completion of anything, return OK if it is (even if there are no matches).
- * For the caller, this means that the character is just passed through like a
- * normal character (instead of being expanded). This allows :s/^I^D etc.
- */
-static int
-nextwild (
- expand_T *xp,
- int type,
- int options, /* extra options for ExpandOne() */
- int escape /* if TRUE, escape the returned matches */
-)
+/// Return FAIL if this is not an appropriate context in which to do
+/// completion of anything, return OK if it is (even if there are no matches).
+/// For the caller, this means that the character is just passed through like a
+/// normal character (instead of being expanded). This allows :s/^I^D etc.
+///
+/// @param options extra options for ExpandOne()
+/// @param escape if TRUE, escape the returned matches
+static int nextwild(expand_T *xp, int type, int options, int escape)
{
int i, j;
- char_u *p1;
- char_u *p2;
+ char_u *p1;
+ char_u *p2;
int difflen;
if (xp->xp_numfiles == -1) {
@@ -3673,10 +3678,10 @@ nextwild (
if (xp->xp_context == EXPAND_UNSUCCESSFUL) {
beep_flush();
- return OK; /* Something illegal on command line */
+ return OK; // Something illegal on command line
}
if (xp->xp_context == EXPAND_NOTHING) {
- /* Caller can use the character as a normal char instead */
+ // Caller can use the character as a normal char instead
return FAIL;
}
@@ -3696,12 +3701,12 @@ nextwild (
// Translate string into pattern and expand it.
p1 = 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));
+ 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),
use_options, type);
xfree(p1);
@@ -3746,67 +3751,62 @@ nextwild (
/* When expanding a ":map" command and no matches are found, assume that
* the key is supposed to be inserted literally */
- if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL)
+ if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL) {
return FAIL;
+ }
- if (xp->xp_numfiles <= 0 && p2 == NULL)
+ if (xp->xp_numfiles <= 0 && p2 == NULL) {
beep_flush();
- else if (xp->xp_numfiles == 1)
- /* free expanded pattern */
+ } else if (xp->xp_numfiles == 1) {
+ // free expanded pattern
(void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE);
+ }
return OK;
}
-/*
- * Do wildcard expansion on the string 'str'.
- * Chars that should not be expanded must be preceded with a backslash.
- * Return a pointer to allocated memory containing the new string.
- * Return NULL for failure.
- *
- * "orig" is the originally expanded string, copied to allocated memory. It
- * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or
- * WILD_PREV "orig" should be NULL.
- *
- * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode"
- * is WILD_EXPAND_FREE or WILD_ALL.
- *
- * mode = WILD_FREE: just free previously expanded matches
- * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches
- * mode = WILD_EXPAND_KEEP: normal expansion, keep matches
- * mode = WILD_NEXT: use next match in multiple match, wrap to first
- * mode = WILD_PREV: use previous match in multiple match, wrap to first
- * mode = WILD_ALL: return all matches concatenated
- * mode = WILD_LONGEST: return longest matched part
- * mode = WILD_ALL_KEEP: get all matches, keep matches
- *
- * options = WILD_LIST_NOTFOUND: list entries without a match
- * options = WILD_HOME_REPLACE: do home_replace() for buffer names
- * options = WILD_USE_NL: Use '\n' for WILD_ALL
- * options = WILD_NO_BEEP: Don't beep for multiple matches
- * options = WILD_ADD_SLASH: add a slash after directory names
- * options = WILD_KEEP_ALL: don't remove 'wildignore' entries
- * options = WILD_SILENT: don't print warning messages
- * options = WILD_ESCAPE: put backslash before special chars
- * options = WILD_ICASE: ignore case for files
- *
- * The variables xp->xp_context and xp->xp_backslash must have been set!
- */
-char_u *
-ExpandOne (
- expand_T *xp,
- char_u *str,
- char_u *orig, /* allocated copy of original of expanded string */
- int options,
- int mode
-)
+/// Do wildcard expansion on the string 'str'.
+/// Chars that should not be expanded must be preceded with a backslash.
+/// Return a pointer to allocated memory containing the new string.
+/// Return NULL for failure.
+///
+/// "orig" is the originally expanded string, copied to allocated memory. It
+/// should either be kept in orig_save or freed. When "mode" is WILD_NEXT or
+/// WILD_PREV "orig" should be NULL.
+///
+/// Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode"
+/// is WILD_EXPAND_FREE or WILD_ALL.
+///
+/// mode = WILD_FREE: just free previously expanded matches
+/// mode = WILD_EXPAND_FREE: normal expansion, do not keep matches
+/// mode = WILD_EXPAND_KEEP: normal expansion, keep matches
+/// mode = WILD_NEXT: use next match in multiple match, wrap to first
+/// mode = WILD_PREV: use previous match in multiple match, wrap to first
+/// mode = WILD_ALL: return all matches concatenated
+/// mode = WILD_LONGEST: return longest matched part
+/// mode = WILD_ALL_KEEP: get all matches, keep matches
+///
+/// options = WILD_LIST_NOTFOUND: list entries without a match
+/// options = WILD_HOME_REPLACE: do home_replace() for buffer names
+/// options = WILD_USE_NL: Use '\n' for WILD_ALL
+/// options = WILD_NO_BEEP: Don't beep for multiple matches
+/// options = WILD_ADD_SLASH: add a slash after directory names
+/// options = WILD_KEEP_ALL: don't remove 'wildignore' entries
+/// options = WILD_SILENT: don't print warning messages
+/// options = WILD_ESCAPE: put backslash before special chars
+/// options = WILD_ICASE: ignore case for files
+///
+/// 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_u *ss = NULL;
+ char_u *ss = NULL;
static int findex;
- static char_u *orig_save = NULL; /* kept value of orig */
+ static char_u *orig_save = NULL; // kept value of orig
int orig_saved = FALSE;
int i;
- int non_suf_match; /* number without matching suffix */
+ int non_suf_match; // number without matching suffix
/*
* first handle the case of using an old match
@@ -3814,27 +3814,31 @@ ExpandOne (
if (mode == WILD_NEXT || mode == WILD_PREV) {
if (xp->xp_numfiles > 0) {
if (mode == WILD_PREV) {
- if (findex == -1)
+ if (findex == -1) {
findex = xp->xp_numfiles;
+ }
--findex;
- } else /* mode == WILD_NEXT */
+ } else { // mode == WILD_NEXT
++findex;
+ }
/*
* When wrapping around, return the original string, set findex to
* -1.
*/
if (findex < 0) {
- if (orig_save == NULL)
+ if (orig_save == NULL) {
findex = xp->xp_numfiles - 1;
- else
+ } else {
findex = -1;
+ }
}
if (findex >= xp->xp_numfiles) {
- if (orig_save == NULL)
+ if (orig_save == NULL) {
findex = 0;
- else
+ } else {
findex = -1;
+ }
}
if (compl_match_array) {
compl_selected = findex;
@@ -3847,8 +3851,9 @@ ExpandOne (
return vim_strsave(orig_save);
}
return vim_strsave(xp->xp_files[findex]);
- } else
+ } else {
return NULL;
+ }
}
if (mode == WILD_CANCEL) {
@@ -3858,7 +3863,7 @@ ExpandOne (
xp->xp_files[findex]);
}
- /* free old names */
+ // free old names
if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) {
FreeWild(xp->xp_numfiles, xp->xp_files);
xp->xp_numfiles = -1;
@@ -3866,8 +3871,9 @@ ExpandOne (
}
findex = 0;
- if (mode == WILD_FREE) /* only release file name */
+ if (mode == WILD_FREE) { // only release file name
return NULL;
+ }
if (xp->xp_numfiles == -1 && mode != WILD_APPLY && mode != WILD_CANCEL) {
xfree(orig_save);
@@ -3878,20 +3884,22 @@ ExpandOne (
* Do the expansion.
*/
if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files,
- options) == FAIL) {
+ 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,
* causing the pattern to be added, which has illegal characters.
*/
- if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND))
+ if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND)) {
EMSG2(_(e_nomatch2), str);
+ }
#endif
} else if (xp->xp_numfiles == 0) {
- if (!(options & WILD_SILENT))
+ if (!(options & WILD_SILENT)) {
EMSG2(_(e_nomatch2), str);
+ }
} else {
- /* Escape the matches for use on the command line. */
+ // Escape the matches for use on the command line.
ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options);
/*
@@ -3899,10 +3907,11 @@ ExpandOne (
*/
if (mode != WILD_ALL && mode != WILD_ALL_KEEP
&& mode != WILD_LONGEST) {
- if (xp->xp_numfiles)
+ if (xp->xp_numfiles) {
non_suf_match = xp->xp_numfiles;
- else
+ } else {
non_suf_match = 1;
+ }
if ((xp->xp_context == EXPAND_FILES
|| xp->xp_context == EXPAND_DIRECTORIES)
&& xp->xp_numfiles > 1) {
@@ -3912,9 +3921,11 @@ ExpandOne (
* expand_wildcards, only need to check the first two.
*/
non_suf_match = 0;
- for (i = 0; i < 2; ++i)
- if (match_suffix(xp->xp_files[i]))
+ for (i = 0; i < 2; ++i) {
+ if (match_suffix(xp->xp_files[i])) {
++non_suf_match;
+ }
+ }
}
if (non_suf_match != 1) {
/* Can we ever get here unless it's while expanding
@@ -3922,13 +3933,15 @@ ExpandOne (
* together. Don't really want to wait for this message
* (and possibly have to hit return to continue!).
*/
- if (!(options & WILD_SILENT))
+ if (!(options & WILD_SILENT)) {
EMSG(_(e_toomany));
- else if (!(options & WILD_NO_BEEP))
+ } else if (!(options & WILD_NO_BEEP)) {
beep_flush();
+ }
}
- if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE))
+ if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) {
ss = vim_strsave(xp->xp_files[0]);
+ }
}
}
}
@@ -3970,23 +3983,27 @@ ExpandOne (
// TODO(philix): use xstpcpy instead of strcat in a loop (ExpandOne)
if (mode == WILD_ALL && xp->xp_numfiles > 0) {
size_t len = 0;
- for (i = 0; i < xp->xp_numfiles; ++i)
+ for (i = 0; i < xp->xp_numfiles; ++i) {
len += STRLEN(xp->xp_files[i]) + 1;
+ }
ss = xmalloc(len);
*ss = NUL;
for (i = 0; i < xp->xp_numfiles; ++i) {
STRCAT(ss, xp->xp_files[i]);
- if (i != xp->xp_numfiles - 1)
+ if (i != xp->xp_numfiles - 1) {
STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
+ }
}
}
- if (mode == WILD_EXPAND_FREE || mode == WILD_ALL)
+ if (mode == WILD_EXPAND_FREE || mode == WILD_ALL) {
ExpandCleanup(xp);
+ }
- /* Free "orig" if it wasn't stored in "orig_save". */
- if (!orig_saved)
+ // Free "orig" if it wasn't stored in "orig_save".
+ if (!orig_saved) {
xfree(orig);
+ }
return ss;
}
@@ -4016,13 +4033,14 @@ void ExpandCleanup(expand_T *xp)
void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int options)
{
int i;
- char_u *p;
+ char_u *p;
/*
* May change home directory back to "~"
*/
- if (options & WILD_HOME_REPLACE)
+ if (options & WILD_HOME_REPLACE) {
tilde_replace(str, numfiles, files);
+ }
if (options & WILD_ESCAPE) {
if (xp->xp_context == EXPAND_FILES
@@ -4035,7 +4053,7 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
* and wildmatch characters, except '~'.
*/
for (i = 0; i < numfiles; ++i) {
- /* for ":set path=" we need to escape spaces twice */
+ // for ":set path=" we need to escape spaces twice
if (xp->xp_backslash == XP_BS_THREE) {
p = vim_strsave_escaped(files[i], (char_u *)" ");
xfree(files[i]);
@@ -4057,15 +4075,17 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
/* If 'str' starts with "\~", replace "~" at start of
* files[i] with "\~". */
- if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~')
+ if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~') {
escape_fname(&files[i]);
+ }
}
xp->xp_backslash = XP_BS_NONE;
/* If the first file starts with a '+' escape it. Otherwise it
* could be seen as "+cmd". */
- if (*files[0] == '+')
+ if (*files[0] == '+') {
escape_fname(&files[0]);
+ }
} else if (xp->xp_context == EXPAND_TAGS) {
/*
* Insert a backslash before characters in a tag name that
@@ -4087,8 +4107,7 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
/// if true then it escapes for a shell command.
///
/// @return [allocated] escaped file name.
-char *vim_strsave_fnameescape(const char *const fname,
- const bool shell FUNC_ATTR_UNUSED)
+char *vim_strsave_fnameescape(const char *const fname, const bool shell FUNC_ATTR_UNUSED)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
#ifdef BACKSLASH_IN_FILENAME
@@ -4108,8 +4127,8 @@ char *vim_strsave_fnameescape(const char *const fname,
#else
#define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<")
#define SHELL_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<>();&")
- char *p = (char *)vim_strsave_escaped(
- (const char_u *)fname, (shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS));
+ char *p =
+ (char *)vim_strsave_escaped((const char_u *)fname, (shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS));
if (shell && csh_like_shell()) {
// For csh and similar shells need to put two backslashes before '!'.
// One is taken by Vim, one by the shell.
@@ -4148,7 +4167,7 @@ static void escape_fname(char_u **pp)
void tilde_replace(char_u *orig_pat, int num_files, char_u **files)
{
int i;
- char_u *p;
+ char_u *p;
if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) {
for (i = 0; i < num_files; ++i) {
@@ -4175,12 +4194,12 @@ static int showmatches(expand_T *xp, int wildmenu)
#define L_SHOWFILE(m) (showtail \
? sm_gettail(files_found[m], false) : files_found[m])
int num_files;
- char_u **files_found;
+ char_u **files_found;
int i, j, k;
int maxlen;
int lines;
int columns;
- char_u *p;
+ char_u *p;
int lastlen;
int attr;
int showtail;
@@ -4188,11 +4207,11 @@ static int showmatches(expand_T *xp, int wildmenu)
if (xp->xp_numfiles == -1) {
set_expand_context(xp);
i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos,
- &num_files, &files_found);
+ &num_files, &files_found);
showtail = expand_showtail(xp);
- if (i != EXPAND_OK)
+ if (i != EXPAND_OK) {
return i;
-
+ }
} else {
num_files = xp->xp_numfiles;
files_found = xp->xp_files;
@@ -4247,10 +4266,12 @@ static int showmatches(expand_T *xp, int wildmenu)
|| xp->xp_context == EXPAND_BUFFERS)) {
home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE);
j = vim_strsize(NameBuff);
- } else
+ } else {
j = vim_strsize(L_SHOWFILE(i));
- if (j > maxlen)
+ }
+ if (j > maxlen) {
maxlen = j;
+ }
}
if (xp->xp_context == EXPAND_TAGS_LISTFILES) {
@@ -4274,7 +4295,7 @@ static int showmatches(expand_T *xp, int wildmenu)
MSG_PUTS_ATTR(_(" kind file\n"), HL_ATTR(HLF_T));
}
- /* list the files line by line */
+ // list the files line by line
for (i = 0; i < lines; ++i) {
lastlen = 999;
for (k = i; k < num_files; k += lines) {
@@ -4287,12 +4308,13 @@ static int showmatches(expand_T *xp, int wildmenu)
msg_puts_long_attr(p + 2, HL_ATTR(HLF_D));
break;
}
- for (j = maxlen - lastlen; --j >= 0; )
+ for (j = maxlen - lastlen; --j >= 0; ) {
msg_putchar(' ');
+ }
if (xp->xp_context == EXPAND_FILES
|| xp->xp_context == EXPAND_SHELLCMD
|| xp->xp_context == EXPAND_BUFFERS) {
- /* highlight directories */
+ // highlight directories
if (xp->xp_numfiles != -1) {
// Expansion was done before and special characters
// were escaped, need to halve backslashes. Also
@@ -4313,7 +4335,7 @@ static int showmatches(expand_T *xp, int wildmenu)
p = L_SHOWFILE(k);
} else {
home_replace(NULL, files_found[k], NameBuff, MAXPATHL,
- TRUE);
+ TRUE);
p = NameBuff;
}
} else {
@@ -4322,11 +4344,11 @@ static int showmatches(expand_T *xp, int wildmenu)
}
lastlen = msg_outtrans_attr(p, j ? attr : 0);
}
- if (msg_col > 0) { /* when not wrapped around */
+ if (msg_col > 0) { // when not wrapped around
msg_clr_eos();
msg_putchar('\n');
}
- ui_flush(); /* show one line at a time */
+ ui_flush(); // show one line at a time
if (got_int) {
got_int = FALSE;
break;
@@ -4337,11 +4359,12 @@ static int showmatches(expand_T *xp, int wildmenu)
* we redraw the command below the lines that we have just listed
* This is a bit tricky, but it saves a lot of screen updating.
*/
- cmdline_row = msg_row; /* will put it back later */
+ cmdline_row = msg_row; // will put it back later
}
- if (xp->xp_numfiles == -1)
+ if (xp->xp_numfiles == -1) {
FreeWild(num_files, files_found);
+ }
return EXPAND_OK;
}
@@ -4352,8 +4375,8 @@ static int showmatches(expand_T *xp, int wildmenu)
*/
char_u *sm_gettail(char_u *s, bool eager)
{
- char_u *p;
- char_u *t = s;
+ char_u *p;
+ char_u *t = s;
int had_sep = FALSE;
for (p = s; *p != NUL; ) {
@@ -4383,26 +4406,29 @@ char_u *sm_gettail(char_u *s, bool eager)
*/
static int expand_showtail(expand_T *xp)
{
- char_u *s;
- char_u *end;
+ char_u *s;
+ char_u *end;
- /* When not completing file names a "/" may mean something different. */
+ // When not completing file names a "/" may mean something different.
if (xp->xp_context != EXPAND_FILES
&& xp->xp_context != EXPAND_SHELLCMD
- && xp->xp_context != EXPAND_DIRECTORIES)
+ && xp->xp_context != EXPAND_DIRECTORIES) {
return FALSE;
+ }
end = path_tail(xp->xp_pattern);
- if (end == xp->xp_pattern) /* there is no path separator */
+ if (end == xp->xp_pattern) { // there is no path separator
return FALSE;
+ }
for (s = 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(s)) {
++s;
- else if (vim_strchr((char_u *)"*?[", *s) != NULL)
+ } else if (vim_strchr((char_u *)"*?[", *s) != NULL) {
return FALSE;
+ }
}
return TRUE;
}
@@ -4418,10 +4444,10 @@ static int expand_showtail(expand_T *xp)
char_u *addstar(char_u *fname, size_t len, int context)
FUNC_ATTR_NONNULL_RET
{
- char_u *retval;
+ char_u *retval;
size_t i, j;
size_t new_len;
- char_u *tail;
+ char_u *tail;
int ends_in_star;
if (context != EXPAND_FILES
@@ -4449,19 +4475,20 @@ char_u *addstar(char_u *fname, size_t len, int context)
} else {
new_len = len + 2; // +2 for '^' at start, NUL at end
for (i = 0; i < len; i++) {
- if (fname[i] == '*' || fname[i] == '~')
+ if (fname[i] == '*' || fname[i] == '~') {
new_len++; /* '*' needs to be replaced by ".*"
'~' needs to be replaced by "\~" */
-
- /* Buffer names are like file names. "." should be literal */
- if (context == EXPAND_BUFFERS && fname[i] == '.')
- new_len++; /* "." becomes "\." */
-
+ }
+ // Buffer names are like file names. "." should be literal
+ if (context == EXPAND_BUFFERS && fname[i] == '.') {
+ new_len++; // "." becomes "\."
+ }
/* Custom expansion takes care of special things, match
* backslashes literally (perhaps also for other types?) */
if ((context == EXPAND_USER_DEFINED
- || context == EXPAND_USER_LIST) && fname[i] == '\\')
- new_len++; /* '\' becomes "\\" */
+ || context == EXPAND_USER_LIST) && fname[i] == '\\') {
+ new_len++; // '\' becomes "\\"
+ }
}
retval = xmalloc(new_len);
{
@@ -4473,22 +4500,30 @@ char_u *addstar(char_u *fname, size_t len, int context)
if (context != EXPAND_USER_DEFINED
&& context != EXPAND_USER_LIST
&& fname[i] == '\\'
- && ++i == len)
+ && ++i == len) {
break;
+ }
switch (fname[i]) {
- case '*': retval[j++] = '.';
+ case '*':
+ retval[j++] = '.';
break;
- case '~': retval[j++] = '\\';
+ case '~':
+ retval[j++] = '\\';
break;
- case '?': retval[j] = '.';
+ case '?':
+ retval[j] = '.';
continue;
- case '.': if (context == EXPAND_BUFFERS)
+ case '.':
+ if (context == EXPAND_BUFFERS) {
retval[j++] = '\\';
+ }
break;
- case '\\': if (context == EXPAND_USER_DEFINED
- || context == EXPAND_USER_LIST)
+ case '\\':
+ if (context == EXPAND_USER_DEFINED
+ || context == EXPAND_USER_LIST) {
retval[j++] = '\\';
+ }
break;
}
retval[j] = fname[i];
@@ -4521,10 +4556,11 @@ char_u *addstar(char_u *fname, size_t len, int context)
if ((*retval != '~' || tail != retval)
&& !ends_in_star
&& vim_strchr(tail, '$') == NULL
- && vim_strchr(retval, '`') == NULL)
+ && vim_strchr(retval, '`') == NULL) {
retval[len++] = '*';
- else if (len > 0 && retval[len - 1] == '$')
+ } else if (len > 0 && retval[len - 1] == '$') {
--len;
+ }
retval[len] = NUL;
}
return retval;
@@ -4534,66 +4570,62 @@ char_u *addstar(char_u *fname, size_t len, int context)
* Must parse the command line so far to work out what context we are in.
* Completion can then be done based on that context.
* This routine sets the variables:
- * xp->xp_pattern The start of the pattern to be expanded within
- * the command line (ends at the cursor).
- * xp->xp_context The type of thing to expand. Will be one of:
+ * xp->xp_pattern The start of the pattern to be expanded within
+ * the command line (ends at the cursor).
+ * xp->xp_context The type of thing to expand. Will be one of:
*
- * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on
- * the command line, like an unknown command. Caller
- * should beep.
- * EXPAND_NOTHING Unrecognised context for completion, use char like
- * a normal char, rather than for completion. eg
- * :s/^I/
- * EXPAND_COMMANDS Cursor is still touching the command, so complete
- * it.
- * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands.
- * EXPAND_FILES After command with EX_XFILE set, or after setting
- * with P_EXPAND set. eg :e ^I, :w>>^I
- * EXPAND_DIRECTORIES In some cases this is used instead of the latter
- * when we know only directories are of interest. eg
- * :set dir=^I
- * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd".
- * EXPAND_SETTINGS Complete variable names. eg :set d^I
+ * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on
+ * the command line, like an unknown command. Caller
+ * should beep.
+ * EXPAND_NOTHING Unrecognised context for completion, use char like
+ * a normal char, rather than for completion. eg
+ * :s/^I/
+ * EXPAND_COMMANDS Cursor is still touching the command, so complete
+ * it.
+ * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands.
+ * EXPAND_FILES After command with EX_XFILE set, or after setting
+ * with P_EXPAND set. eg :e ^I, :w>>^I
+ * EXPAND_DIRECTORIES In some cases this is used instead of the latter
+ * when we know only directories are of interest. eg
+ * :set dir=^I
+ * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd".
+ * EXPAND_SETTINGS Complete variable names. eg :set d^I
* EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I
- * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I
+ * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I
* EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect
- * EXPAND_HELP Complete tags from the file 'helpfile'/tags
- * EXPAND_EVENTS Complete event names
- * EXPAND_SYNTAX Complete :syntax command arguments
- * EXPAND_HIGHLIGHT Complete highlight (syntax) group names
- * EXPAND_AUGROUP Complete autocommand group names
- * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I
- * EXPAND_MAPPINGS Complete mapping and abbreviation names,
- * eg :unmap a^I , :cunab x^I
- * EXPAND_FUNCTIONS Complete internal or user defined function names,
- * eg :call sub^I
- * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I
- * EXPAND_EXPRESSION Complete internal or user defined function/variable
- * names in expressions, eg :while s^I
- * EXPAND_ENV_VARS Complete environment variable names
- * EXPAND_USER Complete user names
+ * EXPAND_HELP Complete tags from the file 'helpfile'/tags
+ * EXPAND_EVENTS Complete event names
+ * EXPAND_SYNTAX Complete :syntax command arguments
+ * EXPAND_HIGHLIGHT Complete highlight (syntax) group names
+ * EXPAND_AUGROUP Complete autocommand group names
+ * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I
+ * EXPAND_MAPPINGS Complete mapping and abbreviation names,
+ * eg :unmap a^I , :cunab x^I
+ * EXPAND_FUNCTIONS Complete internal or user defined function names,
+ * eg :call sub^I
+ * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I
+ * EXPAND_EXPRESSION Complete internal or user defined function/variable
+ * names in expressions, eg :while s^I
+ * EXPAND_ENV_VARS Complete environment variable names
+ * EXPAND_USER Complete user names
*/
static void set_expand_context(expand_T *xp)
{
- /* only expansion for ':', '>' and '=' command-lines */
+ // only expansion for ':', '>' and '=' command-lines
if (ccline.cmdfirstc != ':'
&& ccline.cmdfirstc != '>' && ccline.cmdfirstc != '='
- && !ccline.input_fn
- ) {
+ && !ccline.input_fn) {
xp->xp_context = EXPAND_NOTHING;
return;
}
set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, true);
}
-void
-set_cmd_context (
- expand_T *xp,
- char_u *str, // start of command line
- int len, // length of command line (excl. NUL)
- int col, // position of cursor
- int use_ccline // use ccline for info
-)
+/// @param str start of command line
+/// @param len length of command line (excl. NUL)
+/// @param col position of cursor
+/// @param use_ccline use ccline for info
+void set_cmd_context(expand_T *xp, char_u *str, int len, int col, int use_ccline)
{
char_u old_char = NUL;
@@ -4601,8 +4633,9 @@ set_cmd_context (
* Avoid a UMR warning from Purify, only save the character if it has been
* written before.
*/
- if (col < len)
+ if (col < len) {
old_char = str[col];
+ }
str[col] = NUL;
const char *nextcomm = (const char *)str;
@@ -4627,35 +4660,31 @@ set_cmd_context (
str[col] = old_char;
}
-/*
- * Expand the command line "str" from context "xp".
- * "xp" must have been set by set_cmd_context().
- * xp->xp_pattern points into "str", to where the text that is to be expanded
- * starts.
- * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the
- * cursor.
- * Returns EXPAND_NOTHING when there is nothing to expand, might insert the
- * key that triggered expansion literally.
- * Returns EXPAND_OK otherwise.
- */
-int
-expand_cmdline (
- expand_T *xp,
- char_u *str, /* start of command line */
- int col, /* position of cursor */
- int *matchcount, /* return: nr of matches */
- char_u ***matches /* return: array of pointers to matches */
-)
+/// Expand the command line "str" from context "xp".
+/// "xp" must have been set by set_cmd_context().
+/// xp->xp_pattern points into "str", to where the text that is to be expanded
+/// starts.
+/// Returns EXPAND_UNSUCCESSFUL when there is something illegal before the
+/// cursor.
+/// Returns EXPAND_NOTHING when there is nothing to expand, might insert the
+/// key that triggered expansion literally.
+/// Returns EXPAND_OK otherwise.
+///
+/// @param str start of command line
+/// @param col position of cursor
+/// @param matchcount return: nr of matches
+/// @param matches return: array of pointers to matches
+int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, char_u ***matches)
{
- char_u *file_str = NULL;
+ char_u *file_str = NULL;
int options = WILD_ADD_SLASH|WILD_SILENT;
if (xp->xp_context == EXPAND_UNSUCCESSFUL) {
beep_flush();
- return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */
+ return EXPAND_UNSUCCESSFUL; // Something illegal on command line
}
if (xp->xp_context == EXPAND_NOTHING) {
- /* Caller can use the character as a normal char instead */
+ // Caller can use the character as a normal char instead
return EXPAND_NOTHING;
}
@@ -4664,10 +4693,11 @@ expand_cmdline (
xp->xp_pattern_len = (size_t)((str + col) - xp->xp_pattern);
file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context);
- if (p_wic)
+ if (p_wic) {
options += WILD_ICASE;
+ }
- /* find all files that match the description */
+ // find all files that match the description
if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL) {
*matchcount = 0;
*matches = NULL;
@@ -4731,31 +4761,28 @@ static void cleanup_help_tags(int num_file, char_u **file)
typedef char_u *(*ExpandFunc)(expand_T *, int);
-/*
- * Do the expansion based on xp->xp_context and "pat".
- */
-static int
-ExpandFromContext (
- expand_T *xp,
- char_u *pat,
- int *num_file,
- char_u ***file,
- int options // WILD_ flags
-)
+/// Do the expansion based on xp->xp_context and "pat".
+///
+/// @param options WILD_ flags
+static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char_u ***file, int options)
{
regmatch_T regmatch;
int ret;
int flags;
- flags = EW_DIR; /* include directories */
- if (options & WILD_LIST_NOTFOUND)
+ flags = EW_DIR; // include directories
+ if (options & WILD_LIST_NOTFOUND) {
flags |= EW_NOTFOUND;
- if (options & WILD_ADD_SLASH)
+ }
+ if (options & WILD_ADD_SLASH) {
flags |= EW_ADDSLASH;
- if (options & WILD_KEEP_ALL)
+ }
+ if (options & WILD_KEEP_ALL) {
flags |= EW_KEEPALL;
- if (options & WILD_SILENT)
+ }
+ if (options & WILD_SILENT) {
flags |= EW_SILENT;
+ }
if (options & WILD_NOERROR) {
flags |= EW_NOERROR;
}
@@ -4776,32 +4803,38 @@ ExpandFromContext (
if (xp->xp_backslash != XP_BS_NONE) {
free_pat = TRUE;
pat = vim_strsave(pat);
- for (i = 0; pat[i]; ++i)
+ for (i = 0; pat[i]; ++i) {
if (pat[i] == '\\') {
if (xp->xp_backslash == XP_BS_THREE
&& pat[i + 1] == '\\'
&& pat[i + 2] == '\\'
- && pat[i + 3] == ' ')
+ && pat[i + 3] == ' ') {
STRMOVE(pat + i, pat + i + 3);
+ }
if (xp->xp_backslash == XP_BS_ONE
- && pat[i + 1] == ' ')
+ && pat[i + 1] == ' ') {
STRMOVE(pat + i, pat + i + 1);
+ }
}
+ }
}
- if (xp->xp_context == EXPAND_FILES)
+ if (xp->xp_context == EXPAND_FILES) {
flags |= EW_FILE;
- else if (xp->xp_context == EXPAND_FILES_IN_PATH)
+ } else if (xp->xp_context == EXPAND_FILES_IN_PATH) {
flags |= (EW_FILE | EW_PATH);
- else
+ } else {
flags = (flags | EW_DIR) & ~EW_FILE;
- if (options & WILD_ICASE)
+ }
+ if (options & WILD_ICASE) {
flags |= EW_ICASE;
+ }
- /* Expand wildcards, supporting %:h and the like. */
+ // Expand wildcards, supporting %:h and the like.
ret = expand_wildcards_eval(&pat, num_file, file, flags);
- if (free_pat)
+ if (free_pat) {
xfree(pat);
+ }
#ifdef BACKSLASH_IN_FILENAME
if (p_csl[0] != NUL && (options & WILD_IGNORE_COMPLETESLASH) == 0) {
for (int i = 0; i < *num_file; i++) {
@@ -4842,8 +4875,9 @@ ExpandFromContext (
ExpandOldSetting(num_file, file);
return OK;
}
- if (xp->xp_context == EXPAND_BUFFERS)
+ if (xp->xp_context == EXPAND_BUFFERS) {
return ExpandBufnames(pat, num_file, file, options);
+ }
if (xp->xp_context == EXPAND_DIFF_BUFFERS) {
return ExpandBufnames(pat, num_file, file, options | BUF_DIFF_FILTER);
}
@@ -4896,20 +4930,21 @@ ExpandFromContext (
}
regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
- if (regmatch.regprog == NULL)
+ if (regmatch.regprog == NULL) {
return FAIL;
+ }
- /* set ignore-case according to p_ic, p_scs and pat */
+ // set ignore-case according to p_ic, p_scs and pat
regmatch.rm_ic = ignorecase(pat);
if (xp->xp_context == EXPAND_SETTINGS
- || xp->xp_context == EXPAND_BOOL_SETTINGS)
+ || xp->xp_context == EXPAND_BOOL_SETTINGS) {
ret = ExpandSettings(xp, &regmatch, num_file, file);
- else if (xp->xp_context == EXPAND_MAPPINGS)
+ } else if (xp->xp_context == EXPAND_MAPPINGS) {
ret = ExpandMappings(&regmatch, num_file, file);
- else if (xp->xp_context == EXPAND_USER_DEFINED)
+ } else if (xp->xp_context == EXPAND_USER_DEFINED) {
ret = ExpandUserDefined(xp, &regmatch, num_file, file);
- else {
+ } else {
static struct expgen {
int context;
ExpandFunc func;
@@ -4955,7 +4990,7 @@ ExpandFromContext (
* right function to do the expansion.
*/
ret = FAIL;
- for (i = 0; i < (int)ARRAY_SIZE(tab); ++i)
+ for (i = 0; i < (int)ARRAY_SIZE(tab); ++i) {
if (xp->xp_context == tab[i].context) {
if (tab[i].ic) {
regmatch.rm_ic = TRUE;
@@ -4965,6 +5000,7 @@ ExpandFromContext (
ret = OK;
break;
}
+ }
}
vim_regfree(regmatch.regprog);
@@ -4973,39 +5009,36 @@ ExpandFromContext (
return ret;
}
-/*
- * Expand a list of names.
- *
- * Generic function for command line completion. It calls a function to
- * obtain strings, one by one. The strings are matched against a regexp
- * program. Matching strings are copied into an array, which is returned.
- */
-static void ExpandGeneric(
- expand_T *xp,
- regmatch_T *regmatch,
- int *num_file,
- char_u ***file,
- CompleteListItemGetter func, /* returns a string from the list */
- int escaped
- )
+/// Expand a list of names.
+///
+/// Generic function for command line completion. It calls a function to
+/// obtain strings, one by one. The strings are matched against a regexp
+/// program. Matching strings are copied into an array, which is returned.
+///
+/// @param func returns a string from the list
+static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file,
+ CompleteListItemGetter func, int escaped)
{
int i;
size_t count = 0;
- char_u *str;
+ char_u *str;
// count the number of matching names
for (i = 0;; ++i) {
str = (*func)(xp, i);
- if (str == NULL) // end of list
+ if (str == NULL) { // end of list
break;
- if (*str == NUL) // skip empty strings
+ }
+ if (*str == NUL) { // skip empty strings
continue;
+ }
if (vim_regexec(regmatch, str, (colnr_T)0)) {
++count;
}
}
- if (count == 0)
+ if (count == 0) {
return;
+ }
assert(count < INT_MAX);
*num_file = (int)count;
*file = (char_u **)xmalloc(count * sizeof(char_u *));
@@ -5037,16 +5070,17 @@ static void ExpandGeneric(
}
}
- /* Sort the results. Keep menu's in the specified order. */
+ // Sort the results. Keep menu's in the specified order.
if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS) {
if (xp->xp_context == EXPAND_EXPRESSION
|| xp->xp_context == EXPAND_FUNCTIONS
- || xp->xp_context == EXPAND_USER_FUNC)
- /* <SNR> functions should be sorted to the end. */
+ || xp->xp_context == EXPAND_USER_FUNC) {
+ // <SNR> functions should be sorted to the end.
qsort((void *)*file, (size_t)*num_file, sizeof(char_u *),
- sort_func_compare);
- else
+ sort_func_compare);
+ } else {
sort_strings(*file, *num_file);
+ }
}
/* Reset the variables used for special highlight names expansion, so that
@@ -5062,26 +5096,27 @@ static void ExpandGeneric(
/// *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_u ***file,
- int flagsarg)
+static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg)
FUNC_ATTR_NONNULL_ALL
{
- char_u *pat;
+ char_u *pat;
int i;
- char_u *path = NULL;
+ char_u *path = NULL;
garray_T ga;
char_u *buf = xmalloc(MAXPATHL);
size_t l;
- char_u *s, *e;
+ char_u *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);
- for (i = 0; pat[i]; ++i)
- if (pat[i] == '\\' && pat[i + 1] == ' ')
+ for (i = 0; pat[i]; ++i) {
+ if (pat[i] == '\\' && pat[i + 1] == ' ') {
STRMOVE(pat + i, pat + i + 1);
+ }
+ }
flags |= EW_FILE | EW_EXEC | EW_SHELLCMD;
@@ -5139,7 +5174,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
l = STRLEN(buf);
STRLCPY(buf + l, pat, MAXPATHL - l);
- /* Expand matches in one directory of $PATH. */
+ // Expand matches in one directory of $PATH.
ret = expand_wildcards(1, &buf, num_file, file, flags);
if (ret == OK) {
ga_grow(&ga, *num_file);
@@ -5166,8 +5201,9 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
xfree(*file);
}
}
- if (*e != NUL)
+ if (*e != NUL) {
++e;
+ }
}
*file = ga.ga_data;
*num_file = ga.ga_len;
@@ -5182,8 +5218,8 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
/// Call "user_expand_func()" to invoke a user defined Vim script function and
/// return the result (either a string, a List or NULL).
-static void * call_user_expand_func(user_expand_func_T user_expand_func,
- expand_T *xp, int *num_file, char_u ***file)
+static void * call_user_expand_func(user_expand_func_T user_expand_func, expand_T *xp,
+ int *num_file, char_u ***file)
FUNC_ATTR_NONNULL_ALL
{
char_u keep = 0;
@@ -5192,8 +5228,9 @@ static void * call_user_expand_func(user_expand_func_T user_expand_func,
const sctx_T save_current_sctx = current_sctx;
struct cmdline_info save_ccline;
- if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL)
+ if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) {
return NULL;
+ }
*num_file = 0;
*file = NULL;
@@ -5211,7 +5248,7 @@ static void * call_user_expand_func(user_expand_func_T user_expand_func,
args[1].vval.v_string = xp->xp_line;
args[2].vval.v_number = xp->xp_col;
- /* Save the cmdline, we don't know what the function may do. */
+ // Save the cmdline, we don't know what the function may do.
save_ccline = ccline;
ccline.cmdbuff = NULL;
ccline.cmdprompt = NULL;
@@ -5234,11 +5271,11 @@ static void * call_user_expand_func(user_expand_func_T user_expand_func,
*/
static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file)
{
- char_u *e;
+ char_u *e;
garray_T ga;
- char_u *const retstr = call_user_expand_func(
- (user_expand_func_T)call_func_retstr, xp, num_file, file);
+ char_u *const retstr = call_user_expand_func((user_expand_func_T)call_func_retstr, xp, num_file,
+ file);
if (retstr == NULL) {
return FAIL;
@@ -5247,13 +5284,14 @@ static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file,
ga_init(&ga, (int)sizeof(char *), 3);
for (char_u *s = retstr; *s != NUL; s = e) {
e = vim_strchr(s, '\n');
- if (e == NULL)
+ if (e == NULL) {
e = s + STRLEN(s);
+ }
const char_u keep = *e;
*e = NUL;
const bool skip = xp->xp_pattern[0]
- && vim_regexec(regmatch, s, (colnr_T)0) == 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)));
@@ -5274,8 +5312,8 @@ static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file,
*/
static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file)
{
- list_T *const retlist = call_user_expand_func(
- (user_expand_func_T)call_func_retlist, xp, num_file, file);
+ list_T *const retlist = call_user_expand_func((user_expand_func_T)call_func_retlist, xp, num_file,
+ file);
if (retlist == NULL) {
return FAIL;
}
@@ -5289,8 +5327,7 @@ static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file)
continue; // Skip non-string items and empty strings.
}
- GA_APPEND(char *, &ga, xstrdup(
- (const char *)TV_LIST_ITEM_TV(li)->vval.v_string));
+ GA_APPEND(char *, &ga, xstrdup((const char *)TV_LIST_ITEM_TV(li)->vval.v_string));
});
tv_list_unref(retlist);
@@ -5308,8 +5345,7 @@ static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file)
/// '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.
-static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file,
- char *dirnames[])
+static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirnames[])
{
*num_file = 0;
*file = NULL;
@@ -5403,8 +5439,9 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file,
}
}
- if (GA_EMPTY(&ga))
+ if (GA_EMPTY(&ga)) {
return FAIL;
+ }
/* Sort and remove duplicates which can happen when specifying multiple
* directories in dirnames. */
@@ -5497,7 +5534,7 @@ void globpath(char_u *path, char_u *file, garray_T *ga, int expand_options)
/*********************************
-* Command line history stuff *
+* Command line history stuff *
*********************************/
/// Translate a history character to the associated type number
@@ -5505,26 +5542,20 @@ static HistoryType hist_char2type(const int c)
FUNC_ATTR_CONST FUNC_ATTR_WARN_UNUSED_RESULT
{
switch (c) {
- case ':': {
- return HIST_CMD;
- }
- case '=': {
- return HIST_EXPR;
- }
- case '@': {
- return HIST_INPUT;
- }
- case '>': {
- return HIST_DEBUG;
- }
- case NUL:
- case '/':
- case '?': {
- return HIST_SEARCH;
- }
- default: {
- return HIST_INVALID;
- }
+ case ':':
+ return HIST_CMD;
+ case '=':
+ return HIST_EXPR;
+ case '@':
+ return HIST_INPUT;
+ case '>':
+ return HIST_DEBUG;
+ case NUL:
+ case '/':
+ case '?':
+ return HIST_SEARCH;
+ default:
+ return HIST_INVALID;
}
// Silence -Wreturn-type
return 0;
@@ -5561,10 +5592,12 @@ static char_u *get_history_arg(expand_T *xp, int idx)
compl[0] = (char_u)short_names[idx];
return compl;
}
- if (idx < short_names_count + history_name_count)
+ if (idx < short_names_count + history_name_count) {
return (char_u *)history_names[idx - short_names_count];
- if (idx == short_names_count + history_name_count)
+ }
+ if (idx == short_names_count + history_name_count) {
return (char_u *)"all";
+ }
return NULL;
}
@@ -5642,49 +5675,48 @@ static inline void clear_hist_entry(histentry_T *hisptr)
memset(hisptr, 0, sizeof(*hisptr));
}
-/*
- * Check if command line 'str' is already in history.
- * If 'move_to_front' is TRUE, matching entry is moved to end of history.
- */
-static int
-in_history (
- int type,
- char_u *str,
- int move_to_front, // Move the entry to the front if it exists
- int sep
-)
+/// Check if command line 'str' is already in history.
+/// If 'move_to_front' is TRUE, matching entry is moved to end of history.
+///
+/// @param move_to_front Move the entry to the front if it exists
+static int in_history(int type, char_u *str, int move_to_front, int sep)
{
int i;
int last_i = -1;
- char_u *p;
+ char_u *p;
- if (hisidx[type] < 0)
+ if (hisidx[type] < 0) {
return FALSE;
+ }
i = hisidx[type];
do {
- if (history[type][i].hisstr == NULL)
+ if (history[type][i].hisstr == NULL) {
return FALSE;
+ }
/* For search history, check that the separator character matches as
* well. */
p = history[type][i].hisstr;
if (STRCMP(str, p) == 0
&& (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) {
- if (!move_to_front)
+ if (!move_to_front) {
return TRUE;
+ }
last_i = i;
break;
}
- if (--i < 0)
+ if (--i < 0) {
i = hislen - 1;
+ }
} while (i != hisidx[type]);
if (last_i >= 0) {
list_T *const list = history[type][i].additional_elements;
str = history[type][i].hisstr;
while (i != hisidx[type]) {
- if (++i >= hislen)
+ if (++i >= hislen) {
i = 0;
+ }
history[type][last_i] = history[type][i];
last_i = i;
}
@@ -5710,8 +5742,7 @@ in_history (
///
/// @return Any value from HistoryType enum, including HIST_INVALID. May not
/// return HIST_DEFAULT unless return_default is true.
-HistoryType get_histtype(const char *const name, const size_t len,
- const bool return_default)
+HistoryType get_histtype(const char *const name, const size_t len, const bool return_default)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
// No argument: use current history.
@@ -5732,7 +5763,7 @@ HistoryType get_histtype(const char *const name, const size_t len,
return HIST_INVALID;
}
-static int last_maptick = -1; /* last seen maptick */
+static int last_maptick = -1; // last seen maptick
/// Add the given string to the given history. If the string is already in the
/// history then it is moved to the front. "histype" may be one of he HIST_
@@ -5749,8 +5780,9 @@ void add_to_history(int histype, char_u *new_entry, int in_map, int sep)
}
assert(histype != HIST_DEFAULT);
- if (cmdmod.keeppatterns && histype == HIST_SEARCH)
+ if (cmdmod.keeppatterns && histype == HIST_SEARCH) {
return;
+ }
/*
* Searches inside the same mapping overwrite each other, so that only
@@ -5763,14 +5795,16 @@ void add_to_history(int histype, char_u *new_entry, int in_map, int sep)
hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]];
hist_free_entry(hisptr);
--hisnum[histype];
- if (--hisidx[HIST_SEARCH] < 0)
+ if (--hisidx[HIST_SEARCH] < 0) {
hisidx[HIST_SEARCH] = hislen - 1;
+ }
}
last_maptick = -1;
}
if (!in_history(histype, new_entry, true, sep)) {
- if (++hisidx[histype] == hislen)
+ if (++hisidx[histype] == hislen) {
hisidx[histype] = 0;
+ }
hisptr = &history[histype][hisidx[histype]];
hist_free_entry(hisptr);
@@ -5782,8 +5816,9 @@ void add_to_history(int histype, char_u *new_entry, int in_map, int sep)
hisptr->hisstr[len + 1] = (char_u)sep;
hisptr->hisnum = ++hisnum[histype];
- if (histype == HIST_SEARCH && in_map)
+ if (histype == HIST_SEARCH && in_map) {
last_maptick = maptick;
+ }
}
}
@@ -5795,8 +5830,9 @@ void add_to_history(int histype, char_u *new_entry, int in_map, int sep)
int get_history_idx(int histype)
{
if (hislen == 0 || histype < 0 || histype >= HIST_COUNT
- || hisidx[histype] < 0)
+ || hisidx[histype] < 0) {
return -1;
+ }
return history[histype][hisidx[histype]].hisnum;
}
@@ -5831,8 +5867,9 @@ char_u *get_cmdline_str(void)
}
struct cmdline_info *p = get_ccline_ptr();
- if (p == NULL)
+ if (p == NULL) {
return NULL;
+ }
return vim_strnsave(p->cmdbuff, (size_t)p->cmdlen);
}
@@ -5846,8 +5883,9 @@ int get_cmdline_pos(void)
{
struct cmdline_info *p = get_ccline_ptr();
- if (p == NULL)
+ if (p == NULL) {
return -1;
+ }
return p->cmdpos;
}
@@ -5860,15 +5898,17 @@ int set_cmdline_pos(int pos)
{
struct cmdline_info *p = get_ccline_ptr();
- if (p == NULL)
+ if (p == NULL) {
return 1;
+ }
/* The position is not set directly but after CTRL-\ e or CTRL-R = has
* changed the command line. */
- if (pos < 0)
+ if (pos < 0) {
new_cmdpos = 0;
- else
+ } else {
new_cmdpos = pos;
+ }
return 0;
}
@@ -5882,10 +5922,12 @@ int get_cmdline_type(void)
{
struct cmdline_info *p = get_ccline_ptr();
- if (p == NULL)
+ if (p == NULL) {
return NUL;
- if (p->cmdfirstc == NUL)
+ }
+ if (p->cmdfirstc == NUL) {
return (p->input_fn) ? '@' : '-';
+ }
return p->cmdfirstc;
}
@@ -5902,26 +5944,32 @@ static int calc_hist_idx(int histype, int num)
int wrapped = FALSE;
if (hislen == 0 || histype < 0 || histype >= HIST_COUNT
- || (i = hisidx[histype]) < 0 || num == 0)
+ || (i = hisidx[histype]) < 0 || num == 0) {
return -1;
+ }
hist = history[histype];
if (num > 0) {
- while (hist[i].hisnum > num)
+ while (hist[i].hisnum > num) {
if (--i < 0) {
- if (wrapped)
+ if (wrapped) {
break;
+ }
i += hislen;
wrapped = TRUE;
}
- if (hist[i].hisnum == num && hist[i].hisstr != NULL)
+ }
+ if (hist[i].hisnum == num && hist[i].hisstr != NULL) {
return i;
- } else if (-num <= hislen) {
+ }
+ } else if (-num <= hislen) {
i += num + 1;
- if (i < 0)
+ if (i < 0) {
i += hislen;
- if (hist[i].hisstr != NULL)
+ }
+ if (hist[i].hisstr != NULL) {
return i;
+ }
}
return -1;
}
@@ -5933,10 +5981,11 @@ static int calc_hist_idx(int histype, int num)
char_u *get_history_entry(int histype, int idx)
{
idx = calc_hist_idx(histype, idx);
- if (idx >= 0)
+ if (idx >= 0) {
return history[histype][idx].hisstr;
- else
+ } else {
return (char_u *)"";
+ }
}
/// Clear all entries in a history
@@ -5973,7 +6022,7 @@ int del_history_entry(int histype, char_u *str)
bool found = false;
regmatch.regprog = NULL;
- regmatch.rm_ic = FALSE; /* always match case */
+ regmatch.rm_ic = FALSE; // always match case
if (hislen != 0
&& histype >= 0
&& histype < HIST_COUNT
@@ -5984,8 +6033,9 @@ int del_history_entry(int histype, char_u *str)
i = last = idx;
do {
hisptr = &history[histype][i];
- if (hisptr->hisstr == NULL)
+ if (hisptr->hisstr == NULL) {
break;
+ }
if (vim_regexec(&regmatch, hisptr->hisstr, (colnr_T)0)) {
found = true;
hist_free_entry(hisptr);
@@ -5994,14 +6044,17 @@ int del_history_entry(int histype, char_u *str)
history[histype][last] = *hisptr;
clear_hist_entry(hisptr);
}
- if (--last < 0)
+ if (--last < 0) {
last += hislen;
+ }
}
- if (--i < 0)
+ if (--i < 0) {
i += hislen;
+ }
} while (i != idx);
- if (history[histype][idx].hisstr == NULL)
+ if (history[histype][idx].hisstr == NULL) {
hisidx[histype] = -1;
+ }
}
vim_regfree(regmatch.regprog);
return found;
@@ -6016,16 +6069,18 @@ int del_history_idx(int histype, int idx)
int i, j;
i = calc_hist_idx(histype, idx);
- if (i < 0)
+ if (i < 0) {
return FALSE;
+ }
idx = hisidx[histype];
hist_free_entry(&history[histype][i]);
/* When deleting the last added search string in a mapping, reset
* last_maptick, so that the last added search string isn't deleted again.
*/
- if (histype == HIST_SEARCH && maptick == last_maptick && i == idx)
+ if (histype == HIST_SEARCH && maptick == last_maptick && i == idx) {
last_maptick = -1;
+ }
while (i != idx) {
j = (i + 1) % hislen;
@@ -6089,8 +6144,8 @@ void ex_history(exarg_T *eap)
int hisidx2 = -1;
int idx;
int i, j, k;
- char_u *end;
- char_u *arg = eap->arg;
+ char_u *end;
+ char_u *arg = eap->arg;
if (hislen == 0) {
MSG(_("'history' option is zero"));
@@ -6100,8 +6155,9 @@ void ex_history(exarg_T *eap)
if (!(ascii_isdigit(*arg) || *arg == '-' || *arg == ',')) {
end = arg;
while (ASCII_ISALPHA(*end)
- || vim_strchr((char_u *)":=@>/?", *end) != NULL)
+ || vim_strchr((char_u *)":=@>/?", *end) != NULL) {
end++;
+ }
histype1 = get_histtype((const char *)arg, (size_t)(end - arg), false);
if (histype1 == HIST_INVALID) {
if (STRNICMP(arg, "all", end - arg) == 0) {
@@ -6111,8 +6167,9 @@ void ex_history(exarg_T *eap)
EMSG(_(e_trailing));
return;
}
- } else
+ } else {
histype2 = histype1;
+ }
} else {
end = arg;
}
@@ -6130,14 +6187,17 @@ void ex_history(exarg_T *eap)
hist = history[histype1];
j = hisidx1;
k = hisidx2;
- if (j < 0)
+ if (j < 0) {
j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum;
- if (k < 0)
+ }
+ if (k < 0) {
k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum;
- if (idx >= 0 && j <= k)
+ }
+ if (idx >= 0 && j <= k) {
for (i = idx + 1; !got_int; ++i) {
- if (i == hislen)
+ if (i == hislen) {
i = 0;
+ }
if (hist[i].hisstr != NULL
&& hist[i].hisnum >= j && hist[i].hisnum <= k) {
msg_putchar('\n');
@@ -6152,9 +6212,11 @@ void ex_history(exarg_T *eap)
msg_outtrans(IObuff);
ui_flush();
}
- if (i == idx)
+ if (i == idx) {
break;
+ }
}
+ }
}
}
@@ -6163,24 +6225,18 @@ int hist_type2char(int type)
FUNC_ATTR_CONST
{
switch (type) {
- case HIST_CMD: {
- return ':';
- }
- case HIST_SEARCH: {
- return '/';
- }
- case HIST_EXPR: {
- return '=';
- }
- case HIST_INPUT: {
- return '@';
- }
- case HIST_DEBUG: {
- return '>';
- }
- default: {
- abort();
- }
+ case HIST_CMD:
+ return ':';
+ case HIST_SEARCH:
+ return '/';
+ case HIST_EXPR:
+ return '=';
+ case HIST_INPUT:
+ return '@';
+ case HIST_DEBUG:
+ return '>';
+ default:
+ abort();
}
return NUL;
}
@@ -6196,8 +6252,8 @@ static int open_cmdwin(void)
struct cmdline_info save_ccline;
bufref_T old_curbuf;
bufref_T bufref;
- win_T *old_curwin = curwin;
- win_T *wp;
+ win_T *old_curwin = curwin;
+ win_T *wp;
int i;
linenr_T lnum;
garray_T winsizes;
@@ -6207,10 +6263,9 @@ static int open_cmdwin(void)
bool save_exmode = exmode_active;
int save_cmdmsg_rl = cmdmsg_rl;
- /* Can't do this recursively. Can't do it when typing a password. */
+ // Can't do this recursively. Can't do it when typing a password.
if (cmdwin_type != 0
- || cmdline_star > 0
- ) {
+ || cmdline_star > 0) {
beep_flush();
return K_IGNORE;
}
@@ -6272,8 +6327,9 @@ static int open_cmdwin(void)
if (i >= 0) {
lnum = 0;
do {
- if (++i == hislen)
+ if (++i == hislen) {
i = 0;
+ }
if (history[histtype][i].hisstr != NULL) {
ml_append(lnum++, history[histtype][i].hisstr, (colnr_T)0, false);
}
@@ -6347,10 +6403,11 @@ static int open_cmdwin(void)
cmdwin_result = Ctrl_C;
EMSG(_("E199: Active window or buffer deleted"));
} else {
- /* autocmds may abort script processing */
- if (aborting() && cmdwin_result != K_IGNORE)
+ // autocmds may abort script processing
+ if (aborting() && cmdwin_result != K_IGNORE) {
cmdwin_result = Ctrl_C;
- /* Set the new command line from the cmdline buffer. */
+ }
+ // Set the new command line from the cmdline buffer.
xfree(ccline.cmdbuff);
if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) { // :qa[!] typed
const char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!";
@@ -6370,8 +6427,9 @@ static int open_cmdwin(void)
/* :q or :close, don't execute any command
* and don't modify the cmd window. */
ccline.cmdbuff = NULL;
- } else
+ } else {
ccline.cmdbuff = vim_strsave(get_cursor_line_ptr());
+ }
if (ccline.cmdbuff == NULL) {
ccline.cmdbuff = vim_strsave((char_u *)"");
ccline.cmdlen = 0;
@@ -6382,8 +6440,9 @@ static int open_cmdwin(void)
ccline.cmdlen = (int)STRLEN(ccline.cmdbuff);
ccline.cmdbufflen = ccline.cmdlen + 1;
ccline.cmdpos = curwin->w_cursor.col;
- if (ccline.cmdpos > ccline.cmdlen)
+ if (ccline.cmdpos > ccline.cmdlen) {
ccline.cmdpos = ccline.cmdlen;
+ }
if (cmdwin_result == K_IGNORE) {
ccline.cmdspos = cmd_screencol(ccline.cmdpos);
redrawcmd();
@@ -6449,13 +6508,12 @@ char *script_get(exarg_T *const eap, size_t *const lenp)
}
const char *const end_pattern = (
- cmd[2] != NUL
+ cmd[2] != NUL
? (const char *)skipwhite((const char_u *)cmd + 2)
: ".");
for (;;) {
- char *const theline = (char *)eap->getline(
- eap->cstack->cs_looplevel > 0 ? -1 :
- NUL, eap->cookie, 0, true);
+ char *const theline = (char *)eap->getline(eap->cstack->cs_looplevel > 0 ? -1 :
+ NUL, eap->cookie, 0, true);
if (theline == NULL || strcmp(end_pattern, theline) == 0) {
xfree(theline);
@@ -6497,8 +6555,8 @@ char *script_get(exarg_T *const eap, size_t *const lenp)
///
/// @return Pointer used in next iteration or NULL to indicate that iteration
/// was finished.
-const void *hist_iter(const void *const iter, const uint8_t history_type,
- const bool zero, histentry_T *const hist)
+const void *hist_iter(const void *const iter, const uint8_t history_type, const bool zero,
+ histentry_T *const hist)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(4)
{
*hist = (histentry_T) {
@@ -6509,7 +6567,7 @@ const void *hist_iter(const void *const iter, const uint8_t history_type,
}
histentry_T *const hstart = &(history[history_type][0]);
histentry_T *const hlast = (
- &(history[history_type][hisidx[history_type]]));
+ &(history[history_type][hisidx[history_type]]));
const histentry_T *const hend = &(history[history_type][hislen - 1]);
histentry_T *hiter;
if (iter == NULL) {
@@ -6525,7 +6583,7 @@ const void *hist_iter(const void *const iter, const uint8_t history_type,
} while (hfirst != hlast);
hiter = hfirst;
} else {
- hiter = (histentry_T *) iter;
+ hiter = (histentry_T *)iter;
}
if (hiter == NULL) {
return NULL;
@@ -6538,7 +6596,7 @@ const void *hist_iter(const void *const iter, const uint8_t history_type,
return NULL;
}
hiter++;
- return (const void *) ((hiter > hend) ? hstart : hiter);
+ return (const void *)((hiter > hend) ? hstart : hiter);
}
/// Get array of history items
diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c
index 3038ed3947..11e8353e3a 100644
--- a/src/nvim/ex_session.c
+++ b/src/nvim/ex_session.c
@@ -8,13 +8,11 @@
// :mksession
#include <assert.h>
-#include <string.h>
+#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
-#include <inttypes.h>
+#include <string.h>
-#include "nvim/vim.h"
-#include "nvim/globals.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/cursor.h"
@@ -28,6 +26,7 @@
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
+#include "nvim/globals.h"
#include "nvim/keymap.h"
#include "nvim/misc1.h"
#include "nvim/move.h"
@@ -36,6 +35,7 @@
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/path.h"
+#include "nvim/vim.h"
#include "nvim/window.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -63,7 +63,7 @@ static int put_view_curpos(FILE *fd, const win_T *wp, char *spaces)
static int ses_winsizes(FILE *fd, int restore_size, win_T *tab_firstwin)
{
int n = 0;
- win_T *wp;
+ win_T *wp;
if (restore_size && (ssop_flags & SSOP_WINSIZE)) {
for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) {
@@ -105,7 +105,7 @@ static int ses_winsizes(FILE *fd, int restore_size, win_T *tab_firstwin)
// Returns FAIL when writing the commands to "fd" fails.
static int ses_win_rec(FILE *fd, frame_T *fr)
{
- frame_T *frc;
+ frame_T *frc;
int count = 0;
if (fr->fr_layout != FR_LEAF) {
@@ -149,7 +149,7 @@ static int ses_win_rec(FILE *fd, frame_T *fr)
// Returns NULL when there none.
static frame_T *ses_skipframe(frame_T *fr)
{
- frame_T *frc;
+ frame_T *frc;
FOR_ALL_FRAMES(frc, fr) {
if (ses_do_frame(frc)) {
@@ -200,11 +200,10 @@ static int ses_do_win(win_T *wp)
/// @param flagp
///
/// @returns FAIL if writing fails.
-static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname,
- unsigned *flagp)
+static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, unsigned *flagp)
{
- char_u *buf = NULL;
- char_u *s;
+ char_u *buf = NULL;
+ char_u *s;
if (fprintf(fd, "%s\n%s\n", cmd, "%argdel") < 0) {
return FAIL;
@@ -297,17 +296,15 @@ static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp)
return retval;
}
-// Write commands to "fd" to restore the view of a window.
-// Caller must make sure 'scrolloff' is zero.
-static int put_view(
- FILE *fd,
- win_T *wp,
- int add_edit, // add ":edit" command to view
- unsigned *flagp, // vop_flags or ssop_flags
- int current_arg_idx // current argument index of the window, use
-) // -1 if unknown
+/// Write commands to "fd" to restore the view of a window.
+/// Caller must make sure 'scrolloff' is zero.
+///
+/// @param add_edit add ":edit" command to view
+/// @param flagp vop_flags or ssop_flags
+/// @param current_arg_idx current argument index of the window, use -1 if unknown
+static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int current_arg_idx)
{
- win_T *save_curwin;
+ win_T *save_curwin;
int f;
int do_cursor;
int did_next = false;
@@ -348,8 +345,8 @@ static int put_view(
// Load the file.
//
if (wp->w_buffer->b_ffname != NULL
- && (!bt_nofile(wp->w_buffer) || wp->w_buffer->terminal)
- ) {
+ && (!bt_nofile(wp->w_buffer) ||
+ wp->w_buffer->terminal)) {
// Editing a file in this buffer: use ":edit file".
// This may have side effects! (e.g., compressed or network file).
//
@@ -434,8 +431,8 @@ static int put_view(
//
if ((*flagp & SSOP_FOLDS)
&& wp->w_buffer->b_ffname != NULL
- && (bt_normal(wp->w_buffer) || bt_help(wp->w_buffer))
- ) {
+ && (bt_normal(wp->w_buffer) ||
+ bt_help(wp->w_buffer))) {
if (put_folds(fd, wp) == FAIL) {
return FAIL;
}
@@ -525,12 +522,12 @@ static int makeopens(FILE *fd, char_u *dirnow)
int only_save_windows = true;
int nr;
int restore_size = true;
- win_T *wp;
- char_u *sname;
- win_T *edited_win = NULL;
+ win_T *wp;
+ char_u *sname;
+ win_T *edited_win = NULL;
int tabnr;
- win_T *tab_firstwin;
- frame_T *tab_topframe;
+ win_T *tab_firstwin;
+ frame_T *tab_topframe;
int cur_arg_idx = 0;
int next_arg_idx = 0;
@@ -658,8 +655,7 @@ static int makeopens(FILE *fd, char_u *dirnow)
if (ses_do_win(wp)
&& wp->w_buffer->b_ffname != NULL
&& !bt_help(wp->w_buffer)
- && !bt_nofile(wp->w_buffer)
- ) {
+ && !bt_nofile(wp->w_buffer)) {
if (need_tabnext && put_line(fd, "tabnext") == FAIL) {
return FAIL;
}
@@ -877,12 +873,12 @@ void ex_loadview(exarg_T *eap)
/// - SSOP_SLASH: filenames are written with "/" slash
void ex_mkrc(exarg_T *eap)
{
- FILE *fd;
+ FILE *fd;
int failed = false;
int view_session = false; // :mkview, :mksession
int using_vdir = false; // using 'viewdir'?
char *viewFile = NULL;
- unsigned *flagp;
+ unsigned *flagp;
if (eap->cmdidx == CMD_mksession || eap->cmdidx == CMD_mkview) {
view_session = true;
diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c
index b4f22dbf33..819b8ad3dc 100644
--- a/src/nvim/extmark.c
+++ b/src/nvim/extmark.c
@@ -29,19 +29,20 @@
// code for redrawing the line with the deleted decoration.
#include <assert.h>
+
#include "nvim/api/vim.h"
-#include "nvim/vim.h"
+#include "nvim/buffer.h"
+#include "nvim/buffer_updates.h"
#include "nvim/charset.h"
-#include "nvim/extmark.h"
#include "nvim/decoration.h"
-#include "nvim/buffer_updates.h"
-#include "nvim/memline.h"
-#include "nvim/pos.h"
+#include "nvim/extmark.h"
#include "nvim/globals.h"
-#include "nvim/map.h"
#include "nvim/lib/kbtree.h"
+#include "nvim/map.h"
+#include "nvim/memline.h"
+#include "nvim/pos.h"
#include "nvim/undo.h"
-#include "nvim/buffer.h"
+#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "extmark.c.generated.h"
@@ -56,10 +57,9 @@ static ExtmarkNs *buf_ns_ref(buf_T *buf, uint64_t ns_id, bool put) {
///
/// must not be used during iteration!
/// @returns the mark id
-uint64_t extmark_set(buf_T *buf, uint64_t ns_id, uint64_t id,
- int row, colnr_T col, int end_row, colnr_T end_col,
- Decoration *decor, bool right_gravity,
- bool end_right_gravity, ExtmarkOp op)
+uint64_t extmark_set(buf_T *buf, uint64_t ns_id, uint64_t id, int row, colnr_T col, int end_row,
+ colnr_T end_col, Decoration *decor, bool right_gravity, bool end_right_gravity,
+ ExtmarkOp op)
{
ExtmarkNs *ns = buf_ns_ref(buf, ns_id, true);
assert(ns != NULL);
@@ -178,9 +178,7 @@ bool extmark_del(buf_T *buf, uint64_t ns_id, uint64_t id)
// Free extmarks in a ns between lines
// if ns = 0, it means clear all namespaces
-bool extmark_clear(buf_T *buf, uint64_t ns_id,
- int l_row, colnr_T l_col,
- int u_row, colnr_T u_col)
+bool extmark_clear(buf_T *buf, uint64_t ns_id, int l_row, colnr_T l_col, int u_row, colnr_T u_col)
{
if (!map_size(buf->b_extmark_ns)) {
return false;
@@ -281,10 +279,8 @@ bool extmark_clear(buf_T *buf, uint64_t ns_id,
// will be searched to the start, or end
// dir can be set to control the order of the array
// amount = amount of marks to find or -1 for all
-ExtmarkInfoArray extmark_get(buf_T *buf, uint64_t ns_id,
- int l_row, colnr_T l_col,
- int u_row, colnr_T u_col,
- int64_t amount, bool reverse)
+ExtmarkInfoArray extmark_get(buf_T *buf, uint64_t ns_id, int l_row, colnr_T l_col, int u_row,
+ colnr_T u_col, int64_t amount, bool reverse)
{
ExtmarkInfoArray array = KV_INITIAL_VALUE;
MarkTreeIter itr[1];
@@ -394,10 +390,9 @@ void extmark_free_all(buf_T *buf)
// Save info for undo/redo of set marks
-static void u_extmark_set(buf_T *buf, uint64_t mark,
- int row, colnr_T col)
+static void u_extmark_set(buf_T *buf, uint64_t mark, int row, colnr_T col)
{
- u_header_T *uhp = u_force_get_undo_header(buf);
+ u_header_T *uhp = u_force_get_undo_header(buf);
if (!uhp) {
return;
}
@@ -419,11 +414,9 @@ static void u_extmark_set(buf_T *buf, uint64_t mark,
///
/// useful when we cannot simply reverse the operation. This will do nothing on
/// redo, enforces correct position when undo.
-void u_extmark_copy(buf_T *buf,
- int l_row, colnr_T l_col,
- int u_row, colnr_T u_col)
+void u_extmark_copy(buf_T *buf, int l_row, colnr_T l_col, int u_row, colnr_T u_col)
{
- u_header_T *uhp = u_force_get_undo_header(buf);
+ u_header_T *uhp = u_force_get_undo_header(buf);
if (!uhp) {
return;
}
@@ -467,7 +460,6 @@ void extmark_apply_undo(ExtmarkUndoObject undo_info, bool undo)
splice.new_row, splice.new_col, splice.new_byte,
splice.old_row, splice.old_col, splice.old_byte,
kExtmarkNoUndo);
-
} else {
extmark_splice_impl(curbuf,
splice.start_row, splice.start_col, splice.start_byte,
@@ -475,14 +467,14 @@ void extmark_apply_undo(ExtmarkUndoObject undo_info, bool undo)
splice.new_row, splice.new_col, splice.new_byte,
kExtmarkNoUndo);
}
- // kExtmarkSavePos
+ // kExtmarkSavePos
} else if (undo_info.type == kExtmarkSavePos) {
ExtmarkSavePos pos = undo_info.data.savepos;
if (undo) {
if (pos.old_row >= 0) {
extmark_setraw(curbuf, pos.mark, pos.old_row, pos.old_col);
}
- // Redo
+ // Redo
} else {
if (pos.row >= 0) {
extmark_setraw(curbuf, pos.mark, pos.row, pos.col);
@@ -508,11 +500,7 @@ void extmark_apply_undo(ExtmarkUndoObject undo_info, bool undo)
// Adjust extmark row for inserted/deleted rows (columns stay fixed).
-void extmark_adjust(buf_T *buf,
- linenr_T line1,
- linenr_T line2,
- long amount,
- long amount_after,
+void extmark_adjust(buf_T *buf, linenr_T line1, linenr_T line2, long amount, long amount_after,
ExtmarkOp undo)
{
if (curbuf_splice_pending) {
@@ -537,7 +525,7 @@ void extmark_adjust(buf_T *buf,
}
if (new_row > 0) {
new_byte = ml_find_line_or_offset(buf, line1+new_row, NULL, true)
- - start_byte;
+ - start_byte;
}
extmark_splice_impl(buf,
(int)line1-1, 0, start_byte,
@@ -562,10 +550,8 @@ void extmark_adjust(buf_T *buf,
// the end column of the new region.
// @param new_byte Byte extent of the new region.
// @param undo
-void extmark_splice(buf_T *buf,
- int start_row, colnr_T start_col,
- int old_row, colnr_T old_col, bcount_t old_byte,
- int new_row, colnr_T new_col, bcount_t new_byte,
+void extmark_splice(buf_T *buf, int start_row, colnr_T start_col, int old_row, colnr_T old_col,
+ bcount_t old_byte, int new_row, colnr_T new_col, bcount_t new_byte,
ExtmarkOp undo)
{
long offset = ml_find_line_or_offset(buf, start_row + 1, NULL, true);
@@ -584,11 +570,9 @@ void extmark_splice(buf_T *buf,
undo);
}
-void extmark_splice_impl(buf_T *buf,
- int start_row, colnr_T start_col, bcount_t start_byte,
- int old_row, colnr_T old_col, bcount_t old_byte,
- int new_row, colnr_T new_col, bcount_t new_byte,
- ExtmarkOp undo)
+void extmark_splice_impl(buf_T *buf, int start_row, colnr_T start_col, bcount_t start_byte,
+ int old_row, colnr_T old_col, bcount_t old_byte, int new_row,
+ colnr_T new_col, bcount_t new_byte, ExtmarkOp undo)
{
curbuf->deleted_bytes2 = 0;
buf_updates_send_splice(buf, start_row, start_col, start_byte,
@@ -612,7 +596,7 @@ void extmark_splice_impl(buf_T *buf,
new_row, new_col);
if (undo == kExtmarkUndo) {
- u_header_T *uhp = u_force_get_undo_header(buf);
+ u_header_T *uhp = u_force_get_undo_header(buf);
if (!uhp) {
return;
}
@@ -621,7 +605,7 @@ void extmark_splice_impl(buf_T *buf,
// TODO(bfredl): this is quite rudimentary. We merge small (within line)
// inserts with each other and small deletes with each other. Add full
// merge algorithm later.
- if (old_row == 0 && new_row == 0 && kv_size(uhp->uh_extmark)) {
+ if (old_row == 0 && new_row == 0 && kv_size(uhp->uh_extmark)) {
ExtmarkUndoObject *item = &kv_A(uhp->uh_extmark,
kv_size(uhp->uh_extmark)-1);
if (item->type == kExtmarkSplice) {
@@ -669,22 +653,17 @@ void extmark_splice_impl(buf_T *buf,
}
}
-void extmark_splice_cols(buf_T *buf,
- int start_row, colnr_T start_col,
- colnr_T old_col, colnr_T new_col,
- ExtmarkOp undo)
+void extmark_splice_cols(buf_T *buf, int start_row, colnr_T start_col, colnr_T old_col,
+ colnr_T new_col, ExtmarkOp undo)
{
extmark_splice(buf, start_row, start_col,
0, old_col, old_col,
0, new_col, new_col, undo);
}
-void extmark_move_region(
- buf_T *buf,
- int start_row, colnr_T start_col, bcount_t start_byte,
- int extent_row, colnr_T extent_col, bcount_t extent_byte,
- int new_row, colnr_T new_col, bcount_t new_byte,
- ExtmarkOp undo)
+void extmark_move_region(buf_T *buf, int start_row, colnr_T start_col, bcount_t start_byte,
+ int extent_row, colnr_T extent_col, bcount_t extent_byte, int new_row,
+ colnr_T new_col, bcount_t new_byte, ExtmarkOp undo)
{
curbuf->deleted_bytes2 = 0;
// TODO(bfredl): this is not synced to the buffer state inside the callback.
@@ -704,7 +683,7 @@ void extmark_move_region(
if (undo == kExtmarkUndo) {
- u_header_T *uhp = u_force_get_undo_header(buf);
+ u_header_T *uhp = u_force_get_undo_header(buf);
if (!uhp) {
return;
}