aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/autocmd.c13
-rw-r--r--src/nvim/buffer.c203
-rw-r--r--src/nvim/change.c23
-rw-r--r--src/nvim/cursor.c8
-rw-r--r--src/nvim/debugger.c22
-rw-r--r--src/nvim/diff.c36
-rw-r--r--src/nvim/edit.c2
-rw-r--r--src/nvim/eval.c10
-rw-r--r--src/nvim/eval/funcs.c90
-rw-r--r--src/nvim/eval/userfunc.c18
-rw-r--r--src/nvim/ex_cmds.c8
-rw-r--r--src/nvim/ex_cmds2.c6
-rw-r--r--src/nvim/ex_docmd.c2
-rw-r--r--src/nvim/ex_getln.c40
-rw-r--r--src/nvim/lua/xdiff.c4
-rw-r--r--src/nvim/message.c2
-rw-r--r--src/nvim/move.c8
-rw-r--r--src/nvim/option.c2
-rw-r--r--src/nvim/os/shell.c12
-rw-r--r--src/nvim/quickfix.c24
-rw-r--r--src/nvim/screen.c4
-rw-r--r--src/nvim/search.c44
-rw-r--r--src/nvim/sha256.c11
-rw-r--r--src/nvim/shada.c2814
-rw-r--r--src/nvim/sign.c937
-rw-r--r--src/nvim/state.c15
-rw-r--r--src/nvim/syntax.c4
-rw-r--r--src/uncrustify.cfg20
28 files changed, 2114 insertions, 2268 deletions
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index 4c502b53d4..67b2b8954d 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -956,10 +956,11 @@ static int do_autocmd_event(event_T event, char_u *pat, bool once, int nested, c
return OK;
}
-// Implementation of ":doautocmd [group] event [fname]".
-// Return OK for success, FAIL for failure;
-int do_doautocmd(char_u *arg, bool do_msg, // give message for no matching autocmds?
- bool *did_something)
+/// Implementation of ":doautocmd [group] event [fname]".
+/// Return OK for success, FAIL for failure;
+///
+/// @param do_msg give message for no matching autocmds?
+int do_doautocmd(char_u *arg, bool do_msg, bool *did_something)
{
char_u *fname;
int nothing_done = true;
@@ -1916,8 +1917,8 @@ char_u *get_augroup_name(expand_T *xp, int idx)
return (char_u *)AUGROUP_NAME(idx);
}
-char_u *set_context_in_autocmd(expand_T *xp, char_u *arg, int doautocmd // true for :doauto*, false for :autocmd
- )
+/// @param doautocmd true for :doauto*, false for :autocmd
+char_u *set_context_in_autocmd(expand_T *xp, char_u *arg, int doautocmd)
{
char_u *p;
int group;
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index c58eb1610e..cd84073460 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -98,13 +98,15 @@ typedef enum {
kBffInitChangedtick = 2,
} BufFreeFlags;
-// Read data from buffer for retrying.
-static int read_buffer(int read_stdin, // read file from stdin, otherwise fifo
- exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
- int flags) // extra flags for readfile()
+/// Read data from buffer for retrying.
+///
+/// @param read_stdin read file from stdin, otherwise fifo
+/// @param eap for forced 'ff' and 'fenc' or NULL
+/// @param flags extra flags for readfile()
+static int read_buffer(int read_stdin, exarg_T *eap, int flags)
{
- int retval = OK;
- linenr_T line_count;
+ int retval = OK;
+ linenr_T line_count;
//
// Read from the buffer which the text is already filled in and append at
@@ -146,16 +148,18 @@ static int read_buffer(int read_stdin, // read file from stdin, otherwis
return retval;
}
-// Open current buffer, that is: open the memfile and read the file into
-// memory.
-// Return FAIL for failure, OK otherwise.
-int open_buffer(int read_stdin, // read file from stdin
- exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
- int flags // extra flags for readfile()
- )
+/// Open current buffer, that is: open the memfile and read the file into
+/// memory.
+///
+/// @param read_stdin read file from stdin
+/// @param eap for forced 'ff' and 'fenc' or NULL
+/// @param flags extra flags for readfile()
+///
+/// @return FAIL for failure, OK otherwise.
+int open_buffer(int read_stdin, exarg_T *eap, int flags)
{
int retval = OK;
- bufref_T old_curbuf;
+ bufref_T old_curbuf;
long old_tw = curbuf->b_p_tw;
int read_fifo = false;
@@ -939,23 +943,22 @@ void handle_swap_exists(bufref_T *old_curbuf)
swap_exists_action = SEA_NONE; // -V519
}
-/*
- * do_bufdel() - delete or unload buffer(s)
- *
- * addr_count == 0: ":bdel" - delete current buffer
- * addr_count == 1: ":N bdel" or ":bdel N [N ..]" - first delete
- * buffer "end_bnr", then any other arguments.
- * addr_count == 2: ":N,N bdel" - delete buffers in range
- *
- * command can be DOBUF_UNLOAD (":bunload"), DOBUF_WIPE (":bwipeout") or
- * DOBUF_DEL (":bdel")
- *
- * Returns error message or NULL
- */
-char_u *do_bufdel(int command, char_u *arg, // pointer to extra arguments
- int addr_count, int start_bnr, // first buffer number in a range
- int end_bnr, // buffer nr or last buffer nr in a range
- int forceit)
+/// do_bufdel() - delete or unload buffer(s)
+///
+/// addr_count == 0: ":bdel" - delete current buffer
+/// addr_count == 1: ":N bdel" or ":bdel N [N ..]" - first delete
+/// buffer "end_bnr", then any other arguments.
+/// addr_count == 2: ":N,N bdel" - delete buffers in range
+///
+/// command can be DOBUF_UNLOAD (":bunload"), DOBUF_WIPE (":bwipeout") or
+/// DOBUF_DEL (":bdel")
+///
+/// @param arg pointer to extra arguments
+/// @param start_bnr first buffer number in a range
+/// @param end_bnr buffer nr or last buffer nr in a range
+///
+/// @return error message or NULL
+char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int end_bnr, int forceit)
{
int do_current = 0; // delete current buffer?
int deleted = 0; // number of buffers deleted
@@ -1097,26 +1100,26 @@ static int empty_curbuf(int close_others, int forceit, int action)
return retval;
}
-/*
- * Implementation of the commands for the buffer list.
- *
- * action == DOBUF_GOTO go to specified buffer
- * action == DOBUF_SPLIT split window and go to specified buffer
- * action == DOBUF_UNLOAD unload specified buffer(s)
- * action == DOBUF_DEL delete specified buffer(s) from buffer list
- * action == DOBUF_WIPE delete specified buffer(s) really
- *
- * start == DOBUF_CURRENT go to "count" buffer from current buffer
- * start == DOBUF_FIRST go to "count" buffer from first buffer
- * start == DOBUF_LAST go to "count" buffer from last buffer
- * start == DOBUF_MOD go to "count" modified buffer from current buffer
- *
- * Return FAIL or OK.
- */
-int do_buffer(int action, int start, int dir, // FORWARD or BACKWARD
- int count, // buffer number or number of buffers
- int forceit // true for :...!
- )
+
+/// Implementation of the commands for the buffer list.
+///
+/// action == DOBUF_GOTO go to specified buffer
+/// action == DOBUF_SPLIT split window and go to specified buffer
+/// action == DOBUF_UNLOAD unload specified buffer(s)
+/// action == DOBUF_DEL delete specified buffer(s) from buffer list
+/// action == DOBUF_WIPE delete specified buffer(s) really
+///
+/// start == DOBUF_CURRENT go to "count" buffer from current buffer
+/// start == DOBUF_FIRST go to "count" buffer from first buffer
+/// start == DOBUF_LAST go to "count" buffer from last buffer
+/// start == DOBUF_MOD go to "count" modified buffer from current buffer
+///
+/// @param dir FORWARD or BACKWARD
+/// @param count buffer number or number of buffers
+/// @param forceit true for :...!
+///
+/// @return FAIL or OK.
+int do_buffer(int action, int start, int dir, int count, int forceit)
{
buf_T *buf;
buf_T *bp;
@@ -2154,11 +2157,13 @@ static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id, bool fil
/// Find file in buffer list by a regexp pattern.
/// Return fnum of the found buffer.
/// Return < 0 for error.
-int buflist_findpat(const char_u *pattern, const char_u *pattern_end, // pointer to first char after pattern
- bool unlisted, // find unlisted buffers
- bool diffmode, // find diff-mode buffers only
- bool curtab_only // find buffers in current tab only
- )
+///
+/// @param pattern_end pointer to first char after pattern
+/// @param unlisted find unlisted buffers
+/// @param diffmode find diff-mode buffers only
+/// @param curtab_only find buffers in current tab only
+int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlisted, bool diffmode,
+ bool curtab_only)
FUNC_ATTR_NONNULL_ARG(1)
{
int match = -1;
@@ -2466,14 +2471,14 @@ buf_T *buflist_findnr(int nr)
return handle_get_buffer((handle_T)nr);
}
-/*
- * Get name of file 'n' in the buffer list.
- * When the file has no name an empty string is returned.
- * home_replace() is used to shorten the file name (used for marks).
- * Returns a pointer to allocated memory, of NULL when failed.
- */
-char_u *buflist_nr2name(int n, int fullname, int helptail // for help buffers return tail only
- )
+/// Get name of file 'n' in the buffer list.
+/// When the file has no name an empty string is returned.
+/// home_replace() is used to shorten the file name (used for marks).
+///
+/// @param helptail for help buffers return tail only
+///
+/// @return a pointer to allocated memory, of NULL when failed.
+char_u *buflist_nr2name(int n, int fullname, int helptail)
{
buf_T *buf;
@@ -2800,13 +2805,14 @@ int buflist_name_nr(int fnum, char_u **fname, linenr_T *lnum)
return OK;
}
-// Set the file name for "buf" to "ffname_arg", short file name to
-// "sfname_arg".
-// The file name with the full path is also remembered, for when :cd is used.
-// Returns FAIL for failure (file name already in use by other buffer)
-// OK otherwise.
-int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message // give message when buffer already exists
- )
+/// Set the file name for "buf" to "ffname_arg", short file name to
+/// "sfname_arg".
+/// The file name with the full path is also remembered, for when :cd is used.
+///
+/// @param message give message when buffer already exists
+///
+/// @return FAIL for failure (file name already in use by other buffer) OK otherwise.
+int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message)
{
char_u *ffname = ffname_arg;
char_u *sfname = sfname_arg;
@@ -2934,12 +2940,11 @@ buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum)
return buf;
}
-/*
- * Get alternate file name for current window.
- * Return NULL if there isn't any, and give error message if requested.
- */
-char_u *getaltfname(bool errmsg // give error message
- )
+/// Get alternate file name for current window.
+/// Return NULL if there isn't any, and give error message if requested.
+///
+/// @param errmsg give error message
+char_u *getaltfname(bool errmsg)
{
char_u *fname;
linenr_T dummy;
@@ -3078,11 +3083,10 @@ static bool buf_same_file_id(buf_T *buf, FileID *file_id)
return buf->file_id_valid && os_fileid_equal(&(buf->file_id), file_id);
}
-/*
- * Print info about the current buffer.
- */
-void fileinfo(int fullname, // when non-zero print full path
- int shorthelp, int dont_truncate)
+/// Print info about the current buffer.
+///
+/// @param fullname when non-zero print full path
+void fileinfo(int fullname, int shorthelp, int dont_truncate)
{
char_u *name;
int n;
@@ -4751,12 +4755,11 @@ char_u *alist_name(aentry_T *aep)
return bp->b_fname;
}
-/*
- * do_arg_all(): Open up to 'count' windows, one for each argument.
- */
-void do_arg_all(int count, int forceit, // hide buffers in current windows
- int keep_tabs // keep current tabs, for ":tab drop file"
- )
+/// do_arg_all(): Open up to 'count' windows, one for each argument.
+///
+/// @param forceit hide buffers in current windows
+/// @param keep_tabs keep current tabs, for ":tab drop file"
+void do_arg_all(int count, int forceit, int keep_tabs)
{
char_u *opened; // Array of weight for which args are open:
// 0: not opened
@@ -5254,12 +5257,11 @@ void do_modelines(int flags)
entered--;
}
-/*
- * chk_modeline() - check a single line for a mode string
- * Return FAIL if an error encountered.
- */
-static int chk_modeline(linenr_T lnum, int flags // Same as for do_modelines().
- )
+/// chk_modeline() - check a single line for a mode string
+/// Return FAIL if an error encountered.
+///
+/// @param flags Same as for do_modelines().
+static int chk_modeline(linenr_T lnum, int flags)
{
char_u *s;
char_u *e;
@@ -5631,13 +5633,12 @@ bool buf_contents_changed(buf_T *buf)
return differ;
}
-/*
- * Wipe out a buffer and decrement the last buffer number if it was used for
- * this buffer. Call this to wipe out a temp buffer that does not contain any
- * marks.
- */
-void wipe_buffer(buf_T *buf, bool aucmd // When true trigger autocommands.
- )
+/// Wipe out a buffer and decrement the last buffer number if it was used for
+/// this buffer. Call this to wipe out a temp buffer that does not contain any
+/// marks.
+///
+/// @param aucmd When true trigger autocommands.
+void wipe_buffer(buf_T *buf, bool aucmd)
{
if (!aucmd) {
// Don't trigger BufDelete autocommands here.
diff --git a/src/nvim/change.c b/src/nvim/change.c
index ccceb0e320..4ac5edeaa9 100644
--- a/src/nvim/change.c
+++ b/src/nvim/change.c
@@ -461,15 +461,15 @@ void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra)
/// When only inserting lines, "lnum" and "lnume" are equal.
/// Takes care of calling changed() and updating b_mod_*.
/// Careful: may trigger autocommands that reload the buffer.
-void changed_lines(linenr_T lnum, // first line with change
- colnr_T col, // column in first line with change
- linenr_T lnume, // line below last changed line
- long xtra, // number of extra lines (negative when deleting)
- bool do_buf_event // some callers like undo/redo call changed_lines()
- // and then increment changedtick *again*. This flag
- // allows these callers to send the nvim_buf_lines_event
- // events after they're done modifying changedtick.
- )
+///
+/// @param lnum first line with change
+/// @param col column in first line with change
+/// @param lnume line below last changed line
+/// @param xtra number of extra lines (negative when deleting)
+/// @param do_buf_event some callers like undo/redo call changed_lines() and
+/// then increment changedtick *again*. This flag allows these callers to send
+/// the nvim_buf_lines_event events after they're done modifying changedtick.
+void changed_lines(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra, bool do_buf_event)
{
changed_lines_buf(curbuf, lnum, lnume, xtra);
@@ -950,9 +950,10 @@ int copy_indent(int size, char_u *src)
/// "second_line_indent": indent for after ^^D in Insert mode or if flag
/// OPENLINE_COM_LIST
///
+/// @param dir FORWARD or BACKWARD
+///
/// @return true on success, false on failure
-int open_line(int dir, // FORWARD or BACKWARD
- int flags, int second_line_indent)
+int open_line(int dir, int flags, int second_line_indent)
{
char_u *next_line = NULL; // copy of the next line
char_u *p_extra = NULL; // what goes to next line
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c
index 2eced03c03..e334fd166e 100644
--- a/src/nvim/cursor.c
+++ b/src/nvim/cursor.c
@@ -93,10 +93,10 @@ int coladvance(colnr_T wcol)
return rc;
}
-static int coladvance2(pos_T *pos, bool addspaces, // change the text to achieve our goal?
- bool finetune, // change char offset for the exact column
- colnr_T wcol_arg // column to move to (can be negative)
- )
+/// @param addspaces change the text to achieve our goal?
+/// @param finetune change char offset for the exact column
+/// @param wcol_arg column to move to (can be negative)
+static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_arg)
{
colnr_T wcol = wcol_arg;
int idx;
diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c
index a5dd4cd485..0ddf163176 100644
--- a/src/nvim/debugger.c
+++ b/src/nvim/debugger.c
@@ -718,10 +718,11 @@ 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
- )
+///
+/// @param file true for a file, false for a function
+/// @param fname file or function name
+/// @param after after this line number
+linenr_T dbg_find_breakpoint(bool file, char_u *fname, linenr_T after)
{
return debuggy_find(file, fname, after, &dbg_breakp, NULL);
}
@@ -738,12 +739,13 @@ 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
- )
+///
+/// @param file true for a file, false for a function
+/// @param fname file or function name
+/// @param after after this line number
+/// @param gap either &dbg_breakp or &prof_ga
+/// @param fp if not NULL: return forceit
+static linenr_T debuggy_find(bool file, char_u *fname, linenr_T after, garray_T *gap, bool *fp)
{
struct debuggy *bp;
linenr_T lnum = 0;
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 1d70145209..93c0d636fa 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -73,21 +73,21 @@ 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
+ 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
+ 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
@@ -702,9 +702,9 @@ static void clear_diffout(diffout_T *dout)
/// @return FAIL for failure.
static int diff_write_buffer(buf_T *buf, diffin_T *din)
{
- linenr_T lnum;
+ linenr_T lnum;
char_u *s;
- long len = 0;
+ long len = 0;
char_u *ptr;
// xdiff requires one big block of memory with all the text.
@@ -732,7 +732,7 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din)
for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) {
for (s = ml_get_buf(buf, lnum, false); *s != NUL; ) {
if (diff_flags & DIFF_ICASE) {
- char_u cbuf[MB_MAXBYTES + 1];
+ char_u cbuf[MB_MAXBYTES + 1];
// xdiff doesn't support ignoring case, fold-case the text.
int c = PTR2CHAR(s);
@@ -787,10 +787,10 @@ 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;
+ int idx_new;
if (dio->dio_internal) {
ga_init(&dio->dio_diff.dout_ga, sizeof(char *), 1000);
@@ -928,7 +928,7 @@ void ex_diffupdate(exarg_T *eap)
}
// Only use the internal method if it did not fail for one of the buffers.
- diffio_T diffio;
+ diffio_T diffio;
memset(&diffio, 0, sizeof(diffio));
diffio.dio_internal = diff_internal() && !diff_internal_failed();
@@ -1044,9 +1044,9 @@ static int check_external_diff(diffio_T *diffio)
///
static int diff_file_internal(diffio_T *diffio)
{
- xpparam_t param;
- xdemitconf_t emit_cfg;
- xdemitcb_t emit_cb;
+ xpparam_t param;
+ xdemitconf_t emit_cfg;
+ xdemitcb_t emit_cb;
memset(&param, 0, sizeof(param));
memset(&emit_cfg, 0, sizeof(emit_cfg));
@@ -3033,8 +3033,8 @@ static int parse_diff_ed(char_u *line, linenr_T *lnum_orig, long *count_orig, li
long *count_new)
{
char_u *p;
- long f1, l1, f2, l2;
- int difftype;
+ long f1, l1, f2, l2;
+ int difftype;
// The line must be one of three formats:
// change: {first}[,{last}]c{first}[,{last}]
@@ -3088,7 +3088,7 @@ static int parse_diff_unified(char_u *line, linenr_T *lnum_orig, long *count_ori
linenr_T *lnum_new, long *count_new)
{
char_u *p;
- long oldline, oldcount, newline, newcount;
+ long oldline, oldcount, newline, newcount;
// Parse unified diff hunk header:
// @@ -oldline,oldcount +newline,newcount @@
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 20dc3cd06b..5c4030d8d5 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -147,7 +147,7 @@ struct compl_S {
compl_T *cp_prev;
char_u *cp_str; // matched text
char_u *(cp_text[CPT_COUNT]); // text for the menu
- typval_T cp_user_data;
+ typval_T cp_user_data;
char_u *cp_fname; // file containing the match, allocated when
// cp_flags has CP_FREE_FNAME
int cp_flags; // CP_ values
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 0b73d6b37f..90bff854d9 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -5848,8 +5848,8 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate)
{
char_u *name;
char_u *string = NULL;
- int len;
- int cc;
+ int len;
+ int cc;
++*arg;
name = *arg;
@@ -6299,9 +6299,9 @@ int assert_fails(typval_T *argvars)
FUNC_ATTR_NONNULL_ALL
{
const char *const cmd = tv_get_string_chk(&argvars[0]);
- garray_T ga;
+ garray_T ga;
int ret = 0;
- int save_trylevel = trylevel;
+ int save_trylevel = trylevel;
// trylevel must be zero for a ":throw" command to be considered failed
trylevel = 0;
@@ -7345,7 +7345,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T
const char *line = NULL;
list_T *l = NULL;
listitem_T *li = NULL;
- long added = 0;
+ long added = 0;
linenr_T append_lnum;
buf_T *curbuf_save = NULL;
win_T *curwin_save = NULL;
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index ff91f13444..e2d485d892 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -248,7 +248,7 @@ static int non_zero_arg(typval_T *argvars)
static void float_op_wrapper(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
float_T f;
- float_T (*function)(float_T) = (float_T (*)(float_T))fptr;
+ float_T (*function)(float_T) = (float_T (*)(float_T)) fptr;
rettv->v_type = VAR_FLOAT;
if (tv_get_float_chk(argvars, &f)) {
@@ -2695,13 +2695,13 @@ static void f_foldlevel(typval_T *argvars, typval_T *rettv, FunPtr fptr)
*/
static void f_foldtext(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- linenr_T foldstart;
- linenr_T foldend;
+ linenr_T foldstart;
+ linenr_T foldend;
char_u *dashes;
- linenr_T lnum;
+ linenr_T lnum;
char_u *s;
char_u *r;
- int len;
+ int len;
char *txt;
rettv->v_type = VAR_STRING;
@@ -3310,10 +3310,10 @@ static void f_getcmdwintype(typval_T *argvars, typval_T *rettv, FunPtr fptr)
static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *pat;
- expand_T xpc;
- bool filtered = false;
- int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
- | WILD_NO_BEEP;
+ expand_T xpc;
+ bool filtered = false;
+ int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
+ | WILD_NO_BEEP;
if (argvars[1].v_type != VAR_STRING) {
EMSG2(_(e_invarg2), "type must be a string");
@@ -4113,8 +4113,8 @@ static void f_win_screenpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
//
static void win_move_into_split(win_T *wp, win_T *targetwin, int size, int flags)
{
- int dir;
- int height = wp->w_height;
+ int dir;
+ int height = wp->w_height;
win_T *oldwin = curwin;
if (wp == targetwin) {
@@ -4153,7 +4153,7 @@ static void f_win_splitmove(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
win_T *wp;
win_T *targetwin;
- int flags = 0, size = 0;
+ int flags = 0, size = 0;
wp = find_win_by_nr_or_id(&argvars[0]);
targetwin = find_win_by_nr_or_id(&argvars[1]);
@@ -5968,7 +5968,7 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv,
const SomeMatchType type)
{
char_u *str = NULL;
- long len = 0;
+ long len = 0;
char_u *expr = NULL;
regmatch_T regmatch;
char_u *save_cpo;
@@ -7250,17 +7250,17 @@ static void f_getreginfo(typval_T *argvars, typval_T *rettv, FunPtr fptr)
buf[1] = NUL;
colnr_T reglen = 0;
switch (get_reg_type(regname, &reglen)) {
- case kMTLineWise:
- buf[0] = 'V';
- break;
- case kMTCharWise:
- buf[0] = 'v';
- break;
- case kMTBlockWise:
- vim_snprintf(buf, sizeof(buf), "%c%d", Ctrl_V, reglen + 1);
- break;
- case kMTUnknown:
- abort();
+ case kMTLineWise:
+ buf[0] = 'V';
+ break;
+ case kMTCharWise:
+ buf[0] = 'v';
+ break;
+ case kMTBlockWise:
+ vim_snprintf(buf, sizeof(buf), "%c%d", Ctrl_V, reglen + 1);
+ break;
+ case kMTUnknown:
+ abort();
}
tv_dict_add_str(dict, S_LEN("regtype"), buf);
@@ -9056,7 +9056,7 @@ static void f_setpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
pos_T pos;
int fnum;
- colnr_T curswant = -1;
+ colnr_T curswant = -1;
rettv->vval.v_number = -1;
const char *const name = tv_get_string_chk(argvars);
@@ -9100,25 +9100,25 @@ static int get_yank_type(char_u **const pp, MotionType *const yank_type, long *c
{
char_u *stropt = *pp;
switch (*stropt) {
- case 'v':
- case 'c': // character-wise selection
- *yank_type = kMTCharWise;
- break;
- case 'V':
- case 'l': // line-wise selection
- *yank_type = kMTLineWise;
- break;
- case 'b':
- case Ctrl_V: // block-wise selection
- *yank_type = kMTBlockWise;
- if (ascii_isdigit(stropt[1])) {
- stropt++;
- *block_len = getdigits_long(&stropt, false, 0) - 1;
- stropt--;
- }
- break;
- default:
- return FAIL;
+ case 'v':
+ case 'c': // character-wise selection
+ *yank_type = kMTCharWise;
+ break;
+ case 'V':
+ case 'l': // line-wise selection
+ *yank_type = kMTLineWise;
+ break;
+ case 'b':
+ case Ctrl_V: // block-wise selection
+ *yank_type = kMTBlockWise;
+ if (ascii_isdigit(stropt[1])) {
+ stropt++;
+ *block_len = getdigits_long(&stropt, false, 0) - 1;
+ stropt--;
+ }
+ break;
+ default:
+ return FAIL;
}
*pp = stropt;
return OK;
@@ -9319,7 +9319,7 @@ static void f_settagstack(typval_T *argvars, typval_T *rettv, FunPtr fptr)
static char *e_invact2 = N_("E962: Invalid action: '%s'");
win_T *wp;
dict_T *d;
- int action = 'r';
+ int action = 'r';
rettv->vval.v_number = -1;
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index 77297f9ffa..0e4ddffa33 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -68,11 +68,11 @@ void func_init(void)
static int get_function_args(char_u **argp, char_u endchar, garray_T *newargs, int *varargs,
garray_T *default_args, bool skip)
{
- bool mustend = false;
+ bool mustend = false;
char_u *arg = *argp;
char_u *p = arg;
- int c;
- int i;
+ int c;
+ int i;
if (newargs != NULL) {
ga_init(newargs, (int)sizeof(char_u *), 3);
@@ -205,8 +205,8 @@ static void register_closure(ufunc_T *fp)
/// Get a name for a lambda. Returned in static memory.
char_u *get_lambda_name(void)
{
- static char_u name[30];
- static int lambda_no = 0;
+ static char_u name[30];
+ static int lambda_no = 0;
snprintf((char *)name, sizeof(name), "<lambda>%d", ++lambda_no);
return name;
@@ -217,16 +217,16 @@ char_u *get_lambda_name(void)
/// @return OK or FAIL. Returns NOTDONE for dict or {expr}.
int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate)
{
- garray_T newargs = GA_EMPTY_INIT_VALUE;
+ garray_T newargs = GA_EMPTY_INIT_VALUE;
garray_T *pnewargs;
ufunc_T *fp = NULL;
partial_T *pt = NULL;
- int varargs;
- int ret;
+ int varargs;
+ int ret;
char_u *start = skipwhite(*arg + 1);
char_u *s, *e;
bool *old_eval_lavars = eval_lavars_used;
- bool eval_lavars = false;
+ bool eval_lavars = false;
// First, check if this is a lambda expression. "->" must exists.
ret = get_function_args(&start, '-', NULL, NULL, NULL, true);
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index f8186c000e..ecf0962eea 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -1800,7 +1800,7 @@ int do_write(exarg_T *eap)
int retval = FAIL;
char_u *free_fname = NULL;
buf_T *alt_buf = NULL;
- int name_was_missing;
+ int name_was_missing;
if (not_writing()) { // check 'write' option
return FAIL;
@@ -2294,8 +2294,8 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new
char_u *new_name = NULL;
bool did_set_swapcommand = false;
buf_T *buf;
- bufref_T bufref;
- bufref_T old_curbuf;
+ bufref_T bufref;
+ bufref_T old_curbuf;
char_u *free_fname = NULL;
int retval = FAIL;
long n;
@@ -3078,7 +3078,7 @@ void ex_change(exarg_T *eap)
void ex_z(exarg_T *eap)
{
char_u *x;
- int64_t bigness;
+ int64_t bigness;
char_u *kind;
int minus = 0;
linenr_T start, end, curs, i;
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 1a576bd891..7f3b019d57 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -317,7 +317,7 @@ static void profile_reset(void)
}
// Reset functions.
- size_t n = func_hashtab.ht_used;
+ size_t n = func_hashtab.ht_used;
hashitem_T *hi = func_hashtab.ht_array;
for (; n > (size_t)0; hi++) {
@@ -1703,8 +1703,8 @@ void init_pyxversion(void)
static int requires_py_version(char_u *filename)
{
FILE *file;
- int requires_py_version = 0;
- int i, lines;
+ int requires_py_version = 0;
+ int i, lines;
lines = (int)p_mls;
if (lines < 0) {
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 68dd039278..70057ffd46 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -5637,7 +5637,7 @@ static void ex_command(exarg_T *eap)
uint32_t argt = 0;
long def = -1;
int flags = 0;
- int compl = EXPAND_NOTHING;
+ int compl = EXPAND_NOTHING;
char_u *compl_arg = NULL;
cmd_addr_T addr_type_arg = ADDR_NONE;
int has_attr = (eap->arg[0] == '-');
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index ddf60eac18..5f0dca736a 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -140,25 +140,25 @@ static unsigned last_prompt_id = 0;
// Struct to store the viewstate during 'incsearch' highlighting.
typedef struct {
- colnr_T vs_curswant;
- colnr_T vs_leftcol;
- linenr_T vs_topline;
- int vs_topfill;
- linenr_T vs_botline;
- int vs_empty_rows;
+ colnr_T vs_curswant;
+ colnr_T vs_leftcol;
+ linenr_T vs_topline;
+ int vs_topfill;
+ linenr_T vs_botline;
+ int vs_empty_rows;
} viewstate_T;
// Struct to store the state of 'incsearch' highlighting.
typedef struct {
- pos_T search_start; // where 'incsearch' starts searching
- pos_T save_cursor;
+ pos_T search_start; // where 'incsearch' starts searching
+ pos_T save_cursor;
viewstate_T init_viewstate;
viewstate_T old_viewstate;
- pos_T match_start;
- pos_T match_end;
- bool did_incsearch;
- bool incsearch_postponed;
- int magic_save;
+ pos_T match_start;
+ pos_T match_end;
+ bool did_incsearch;
+ bool incsearch_postponed;
+ int magic_save;
} incsearch_state_T;
typedef struct command_line_state {
@@ -178,8 +178,8 @@ typedef struct command_line_state {
int did_wild_list; // did wild_list() recently
int wim_index; // index in wim_flags[]
int res;
- int save_msg_scroll;
- int save_State; // remember State when called
+ int save_msg_scroll;
+ int save_State; // remember State when called
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
@@ -383,7 +383,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s
// Don't do 'hlsearch' highlighting if the pattern matches everything.
if (!use_last_pat) {
char_u c = *end;
- int empty;
+ int empty;
*end = NUL;
empty = empty_pattern(p);
@@ -1502,7 +1502,7 @@ static int may_do_command_line_next_incsearch(int firstc, long count, incsearch_
ui_busy_start();
ui_flush();
- pos_T t;
+ pos_T t;
char_u *pat;
int search_flags = SEARCH_NOOF;
char_u save;
@@ -5272,7 +5272,7 @@ static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T
static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file)
{
char_u *e;
- garray_T ga;
+ garray_T ga;
char_u *const retstr = call_user_expand_func((user_expand_func_T)call_func_retstr, xp, num_file,
file);
@@ -6250,8 +6250,8 @@ int hist_type2char(int type)
static int open_cmdwin(void)
{
struct cmdline_info save_ccline;
- bufref_T old_curbuf;
- bufref_T bufref;
+ bufref_T old_curbuf;
+ bufref_T bufref;
win_T *old_curwin = curwin;
win_T *wp;
int i;
diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c
index b89807b9f1..2a1f39083c 100644
--- a/src/nvim/lua/xdiff.c
+++ b/src/nvim/lua/xdiff.c
@@ -265,8 +265,8 @@ int nlua_xdl_diff(lua_State *lstate)
Error err = ERROR_INIT;
xdemitconf_t cfg;
- xpparam_t params;
- xdemitcb_t ecb;
+ xpparam_t params;
+ xdemitcb_t ecb;
memset(&cfg, 0, sizeof(cfg));
memset(&params, 0, sizeof(params));
diff --git a/src/nvim/message.c b/src/nvim/message.c
index f9fe7774f6..ed673b52d3 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -762,7 +762,7 @@ bool emsgf_multiline(const char *const fmt, ...)
va_list ap;
- static char errbuf[MULTILINE_BUFSIZE];
+ static char errbuf[MULTILINE_BUFSIZE];
if (emsg_not_now()) {
return true;
}
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 3a5b2fb211..2f64f9ab29 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -992,7 +992,7 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
if ((local && existing_row) || visible_row) {
colnr_T off;
colnr_T col;
- int width;
+ int width;
getvcol(wp, pos, &scol, &ccol, &ecol);
@@ -1531,10 +1531,10 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
lineoff_T boff;
int fill_below_window;
linenr_T old_topline = curwin->w_topline;
- int old_topfill = curwin->w_topfill;
+ int old_topfill = curwin->w_topfill;
linenr_T old_botline = curwin->w_botline;
- int old_valid = curwin->w_valid;
- int old_empty_rows = curwin->w_empty_rows;
+ int old_valid = curwin->w_valid;
+ int old_empty_rows = curwin->w_empty_rows;
linenr_T cln = curwin->w_cursor.lnum; // Cursor Line Number
long so = get_scrolloff_value(curwin);
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 310f382db7..8623dc6c0c 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -3439,7 +3439,7 @@ static char_u *set_chars_option(win_T *wp, char_u **varp, bool set)
struct chars_tab {
int *cp; ///< char value
char *name; ///< char id
- int def; ///< default value
+ int def; ///< default value
};
struct chars_tab *tab;
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index f0d446b4c5..2bff65b241 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -873,10 +873,10 @@ static void system_data_cb(Stream *stream, RBuffer *buf, size_t count, void *dat
/// Returns the previous decision if size=0.
static bool out_data_decide_throttle(size_t size)
{
- static uint64_t started = 0; // Start time of the current throttle.
- static size_t received = 0; // Bytes observed since last throttle.
- static size_t visit = 0; // "Pulse" count of the current throttle.
- static char pulse_msg[] = { ' ', ' ', ' ', '\0' };
+ static uint64_t started = 0; // Start time of the current throttle.
+ static size_t received = 0; // Bytes observed since last throttle.
+ static size_t visit = 0; // "Pulse" count of the current throttle.
+ static char pulse_msg[] = { ' ', ' ', ' ', '\0' };
if (!size) {
bool previous_decision = (visit > 0);
@@ -933,8 +933,8 @@ static bool out_data_decide_throttle(size_t size)
static void out_data_ring(char *output, size_t size)
{
#define MAX_CHUNK_SIZE (OUT_DATA_THRESHOLD / 2)
- static char last_skipped[MAX_CHUNK_SIZE]; // Saved output.
- static size_t last_skipped_len = 0;
+ static char last_skipped[MAX_CHUNK_SIZE]; // Saved output.
+ static size_t last_skipped_len = 0;
assert(output != NULL || (size == 0 || size == SIZE_MAX));
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index d0bd63e6ca..eb0ba874f4 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -93,7 +93,7 @@ typedef enum
/// information and entries can be added later using setqflist()/setloclist().
typedef struct qf_list_S {
unsigned qf_id; ///< Unique identifier for this list
- qfltype_T qfl_type;
+ qfltype_T qfl_type;
qfline_T *qf_start; ///< pointer to the first error
qfline_T *qf_last; ///< pointer to the last error
qfline_T *qf_ptr; ///< pointer to the current error
@@ -103,7 +103,7 @@ typedef struct qf_list_S {
char_u *qf_title; ///< title derived from the command that created
///< the error list or set by setqflist
typval_T *qf_ctx; ///< context set by setqflist/setloclist
- Callback qftf_cb; ///< 'quickfixtextfunc' callback function
+ Callback qftf_cb; ///< 'quickfixtextfunc' callback function
struct dir_stack_T *qf_dir_stack;
char_u *qf_directory;
@@ -201,13 +201,13 @@ typedef struct {
size_t errmsglen;
long lnum;
long end_lnum;
- int col;
+ int col;
int end_col;
bool use_viscol;
char_u *pattern;
- int enr;
+ int enr;
char_u type;
- bool valid;
+ bool valid;
} qffields_T;
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -244,7 +244,7 @@ static char_u *e_no_more_items = (char_u *)N_("E553: No more items");
// Looking up a buffer can be slow if there are many. Remember the last one
// to make this a lot faster if there are multiple matches in the same file.
static char_u *qf_last_bufname = NULL;
-static bufref_T qf_last_bufref = { NULL, 0, 0 };
+static bufref_T qf_last_bufref = { NULL, 0, 0 };
static char *e_current_quickfix_list_was_changed =
N_("E925: Current quickfix list was changed");
@@ -913,7 +913,7 @@ static int qf_parse_line(qf_list_T *qfl, char_u *linebuf, size_t linelen, efm_T
qffields_T *fields)
{
efm_T *fmt_ptr;
- int idx = 0;
+ int idx = 0;
char_u *tail = NULL;
int status;
@@ -3115,8 +3115,8 @@ void qf_list(exarg_T *eap)
int idx1 = 1;
int idx2 = -1;
char_u *arg = eap->arg;
- int all = eap->forceit; // if not :cl!, only show
- // recognised errors
+ int all = eap->forceit; // if not :cl!, only show
+ // recognised errors
qf_info_T *qi;
if ((qi = qf_cmd_get_stack(eap, true)) == NULL) {
@@ -6448,7 +6448,7 @@ static int qf_setprop_items_from_lines(qf_info_T *qi, int qf_idx, const dict_T *
{
char_u *errorformat = p_efm;
dictitem_T *efm_di;
- int retval = FAIL;
+ int retval = FAIL;
// Use the user supplied errorformat settings (if present)
if ((efm_di = tv_dict_find(what, S_LEN("efm"))) != NULL) {
@@ -6491,7 +6491,7 @@ static int qf_setprop_context(qf_list_T *qfl, dictitem_T *di)
static int qf_setprop_curidx(qf_info_T *qi, qf_list_T *qfl, const dictitem_T *di)
FUNC_ATTR_NONNULL_ALL
{
- int newidx;
+ int newidx;
// If the specified index is '$', then use the last entry
if (di->di_tv.v_type == VAR_STRING
@@ -6537,7 +6537,7 @@ static int qf_set_properties(qf_info_T *qi, const dict_T *what, int action, char
{
qf_list_T *qfl;
dictitem_T *di;
- int retval = FAIL;
+ int retval = FAIL;
bool newlist = action == ' ' || qf_stack_empty(qi);
int qf_idx = qf_setprop_get_qfidx(qi, what, action, &newlist);
if (qf_idx == INVALID_QFIDX) { // List not found
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 79e960fe8b..5d887444f5 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -3667,8 +3667,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
n_extra = tab_len;
} else {
char_u *p;
- int i;
- int saved_nextra = n_extra;
+ int i;
+ int saved_nextra = n_extra;
if (vcol_off > 0) {
// there are characters to conceal
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 4be2402f1d..3d30932d69 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -1046,8 +1046,8 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count,
char_u *strcopy = NULL;
char_u *ps;
char_u *msgbuf = NULL;
- size_t len;
- bool has_offset = false;
+ size_t len;
+ bool has_offset = false;
/*
* A line offset is not remembered, this is vi compatible.
@@ -1182,8 +1182,8 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count,
if ((options & SEARCH_ECHO) && messaging() && !msg_silent
&& (!cmd_silent || !shortmess(SHM_SEARCHCOUNT))) {
char_u *trunc;
- char_u off_buf[40];
- size_t off_len = 0;
+ char_u off_buf[40];
+ size_t off_len = 0;
// Compute msg_row early.
msg_start();
@@ -2459,7 +2459,7 @@ int findsent(Direction dir, long count)
{
pos_T pos, tpos;
int c;
- int (*func)(pos_T *);
+ int (*func)(pos_T *);
bool noskip = false; // do not skip blanks
pos = curwin->w_cursor;
@@ -4474,7 +4474,7 @@ static void cmdline_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, bool sh
update_search_stat(dirc, pos, cursor_pos, &stat, recompute, maxcount,
timeout);
if (stat.cur > 0) {
- char t[SEARCH_STAT_BUF_LEN];
+ char t[SEARCH_STAT_BUF_LEN];
if (curwin->w_p_rl && *curwin->w_p_rlc == 's') {
if (stat.incomplete == 1) {
@@ -4534,19 +4534,19 @@ static void cmdline_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, bool sh
static void update_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, searchstat_T *stat,
bool recompute, int maxcount, long timeout)
{
- int save_ws = p_ws;
- bool wraparound = false;
- pos_T p = (*pos);
- static pos_T lastpos = { 0, 0, 0 };
- static int cur = 0;
- static int cnt = 0;
- static bool exact_match = false;
- static int incomplete = 0;
- static int last_maxcount = SEARCH_STAT_DEF_MAX_COUNT;
- static int chgtick = 0;
+ int save_ws = p_ws;
+ bool wraparound = false;
+ pos_T p = (*pos);
+ static pos_T lastpos = { 0, 0, 0 };
+ static int cur = 0;
+ static int cnt = 0;
+ static bool exact_match = false;
+ static int incomplete = 0;
+ static int last_maxcount = SEARCH_STAT_DEF_MAX_COUNT;
+ static int chgtick = 0;
static char_u *lastpat = NULL;
static buf_T *lbuf = NULL;
- proftime_T start;
+ proftime_T start;
memset(stat, 0, sizeof(searchstat_T));
@@ -4636,12 +4636,12 @@ static void update_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, searchst
// "searchcount()" function
void f_searchcount(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- pos_T pos = curwin->w_cursor;
+ pos_T pos = curwin->w_cursor;
char_u *pattern = NULL;
- int maxcount = SEARCH_STAT_DEF_MAX_COUNT;
- long timeout = SEARCH_STAT_DEF_TIMEOUT;
- bool recompute = true;
- searchstat_T stat;
+ int maxcount = SEARCH_STAT_DEF_MAX_COUNT;
+ long timeout = SEARCH_STAT_DEF_TIMEOUT;
+ bool recompute = true;
+ searchstat_T stat;
tv_dict_alloc_ret(rettv);
diff --git a/src/nvim/sha256.c b/src/nvim/sha256.c
index a2378cc202..9d6a2f2c41 100644
--- a/src/nvim/sha256.c
+++ b/src/nvim/sha256.c
@@ -51,8 +51,7 @@ void sha256_start(context_sha256_T *ctx)
ctx->state[7] = 0x5BE0CD19;
}
-static void sha256_process(context_sha256_T *ctx,
- const char_u data[SHA256_BUFFER_SIZE])
+static void sha256_process(context_sha256_T *ctx, const char_u data[SHA256_BUFFER_SIZE])
{
uint32_t temp1, temp2, W[SHA256_BUFFER_SIZE];
uint32_t A, B, C, D, E, F, G, H;
@@ -88,7 +87,7 @@ static void sha256_process(context_sha256_T *ctx,
#define R(t) \
(W[t] = S1(W[t - 2]) + W[t - 7] + \
- S0(W[t - 15]) + W[t - 16])
+ S0(W[t - 15]) + W[t - 16])
#define P(a, b, c, d, e, f, g, h, x, K) { \
temp1 = h + S3(e) + F1(e, f, g) + K + x; \
@@ -188,7 +187,7 @@ void sha256_update(context_sha256_T *ctx, const char_u *input, size_t length)
uint32_t left = ctx->total[0] & (SHA256_BUFFER_SIZE-1); // left < buf size
- ctx->total[0] += (uint32_t) length;
+ ctx->total[0] += (uint32_t)length;
ctx->total[0] &= 0xFFFFFFFF;
if (ctx->total[0] < length) {
@@ -262,8 +261,8 @@ void sha256_finish(context_sha256_T *ctx, char_u digest[SHA256_SUM_SIZE])
///
/// @returns hex digest of "buf[buf_len]" in a static array.
/// if "salt" is not NULL also do "salt[salt_len]".
-const char *sha256_bytes(const uint8_t *restrict buf, size_t buf_len,
- const uint8_t *restrict salt, size_t salt_len)
+const char *sha256_bytes(const uint8_t *restrict buf, size_t buf_len, const uint8_t *restrict salt,
+ size_t salt_len)
{
char_u sha256sum[SHA256_SUM_SIZE];
static char hexit[SHA256_BUFFER_SIZE + 1]; // buf size + NULL
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index 7d277fe5c8..25c9823dc7 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -1,51 +1,50 @@
// 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 <stdlib.h>
-#include <stddef.h>
-#include <stdbool.h>
-#include <string.h>
-#include <inttypes.h>
-#include <errno.h>
#include <assert.h>
-
+#include <errno.h>
+#include <inttypes.h>
#include <msgpack.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
#include <uv.h>
-#include "nvim/os/os.h"
-#include "nvim/os/time.h"
-#include "nvim/vim.h"
-#include "nvim/pos.h"
-#include "nvim/ascii.h"
-#include "nvim/shada.h"
-#include "nvim/message.h"
-#include "nvim/globals.h"
-#include "nvim/memory.h"
-#include "nvim/mark.h"
-#include "nvim/macros.h"
-#include "nvim/ops.h"
-#include "nvim/garray.h"
-#include "nvim/option.h"
-#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
+#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/buffer_defs.h"
+#include "nvim/eval/decode.h"
+#include "nvim/eval/encode.h"
+#include "nvim/eval/typval.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
-#include "nvim/search.h"
-#include "nvim/regexp.h"
-#include "nvim/eval/typval.h"
-#include "nvim/version.h"
-#include "nvim/path.h"
#include "nvim/fileio.h"
-#include "nvim/os/fileio.h"
-#include "nvim/strings.h"
-#include "nvim/quickfix.h"
-#include "nvim/eval/encode.h"
-#include "nvim/eval/decode.h"
+#include "nvim/garray.h"
+#include "nvim/globals.h"
#include "nvim/lib/khash.h"
#include "nvim/lib/kvec.h"
+#include "nvim/macros.h"
+#include "nvim/mark.h"
+#include "nvim/memory.h"
+#include "nvim/message.h"
+#include "nvim/msgpack_rpc/helpers.h"
+#include "nvim/ops.h"
+#include "nvim/option.h"
+#include "nvim/os/fileio.h"
+#include "nvim/os/os.h"
+#include "nvim/os/time.h"
+#include "nvim/path.h"
+#include "nvim/pos.h"
+#include "nvim/quickfix.h"
+#include "nvim/regexp.h"
+#include "nvim/search.h"
+#include "nvim/shada.h"
+#include "nvim/strings.h"
+#include "nvim/version.h"
+#include "nvim/vim.h"
#ifdef HAVE_BE64TOH
# define _BSD_SOURCE 1
@@ -67,24 +66,24 @@ KHASH_MAP_INIT_STR(fnamebufs, buf_T *)
KHASH_SET_INIT_STR(strset)
#define copy_option_part(src, dest, ...) \
- ((char *) copy_option_part((char_u **) src, (char_u *) dest, __VA_ARGS__))
+ ((char *)copy_option_part((char_u **)src, (char_u *)dest, __VA_ARGS__))
#define find_shada_parameter(...) \
- ((const char *) find_shada_parameter(__VA_ARGS__))
+ ((const char *)find_shada_parameter(__VA_ARGS__))
#define home_replace_save(a, b) \
- ((char *)home_replace_save(a, (char_u *)b))
+ ((char *)home_replace_save(a, (char_u *)b))
#define home_replace(a, b, c, d, e) \
- home_replace(a, (char_u *)b, (char_u *)c, d, e)
+ home_replace(a, (char_u *)b, (char_u *)c, d, e)
#define vim_rename(a, b) \
- (vim_rename((char_u *)a, (char_u *)b))
+ (vim_rename((char_u *)a, (char_u *)b))
#define mb_strnicmp(a, b, c) \
- (mb_strnicmp((char_u *)a, (char_u *)b, c))
+ (mb_strnicmp((char_u *)a, (char_u *)b, c))
#define path_try_shorten_fname(b) \
- ((char *)path_try_shorten_fname((char_u *)b))
+ ((char *)path_try_shorten_fname((char_u *)b))
#define buflist_new(ffname, sfname, ...) \
- (buflist_new((char_u *)ffname, (char_u *)sfname, __VA_ARGS__))
-#define os_isdir(f) (os_isdir((char_u *) f))
-#define regtilde(s, m) ((char *) regtilde((char_u *) s, m))
-#define path_tail_with_sep(f) ((char *) path_tail_with_sep((char_u *)f))
+ (buflist_new((char_u *)ffname, (char_u *)sfname, __VA_ARGS__))
+#define os_isdir(f) (os_isdir((char_u *)f))
+#define regtilde(s, m) ((char *)regtilde((char_u *)s, m))
+#define path_tail_with_sep(f) ((char *)path_tail_with_sep((char_u *)f))
#define SEARCH_KEY_MAGIC "sm"
#define SEARCH_KEY_SMARTCASE "sc"
@@ -172,7 +171,7 @@ typedef enum {
kSDItemBufferList = 9, ///< Buffer list.
kSDItemLocalMark = 10, ///< Buffer-local mark.
kSDItemChange = 11, ///< Item from buffer change list.
-#define SHADA_LAST_ENTRY ((uint64_t) kSDItemChange)
+#define SHADA_LAST_ENTRY ((uint64_t)kSDItemChange)
} ShadaEntryType;
/// Possible results when reading ShaDa file
@@ -202,11 +201,11 @@ enum SRNIFlags {
kSDReadHeader = (1 << kSDItemHeader), ///< Determines whether header should
///< be read (it is usually ignored).
kSDReadUndisableableData = (
- (1 << kSDItemSearchPattern)
- | (1 << kSDItemSubString)
- | (1 << kSDItemJump)), ///< Data reading which cannot be disabled by
- ///< &shada or other options except for disabling
- ///< reading ShaDa as a whole.
+ (1 << kSDItemSearchPattern)
+ | (1 << kSDItemSubString)
+ | (1 << kSDItemJump)), ///< Data reading which cannot be disabled by
+ ///< &shada or other options except for disabling
+ ///< reading ShaDa as a whole.
kSDReadRegisters = (1 << kSDItemRegister), ///< Determines whether registers
///< should be read (may only be
///< disabled when writing, but
@@ -434,13 +433,13 @@ typedef struct sd_write_def {
#endif
#define DEF_SDE(name, attr, ...) \
- [kSDItem##name] = { \
- .timestamp = 0, \
- .type = kSDItem##name, \
- .data = { \
- .attr = { __VA_ARGS__ } \
- } \
- }
+ [kSDItem##name] = { \
+ .timestamp = 0, \
+ .type = kSDItem##name, \
+ .data = { \
+ .attr = { __VA_ARGS__ } \
+ } \
+ }
#define DEFAULT_POS { 1, 0, 0 }
static const pos_T default_pos = DEFAULT_POS;
static const ShadaEntry sd_default_values[] = {
@@ -475,9 +474,9 @@ static const ShadaEntry sd_default_values[] = {
DEF_SDE(Variable, global_var,
.name = NULL,
.value = {
- .v_type = VAR_UNKNOWN,
- .vval = { .v_string = NULL }
- },
+ .v_type = VAR_UNKNOWN,
+ .vval = { .v_string = NULL }
+ },
.additional_elements = NULL),
DEF_SDE(GlobalMark, filemark,
.name = '"',
@@ -533,17 +532,16 @@ static inline void hmll_init(HMLList *const hmll, const size_t size)
///
/// @return `for` cycle header (use `HMLL_FORALL(hmll, cur_entry) {body}`).
#define HMLL_FORALL(hmll, cur_entry, code) \
- for (HMLListEntry *cur_entry = (hmll)->first; cur_entry != NULL; \
- cur_entry = cur_entry->next) { \
- code \
- } \
+ for (HMLListEntry *cur_entry = (hmll)->first; cur_entry != NULL; \
+ cur_entry = cur_entry->next) { \
+ code \
+ } \
/// Remove entry from the linked list
///
/// @param hmll List to remove from.
/// @param hmll_entry Entry to remove.
-static inline void hmll_remove(HMLList *const hmll,
- HMLListEntry *const hmll_entry)
+static inline void hmll_remove(HMLList *const hmll, HMLListEntry *const hmll_entry)
FUNC_ATTR_NONNULL_ALL
{
if (hmll_entry == hmll->last_free_entry - 1) {
@@ -580,9 +578,7 @@ static inline void hmll_remove(HMLList *const hmll,
/// to insert at the first entry.
/// @param[in] data Data to insert.
/// @param[in] can_free_entry True if data can be freed.
-static inline void hmll_insert(HMLList *const hmll,
- HMLListEntry *hmll_entry,
- const ShadaEntry data,
+static inline void hmll_insert(HMLList *const hmll, HMLListEntry *hmll_entry, const ShadaEntry data,
const bool can_free_entry)
FUNC_ATTR_NONNULL_ARG(1)
{
@@ -595,11 +591,11 @@ static inline void hmll_insert(HMLList *const hmll,
}
HMLListEntry *target_entry;
if (hmll->free_entry == NULL) {
- assert((size_t) (hmll->last_free_entry - hmll->entries)
+ assert((size_t)(hmll->last_free_entry - hmll->entries)
== hmll->num_entries);
target_entry = hmll->last_free_entry++;
} else {
- assert((size_t) (hmll->last_free_entry - hmll->entries) - 1
+ assert((size_t)(hmll->last_free_entry - hmll->entries) - 1
== hmll->num_entries);
target_entry = hmll->free_entry;
hmll->free_entry = NULL;
@@ -637,10 +633,10 @@ static inline void hmll_insert(HMLList *const hmll,
///
/// @return `for` cycle header (use `HMLL_FORALL(hmll, cur_entry) {body}`).
#define HMLL_ITER_BACK(hmll, cur_entry, code) \
- for (cur_entry = (hmll)->last; cur_entry != NULL; \
- cur_entry = cur_entry->prev) { \
- code \
- }
+ for (cur_entry = (hmll)->last; cur_entry != NULL; \
+ cur_entry = cur_entry->prev) { \
+ code \
+ }
/// Free linked list
///
@@ -655,8 +651,7 @@ static inline void hmll_dealloc(HMLList *const hmll)
/// Wrapper for reading from file descriptors
///
/// @return -1 or number of bytes read.
-static ptrdiff_t read_file(ShaDaReadDef *const sd_reader, void *const dest,
- const size_t size)
+static ptrdiff_t read_file(ShaDaReadDef *const sd_reader, void *const dest, const size_t size)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
const ptrdiff_t ret = file_read(sd_reader->cookie, dest, size);
@@ -678,14 +673,13 @@ static int read_char(ShaDaReadDef *const sd_reader)
if (read_bytes != 1) {
return EOF;
}
- return (int) ret;
+ return (int)ret;
}
/// Wrapper for writing to file descriptors
///
/// @return -1 or number of bytes written.
-static ptrdiff_t write_file(ShaDaWriteDef *const sd_writer,
- const void *const dest,
+static ptrdiff_t write_file(ShaDaWriteDef *const sd_writer, const void *const dest,
const size_t size)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
@@ -720,8 +714,7 @@ static void close_sd_writer(ShaDaWriteDef *const sd_writer)
///
/// @return FAIL in case of failure, OK in case of success. May set
/// sd_reader->eof or sd_reader->error.
-static int sd_reader_skip_read(ShaDaReadDef *const sd_reader,
- const size_t offset)
+static int sd_reader_skip_read(ShaDaReadDef *const sd_reader, const size_t offset)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
const ptrdiff_t skip_bytes = file_skip(sd_reader->cookie, offset);
@@ -749,8 +742,7 @@ static int sd_reader_skip_read(ShaDaReadDef *const sd_reader,
///
/// @return kSDReadStatusReadError, kSDReadStatusNotShaDa or
/// kSDReadStatusSuccess.
-static ShaDaReadResult sd_reader_skip(ShaDaReadDef *const sd_reader,
- const size_t offset)
+static ShaDaReadResult sd_reader_skip(ShaDaReadDef *const sd_reader, const size_t offset)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
if (sd_reader->skip(sd_reader, offset) != OK) {
@@ -762,7 +754,7 @@ static ShaDaReadResult sd_reader_skip(ShaDaReadDef *const sd_reader,
emsgf(_(RCERR "Error while reading ShaDa file: "
"last entry specified that it occupies %" PRIu64 " bytes, "
"but file ended earlier"),
- (uint64_t) offset);
+ (uint64_t)offset);
return kSDReadStatusNotShaDa;
}
abort();
@@ -776,8 +768,7 @@ static ShaDaReadResult sd_reader_skip(ShaDaReadDef *const sd_reader,
/// @param[out] sd_reader Location where reader structure will be saved.
///
/// @return libuv error in case of error, 0 otherwise.
-static int open_shada_file_for_reading(const char *const fname,
- ShaDaReadDef *sd_reader)
+static int open_shada_file_for_reading(const char *const fname, ShaDaReadDef *sd_reader)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
int error;
@@ -819,7 +810,7 @@ static void close_file(void *cookie)
static inline bool in_bufset(const khash_t(bufset) *const set, const buf_T *buf)
FUNC_ATTR_PURE
{
- return kh_get(bufset, set, (uintptr_t) buf) != kh_end(set);
+ return kh_get(bufset, set, (uintptr_t)buf) != kh_end(set);
}
/// Check whether string is in the given set
@@ -837,7 +828,7 @@ static inline bool in_strset(const khash_t(strset) *const set, char *str)
/// Msgpack callback for writing to ShaDaWriteDef*
static int msgpack_sd_writer_write(void *data, const char *buf, size_t len)
{
- ShaDaWriteDef *const sd_writer = (ShaDaWriteDef *) data;
+ ShaDaWriteDef *const sd_writer = (ShaDaWriteDef *)data;
ptrdiff_t written_bytes = sd_writer->write(sd_writer, buf, len);
if (written_bytes == -1) {
emsgf(_(SERR "System error while writing ShaDa file: %s"),
@@ -910,10 +901,8 @@ static int shada_read_file(const char *const file, const int flags)
/// @param[out] hist Location where iteration results should be saved.
///
/// @return Next iteration state.
-static const void *shada_hist_iter(const void *const iter,
- const uint8_t history_type,
- const bool zero,
- ShadaEntry *const hist)
+static const void *shada_hist_iter(const void *const iter, const uint8_t history_type,
+ const bool zero, ShadaEntry *const hist)
FUNC_ATTR_NONNULL_ARG(4) FUNC_ATTR_WARN_UNUSED_RESULT
{
histentry_T hist_he;
@@ -927,9 +916,9 @@ static const void *shada_hist_iter(const void *const iter,
.data = {
.history_item = {
.histtype = history_type,
- .string = (char *) hist_he.hisstr,
- .sep = (char) (history_type == HIST_SEARCH
- ? (char) hist_he.hisstr[STRLEN(hist_he.hisstr) + 1]
+ .string = (char *)hist_he.hisstr,
+ .sep = (char)(history_type == HIST_SEARCH
+ ? (char)hist_he.hisstr[STRLEN(hist_he.hisstr) + 1]
: 0),
.additional_elements = hist_he.additional_elements,
}
@@ -954,8 +943,8 @@ static const void *shada_hist_iter(const void *const iter,
/// be used. Must be true only if inserting
/// entry from current Neovim history.
/// @param[in] can_free_entry True if entry can be freed.
-static void hms_insert(HistoryMergerState *const hms_p, const ShadaEntry entry,
- const bool do_iter, const bool can_free_entry)
+static void hms_insert(HistoryMergerState *const hms_p, const ShadaEntry entry, const bool do_iter,
+ const bool can_free_entry)
FUNC_ATTR_NONNULL_ALL
{
if (do_iter) {
@@ -1008,11 +997,8 @@ static void hms_insert(HistoryMergerState *const hms_p, const ShadaEntry entry,
/// @param[in] do_merge Prepare structure for merging elements.
/// @param[in] reading If true, then merger is reading history for use
/// in Neovim.
-static inline void hms_init(HistoryMergerState *const hms_p,
- const uint8_t history_type,
- const size_t num_elements,
- const bool do_merge,
- const bool reading)
+static inline void hms_init(HistoryMergerState *const hms_p, const uint8_t history_type,
+ const size_t num_elements, const bool do_merge, const bool reading)
FUNC_ATTR_NONNULL_ALL
{
hmll_init(&hms_p->hmll, num_elements);
@@ -1027,8 +1013,7 @@ static inline void hms_init(HistoryMergerState *const hms_p,
///
/// @param[in,out] hms_p Merger structure into which history should be
/// inserted.
-static inline void hms_insert_whole_neovim_history(
- HistoryMergerState *const hms_p)
+static inline void hms_insert_whole_neovim_history(HistoryMergerState *const hms_p)
FUNC_ATTR_NONNULL_ALL
{
while (hms_p->last_hist_entry.type != kSDItemMissing) {
@@ -1048,21 +1033,20 @@ static inline void hms_insert_whole_neovim_history(
/// @param[out] new_hisidx New last history entry index.
/// @param[out] new_hisnum Amount of history items in merger structure.
static inline void hms_to_he_array(const HistoryMergerState *const hms_p,
- histentry_T *const hist_array,
- int *const new_hisidx,
+ histentry_T *const hist_array, int *const new_hisidx,
int *const new_hisnum)
FUNC_ATTR_NONNULL_ALL
{
histentry_T *hist = hist_array;
HMLL_FORALL(&hms_p->hmll, cur_entry, {
hist->timestamp = cur_entry->data.timestamp;
- hist->hisnum = (int) (hist - hist_array) + 1;
- hist->hisstr = (char_u *) cur_entry->data.data.history_item.string;
+ hist->hisnum = (int)(hist - hist_array) + 1;
+ hist->hisstr = (char_u *)cur_entry->data.data.history_item.string;
hist->additional_elements =
- cur_entry->data.data.history_item.additional_elements;
+ cur_entry->data.data.history_item.additional_elements;
hist++;
})
- *new_hisnum = (int) (hist - hist_array);
+ *new_hisnum = (int)(hist - hist_array);
*new_hisidx = *new_hisnum - 1;
}
@@ -1083,7 +1067,7 @@ static inline void hms_dealloc(HistoryMergerState *const hms_p)
///
/// @return for cycle header. Use `HMS_ITER(hms_p, cur_entry) {body}`.
#define HMS_ITER(hms_p, cur_entry, code) \
- HMLL_FORALL(&((hms_p)->hmll), cur_entry, code)
+ HMLL_FORALL(&((hms_p)->hmll), cur_entry, code)
/// Find buffer for given buffer name (cached)
///
@@ -1091,8 +1075,7 @@ static inline void hms_dealloc(HistoryMergerState *const hms_p)
/// @param[in] fname File name to find.
///
/// @return Pointer to the buffer or NULL.
-static buf_T *find_buffer(khash_t(fnamebufs) *const fname_bufs,
- const char *const fname)
+static buf_T *find_buffer(khash_t(fnamebufs) *const fname_bufs, const char *const fname)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
int kh_ret;
@@ -1123,7 +1106,7 @@ static inline bool marks_equal(const pos_T a, const pos_T b)
entry, fname_cond, free_func, fin_func, \
idxadj_func, afterfree_func) \
do { \
- const int jl_len = (int) jumps_size; \
+ const int jl_len = (int)jumps_size; \
int i; \
for (i = jl_len; i > 0; i--) { \
const jumps_type jl_entry = jumps[i - 1]; \
@@ -1140,17 +1123,17 @@ static inline bool marks_equal(const pos_T a, const pos_T b)
free_func(jumps[0]); \
i--; \
if (i > 0) { \
- memmove(&jumps[0], &jumps[1], sizeof(jumps[1]) * (size_t) i); \
+ memmove(&jumps[0], &jumps[1], sizeof(jumps[1]) * (size_t)i); \
} \
} else if (i != jl_len) { \
memmove(&jumps[i + 1], &jumps[i], \
- sizeof(jumps[0]) * (size_t) (jl_len - i)); \
+ sizeof(jumps[0]) * (size_t)(jl_len - i)); \
} \
} else if (i == 0) { \
if (jl_len == JUMPLISTSIZE) { \
i = -1; \
} else if (jl_len > 0) { \
- memmove(&jumps[1], &jumps[0], sizeof(jumps[0]) * (size_t) jl_len); \
+ memmove(&jumps[1], &jumps[0], sizeof(jumps[0]) * (size_t)jl_len); \
} \
} \
if (i != -1) { \
@@ -1177,8 +1160,8 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
const bool get_old_files = (flags & (kShaDaGetOldfiles | kShaDaForceit)
&& (force || tv_list_len(oldfiles_list) == 0));
const bool want_marks = flags & kShaDaWantMarks;
- const unsigned srni_flags = (unsigned) (
- (flags & kShaDaWantInfo
+ const unsigned srni_flags = (unsigned)(
+ (flags & kShaDaWantInfo
? (kSDReadUndisableableData
| kSDReadRegisters
| kSDReadGlobalMarks
@@ -1190,11 +1173,11 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
&& ARGCOUNT == 0
? kSDReadBufferList
: 0))
- : 0)
- | (want_marks && get_shada_parameter('\'') > 0
+ : 0)
+ | (want_marks && get_shada_parameter('\'') > 0
? kSDReadLocalMarks | kSDReadChanges
: 0)
- | (get_old_files
+ | (get_old_files
? kSDReadLocalMarks
: 0));
if (srni_flags == 0) {
@@ -1204,7 +1187,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
HistoryMergerState hms[HIST_COUNT];
if (srni_flags & kSDReadHistory) {
for (uint8_t i = 0; i < HIST_COUNT; i++) {
- hms_init(&hms[i], i, (size_t) p_hi, true, true);
+ hms_init(&hms[i], i, (size_t)p_hi, true, true);
}
}
ShadaEntry cur_entry;
@@ -1219,253 +1202,237 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
while ((srni_ret = shada_read_next_item(sd_reader, &cur_entry, srni_flags, 0))
!= kSDReadStatusFinished) {
switch (srni_ret) {
- case kSDReadStatusSuccess: {
- break;
- }
- case kSDReadStatusFinished: {
- // Should be handled by the while condition.
- abort();
- }
- case kSDReadStatusNotShaDa:
- case kSDReadStatusReadError: {
- goto shada_read_main_cycle_end;
- }
- case kSDReadStatusMalformed: {
- continue;
- }
+ case kSDReadStatusSuccess:
+ break;
+ case kSDReadStatusFinished:
+ // Should be handled by the while condition.
+ abort();
+ case kSDReadStatusNotShaDa:
+ case kSDReadStatusReadError:
+ goto shada_read_main_cycle_end;
+ case kSDReadStatusMalformed:
+ continue;
}
switch (cur_entry.type) {
- case kSDItemMissing: {
- abort();
- }
- case kSDItemUnknown: {
- break;
- }
- case kSDItemHeader: {
- shada_free_shada_entry(&cur_entry);
- break;
- }
- case kSDItemSearchPattern: {
- if (!force) {
- SearchPattern pat;
- (cur_entry.data.search_pattern.is_substitute_pattern
+ case kSDItemMissing:
+ abort();
+ case kSDItemUnknown:
+ break;
+ case kSDItemHeader:
+ shada_free_shada_entry(&cur_entry);
+ break;
+ case kSDItemSearchPattern:
+ if (!force) {
+ SearchPattern pat;
+ (cur_entry.data.search_pattern.is_substitute_pattern
? &get_substitute_pattern
: &get_search_pattern)(&pat);
- if (pat.pat != NULL && pat.timestamp >= cur_entry.timestamp) {
- shada_free_shada_entry(&cur_entry);
- break;
- }
+ if (pat.pat != NULL && pat.timestamp >= cur_entry.timestamp) {
+ shada_free_shada_entry(&cur_entry);
+ break;
}
- (cur_entry.data.search_pattern.is_substitute_pattern
+ }
+ (cur_entry.data.search_pattern.is_substitute_pattern
? &set_substitute_pattern
: &set_search_pattern)((SearchPattern) {
- .magic = cur_entry.data.search_pattern.magic,
- .no_scs = !cur_entry.data.search_pattern.smartcase,
- .off = {
- .dir = cur_entry.data.search_pattern.search_backward ? '?' : '/',
- .line = cur_entry.data.search_pattern.has_line_offset,
- .end = cur_entry.data.search_pattern.place_cursor_at_end,
- .off = cur_entry.data.search_pattern.offset,
- },
- .pat = (char_u *) cur_entry.data.search_pattern.pat,
- .additional_data = cur_entry.data.search_pattern.additional_data,
- .timestamp = cur_entry.timestamp,
- });
- if (cur_entry.data.search_pattern.is_last_used) {
- set_last_used_pattern(
- cur_entry.data.search_pattern.is_substitute_pattern);
- set_no_hlsearch(!cur_entry.data.search_pattern.highlighted);
- }
- // Do not free shada entry: its allocated memory was saved above.
- break;
- }
- case kSDItemSubString: {
- if (!force) {
- SubReplacementString sub;
- sub_get_replacement(&sub);
- if (sub.sub != NULL && sub.timestamp >= cur_entry.timestamp) {
- shada_free_shada_entry(&cur_entry);
- break;
- }
- }
- sub_set_replacement((SubReplacementString) {
- .sub = cur_entry.data.sub_string.sub,
- .timestamp = cur_entry.timestamp,
- .additional_elements = cur_entry.data.sub_string.additional_elements,
- });
- // Without using regtilde and without / &cpo flag previous substitute
- // string is close to useless: you can only use it with :& or :~ and
- // that’s all because s//~ is not available until the first call to
- // regtilde. Vim was not calling this for some reason.
- (void) regtilde(cur_entry.data.sub_string.sub, p_magic);
- // Do not free shada entry: its allocated memory was saved above.
- break;
+ .magic = cur_entry.data.search_pattern.magic,
+ .no_scs = !cur_entry.data.search_pattern.smartcase,
+ .off = {
+ .dir = cur_entry.data.search_pattern.search_backward ? '?' : '/',
+ .line = cur_entry.data.search_pattern.has_line_offset,
+ .end = cur_entry.data.search_pattern.place_cursor_at_end,
+ .off = cur_entry.data.search_pattern.offset,
+ },
+ .pat = (char_u *)cur_entry.data.search_pattern.pat,
+ .additional_data = cur_entry.data.search_pattern.additional_data,
+ .timestamp = cur_entry.timestamp,
+ });
+ if (cur_entry.data.search_pattern.is_last_used) {
+ set_last_used_pattern(cur_entry.data.search_pattern.is_substitute_pattern);
+ set_no_hlsearch(!cur_entry.data.search_pattern.highlighted);
}
- case kSDItemHistoryEntry: {
- if (cur_entry.data.history_item.histtype >= HIST_COUNT) {
+ // Do not free shada entry: its allocated memory was saved above.
+ break;
+ case kSDItemSubString:
+ if (!force) {
+ SubReplacementString sub;
+ sub_get_replacement(&sub);
+ if (sub.sub != NULL && sub.timestamp >= cur_entry.timestamp) {
shada_free_shada_entry(&cur_entry);
break;
}
- hms_insert(hms + cur_entry.data.history_item.histtype, cur_entry, true,
- true);
- // Do not free shada entry: its allocated memory was saved above.
+ }
+ sub_set_replacement((SubReplacementString) {
+ .sub = cur_entry.data.sub_string.sub,
+ .timestamp = cur_entry.timestamp,
+ .additional_elements = cur_entry.data.sub_string.additional_elements,
+ });
+ // Without using regtilde and without / &cpo flag previous substitute
+ // string is close to useless: you can only use it with :& or :~ and
+ // that’s all because s//~ is not available until the first call to
+ // regtilde. Vim was not calling this for some reason.
+ (void)regtilde(cur_entry.data.sub_string.sub, p_magic);
+ // Do not free shada entry: its allocated memory was saved above.
+ break;
+ case kSDItemHistoryEntry:
+ if (cur_entry.data.history_item.histtype >= HIST_COUNT) {
+ shada_free_shada_entry(&cur_entry);
+ break;
+ }
+ hms_insert(hms + cur_entry.data.history_item.histtype, cur_entry, true,
+ true);
+ // Do not free shada entry: its allocated memory was saved above.
+ break;
+ case kSDItemRegister:
+ if (cur_entry.data.reg.type != kMTCharWise
+ && cur_entry.data.reg.type != kMTLineWise
+ && cur_entry.data.reg.type != kMTBlockWise) {
+ shada_free_shada_entry(&cur_entry);
break;
}
- case kSDItemRegister: {
- if (cur_entry.data.reg.type != kMTCharWise
- && cur_entry.data.reg.type != kMTLineWise
- && cur_entry.data.reg.type != kMTBlockWise) {
+ if (!force) {
+ const yankreg_T *const reg = op_reg_get(cur_entry.data.reg.name);
+ if (reg == NULL || reg->timestamp >= cur_entry.timestamp) {
shada_free_shada_entry(&cur_entry);
break;
}
- if (!force) {
- const yankreg_T *const reg = op_reg_get(cur_entry.data.reg.name);
- if (reg == NULL || reg->timestamp >= cur_entry.timestamp) {
- shada_free_shada_entry(&cur_entry);
- break;
- }
- }
- if (!op_reg_set(cur_entry.data.reg.name, (yankreg_T) {
- .y_array = (char_u **)cur_entry.data.reg.contents,
- .y_size = cur_entry.data.reg.contents_size,
- .y_type = cur_entry.data.reg.type,
- .y_width = (colnr_T) cur_entry.data.reg.width,
- .timestamp = cur_entry.timestamp,
- .additional_data = cur_entry.data.reg.additional_data,
- }, cur_entry.data.reg.is_unnamed)) {
- shada_free_shada_entry(&cur_entry);
- }
- // Do not free shada entry: its allocated memory was saved above.
- break;
}
- case kSDItemVariable: {
- var_set_global(cur_entry.data.global_var.name,
- cur_entry.data.global_var.value);
- cur_entry.data.global_var.value.v_type = VAR_UNKNOWN;
+ if (!op_reg_set(cur_entry.data.reg.name, (yankreg_T) {
+ .y_array = (char_u **)cur_entry.data.reg.contents,
+ .y_size = cur_entry.data.reg.contents_size,
+ .y_type = cur_entry.data.reg.type,
+ .y_width = (colnr_T)cur_entry.data.reg.width,
+ .timestamp = cur_entry.timestamp,
+ .additional_data = cur_entry.data.reg.additional_data,
+ }, cur_entry.data.reg.is_unnamed)) {
shada_free_shada_entry(&cur_entry);
- break;
}
- case kSDItemJump:
- case kSDItemGlobalMark: {
- buf_T *buf = find_buffer(&fname_bufs, cur_entry.data.filemark.fname);
- if (buf != NULL) {
- XFREE_CLEAR(cur_entry.data.filemark.fname);
- }
- xfmark_T fm = (xfmark_T) {
- .fname = (char_u *) (buf == NULL
+ // Do not free shada entry: its allocated memory was saved above.
+ break;
+ case kSDItemVariable:
+ var_set_global(cur_entry.data.global_var.name,
+ cur_entry.data.global_var.value);
+ cur_entry.data.global_var.value.v_type = VAR_UNKNOWN;
+ shada_free_shada_entry(&cur_entry);
+ break;
+ case kSDItemJump:
+ case kSDItemGlobalMark: {
+ buf_T *buf = find_buffer(&fname_bufs, cur_entry.data.filemark.fname);
+ if (buf != NULL) {
+ XFREE_CLEAR(cur_entry.data.filemark.fname);
+ }
+ xfmark_T fm = (xfmark_T) {
+ .fname = (char_u *)(buf == NULL
? cur_entry.data.filemark.fname
: NULL),
- .fmark = {
- .mark = cur_entry.data.filemark.mark,
- .fnum = (buf == NULL ? 0 : buf->b_fnum),
- .timestamp = cur_entry.timestamp,
- .additional_data = cur_entry.data.filemark.additional_data,
- },
- };
- if (cur_entry.type == kSDItemGlobalMark) {
- if (!mark_set_global(cur_entry.data.filemark.name, fm, !force)) {
- shada_free_shada_entry(&cur_entry);
- break;
- }
- } else {
+ .fmark = {
+ .mark = cur_entry.data.filemark.mark,
+ .fnum = (buf == NULL ? 0 : buf->b_fnum),
+ .timestamp = cur_entry.timestamp,
+ .additional_data = cur_entry.data.filemark.additional_data,
+ },
+ };
+ if (cur_entry.type == kSDItemGlobalMark) {
+ if (!mark_set_global(cur_entry.data.filemark.name, fm, !force)) {
+ shada_free_shada_entry(&cur_entry);
+ break;
+ }
+ } else {
#define SDE_TO_XFMARK(entry) fm
#define ADJUST_IDX(i) \
- if (curwin->w_jumplistidx >= i \
- && curwin->w_jumplistidx + 1 <= curwin->w_jumplistlen) { \
- curwin->w_jumplistidx++; \
- }
+ if (curwin->w_jumplistidx >= i \
+ && curwin->w_jumplistidx + 1 <= curwin->w_jumplistlen) { \
+ curwin->w_jumplistidx++; \
+ }
#define DUMMY_AFTERFREE(entry)
- MERGE_JUMPS(curwin->w_jumplistlen, curwin->w_jumplist, xfmark_T,
- fmark.timestamp, fmark.mark, cur_entry,
- (buf == NULL
+ MERGE_JUMPS(curwin->w_jumplistlen, curwin->w_jumplist, xfmark_T,
+ fmark.timestamp, fmark.mark, cur_entry,
+ (buf == NULL
? (jl_entry.fname != NULL
&& STRCMP(fm.fname, jl_entry.fname) == 0)
: fm.fmark.fnum == jl_entry.fmark.fnum),
- free_xfmark, SDE_TO_XFMARK, ADJUST_IDX, DUMMY_AFTERFREE);
+ free_xfmark, SDE_TO_XFMARK, ADJUST_IDX, DUMMY_AFTERFREE);
#undef SDE_TO_XFMARK
#undef ADJUST_IDX
#undef DUMMY_AFTERFREE
- }
- // Do not free shada entry: its allocated memory was saved above.
- break;
}
- case kSDItemBufferList: {
- for (size_t i = 0; i < cur_entry.data.buffer_list.size; i++) {
- char *const sfname = path_try_shorten_fname(
- cur_entry.data.buffer_list.buffers[i].fname);
- buf_T *const buf = buflist_new(
- cur_entry.data.buffer_list.buffers[i].fname, sfname, 0,
- BLN_LISTED);
- if (buf != NULL) {
- RESET_FMARK(&buf->b_last_cursor,
- cur_entry.data.buffer_list.buffers[i].pos, 0);
- buflist_setfpos(buf, curwin, buf->b_last_cursor.mark.lnum,
- buf->b_last_cursor.mark.col, false);
- buf->additional_data =
- cur_entry.data.buffer_list.buffers[i].additional_data;
- cur_entry.data.buffer_list.buffers[i].additional_data = NULL;
- }
+ // Do not free shada entry: its allocated memory was saved above.
+ break;
+ }
+ case kSDItemBufferList:
+ for (size_t i = 0; i < cur_entry.data.buffer_list.size; i++) {
+ char *const sfname = path_try_shorten_fname(cur_entry.data.buffer_list.buffers[i].fname);
+ buf_T *const buf = buflist_new(cur_entry.data.buffer_list.buffers[i].fname, sfname, 0,
+ BLN_LISTED);
+ if (buf != NULL) {
+ RESET_FMARK(&buf->b_last_cursor,
+ cur_entry.data.buffer_list.buffers[i].pos, 0);
+ buflist_setfpos(buf, curwin, buf->b_last_cursor.mark.lnum,
+ buf->b_last_cursor.mark.col, false);
+ buf->additional_data =
+ cur_entry.data.buffer_list.buffers[i].additional_data;
+ cur_entry.data.buffer_list.buffers[i].additional_data = NULL;
}
- shada_free_shada_entry(&cur_entry);
- break;
}
- case kSDItemChange:
- case kSDItemLocalMark: {
- if (get_old_files && !in_strset(&oldfiles_set,
- cur_entry.data.filemark.fname)) {
- char *fname = cur_entry.data.filemark.fname;
- if (want_marks) {
- // Do not bother with allocating memory for the string if already
- // allocated string from cur_entry can be used. It cannot be used if
- // want_marks is set because this way it may be used for a mark.
- fname = xstrdup(fname);
- }
- int kh_ret;
- (void)kh_put(strset, &oldfiles_set, fname, &kh_ret);
- tv_list_append_allocated_string(oldfiles_list, fname);
- if (!want_marks) {
- // Avoid free because this string was already used.
- cur_entry.data.filemark.fname = NULL;
- }
+ shada_free_shada_entry(&cur_entry);
+ break;
+ case kSDItemChange:
+ case kSDItemLocalMark: {
+ if (get_old_files && !in_strset(&oldfiles_set,
+ cur_entry.data.filemark.fname)) {
+ char *fname = cur_entry.data.filemark.fname;
+ if (want_marks) {
+ // Do not bother with allocating memory for the string if already
+ // allocated string from cur_entry can be used. It cannot be used if
+ // want_marks is set because this way it may be used for a mark.
+ fname = xstrdup(fname);
}
+ int kh_ret;
+ (void)kh_put(strset, &oldfiles_set, fname, &kh_ret);
+ tv_list_append_allocated_string(oldfiles_list, fname);
if (!want_marks) {
- shada_free_shada_entry(&cur_entry);
- break;
+ // Avoid free because this string was already used.
+ cur_entry.data.filemark.fname = NULL;
}
- buf_T *buf = find_buffer(&fname_bufs, cur_entry.data.filemark.fname);
- if (buf == NULL) {
+ }
+ if (!want_marks) {
+ shada_free_shada_entry(&cur_entry);
+ break;
+ }
+ buf_T *buf = find_buffer(&fname_bufs, cur_entry.data.filemark.fname);
+ if (buf == NULL) {
+ shada_free_shada_entry(&cur_entry);
+ break;
+ }
+ const fmark_T fm = (fmark_T) {
+ .mark = cur_entry.data.filemark.mark,
+ .fnum = 0,
+ .timestamp = cur_entry.timestamp,
+ .additional_data = cur_entry.data.filemark.additional_data,
+ };
+ if (cur_entry.type == kSDItemLocalMark) {
+ if (!mark_set_local(cur_entry.data.filemark.name, buf, fm, !force)) {
shada_free_shada_entry(&cur_entry);
break;
}
- const fmark_T fm = (fmark_T) {
- .mark = cur_entry.data.filemark.mark,
- .fnum = 0,
- .timestamp = cur_entry.timestamp,
- .additional_data = cur_entry.data.filemark.additional_data,
- };
- if (cur_entry.type == kSDItemLocalMark) {
- if (!mark_set_local(cur_entry.data.filemark.name, buf, fm, !force)) {
- shada_free_shada_entry(&cur_entry);
- break;
- }
- } else {
- int kh_ret;
- (void) kh_put(bufset, &cl_bufs, (uintptr_t) buf, &kh_ret);
+ } else {
+ int kh_ret;
+ (void)kh_put(bufset, &cl_bufs, (uintptr_t)buf, &kh_ret);
#define SDE_TO_FMARK(entry) fm
#define AFTERFREE(entry) (entry).data.filemark.fname = NULL
#define DUMMY_IDX_ADJ(i)
- MERGE_JUMPS(buf->b_changelistlen, buf->b_changelist, fmark_T,
- timestamp, mark, cur_entry, true,
- free_fmark, SDE_TO_FMARK, DUMMY_IDX_ADJ, AFTERFREE);
+ MERGE_JUMPS(buf->b_changelistlen, buf->b_changelist, fmark_T,
+ timestamp, mark, cur_entry, true,
+ free_fmark, SDE_TO_FMARK, DUMMY_IDX_ADJ, AFTERFREE);
#undef SDE_TO_FMARK
#undef AFTERFREE
#undef DUMMY_IDX_ADJ
- }
- // Do not free shada entry: except for fname, its allocated memory (i.e.
- // additional_data attribute contents if non-NULL) was saved above.
- xfree(cur_entry.data.filemark.fname);
- break;
}
+ // Do not free shada entry: except for fname, its allocated memory (i.e.
+ // additional_data attribute contents if non-NULL) was saved above.
+ xfree(cur_entry.data.filemark.fname);
+ break;
+ }
}
}
shada_read_main_cycle_end:
@@ -1490,7 +1457,7 @@ shada_read_main_cycle_end:
}
if (cl_bufs.n_occupied) {
FOR_ALL_TAB_WINDOWS(tp, wp) {
- (void) tp;
+ (void)tp;
if (in_bufset(&cl_bufs, wp->w_buffer)) {
wp->w_changelistidx = wp->w_buffer->b_changelistlen;
}
@@ -1499,7 +1466,7 @@ shada_read_main_cycle_end:
kh_dealloc(bufset, &cl_bufs);
const char *key;
kh_foreach_key(&fname_bufs, key, {
- xfree((void *) key);
+ xfree((void *)key);
})
kh_dealloc(fnamebufs, &fname_bufs);
kh_dealloc(strset, &oldfiles_set);
@@ -1544,33 +1511,33 @@ static char *shada_filename(const char *file)
// If shell is not performing them then they should be done in main.c
// where arguments are parsed, *not here*.
expand_env((char_u *)file, &(NameBuff[0]), MAXPATHL);
- file = (const char *) &(NameBuff[0]);
+ file = (const char *)&(NameBuff[0]);
}
}
return xstrdup(file);
}
#define PACK_STATIC_STR(s) \
- do { \
- msgpack_pack_str(spacker, sizeof(s) - 1); \
- msgpack_pack_str_body(spacker, s, sizeof(s) - 1); \
- } while (0)
+ do { \
+ msgpack_pack_str(spacker, sizeof(s) - 1); \
+ msgpack_pack_str_body(spacker, s, sizeof(s) - 1); \
+ } while (0)
#define PACK_STRING(s) \
- do { \
- const String s_ = (s); \
- msgpack_pack_str(spacker, s_.size); \
- if (s_.size) { \
- msgpack_pack_str_body(spacker, s_.data, s_.size); \
- } \
- } while (0)
+ do { \
+ const String s_ = (s); \
+ msgpack_pack_str(spacker, s_.size); \
+ if (s_.size) { \
+ msgpack_pack_str_body(spacker, s_.data, s_.size); \
+ } \
+ } while (0)
#define PACK_BIN(s) \
- do { \
- const String s_ = (s); \
- msgpack_pack_bin(spacker, s_.size); \
- if (s_.size > 0) { \
- msgpack_pack_bin_body(spacker, s_.data, s_.size); \
- } \
- } while (0)
+ do { \
+ const String s_ = (s); \
+ msgpack_pack_bin(spacker, s_.size); \
+ if (s_.size > 0) { \
+ msgpack_pack_bin_body(spacker, s_.data, s_.size); \
+ } \
+ } while (0)
/// Write single ShaDa entry
///
@@ -1580,8 +1547,7 @@ static char *shada_filename(const char *file)
/// restrictions.
///
/// @return kSDWriteSuccessfull, kSDWriteFailed or kSDWriteIgnError.
-static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer,
- ShadaEntry entry,
+static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntry entry,
const size_t max_kbyte)
FUNC_ATTR_NONNULL_ALL
{
@@ -1625,244 +1591,239 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer,
#define CHECK_DEFAULT(entry, attr) \
(sd_default_values[entry.type].data.attr == entry.data.attr)
#define ONE_IF_NOT_DEFAULT(entry, attr) \
- ((size_t) (!CHECK_DEFAULT(entry, attr)))
+ ((size_t)(!CHECK_DEFAULT(entry, attr)))
switch (entry.type) {
- case kSDItemMissing: {
- abort();
+ case kSDItemMissing:
+ abort();
+ case kSDItemUnknown:
+ if (spacker->callback(spacker->data, entry.data.unknown_item.contents,
+ (unsigned)entry.data.unknown_item.size) == -1) {
+ goto shada_pack_entry_error;
}
- case kSDItemUnknown: {
- if (spacker->callback(spacker->data, entry.data.unknown_item.contents,
- (unsigned) entry.data.unknown_item.size) == -1) {
- goto shada_pack_entry_error;
- }
- break;
+ break;
+ case kSDItemHistoryEntry: {
+ const bool is_hist_search =
+ entry.data.history_item.histtype == HIST_SEARCH;
+ const size_t arr_size = 2 + (size_t)is_hist_search + (size_t)(
+ tv_list_len(entry.data.
+ history_item.
+ additional_elements));
+ msgpack_pack_array(spacker, arr_size);
+ msgpack_pack_uint8(spacker, entry.data.history_item.histtype);
+ PACK_BIN(cstr_as_string(entry.data.history_item.string));
+ if (is_hist_search) {
+ msgpack_pack_uint8(spacker, (uint8_t)entry.data.history_item.sep);
}
- case kSDItemHistoryEntry: {
- const bool is_hist_search =
- entry.data.history_item.histtype == HIST_SEARCH;
- const size_t arr_size = 2 + (size_t)is_hist_search + (size_t)(
- tv_list_len(entry.data.history_item.additional_elements));
- msgpack_pack_array(spacker, arr_size);
- msgpack_pack_uint8(spacker, entry.data.history_item.histtype);
- PACK_BIN(cstr_as_string(entry.data.history_item.string));
- if (is_hist_search) {
- msgpack_pack_uint8(spacker, (uint8_t)entry.data.history_item.sep);
- }
- DUMP_ADDITIONAL_ELEMENTS(entry.data.history_item.additional_elements,
- "history entry item");
- break;
- }
- case kSDItemVariable: {
- if (entry.data.global_var.value.v_type == VAR_TYPE_BLOB) {
- // Strings and Blobs both pack as msgpack BINs; differentiate them by
- // storing an additional VAR_TYPE_BLOB element alongside Blobs
- list_T *const list = tv_list_alloc(1);
- tv_list_append_number(list, VAR_TYPE_BLOB);
- entry.data.global_var.additional_elements = list;
- }
- const size_t arr_size = 2 + (size_t)(
- tv_list_len(entry.data.global_var.additional_elements));
- msgpack_pack_array(spacker, arr_size);
- const String varname = cstr_as_string(entry.data.global_var.name);
- PACK_BIN(varname);
- char vardesc[256] = "variable g:";
- memcpy(&vardesc[sizeof("variable g:") - 1], varname.data,
- varname.size + 1);
- if (encode_vim_to_msgpack(spacker, &entry.data.global_var.value, vardesc)
- == FAIL) {
- ret = kSDWriteIgnError;
- EMSG2(_(WERR "Failed to write variable %s"),
- entry.data.global_var.name);
- goto shada_pack_entry_error;
- }
- DUMP_ADDITIONAL_ELEMENTS(entry.data.global_var.additional_elements,
- "variable item");
- break;
+ DUMP_ADDITIONAL_ELEMENTS(entry.data.history_item.additional_elements,
+ "history entry item");
+ break;
+ }
+ case kSDItemVariable: {
+ if (entry.data.global_var.value.v_type == VAR_TYPE_BLOB) {
+ // Strings and Blobs both pack as msgpack BINs; differentiate them by
+ // storing an additional VAR_TYPE_BLOB element alongside Blobs
+ list_T *const list = tv_list_alloc(1);
+ tv_list_append_number(list, VAR_TYPE_BLOB);
+ entry.data.global_var.additional_elements = list;
}
- case kSDItemSubString: {
- const size_t arr_size = 1 + (size_t)(
- tv_list_len(entry.data.sub_string.additional_elements));
- msgpack_pack_array(spacker, arr_size);
- PACK_BIN(cstr_as_string(entry.data.sub_string.sub));
- DUMP_ADDITIONAL_ELEMENTS(entry.data.sub_string.additional_elements,
- "sub string item");
- break;
+ const size_t arr_size = 2 + (size_t)(
+ tv_list_len(entry.data.global_var.additional_elements));
+ msgpack_pack_array(spacker, arr_size);
+ const String varname = cstr_as_string(entry.data.global_var.name);
+ PACK_BIN(varname);
+ char vardesc[256] = "variable g:";
+ memcpy(&vardesc[sizeof("variable g:") - 1], varname.data,
+ varname.size + 1);
+ if (encode_vim_to_msgpack(spacker, &entry.data.global_var.value, vardesc)
+ == FAIL) {
+ ret = kSDWriteIgnError;
+ EMSG2(_(WERR "Failed to write variable %s"),
+ entry.data.global_var.name);
+ goto shada_pack_entry_error;
}
- case kSDItemSearchPattern: {
- const size_t map_size = (size_t) (
- 1 // Search pattern is always present
- + ONE_IF_NOT_DEFAULT(entry, search_pattern.magic)
- + ONE_IF_NOT_DEFAULT(entry, search_pattern.is_last_used)
- + ONE_IF_NOT_DEFAULT(entry, search_pattern.smartcase)
- + ONE_IF_NOT_DEFAULT(entry, search_pattern.has_line_offset)
- + ONE_IF_NOT_DEFAULT(entry, search_pattern.place_cursor_at_end)
- + ONE_IF_NOT_DEFAULT(entry, search_pattern.is_substitute_pattern)
- + ONE_IF_NOT_DEFAULT(entry, search_pattern.highlighted)
- + ONE_IF_NOT_DEFAULT(entry, search_pattern.offset)
- + ONE_IF_NOT_DEFAULT(entry, search_pattern.search_backward)
- // finally, additional data:
- + (size_t) (
- entry.data.search_pattern.additional_data
+ DUMP_ADDITIONAL_ELEMENTS(entry.data.global_var.additional_elements,
+ "variable item");
+ break;
+ }
+ case kSDItemSubString: {
+ const size_t arr_size = 1 + (size_t)(
+ tv_list_len(entry.data.sub_string.additional_elements));
+ msgpack_pack_array(spacker, arr_size);
+ PACK_BIN(cstr_as_string(entry.data.sub_string.sub));
+ DUMP_ADDITIONAL_ELEMENTS(entry.data.sub_string.additional_elements,
+ "sub string item");
+ break;
+ }
+ case kSDItemSearchPattern: {
+ const size_t map_size = (size_t)(
+ 1 // Search pattern is always present
+ + ONE_IF_NOT_DEFAULT(entry, search_pattern.magic)
+ + ONE_IF_NOT_DEFAULT(entry, search_pattern.is_last_used)
+ + ONE_IF_NOT_DEFAULT(entry, search_pattern.smartcase)
+ + ONE_IF_NOT_DEFAULT(entry, search_pattern.has_line_offset)
+ + ONE_IF_NOT_DEFAULT(entry, search_pattern.place_cursor_at_end)
+ + ONE_IF_NOT_DEFAULT(entry,
+ search_pattern.is_substitute_pattern)
+ + ONE_IF_NOT_DEFAULT(entry, search_pattern.highlighted)
+ + ONE_IF_NOT_DEFAULT(entry, search_pattern.offset)
+ + ONE_IF_NOT_DEFAULT(entry, search_pattern.search_backward)
+ // finally, additional data:
+ + (size_t)(
+ entry.data.search_pattern.additional_data
? entry.data.search_pattern.additional_data->dv_hashtab.ht_used
: 0));
- msgpack_pack_map(spacker, map_size);
- PACK_STATIC_STR(SEARCH_KEY_PAT);
- PACK_BIN(cstr_as_string(entry.data.search_pattern.pat));
+ msgpack_pack_map(spacker, map_size);
+ PACK_STATIC_STR(SEARCH_KEY_PAT);
+ PACK_BIN(cstr_as_string(entry.data.search_pattern.pat));
#define PACK_BOOL(entry, name, attr) \
- do { \
- if (!CHECK_DEFAULT(entry, search_pattern.attr)) { \
- PACK_STATIC_STR(name); \
- if (sd_default_values[entry.type].data.search_pattern.attr) { \
- msgpack_pack_false(spacker); \
- } else { \
- msgpack_pack_true(spacker); \
- } \
- } \
- } while (0)
- PACK_BOOL(entry, SEARCH_KEY_MAGIC, magic);
- PACK_BOOL(entry, SEARCH_KEY_IS_LAST_USED, is_last_used);
- PACK_BOOL(entry, SEARCH_KEY_SMARTCASE, smartcase);
- PACK_BOOL(entry, SEARCH_KEY_HAS_LINE_OFFSET, has_line_offset);
- PACK_BOOL(entry, SEARCH_KEY_PLACE_CURSOR_AT_END, place_cursor_at_end);
- PACK_BOOL(entry, SEARCH_KEY_IS_SUBSTITUTE_PATTERN, is_substitute_pattern);
- PACK_BOOL(entry, SEARCH_KEY_HIGHLIGHTED, highlighted);
- PACK_BOOL(entry, SEARCH_KEY_BACKWARD, search_backward);
- if (!CHECK_DEFAULT(entry, search_pattern.offset)) {
- PACK_STATIC_STR(SEARCH_KEY_OFFSET);
- msgpack_pack_int64(spacker, entry.data.search_pattern.offset);
- }
-#undef PACK_BOOL
- DUMP_ADDITIONAL_DATA(entry.data.search_pattern.additional_data,
- "search pattern item");
- break;
+ do { \
+ if (!CHECK_DEFAULT(entry, search_pattern.attr)) { \
+ PACK_STATIC_STR(name); \
+ if (sd_default_values[entry.type].data.search_pattern.attr) { \
+ msgpack_pack_false(spacker); \
+ } else { \
+ msgpack_pack_true(spacker); \
+ } \
+ } \
+ } while (0)
+ PACK_BOOL(entry, SEARCH_KEY_MAGIC, magic);
+ PACK_BOOL(entry, SEARCH_KEY_IS_LAST_USED, is_last_used);
+ PACK_BOOL(entry, SEARCH_KEY_SMARTCASE, smartcase);
+ PACK_BOOL(entry, SEARCH_KEY_HAS_LINE_OFFSET, has_line_offset);
+ PACK_BOOL(entry, SEARCH_KEY_PLACE_CURSOR_AT_END, place_cursor_at_end);
+ PACK_BOOL(entry, SEARCH_KEY_IS_SUBSTITUTE_PATTERN, is_substitute_pattern);
+ PACK_BOOL(entry, SEARCH_KEY_HIGHLIGHTED, highlighted);
+ PACK_BOOL(entry, SEARCH_KEY_BACKWARD, search_backward);
+ if (!CHECK_DEFAULT(entry, search_pattern.offset)) {
+ PACK_STATIC_STR(SEARCH_KEY_OFFSET);
+ msgpack_pack_int64(spacker, entry.data.search_pattern.offset);
}
- case kSDItemChange:
- case kSDItemGlobalMark:
- case kSDItemLocalMark:
- case kSDItemJump: {
- const size_t map_size = (size_t) (
- 1 // File name
- + ONE_IF_NOT_DEFAULT(entry, filemark.mark.lnum)
- + ONE_IF_NOT_DEFAULT(entry, filemark.mark.col)
- + ONE_IF_NOT_DEFAULT(entry, filemark.name)
- // Additional entries, if any:
- + (size_t) (
- entry.data.filemark.additional_data == NULL
+#undef PACK_BOOL
+ DUMP_ADDITIONAL_DATA(entry.data.search_pattern.additional_data,
+ "search pattern item");
+ break;
+ }
+ case kSDItemChange:
+ case kSDItemGlobalMark:
+ case kSDItemLocalMark:
+ case kSDItemJump: {
+ const size_t map_size = (size_t)(
+ 1 // File name
+ + ONE_IF_NOT_DEFAULT(entry, filemark.mark.lnum)
+ + ONE_IF_NOT_DEFAULT(entry, filemark.mark.col)
+ + ONE_IF_NOT_DEFAULT(entry, filemark.name)
+ // Additional entries, if any:
+ + (size_t)(
+ entry.data.filemark.additional_data == NULL
? 0
: entry.data.filemark.additional_data->dv_hashtab.ht_used));
- msgpack_pack_map(spacker, map_size);
- PACK_STATIC_STR(KEY_FILE);
- PACK_BIN(cstr_as_string(entry.data.filemark.fname));
- if (!CHECK_DEFAULT(entry, filemark.mark.lnum)) {
- PACK_STATIC_STR(KEY_LNUM);
- msgpack_pack_long(spacker, entry.data.filemark.mark.lnum);
- }
- if (!CHECK_DEFAULT(entry, filemark.mark.col)) {
- PACK_STATIC_STR(KEY_COL);
- msgpack_pack_long(spacker, entry.data.filemark.mark.col);
- }
- assert(entry.type == kSDItemJump || entry.type == kSDItemChange
+ msgpack_pack_map(spacker, map_size);
+ PACK_STATIC_STR(KEY_FILE);
+ PACK_BIN(cstr_as_string(entry.data.filemark.fname));
+ if (!CHECK_DEFAULT(entry, filemark.mark.lnum)) {
+ PACK_STATIC_STR(KEY_LNUM);
+ msgpack_pack_long(spacker, entry.data.filemark.mark.lnum);
+ }
+ if (!CHECK_DEFAULT(entry, filemark.mark.col)) {
+ PACK_STATIC_STR(KEY_COL);
+ msgpack_pack_long(spacker, entry.data.filemark.mark.col);
+ }
+ assert(entry.type == kSDItemJump || entry.type == kSDItemChange
? CHECK_DEFAULT(entry, filemark.name)
: true);
- if (!CHECK_DEFAULT(entry, filemark.name)) {
- PACK_STATIC_STR(KEY_NAME_CHAR);
- msgpack_pack_uint8(spacker, (uint8_t) entry.data.filemark.name);
- }
- DUMP_ADDITIONAL_DATA(entry.data.filemark.additional_data,
- "mark (change, jump, global or local) item");
- break;
+ if (!CHECK_DEFAULT(entry, filemark.name)) {
+ PACK_STATIC_STR(KEY_NAME_CHAR);
+ msgpack_pack_uint8(spacker, (uint8_t)entry.data.filemark.name);
}
- case kSDItemRegister: {
- const size_t map_size = (size_t) (
- 2 // Register contents and name
- + ONE_IF_NOT_DEFAULT(entry, reg.type)
- + ONE_IF_NOT_DEFAULT(entry, reg.width)
- + ONE_IF_NOT_DEFAULT(entry, reg.is_unnamed)
- // Additional entries, if any:
- + (size_t) (entry.data.reg.additional_data == NULL
+ DUMP_ADDITIONAL_DATA(entry.data.filemark.additional_data,
+ "mark (change, jump, global or local) item");
+ break;
+ }
+ case kSDItemRegister: {
+ const size_t map_size = (size_t)(
+ 2 // Register contents and name
+ + ONE_IF_NOT_DEFAULT(entry, reg.type)
+ + ONE_IF_NOT_DEFAULT(entry, reg.width)
+ + ONE_IF_NOT_DEFAULT(entry, reg.is_unnamed)
+ // Additional entries, if any:
+ + (size_t)(entry.data.reg.additional_data == NULL
? 0
: entry.data.reg.additional_data->dv_hashtab.ht_used));
- msgpack_pack_map(spacker, map_size);
- PACK_STATIC_STR(REG_KEY_CONTENTS);
- msgpack_pack_array(spacker, entry.data.reg.contents_size);
- for (size_t i = 0; i < entry.data.reg.contents_size; i++) {
- PACK_BIN(cstr_as_string(entry.data.reg.contents[i]));
- }
- PACK_STATIC_STR(KEY_NAME_CHAR);
- msgpack_pack_char(spacker, entry.data.reg.name);
- if (!CHECK_DEFAULT(entry, reg.type)) {
- PACK_STATIC_STR(REG_KEY_TYPE);
- msgpack_pack_uint8(spacker, (uint8_t)entry.data.reg.type);
- }
- if (!CHECK_DEFAULT(entry, reg.width)) {
- PACK_STATIC_STR(REG_KEY_WIDTH);
- msgpack_pack_uint64(spacker, (uint64_t) entry.data.reg.width);
- }
- if (!CHECK_DEFAULT(entry, reg.is_unnamed)) {
- PACK_STATIC_STR(REG_KEY_UNNAMED);
- if (entry.data.reg.is_unnamed) {
- msgpack_pack_true(spacker);
- } else {
- msgpack_pack_false(spacker);
- }
+ msgpack_pack_map(spacker, map_size);
+ PACK_STATIC_STR(REG_KEY_CONTENTS);
+ msgpack_pack_array(spacker, entry.data.reg.contents_size);
+ for (size_t i = 0; i < entry.data.reg.contents_size; i++) {
+ PACK_BIN(cstr_as_string(entry.data.reg.contents[i]));
+ }
+ PACK_STATIC_STR(KEY_NAME_CHAR);
+ msgpack_pack_char(spacker, entry.data.reg.name);
+ if (!CHECK_DEFAULT(entry, reg.type)) {
+ PACK_STATIC_STR(REG_KEY_TYPE);
+ msgpack_pack_uint8(spacker, (uint8_t)entry.data.reg.type);
+ }
+ if (!CHECK_DEFAULT(entry, reg.width)) {
+ PACK_STATIC_STR(REG_KEY_WIDTH);
+ msgpack_pack_uint64(spacker, (uint64_t)entry.data.reg.width);
+ }
+ if (!CHECK_DEFAULT(entry, reg.is_unnamed)) {
+ PACK_STATIC_STR(REG_KEY_UNNAMED);
+ if (entry.data.reg.is_unnamed) {
+ msgpack_pack_true(spacker);
+ } else {
+ msgpack_pack_false(spacker);
}
- DUMP_ADDITIONAL_DATA(entry.data.reg.additional_data, "register item");
- break;
}
- case kSDItemBufferList: {
- msgpack_pack_array(spacker, entry.data.buffer_list.size);
- for (size_t i = 0; i < entry.data.buffer_list.size; i++) {
- const size_t map_size = (size_t) (
- 1 // Buffer name
- + (size_t) (entry.data.buffer_list.buffers[i].pos.lnum
- != default_pos.lnum)
- + (size_t) (entry.data.buffer_list.buffers[i].pos.col
- != default_pos.col)
- // Additional entries, if any:
- + (size_t) (
- entry.data.buffer_list.buffers[i].additional_data == NULL
+ DUMP_ADDITIONAL_DATA(entry.data.reg.additional_data, "register item");
+ break;
+ }
+ case kSDItemBufferList:
+ msgpack_pack_array(spacker, entry.data.buffer_list.size);
+ for (size_t i = 0; i < entry.data.buffer_list.size; i++) {
+ const size_t map_size = (size_t)(
+ 1 // Buffer name
+ + (size_t)(entry.data.buffer_list.buffers[i].pos.lnum
+ != default_pos.lnum)
+ + (size_t)(entry.data.buffer_list.buffers[i].pos.col
+ != default_pos.col)
+ // Additional entries, if any:
+ + (size_t)(
+ entry.data.buffer_list.buffers[i].additional_data
+ == NULL
? 0
: (entry.data.buffer_list.buffers[i].additional_data
->dv_hashtab.ht_used)));
- msgpack_pack_map(spacker, map_size);
- PACK_STATIC_STR(KEY_FILE);
- PACK_BIN(cstr_as_string(entry.data.buffer_list.buffers[i].fname));
- if (entry.data.buffer_list.buffers[i].pos.lnum != 1) {
- PACK_STATIC_STR(KEY_LNUM);
- msgpack_pack_uint64(
- spacker, (uint64_t) entry.data.buffer_list.buffers[i].pos.lnum);
- }
- if (entry.data.buffer_list.buffers[i].pos.col != 0) {
- PACK_STATIC_STR(KEY_COL);
- msgpack_pack_uint64(
- spacker, (uint64_t) entry.data.buffer_list.buffers[i].pos.col);
- }
- DUMP_ADDITIONAL_DATA(entry.data.buffer_list.buffers[i].additional_data,
- "buffer list subitem");
+ msgpack_pack_map(spacker, map_size);
+ PACK_STATIC_STR(KEY_FILE);
+ PACK_BIN(cstr_as_string(entry.data.buffer_list.buffers[i].fname));
+ if (entry.data.buffer_list.buffers[i].pos.lnum != 1) {
+ PACK_STATIC_STR(KEY_LNUM);
+ msgpack_pack_uint64(spacker, (uint64_t)entry.data.buffer_list.buffers[i].pos.lnum);
}
- break;
+ if (entry.data.buffer_list.buffers[i].pos.col != 0) {
+ PACK_STATIC_STR(KEY_COL);
+ msgpack_pack_uint64(spacker, (uint64_t)entry.data.buffer_list.buffers[i].pos.col);
+ }
+ DUMP_ADDITIONAL_DATA(entry.data.buffer_list.buffers[i].additional_data,
+ "buffer list subitem");
}
- case kSDItemHeader: {
- msgpack_pack_map(spacker, entry.data.header.size);
- for (size_t i = 0; i < entry.data.header.size; i++) {
- PACK_STRING(entry.data.header.items[i].key);
- const Object obj = entry.data.header.items[i].value;
- switch (obj.type) {
- case kObjectTypeString: {
- PACK_BIN(obj.data.string);
- break;
- }
- case kObjectTypeInteger: {
- msgpack_pack_int64(spacker, (int64_t) obj.data.integer);
- break;
- }
- default: {
- abort();
- }
- }
+ break;
+ case kSDItemHeader:
+ msgpack_pack_map(spacker, entry.data.header.size);
+ for (size_t i = 0; i < entry.data.header.size; i++) {
+ PACK_STRING(entry.data.header.items[i].key);
+ const Object obj = entry.data.header.items[i].value;
+ switch (obj.type) {
+ case kObjectTypeString:
+ PACK_BIN(obj.data.string);
+ break;
+ case kObjectTypeInteger:
+ msgpack_pack_int64(spacker, (int64_t)obj.data.integer);
+ break;
+ default:
+ abort();
}
- break;
}
+ break;
}
#undef CHECK_DEFAULT
#undef ONE_IF_NOT_DEFAULT
@@ -1872,17 +1833,17 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer,
goto shada_pack_entry_error;
}
} else {
- if (msgpack_pack_uint64(packer, (uint64_t) entry.type) == -1) {
+ if (msgpack_pack_uint64(packer, (uint64_t)entry.type) == -1) {
goto shada_pack_entry_error;
}
}
- if (msgpack_pack_uint64(packer, (uint64_t) entry.timestamp) == -1) {
+ if (msgpack_pack_uint64(packer, (uint64_t)entry.timestamp) == -1) {
goto shada_pack_entry_error;
}
if (sbuf.size > 0) {
- if ((msgpack_pack_uint64(packer, (uint64_t) sbuf.size) == -1)
+ if ((msgpack_pack_uint64(packer, (uint64_t)sbuf.size) == -1)
|| (packer->callback(packer->data, sbuf.data,
- (unsigned) sbuf.size) == -1)) {
+ (unsigned)sbuf.size) == -1)) {
goto shada_pack_entry_error;
}
}
@@ -1905,9 +1866,9 @@ shada_pack_entry_error:
/// @param[in] entry Entry written.
/// @param[in] max_kbyte Maximum size of an item in KiB. Zero means no
/// restrictions.
-static inline ShaDaWriteResult shada_pack_pfreed_entry(
- msgpack_packer *const packer, PossiblyFreedShadaEntry entry,
- const size_t max_kbyte)
+static inline ShaDaWriteResult shada_pack_pfreed_entry(msgpack_packer *const packer,
+ PossiblyFreedShadaEntry entry,
+ const size_t max_kbyte)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_ALWAYS_INLINE
{
ShaDaWriteResult ret = kSDWriteSuccessfull;
@@ -1945,9 +1906,10 @@ static int compare_file_marks(const void *a, const void *b)
///
/// @return kSDReadStatusNotShaDa, kSDReadStatusReadError or
/// kSDReadStatusSuccess.
-static inline ShaDaReadResult shada_parse_msgpack(
- ShaDaReadDef *const sd_reader, const size_t length,
- msgpack_unpacked *ret_unpacked, char **const ret_buf)
+static inline ShaDaReadResult shada_parse_msgpack(ShaDaReadDef *const sd_reader,
+ const size_t length,
+ msgpack_unpacked *ret_unpacked,
+ char **const ret_buf)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
{
const uintmax_t initial_fpos = sd_reader->fpos;
@@ -1964,47 +1926,42 @@ shada_parse_msgpack_read_next: {}
msgpack_unpacked unpacked;
msgpack_unpacked_init(&unpacked);
const msgpack_unpack_return result =
- msgpack_unpack_next(&unpacked, buf, length, &off);
+ msgpack_unpack_next(&unpacked, buf, length, &off);
ShaDaReadResult ret = kSDReadStatusSuccess;
switch (result) {
- case MSGPACK_UNPACK_SUCCESS: {
- if (off < length) {
- goto shada_parse_msgpack_extra_bytes;
- }
- break;
+ case MSGPACK_UNPACK_SUCCESS:
+ if (off < length) {
+ goto shada_parse_msgpack_extra_bytes;
}
- case MSGPACK_UNPACK_PARSE_ERROR: {
- emsgf(_(RCERR "Failed to parse ShaDa file due to a msgpack parser error "
- "at position %" PRIu64),
- (uint64_t) initial_fpos);
- ret = kSDReadStatusNotShaDa;
- break;
+ break;
+ case MSGPACK_UNPACK_PARSE_ERROR:
+ emsgf(_(RCERR "Failed to parse ShaDa file due to a msgpack parser error "
+ "at position %" PRIu64),
+ (uint64_t)initial_fpos);
+ ret = kSDReadStatusNotShaDa;
+ break;
+ case MSGPACK_UNPACK_NOMEM_ERROR:
+ if (!did_try_to_free) {
+ did_try_to_free = true;
+ try_to_free_memory();
+ goto shada_parse_msgpack_read_next;
}
- case MSGPACK_UNPACK_NOMEM_ERROR: {
- if (!did_try_to_free) {
- did_try_to_free = true;
- try_to_free_memory();
- goto shada_parse_msgpack_read_next;
- }
- EMSG(_(e_outofmem));
- ret = kSDReadStatusReadError;
- break;
- }
- case MSGPACK_UNPACK_CONTINUE: {
- emsgf(_(RCERR "Failed to parse ShaDa file: incomplete msgpack string "
- "at position %" PRIu64),
- (uint64_t) initial_fpos);
- ret = kSDReadStatusNotShaDa;
- break;
- }
- case MSGPACK_UNPACK_EXTRA_BYTES: {
+ EMSG(_(e_outofmem));
+ ret = kSDReadStatusReadError;
+ break;
+ case MSGPACK_UNPACK_CONTINUE:
+ emsgf(_(RCERR "Failed to parse ShaDa file: incomplete msgpack string "
+ "at position %" PRIu64),
+ (uint64_t)initial_fpos);
+ ret = kSDReadStatusNotShaDa;
+ break;
+ case MSGPACK_UNPACK_EXTRA_BYTES:
shada_parse_msgpack_extra_bytes:
- emsgf(_(RCERR "Failed to parse ShaDa file: extra bytes in msgpack string "
- "at position %" PRIu64),
- (uint64_t) initial_fpos);
- ret = kSDReadStatusNotShaDa;
- break;
- }
+ emsgf(_(RCERR "Failed to parse ShaDa file: extra bytes in msgpack string "
+ "at position %" PRIu64),
+ (uint64_t)initial_fpos);
+ ret = kSDReadStatusNotShaDa;
+ break;
}
if (ret_buf != NULL && ret == kSDReadStatusSuccess) {
if (ret_unpacked == NULL) {
@@ -2034,81 +1991,67 @@ static const char *shada_format_entry(const ShadaEntry entry)
vim_snprintf(S_LEN(ret), "%s", "[ ] ts=%" PRIu64 " ");
// ^ Space for `can_free_entry`
switch (entry.type) {
- case kSDItemMissing: {
- vim_snprintf_add(S_LEN(ret), "Missing");
- break;
- }
- case kSDItemHeader: {
- vim_snprintf_add(S_LEN(ret), "Header { TODO }");
- break;
- }
- case kSDItemBufferList: {
- vim_snprintf_add(S_LEN(ret), "BufferList { TODO }");
- break;
- }
- case kSDItemUnknown: {
- vim_snprintf_add(S_LEN(ret), "Unknown { TODO }");
- break;
- }
- case kSDItemSearchPattern: {
- vim_snprintf_add(S_LEN(ret), "SearchPattern { TODO }");
- break;
- }
- case kSDItemSubString: {
- vim_snprintf_add(S_LEN(ret), "SubString { TODO }");
- break;
- }
- case kSDItemHistoryEntry: {
- vim_snprintf_add(S_LEN(ret), "HistoryEntry { TODO }");
- break;
- }
- case kSDItemRegister: {
- vim_snprintf_add(S_LEN(ret), "Register { TODO }");
- break;
- }
- case kSDItemVariable: {
- vim_snprintf_add(S_LEN(ret), "Variable { TODO }");
- break;
- }
+ case kSDItemMissing:
+ vim_snprintf_add(S_LEN(ret), "Missing");
+ break;
+ case kSDItemHeader:
+ vim_snprintf_add(S_LEN(ret), "Header { TODO }");
+ break;
+ case kSDItemBufferList:
+ vim_snprintf_add(S_LEN(ret), "BufferList { TODO }");
+ break;
+ case kSDItemUnknown:
+ vim_snprintf_add(S_LEN(ret), "Unknown { TODO }");
+ break;
+ case kSDItemSearchPattern:
+ vim_snprintf_add(S_LEN(ret), "SearchPattern { TODO }");
+ break;
+ case kSDItemSubString:
+ vim_snprintf_add(S_LEN(ret), "SubString { TODO }");
+ break;
+ case kSDItemHistoryEntry:
+ vim_snprintf_add(S_LEN(ret), "HistoryEntry { TODO }");
+ break;
+ case kSDItemRegister:
+ vim_snprintf_add(S_LEN(ret), "Register { TODO }");
+ break;
+ case kSDItemVariable:
+ vim_snprintf_add(S_LEN(ret), "Variable { TODO }");
+ break;
#define FORMAT_MARK_ENTRY(entry_name, name_fmt, name_fmt_arg) \
- do { \
- typval_T ad_tv = { \
- .v_type = VAR_DICT, \
- .vval.v_dict = entry.data.filemark.additional_data \
- }; \
- size_t ad_len; \
- char *const ad = encode_tv2string(&ad_tv, &ad_len); \
- vim_snprintf_add( \
- S_LEN(ret), \
- entry_name " {" name_fmt " file=[%zu]\"%.512s\", " \
- "pos={l=%" PRIdLINENR ",c=%" PRIdCOLNR ",a=%" PRIdCOLNR "}, " \
- "ad={%p:[%zu]%.64s} }", \
- name_fmt_arg, \
- strlen(entry.data.filemark.fname), \
- entry.data.filemark.fname, \
- entry.data.filemark.mark.lnum, \
- entry.data.filemark.mark.col, \
- entry.data.filemark.mark.coladd, \
- (void *)entry.data.filemark.additional_data, \
- ad_len, \
- ad); \
- } while (0)
- case kSDItemGlobalMark: {
- FORMAT_MARK_ENTRY("GlobalMark", " name='%c',", entry.data.filemark.name);
- break;
- }
- case kSDItemChange: {
- FORMAT_MARK_ENTRY("Change", "%s", "");
- break;
- }
- case kSDItemLocalMark: {
- FORMAT_MARK_ENTRY("LocalMark", " name='%c',", entry.data.filemark.name);
- break;
- }
- case kSDItemJump: {
- FORMAT_MARK_ENTRY("Jump", "%s", "");
- break;
- }
+ do { \
+ typval_T ad_tv = { \
+ .v_type = VAR_DICT, \
+ .vval.v_dict = entry.data.filemark.additional_data \
+ }; \
+ size_t ad_len; \
+ char *const ad = encode_tv2string(&ad_tv, &ad_len); \
+ vim_snprintf_add(S_LEN(ret), \
+ entry_name " {" name_fmt " file=[%zu]\"%.512s\", " \
+ "pos={l=%" PRIdLINENR ",c=%" PRIdCOLNR ",a=%" PRIdCOLNR "}, " \
+ "ad={%p:[%zu]%.64s} }", \
+ name_fmt_arg, \
+ strlen(entry.data.filemark.fname), \
+ entry.data.filemark.fname, \
+ entry.data.filemark.mark.lnum, \
+ entry.data.filemark.mark.col, \
+ entry.data.filemark.mark.coladd, \
+ (void *)entry.data.filemark.additional_data, \
+ ad_len, \
+ ad); \
+ } while (0)
+ case kSDItemGlobalMark:
+ FORMAT_MARK_ENTRY("GlobalMark", " name='%c',", entry.data.filemark.name);
+ break;
+ case kSDItemChange:
+ FORMAT_MARK_ENTRY("Change", "%s", "");
+ break;
+ case kSDItemLocalMark:
+ FORMAT_MARK_ENTRY("LocalMark", " name='%c',", entry.data.filemark.name);
+ break;
+ case kSDItemJump:
+ FORMAT_MARK_ENTRY("Jump", "%s", "");
+ break;
#undef FORMAT_MARK_ENTRY
}
return ret;
@@ -2119,8 +2062,7 @@ static const char *shada_format_entry(const ShadaEntry entry)
/// @param[in] entry ShaDa entry to format.
///
/// @return string representing ShaDa entry in a static buffer.
-static const char *shada_format_pfreed_entry(
- const PossiblyFreedShadaEntry pfs_entry)
+static const char *shada_format_pfreed_entry(const PossiblyFreedShadaEntry pfs_entry)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_UNUSED FUNC_ATTR_NONNULL_RET
{
char *ret = (char *)shada_format_entry(pfs_entry.data);
@@ -2136,10 +2078,11 @@ static const char *shada_format_pfreed_entry(
/// @param[in,out] ret_wms Location where results are saved.
/// @param[out] packer MessagePack packer for entries which are not
/// merged.
-static inline ShaDaWriteResult shada_read_when_writing(
- ShaDaReadDef *const sd_reader, const unsigned srni_flags,
- const size_t max_kbyte, WriteMergerState *const wms,
- msgpack_packer *const packer)
+static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_reader,
+ const unsigned srni_flags,
+ const size_t max_kbyte,
+ WriteMergerState *const wms,
+ msgpack_packer *const packer)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
ShaDaWriteResult ret = kSDWriteSuccessfull;
@@ -2149,217 +2092,202 @@ static inline ShaDaWriteResult shada_read_when_writing(
max_kbyte))
!= kSDReadStatusFinished) {
switch (srni_ret) {
- case kSDReadStatusSuccess: {
- break;
- }
- case kSDReadStatusFinished: {
- // Should be handled by the while condition.
- abort();
- }
- case kSDReadStatusNotShaDa: {
- ret = kSDWriteReadNotShada;
- FALLTHROUGH;
- }
- case kSDReadStatusReadError: {
- return ret;
- }
- case kSDReadStatusMalformed: {
- continue;
- }
+ case kSDReadStatusSuccess:
+ break;
+ case kSDReadStatusFinished:
+ // Should be handled by the while condition.
+ abort();
+ case kSDReadStatusNotShaDa:
+ ret = kSDWriteReadNotShada;
+ FALLTHROUGH;
+ case kSDReadStatusReadError:
+ return ret;
+ case kSDReadStatusMalformed:
+ continue;
}
#define COMPARE_WITH_ENTRY(wms_entry_, entry) \
- do { \
- PossiblyFreedShadaEntry *const wms_entry = (wms_entry_); \
- if (wms_entry->data.type != kSDItemMissing) { \
- if (wms_entry->data.timestamp >= (entry).timestamp) { \
- shada_free_shada_entry(&(entry)); \
- break; \
- } \
- if (wms_entry->can_free_entry) { \
- shada_free_shada_entry(&wms_entry->data); \
- } \
+ do { \
+ PossiblyFreedShadaEntry *const wms_entry = (wms_entry_); \
+ if (wms_entry->data.type != kSDItemMissing) { \
+ if (wms_entry->data.timestamp >= (entry).timestamp) { \
+ shada_free_shada_entry(&(entry)); \
+ break; \
+ } \
+ if (wms_entry->can_free_entry) { \
+ shada_free_shada_entry(&wms_entry->data); \
} \
- *wms_entry = pfs_entry; \
- } while (0)
+ } \
+ *wms_entry = pfs_entry; \
+ } while (0)
const PossiblyFreedShadaEntry pfs_entry = {
.can_free_entry = true,
.data = entry,
};
switch (entry.type) {
- case kSDItemMissing: {
+ case kSDItemMissing:
+ break;
+ case kSDItemHeader:
+ case kSDItemBufferList:
+ abort();
+ case kSDItemUnknown:
+ ret = shada_pack_entry(packer, entry, 0);
+ shada_free_shada_entry(&entry);
+ break;
+ case kSDItemSearchPattern:
+ COMPARE_WITH_ENTRY((entry.data.search_pattern.is_substitute_pattern
+ ? &wms->sub_search_pattern
+ : &wms->search_pattern), entry);
+ break;
+ case kSDItemSubString:
+ COMPARE_WITH_ENTRY(&wms->replacement, entry);
+ break;
+ case kSDItemHistoryEntry:
+ if (entry.data.history_item.histtype >= HIST_COUNT) {
+ ret = shada_pack_entry(packer, entry, 0);
+ shada_free_shada_entry(&entry);
break;
}
- case kSDItemHeader:
- case kSDItemBufferList: {
- abort();
+ if (wms->hms[entry.data.history_item.histtype].hmll.size != 0) {
+ hms_insert(&wms->hms[entry.data.history_item.histtype], entry, true,
+ true);
+ } else {
+ shada_free_shada_entry(&entry);
}
- case kSDItemUnknown: {
+ break;
+ case kSDItemRegister: {
+ const int idx = op_reg_index(entry.data.reg.name);
+ if (idx < 0) {
ret = shada_pack_entry(packer, entry, 0);
shada_free_shada_entry(&entry);
break;
}
- case kSDItemSearchPattern: {
- COMPARE_WITH_ENTRY((entry.data.search_pattern.is_substitute_pattern
- ? &wms->sub_search_pattern
- : &wms->search_pattern), entry);
- break;
- }
- case kSDItemSubString: {
- COMPARE_WITH_ENTRY(&wms->replacement, entry);
- break;
+ COMPARE_WITH_ENTRY(&wms->registers[idx], entry);
+ break;
+ }
+ case kSDItemVariable:
+ if (!in_strset(&wms->dumped_variables, entry.data.global_var.name)) {
+ ret = shada_pack_entry(packer, entry, 0);
}
- case kSDItemHistoryEntry: {
- if (entry.data.history_item.histtype >= HIST_COUNT) {
- ret = shada_pack_entry(packer, entry, 0);
- shada_free_shada_entry(&entry);
- break;
+ shada_free_shada_entry(&entry);
+ break;
+ case kSDItemGlobalMark:
+ if (ascii_isdigit(entry.data.filemark.name)) {
+ bool processed_mark = false;
+ // Completely ignore numbered mark names, make a list sorted by
+ // timestamp.
+ for (size_t i = ARRAY_SIZE(wms->numbered_marks); i > 0; i--) {
+ ShadaEntry wms_entry = wms->numbered_marks[i - 1].data;
+ if (wms_entry.type != kSDItemGlobalMark) {
+ continue;
+ }
+ // Ignore duplicates.
+ if (wms_entry.timestamp == entry.timestamp
+ && (wms_entry.data.filemark.additional_data == NULL
+ && entry.data.filemark.additional_data == NULL)
+ && marks_equal(wms_entry.data.filemark.mark,
+ entry.data.filemark.mark)
+ && strcmp(wms_entry.data.filemark.fname,
+ entry.data.filemark.fname) == 0) {
+ shada_free_shada_entry(&entry);
+ processed_mark = true;
+ break;
+ }
+ if (wms_entry.timestamp >= entry.timestamp) {
+ processed_mark = true;
+ if (i < ARRAY_SIZE(wms->numbered_marks)) {
+ replace_numbered_mark(wms, i, pfs_entry);
+ } else {
+ shada_free_shada_entry(&entry);
+ }
+ break;
+ }
}
- if (wms->hms[entry.data.history_item.histtype].hmll.size != 0) {
- hms_insert(&wms->hms[entry.data.history_item.histtype], entry, true,
- true);
- } else {
- shada_free_shada_entry(&entry);
+ if (!processed_mark) {
+ replace_numbered_mark(wms, 0, pfs_entry);
}
- break;
- }
- case kSDItemRegister: {
- const int idx = op_reg_index(entry.data.reg.name);
+ } else {
+ const int idx = mark_global_index(entry.data.filemark.name);
if (idx < 0) {
ret = shada_pack_entry(packer, entry, 0);
shada_free_shada_entry(&entry);
break;
}
- COMPARE_WITH_ENTRY(&wms->registers[idx], entry);
- break;
+ COMPARE_WITH_ENTRY(&wms->global_marks[idx], entry);
}
- case kSDItemVariable: {
- if (!in_strset(&wms->dumped_variables, entry.data.global_var.name)) {
- ret = shada_pack_entry(packer, entry, 0);
- }
+ break;
+ case kSDItemChange:
+ case kSDItemLocalMark: {
+ if (shada_removable(entry.data.filemark.fname)) {
shada_free_shada_entry(&entry);
break;
}
- case kSDItemGlobalMark: {
- if (ascii_isdigit(entry.data.filemark.name)) {
- bool processed_mark = false;
- // Completely ignore numbered mark names, make a list sorted by
- // timestamp.
- for (size_t i = ARRAY_SIZE(wms->numbered_marks); i > 0; i--) {
- ShadaEntry wms_entry = wms->numbered_marks[i - 1].data;
- if (wms_entry.type != kSDItemGlobalMark) {
- continue;
- }
- // Ignore duplicates.
- if (wms_entry.timestamp == entry.timestamp
- && (wms_entry.data.filemark.additional_data == NULL
- && entry.data.filemark.additional_data == NULL)
- && marks_equal(wms_entry.data.filemark.mark,
- entry.data.filemark.mark)
- && strcmp(wms_entry.data.filemark.fname,
- entry.data.filemark.fname) == 0) {
+ const char *const fname = (const char *)entry.data.filemark.fname;
+ khiter_t k;
+ int kh_ret;
+ k = kh_put(file_marks, &wms->file_marks, fname, &kh_ret);
+ FileMarks *const filemarks = &kh_val(&wms->file_marks, k);
+ if (kh_ret > 0) {
+ memset(filemarks, 0, sizeof(*filemarks));
+ }
+ if (entry.timestamp > filemarks->greatest_timestamp) {
+ filemarks->greatest_timestamp = entry.timestamp;
+ }
+ if (entry.type == kSDItemLocalMark) {
+ const int idx = mark_local_index(entry.data.filemark.name);
+ if (idx < 0) {
+ filemarks->additional_marks = xrealloc(filemarks->additional_marks,
+ (++filemarks->additional_marks_size
+ * sizeof(filemarks->additional_marks[0])));
+ filemarks->additional_marks[filemarks->additional_marks_size - 1] =
+ entry;
+ } else {
+ PossiblyFreedShadaEntry *const wms_entry = &filemarks->marks[idx];
+ if (wms_entry->data.type != kSDItemMissing) {
+ if (wms_entry->data.timestamp >= entry.timestamp) {
shada_free_shada_entry(&entry);
- processed_mark = true;
break;
}
- if (wms_entry.timestamp >= entry.timestamp) {
- processed_mark = true;
- if (i < ARRAY_SIZE(wms->numbered_marks)) {
- replace_numbered_mark(wms, i, pfs_entry);
- } else {
- shada_free_shada_entry(&entry);
+ if (wms_entry->can_free_entry) {
+ if (kh_key(&wms->file_marks, k)
+ == wms_entry->data.data.filemark.fname) {
+ kh_key(&wms->file_marks, k) = entry.data.filemark.fname;
}
- break;
+ shada_free_shada_entry(&wms_entry->data);
}
}
- if (!processed_mark) {
- replace_numbered_mark(wms, 0, pfs_entry);
- }
- } else {
- const int idx = mark_global_index(entry.data.filemark.name);
- if (idx < 0) {
- ret = shada_pack_entry(packer, entry, 0);
- shada_free_shada_entry(&entry);
- break;
- }
- COMPARE_WITH_ENTRY(&wms->global_marks[idx], entry);
- }
- break;
- }
- case kSDItemChange:
- case kSDItemLocalMark: {
- if (shada_removable(entry.data.filemark.fname)) {
- shada_free_shada_entry(&entry);
- break;
- }
- const char *const fname = (const char *) entry.data.filemark.fname;
- khiter_t k;
- int kh_ret;
- k = kh_put(file_marks, &wms->file_marks, fname, &kh_ret);
- FileMarks *const filemarks = &kh_val(&wms->file_marks, k);
- if (kh_ret > 0) {
- memset(filemarks, 0, sizeof(*filemarks));
- }
- if (entry.timestamp > filemarks->greatest_timestamp) {
- filemarks->greatest_timestamp = entry.timestamp;
+ *wms_entry = pfs_entry;
}
- if (entry.type == kSDItemLocalMark) {
- const int idx = mark_local_index(entry.data.filemark.name);
- if (idx < 0) {
- filemarks->additional_marks = xrealloc(
- filemarks->additional_marks,
- (++filemarks->additional_marks_size
- * sizeof(filemarks->additional_marks[0])));
- filemarks->additional_marks[filemarks->additional_marks_size - 1] =
- entry;
- } else {
- PossiblyFreedShadaEntry *const wms_entry = &filemarks->marks[idx];
- if (wms_entry->data.type != kSDItemMissing) {
- if (wms_entry->data.timestamp >= entry.timestamp) {
- shada_free_shada_entry(&entry);
- break;
- }
- if (wms_entry->can_free_entry) {
- if (kh_key(&wms->file_marks, k)
- == wms_entry->data.data.filemark.fname) {
- kh_key(&wms->file_marks, k) = entry.data.filemark.fname;
- }
- shada_free_shada_entry(&wms_entry->data);
- }
- }
- *wms_entry = pfs_entry;
- }
- } else {
+ } else {
#define FREE_POSSIBLY_FREED_SHADA_ENTRY(entry) \
- do { \
- if (entry.can_free_entry) { \
- shada_free_shada_entry(&entry.data); \
- } \
- } while (0)
+ do { \
+ if (entry.can_free_entry) { \
+ shada_free_shada_entry(&entry.data); \
+ } \
+ } while (0)
#define SDE_TO_PFSDE(entry) \
- ((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = entry })
+ ((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = entry })
#define AFTERFREE_DUMMY(entry)
#define DUMMY_IDX_ADJ(i)
- MERGE_JUMPS(filemarks->changes_size, filemarks->changes,
- PossiblyFreedShadaEntry, data.timestamp,
- data.data.filemark.mark, entry, true,
- FREE_POSSIBLY_FREED_SHADA_ENTRY, SDE_TO_PFSDE,
- DUMMY_IDX_ADJ, AFTERFREE_DUMMY);
- }
- break;
- }
- case kSDItemJump: {
- MERGE_JUMPS(wms->jumps_size, wms->jumps, PossiblyFreedShadaEntry,
- data.timestamp, data.data.filemark.mark, entry,
- strcmp(jl_entry.data.data.filemark.fname,
- entry.data.filemark.fname) == 0,
+ MERGE_JUMPS(filemarks->changes_size, filemarks->changes,
+ PossiblyFreedShadaEntry, data.timestamp,
+ data.data.filemark.mark, entry, true,
FREE_POSSIBLY_FREED_SHADA_ENTRY, SDE_TO_PFSDE,
DUMMY_IDX_ADJ, AFTERFREE_DUMMY);
+ }
+ break;
+ }
+ case kSDItemJump:
+ MERGE_JUMPS(wms->jumps_size, wms->jumps, PossiblyFreedShadaEntry,
+ data.timestamp, data.data.filemark.mark, entry,
+ strcmp(jl_entry.data.data.filemark.fname,
+ entry.data.filemark.fname) == 0,
+ FREE_POSSIBLY_FREED_SHADA_ENTRY, SDE_TO_PFSDE,
+ DUMMY_IDX_ADJ, AFTERFREE_DUMMY);
#undef FREE_POSSIBLY_FREED_SHADA_ENTRY
#undef SDE_TO_PFSDE
#undef DUMMY_IDX_ADJ
#undef AFTERFREE_DUMMY
- break;
- }
+ break;
}
}
#undef COMPARE_WITH_ENTRY
@@ -2372,8 +2300,7 @@ static inline ShaDaWriteResult shada_read_when_writing(
/// @param[in] removable_bufs Cache of buffers ignored due to their location.
///
/// @return true or false.
-static inline bool ignore_buf(const buf_T *const buf,
- khash_t(bufset) *const removable_bufs)
+static inline bool ignore_buf(const buf_T *const buf, khash_t(bufset) *const removable_bufs)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
{
return (buf->b_ffname == NULL || !buf->b_p_bl || bt_quickfix(buf) \
@@ -2385,8 +2312,7 @@ static inline bool ignore_buf(const buf_T *const buf,
/// @param[in] removable_bufs Buffers which are ignored
///
/// @return ShadaEntry List of buffers to save, kSDItemBufferList entry.
-static inline ShadaEntry shada_get_buflist(
- khash_t(bufset) *const removable_bufs)
+static inline ShadaEntry shada_get_buflist(khash_t(bufset) *const removable_bufs)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
{
int max_bufs = get_shada_parameter('%');
@@ -2400,14 +2326,14 @@ static inline ShadaEntry shada_get_buflist(
ShadaEntry buflist_entry = (ShadaEntry) {
.type = kSDItemBufferList,
- .timestamp = os_time(),
- .data = {
- .buffer_list = {
- .size = buf_count,
- .buffers = xmalloc(buf_count
- * sizeof(*buflist_entry.data.buffer_list.buffers)),
- },
+ .timestamp = os_time(),
+ .data = {
+ .buffer_list = {
+ .size = buf_count,
+ .buffers = xmalloc(buf_count
+ * sizeof(*buflist_entry.data.buffer_list.buffers)),
},
+ },
};
size_t i = 0;
FOR_ALL_BUFFERS(buf) {
@@ -2419,8 +2345,8 @@ static inline ShadaEntry shada_get_buflist(
}
buflist_entry.data.buffer_list.buffers[i] = (struct buffer_list_buffer) {
.pos = buf->b_last_cursor.mark,
- .fname = (char *)buf->b_ffname,
- .additional_data = buf->additional_data,
+ .fname = (char *)buf->b_ffname,
+ .additional_data = buf->additional_data,
};
i++;
}
@@ -2442,8 +2368,7 @@ static inline ShadaEntry shada_get_buflist(
/// saved.
static inline void add_search_pattern(PossiblyFreedShadaEntry *const ret_pse,
const SearchPatternGetter get_pattern,
- const bool is_substitute_pattern,
- const bool search_last_used,
+ const bool is_substitute_pattern, const bool search_last_used,
const bool search_highlighted)
FUNC_ATTR_ALWAYS_INLINE
{
@@ -2464,7 +2389,7 @@ static inline void add_search_pattern(PossiblyFreedShadaEntry *const ret_pse,
? defaults.data.search_pattern.has_line_offset
: pat.off.line),
.place_cursor_at_end = (
- is_substitute_pattern
+ is_substitute_pattern
? defaults.data.search_pattern.place_cursor_at_end
: pat.off.end),
.offset = (is_substitute_pattern
@@ -2488,8 +2413,7 @@ static inline void add_search_pattern(PossiblyFreedShadaEntry *const ret_pse,
///
/// @param[in] wms The WriteMergerState used when writing.
/// @param[in] max_reg_lines The maximum number of register lines.
-static inline void shada_initialize_registers(WriteMergerState *const wms,
- int max_reg_lines)
+static inline void shada_initialize_registers(WriteMergerState *const wms, int max_reg_lines)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_ALWAYS_INLINE
{
const void *reg_iter = NULL;
@@ -2534,8 +2458,7 @@ static inline void shada_initialize_registers(WriteMergerState *const wms,
/// @param[out] wms Merger state to adjust.
/// @param[in] idx Index at which new mark should be placed.
/// @param[in] entry New mark.
-static inline void replace_numbered_mark(WriteMergerState *const wms,
- const size_t idx,
+static inline void replace_numbered_mark(WriteMergerState *const wms, const size_t idx,
const PossiblyFreedShadaEntry entry)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_ALWAYS_INLINE
{
@@ -2573,8 +2496,7 @@ static inline void find_removable_bufs(khash_t(bufset) *removable_bufs)
/// @param[in] sd_reader Structure containing file reader definition. If it is
/// not NULL then contents of this file will be merged
/// with current Neovim runtime.
-static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
- ShaDaReadDef *const sd_reader)
+static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef *const sd_reader)
FUNC_ATTR_NONNULL_ARG(1)
{
ShaDaWriteResult ret = kSDWriteSuccessfull;
@@ -2595,8 +2517,8 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
}
const bool dump_registers = (max_reg_lines != 0);
khash_t(bufset) removable_bufs = KHASH_EMPTY_TABLE(bufset);
- const size_t max_kbyte = (size_t) max_kbyte_i;
- const size_t num_marked_files = (size_t) get_shada_parameter('\'');
+ const size_t max_kbyte = (size_t)max_kbyte_i;
+ const size_t num_marked_files = (size_t)get_shada_parameter('\'');
const bool dump_global_marks = get_shada_parameter('f') != 0;
bool dump_history = false;
@@ -2609,20 +2531,21 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
if (num_saved > 0) {
dump_history = true;
dump_one_history[i] = true;
- hms_init(&wms->hms[i], i, (size_t) num_saved, sd_reader != NULL, false);
+ hms_init(&wms->hms[i], i, (size_t)num_saved, sd_reader != NULL, false);
} else {
dump_one_history[i] = false;
}
}
- const unsigned srni_flags = (unsigned) (
- kSDReadUndisableableData
- | kSDReadUnknown
- | (dump_history ? kSDReadHistory : 0)
- | (dump_registers ? kSDReadRegisters : 0)
- | (dump_global_vars ? kSDReadVariables : 0)
- | (dump_global_marks ? kSDReadGlobalMarks : 0)
- | (num_marked_files ? kSDReadLocalMarks | kSDReadChanges : 0));
+ const unsigned srni_flags = (unsigned)(
+ kSDReadUndisableableData
+ | kSDReadUnknown
+ | (dump_history ? kSDReadHistory : 0)
+ | (dump_registers ? kSDReadRegisters : 0)
+ | (dump_global_vars ? kSDReadVariables : 0)
+ | (dump_global_marks ? kSDReadGlobalMarks : 0)
+ | (num_marked_files ? kSDReadLocalMarks |
+ kSDReadChanges : 0));
msgpack_packer *const packer = msgpack_packer_new(sd_writer,
&msgpack_sd_writer_write);
@@ -2652,11 +2575,11 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
{ STATIC_CSTR_AS_STRING("version"),
STRING_OBJ(cstr_as_string(longVersion)) },
{ STATIC_CSTR_AS_STRING("max_kbyte"),
- INTEGER_OBJ((Integer) max_kbyte) },
+ INTEGER_OBJ((Integer)max_kbyte) },
{ STATIC_CSTR_AS_STRING("pid"),
- INTEGER_OBJ((Integer) os_get_pid()) },
+ INTEGER_OBJ((Integer)os_get_pid()) },
{ STATIC_CSTR_AS_STRING("encoding"),
- STRING_OBJ(cstr_as_string((char *) p_enc)) },
+ STRING_OBJ(cstr_as_string((char *)p_enc)) },
}),
}
}
@@ -2688,34 +2611,32 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
break;
}
switch (vartv.v_type) {
- case VAR_FUNC:
- case VAR_PARTIAL:
+ case VAR_FUNC:
+ case VAR_PARTIAL:
+ tv_clear(&vartv);
+ continue;
+ case VAR_DICT: {
+ dict_T *di = vartv.vval.v_dict;
+ int copyID = get_copyID();
+ if (!set_ref_in_ht(&di->dv_hashtab, copyID, NULL)
+ && copyID == di->dv_copyID) {
tv_clear(&vartv);
continue;
- case VAR_DICT:
- {
- dict_T *di = vartv.vval.v_dict;
- int copyID = get_copyID();
- if (!set_ref_in_ht(&di->dv_hashtab, copyID, NULL)
- && copyID == di->dv_copyID) {
- tv_clear(&vartv);
- continue;
- }
- break;
- }
- case VAR_LIST:
- {
- list_T *l = vartv.vval.v_list;
- int copyID = get_copyID();
- if (!set_ref_in_list(l, copyID, NULL)
- && copyID == l->lv_copyID) {
- tv_clear(&vartv);
- continue;
- }
- break;
- }
- default:
- break;
+ }
+ break;
+ }
+ case VAR_LIST: {
+ list_T *l = vartv.vval.v_list;
+ int copyID = get_copyID();
+ if (!set_ref_in_list(l, copyID, NULL)
+ && copyID == l->lv_copyID) {
+ tv_clear(&vartv);
+ continue;
+ }
+ break;
+ }
+ default:
+ break;
}
typval_T tgttv;
tv_copy(&vartv, &tgttv);
@@ -2725,7 +2646,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
.timestamp = cur_timestamp,
.data = {
.global_var = {
- .name = (char *) name,
+ .name = (char *)name,
.value = tgttv,
.additional_elements = NULL,
}
@@ -2740,7 +2661,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
tv_clear(&tgttv);
if (spe_ret == kSDWriteSuccessfull) {
int kh_ret;
- (void) kh_put(strset, &wms->dumped_variables, name, &kh_ret);
+ (void)kh_put(strset, &wms->dumped_variables, name, &kh_ret);
}
} while (var_iter != NULL);
}
@@ -2773,7 +2694,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
.timestamp = sub.timestamp,
.data = {
.sub_string = {
- .sub = (char *) sub.sub,
+ .sub = (char *)sub.sub,
.additional_elements = sub.additional_elements,
}
}
@@ -2795,17 +2716,17 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
const char *fname;
if (fm.fmark.fnum == 0) {
assert(fm.fname != NULL);
- if (shada_removable((const char *) fm.fname)) {
+ if (shada_removable((const char *)fm.fname)) {
continue;
}
- fname = (const char *) fm.fname;
+ fname = (const char *)fm.fname;
} else {
const buf_T *const buf = buflist_findnr(fm.fmark.fnum);
if (buf == NULL || buf->b_ffname == NULL
|| in_bufset(&removable_bufs, buf)) {
continue;
}
- fname = (const char *) buf->b_ffname;
+ fname = (const char *)buf->b_ffname;
}
const PossiblyFreedShadaEntry pf_entry = {
.can_free_entry = false,
@@ -2842,7 +2763,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
continue;
}
const void *local_marks_iter = NULL;
- const char *const fname = (const char *) buf->b_ffname;
+ const char *const fname = (const char *)buf->b_ffname;
khiter_t k;
int kh_ret;
k = kh_put(file_marks, &wms->file_marks, fname, &kh_ret);
@@ -2866,7 +2787,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
.filemark = {
.mark = fm.mark,
.name = name,
- .fname = (char *) fname,
+ .fname = (char *)fname,
.additional_data = fm.additional_data,
}
}
@@ -2886,7 +2807,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
.data = {
.filemark = {
.mark = fm.mark,
- .fname = (char *) fname,
+ .fname = (char *)fname,
.additional_data = fm.additional_data,
}
}
@@ -2896,13 +2817,13 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
filemarks->greatest_timestamp = fm.timestamp;
}
}
- filemarks->changes_size = (size_t) buf->b_changelistlen;
+ filemarks->changes_size = (size_t)buf->b_changelistlen;
}
}
if (sd_reader != NULL) {
- const ShaDaWriteResult srww_ret = shada_read_when_writing(
- sd_reader, srni_flags, max_kbyte, wms, packer);
+ const ShaDaWriteResult srww_ret = shada_read_when_writing(sd_reader, srni_flags, max_kbyte, wms,
+ packer);
if (srww_ret != kSDWriteSuccessfull) {
ret = srww_ret;
}
@@ -2968,7 +2889,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
const size_t file_markss_size = kh_size(&wms->file_marks);
FileMarks **const all_file_markss =
- xmalloc(file_markss_size * sizeof(*all_file_markss));
+ xmalloc(file_markss_size * sizeof(*all_file_markss));
FileMarks **cur_file_marks = all_file_markss;
for (khint_t i = kh_begin(&wms->file_marks); i != kh_end(&wms->file_marks);
i++) {
@@ -2976,7 +2897,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
*cur_file_marks++ = &kh_val(&wms->file_marks, i);
}
}
- qsort((void *) all_file_markss, file_markss_size, sizeof(*all_file_markss),
+ qsort((void *)all_file_markss, file_markss_size, sizeof(*all_file_markss),
&compare_file_marks);
const size_t file_markss_to_dump = MIN(num_marked_files, file_markss_size);
for (size_t i = 0; i < file_markss_to_dump; i++) {
@@ -3007,11 +2928,10 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
if (dump_one_history[i]) {
hms_insert_whole_neovim_history(&wms->hms[i]);
HMS_ITER(&wms->hms[i], cur_entry, {
- if (shada_pack_pfreed_entry(
- packer, (PossiblyFreedShadaEntry) {
- .data = cur_entry->data,
- .can_free_entry = cur_entry->can_free_entry,
- }, max_kbyte) == kSDWriteFailed) {
+ if (shada_pack_pfreed_entry(packer, (PossiblyFreedShadaEntry) {
+ .data = cur_entry->data,
+ .can_free_entry = cur_entry->can_free_entry,
+ }, max_kbyte) == kSDWriteFailed) {
ret = kSDWriteFailed;
break;
}
@@ -3082,7 +3002,7 @@ int shada_write_file(const char *const file, bool nomerge)
}
// Save permissions from the original file, with modifications:
- int perm = (int) os_getperm(fname);
+ int perm = (int)os_getperm(fname);
perm = (perm >= 0) ? ((perm & 0777) | 0600) : 0600;
// ^3 ^1 ^2 ^2,3
// 1: Strip SUID bit if any.
@@ -3090,8 +3010,7 @@ int shada_write_file(const char *const file, bool nomerge)
// 3: If somebody happened to delete the file after it was opened for
// reading use u=rw permissions.
shada_write_file_open: {}
- sd_writer.cookie = file_open_new(
- &error, tempname, kFileCreateOnly|kFileNoSymlink, perm);
+ sd_writer.cookie = file_open_new(&error, tempname, kFileCreateOnly|kFileNoSymlink, perm);
if (sd_writer.cookie == NULL) {
if (error == UV_EEXIST || error == UV_ELOOP) {
// File already exists, try another name
@@ -3244,8 +3163,7 @@ int shada_read_marks(void)
/// @param[in] missing_ok If true, do not error out when file is missing.
///
/// @return OK in case of success, FAIL otherwise.
-int shada_read_everything(const char *const fname, const bool forceit,
- const bool missing_ok)
+int shada_read_everything(const char *const fname, const bool forceit, const bool missing_ok)
{
return shada_read_file(fname,
kShaDaWantInfo|kShaDaWantMarks|kShaDaGetOldfiles
@@ -3259,62 +3177,52 @@ static void shada_free_shada_entry(ShadaEntry *const entry)
return;
}
switch (entry->type) {
- case kSDItemMissing: {
- break;
+ case kSDItemMissing:
+ break;
+ case kSDItemUnknown:
+ xfree(entry->data.unknown_item.contents);
+ break;
+ case kSDItemHeader:
+ api_free_dictionary(entry->data.header);
+ break;
+ case kSDItemChange:
+ case kSDItemJump:
+ case kSDItemGlobalMark:
+ case kSDItemLocalMark:
+ tv_dict_unref(entry->data.filemark.additional_data);
+ xfree(entry->data.filemark.fname);
+ break;
+ case kSDItemSearchPattern:
+ tv_dict_unref(entry->data.search_pattern.additional_data);
+ xfree(entry->data.search_pattern.pat);
+ break;
+ case kSDItemRegister:
+ tv_dict_unref(entry->data.reg.additional_data);
+ for (size_t i = 0; i < entry->data.reg.contents_size; i++) {
+ xfree(entry->data.reg.contents[i]);
}
- case kSDItemUnknown: {
- xfree(entry->data.unknown_item.contents);
- break;
- }
- case kSDItemHeader: {
- api_free_dictionary(entry->data.header);
- break;
- }
- case kSDItemChange:
- case kSDItemJump:
- case kSDItemGlobalMark:
- case kSDItemLocalMark: {
- tv_dict_unref(entry->data.filemark.additional_data);
- xfree(entry->data.filemark.fname);
- break;
- }
- case kSDItemSearchPattern: {
- tv_dict_unref(entry->data.search_pattern.additional_data);
- xfree(entry->data.search_pattern.pat);
- break;
- }
- case kSDItemRegister: {
- tv_dict_unref(entry->data.reg.additional_data);
- for (size_t i = 0; i < entry->data.reg.contents_size; i++) {
- xfree(entry->data.reg.contents[i]);
- }
- xfree(entry->data.reg.contents);
- break;
- }
- case kSDItemHistoryEntry: {
- tv_list_unref(entry->data.history_item.additional_elements);
- xfree(entry->data.history_item.string);
- break;
- }
- case kSDItemVariable: {
- tv_list_unref(entry->data.global_var.additional_elements);
- xfree(entry->data.global_var.name);
- tv_clear(&entry->data.global_var.value);
- break;
- }
- case kSDItemSubString: {
- tv_list_unref(entry->data.sub_string.additional_elements);
- xfree(entry->data.sub_string.sub);
- break;
- }
- case kSDItemBufferList: {
- for (size_t i = 0; i < entry->data.buffer_list.size; i++) {
- xfree(entry->data.buffer_list.buffers[i].fname);
- tv_dict_unref(entry->data.buffer_list.buffers[i].additional_data);
- }
- xfree(entry->data.buffer_list.buffers);
- break;
+ xfree(entry->data.reg.contents);
+ break;
+ case kSDItemHistoryEntry:
+ tv_list_unref(entry->data.history_item.additional_elements);
+ xfree(entry->data.history_item.string);
+ break;
+ case kSDItemVariable:
+ tv_list_unref(entry->data.global_var.additional_elements);
+ xfree(entry->data.global_var.name);
+ tv_clear(&entry->data.global_var.value);
+ break;
+ case kSDItemSubString:
+ tv_list_unref(entry->data.sub_string.additional_elements);
+ xfree(entry->data.sub_string.sub);
+ break;
+ case kSDItemBufferList:
+ for (size_t i = 0; i < entry->data.buffer_list.size; i++) {
+ xfree(entry->data.buffer_list.buffers[i].fname);
+ tv_dict_unref(entry->data.buffer_list.buffers[i].additional_data);
}
+ xfree(entry->data.buffer_list.buffers);
+ break;
}
}
@@ -3327,10 +3235,10 @@ static inline uint64_t be64toh(uint64_t big_endian_64_bits)
// It may appear that when !defined(ORDER_BIG_ENDIAN) actual order is big
// endian. This variant is suboptimal, but it works regardless of actual
// order.
- uint8_t *buf = (uint8_t *) &big_endian_64_bits;
+ uint8_t *buf = (uint8_t *)&big_endian_64_bits;
uint64_t ret = 0;
for (size_t i = 8; i; i--) {
- ret |= ((uint64_t) buf[i - 1]) << ((8 - i) * 8);
+ ret |= ((uint64_t)buf[i - 1]) << ((8 - i) * 8);
}
return ret;
#endif
@@ -3346,8 +3254,7 @@ static inline uint64_t be64toh(uint64_t big_endian_64_bits)
/// @return kSDReadStatusSuccess if everything was OK, kSDReadStatusNotShaDa if
/// there were not enough bytes to read or kSDReadStatusReadError if
/// there was some error while reading.
-static ShaDaReadResult fread_len(ShaDaReadDef *const sd_reader,
- char *const buffer,
+static ShaDaReadResult fread_len(ShaDaReadDef *const sd_reader, char *const buffer,
const size_t length)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
@@ -3385,8 +3292,7 @@ static ShaDaReadResult fread_len(ShaDaReadDef *const sd_reader,
/// @return kSDReadStatusSuccess if reading was successful,
/// kSDReadStatusNotShaDa if there were not enough bytes to read or
/// kSDReadStatusReadError if reading failed for whatever reason.
-static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader,
- const int first_char,
+static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const int first_char,
uint64_t *const result)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
@@ -3401,42 +3307,37 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader,
emsgf(_(RCERR "Error while reading ShaDa file: "
"expected positive integer at position %" PRIu64
", but got nothing"),
- (uint64_t) fpos);
+ (uint64_t)fpos);
return kSDReadStatusNotShaDa;
}
}
if (~first_char & 0x80) {
// Positive fixnum
- *result = (uint64_t) ((uint8_t) first_char);
+ *result = (uint64_t)((uint8_t)first_char);
} else {
size_t length = 0;
switch (first_char) {
- case 0xCC: { // uint8
- length = 1;
- break;
- }
- case 0xCD: { // uint16
- length = 2;
- break;
- }
- case 0xCE: { // uint32
- length = 4;
- break;
- }
- case 0xCF: { // uint64
- length = 8;
- break;
- }
- default: {
- emsgf(_(RCERR "Error while reading ShaDa file: "
- "expected positive integer at position %" PRIu64),
- (uint64_t) fpos);
- return kSDReadStatusNotShaDa;
- }
+ case 0xCC: // uint8
+ length = 1;
+ break;
+ case 0xCD: // uint16
+ length = 2;
+ break;
+ case 0xCE: // uint32
+ length = 4;
+ break;
+ case 0xCF: // uint64
+ length = 8;
+ break;
+ default:
+ emsgf(_(RCERR "Error while reading ShaDa file: "
+ "expected positive integer at position %" PRIu64),
+ (uint64_t)fpos);
+ return kSDReadStatusNotShaDa;
}
uint64_t buf = 0;
- char *buf_u8 = (char *) &buf;
+ char *buf_u8 = (char *)&buf;
ShaDaReadResult fl_ret;
if ((fl_ret = fread_len(sd_reader, &(buf_u8[sizeof(buf)-length]), length))
!= kSDReadStatusSuccess) {
@@ -3448,24 +3349,24 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader,
}
#define READERR(entry_name, error_desc) \
- RERR "Error while reading ShaDa file: " \
- entry_name " entry at position %" PRIu64 " " \
- error_desc
+ RERR "Error while reading ShaDa file: " \
+ entry_name " entry at position %" PRIu64 " " \
+ error_desc
#define CHECK_KEY(key, expected) ( \
- key.via.str.size == sizeof(expected) - 1 \
- && STRNCMP(key.via.str.ptr, expected, sizeof(expected) - 1) == 0)
+ key.via.str.size == sizeof(expected) - 1 \
+ && STRNCMP(key.via.str.ptr, expected, sizeof(expected) - 1) == 0)
#define CLEAR_GA_AND_ERROR_OUT(ga) \
- do { \
- ga_clear(&ga); \
- goto shada_read_next_item_error; \
- } while (0)
+ do { \
+ ga_clear(&ga); \
+ goto shada_read_next_item_error; \
+ } while (0)
#define ID(s) s
#define BINDUP(b) xmemdupz(b.ptr, b.size)
-#define TOINT(s) ((int) (s))
-#define TOLONG(s) ((long) (s))
-#define TOCHAR(s) ((char) (s))
-#define TOU8(s) ((uint8_t) (s))
-#define TOSIZE(s) ((size_t) (s))
+#define TOINT(s) ((int)(s))
+#define TOLONG(s) ((long)(s))
+#define TOCHAR(s) ((char)(s))
+#define TOU8(s) ((uint8_t)(s))
+#define TOSIZE(s) ((size_t)(s))
#define CHECKED_ENTRY(condition, error_desc, entry_name, obj, tgt, attr, \
proc) \
do { \
@@ -3486,18 +3387,16 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader,
}
#define CHECKED_KEY(un, entry_name, name, error_desc, tgt, condition, attr, \
proc) \
- else if (CHECK_KEY( /* NOLINT(readability/braces) */ \
- un.data.via.map.ptr[i].key, name)) { \
- CHECKED_ENTRY( \
- condition, "has " name " key value " error_desc, \
- entry_name, un.data.via.map.ptr[i].val, \
- tgt, attr, proc); \
+ else if (CHECK_KEY( /* NOLINT(readability/braces) */ \
+ un.data.via.map.ptr[i].key, name)) { \
+ CHECKED_ENTRY(condition, "has " name " key value " error_desc, \
+ entry_name, un.data.via.map.ptr[i].val, \
+ tgt, attr, proc); \
}
#define TYPED_KEY(un, entry_name, name, type_name, tgt, objtype, attr, proc) \
- CHECKED_KEY( \
- un, entry_name, name, "which is not " type_name, tgt, \
- un.data.via.map.ptr[i].val.type == MSGPACK_OBJECT_##objtype, \
- attr, proc)
+ CHECKED_KEY(un, entry_name, name, "which is not " type_name, tgt, \
+ un.data.via.map.ptr[i].val.type == MSGPACK_OBJECT_##objtype, \
+ attr, proc)
#define BOOLEAN_KEY(un, entry_name, name, tgt) \
TYPED_KEY(un, entry_name, name, "a boolean", tgt, BOOLEAN, boolean, ID)
#define STRING_KEY(un, entry_name, name, tgt) \
@@ -3506,19 +3405,18 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader,
TYPED_KEY(un, entry_name, name, "a binary", tgt, BIN, bin, \
BIN_CONVERTED)
#define INT_KEY(un, entry_name, name, tgt, proc) \
- CHECKED_KEY( \
- un, entry_name, name, "which is not an integer", tgt, \
- ((un.data.via.map.ptr[i].val.type \
- == MSGPACK_OBJECT_POSITIVE_INTEGER) \
- || (un.data.via.map.ptr[i].val.type \
- == MSGPACK_OBJECT_NEGATIVE_INTEGER)), \
- i64, proc)
+ CHECKED_KEY(un, entry_name, name, "which is not an integer", tgt, \
+ ((un.data.via.map.ptr[i].val.type \
+ == MSGPACK_OBJECT_POSITIVE_INTEGER) \
+ || (un.data.via.map.ptr[i].val.type \
+ == MSGPACK_OBJECT_NEGATIVE_INTEGER)), \
+ i64, proc)
#define INTEGER_KEY(un, entry_name, name, tgt) \
INT_KEY(un, entry_name, name, tgt, TOINT)
#define LONG_KEY(un, entry_name, name, tgt) \
INT_KEY(un, entry_name, name, tgt, TOLONG)
#define ADDITIONAL_KEY(un) \
- else { /* NOLINT(readability/braces) */ \
+ else { /* NOLINT(readability/braces) */ \
ga_grow(&ad_ga, 1); \
memcpy(((char *)ad_ga.ga_data) + ((size_t)ad_ga.ga_len \
* sizeof(*un.data.via.map.ptr)), \
@@ -3529,54 +3427,54 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader,
#define CONVERTED(str, len) (xmemdupz((str), (len)))
#define BIN_CONVERTED(b) CONVERTED(b.ptr, b.size)
#define SET_ADDITIONAL_DATA(tgt, name) \
- do { \
- if (ad_ga.ga_len) { \
- msgpack_object obj = { \
- .type = MSGPACK_OBJECT_MAP, \
- .via = { \
- .map = { \
- .size = (uint32_t) ad_ga.ga_len, \
- .ptr = ad_ga.ga_data, \
- } \
- } \
- }; \
- typval_T adtv; \
- if (msgpack_to_vim(obj, &adtv) == FAIL \
- || adtv.v_type != VAR_DICT) { \
- emsgf(_(READERR(name, \
- "cannot be converted to a VimL dictionary")), \
- initial_fpos); \
- ga_clear(&ad_ga); \
- tv_clear(&adtv); \
- goto shada_read_next_item_error; \
+ do { \
+ if (ad_ga.ga_len) { \
+ msgpack_object obj = { \
+ .type = MSGPACK_OBJECT_MAP, \
+ .via = { \
+ .map = { \
+ .size = (uint32_t)ad_ga.ga_len, \
+ .ptr = ad_ga.ga_data, \
} \
- tgt = adtv.vval.v_dict; \
} \
+ }; \
+ typval_T adtv; \
+ if (msgpack_to_vim(obj, &adtv) == FAIL \
+ || adtv.v_type != VAR_DICT) { \
+ emsgf(_(READERR(name, \
+ "cannot be converted to a VimL dictionary")), \
+ initial_fpos); \
ga_clear(&ad_ga); \
- } while (0)
+ tv_clear(&adtv); \
+ goto shada_read_next_item_error; \
+ } \
+ tgt = adtv.vval.v_dict; \
+ } \
+ ga_clear(&ad_ga); \
+ } while (0)
#define SET_ADDITIONAL_ELEMENTS(src, src_maxsize, tgt, name) \
- do { \
- if ((src).size > (size_t) (src_maxsize)) { \
- msgpack_object obj = { \
- .type = MSGPACK_OBJECT_ARRAY, \
- .via = { \
- .array = { \
- .size = ((src).size - (uint32_t) (src_maxsize)), \
- .ptr = (src).ptr + (src_maxsize), \
- } \
- } \
- }; \
- typval_T aetv; \
- if (msgpack_to_vim(obj, &aetv) == FAIL) { \
- emsgf(_(READERR(name, "cannot be converted to a VimL list")), \
- initial_fpos); \
- tv_clear(&aetv); \
- goto shada_read_next_item_error; \
+ do { \
+ if ((src).size > (size_t)(src_maxsize)) { \
+ msgpack_object obj = { \
+ .type = MSGPACK_OBJECT_ARRAY, \
+ .via = { \
+ .array = { \
+ .size = ((src).size - (uint32_t)(src_maxsize)), \
+ .ptr = (src).ptr + (src_maxsize), \
} \
- assert(aetv.v_type == VAR_LIST); \
- (tgt) = aetv.vval.v_list; \
} \
- } while (0)
+ }; \
+ typval_T aetv; \
+ if (msgpack_to_vim(obj, &aetv) == FAIL) { \
+ emsgf(_(READERR(name, "cannot be converted to a VimL list")), \
+ initial_fpos); \
+ tv_clear(&aetv); \
+ goto shada_read_next_item_error; \
+ } \
+ assert(aetv.v_type == VAR_LIST); \
+ (tgt) = aetv.vval.v_list; \
+ } \
+ } while (0)
/// Iterate over shada file contents
///
@@ -3588,10 +3486,8 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader,
/// greater then given.
///
/// @return Any value from ShaDaReadResult enum.
-static ShaDaReadResult shada_read_next_item(ShaDaReadDef *const sd_reader,
- ShadaEntry *const entry,
- const unsigned flags,
- const size_t max_kbyte)
+static ShaDaReadResult shada_read_next_item(ShaDaReadDef *const sd_reader, ShadaEntry *const entry,
+ const unsigned flags, const size_t max_kbyte)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
ShaDaReadResult ret = kSDReadStatusMalformed;
@@ -3607,11 +3503,11 @@ shada_read_next_item_start:
// First: manually unpack type, timestamp and length.
// This is needed to avoid both seeking and having to maintain a buffer.
- uint64_t type_u64 = (uint64_t) kSDItemMissing;
+ uint64_t type_u64 = (uint64_t)kSDItemMissing;
uint64_t timestamp_u64;
uint64_t length_u64;
- const uint64_t initial_fpos = (uint64_t) sd_reader->fpos;
+ const uint64_t initial_fpos = (uint64_t)sd_reader->fpos;
const int first_char = read_char(sd_reader);
if (first_char == EOF && sd_reader->eof) {
return kSDReadStatusFinished;
@@ -3654,7 +3550,7 @@ shada_read_next_item_start:
if ((type_u64 > SHADA_LAST_ENTRY
? !(flags & kSDReadUnknown)
- : !((unsigned) (1 << type_u64) & flags))
+ : !((unsigned)(1 << type_u64) & flags))
|| (max_kbyte && length > max_kbyte * 1024)) {
// First entry is unknown or equal to "\n" (10)? Most likely this means that
// current file is not a ShaDa file because first item should normally be
@@ -3682,16 +3578,16 @@ shada_read_next_item_start:
entry->data.unknown_item.size = length;
entry->data.unknown_item.type = type_u64;
if (initial_fpos == 0) {
- const ShaDaReadResult spm_ret = shada_parse_msgpack(
- sd_reader, length, NULL, &entry->data.unknown_item.contents);
+ const ShaDaReadResult spm_ret = shada_parse_msgpack(sd_reader, length, NULL,
+ &entry->data.unknown_item.contents);
if (spm_ret != kSDReadStatusSuccess) {
entry->type = kSDItemMissing;
}
return spm_ret;
} else {
entry->data.unknown_item.contents = xmalloc(length);
- const ShaDaReadResult fl_ret = fread_len(
- sd_reader, entry->data.unknown_item.contents, length);
+ const ShaDaReadResult fl_ret =
+ fread_len(sd_reader, entry->data.unknown_item.contents, length);
if (fl_ret != kSDReadStatusSuccess) {
shada_free_shada_entry(entry);
entry->type = kSDItemMissing;
@@ -3711,373 +3607,367 @@ shada_read_next_item_start:
}
ret = kSDReadStatusMalformed;
entry->data = sd_default_values[type_u64].data;
- switch ((ShadaEntryType) type_u64) {
- case kSDItemHeader: {
- if (!msgpack_rpc_to_dictionary(&(unpacked.data), &(entry->data.header))) {
- emsgf(_(READERR("header", "is not a dictionary")), initial_fpos);
- goto shada_read_next_item_error;
- }
- break;
+ switch ((ShadaEntryType)type_u64) {
+ case kSDItemHeader:
+ if (!msgpack_rpc_to_dictionary(&(unpacked.data), &(entry->data.header))) {
+ emsgf(_(READERR("header", "is not a dictionary")), initial_fpos);
+ goto shada_read_next_item_error;
}
- case kSDItemSearchPattern: {
- if (unpacked.data.type != MSGPACK_OBJECT_MAP) {
- emsgf(_(READERR("search pattern", "is not a dictionary")),
- initial_fpos);
- goto shada_read_next_item_error;
- }
- garray_T ad_ga;
- ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
- for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
- CHECK_KEY_IS_STR(unpacked, "search pattern")
- BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_MAGIC,
- entry->data.search_pattern.magic)
- BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_SMARTCASE,
- entry->data.search_pattern.smartcase)
- BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_HAS_LINE_OFFSET,
- entry->data.search_pattern.has_line_offset)
- BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_PLACE_CURSOR_AT_END,
- entry->data.search_pattern.place_cursor_at_end)
- BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_IS_LAST_USED,
- entry->data.search_pattern.is_last_used)
- BOOLEAN_KEY(unpacked, "search pattern",
- SEARCH_KEY_IS_SUBSTITUTE_PATTERN,
- entry->data.search_pattern.is_substitute_pattern)
- BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_HIGHLIGHTED,
- entry->data.search_pattern.highlighted)
- BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_BACKWARD,
- entry->data.search_pattern.search_backward)
- INTEGER_KEY(unpacked, "search pattern", SEARCH_KEY_OFFSET,
- entry->data.search_pattern.offset)
- CONVERTED_STRING_KEY(unpacked, "search pattern", SEARCH_KEY_PAT,
- entry->data.search_pattern.pat)
- ADDITIONAL_KEY(unpacked)
- }
- if (entry->data.search_pattern.pat == NULL) {
- emsgf(_(READERR("search pattern", "has no pattern")), initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- SET_ADDITIONAL_DATA(entry->data.search_pattern.additional_data,
- "search pattern");
- break;
+ break;
+ case kSDItemSearchPattern: {
+ if (unpacked.data.type != MSGPACK_OBJECT_MAP) {
+ emsgf(_(READERR("search pattern", "is not a dictionary")),
+ initial_fpos);
+ goto shada_read_next_item_error;
}
- case kSDItemChange:
- case kSDItemJump:
- case kSDItemGlobalMark:
- case kSDItemLocalMark: {
- if (unpacked.data.type != MSGPACK_OBJECT_MAP) {
- emsgf(_(READERR("mark", "is not a dictionary")), initial_fpos);
- goto shada_read_next_item_error;
- }
- garray_T ad_ga;
- ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
- for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
- CHECK_KEY_IS_STR(unpacked, "mark")
- if (CHECK_KEY(unpacked.data.via.map.ptr[i].key, KEY_NAME_CHAR)) {
- if (type_u64 == kSDItemJump || type_u64 == kSDItemChange) {
- emsgf(_(READERR("mark", "has n key which is only valid for "
- "local and global mark entries")), initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- CHECKED_ENTRY(
- (unpacked.data.via.map.ptr[i].val.type
- == MSGPACK_OBJECT_POSITIVE_INTEGER),
- "has n key value which is not an unsigned integer",
- "mark", unpacked.data.via.map.ptr[i].val,
- entry->data.filemark.name, u64, TOCHAR);
+ garray_T ad_ga;
+ ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
+ for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
+ CHECK_KEY_IS_STR(unpacked, "search pattern")
+ BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_MAGIC,
+ entry->data.search_pattern.magic)
+ BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_SMARTCASE,
+ entry->data.search_pattern.smartcase)
+ BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_HAS_LINE_OFFSET,
+ entry->data.search_pattern.has_line_offset)
+ BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_PLACE_CURSOR_AT_END,
+ entry->data.search_pattern.place_cursor_at_end)
+ BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_IS_LAST_USED,
+ entry->data.search_pattern.is_last_used)
+ BOOLEAN_KEY(unpacked, "search pattern",
+ SEARCH_KEY_IS_SUBSTITUTE_PATTERN,
+ entry->data.search_pattern.is_substitute_pattern)
+ BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_HIGHLIGHTED,
+ entry->data.search_pattern.highlighted)
+ BOOLEAN_KEY(unpacked, "search pattern", SEARCH_KEY_BACKWARD,
+ entry->data.search_pattern.search_backward)
+ INTEGER_KEY(unpacked, "search pattern", SEARCH_KEY_OFFSET,
+ entry->data.search_pattern.offset)
+ CONVERTED_STRING_KEY(unpacked, "search pattern", SEARCH_KEY_PAT,
+ entry->data.search_pattern.pat)
+ ADDITIONAL_KEY(unpacked)
+ }
+ if (entry->data.search_pattern.pat == NULL) {
+ emsgf(_(READERR("search pattern", "has no pattern")), initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ }
+ SET_ADDITIONAL_DATA(entry->data.search_pattern.additional_data,
+ "search pattern");
+ break;
+ }
+ case kSDItemChange:
+ case kSDItemJump:
+ case kSDItemGlobalMark:
+ case kSDItemLocalMark: {
+ if (unpacked.data.type != MSGPACK_OBJECT_MAP) {
+ emsgf(_(READERR("mark", "is not a dictionary")), initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ garray_T ad_ga;
+ ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
+ for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
+ CHECK_KEY_IS_STR(unpacked, "mark")
+ if (CHECK_KEY(unpacked.data.via.map.ptr[i].key, KEY_NAME_CHAR)) {
+ if (type_u64 == kSDItemJump || type_u64 == kSDItemChange) {
+ emsgf(_(READERR("mark", "has n key which is only valid for "
+ "local and global mark entries")), initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
}
- LONG_KEY(unpacked, "mark", KEY_LNUM, entry->data.filemark.mark.lnum)
- INTEGER_KEY(unpacked, "mark", KEY_COL, entry->data.filemark.mark.col)
- STRING_KEY(unpacked, "mark", KEY_FILE, entry->data.filemark.fname)
- ADDITIONAL_KEY(unpacked)
+ CHECKED_ENTRY((unpacked.data.via.map.ptr[i].val.type
+ == MSGPACK_OBJECT_POSITIVE_INTEGER),
+ "has n key value which is not an unsigned integer",
+ "mark", unpacked.data.via.map.ptr[i].val,
+ entry->data.filemark.name, u64, TOCHAR);
}
- if (entry->data.filemark.fname == NULL) {
- emsgf(_(READERR("mark", "is missing file name")), initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- if (entry->data.filemark.mark.lnum <= 0) {
- emsgf(_(READERR("mark", "has invalid line number")), initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- if (entry->data.filemark.mark.col < 0) {
- emsgf(_(READERR("mark", "has invalid column number")), initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- SET_ADDITIONAL_DATA(entry->data.filemark.additional_data, "mark");
- break;
+ LONG_KEY(unpacked, "mark", KEY_LNUM, entry->data.filemark.mark.lnum)
+ INTEGER_KEY(unpacked, "mark", KEY_COL, entry->data.filemark.mark.col)
+ STRING_KEY(unpacked, "mark", KEY_FILE, entry->data.filemark.fname)
+ ADDITIONAL_KEY(unpacked)
}
- case kSDItemRegister: {
- if (unpacked.data.type != MSGPACK_OBJECT_MAP) {
- emsgf(_(READERR("register", "is not a dictionary")), initial_fpos);
- goto shada_read_next_item_error;
- }
- garray_T ad_ga;
- ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
- for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
- CHECK_KEY_IS_STR(unpacked, "register")
- if (CHECK_KEY(unpacked.data.via.map.ptr[i].key,
- REG_KEY_CONTENTS)) {
- if (unpacked.data.via.map.ptr[i].val.type != MSGPACK_OBJECT_ARRAY) {
- emsgf(_(READERR("register",
- "has " REG_KEY_CONTENTS
- " key with non-array value")),
- initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- if (unpacked.data.via.map.ptr[i].val.via.array.size == 0) {
- emsgf(_(READERR("register",
- "has " REG_KEY_CONTENTS " key with empty array")),
- initial_fpos);
+ if (entry->data.filemark.fname == NULL) {
+ emsgf(_(READERR("mark", "is missing file name")), initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ }
+ if (entry->data.filemark.mark.lnum <= 0) {
+ emsgf(_(READERR("mark", "has invalid line number")), initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ }
+ if (entry->data.filemark.mark.col < 0) {
+ emsgf(_(READERR("mark", "has invalid column number")), initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ }
+ SET_ADDITIONAL_DATA(entry->data.filemark.additional_data, "mark");
+ break;
+ }
+ case kSDItemRegister: {
+ if (unpacked.data.type != MSGPACK_OBJECT_MAP) {
+ emsgf(_(READERR("register", "is not a dictionary")), initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ garray_T ad_ga;
+ ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
+ for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
+ CHECK_KEY_IS_STR(unpacked, "register")
+ if (CHECK_KEY(unpacked.data.via.map.ptr[i].key,
+ REG_KEY_CONTENTS)) {
+ if (unpacked.data.via.map.ptr[i].val.type != MSGPACK_OBJECT_ARRAY) {
+ emsgf(_(READERR("register",
+ "has " REG_KEY_CONTENTS
+ " key with non-array value")),
+ initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ }
+ if (unpacked.data.via.map.ptr[i].val.via.array.size == 0) {
+ emsgf(_(READERR("register",
+ "has " REG_KEY_CONTENTS " key with empty array")),
+ initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ }
+ const msgpack_object_array arr =
+ unpacked.data.via.map.ptr[i].val.via.array;
+ for (size_t j = 0; j < arr.size; j++) {
+ if (arr.ptr[j].type != MSGPACK_OBJECT_BIN) {
+ emsgf(_(READERR("register", "has " REG_KEY_CONTENTS " array "
+ "with non-binary value")), initial_fpos);
CLEAR_GA_AND_ERROR_OUT(ad_ga);
}
- const msgpack_object_array arr =
- unpacked.data.via.map.ptr[i].val.via.array;
- for (size_t j = 0; j < arr.size; j++) {
- if (arr.ptr[j].type != MSGPACK_OBJECT_BIN) {
- emsgf(_(READERR("register", "has " REG_KEY_CONTENTS " array "
- "with non-binary value")), initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- }
- entry->data.reg.contents_size = arr.size;
- entry->data.reg.contents = xmalloc(arr.size * sizeof(char *));
- for (size_t j = 0; j < arr.size; j++) {
- entry->data.reg.contents[j] = BIN_CONVERTED(arr.ptr[j].via.bin);
- }
}
- BOOLEAN_KEY(unpacked, "register", REG_KEY_UNNAMED,
- entry->data.reg.is_unnamed)
- TYPED_KEY(unpacked, "register", REG_KEY_TYPE, "an unsigned integer",
- entry->data.reg.type, POSITIVE_INTEGER, u64, TOU8)
- TYPED_KEY(unpacked, "register", KEY_NAME_CHAR, "an unsigned integer",
- entry->data.reg.name, POSITIVE_INTEGER, u64, TOCHAR)
- TYPED_KEY(unpacked, "register", REG_KEY_WIDTH, "an unsigned integer",
- entry->data.reg.width, POSITIVE_INTEGER, u64, TOSIZE)
- ADDITIONAL_KEY(unpacked)
- }
- if (entry->data.reg.contents == NULL) {
- emsgf(_(READERR("register", "has missing " REG_KEY_CONTENTS " array")),
- initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ entry->data.reg.contents_size = arr.size;
+ entry->data.reg.contents = xmalloc(arr.size * sizeof(char *));
+ for (size_t j = 0; j < arr.size; j++) {
+ entry->data.reg.contents[j] = BIN_CONVERTED(arr.ptr[j].via.bin);
+ }
}
- SET_ADDITIONAL_DATA(entry->data.reg.additional_data, "register");
- break;
+ BOOLEAN_KEY(unpacked, "register", REG_KEY_UNNAMED,
+ entry->data.reg.is_unnamed)
+ TYPED_KEY(unpacked, "register", REG_KEY_TYPE, "an unsigned integer",
+ entry->data.reg.type, POSITIVE_INTEGER, u64, TOU8)
+ TYPED_KEY(unpacked, "register", KEY_NAME_CHAR, "an unsigned integer",
+ entry->data.reg.name, POSITIVE_INTEGER, u64, TOCHAR)
+ TYPED_KEY(unpacked, "register", REG_KEY_WIDTH, "an unsigned integer",
+ entry->data.reg.width, POSITIVE_INTEGER, u64, TOSIZE)
+ ADDITIONAL_KEY(unpacked)
}
- case kSDItemHistoryEntry: {
- if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) {
- emsgf(_(READERR("history", "is not an array")), initial_fpos);
- goto shada_read_next_item_error;
- }
- if (unpacked.data.via.array.size < 2) {
- emsgf(_(READERR("history", "does not have enough elements")),
- initial_fpos);
+ if (entry->data.reg.contents == NULL) {
+ emsgf(_(READERR("register", "has missing " REG_KEY_CONTENTS " array")),
+ initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ }
+ SET_ADDITIONAL_DATA(entry->data.reg.additional_data, "register");
+ break;
+ }
+ case kSDItemHistoryEntry: {
+ if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) {
+ emsgf(_(READERR("history", "is not an array")), initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ if (unpacked.data.via.array.size < 2) {
+ emsgf(_(READERR("history", "does not have enough elements")),
+ initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ if (unpacked.data.via.array.ptr[0].type
+ != MSGPACK_OBJECT_POSITIVE_INTEGER) {
+ emsgf(_(READERR("history", "has wrong history type type")),
+ initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ if (unpacked.data.via.array.ptr[1].type
+ != MSGPACK_OBJECT_BIN) {
+ emsgf(_(READERR("history", "has wrong history string type")),
+ initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ if (memchr(unpacked.data.via.array.ptr[1].via.bin.ptr, 0,
+ unpacked.data.via.array.ptr[1].via.bin.size) != NULL) {
+ emsgf(_(READERR("history", "contains string with zero byte inside")),
+ initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ entry->data.history_item.histtype =
+ (uint8_t)unpacked.data.via.array.ptr[0].via.u64;
+ const bool is_hist_search =
+ entry->data.history_item.histtype == HIST_SEARCH;
+ if (is_hist_search) {
+ if (unpacked.data.via.array.size < 3) {
+ emsgf(_(READERR("search history",
+ "does not have separator character")), initial_fpos);
goto shada_read_next_item_error;
}
- if (unpacked.data.via.array.ptr[0].type
+ if (unpacked.data.via.array.ptr[2].type
!= MSGPACK_OBJECT_POSITIVE_INTEGER) {
- emsgf(_(READERR("history", "has wrong history type type")),
- initial_fpos);
- goto shada_read_next_item_error;
- }
- if (unpacked.data.via.array.ptr[1].type
- != MSGPACK_OBJECT_BIN) {
- emsgf(_(READERR("history", "has wrong history string type")),
- initial_fpos);
+ emsgf(_(READERR("search history",
+ "has wrong history separator type")), initial_fpos);
goto shada_read_next_item_error;
}
- if (memchr(unpacked.data.via.array.ptr[1].via.bin.ptr, 0,
- unpacked.data.via.array.ptr[1].via.bin.size) != NULL) {
- emsgf(_(READERR("history", "contains string with zero byte inside")),
- initial_fpos);
- goto shada_read_next_item_error;
- }
- entry->data.history_item.histtype =
- (uint8_t) unpacked.data.via.array.ptr[0].via.u64;
- const bool is_hist_search =
- entry->data.history_item.histtype == HIST_SEARCH;
- if (is_hist_search) {
- if (unpacked.data.via.array.size < 3) {
- emsgf(_(READERR("search history",
- "does not have separator character")), initial_fpos);
- goto shada_read_next_item_error;
- }
- if (unpacked.data.via.array.ptr[2].type
- != MSGPACK_OBJECT_POSITIVE_INTEGER) {
- emsgf(_(READERR("search history",
- "has wrong history separator type")), initial_fpos);
+ entry->data.history_item.sep =
+ (char)unpacked.data.via.array.ptr[2].via.u64;
+ }
+ size_t strsize;
+ strsize = (
+ unpacked.data.via.array.ptr[1].via.bin.size
+ + 1 // Zero byte
+ + 1); // Separator character
+ entry->data.history_item.string = xmalloc(strsize);
+ memcpy(entry->data.history_item.string,
+ unpacked.data.via.array.ptr[1].via.bin.ptr,
+ unpacked.data.via.array.ptr[1].via.bin.size);
+ entry->data.history_item.string[strsize - 2] = 0;
+ entry->data.history_item.string[strsize - 1] =
+ entry->data.history_item.sep;
+ SET_ADDITIONAL_ELEMENTS(unpacked.data.via.array, (2 + is_hist_search),
+ entry->data.history_item.additional_elements,
+ "history");
+ break;
+ }
+ case kSDItemVariable: {
+ if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) {
+ emsgf(_(READERR("variable", "is not an array")), initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ if (unpacked.data.via.array.size < 2) {
+ emsgf(_(READERR("variable", "does not have enough elements")),
+ initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ if (unpacked.data.via.array.ptr[0].type != MSGPACK_OBJECT_BIN) {
+ emsgf(_(READERR("variable", "has wrong variable name type")),
+ initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ entry->data.global_var.name =
+ xmemdupz(unpacked.data.via.array.ptr[0].via.bin.ptr,
+ unpacked.data.via.array.ptr[0].via.bin.size);
+ SET_ADDITIONAL_ELEMENTS(unpacked.data.via.array, 2,
+ entry->data.global_var.additional_elements,
+ "variable");
+ bool is_blob = false;
+ // A msgpack BIN could be a String or Blob; an additional VAR_TYPE_BLOB
+ // element is stored with Blobs which can be used to differentiate them
+ if (unpacked.data.via.array.ptr[1].type == MSGPACK_OBJECT_BIN) {
+ const listitem_T *type_item
+ = tv_list_first(entry->data.global_var.additional_elements);
+ if (type_item != NULL) {
+ const typval_T *type_tv = TV_LIST_ITEM_TV(type_item);
+ if (type_tv->v_type != VAR_NUMBER
+ || type_tv->vval.v_number != VAR_TYPE_BLOB) {
+ emsgf(_(READERR("variable", "has wrong variable type")),
+ initial_fpos);
goto shada_read_next_item_error;
}
- entry->data.history_item.sep =
- (char) unpacked.data.via.array.ptr[2].via.u64;
+ is_blob = true;
}
- size_t strsize;
- strsize = (
- unpacked.data.via.array.ptr[1].via.bin.size
- + 1 // Zero byte
- + 1); // Separator character
- entry->data.history_item.string = xmalloc(strsize);
- memcpy(entry->data.history_item.string,
- unpacked.data.via.array.ptr[1].via.bin.ptr,
- unpacked.data.via.array.ptr[1].via.bin.size);
- entry->data.history_item.string[strsize - 2] = 0;
- entry->data.history_item.string[strsize - 1] =
- entry->data.history_item.sep;
- SET_ADDITIONAL_ELEMENTS(unpacked.data.via.array, (2 + is_hist_search),
- entry->data.history_item.additional_elements,
- "history");
- break;
}
- case kSDItemVariable: {
- if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) {
- emsgf(_(READERR("variable", "is not an array")), initial_fpos);
- goto shada_read_next_item_error;
- }
- if (unpacked.data.via.array.size < 2) {
- emsgf(_(READERR("variable", "does not have enough elements")),
- initial_fpos);
- goto shada_read_next_item_error;
- }
- if (unpacked.data.via.array.ptr[0].type != MSGPACK_OBJECT_BIN) {
- emsgf(_(READERR("variable", "has wrong variable name type")),
- initial_fpos);
- goto shada_read_next_item_error;
- }
- entry->data.global_var.name =
- xmemdupz(unpacked.data.via.array.ptr[0].via.bin.ptr,
- unpacked.data.via.array.ptr[0].via.bin.size);
- SET_ADDITIONAL_ELEMENTS(unpacked.data.via.array, 2,
- entry->data.global_var.additional_elements,
- "variable");
- bool is_blob = false;
- // A msgpack BIN could be a String or Blob; an additional VAR_TYPE_BLOB
- // element is stored with Blobs which can be used to differentiate them
- if (unpacked.data.via.array.ptr[1].type == MSGPACK_OBJECT_BIN) {
- const listitem_T *type_item
- = tv_list_first(entry->data.global_var.additional_elements);
- if (type_item != NULL) {
- const typval_T *type_tv = TV_LIST_ITEM_TV(type_item);
- if (type_tv->v_type != VAR_NUMBER
- || type_tv->vval.v_number != VAR_TYPE_BLOB) {
- emsgf(_(READERR("variable", "has wrong variable type")),
- initial_fpos);
- goto shada_read_next_item_error;
- }
- is_blob = true;
- }
- }
- if (is_blob) {
- const msgpack_object_bin *const bin
- = &unpacked.data.via.array.ptr[1].via.bin;
- blob_T *const blob = tv_blob_alloc();
- ga_concat_len(&blob->bv_ga, bin->ptr, (size_t)bin->size);
- tv_blob_set_ret(&entry->data.global_var.value, blob);
- } else if (msgpack_to_vim(unpacked.data.via.array.ptr[1],
- &(entry->data.global_var.value)) == FAIL) {
- emsgf(_(READERR("variable", "has value that cannot "
- "be converted to the VimL value")), initial_fpos);
- goto shada_read_next_item_error;
- }
- break;
+ if (is_blob) {
+ const msgpack_object_bin *const bin
+ = &unpacked.data.via.array.ptr[1].via.bin;
+ blob_T *const blob = tv_blob_alloc();
+ ga_concat_len(&blob->bv_ga, bin->ptr, (size_t)bin->size);
+ tv_blob_set_ret(&entry->data.global_var.value, blob);
+ } else if (msgpack_to_vim(unpacked.data.via.array.ptr[1],
+ &(entry->data.global_var.value)) == FAIL) {
+ emsgf(_(READERR("variable", "has value that cannot "
+ "be converted to the VimL value")), initial_fpos);
+ goto shada_read_next_item_error;
}
- case kSDItemSubString: {
- if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) {
- emsgf(_(READERR("sub string", "is not an array")), initial_fpos);
- goto shada_read_next_item_error;
- }
- if (unpacked.data.via.array.size < 1) {
- emsgf(_(READERR("sub string", "does not have enough elements")),
- initial_fpos);
- goto shada_read_next_item_error;
- }
- if (unpacked.data.via.array.ptr[0].type != MSGPACK_OBJECT_BIN) {
- emsgf(_(READERR("sub string", "has wrong sub string type")),
- initial_fpos);
- goto shada_read_next_item_error;
- }
- entry->data.sub_string.sub =
- BIN_CONVERTED(unpacked.data.via.array.ptr[0].via.bin);
- SET_ADDITIONAL_ELEMENTS(unpacked.data.via.array, 1,
- entry->data.sub_string.additional_elements,
- "sub string");
+ break;
+ }
+ case kSDItemSubString:
+ if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) {
+ emsgf(_(READERR("sub string", "is not an array")), initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ if (unpacked.data.via.array.size < 1) {
+ emsgf(_(READERR("sub string", "does not have enough elements")),
+ initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ if (unpacked.data.via.array.ptr[0].type != MSGPACK_OBJECT_BIN) {
+ emsgf(_(READERR("sub string", "has wrong sub string type")),
+ initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ entry->data.sub_string.sub =
+ BIN_CONVERTED(unpacked.data.via.array.ptr[0].via.bin);
+ SET_ADDITIONAL_ELEMENTS(unpacked.data.via.array, 1,
+ entry->data.sub_string.additional_elements,
+ "sub string");
+ break;
+ case kSDItemBufferList:
+ if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) {
+ emsgf(_(READERR("buffer list", "is not an array")), initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ if (unpacked.data.via.array.size == 0) {
break;
}
- case kSDItemBufferList: {
- if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) {
- emsgf(_(READERR("buffer list", "is not an array")), initial_fpos);
- goto shada_read_next_item_error;
- }
- if (unpacked.data.via.array.size == 0) {
- break;
- }
- entry->data.buffer_list.buffers =
- xcalloc(unpacked.data.via.array.size,
- sizeof(*entry->data.buffer_list.buffers));
- for (size_t i = 0; i < unpacked.data.via.array.size; i++) {
- entry->data.buffer_list.size++;
- msgpack_unpacked unpacked_2 = (msgpack_unpacked) {
- .data = unpacked.data.via.array.ptr[i],
- };
+ entry->data.buffer_list.buffers =
+ xcalloc(unpacked.data.via.array.size,
+ sizeof(*entry->data.buffer_list.buffers));
+ for (size_t i = 0; i < unpacked.data.via.array.size; i++) {
+ entry->data.buffer_list.size++;
+ msgpack_unpacked unpacked_2 = (msgpack_unpacked) {
+ .data = unpacked.data.via.array.ptr[i],
+ };
+ {
+ if (unpacked_2.data.type != MSGPACK_OBJECT_MAP) {
+ emsgf(_(RERR "Error while reading ShaDa file: "
+ "buffer list at position %" PRIu64 " "
+ "contains entry that is not a dictionary"),
+ initial_fpos);
+ goto shada_read_next_item_error;
+ }
+ entry->data.buffer_list.buffers[i].pos = default_pos;
+ garray_T ad_ga;
+ ga_init(&ad_ga, sizeof(*(unpacked_2.data.via.map.ptr)), 1);
{
- if (unpacked_2.data.type != MSGPACK_OBJECT_MAP) {
- emsgf(_(RERR "Error while reading ShaDa file: "
- "buffer list at position %" PRIu64 " "
- "contains entry that is not a dictionary"),
- initial_fpos);
- goto shada_read_next_item_error;
- }
- entry->data.buffer_list.buffers[i].pos = default_pos;
- garray_T ad_ga;
- ga_init(&ad_ga, sizeof(*(unpacked_2.data.via.map.ptr)), 1);
+ // XXX: Temporarily reassign `i` because the macros depend on it.
+ const size_t j = i;
{
- // XXX: Temporarily reassign `i` because the macros depend on it.
- const size_t j = i;
- {
- for (i = 0; i < unpacked_2.data.via.map.size; i++) { // -V535
- CHECK_KEY_IS_STR(unpacked_2, "buffer list entry")
- LONG_KEY(unpacked_2, "buffer list entry", KEY_LNUM,
- entry->data.buffer_list.buffers[j].pos.lnum)
- INTEGER_KEY(unpacked_2, "buffer list entry", KEY_COL,
- entry->data.buffer_list.buffers[j].pos.col)
- STRING_KEY(unpacked_2, "buffer list entry", KEY_FILE,
- entry->data.buffer_list.buffers[j].fname)
- ADDITIONAL_KEY(unpacked_2)
- }
+ for (i = 0; i < unpacked_2.data.via.map.size; i++) { // -V535
+ CHECK_KEY_IS_STR(unpacked_2, "buffer list entry")
+ LONG_KEY(unpacked_2, "buffer list entry", KEY_LNUM,
+ entry->data.buffer_list.buffers[j].pos.lnum)
+ INTEGER_KEY(unpacked_2, "buffer list entry", KEY_COL,
+ entry->data.buffer_list.buffers[j].pos.col)
+ STRING_KEY(unpacked_2, "buffer list entry", KEY_FILE,
+ entry->data.buffer_list.buffers[j].fname)
+ ADDITIONAL_KEY(unpacked_2)
}
- i = j; // XXX: Restore `i`.
}
- if (entry->data.buffer_list.buffers[i].pos.lnum <= 0) {
- emsgf(_(RERR "Error while reading ShaDa file: "
- "buffer list at position %" PRIu64 " "
- "contains entry with invalid line number"),
- initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- if (entry->data.buffer_list.buffers[i].pos.col < 0) {
- emsgf(_(RERR "Error while reading ShaDa file: "
- "buffer list at position %" PRIu64 " "
- "contains entry with invalid column number"),
- initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- if (entry->data.buffer_list.buffers[i].fname == NULL) {
- emsgf(_(RERR "Error while reading ShaDa file: "
- "buffer list at position %" PRIu64 " "
- "contains entry that does not have a file name"),
- initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- SET_ADDITIONAL_DATA(
- entry->data.buffer_list.buffers[i].additional_data,
- "buffer list entry");
+ i = j; // XXX: Restore `i`.
+ }
+ if (entry->data.buffer_list.buffers[i].pos.lnum <= 0) {
+ emsgf(_(RERR "Error while reading ShaDa file: "
+ "buffer list at position %" PRIu64 " "
+ "contains entry with invalid line number"),
+ initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ }
+ if (entry->data.buffer_list.buffers[i].pos.col < 0) {
+ emsgf(_(RERR "Error while reading ShaDa file: "
+ "buffer list at position %" PRIu64 " "
+ "contains entry with invalid column number"),
+ initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
}
+ if (entry->data.buffer_list.buffers[i].fname == NULL) {
+ emsgf(_(RERR "Error while reading ShaDa file: "
+ "buffer list at position %" PRIu64 " "
+ "contains entry that does not have a file name"),
+ initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ }
+ SET_ADDITIONAL_DATA(entry->data.buffer_list.buffers[i].additional_data,
+ "buffer list entry");
}
- break;
- }
- case kSDItemMissing:
- case kSDItemUnknown: {
- abort();
}
+ break;
+ case kSDItemMissing:
+ case kSDItemUnknown:
+ abort();
}
- entry->type = (ShadaEntryType) type_u64;
+ entry->type = (ShadaEntryType)type_u64;
ret = kSDReadStatusSuccess;
shada_read_next_item_end:
if (buf != NULL) {
@@ -4086,7 +3976,7 @@ shada_read_next_item_end:
}
return ret;
shada_read_next_item_error:
- entry->type = (ShadaEntryType) type_u64;
+ entry->type = (ShadaEntryType)type_u64;
shada_free_shada_entry(entry);
entry->type = kSDItemMissing;
goto shada_read_next_item_end;
@@ -4121,13 +4011,13 @@ shada_read_next_item_error:
static bool shada_removable(const char *name)
FUNC_ATTR_WARN_UNUSED_RESULT
{
- char *p;
+ char *p;
char part[MAXPATHL + 1];
bool retval = false;
char *new_name = home_replace_save(NULL, name);
- for (p = (char *) p_shada; *p; ) {
- (void) copy_option_part(&p, part, ARRAY_SIZE(part), ", ");
+ for (p = (char *)p_shada; *p; ) {
+ (void)copy_option_part(&p, part, ARRAY_SIZE(part), ", ");
if (part[0] == 'r') {
home_replace(NULL, part + 1, NameBuff, MAXPATHL, true);
size_t n = STRLEN(NameBuff);
@@ -4148,8 +4038,8 @@ static bool shada_removable(const char *name)
/// location.
///
/// @return number of jumplist entries
-static inline size_t shada_init_jumps(
- PossiblyFreedShadaEntry *jumps, khash_t(bufset) *const removable_bufs)
+static inline size_t shada_init_jumps(PossiblyFreedShadaEntry *jumps,
+ khash_t(bufset) *const removable_bufs)
{
if (!curwin->w_jumplistlen) {
return 0;
@@ -4176,9 +4066,9 @@ static inline size_t shada_init_jumps(
: fm.fmark.fnum != 0) {
continue;
}
- const char *const fname = (char *) (fm.fmark.fnum == 0
+ const char *const fname = (char *)(fm.fmark.fnum == 0
? (fm.fname == NULL ? NULL : fm.fname)
- : buf ? buf->b_ffname : NULL);
+ : buf ? buf->b_ffname : NULL);
if (fname == NULL) {
continue;
}
@@ -4191,7 +4081,7 @@ static inline size_t shada_init_jumps(
.filemark = {
.name = NUL,
.mark = fm.fmark.mark,
- .fname = (char *) fname,
+ .fname = (char *)fname,
.additional_data = fm.fmark.additional_data,
}
}
@@ -4272,9 +4162,8 @@ void shada_encode_gvars(msgpack_sbuffer *const sbuf)
do {
typval_T vartv;
const char *name = NULL;
- var_iter = var_shada_iter(
- var_iter, &name, &vartv,
- VAR_FLAVOUR_DEFAULT | VAR_FLAVOUR_SESSION | VAR_FLAVOUR_SHADA);
+ var_iter = var_shada_iter(var_iter, &name, &vartv,
+ VAR_FLAVOUR_DEFAULT | VAR_FLAVOUR_SESSION | VAR_FLAVOUR_SHADA);
if (name == NULL) {
break;
}
@@ -4304,8 +4193,7 @@ void shada_encode_gvars(msgpack_sbuffer *const sbuf)
/// Wrapper for reading from msgpack_sbuffer.
///
/// @return number of bytes read.
-static ptrdiff_t read_sbuf(ShaDaReadDef *const sd_reader, void *const dest,
- const size_t size)
+static ptrdiff_t read_sbuf(ShaDaReadDef *const sd_reader, void *const dest, const size_t size)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
msgpack_sbuffer *sbuf = (msgpack_sbuffer *)sd_reader->cookie;
@@ -4327,8 +4215,7 @@ static ptrdiff_t read_sbuf(ShaDaReadDef *const sd_reader, void *const dest,
///
/// @return FAIL in case of failure, OK in case of success. May set
/// sd_reader->eof.
-static int sd_sbuf_reader_skip_read(ShaDaReadDef *const sd_reader,
- const size_t offset)
+static int sd_sbuf_reader_skip_read(ShaDaReadDef *const sd_reader, const size_t offset)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
msgpack_sbuffer *sbuf = (msgpack_sbuffer *)sd_reader->cookie;
@@ -4346,8 +4233,7 @@ static int sd_sbuf_reader_skip_read(ShaDaReadDef *const sd_reader,
///
/// @param[in] sbuf msgpack_sbuffer to read from.
/// @param[out] sd_reader Location where reader structure will be saved.
-static void open_shada_sbuf_for_reading(const msgpack_sbuffer *const sbuf,
- ShaDaReadDef *sd_reader)
+static void open_shada_sbuf_for_reading(const msgpack_sbuffer *const sbuf, ShaDaReadDef *sd_reader)
FUNC_ATTR_NONNULL_ALL
{
*sd_reader = (ShaDaReadDef) {
diff --git a/src/nvim/sign.c b/src/nvim/sign.c
index c6f59b42b8..25427de6bf 100644
--- a/src/nvim/sign.c
+++ b/src/nvim/sign.c
@@ -6,33 +6,33 @@
//
-#include "nvim/vim.h"
-#include "nvim/sign.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
-#include "nvim/ex_docmd.h"
#include "nvim/edit.h"
+#include "nvim/ex_docmd.h"
#include "nvim/fold.h"
#include "nvim/move.h"
+#include "nvim/option.h"
#include "nvim/screen.h"
+#include "nvim/sign.h"
#include "nvim/syntax.h"
-#include "nvim/option.h"
+#include "nvim/vim.h"
/// Struct to hold the sign properties.
typedef struct sign sign_T;
struct sign
{
- sign_T *sn_next; // next sign in list
- int sn_typenr; // type number of sign
- char_u *sn_name; // name of sign
- char_u *sn_icon; // name of pixmap
- char_u *sn_text; // text used instead of pixmap
- int sn_line_hl; // highlight ID for line
- int sn_text_hl; // highlight ID for text
- int sn_num_hl; // highlight ID for line number
+ sign_T *sn_next; // next sign in list
+ int sn_typenr; // type number of sign
+ char_u *sn_name; // name of sign
+ char_u *sn_icon; // name of pixmap
+ char_u *sn_text; // text used instead of pixmap
+ int sn_line_hl; // highlight ID for line
+ int sn_text_hl; // highlight ID for text
+ int sn_num_hl; // highlight ID for line number
};
static sign_T *first_sign = NULL;
@@ -42,19 +42,19 @@ static void sign_list_defined(sign_T *sp);
static void sign_undefine(sign_T *sp, sign_T *sp_prev);
static char *cmds[] = {
- "define",
+ "define",
#define SIGNCMD_DEFINE 0
- "undefine",
+ "undefine",
#define SIGNCMD_UNDEFINE 1
- "list",
+ "list",
#define SIGNCMD_LIST 2
- "place",
+ "place",
#define SIGNCMD_PLACE 3
- "unplace",
+ "unplace",
#define SIGNCMD_UNPLACE 4
- "jump",
+ "jump",
#define SIGNCMD_JUMP 5
- NULL
+ NULL
#define SIGNCMD_LAST 6
};
@@ -65,17 +65,17 @@ static int next_sign_id = 1; // next sign id in the global group
/// Initialize data needed for managing signs
void init_signs(void)
{
- hash_init(&sg_table); // sign group hash table
+ hash_init(&sg_table); // sign group hash table
}
/// A new sign in group 'groupname' is added. If the group is not present,
/// create it. Otherwise reference the group.
///
-static signgroup_T * sign_group_ref(const char_u *groupname)
+static signgroup_T *sign_group_ref(const char_u *groupname)
{
- hash_T hash;
- hashitem_T *hi;
- signgroup_T *group;
+ hash_T hash;
+ hashitem_T *hi;
+ signgroup_T *group;
hash = hash_hash(groupname);
hi = hash_lookup(&sg_table, (char *)groupname, STRLEN(groupname), hash);
@@ -100,7 +100,7 @@ static signgroup_T * sign_group_ref(const char_u *groupname)
/// removed, then remove the group.
static void sign_group_unref(char_u *groupname)
{
- hashitem_T *hi;
+ hashitem_T *hi;
signgroup_T *group;
hi = hash_find(&sg_table, groupname);
@@ -120,10 +120,10 @@ static void sign_group_unref(char_u *groupname)
/// or in a named group. If 'group' is '*', then the sign is part of the group.
bool sign_in_group(sign_entry_T *sign, const char_u *group)
{
- return ((group != NULL && STRCMP(group, "*") == 0)
- || (group == NULL && sign->se_group == NULL)
- || (group != NULL && sign->se_group != NULL
- && STRCMP(group, sign->se_group->sg_name) == 0));
+ return ((group != NULL && STRCMP(group, "*") == 0)
+ || (group == NULL && sign->se_group == NULL)
+ || (group != NULL && sign->se_group != NULL
+ && STRCMP(group, sign->se_group->sg_name) == 0));
}
/// Get the next free sign identifier in the specified group
@@ -166,17 +166,19 @@ int sign_group_get_next_signid(buf_T *buf, const char_u *groupname)
/// Insert a new sign into the signlist for buffer 'buf' between the 'prev' and
/// 'next' signs.
-static void insert_sign(
- buf_T *buf, // buffer to store sign in
- sign_entry_T *prev, // previous sign entry
- sign_entry_T *next, // next sign entry
- int id, // sign ID
- const char_u *group, // sign group; NULL for global group
- int prio, // sign priority
- linenr_T lnum, // line number which gets the mark
- int typenr, // typenr of sign we are adding
- bool has_text_or_icon // sign has text or icon
-)
+///
+/// @param buf buffer to store sign in
+/// @param prev previous sign entry
+/// @param next next sign entry
+/// @param id sign ID
+/// @param group sign group; NULL for global group
+/// @param prio sign priority
+/// @param lnum line number which gets the mark
+/// @param typenr typenr of sign we are adding
+/// @param has_text_or_icon sign has text or icon
+static void insert_sign(buf_T *buf, sign_entry_T *prev, sign_entry_T *next, int id,
+ const char_u *group, int prio, linenr_T lnum, int typenr,
+ bool has_text_or_icon)
{
sign_entry_T *newsign = xmalloc(sizeof(sign_entry_T));
newsign->se_id = id;
@@ -212,18 +214,19 @@ static void insert_sign(
}
/// Insert a new sign sorted by line number and sign priority.
-static void insert_sign_by_lnum_prio(
- buf_T *buf, // buffer to store sign in
- sign_entry_T *prev, // previous sign entry
- int id, // sign ID
- const char_u *group, // sign group; NULL for global group
- int prio, // sign priority
- linenr_T lnum, // line number which gets the mark
- int typenr, // typenr of sign we are adding
- bool has_text_or_icon // sign has text or icon
-)
+///
+/// @param buf buffer to store sign in
+/// @param prev previous sign entry
+/// @param id sign ID
+/// @param group sign group; NULL for global group
+/// @param prio sign priority
+/// @param lnum line number which gets the mark
+/// @param typenr typenr of sign we are adding
+/// @param has_text_or_icon sign has text or icon
+static void insert_sign_by_lnum_prio(buf_T *buf, sign_entry_T *prev, int id, const char_u *group,
+ int prio, linenr_T lnum, int typenr, bool has_text_or_icon)
{
- sign_entry_T *sign;
+ sign_entry_T *sign;
// keep signs sorted by lnum, priority and id: insert new sign at
// the proper position in the list for this lnum.
@@ -242,9 +245,9 @@ static void insert_sign_by_lnum_prio(
}
/// Get the name of a sign by its typenr.
-char_u * sign_typenr2name(int typenr)
+char_u *sign_typenr2name(int typenr)
{
- sign_T *sp;
+ sign_T *sp;
for (sp = first_sign; sp != NULL; sp = sp->sn_next) {
if (sp->sn_typenr == typenr) {
@@ -255,9 +258,9 @@ char_u * sign_typenr2name(int typenr)
}
/// Return information about a sign in a Dict
-dict_T * sign_get_info(sign_entry_T *sign)
+dict_T *sign_get_info(sign_entry_T *sign)
{
- dict_T *d = tv_dict_alloc();
+ dict_T *d = tv_dict_alloc();
tv_dict_add_nr(d, S_LEN("id"), sign->se_id);
tv_dict_add_str(d, S_LEN("group"), ((sign->se_group == NULL)
? (char *)""
@@ -345,15 +348,16 @@ static void sign_sort_by_prio_on_line(buf_T *buf, sign_entry_T *sign)
/// Add the sign into the signlist. Find the right spot to do it though.
-void buf_addsign(
- buf_T *buf, // buffer to store sign in
- int id, // sign ID
- const char_u *groupname, // sign group
- int prio, // sign priority
- linenr_T lnum, // line number which gets the mark
- int typenr, // typenr of sign we are adding
- bool has_text_or_icon // sign has text or icon
-)
+///
+/// @param buf buffer to store sign in
+/// @param id sign ID
+/// @param groupname sign group
+/// @param prio sign priority
+/// @param lnum line number which gets the mark
+/// @param typenr typenr of sign we are adding
+/// @param has_text_or_icon sign has text or icon
+void buf_addsign(buf_T *buf, int id, const char_u *groupname, int prio, linenr_T lnum, int typenr,
+ bool has_text_or_icon)
{
sign_entry_T *sign; // a sign in the signlist
sign_entry_T *prev; // the previous sign
@@ -368,53 +372,51 @@ void buf_addsign(
sign_sort_by_prio_on_line(buf, sign);
return;
} else if (lnum < sign->se_lnum) {
- insert_sign_by_lnum_prio(
- buf,
- prev,
- id,
- groupname,
- prio,
- lnum,
- typenr,
- has_text_or_icon);
+ insert_sign_by_lnum_prio(buf,
+ prev,
+ id,
+ groupname,
+ prio,
+ lnum,
+ typenr,
+ has_text_or_icon);
return;
}
prev = sign;
}
- insert_sign_by_lnum_prio(
- buf,
- prev,
- id,
- groupname,
- prio,
- lnum,
- typenr,
- has_text_or_icon);
+ insert_sign_by_lnum_prio(buf,
+ prev,
+ id,
+ groupname,
+ prio,
+ lnum,
+ typenr,
+ has_text_or_icon);
}
-// For an existing, placed sign "markId" change the type to "typenr".
-// Returns the line number of the sign, or zero if the sign is not found.
-linenr_T buf_change_sign_type(
- buf_T *buf, // buffer to store sign in
- int markId, // sign ID
- const char_u *group, // sign group
- int typenr, // typenr of sign we are adding
- int prio // sign priority
-)
+/// For an existing, placed sign "markId" change the type to "typenr".
+/// Returns the line number of the sign, or zero if the sign is not found.
+///
+/// @param buf buffer to store sign in
+/// @param markId sign ID
+/// @param group sign group
+/// @param typenr typenr of sign we are adding
+/// @param prio sign priority
+linenr_T buf_change_sign_type(buf_T *buf, int markId, const char_u *group, int typenr, int prio)
{
- sign_entry_T *sign; // a sign in the signlist
+ sign_entry_T *sign; // a sign in the signlist
- FOR_ALL_SIGNS_IN_BUF(buf, sign) {
- if (sign->se_id == markId && sign_in_group(sign, group)) {
- sign->se_typenr = typenr;
- sign->se_priority = prio;
- sign_sort_by_prio_on_line(buf, sign);
- return sign->se_lnum;
- }
+ FOR_ALL_SIGNS_IN_BUF(buf, sign) {
+ if (sign->se_id == markId && sign_in_group(sign, group)) {
+ sign->se_typenr = typenr;
+ sign->se_priority = prio;
+ sign_sort_by_prio_on_line(buf, sign);
+ return sign->se_lnum;
}
+ }
- return (linenr_T)0;
+ return (linenr_T)0;
}
/// Return the sign attrs which has the attribute specified by 'type'. Returns
@@ -426,44 +428,43 @@ linenr_T buf_change_sign_type(
/// @param max_signs the number of signs, with priority for the ones
/// with the highest Ids.
/// @return Attrs of the matching sign, or NULL
-sign_attrs_T * sign_get_attr(SignType type, sign_attrs_T sattrs[],
- int idx, int max_signs)
+sign_attrs_T *sign_get_attr(SignType type, sign_attrs_T sattrs[], int idx, int max_signs)
{
- sign_attrs_T *matches[SIGN_SHOW_MAX];
- int nr_matches = 0;
-
- for (int i = 0; i < SIGN_SHOW_MAX; i++) {
- if ( (type == SIGN_TEXT && sattrs[i].sat_text != NULL)
- || (type == SIGN_LINEHL && sattrs[i].sat_linehl != 0)
- || (type == SIGN_NUMHL && sattrs[i].sat_numhl != 0)) {
- matches[nr_matches] = &sattrs[i];
- nr_matches++;
- // attr list is sorted with most important (priority, id), thus we
- // may stop as soon as we have max_signs matches
- if (nr_matches >= max_signs) {
- break;
- }
- }
+ sign_attrs_T *matches[SIGN_SHOW_MAX];
+ int nr_matches = 0;
+
+ for (int i = 0; i < SIGN_SHOW_MAX; i++) {
+ if ( (type == SIGN_TEXT && sattrs[i].sat_text != NULL)
+ || (type == SIGN_LINEHL && sattrs[i].sat_linehl != 0)
+ || (type == SIGN_NUMHL && sattrs[i].sat_numhl != 0)) {
+ matches[nr_matches] = &sattrs[i];
+ nr_matches++;
+ // attr list is sorted with most important (priority, id), thus we
+ // may stop as soon as we have max_signs matches
+ if (nr_matches >= max_signs) {
+ break;
+ }
}
+ }
- if (nr_matches > idx) {
- return matches[nr_matches - idx - 1];
- }
+ if (nr_matches > idx) {
+ return matches[nr_matches - idx - 1];
+ }
- return NULL;
+ return NULL;
}
/// Lookup a sign by typenr. Returns NULL if sign is not found.
-static sign_T * find_sign_by_typenr(int typenr)
+static sign_T *find_sign_by_typenr(int typenr)
{
- sign_T *sp;
+ sign_T *sp;
- for (sp = first_sign; sp != NULL; sp = sp->sn_next) {
- if (sp->sn_typenr == typenr) {
- return sp;
- }
+ for (sp = first_sign; sp != NULL; sp = sp->sn_next) {
+ if (sp->sn_typenr == typenr) {
+ return sp;
}
- return NULL;
+ }
+ return NULL;
}
/// Return the attributes of all the signs placed on line 'lnum' in buffer
@@ -474,44 +475,44 @@ static sign_T * find_sign_by_typenr(int typenr)
/// @return Number of signs of which attrs were found
int buf_get_signattrs(buf_T *buf, linenr_T lnum, sign_attrs_T sattrs[])
{
- sign_entry_T *sign;
- sign_T *sp;
+ sign_entry_T *sign;
+ sign_T *sp;
- int nr_matches = 0;
+ int nr_matches = 0;
- FOR_ALL_SIGNS_IN_BUF(buf, sign) {
- if (sign->se_lnum > lnum) {
- // Signs are sorted by line number in the buffer. No need to check
- // for signs after the specified line number 'lnum'.
- break;
- }
+ FOR_ALL_SIGNS_IN_BUF(buf, sign) {
+ if (sign->se_lnum > lnum) {
+ // Signs are sorted by line number in the buffer. No need to check
+ // for signs after the specified line number 'lnum'.
+ break;
+ }
- if (sign->se_lnum == lnum) {
- sign_attrs_T sattr;
- memset(&sattr, 0, sizeof(sattr));
- sattr.sat_typenr = sign->se_typenr;
- sp = find_sign_by_typenr(sign->se_typenr);
- if (sp != NULL) {
- sattr.sat_text = sp->sn_text;
- if (sattr.sat_text != NULL && sp->sn_text_hl != 0) {
- sattr.sat_texthl = syn_id2attr(sp->sn_text_hl);
- }
- if (sp->sn_line_hl != 0) {
- sattr.sat_linehl = syn_id2attr(sp->sn_line_hl);
- }
- if (sp->sn_num_hl != 0) {
- sattr.sat_numhl = syn_id2attr(sp->sn_num_hl);
- }
- }
-
- sattrs[nr_matches] = sattr;
- nr_matches++;
- if (nr_matches == SIGN_SHOW_MAX) {
- break;
- }
+ if (sign->se_lnum == lnum) {
+ sign_attrs_T sattr;
+ memset(&sattr, 0, sizeof(sattr));
+ sattr.sat_typenr = sign->se_typenr;
+ sp = find_sign_by_typenr(sign->se_typenr);
+ if (sp != NULL) {
+ sattr.sat_text = sp->sn_text;
+ if (sattr.sat_text != NULL && sp->sn_text_hl != 0) {
+ sattr.sat_texthl = syn_id2attr(sp->sn_text_hl);
+ }
+ if (sp->sn_line_hl != 0) {
+ sattr.sat_linehl = syn_id2attr(sp->sn_line_hl);
+ }
+ if (sp->sn_num_hl != 0) {
+ sattr.sat_numhl = syn_id2attr(sp->sn_num_hl);
}
+ }
+
+ sattrs[nr_matches] = sattr;
+ nr_matches++;
+ if (nr_matches == SIGN_SHOW_MAX) {
+ break;
+ }
}
- return nr_matches;
+ }
+ return nr_matches;
}
/// Delete sign 'id' in group 'group' from buffer 'buf'.
@@ -520,14 +521,15 @@ int buf_get_signattrs(buf_T *buf, linenr_T lnum, sign_attrs_T sattrs[])
/// If 'group' is '*', then delete the sign in all the groups. If 'group' is
/// NULL, then delete the sign in the global group. Otherwise delete the sign in
/// the specified group.
-/// Returns the line number of the deleted sign. If multiple signs are deleted,
+///
+/// @param buf buffer sign is stored in
+/// @param atlnum sign at this line, 0 - at any line
+/// @param id sign id
+/// @param group sign group
+///
+/// @return the line number of the deleted sign. If multiple signs are deleted,
/// then returns the line number of the last sign deleted.
-linenr_T buf_delsign(
- buf_T *buf, // buffer sign is stored in
- linenr_T atlnum, // sign at this line, 0 - at any line
- int id, // sign id
- char_u *group // sign group
-)
+linenr_T buf_delsign(buf_T *buf, linenr_T atlnum, int id, char_u *group)
{
sign_entry_T **lastp; // pointer to pointer to current sign
sign_entry_T *sign; // a sign in a b_signlist
@@ -580,30 +582,30 @@ linenr_T buf_delsign(
/// Find the line number of the sign with the requested id in group 'group'. If
/// the sign does not exist, return 0 as the line number. This will still let
/// the correct file get loaded.
-int buf_findsign(
- buf_T *buf, // buffer to store sign in
- int id, // sign ID
- char_u *group // sign group
-)
+///
+/// @param buf buffer to store sign in
+/// @param id sign ID
+/// @param group sign group
+int buf_findsign(buf_T *buf, int id, char_u *group)
{
- sign_entry_T *sign; // a sign in the signlist
+ sign_entry_T *sign; // a sign in the signlist
- FOR_ALL_SIGNS_IN_BUF(buf, sign) {
- if (sign->se_id == id && sign_in_group(sign, group)) {
- return (int)sign->se_lnum;
- }
+ FOR_ALL_SIGNS_IN_BUF(buf, sign) {
+ if (sign->se_id == id && sign_in_group(sign, group)) {
+ return (int)sign->se_lnum;
}
+ }
- return 0;
+ return 0;
}
/// Return the sign at line 'lnum' in buffer 'buf'. Returns NULL if a sign is
/// not found at the line. If 'groupname' is NULL, searches in the global group.
-static sign_entry_T * buf_getsign_at_line(
- buf_T *buf, // buffer whose sign we are searching for
- linenr_T lnum, // line number of sign
- char_u *groupname // sign group name
-)
+///
+/// @param buf buffer whose sign we are searching for
+/// @param lnum line number of sign
+/// @param groupname sign group name
+static sign_entry_T *buf_getsign_at_line(buf_T *buf, linenr_T lnum, char_u *groupname)
{
sign_entry_T *sign; // a sign in the signlist
@@ -623,61 +625,61 @@ static sign_entry_T * buf_getsign_at_line(
}
/// Return the identifier of the sign at line number 'lnum' in buffer 'buf'.
-int buf_findsign_id(
- buf_T *buf, // buffer whose sign we are searching for
- linenr_T lnum, // line number of sign
- char_u *groupname // sign group name
-)
+///
+/// @param buf buffer whose sign we are searching for
+/// @param lnum line number of sign
+/// @param groupname sign group name
+int buf_findsign_id(buf_T *buf, linenr_T lnum, char_u *groupname)
{
- sign_entry_T *sign; // a sign in the signlist
+ sign_entry_T *sign; // a sign in the signlist
- sign = buf_getsign_at_line(buf, lnum, groupname);
- if (sign != NULL) {
- return sign->se_id;
- }
+ sign = buf_getsign_at_line(buf, lnum, groupname);
+ if (sign != NULL) {
+ return sign->se_id;
+ }
- return 0;
+ return 0;
}
/// Delete signs in buffer "buf".
void buf_delete_signs(buf_T *buf, char_u *group)
{
- sign_entry_T *sign;
- sign_entry_T **lastp; // pointer to pointer to current sign
- sign_entry_T *next;
+ sign_entry_T *sign;
+ sign_entry_T **lastp; // pointer to pointer to current sign
+ sign_entry_T *next;
- // When deleting the last sign need to redraw the windows to remove the
- // sign column. Not when curwin is NULL (this means we're exiting).
- if (buf->b_signlist != NULL && curwin != NULL) {
- changed_line_abv_curs();
- }
+ // When deleting the last sign need to redraw the windows to remove the
+ // sign column. Not when curwin is NULL (this means we're exiting).
+ if (buf->b_signlist != NULL && curwin != NULL) {
+ changed_line_abv_curs();
+ }
- lastp = &buf->b_signlist;
- for (sign = buf->b_signlist; sign != NULL; sign = next) {
- next = sign->se_next;
- if (sign_in_group(sign, group)) {
- *lastp = next;
- if (next != NULL) {
- next->se_prev = sign->se_prev;
- }
- if (sign->se_group != NULL) {
- sign_group_unref(sign->se_group->sg_name);
- }
- xfree(sign);
- } else {
- lastp = &sign->se_next;
+ lastp = &buf->b_signlist;
+ for (sign = buf->b_signlist; sign != NULL; sign = next) {
+ next = sign->se_next;
+ if (sign_in_group(sign, group)) {
+ *lastp = next;
+ if (next != NULL) {
+ next->se_prev = sign->se_prev;
+ }
+ if (sign->se_group != NULL) {
+ sign_group_unref(sign->se_group->sg_name);
}
+ xfree(sign);
+ } else {
+ lastp = &sign->se_next;
}
- buf->b_signcols_valid = false;
+ }
+ buf->b_signcols_valid = false;
}
/// List placed signs for "rbuf". If "rbuf" is NULL do it for all buffers.
void sign_list_placed(buf_T *rbuf, char_u *sign_group)
{
buf_T *buf;
- sign_entry_T *sign;
- char lbuf[MSG_BUF_LEN];
- char group[MSG_BUF_LEN];
+ sign_entry_T *sign;
+ char lbuf[MSG_BUF_LEN];
+ char group[MSG_BUF_LEN];
MSG_PUTS_TITLE(_("\n--- Signs ---"));
msg_putchar('\n');
@@ -720,12 +722,7 @@ void sign_list_placed(buf_T *rbuf, char_u *sign_group)
}
/// Adjust a placed sign for inserted/deleted lines.
-void sign_mark_adjust(
- linenr_T line1,
- linenr_T line2,
- long amount,
- long amount_after
-)
+void sign_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after)
{
sign_entry_T *sign; // a sign in a b_signlist
sign_entry_T *next; // the next sign in a b_signlist
@@ -769,26 +766,26 @@ void sign_mark_adjust(
/// Find index of a ":sign" subcmd from its name.
/// "*end_cmd" must be writable.
-static int sign_cmd_idx(
- char_u *begin_cmd, // begin of sign subcmd
- char_u *end_cmd // just after sign subcmd
-)
+///
+/// @param begin_cmd begin of sign subcmd
+/// @param end_cmd just after sign subcmd
+static int sign_cmd_idx(char_u *begin_cmd, char_u *end_cmd)
{
- int idx;
- char_u save = *end_cmd;
+ int idx;
+ char_u save = *end_cmd;
- *end_cmd = (char_u)NUL;
- for (idx = 0; ; idx++) {
- if (cmds[idx] == NULL || STRCMP(begin_cmd, cmds[idx]) == 0) {
- break;
- }
+ *end_cmd = (char_u)NUL;
+ for (idx = 0; ; idx++) {
+ if (cmds[idx] == NULL || STRCMP(begin_cmd, cmds[idx]) == 0) {
+ break;
}
- *end_cmd = save;
- return idx;
+ }
+ *end_cmd = save;
+ return idx;
}
/// Find a sign by name. Also returns pointer to the previous sign.
-static sign_T * sign_find(const char_u *name, sign_T **sp_prev)
+static sign_T *sign_find(const char_u *name, sign_T **sp_prev)
{
sign_T *sp;
@@ -808,10 +805,10 @@ static sign_T * sign_find(const char_u *name, sign_T **sp_prev)
}
/// Allocate a new sign
-static sign_T * alloc_new_sign(char_u *name)
+static sign_T *alloc_new_sign(char_u *name)
{
- sign_T *sp;
- sign_T *lp;
+ sign_T *sp;
+ sign_T *lp;
int start = next_sign_typenr;
// Allocate a new sign.
@@ -858,8 +855,8 @@ static void sign_define_init_icon(sign_T *sp, char_u *icon)
/// Initialize the text for a new sign
static int sign_define_init_text(sign_T *sp, char_u *text)
{
- char_u *s;
- char_u *endp;
+ char_u *s;
+ char_u *endp;
int cells;
size_t len;
@@ -904,17 +901,11 @@ static int sign_define_init_text(sign_T *sp, char_u *text)
}
/// Define a new sign or update an existing sign
-int sign_define_by_name(
- char_u *name,
- char_u *icon,
- char_u *linehl,
- char_u *text,
- char_u *texthl,
- char_u *numhl
-)
+int sign_define_by_name(char_u *name, char_u *icon, char_u *linehl, char_u *text, char_u *texthl,
+ char_u *numhl)
{
- sign_T *sp_prev;
- sign_T *sp;
+ sign_T *sp_prev;
+ sign_T *sp;
sp = sign_find(name, &sp_prev);
if (sp == NULL) {
@@ -966,8 +957,8 @@ int sign_define_by_name(
/// Free the sign specified by 'name'.
int sign_undefine_by_name(const char_u *name)
{
- sign_T *sp_prev;
- sign_T *sp;
+ sign_T *sp_prev;
+ sign_T *sp;
sp = sign_find(name, &sp_prev);
if (sp == NULL) {
@@ -982,18 +973,18 @@ int sign_undefine_by_name(const char_u *name)
static void may_force_numberwidth_recompute(buf_T *buf, int unplace)
{
FOR_ALL_TAB_WINDOWS(tp, wp)
- if (wp->w_buffer == buf
- && (wp->w_p_nu || wp->w_p_rnu)
- && (unplace || wp->w_nrwidth_width < 2)
- && (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')) {
- wp->w_nrwidth_line_count = 0;
- }
+ if (wp->w_buffer == buf
+ && (wp->w_p_nu || wp->w_p_rnu)
+ && (unplace || wp->w_nrwidth_width < 2)
+ && (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')) {
+ wp->w_nrwidth_line_count = 0;
+ }
}
/// List the signs matching 'name'
static void sign_list_by_name(char_u *name)
{
- sign_T *sp;
+ sign_T *sp;
sp = sign_find(name, NULL);
if (sp != NULL) {
@@ -1005,14 +996,8 @@ static void sign_list_by_name(char_u *name)
/// Place a sign at the specified file location or update a sign.
-int sign_place(
- int *sign_id,
- const char_u *sign_group,
- const char_u *sign_name,
- buf_T *buf,
- linenr_T lnum,
- int prio
-)
+int sign_place(int *sign_id, const char_u *sign_group, const char_u *sign_name, buf_T *buf,
+ linenr_T lnum, int prio)
{
sign_T *sp;
@@ -1038,14 +1023,13 @@ int sign_place(
// ":sign place {id} line={lnum} name={name} file={fname}":
// place a sign
bool has_text_or_icon = sp->sn_text != NULL || sp->sn_icon != NULL;
- buf_addsign(
- buf,
- *sign_id,
- sign_group,
- prio,
- lnum,
- sp->sn_typenr,
- has_text_or_icon);
+ buf_addsign(buf,
+ *sign_id,
+ sign_group,
+ prio,
+ lnum,
+ sp->sn_typenr,
+ has_text_or_icon);
} else {
// ":sign place {id} file={fname}": change sign type and/or priority
lnum = buf_change_sign_type(buf, *sign_id, sign_group, sp->sn_typenr, prio);
@@ -1075,7 +1059,7 @@ int sign_unplace(int sign_id, char_u *sign_group, buf_T *buf, linenr_T atlnum)
redraw_buf_later(buf, NOT_VALID);
buf_delete_signs(buf, sign_group);
} else {
- linenr_T lnum;
+ linenr_T lnum;
// Delete only the specified signs
lnum = buf_delsign(buf, atlnum, sign_id, sign_group);
@@ -1098,7 +1082,7 @@ int sign_unplace(int sign_id, char_u *sign_group, buf_T *buf, linenr_T atlnum)
/// Unplace the sign at the current cursor line.
static void sign_unplace_at_cursor(char_u *groupname)
{
- int id = -1;
+ int id = -1;
id = buf_findsign_id(curwin->w_buffer, curwin->w_cursor.lnum, groupname);
if (id > 0) {
@@ -1144,13 +1128,13 @@ linenr_T sign_jump(int sign_id, char_u *sign_group, buf_T *buf)
/// ":sign define {name} ..." command
static void sign_define_cmd(char_u *sign_name, char_u *cmdline)
{
- char_u *arg;
- char_u *p = cmdline;
- char_u *icon = NULL;
- char_u *text = NULL;
- char_u *linehl = NULL;
- char_u *texthl = NULL;
- char_u *numhl = NULL;
+ char_u *arg;
+ char_u *p = cmdline;
+ char_u *icon = NULL;
+ char_u *text = NULL;
+ char_u *linehl = NULL;
+ char_u *texthl = NULL;
+ char_u *numhl = NULL;
int failed = false;
// set values for a defined sign.
@@ -1194,14 +1178,8 @@ static void sign_define_cmd(char_u *sign_name, char_u *cmdline)
}
/// ":sign place" command
-static void sign_place_cmd(
- buf_T *buf,
- linenr_T lnum,
- char_u *sign_name,
- int id,
- char_u *group,
- int prio
-)
+static void sign_place_cmd(buf_T *buf, linenr_T lnum, char_u *sign_name, int id, char_u *group,
+ int prio)
{
if (id <= 0) {
// List signs placed in a file/buffer
@@ -1233,62 +1211,56 @@ static void sign_place_cmd(
}
/// ":sign unplace" command
-static void sign_unplace_cmd(
- buf_T *buf,
- linenr_T lnum,
- char_u *sign_name,
- int id,
- char_u *group
-)
+static void sign_unplace_cmd(buf_T *buf, linenr_T lnum, char_u *sign_name, int id, char_u *group)
{
- if (lnum >= 0 || sign_name != NULL || (group != NULL && *group == '\0')) {
- EMSG(_(e_invarg));
- return;
- }
+ if (lnum >= 0 || sign_name != NULL || (group != NULL && *group == '\0')) {
+ EMSG(_(e_invarg));
+ return;
+ }
- if (id == -2) {
- if (buf != NULL) {
- // :sign unplace * file={fname}
- // :sign unplace * group={group} file={fname}
- // :sign unplace * group=* file={fname}
- // :sign unplace * buffer={nr}
- // :sign unplace * group={group} buffer={nr}
- // :sign unplace * group=* buffer={nr}
- sign_unplace(0, group, buf, 0);
- } else {
- // :sign unplace *
- // :sign unplace * group={group}
- // :sign unplace * group=*
- FOR_ALL_BUFFERS(cbuf) {
- if (cbuf->b_signlist != NULL) {
- buf_delete_signs(cbuf, group);
- }
+ if (id == -2) {
+ if (buf != NULL) {
+ // :sign unplace * file={fname}
+ // :sign unplace * group={group} file={fname}
+ // :sign unplace * group=* file={fname}
+ // :sign unplace * buffer={nr}
+ // :sign unplace * group={group} buffer={nr}
+ // :sign unplace * group=* buffer={nr}
+ sign_unplace(0, group, buf, 0);
+ } else {
+ // :sign unplace *
+ // :sign unplace * group={group}
+ // :sign unplace * group=*
+ FOR_ALL_BUFFERS(cbuf) {
+ if (cbuf->b_signlist != NULL) {
+ buf_delete_signs(cbuf, group);
}
}
+ }
+ } else {
+ if (buf != NULL) {
+ // :sign unplace {id} file={fname}
+ // :sign unplace {id} group={group} file={fname}
+ // :sign unplace {id} group=* file={fname}
+ // :sign unplace {id} buffer={nr}
+ // :sign unplace {id} group={group} buffer={nr}
+ // :sign unplace {id} group=* buffer={nr}
+ sign_unplace(id, group, buf, 0);
} else {
- if (buf != NULL) {
- // :sign unplace {id} file={fname}
- // :sign unplace {id} group={group} file={fname}
- // :sign unplace {id} group=* file={fname}
- // :sign unplace {id} buffer={nr}
- // :sign unplace {id} group={group} buffer={nr}
- // :sign unplace {id} group=* buffer={nr}
- sign_unplace(id, group, buf, 0);
+ if (id == -1) {
+ // :sign unplace group={group}
+ // :sign unplace group=*
+ sign_unplace_at_cursor(group);
} else {
- if (id == -1) {
- // :sign unplace group={group}
- // :sign unplace group=*
- sign_unplace_at_cursor(group);
- } else {
- // :sign unplace {id}
- // :sign unplace {id} group={group}
- // :sign unplace {id} group=*
- FOR_ALL_BUFFERS(cbuf) {
- sign_unplace(id, group, cbuf, 0);
- }
+ // :sign unplace {id}
+ // :sign unplace {id} group={group}
+ // :sign unplace {id} group=*
+ FOR_ALL_BUFFERS(cbuf) {
+ sign_unplace(id, group, cbuf, 0);
}
}
}
+ }
}
/// Jump to a placed sign commands:
@@ -1296,13 +1268,7 @@ static void sign_unplace_cmd(
/// :sign jump {id} buffer={nr}
/// :sign jump {id} group={group} file={fname}
/// :sign jump {id} group={group} buffer={nr}
-static void sign_jump_cmd(
- buf_T *buf,
- linenr_T lnum,
- char_u *sign_name,
- int id,
- char_u *group
-)
+static void sign_jump_cmd(buf_T *buf, linenr_T lnum, char_u *sign_name, int id, char_u *group)
{
if (sign_name == NULL && group == NULL && id == -1) {
EMSG(_(e_argreq));
@@ -1324,21 +1290,13 @@ static void sign_jump_cmd(
/// ":sign jump" commands.
/// The supported arguments are: line={lnum} name={name} group={group}
/// priority={prio} and file={fname} or buffer={nr}.
-static int parse_sign_cmd_args(
- int cmd,
- char_u *arg,
- char_u **sign_name,
- int *signid,
- char_u **group,
- int *prio,
- buf_T **buf,
- linenr_T *lnum
-)
+static int parse_sign_cmd_args(int cmd, char_u *arg, char_u **sign_name, int *signid,
+ char_u **group, int *prio, buf_T **buf, linenr_T *lnum)
{
- char_u *arg1;
- char_u *name;
- char_u *filename = NULL;
- int lnum_arg = false;
+ char_u *arg1;
+ char_u *name;
+ char_u *filename = NULL;
+ int lnum_arg = false;
// first arg could be placed sign id
arg1 = arg;
@@ -1448,7 +1406,7 @@ void ex_sign(exarg_T *eap)
} else if (*arg == NUL) {
EMSG(_("E156: Missing sign name"));
} else {
- char_u *name;
+ char_u *name;
// Isolate the sign name. If it's a number skip leading zeroes,
// so that "099" and "99" are the same sign. But keep "0".
@@ -1574,12 +1532,8 @@ list_T *get_buffer_signs(buf_T *buf)
}
/// Return information about all the signs placed in a buffer
-static void sign_get_placed_in_buf(
- buf_T *buf,
- linenr_T lnum,
- int sign_id,
- const char_u *sign_group,
- list_T *retlist)
+static void sign_get_placed_in_buf(buf_T *buf, linenr_T lnum, int sign_id, const char_u *sign_group,
+ list_T *retlist)
{
dict_T *d;
list_T *l;
@@ -1609,13 +1563,8 @@ static void sign_get_placed_in_buf(
/// Get a list of signs placed in buffer 'buf'. If 'num' is non-zero, return the
/// sign placed at the line number. If 'lnum' is zero, return all the signs
/// placed in 'buf'. If 'buf' is NULL, return signs placed in all the buffers.
-void sign_get_placed(
- buf_T *buf,
- linenr_T lnum,
- int sign_id,
- const char_u *sign_group,
- list_T *retlist
-)
+void sign_get_placed(buf_T *buf, linenr_T lnum, int sign_id, const char_u *sign_group,
+ list_T *retlist)
{
if (buf != NULL) {
sign_get_placed_in_buf(buf, lnum, sign_id, sign_group, retlist);
@@ -1697,13 +1646,13 @@ void free_signs(void)
static enum
{
- EXP_SUBCMD, // expand :sign sub-commands
- EXP_DEFINE, // expand :sign define {name} args
- EXP_PLACE, // expand :sign place {id} args
- EXP_LIST, // expand :sign place args
- EXP_UNPLACE, // expand :sign unplace"
- EXP_SIGN_NAMES, // expand with name of placed signs
- EXP_SIGN_GROUPS, // expand with name of placed sign groups
+ EXP_SUBCMD, // expand :sign sub-commands
+ EXP_DEFINE, // expand :sign define {name} args
+ EXP_PLACE, // expand :sign place {id} args
+ EXP_LIST, // expand :sign place args
+ EXP_UNPLACE, // expand :sign unplace"
+ EXP_SIGN_NAMES, // expand with name of placed signs
+ EXP_SIGN_GROUPS, // expand with name of placed sign groups
} expand_what;
// Return the n'th sign name (used for command line completion)
@@ -1740,45 +1689,45 @@ static char_u *get_nth_sign_group_name(int idx)
/// Function given to ExpandGeneric() to obtain the sign command
/// expansion.
-char_u * get_sign_name(expand_T *xp, int idx)
+char_u *get_sign_name(expand_T *xp, int idx)
{
switch (expand_what) {
- case EXP_SUBCMD:
- return (char_u *)cmds[idx];
- case EXP_DEFINE: {
- char *define_arg[] = { "icon=", "linehl=", "text=", "texthl=", "numhl=",
- NULL };
- return (char_u *)define_arg[idx];
- }
- case EXP_PLACE: {
- char *place_arg[] = { "line=", "name=", "group=", "priority=", "file=",
- "buffer=", NULL };
- return (char_u *)place_arg[idx];
- }
- case EXP_LIST: {
- char *list_arg[] = { "group=", "file=", "buffer=", NULL };
- return (char_u *)list_arg[idx];
- }
- case EXP_UNPLACE: {
- char *unplace_arg[] = { "group=", "file=", "buffer=", NULL };
- return (char_u *)unplace_arg[idx];
- }
- case EXP_SIGN_NAMES:
- return get_nth_sign_name(idx);
- case EXP_SIGN_GROUPS:
- return get_nth_sign_group_name(idx);
- default:
- return NULL;
+ case EXP_SUBCMD:
+ return (char_u *)cmds[idx];
+ case EXP_DEFINE: {
+ char *define_arg[] = { "icon=", "linehl=", "text=", "texthl=", "numhl=",
+ NULL };
+ return (char_u *)define_arg[idx];
+ }
+ case EXP_PLACE: {
+ char *place_arg[] = { "line=", "name=", "group=", "priority=", "file=",
+ "buffer=", NULL };
+ return (char_u *)place_arg[idx];
+ }
+ case EXP_LIST: {
+ char *list_arg[] = { "group=", "file=", "buffer=", NULL };
+ return (char_u *)list_arg[idx];
+ }
+ case EXP_UNPLACE: {
+ char *unplace_arg[] = { "group=", "file=", "buffer=", NULL };
+ return (char_u *)unplace_arg[idx];
+ }
+ case EXP_SIGN_NAMES:
+ return get_nth_sign_name(idx);
+ case EXP_SIGN_GROUPS:
+ return get_nth_sign_group_name(idx);
+ default:
+ return NULL;
}
}
/// Handle command line completion for :sign command.
void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
{
- char_u *end_subcmd;
- char_u *last;
- int cmd_idx;
- char_u *begin_subcmd_args;
+ char_u *end_subcmd;
+ char_u *last;
+ int cmd_idx;
+ char_u *begin_subcmd_args;
// Default: expand subcommands.
xp->xp_context = EXPAND_SIGN;
@@ -1822,70 +1771,70 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
// Expand last argument name (before equal sign).
xp->xp_pattern = last;
switch (cmd_idx) {
- case SIGNCMD_DEFINE:
- expand_what = EXP_DEFINE;
- break;
- case SIGNCMD_PLACE:
- // List placed signs
- if (ascii_isdigit(*begin_subcmd_args)) {
- // :sign place {id} {args}...
- expand_what = EXP_PLACE;
- } else {
- // :sign place {args}...
- expand_what = EXP_LIST;
- }
- break;
- case SIGNCMD_LIST:
- case SIGNCMD_UNDEFINE:
- // :sign list <CTRL-D>
- // :sign undefine <CTRL-D>
- expand_what = EXP_SIGN_NAMES;
- break;
- case SIGNCMD_JUMP:
- case SIGNCMD_UNPLACE:
- expand_what = EXP_UNPLACE;
- break;
- default:
- xp->xp_context = EXPAND_NOTHING;
+ case SIGNCMD_DEFINE:
+ expand_what = EXP_DEFINE;
+ break;
+ case SIGNCMD_PLACE:
+ // List placed signs
+ if (ascii_isdigit(*begin_subcmd_args)) {
+ // :sign place {id} {args}...
+ expand_what = EXP_PLACE;
+ } else {
+ // :sign place {args}...
+ expand_what = EXP_LIST;
+ }
+ break;
+ case SIGNCMD_LIST:
+ case SIGNCMD_UNDEFINE:
+ // :sign list <CTRL-D>
+ // :sign undefine <CTRL-D>
+ expand_what = EXP_SIGN_NAMES;
+ break;
+ case SIGNCMD_JUMP:
+ case SIGNCMD_UNPLACE:
+ expand_what = EXP_UNPLACE;
+ break;
+ default:
+ xp->xp_context = EXPAND_NOTHING;
}
} else {
- // Expand last argument value (after equal sign).
+ // Expand last argument value (after equal sign).
xp->xp_pattern = p + 1;
switch (cmd_idx) {
- case SIGNCMD_DEFINE:
- if (STRNCMP(last, "texthl", 6) == 0
- || STRNCMP(last, "linehl", 6) == 0
- || STRNCMP(last, "numhl", 5) == 0) {
- xp->xp_context = EXPAND_HIGHLIGHT;
- } else if (STRNCMP(last, "icon", 4) == 0) {
- xp->xp_context = EXPAND_FILES;
- } else {
- xp->xp_context = EXPAND_NOTHING;
- }
- break;
- case SIGNCMD_PLACE:
- if (STRNCMP(last, "name", 4) == 0) {
- expand_what = EXP_SIGN_NAMES;
- } else if (STRNCMP(last, "group", 5) == 0) {
- expand_what = EXP_SIGN_GROUPS;
- } else if (STRNCMP(last, "file", 4) == 0) {
- xp->xp_context = EXPAND_BUFFERS;
- } else {
- xp->xp_context = EXPAND_NOTHING;
- }
- break;
- case SIGNCMD_UNPLACE:
- case SIGNCMD_JUMP:
- if (STRNCMP(last, "group", 5) == 0) {
- expand_what = EXP_SIGN_GROUPS;
- } else if (STRNCMP(last, "file", 4) == 0) {
- xp->xp_context = EXPAND_BUFFERS;
- } else {
- xp->xp_context = EXPAND_NOTHING;
- }
- break;
- default:
+ case SIGNCMD_DEFINE:
+ if (STRNCMP(last, "texthl", 6) == 0
+ || STRNCMP(last, "linehl", 6) == 0
+ || STRNCMP(last, "numhl", 5) == 0) {
+ xp->xp_context = EXPAND_HIGHLIGHT;
+ } else if (STRNCMP(last, "icon", 4) == 0) {
+ xp->xp_context = EXPAND_FILES;
+ } else {
xp->xp_context = EXPAND_NOTHING;
+ }
+ break;
+ case SIGNCMD_PLACE:
+ if (STRNCMP(last, "name", 4) == 0) {
+ expand_what = EXP_SIGN_NAMES;
+ } else if (STRNCMP(last, "group", 5) == 0) {
+ expand_what = EXP_SIGN_GROUPS;
+ } else if (STRNCMP(last, "file", 4) == 0) {
+ xp->xp_context = EXPAND_BUFFERS;
+ } else {
+ xp->xp_context = EXPAND_NOTHING;
+ }
+ break;
+ case SIGNCMD_UNPLACE:
+ case SIGNCMD_JUMP:
+ if (STRNCMP(last, "group", 5) == 0) {
+ expand_what = EXP_SIGN_GROUPS;
+ } else if (STRNCMP(last, "file", 4) == 0) {
+ xp->xp_context = EXPAND_BUFFERS;
+ } else {
+ xp->xp_context = EXPAND_NOTHING;
+ }
+ break;
+ default:
+ xp->xp_context = EXPAND_NOTHING;
}
}
}
@@ -1914,11 +1863,11 @@ int sign_define_from_dict(const char *name_arg, dict_T *dict)
goto cleanup;
}
if (dict != NULL) {
- icon = tv_dict_get_string(dict, "icon" , true);
+ icon = tv_dict_get_string(dict, "icon", true);
linehl = tv_dict_get_string(dict, "linehl", true);
- text = tv_dict_get_string(dict, "text" , true);
+ text = tv_dict_get_string(dict, "text", true);
texthl = tv_dict_get_string(dict, "texthl", true);
- numhl = tv_dict_get_string(dict, "numhl" , true);
+ numhl = tv_dict_get_string(dict, "numhl", true);
}
if (sign_define_by_name((char_u *)name, (char_u *)icon, (char_u *)linehl,
@@ -1942,27 +1891,23 @@ cleanup:
/// values in 'retlist'.
void sign_define_multiple(list_T *l, list_T *retlist)
{
- int retval;
+ int retval;
- TV_LIST_ITER_CONST(l, li, {
- retval = -1;
- if (TV_LIST_ITEM_TV(li)->v_type == VAR_DICT) {
- retval = sign_define_from_dict(NULL, TV_LIST_ITEM_TV(li)->vval.v_dict);
- } else {
- EMSG(_(e_dictreq));
- }
- tv_list_append_number(retlist, retval);
- });
+ TV_LIST_ITER_CONST(l, li, {
+ retval = -1;
+ if (TV_LIST_ITEM_TV(li)->v_type == VAR_DICT) {
+ retval = sign_define_from_dict(NULL, TV_LIST_ITEM_TV(li)->vval.v_dict);
+ } else {
+ EMSG(_(e_dictreq));
+ }
+ tv_list_append_number(retlist, retval);
+ });
}
/// Place a new sign using the values specified in dict 'dict'. Returns the sign
/// identifier if successfully placed, otherwise returns 0.
-int sign_place_from_dict(
- typval_T *id_tv,
- typval_T *group_tv,
- typval_T *name_tv,
- typval_T *buf_tv,
- dict_T *dict)
+int sign_place_from_dict(typval_T *id_tv, typval_T *group_tv, typval_T *name_tv, typval_T *buf_tv,
+ dict_T *dict)
{
int sign_id = 0;
char_u *group = NULL;
diff --git a/src/nvim/state.c b/src/nvim/state.c
index 02d63d8ab1..a9f3d67849 100644
--- a/src/nvim/state.c
+++ b/src/nvim/state.c
@@ -3,19 +3,18 @@
#include <assert.h>
-#include "nvim/lib/kvec.h"
-
#include "nvim/ascii.h"
+#include "nvim/edit.h"
+#include "nvim/ex_docmd.h"
+#include "nvim/getchar.h"
+#include "nvim/lib/kvec.h"
#include "nvim/log.h"
-#include "nvim/state.h"
-#include "nvim/vim.h"
#include "nvim/main.h"
-#include "nvim/getchar.h"
#include "nvim/option_defs.h"
-#include "nvim/ui.h"
#include "nvim/os/input.h"
-#include "nvim/ex_docmd.h"
-#include "nvim/edit.h"
+#include "nvim/state.h"
+#include "nvim/ui.h"
+#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "state.c.generated.h"
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 559a7380eb..760c7c0ecc 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -1703,7 +1703,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con
regmmatch_T regmatch;
lpos_T pos;
reg_extmatch_T *cur_extmatch = NULL;
- char_u buf_chartab[32]; // chartab array for syn iskeyword
+ char_u buf_chartab[32]; // chartab array for syn iskeyword
char_u *line; // current line. NOTE: becomes invalid after
// looking for a pattern match!
@@ -5654,7 +5654,7 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in
struct subcommand {
char *name; // subcommand name
- void (*func)(exarg_T *, int); // function to call
+ void (*func)(exarg_T *, int); // function to call
};
static struct subcommand subcommands[] =
diff --git a/src/uncrustify.cfg b/src/uncrustify.cfg
index 08296a644a..821fbca3fc 100644
--- a/src/uncrustify.cfg
+++ b/src/uncrustify.cfg
@@ -1,4 +1,4 @@
-# Uncrustify-0.73.0-168-f20a083e
+# Uncrustify-0.73.0-181-847f1e99
#
# General options
@@ -259,7 +259,7 @@ sp_before_byref_func = ignore # ignore/add/remove/force/not_defined
# following word.
#
# Default: force
-sp_after_type = ignore # ignore/add/remove/force/not_defined
+sp_after_type = force # ignore/add/remove/force/not_defined
# Add or remove space between 'decltype(...)' and word,
# brace or function call.
@@ -447,12 +447,18 @@ sp_before_ellipsis = ignore # ignore/add/remove/force/not_defined
# Add or remove space between a type and '...'.
sp_type_ellipsis = ignore # ignore/add/remove/force/not_defined
+# Add or remove space between a '*' and '...'.
+sp_ptr_type_ellipsis = ignore # ignore/add/remove/force/not_defined
+
# (D) Add or remove space between a type and '?'.
sp_type_question = ignore # ignore/add/remove/force/not_defined
# Add or remove space between ')' and '...'.
sp_paren_ellipsis = ignore # ignore/add/remove/force/not_defined
+# Add or remove space between '&&' and '...'.
+sp_byref_ellipsis = ignore # ignore/add/remove/force/not_defined
+
# Add or remove space between ')' and a qualifier such as 'const'.
sp_paren_qualifier = ignore # ignore/add/remove/force/not_defined
@@ -507,6 +513,12 @@ sp_sizeof_ellipsis = ignore # ignore/add/remove/force/not_defined
# Add or remove space between 'sizeof...' and '('.
sp_sizeof_ellipsis_paren = ignore # ignore/add/remove/force/not_defined
+# Add or remove space between '...' and a parameter pack.
+sp_ellipsis_parameter_pack = ignore # ignore/add/remove/force/not_defined
+
+# Add or remove space between a parameter pack and '...'.
+sp_parameter_pack_ellipsis = ignore # ignore/add/remove/force/not_defined
+
# Add or remove space between 'decltype' and '('.
sp_decltype_paren = ignore # ignore/add/remove/force/not_defined
@@ -2020,7 +2032,7 @@ nl_constr_colon = ignore # ignore/add/remove/force/not_defined
# Whether to collapse a two-line namespace, like 'namespace foo\n{ decl; }'
# into a single line. If true, prevents other brace newline rules from turning
-# such code into four lines.
+# such code into four lines. If true, it also preserves one-liner namespaces.
nl_namespace_two_to_one_liner = false # true/false
# Whether to remove a newline in simple unbraced if statements, turning them
@@ -3279,5 +3291,5 @@ set PREPROC REAL_FATTR_CONST
set PREPROC REAL_FATTR_NONNULL_ALL
set PREPROC REAL_FATTR_PURE
set PREPROC REAL_FATTR_WARN_UNUSED_RESULT
-# option(s) with 'not default' value: 62
+# option(s) with 'not default' value: 61
#