aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordundargoc <33953936+dundargoc@users.noreply.github.com>2021-09-22 15:25:38 +0200
committerGitHub <noreply@github.com>2021-09-22 06:25:38 -0700
commit48e67b229415b4e2b3315bd00b817e5f9ab970c8 (patch)
tree334596ac20fa458d3966e9dbc5ed7f2478ccbafa
parentfb6f27e86f2ca2fbff88737251d9e26016a62081 (diff)
downloadrneovim-48e67b229415b4e2b3315bd00b817e5f9ab970c8.tar.gz
rneovim-48e67b229415b4e2b3315bd00b817e5f9ab970c8.tar.bz2
rneovim-48e67b229415b4e2b3315bd00b817e5f9ab970c8.zip
refactor: format with uncrustify #15741
-rw-r--r--src/nvim/main.c843
-rw-r--r--src/nvim/map.c16
-rw-r--r--src/nvim/mark.c526
-rw-r--r--src/nvim/marktree.c41
-rw-r--r--src/nvim/math.c10
-rw-r--r--src/nvim/memfile.c116
-rw-r--r--src/nvim/memline.c1500
-rw-r--r--src/nvim/memory.c90
-rw-r--r--src/nvim/menu.c476
-rw-r--r--src/nvim/message.c613
-rw-r--r--src/nvim/misc1.c261
-rw-r--r--src/nvim/mouse.c150
-rw-r--r--src/nvim/move.c373
13 files changed, 2638 insertions, 2377 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 99d8a03381..d977589ad7 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -3,25 +3,22 @@
#define EXTERN
#include <assert.h>
+#include <msgpack.h>
+#include <stdbool.h>
#include <stdint.h>
#include <string.h>
-#include <stdbool.h>
-
-#include <msgpack.h>
#include "nvim/ascii.h"
-#include "nvim/channel.h"
-#include "nvim/vim.h"
-#include "nvim/main.h"
#include "nvim/aucmd.h"
#include "nvim/buffer.h"
+#include "nvim/channel.h"
#include "nvim/charset.h"
+#include "nvim/decoration.h"
#include "nvim/diff.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
-#include "nvim/decoration.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
@@ -30,29 +27,36 @@
#include "nvim/iconv.h"
#include "nvim/if_cscope.h"
#include "nvim/lua/executor.h"
+#include "nvim/main.h"
+#include "nvim/vim.h"
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
+#include "nvim/garray.h"
+#include "nvim/log.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
+#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/garray.h"
-#include "nvim/log.h"
-#include "nvim/memory.h"
-#include "nvim/move.h"
#include "nvim/mouse.h"
+#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/ops.h"
#include "nvim/option.h"
-#include "nvim/os_unix.h"
+#include "nvim/os/fileio.h"
+#include "nvim/os/input.h"
+#include "nvim/os/os.h"
#include "nvim/os/os_defs.h"
+#include "nvim/os/time.h"
+#include "nvim/os_unix.h"
#include "nvim/path.h"
-#include "nvim/profile.h"
#include "nvim/popupmnu.h"
+#include "nvim/profile.h"
#include "nvim/quickfix.h"
#include "nvim/screen.h"
+#include "nvim/shada.h"
#include "nvim/sign.h"
#include "nvim/state.h"
#include "nvim/strings.h"
@@ -61,24 +65,19 @@
#include "nvim/ui_compositor.h"
#include "nvim/version.h"
#include "nvim/window.h"
-#include "nvim/shada.h"
-#include "nvim/os/input.h"
-#include "nvim/os/os.h"
-#include "nvim/os/time.h"
-#include "nvim/os/fileio.h"
#ifdef WIN32
# include "nvim/os/os_win_console.h"
#endif
+#include "nvim/api/private/defs.h"
+#include "nvim/api/private/dispatch.h"
+#include "nvim/api/private/helpers.h"
+#include "nvim/api/ui.h"
#include "nvim/event/loop.h"
-#include "nvim/os/signal.h"
#include "nvim/event/process.h"
+#include "nvim/msgpack_rpc/channel.h"
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/msgpack_rpc/server.h"
-#include "nvim/msgpack_rpc/channel.h"
-#include "nvim/api/ui.h"
-#include "nvim/api/private/defs.h"
-#include "nvim/api/private/helpers.h"
-#include "nvim/api/private/dispatch.h"
+#include "nvim/os/signal.h"
#ifndef WIN32
# include "nvim/os/pty_process_unix.h"
#endif
@@ -278,9 +277,9 @@ int main(int argc, char **argv)
TIME_MSG("expanding arguments");
- if (params.diff_mode && params.window_count == -1)
- params.window_count = 0; /* open up to 3 windows */
-
+ if (params.diff_mode && params.window_count == -1) {
+ params.window_count = 0; // open up to 3 windows
+ }
// Don't redraw until much later.
RedrawingDisabled++;
@@ -586,15 +585,16 @@ void getout(int exitval)
/* When running in Ex mode an error causes us to exit with a non-zero exit
* code. POSIX requires this, although it's not 100% clear from the
* standard. */
- if (exmode_active)
+ if (exmode_active) {
exitval += ex_exitval;
+ }
set_vim_var_nr(VV_EXITING, exitval);
// Position the cursor on the last screen line, below all the text
ui_cursor_goto(Rows - 1, 0);
- /* Optionally print hashtable efficiency. */
+ // Optionally print hashtable efficiency.
hash_debug_results();
if (v_dying <= 1) {
@@ -605,7 +605,7 @@ void getout(int exitval)
next_tp = tp->tp_next;
FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
if (wp->w_buffer == NULL) {
- /* Autocmd must have close the buffer already, skip. */
+ // Autocmd must have close the buffer already, skip.
continue;
}
@@ -626,7 +626,7 @@ void getout(int exitval)
}
}
- /* Trigger BufUnload for buffers that are loaded */
+ // Trigger BufUnload for buffers that are loaded
FOR_ALL_BUFFERS(buf) {
if (buf->b_ml.ml_mfp != NULL) {
bufref_T bufref;
@@ -674,8 +674,8 @@ void getout(int exitval)
profile_dump();
if (did_emsg
- ) {
- /* give the user a chance to read the (error) message */
+ ) {
+ // give the user a chance to read the (error) message
no_wait_return = FALSE;
wait_return(FALSE);
}
@@ -727,7 +727,7 @@ static void init_locale(void)
setlocale(LC_ALL, "");
# ifdef LC_NUMERIC
- /* Make sure strtod() uses a decimal point, not a comma. */
+ // Make sure strtod() uses a decimal point, not a comma.
setlocale(LC_NUMERIC, "C");
# endif
@@ -749,10 +749,10 @@ static void init_locale(void)
static bool edit_stdin(bool explicit, mparm_T *parmp)
{
bool implicit = !headless_mode
- && !embedded_mode
- && (!exmode_active || parmp->input_neverscript)
- && !parmp->input_isatty
- && scriptin[0] == NULL; // `-s -` was not given.
+ && !embedded_mode
+ && (!exmode_active || parmp->input_neverscript)
+ && !parmp->input_isatty
+ && scriptin[0] == NULL; // `-s -` was not given.
return explicit || implicit;
}
@@ -784,270 +784,242 @@ static void command_line_scan(mparm_T *parmp)
parmp->commands[parmp->n_commands++] = &(argv[0][1]);
}
- // Optional argument.
+ // Optional argument.
} else if (argv[0][0] == '-' && !had_minmin) {
want_argument = false;
c = argv[0][argv_idx++];
switch (c) {
- case NUL: { // "nvim -" read from stdin
- if (exmode_active) {
- // "nvim -e -" silent mode
- silent_mode = true;
- parmp->no_swap_file = true;
- } else {
- if (parmp->edit_type != EDIT_NONE
- && parmp->edit_type != EDIT_FILE
- && parmp->edit_type != EDIT_STDIN) {
- mainerr(err_too_many_args, argv[0]);
- }
- had_stdin_file = true;
- parmp->edit_type = EDIT_STDIN;
+ case NUL: // "nvim -" read from stdin
+ if (exmode_active) {
+ // "nvim -e -" silent mode
+ silent_mode = true;
+ parmp->no_swap_file = true;
+ } else {
+ if (parmp->edit_type != EDIT_NONE
+ && parmp->edit_type != EDIT_FILE
+ && parmp->edit_type != EDIT_STDIN) {
+ mainerr(err_too_many_args, argv[0]);
}
- argv_idx = -1; // skip to next argument
- break;
+ had_stdin_file = true;
+ parmp->edit_type = EDIT_STDIN;
}
- case '-': { // "--" don't take any more option arguments
- // "--help" give help message
- // "--version" give version message
- // "--noplugin[s]" skip plugins
- // "--cmd <cmd>" execute cmd before vimrc
- if (STRICMP(argv[0] + argv_idx, "help") == 0) {
- usage();
- os_exit(0);
- } else if (STRICMP(argv[0] + argv_idx, "version") == 0) {
- version();
- os_exit(0);
- } else if (STRICMP(argv[0] + argv_idx, "api-info") == 0) {
- FileDescriptor fp;
- const int fof_ret = file_open_fd(&fp, STDOUT_FILENO,
- kFileWriteOnly);
- msgpack_packer *p = msgpack_packer_new(&fp, msgpack_file_write);
-
- if (fof_ret != 0) {
- emsgf(_("E5421: Failed to open stdin: %s"), os_strerror(fof_ret));
- }
+ argv_idx = -1; // skip to next argument
+ break;
+ case '-': // "--" don't take any more option arguments
+ // "--help" give help message
+ // "--version" give version message
+ // "--noplugin[s]" skip plugins
+ // "--cmd <cmd>" execute cmd before vimrc
+ if (STRICMP(argv[0] + argv_idx, "help") == 0) {
+ usage();
+ os_exit(0);
+ } else if (STRICMP(argv[0] + argv_idx, "version") == 0) {
+ version();
+ os_exit(0);
+ } else if (STRICMP(argv[0] + argv_idx, "api-info") == 0) {
+ FileDescriptor fp;
+ const int fof_ret = file_open_fd(&fp, STDOUT_FILENO,
+ kFileWriteOnly);
+ msgpack_packer *p = msgpack_packer_new(&fp, msgpack_file_write);
+
+ if (fof_ret != 0) {
+ emsgf(_("E5421: Failed to open stdin: %s"), os_strerror(fof_ret));
+ }
- if (p == NULL) {
- EMSG(_(e_outofmem));
- }
+ if (p == NULL) {
+ EMSG(_(e_outofmem));
+ }
- Object md = DICTIONARY_OBJ(api_metadata());
- msgpack_rpc_from_object(md, p);
+ Object md = DICTIONARY_OBJ(api_metadata());
+ msgpack_rpc_from_object(md, p);
- msgpack_packer_free(p);
- const int ff_ret = file_flush(&fp);
- if (ff_ret < 0) {
- msgpack_file_write_error(ff_ret);
- }
- os_exit(0);
- } else if (STRICMP(argv[0] + argv_idx, "headless") == 0) {
- headless_mode = true;
- } else if (STRICMP(argv[0] + argv_idx, "embed") == 0) {
- embedded_mode = true;
- } else if (STRNICMP(argv[0] + argv_idx, "listen", 6) == 0) {
- want_argument = true;
- argv_idx += 6;
- } else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) {
- // Do nothing: file args are always literal. #7679
- } else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) {
- p_lpl = false;
- } else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0) {
- want_argument = true;
- argv_idx += 3;
- } else if (STRNICMP(argv[0] + argv_idx, "startuptime", 11) == 0) {
- want_argument = true;
- argv_idx += 11;
- } else if (STRNICMP(argv[0] + argv_idx, "clean", 5) == 0) {
- parmp->use_vimrc = "NONE";
- parmp->clean = true;
- set_option_value("shadafile", 0L, "NONE", 0);
- } else {
- if (argv[0][argv_idx])
- mainerr(err_opt_unknown, argv[0]);
- had_minmin = true;
+ msgpack_packer_free(p);
+ const int ff_ret = file_flush(&fp);
+ if (ff_ret < 0) {
+ msgpack_file_write_error(ff_ret);
}
- if (!want_argument) {
- argv_idx = -1; // skip to next argument
+ os_exit(0);
+ } else if (STRICMP(argv[0] + argv_idx, "headless") == 0) {
+ headless_mode = true;
+ } else if (STRICMP(argv[0] + argv_idx, "embed") == 0) {
+ embedded_mode = true;
+ } else if (STRNICMP(argv[0] + argv_idx, "listen", 6) == 0) {
+ want_argument = true;
+ argv_idx += 6;
+ } else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) {
+ // Do nothing: file args are always literal. #7679
+ } else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) {
+ p_lpl = false;
+ } else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0) {
+ want_argument = true;
+ argv_idx += 3;
+ } else if (STRNICMP(argv[0] + argv_idx, "startuptime", 11) == 0) {
+ want_argument = true;
+ argv_idx += 11;
+ } else if (STRNICMP(argv[0] + argv_idx, "clean", 5) == 0) {
+ parmp->use_vimrc = "NONE";
+ parmp->clean = true;
+ set_option_value("shadafile", 0L, "NONE", 0);
+ } else {
+ if (argv[0][argv_idx]) {
+ mainerr(err_opt_unknown, argv[0]);
}
- break;
- }
- case 'A': { // "-A" start in Arabic mode.
- set_option_value("arabic", 1L, NULL, 0);
- break;
+ had_minmin = true;
}
- case 'b': { // "-b" binary mode.
- // Needs to be effective before expanding file names, because
- // for Win32 this makes us edit a shortcut file itself,
- // instead of the file it links to.
- set_options_bin(curbuf->b_p_bin, 1, 0);
- curbuf->b_p_bin = 1; // Binary file I/O.
- break;
+ if (!want_argument) {
+ argv_idx = -1; // skip to next argument
}
+ break;
+ case 'A': // "-A" start in Arabic mode.
+ set_option_value("arabic", 1L, NULL, 0);
+ break;
+ case 'b': // "-b" binary mode.
+ // Needs to be effective before expanding file names, because
+ // for Win32 this makes us edit a shortcut file itself,
+ // instead of the file it links to.
+ set_options_bin(curbuf->b_p_bin, 1, 0);
+ curbuf->b_p_bin = 1; // Binary file I/O.
+ break;
- case 'D': { // "-D" Debugging
- parmp->use_debug_break_level = 9999;
- break;
- }
- case 'd': { // "-d" 'diff'
- parmp->diff_mode = true;
- break;
- }
- case 'e': { // "-e" Ex mode
- exmode_active = true;
- break;
- }
- case 'E': { // "-E" Ex mode
- exmode_active = true;
- parmp->input_neverscript = true;
- break;
- }
- case 'f': { // "-f" GUI: run in foreground.
- break;
- }
- case '?': // "-?" give help message (for MS-Windows)
- case 'h': { // "-h" give help message
- usage();
- os_exit(0);
- }
- case 'H': { // "-H" start in Hebrew mode: rl + hkmap set.
- p_hkmap = true;
- set_option_value("rl", 1L, NULL, 0);
- break;
- }
- case 'l': { // "-l" lisp mode, 'lisp' and 'showmatch' on.
- set_option_value("lisp", 1L, NULL, 0);
- p_sm = true;
- break;
- }
- case 'M': { // "-M" no changes or writing of files
- reset_modifiable();
- FALLTHROUGH;
- }
- case 'm': { // "-m" no writing of files
- p_write = false;
- break;
- }
+ case 'D': // "-D" Debugging
+ parmp->use_debug_break_level = 9999;
+ break;
+ case 'd': // "-d" 'diff'
+ parmp->diff_mode = true;
+ break;
+ case 'e': // "-e" Ex mode
+ exmode_active = true;
+ break;
+ case 'E': // "-E" Ex mode
+ exmode_active = true;
+ parmp->input_neverscript = true;
+ break;
+ case 'f': // "-f" GUI: run in foreground.
+ break;
+ case '?': // "-?" give help message (for MS-Windows)
+ case 'h': // "-h" give help message
+ usage();
+ os_exit(0);
+ case 'H': // "-H" start in Hebrew mode: rl + hkmap set.
+ p_hkmap = true;
+ set_option_value("rl", 1L, NULL, 0);
+ break;
+ case 'l': // "-l" lisp mode, 'lisp' and 'showmatch' on.
+ set_option_value("lisp", 1L, NULL, 0);
+ p_sm = true;
+ break;
+ case 'M': // "-M" no changes or writing of files
+ reset_modifiable();
+ FALLTHROUGH;
+ case 'm': // "-m" no writing of files
+ p_write = false;
+ break;
- case 'N': // "-N" Nocompatible
- case 'X': // "-X" Do not connect to X server
- // No-op
- break;
+ case 'N': // "-N" Nocompatible
+ case 'X': // "-X" Do not connect to X server
+ // No-op
+ break;
- case 'n': { // "-n" no swap file
- parmp->no_swap_file = true;
- break;
- }
- case 'p': { // "-p[N]" open N tab pages
- // default is 0: open window for each file
- parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
- parmp->window_layout = WIN_TABS;
- break;
- }
- case 'o': { // "-o[N]" open N horizontal split windows
- // default is 0: open window for each file
- parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
- parmp->window_layout = WIN_HOR;
- break;
- }
- case 'O': { // "-O[N]" open N vertical split windows
- // default is 0: open window for each file
- parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
- parmp->window_layout = WIN_VER;
- break;
- }
- case 'q': { // "-q" QuickFix mode
- if (parmp->edit_type != EDIT_NONE) {
- mainerr(err_too_many_args, argv[0]);
- }
- parmp->edit_type = EDIT_QF;
- if (argv[0][argv_idx]) { // "-q{errorfile}"
- parmp->use_ef = (char_u *)argv[0] + argv_idx;
- argv_idx = -1;
- } else if (argc > 1) { // "-q {errorfile}"
- want_argument = true;
- }
- break;
- }
- case 'R': { // "-R" readonly mode
- readonlymode = true;
- curbuf->b_p_ro = true;
- p_uc = 10000; // don't update very often
- break;
+ case 'n': // "-n" no swap file
+ parmp->no_swap_file = true;
+ break;
+ case 'p': // "-p[N]" open N tab pages
+ // default is 0: open window for each file
+ parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
+ parmp->window_layout = WIN_TABS;
+ break;
+ case 'o': // "-o[N]" open N horizontal split windows
+ // default is 0: open window for each file
+ parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
+ parmp->window_layout = WIN_HOR;
+ break;
+ case 'O': // "-O[N]" open N vertical split windows
+ // default is 0: open window for each file
+ parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
+ parmp->window_layout = WIN_VER;
+ break;
+ case 'q': // "-q" QuickFix mode
+ if (parmp->edit_type != EDIT_NONE) {
+ mainerr(err_too_many_args, argv[0]);
}
- case 'r': // "-r" recovery mode
- case 'L': { // "-L" recovery mode
- recoverymode = 1;
- break;
+ parmp->edit_type = EDIT_QF;
+ if (argv[0][argv_idx]) { // "-q{errorfile}"
+ parmp->use_ef = (char_u *)argv[0] + argv_idx;
+ argv_idx = -1;
+ } else if (argc > 1) { // "-q {errorfile}"
+ want_argument = true;
}
- case 's': {
- if (exmode_active) { // "-es" silent (batch) Ex-mode
- silent_mode = true;
- parmp->no_swap_file = true;
- } else { // "-s {scriptin}" read from script file
- want_argument = true;
- }
- break;
+ break;
+ case 'R': // "-R" readonly mode
+ readonlymode = true;
+ curbuf->b_p_ro = true;
+ p_uc = 10000; // don't update very often
+ break;
+ case 'r': // "-r" recovery mode
+ case 'L': // "-L" recovery mode
+ recoverymode = 1;
+ break;
+ case 's':
+ if (exmode_active) { // "-es" silent (batch) Ex-mode
+ silent_mode = true;
+ parmp->no_swap_file = true;
+ } else { // "-s {scriptin}" read from script file
+ want_argument = true;
}
- case 't': { // "-t {tag}" or "-t{tag}" jump to tag
- if (parmp->edit_type != EDIT_NONE) {
- mainerr(err_too_many_args, argv[0]);
- }
- parmp->edit_type = EDIT_TAG;
- if (argv[0][argv_idx]) { // "-t{tag}"
- parmp->tagname = (char_u *)argv[0] + argv_idx;
- argv_idx = -1;
- } else { // "-t {tag}"
- want_argument = true;
- }
- break;
+ break;
+ case 't': // "-t {tag}" or "-t{tag}" jump to tag
+ if (parmp->edit_type != EDIT_NONE) {
+ mainerr(err_too_many_args, argv[0]);
}
- case 'v': {
- version();
- os_exit(0);
+ parmp->edit_type = EDIT_TAG;
+ if (argv[0][argv_idx]) { // "-t{tag}"
+ parmp->tagname = (char_u *)argv[0] + argv_idx;
+ argv_idx = -1;
+ } else { // "-t {tag}"
+ want_argument = true;
}
- case 'V': { // "-V{N}" Verbose level
- // default is 10: a little bit verbose
- p_verbose = get_number_arg(argv[0], &argv_idx, 10);
- if (argv[0][argv_idx] != NUL) {
- set_option_value("verbosefile", 0L, argv[0] + argv_idx, 0);
- argv_idx = (int)STRLEN(argv[0]);
- }
- break;
+ break;
+ case 'v':
+ version();
+ os_exit(0);
+ case 'V': // "-V{N}" Verbose level
+ // default is 10: a little bit verbose
+ p_verbose = get_number_arg(argv[0], &argv_idx, 10);
+ if (argv[0][argv_idx] != NUL) {
+ set_option_value("verbosefile", 0L, argv[0] + argv_idx, 0);
+ argv_idx = (int)STRLEN(argv[0]);
}
- case 'w': { // "-w{number}" set window height
- // "-w {scriptout}" write to script
- if (ascii_isdigit(((char_u *)argv[0])[argv_idx])) {
- n = get_number_arg(argv[0], &argv_idx, 10);
- set_option_value("window", n, NULL, 0);
- break;
- }
- want_argument = true;
+ break;
+ case 'w': // "-w{number}" set window height
+ // "-w {scriptout}" write to script
+ if (ascii_isdigit(((char_u *)argv[0])[argv_idx])) {
+ n = get_number_arg(argv[0], &argv_idx, 10);
+ set_option_value("window", n, NULL, 0);
break;
}
+ want_argument = true;
+ break;
- case 'c': { // "-c{command}" or "-c {command}" exec command
- if (argv[0][argv_idx] != NUL) {
- if (parmp->n_commands >= MAX_ARG_CMDS) {
- mainerr(err_extra_cmd, NULL);
- }
- parmp->commands[parmp->n_commands++] = argv[0] + argv_idx;
- argv_idx = -1;
- break;
+ case 'c': // "-c{command}" or "-c {command}" exec command
+ if (argv[0][argv_idx] != NUL) {
+ if (parmp->n_commands >= MAX_ARG_CMDS) {
+ mainerr(err_extra_cmd, NULL);
}
- FALLTHROUGH;
- }
- case 'S': // "-S {file}" execute Vim script
- case 'i': // "-i {shada}" use for ShaDa file
- case 'u': // "-u {vimrc}" vim inits file
- case 'U': // "-U {gvimrc}" gvim inits file
- case 'W': { // "-W {scriptout}" overwrite
- want_argument = true;
+ parmp->commands[parmp->n_commands++] = argv[0] + argv_idx;
+ argv_idx = -1;
break;
}
+ FALLTHROUGH;
+ case 'S': // "-S {file}" execute Vim script
+ case 'i': // "-i {shada}" use for ShaDa file
+ case 'u': // "-u {vimrc}" vim inits file
+ case 'U': // "-U {gvimrc}" gvim inits file
+ case 'W': // "-W {scriptout}" overwrite
+ want_argument = true;
+ break;
- default: {
- mainerr(err_opt_unknown, argv[0]);
- }
+ default:
+ mainerr(err_opt_unknown, argv[0]);
}
// Handle option arguments with argument.
@@ -1065,130 +1037,122 @@ static void command_line_scan(mparm_T *parmp)
argv_idx = -1;
switch (c) {
- case 'c': // "-c {command}" execute command
- case 'S': { // "-S {file}" execute Vim script
- if (parmp->n_commands >= MAX_ARG_CMDS) {
- mainerr(err_extra_cmd, NULL);
- }
- if (c == 'S') {
- char *a;
-
- if (argc < 1) {
- // "-S" without argument: use default session file name.
- a = SESSION_FILE;
- } else if (argv[0][0] == '-') {
- // "-S" followed by another option: use default session file.
- a = SESSION_FILE;
- ++argc;
- --argv;
- } else {
- a = argv[0];
- }
-
- size_t s_size = STRLEN(a) + 9;
- char *s = xmalloc(s_size);
- snprintf(s, s_size, "so %s", a);
- parmp->cmds_tofree[parmp->n_commands] = true;
- parmp->commands[parmp->n_commands++] = s;
+ case 'c': // "-c {command}" execute command
+ case 'S': // "-S {file}" execute Vim script
+ if (parmp->n_commands >= MAX_ARG_CMDS) {
+ mainerr(err_extra_cmd, NULL);
+ }
+ if (c == 'S') {
+ char *a;
+
+ if (argc < 1) {
+ // "-S" without argument: use default session file name.
+ a = SESSION_FILE;
+ } else if (argv[0][0] == '-') {
+ // "-S" followed by another option: use default session file.
+ a = SESSION_FILE;
+ ++argc;
+ --argv;
} else {
- parmp->commands[parmp->n_commands++] = argv[0];
+ a = argv[0];
}
- break;
+
+ size_t s_size = STRLEN(a) + 9;
+ char *s = xmalloc(s_size);
+ snprintf(s, s_size, "so %s", a);
+ parmp->cmds_tofree[parmp->n_commands] = true;
+ parmp->commands[parmp->n_commands++] = s;
+ } else {
+ parmp->commands[parmp->n_commands++] = argv[0];
}
+ break;
- case '-': {
- if (strequal(argv[-1], "--cmd")) {
- // "--cmd {command}" execute command
- if (parmp->n_pre_commands >= MAX_ARG_CMDS) {
- mainerr(err_extra_cmd, NULL);
- }
- parmp->pre_commands[parmp->n_pre_commands++] = argv[0];
- } else if (strequal(argv[-1], "--listen")) {
- // "--listen {address}"
- parmp->listen_addr = argv[0];
+ case '-':
+ if (strequal(argv[-1], "--cmd")) {
+ // "--cmd {command}" execute command
+ if (parmp->n_pre_commands >= MAX_ARG_CMDS) {
+ mainerr(err_extra_cmd, NULL);
}
- // "--startuptime <file>" already handled
- break;
+ parmp->pre_commands[parmp->n_pre_commands++] = argv[0];
+ } else if (strequal(argv[-1], "--listen")) {
+ // "--listen {address}"
+ parmp->listen_addr = argv[0];
}
+ // "--startuptime <file>" already handled
+ break;
- case 'q': { // "-q {errorfile}" QuickFix mode
- parmp->use_ef = (char_u *)argv[0];
- break;
- }
+ case 'q': // "-q {errorfile}" QuickFix mode
+ parmp->use_ef = (char_u *)argv[0];
+ break;
- case 'i': { // "-i {shada}" use for shada
- set_option_value("shadafile", 0L, argv[0], 0);
- break;
- }
+ case 'i': // "-i {shada}" use for shada
+ set_option_value("shadafile", 0L, argv[0], 0);
+ break;
- case 's': { // "-s {scriptin}" read from script file
- if (scriptin[0] != NULL) {
+ case 's': { // "-s {scriptin}" read from script file
+ if (scriptin[0] != NULL) {
scripterror:
- vim_snprintf((char *)IObuff, IOSIZE,
- _("Attempt to open script file again: \"%s %s\"\n"),
- argv[-1], argv[0]);
- mch_errmsg((const char *)IObuff);
- os_exit(2);
- }
- int error;
- if (strequal(argv[0], "-")) {
- const int stdin_dup_fd = os_dup(STDIN_FILENO);
+ vim_snprintf((char *)IObuff, IOSIZE,
+ _("Attempt to open script file again: \"%s %s\"\n"),
+ argv[-1], argv[0]);
+ mch_errmsg((const char *)IObuff);
+ os_exit(2);
+ }
+ int error;
+ if (strequal(argv[0], "-")) {
+ const int stdin_dup_fd = os_dup(STDIN_FILENO);
#ifdef WIN32
- // Replace the original stdin with the console input handle.
- os_replace_stdin_to_conin();
+ // Replace the original stdin with the console input handle.
+ os_replace_stdin_to_conin();
#endif
- FileDescriptor *const stdin_dup = file_open_fd_new(
- &error, stdin_dup_fd, kFileReadOnly|kFileNonBlocking);
- assert(stdin_dup != NULL);
- scriptin[0] = stdin_dup;
- } else if ((scriptin[0] = file_open_new(
- &error, argv[0], kFileReadOnly|kFileNonBlocking, 0)) == NULL) {
- vim_snprintf((char *)IObuff, IOSIZE,
- _("Cannot open for reading: \"%s\": %s\n"),
- argv[0], os_strerror(error));
- mch_errmsg((const char *)IObuff);
- os_exit(2);
- }
- save_typebuf();
- break;
+ FileDescriptor *const stdin_dup = file_open_fd_new(&error, stdin_dup_fd,
+ kFileReadOnly|kFileNonBlocking);
+ assert(stdin_dup != NULL);
+ scriptin[0] = stdin_dup;
+ } else if ((scriptin[0] =
+ file_open_new(&error, argv[0], kFileReadOnly|kFileNonBlocking,
+ 0)) == NULL) {
+ vim_snprintf((char *)IObuff, IOSIZE,
+ _("Cannot open for reading: \"%s\": %s\n"),
+ argv[0], os_strerror(error));
+ mch_errmsg((const char *)IObuff);
+ os_exit(2);
}
+ save_typebuf();
+ break;
+ }
- case 't': { // "-t {tag}"
- parmp->tagname = (char_u *)argv[0];
- break;
- }
- case 'u': { // "-u {vimrc}" vim inits file
- parmp->use_vimrc = argv[0];
- break;
- }
- case 'U': { // "-U {gvimrc}" gvim inits file
+ case 't': // "-t {tag}"
+ parmp->tagname = (char_u *)argv[0];
+ break;
+ case 'u': // "-u {vimrc}" vim inits file
+ parmp->use_vimrc = argv[0];
+ break;
+ case 'U': // "-U {gvimrc}" gvim inits file
+ break;
+
+ case 'w': // "-w {nr}" 'window' value
+ // "-w {scriptout}" append to script file
+ if (ascii_isdigit(*((char_u *)argv[0]))) {
+ argv_idx = 0;
+ n = get_number_arg(argv[0], &argv_idx, 10);
+ set_option_value("window", n, NULL, 0);
+ argv_idx = -1;
break;
}
-
- case 'w': { // "-w {nr}" 'window' value
- // "-w {scriptout}" append to script file
- if (ascii_isdigit(*((char_u *)argv[0]))) {
- argv_idx = 0;
- n = get_number_arg(argv[0], &argv_idx, 10);
- set_option_value("window", n, NULL, 0);
- argv_idx = -1;
- break;
- }
- FALLTHROUGH;
+ FALLTHROUGH;
+ case 'W': // "-W {scriptout}" overwrite script file
+ if (scriptout != NULL) {
+ goto scripterror;
}
- case 'W': { // "-W {scriptout}" overwrite script file
- if (scriptout != NULL) {
- goto scripterror;
- }
- if ((scriptout = os_fopen(argv[0], c == 'w' ? APPENDBIN : WRITEBIN))
- == NULL) {
- mch_errmsg(_("Cannot open for script output: \""));
- mch_errmsg(argv[0]);
- mch_errmsg("\"\n");
- os_exit(2);
- }
- break;
+ if ((scriptout = os_fopen(argv[0], c == 'w' ? APPENDBIN : WRITEBIN))
+ == NULL) {
+ mch_errmsg(_("Cannot open for script output: \""));
+ mch_errmsg(argv[0]);
+ mch_errmsg("\"\n");
+ os_exit(2);
}
+ break;
}
}
} else { // File name argument.
@@ -1209,7 +1173,7 @@ scripterror:
if (parmp->diff_mode && os_isdir(p) && GARGCOUNT > 0
&& !os_isdir(alist_name(&GARGLIST[0]))) {
char_u *r = (char_u *)concat_fnames((char *)p,
- (char *)path_tail(alist_name(&GARGLIST[0])), true);
+ (char *)path_tail(alist_name(&GARGLIST[0])), true);
xfree(p);
p = r;
}
@@ -1334,10 +1298,11 @@ static char_u *get_fname(mparm_T *parmp, char_u *cwd)
static void set_window_layout(mparm_T *paramp)
{
if (paramp->diff_mode && paramp->window_layout == 0) {
- if (diffopt_horizontal())
- paramp->window_layout = WIN_HOR; /* use horizontal split */
- else
- paramp->window_layout = WIN_VER; /* use vertical split */
+ if (diffopt_horizontal()) {
+ paramp->window_layout = WIN_HOR; // use horizontal split
+ } else {
+ paramp->window_layout = WIN_VER; // use vertical split
+ }
}
}
@@ -1403,9 +1368,10 @@ static void handle_tag(char_u *tagname)
do_cmdline_cmd((char *)IObuff);
TIME_MSG("jumping to tag");
- /* If the user doesn't want to edit the file then we quit here. */
- if (swap_exists_did_quit)
+ // If the user doesn't want to edit the file then we quit here.
+ if (swap_exists_did_quit) {
getout(1);
+ }
}
}
@@ -1443,26 +1409,31 @@ static void create_windows(mparm_T *parmp)
/*
* Create the number of windows that was requested.
*/
- if (parmp->window_count == -1) /* was not set */
+ if (parmp->window_count == -1) { // was not set
parmp->window_count = 1;
- if (parmp->window_count == 0)
+ }
+ if (parmp->window_count == 0) {
parmp->window_count = GARGCOUNT;
+ }
if (parmp->window_count > 1) {
// Don't change the windows if there was a command in vimrc that
// already split some windows
- if (parmp->window_layout == 0)
+ if (parmp->window_layout == 0) {
parmp->window_layout = WIN_HOR;
+ }
if (parmp->window_layout == WIN_TABS) {
parmp->window_count = make_tabpages(parmp->window_count);
TIME_MSG("making tab pages");
} else if (firstwin->w_next == NULL) {
parmp->window_count = make_windows(parmp->window_count,
- parmp->window_layout == WIN_VER);
+ parmp->window_layout == WIN_VER);
TIME_MSG("making windows");
- } else
+ } else {
parmp->window_count = win_count();
- } else
+ }
+ } else {
parmp->window_count = 1;
+ }
if (recoverymode) { // do recover
msg_scroll = true; // scroll message up
@@ -1482,17 +1453,20 @@ static void create_windows(mparm_T *parmp)
dorewind = TRUE;
while (done++ < 1000) {
if (dorewind) {
- if (parmp->window_layout == WIN_TABS)
+ if (parmp->window_layout == WIN_TABS) {
goto_tabpage(1);
- else
+ } else {
curwin = firstwin;
+ }
} else if (parmp->window_layout == WIN_TABS) {
- if (curtab->tp_next == NULL)
+ if (curtab->tp_next == NULL) {
break;
+ }
goto_tabpage(0);
} else {
- if (curwin->w_next == NULL)
+ if (curwin->w_next == NULL) {
break;
+ }
curwin = curwin->w_next;
}
dorewind = FALSE;
@@ -1506,13 +1480,13 @@ static void create_windows(mparm_T *parmp)
swap_exists_action = SEA_DIALOG;
set_buflisted(TRUE);
- /* create memfile, read file */
+ // create memfile, read file
(void)open_buffer(FALSE, NULL, 0);
if (swap_exists_action == SEA_QUIT) {
if (got_int || only_one_window()) {
- /* abort selected or quit and only one window */
- did_emsg = FALSE; /* avoid hit-enter prompt */
+ // abort selected or quit and only one window
+ did_emsg = FALSE; // avoid hit-enter prompt
getout(1);
}
/* We can't close the window, it would disturb what
@@ -1521,20 +1495,22 @@ static void create_windows(mparm_T *parmp)
setfname(curbuf, NULL, NULL, false);
curwin->w_arg_idx = -1;
swap_exists_action = SEA_NONE;
- } else
+ } else {
handle_swap_exists(NULL);
- dorewind = TRUE; /* start again */
+ }
+ dorewind = TRUE; // start again
}
os_breakcheck();
if (got_int) {
- (void)vgetc(); /* only break the file loading, not the rest */
+ (void)vgetc(); // only break the file loading, not the rest
break;
}
}
- if (parmp->window_layout == WIN_TABS)
+ if (parmp->window_layout == WIN_TABS) {
goto_tabpage(1);
- else
+ } else {
curwin = firstwin;
+ }
curbuf = curwin->w_buffer;
--autocmd_no_enter;
--autocmd_no_leave;
@@ -1545,10 +1521,10 @@ static void create_windows(mparm_T *parmp)
/// windows. make_windows() has already opened the windows.
static void edit_buffers(mparm_T *parmp, char_u *cwd)
{
- int arg_idx; /* index in argument list */
+ int arg_idx; // index in argument list
int i;
bool advance = true;
- win_T *win;
+ win_T *win;
char *p_shm_save = NULL;
/*
@@ -1557,7 +1533,7 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
++autocmd_no_enter;
++autocmd_no_leave;
- /* When w_arg_idx is -1 remove the window (see create_windows()). */
+ // When w_arg_idx is -1 remove the window (see create_windows()).
if (curwin->w_arg_idx == -1) {
win_close(curwin, true);
advance = false;
@@ -1578,8 +1554,9 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
if (advance) {
if (parmp->window_layout == WIN_TABS) {
- if (curtab->tp_next == NULL) /* just checking */
+ if (curtab->tp_next == NULL) { // just checking
break;
+ }
goto_tabpage(0);
// Temporarily reset 'shm' option to not print fileinfo when
// loading the other buffers. This would overwrite the already
@@ -1592,8 +1569,9 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
set_option_value("shm", 0L, buf, 0);
}
} else {
- if (curwin->w_next == NULL) /* just checking */
+ if (curwin->w_next == NULL) { // just checking
break;
+ }
win_enter(curwin->w_next, false);
}
}
@@ -1608,12 +1586,12 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
swap_exists_did_quit = false;
(void)do_ecmd(0, arg_idx < GARGCOUNT
? alist_name(&GARGLIST[arg_idx]) : NULL,
- NULL, NULL, ECMD_LASTL, ECMD_HIDE, curwin);
+ NULL, NULL, ECMD_LASTL, ECMD_HIDE, curwin);
if (swap_exists_did_quit) {
- /* abort or quit selected */
+ // abort or quit selected
if (got_int || only_one_window()) {
- /* abort selected and only one window */
- did_emsg = FALSE; /* avoid hit-enter prompt */
+ // abort selected and only one window
+ did_emsg = FALSE; // avoid hit-enter prompt
getout(1);
}
win_close(curwin, true);
@@ -1626,7 +1604,7 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
}
os_breakcheck();
if (got_int) {
- (void)vgetc(); /* only break the file loading, not the rest */
+ (void)vgetc(); // only break the file loading, not the rest
break;
}
}
@@ -1636,13 +1614,14 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
xfree(p_shm_save);
}
- if (parmp->window_layout == WIN_TABS)
+ if (parmp->window_layout == WIN_TABS) {
goto_tabpage(1);
+ }
--autocmd_no_enter;
- /* make the first window the current window */
+ // make the first window the current window
win = firstwin;
- /* Avoid making a preview window the current window. */
+ // Avoid making a preview window the current window.
while (win->w_p_pvw) {
win = win->w_next;
if (win == NULL) {
@@ -1654,8 +1633,9 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
--autocmd_no_leave;
TIME_MSG("editing files in windows");
- if (parmp->window_count > 1 && parmp->window_layout != WIN_TABS)
- win_equal(curwin, false, 'b'); /* adjust heights */
+ if (parmp->window_count > 1 && parmp->window_layout != WIN_TABS) {
+ win_equal(curwin, false, 'b'); // adjust heights
+ }
}
/*
@@ -1668,7 +1648,7 @@ static void exe_pre_commands(mparm_T *parmp)
int i;
if (cnt > 0) {
- curwin->w_cursor.lnum = 0; /* just in case.. */
+ curwin->w_cursor.lnum = 0; // just in case..
sourcing_name = (char_u *)_("pre-vimrc command line");
current_sctx.sc_sid = SID_CMDARG;
for (i = 0; i < cnt; i++) {
@@ -1693,15 +1673,17 @@ static void exe_commands(mparm_T *parmp)
* with g`" was used.
*/
msg_scroll = TRUE;
- if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1)
+ if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1) {
curwin->w_cursor.lnum = 0;
+ }
sourcing_name = (char_u *)"command line";
current_sctx.sc_sid = SID_CARG;
current_sctx.sc_seq = 0;
for (i = 0; i < parmp->n_commands; i++) {
do_cmdline_cmd(parmp->commands[i]);
- if (parmp->cmds_tofree[i])
+ if (parmp->cmds_tofree[i]) {
xfree(parmp->commands[i]);
+ }
}
sourcing_name = NULL;
current_sctx.sc_sid = 0;
@@ -1709,12 +1691,14 @@ static void exe_commands(mparm_T *parmp)
curwin->w_cursor.lnum = 1;
}
- if (!exmode_active)
+ if (!exmode_active) {
msg_scroll = FALSE;
+ }
- /* When started with "-q errorfile" jump to first error again. */
- if (parmp->edit_type == EDIT_QF)
+ // When started with "-q errorfile" jump to first error again.
+ if (parmp->edit_type == EDIT_QF) {
qf_jump(NULL, 0, 0, FALSE);
+ }
TIME_MSG("executing command arguments");
}
@@ -1744,7 +1728,7 @@ static void do_system_initialization(void)
memcpy(vimrc, dir, dir_len);
vimrc[dir_len] = PATHSEP;
memcpy(vimrc + dir_len + 1, path_tail, sizeof(path_tail));
- if (do_source((char_u *)vimrc, false, DOSO_NONE) != FAIL) {
+ if (do_source((char_u *)vimrc, false, DOSO_NONE) != FAIL) {
xfree(vimrc);
xfree(config_dirs);
return;
@@ -1826,7 +1810,7 @@ static bool do_user_initialization(void)
memmove(vimrc, dir, dir_len);
vimrc[dir_len] = PATHSEP;
memmove(vimrc + dir_len + 1, path_tail, sizeof(path_tail));
- if (do_source((char_u *) vimrc, true, DOSO_VIMRC) != FAIL) {
+ if (do_source((char_u *)vimrc, true, DOSO_VIMRC) != FAIL) {
do_exrc = p_exrc;
if (do_exrc) {
do_exrc = (path_full_compare((char_u *)VIMRC_FILE, (char_u *)vimrc,
@@ -1877,7 +1861,7 @@ static void source_startup_scripts(const mparm_T *const parmp)
// If vimrc file is not owned by user, set 'secure' mode.
if (!file_owned(VIMRC_FILE))
#endif
- secure = p_secure;
+ secure = p_secure;
if (do_source((char_u *)VIMRC_FILE, true, DOSO_VIMRC) == FAIL) {
#if defined(UNIX)
@@ -2033,7 +2017,8 @@ static void usage(void)
*/
static void check_swap_exists_action(void)
{
- if (swap_exists_action == SEA_QUIT)
+ if (swap_exists_action == SEA_QUIT) {
getout(1);
+ }
handle_swap_exists(NULL);
}
diff --git a/src/nvim/map.c b/src/nvim/map.c
index ccd332192e..1c986a4fa4 100644
--- a/src/nvim/map.c
+++ b/src/nvim/map.c
@@ -8,20 +8,18 @@
// khash.h does not make its own copy of the key or value.
//
-#include <stdlib.h>
+#include <lauxlib.h>
+#include <lua.h>
#include <stdbool.h>
+#include <stdlib.h>
#include <string.h>
-#include <lua.h>
-#include <lauxlib.h>
-
+#include "nvim/api/private/dispatch.h"
+#include "nvim/lib/khash.h"
#include "nvim/map.h"
#include "nvim/map_defs.h"
-#include "nvim/vim.h"
#include "nvim/memory.h"
-#include "nvim/api/private/dispatch.h"
-
-#include "nvim/lib/khash.h"
+#include "nvim/vim.h"
#define cstr_t_hash kh_str_hash_func
#define cstr_t_eq kh_str_hash_equal
@@ -52,7 +50,7 @@
#define MAP_IMPL(T, U, ...) \
INITIALIZER_DECLARE(T, U, __VA_ARGS__); \
- __KHASH_IMPL(T##_##U##_map,, T, U, 1, T##_hash, T##_eq) \
+ __KHASH_IMPL(T##_##U##_map, , T, U, 1, T##_hash, T##_eq) \
\
void map_##T##_##U##_destroy(Map(T, U) *map) \
{ \
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index 0b14089550..b296bf39cf 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -7,35 +7,35 @@
#include <assert.h>
#include <inttypes.h>
-#include <string.h>
#include <limits.h>
+#include <string.h>
-#include "nvim/vim.h"
#include "nvim/ascii.h"
-#include "nvim/mark.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/diff.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
+#include "nvim/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
-#include "nvim/extmark.h"
+#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/normal.h"
#include "nvim/option.h"
+#include "nvim/os/input.h"
+#include "nvim/os/os.h"
+#include "nvim/os/time.h"
#include "nvim/path.h"
#include "nvim/quickfix.h"
#include "nvim/search.h"
#include "nvim/sign.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
-#include "nvim/os/os.h"
-#include "nvim/os/time.h"
-#include "nvim/os/input.h"
+#include "nvim/vim.h"
/*
* This file contains routines to maintain and manipulate marks.
@@ -94,17 +94,19 @@ int setmark_pos(int c, pos_T *pos, int fnum)
{
int i;
- /* Check for a special key (may cause islower() to crash). */
- if (c < 0)
+ // Check for a special key (may cause islower() to crash).
+ if (c < 0) {
return FAIL;
+ }
if (c == '\'' || c == '`') {
if (pos == &curwin->w_cursor) {
setpcmark();
- /* keep it even when the cursor doesn't move */
+ // keep it even when the cursor doesn't move
curwin->w_prev_pcmark = curwin->w_pcmark;
- } else
+ } else {
curwin->w_pcmark = *pos;
+ }
return OK;
}
@@ -166,11 +168,12 @@ int setmark_pos(int c, pos_T *pos, int fnum)
*/
void setpcmark(void)
{
- xfmark_T *fm;
+ xfmark_T *fm;
- /* for :global the mark is set only once */
- if (global_busy || listcmd_busy || cmdmod.keepjumps)
+ // for :global the mark is set only once
+ if (global_busy || listcmd_busy || cmdmod.keepjumps) {
return;
+ }
curwin->w_prev_pcmark = curwin->w_pcmark;
curwin->w_pcmark = curwin->w_cursor;
@@ -189,7 +192,7 @@ void setpcmark(void)
}
}
- /* If jumplist is full: remove oldest entry */
+ // If jumplist is full: remove oldest entry
if (++curwin->w_jumplistlen > JUMPLISTSIZE) {
curwin->w_jumplistlen = JUMPLISTSIZE;
free_xfmark(curwin->w_jumplist[0]);
@@ -214,7 +217,7 @@ void checkpcmark(void)
&& (equalpos(curwin->w_pcmark, curwin->w_cursor)
|| curwin->w_pcmark.lnum == 0)) {
curwin->w_pcmark = curwin->w_prev_pcmark;
- curwin->w_prev_pcmark.lnum = 0; /* Show it has been checked */
+ curwin->w_prev_pcmark.lnum = 0; // Show it has been checked
}
}
@@ -223,18 +226,20 @@ void checkpcmark(void)
*/
pos_T *movemark(int count)
{
- pos_T *pos;
- xfmark_T *jmp;
+ pos_T *pos;
+ xfmark_T *jmp;
cleanup_jumplist(curwin, true);
- if (curwin->w_jumplistlen == 0) /* nothing to jump to */
+ if (curwin->w_jumplistlen == 0) { // nothing to jump to
return (pos_T *)NULL;
+ }
for (;; ) {
if (curwin->w_jumplistidx + count < 0
- || curwin->w_jumplistidx + count >= curwin->w_jumplistlen)
+ || curwin->w_jumplistidx + count >= curwin->w_jumplistlen) {
return (pos_T *)NULL;
+ }
/*
* if first CTRL-O or CTRL-I command after a jump, add cursor position
@@ -243,30 +248,34 @@ pos_T *movemark(int count)
*/
if (curwin->w_jumplistidx == curwin->w_jumplistlen) {
setpcmark();
- --curwin->w_jumplistidx; /* skip the new entry */
- if (curwin->w_jumplistidx + count < 0)
+ --curwin->w_jumplistidx; // skip the new entry
+ if (curwin->w_jumplistidx + count < 0) {
return (pos_T *)NULL;
+ }
}
curwin->w_jumplistidx += count;
jmp = curwin->w_jumplist + curwin->w_jumplistidx;
- if (jmp->fmark.fnum == 0)
+ if (jmp->fmark.fnum == 0) {
fname2fnum(jmp);
+ }
if (jmp->fmark.fnum != curbuf->b_fnum) {
- /* jump to other file */
- if (buflist_findnr(jmp->fmark.fnum) == NULL) { /* Skip this one .. */
+ // jump to other file
+ if (buflist_findnr(jmp->fmark.fnum) == NULL) { // Skip this one ..
count += count < 0 ? -1 : 1;
continue;
}
if (buflist_getfile(jmp->fmark.fnum, jmp->fmark.mark.lnum,
- 0, FALSE) == FAIL)
+ 0, FALSE) == FAIL) {
return (pos_T *)NULL;
- /* Set lnum again, autocommands my have changed it */
+ }
+ // Set lnum again, autocommands my have changed it
curwin->w_cursor = jmp->fmark.mark;
pos = (pos_T *)-1;
- } else
+ } else {
pos = &(jmp->fmark.mark);
+ }
return pos;
}
}
@@ -278,20 +287,24 @@ pos_T *movechangelist(int count)
{
int n;
- if (curbuf->b_changelistlen == 0) /* nothing to jump to */
+ if (curbuf->b_changelistlen == 0) { // nothing to jump to
return (pos_T *)NULL;
+ }
n = curwin->w_changelistidx;
if (n + count < 0) {
- if (n == 0)
+ if (n == 0) {
return (pos_T *)NULL;
+ }
n = 0;
} else if (n + count >= curbuf->b_changelistlen) {
- if (n == curbuf->b_changelistlen - 1)
+ if (n == curbuf->b_changelistlen - 1) {
return (pos_T *)NULL;
+ }
n = curbuf->b_changelistlen - 1;
- } else
+ } else {
n += count;
+ }
curwin->w_changelistidx = n;
return &(curbuf->b_changelist[n].mark);
}
@@ -319,16 +332,17 @@ pos_T *getmark(int c, bool changefile)
pos_T *getmark_buf_fnum(buf_T *buf, int c, bool changefile, int *fnum)
{
- pos_T *posp;
- pos_T *startp, *endp;
+ pos_T *posp;
+ pos_T *startp, *endp;
static pos_T pos_copy;
posp = NULL;
/* Check for special key, can't be a mark name and might cause islower()
* to crash. */
- if (c < 0)
+ if (c < 0) {
return posp;
+ }
if (c > '~') { // check for islower()/isupper()
} else if (c == '\'' || c == '`') { // previous context mark
pos_copy = curwin->w_pcmark; // need to make a copy because
@@ -351,13 +365,13 @@ pos_T *getmark_buf_fnum(buf_T *buf, int c, bool changefile, int *fnum)
pos = curwin->w_cursor;
listcmd_busy = true; // avoid that '' is changed
if (findpar(&oa.inclusive,
- c == '}' ? FORWARD : BACKWARD, 1L, NUL, FALSE)) {
+ c == '}' ? FORWARD : BACKWARD, 1L, NUL, FALSE)) {
pos_copy = curwin->w_cursor;
posp = &pos_copy;
}
curwin->w_cursor = pos;
listcmd_busy = slcb;
- } else if (c == '(' || c == ')') { /* to previous/next sentence */
+ } else if (c == '(' || c == ')') { // to previous/next sentence
pos_T pos;
bool slcb = listcmd_busy;
@@ -369,7 +383,7 @@ pos_T *getmark_buf_fnum(buf_T *buf, int c, bool changefile, int *fnum)
}
curwin->w_cursor = pos;
listcmd_busy = slcb;
- } else if (c == '<' || c == '>') { /* start/end of visual area */
+ } else if (c == '<' || c == '>') { // start/end of visual area
startp = &buf->b_visual.vi_start;
endp = &buf->b_visual.vi_end;
if (((c == '<') == lt(*startp, *endp) || endp->lnum == 0)
@@ -383,63 +397,62 @@ pos_T *getmark_buf_fnum(buf_T *buf, int c, bool changefile, int *fnum)
if (buf->b_visual.vi_mode == 'V') {
pos_copy = *posp;
posp = &pos_copy;
- if (c == '<')
+ if (c == '<') {
pos_copy.col = 0;
- else
+ } else {
pos_copy.col = MAXCOL;
+ }
pos_copy.coladd = 0;
}
- } else if (ASCII_ISLOWER(c)) { /* normal named mark */
+ } else if (ASCII_ISLOWER(c)) { // normal named mark
posp = &(buf->b_namedm[c - 'a'].mark);
- } else if (ASCII_ISUPPER(c) || ascii_isdigit(c)) { /* named file mark */
- if (ascii_isdigit(c))
+ } else if (ASCII_ISUPPER(c) || ascii_isdigit(c)) { // named file mark
+ if (ascii_isdigit(c)) {
c = c - '0' + NMARKS;
- else
+ } else {
c -= 'A';
+ }
posp = &(namedfm[c].fmark.mark);
if (namedfm[c].fmark.fnum == 0) {
fname2fnum(&namedfm[c]);
}
- if (fnum != NULL)
+ if (fnum != NULL) {
*fnum = namedfm[c].fmark.fnum;
- else if (namedfm[c].fmark.fnum != buf->b_fnum) {
- /* mark is in another file */
+ } else if (namedfm[c].fmark.fnum != buf->b_fnum) {
+ // mark is in another file
posp = &pos_copy;
if (namedfm[c].fmark.mark.lnum != 0
&& changefile && namedfm[c].fmark.fnum) {
if (buflist_getfile(namedfm[c].fmark.fnum,
- (linenr_T)1, GETF_SETMARK, FALSE) == OK) {
- /* Set the lnum now, autocommands could have changed it */
+ (linenr_T)1, GETF_SETMARK, FALSE) == OK) {
+ // Set the lnum now, autocommands could have changed it
curwin->w_cursor = namedfm[c].fmark.mark;
return (pos_T *)-1;
}
- pos_copy.lnum = -1; /* can't get file */
- } else
+ pos_copy.lnum = -1; // can't get file
+ } else {
pos_copy.lnum = 0; /* mark exists, but is not valid in
current buffer */
+ }
}
}
return posp;
}
-/*
- * Search for the next named mark in the current file.
- *
- * Returns pointer to pos_T of the next mark or NULL if no mark is found.
- */
-pos_T *
-getnextmark (
- pos_T *startpos, /* where to start */
- int dir, /* direction for search */
- int begin_line
-)
+/// Search for the next named mark in the current file.
+///
+/// @param startpos where to start
+/// @param dir direction for search
+///
+/// @return pointer to pos_T of the next mark or NULL if no mark is found.
+pos_T *getnextmark(pos_T *startpos, int dir, int begin_line)
{
int i;
- pos_T *result = NULL;
+ pos_T *result = NULL;
pos_T pos;
pos = *startpos;
@@ -448,21 +461,24 @@ getnextmark (
* position must be in a previous line.
* When searching forward and leaving the cursor on the first non-blank,
* position must be in a next line. */
- if (dir == BACKWARD && begin_line)
+ if (dir == BACKWARD && begin_line) {
pos.col = 0;
- else if (dir == FORWARD && begin_line)
+ } else if (dir == FORWARD && begin_line) {
pos.col = MAXCOL;
+ }
for (i = 0; i < NMARKS; i++) {
if (curbuf->b_namedm[i].mark.lnum > 0) {
if (dir == FORWARD) {
if ((result == NULL || lt(curbuf->b_namedm[i].mark, *result))
- && lt(pos, curbuf->b_namedm[i].mark))
+ && lt(pos, curbuf->b_namedm[i].mark)) {
result = &curbuf->b_namedm[i].mark;
+ }
} else {
if ((result == NULL || lt(*result, curbuf->b_namedm[i].mark))
- && lt(curbuf->b_namedm[i].mark, pos))
+ && lt(curbuf->b_namedm[i].mark, pos)) {
result = &curbuf->b_namedm[i].mark;
+ }
}
}
}
@@ -494,10 +510,11 @@ static void fname2fnum(xfmark_T *fm)
expand_env((char_u *)"~/", NameBuff, MAXPATHL);
len = (int)STRLEN(NameBuff);
STRLCPY(NameBuff + len, fm->fname + 2, MAXPATHL - len);
- } else
+ } else {
STRLCPY(NameBuff, fm->fname, MAXPATHL);
+ }
- /* Try to shorten the file name. */
+ // Try to shorten the file name.
os_dirname(IObuff, IOSIZE);
p = path_shorten_fname(NameBuff, IObuff);
@@ -513,14 +530,16 @@ static void fname2fnum(xfmark_T *fm)
*/
void fmarks_check_names(buf_T *buf)
{
- char_u *name = buf->b_ffname;
+ char_u *name = buf->b_ffname;
int i;
- if (buf->b_ffname == NULL)
+ if (buf->b_ffname == NULL) {
return;
+ }
- for (i = 0; i < NGLOBALMARKS; ++i)
+ for (i = 0; i < NGLOBALMARKS; ++i) {
fmarks_check_one(&namedfm[i], name, buf);
+ }
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
for (i = 0; i < wp->w_jumplistlen; ++i) {
@@ -552,8 +571,9 @@ int check_mark(pos_T *pos)
if (pos->lnum <= 0) {
/* lnum is negative if mark is in another file can can't get that
* file, error message already give then. */
- if (pos->lnum == 0)
+ if (pos->lnum == 0) {
EMSG(_(e_marknotset));
+ }
return FAIL;
}
if (pos->lnum > curbuf->b_ml.ml_line_count) {
@@ -593,8 +613,9 @@ void clrallmarks(buf_T *const buf)
*/
char_u *fm_getname(fmark_T *fmark, int lead_len)
{
- if (fmark->fnum == curbuf->b_fnum) /* current buffer */
+ if (fmark->fnum == curbuf->b_fnum) { // current buffer
return mark_line(&(fmark->mark), lead_len);
+ }
return buflist_nr2name(fmark->fnum, FALSE, TRUE);
}
@@ -604,11 +625,12 @@ char_u *fm_getname(fmark_T *fmark, int lead_len)
*/
static char_u *mark_line(pos_T *mp, int lead_len)
{
- char_u *s, *p;
+ char_u *s, *p;
int len;
- if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count)
+ if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count) {
return vim_strsave((char_u *)"-invalid-");
+ }
assert(Columns >= 0 && (size_t)Columns <= SIZE_MAX);
// Allow for up to 5 bytes per character.
s = vim_strnsave(skipwhite(ml_get(mp->lnum)), (size_t)Columns * 5);
@@ -617,8 +639,9 @@ static char_u *mark_line(pos_T *mp, int lead_len)
len = 0;
for (p = s; *p != NUL; MB_PTR_ADV(p)) {
len += ptr2cells(p);
- if (len >= Columns - lead_len)
+ if (len >= Columns - lead_len) {
break;
+ }
}
*p = NUL;
return s;
@@ -629,28 +652,32 @@ static char_u *mark_line(pos_T *mp, int lead_len)
*/
void ex_marks(exarg_T *eap)
{
- char_u *arg = eap->arg;
+ char_u *arg = eap->arg;
int i;
- char_u *name;
- pos_T *posp, *startp, *endp;
+ char_u *name;
+ pos_T *posp, *startp, *endp;
- if (arg != NULL && *arg == NUL)
+ if (arg != NULL && *arg == NUL) {
arg = NULL;
+ }
show_one_mark('\'', arg, &curwin->w_pcmark, NULL, true);
- for (i = 0; i < NMARKS; ++i)
+ for (i = 0; i < NMARKS; ++i) {
show_one_mark(i + 'a', arg, &curbuf->b_namedm[i].mark, NULL, true);
+ }
for (i = 0; i < NGLOBALMARKS; ++i) {
- if (namedfm[i].fmark.fnum != 0)
+ if (namedfm[i].fmark.fnum != 0) {
name = fm_getname(&namedfm[i].fmark, 15);
- else
+ } else {
name = namedfm[i].fname;
+ }
if (name != NULL) {
show_one_mark(i >= NMARKS ? i - NMARKS + '0' : i + 'A',
- arg, &namedfm[i].fmark.mark, name,
- namedfm[i].fmark.fnum == curbuf->b_fnum);
- if (namedfm[i].fmark.fnum != 0)
+ arg, &namedfm[i].fmark.mark, name,
+ namedfm[i].fmark.fnum == curbuf->b_fnum);
+ if (namedfm[i].fmark.fnum != 0) {
xfree(name);
+ }
}
}
show_one_mark('"', arg, &curbuf->b_last_cursor.mark, NULL, true);
@@ -673,14 +700,8 @@ void ex_marks(exarg_T *eap)
show_one_mark(-1, arg, NULL, NULL, false);
}
-static void
-show_one_mark(
- int c,
- char_u *arg,
- pos_T *p,
- char_u *name_arg,
- int current // in current file
-)
+/// @param current in current file
+static void show_one_mark(int c, char_u *arg, pos_T *p, char_u *name_arg, int current)
{
static bool did_title = false;
bool mustfree = false;
@@ -731,41 +752,42 @@ show_one_mark(
*/
void ex_delmarks(exarg_T *eap)
{
- char_u *p;
+ char_u *p;
int from, to;
int i;
int lower;
int digit;
int n;
- if (*eap->arg == NUL && eap->forceit)
- /* clear all marks */
+ if (*eap->arg == NUL && eap->forceit) {
+ // clear all marks
clrallmarks(curbuf);
- else if (eap->forceit)
+ } else if (eap->forceit) {
EMSG(_(e_invarg));
- else if (*eap->arg == NUL)
+ } else if (*eap->arg == NUL) {
EMSG(_(e_argreq));
- else {
- /* clear specified marks only */
+ } else {
+ // clear specified marks only
for (p = eap->arg; *p != NUL; ++p) {
lower = ASCII_ISLOWER(*p);
digit = ascii_isdigit(*p);
if (lower || digit || ASCII_ISUPPER(*p)) {
if (p[1] == '-') {
- /* clear range of marks */
+ // clear range of marks
from = *p;
to = p[2];
if (!(lower ? ASCII_ISLOWER(p[2])
- : (digit ? ascii_isdigit(p[2])
- : ASCII_ISUPPER(p[2])))
+ : (digit ? ascii_isdigit(p[2])
+ : ASCII_ISUPPER(p[2])))
|| to < from) {
EMSG2(_(e_invarg2), p);
return;
}
p += 2;
- } else
- /* clear one lower case mark */
+ } else {
+ // clear one lower case mark
from = to = *p;
+ }
for (i = from; i <= to; ++i) {
if (lower) {
@@ -781,19 +803,29 @@ void ex_delmarks(exarg_T *eap)
XFREE_CLEAR(namedfm[n].fname);
}
}
- } else
+ } else {
switch (*p) {
- case '"': CLEAR_FMARK(&curbuf->b_last_cursor); break;
- case '^': CLEAR_FMARK(&curbuf->b_last_insert); break;
- case '.': CLEAR_FMARK(&curbuf->b_last_change); break;
- case '[': curbuf->b_op_start.lnum = 0; break;
- case ']': curbuf->b_op_end.lnum = 0; break;
- case '<': curbuf->b_visual.vi_start.lnum = 0; break;
- case '>': curbuf->b_visual.vi_end.lnum = 0; break;
- case ' ': break;
- default: EMSG2(_(e_invarg2), p);
+ case '"':
+ CLEAR_FMARK(&curbuf->b_last_cursor); break;
+ case '^':
+ CLEAR_FMARK(&curbuf->b_last_insert); break;
+ case '.':
+ CLEAR_FMARK(&curbuf->b_last_change); break;
+ case '[':
+ curbuf->b_op_start.lnum = 0; break;
+ case ']':
+ curbuf->b_op_end.lnum = 0; break;
+ case '<':
+ curbuf->b_visual.vi_start.lnum = 0; break;
+ case '>':
+ curbuf->b_visual.vi_end.lnum = 0; break;
+ case ' ':
+ break;
+ default:
+ EMSG2(_(e_invarg2), p);
return;
}
+ }
}
}
}
@@ -804,7 +836,7 @@ void ex_delmarks(exarg_T *eap)
void ex_jumps(exarg_T *eap)
{
int i;
- char_u *name;
+ char_u *name;
cleanup_jumplist(curwin, true);
// Highlight title
@@ -825,11 +857,11 @@ void ex_jumps(exarg_T *eap)
break;
}
sprintf((char *)IObuff, "%c %2d %5ld %4d ",
- i == curwin->w_jumplistidx ? '>' : ' ',
- i > curwin->w_jumplistidx ? i - curwin->w_jumplistidx
- : curwin->w_jumplistidx - i,
- curwin->w_jumplist[i].fmark.mark.lnum,
- curwin->w_jumplist[i].fmark.mark.col);
+ i == curwin->w_jumplistidx ? '>' : ' ',
+ i > curwin->w_jumplistidx ? i - curwin->w_jumplistidx
+ : curwin->w_jumplistidx - i,
+ curwin->w_jumplist[i].fmark.mark.lnum,
+ curwin->w_jumplist[i].fmark.mark.col);
msg_outtrans(IObuff);
msg_outtrans_attr(name,
curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum
@@ -839,8 +871,9 @@ void ex_jumps(exarg_T *eap)
}
ui_flush();
}
- if (curwin->w_jumplistidx == curwin->w_jumplistlen)
+ if (curwin->w_jumplistidx == curwin->w_jumplistlen) {
MSG_PUTS("\n>");
+ }
}
void ex_clearjumps(exarg_T *eap)
@@ -856,7 +889,7 @@ void ex_clearjumps(exarg_T *eap)
void ex_changes(exarg_T *eap)
{
int i;
- char_u *name;
+ char_u *name;
// Highlight title
MSG_PUTS_TITLE(_("\nchange line col text"));
@@ -864,14 +897,15 @@ void ex_changes(exarg_T *eap)
for (i = 0; i < curbuf->b_changelistlen && !got_int; ++i) {
if (curbuf->b_changelist[i].mark.lnum != 0) {
msg_putchar('\n');
- if (got_int)
+ if (got_int) {
break;
+ }
sprintf((char *)IObuff, "%c %3d %5ld %4d ",
- i == curwin->w_changelistidx ? '>' : ' ',
- i > curwin->w_changelistidx ? i - curwin->w_changelistidx
- : curwin->w_changelistidx - i,
- (long)curbuf->b_changelist[i].mark.lnum,
- curbuf->b_changelist[i].mark.col);
+ i == curwin->w_changelistidx ? '>' : ' ',
+ i > curwin->w_changelistidx ? i - curwin->w_changelistidx
+ : curwin->w_changelistidx - i,
+ (long)curbuf->b_changelist[i].mark.lnum,
+ curbuf->b_changelist[i].mark.col);
msg_outtrans(IObuff);
name = mark_line(&curbuf->b_changelist[i].mark, 17);
msg_outtrans_attr(name, HL_ATTR(HLF_D));
@@ -880,8 +914,9 @@ void ex_changes(exarg_T *eap)
}
ui_flush();
}
- if (curwin->w_changelistidx == curbuf->b_changelistlen)
+ if (curwin->w_changelistidx == curbuf->b_changelistlen) {
MSG_PUTS("\n>");
+ }
}
#define one_adjust(add) \
@@ -890,27 +925,27 @@ void ex_changes(exarg_T *eap)
if (*lp >= line1 && *lp <= line2) \
{ \
if (amount == MAXLNUM) \
- *lp = 0; \
+ *lp = 0; \
else \
- *lp += amount; \
+ *lp += amount; \
} \
else if (amount_after && *lp > line2) \
- *lp += amount_after; \
+ *lp += amount_after; \
}
-/* don't delete the line, just put at first deleted line */
+// don't delete the line, just put at first deleted line
#define one_adjust_nodel(add) \
{ \
lp = add; \
if (*lp >= line1 && *lp <= line2) \
{ \
if (amount == MAXLNUM) \
- *lp = line1; \
+ *lp = line1; \
else \
- *lp += amount; \
+ *lp += amount; \
} \
else if (amount_after && *lp > line2) \
- *lp += amount_after; \
+ *lp += amount_after; \
}
/*
@@ -922,13 +957,9 @@ void ex_changes(exarg_T *eap)
* If 'amount_after' is non-zero adjust marks after line2.
* Example: Delete lines 34 and 35: mark_adjust(34, 35, MAXLNUM, -2);
* Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0);
- * or: mark_adjust(56, 55, MAXLNUM, 2);
+ * or: mark_adjust(56, 55, MAXLNUM, 2);
*/
-void mark_adjust(linenr_T line1,
- linenr_T line2,
- long amount,
- long amount_after,
- ExtmarkOp op)
+void mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after, ExtmarkOp op)
{
mark_adjust_internal(line1, line2, amount, amount_after, true, op);
}
@@ -938,54 +969,56 @@ void mark_adjust(linenr_T line1,
// This is only useful when folds need to be moved in a way different to
// calling foldMarkAdjust() with arguments line1, line2, amount, amount_after,
// for an example of why this may be necessary, see do_move().
-void mark_adjust_nofold(linenr_T line1, linenr_T line2, long amount,
- long amount_after,
+void mark_adjust_nofold(linenr_T line1, linenr_T line2, long amount, long amount_after,
ExtmarkOp op)
{
mark_adjust_internal(line1, line2, amount, amount_after, false, op);
}
-static void mark_adjust_internal(linenr_T line1, linenr_T line2,
- long amount, long amount_after,
- bool adjust_folds,
- ExtmarkOp op)
+static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, long amount_after,
+ bool adjust_folds, ExtmarkOp op)
{
int i;
int fnum = curbuf->b_fnum;
- linenr_T *lp;
+ linenr_T *lp;
static pos_T initpos = { 1, 0, 0 };
- if (line2 < line1 && amount_after == 0L) /* nothing to do */
+ if (line2 < line1 && amount_after == 0L) { // nothing to do
return;
+ }
if (!cmdmod.lockmarks) {
- /* named marks, lower case and upper case */
+ // named marks, lower case and upper case
for (i = 0; i < NMARKS; i++) {
one_adjust(&(curbuf->b_namedm[i].mark.lnum));
- if (namedfm[i].fmark.fnum == fnum)
+ if (namedfm[i].fmark.fnum == fnum) {
one_adjust_nodel(&(namedfm[i].fmark.mark.lnum));
+ }
}
for (i = NMARKS; i < NGLOBALMARKS; i++) {
- if (namedfm[i].fmark.fnum == fnum)
+ if (namedfm[i].fmark.fnum == fnum) {
one_adjust_nodel(&(namedfm[i].fmark.mark.lnum));
+ }
}
- /* last Insert position */
+ // last Insert position
one_adjust(&(curbuf->b_last_insert.mark.lnum));
- /* last change position */
+ // last change position
one_adjust(&(curbuf->b_last_change.mark.lnum));
- /* last cursor position, if it was set */
- if (!equalpos(curbuf->b_last_cursor.mark, initpos))
+ // last cursor position, if it was set
+ if (!equalpos(curbuf->b_last_cursor.mark, initpos)) {
one_adjust(&(curbuf->b_last_cursor.mark.lnum));
+ }
- /* list of change positions */
- for (i = 0; i < curbuf->b_changelistlen; ++i)
+ // list of change positions
+ for (i = 0; i < curbuf->b_changelistlen; ++i) {
one_adjust_nodel(&(curbuf->b_changelist[i].mark.lnum));
+ }
- /* Visual area */
+ // Visual area
one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum));
one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum));
@@ -1008,15 +1041,16 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
}
}
- /* previous context mark */
+ // previous context mark
one_adjust(&(curwin->w_pcmark.lnum));
- /* previous pcmark */
+ // previous pcmark
one_adjust(&(curwin->w_prev_pcmark.lnum));
- /* saved cursor for formatting */
- if (saved_cursor.lnum != 0)
+ // saved cursor for formatting
+ if (saved_cursor.lnum != 0) {
one_adjust_nodel(&(saved_cursor.lnum));
+ }
/*
* Adjust items in all windows related to the current buffer.
@@ -1034,7 +1068,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
if (win->w_buffer == curbuf) {
if (!cmdmod.lockmarks) {
- /* marks in the tag stack */
+ // marks in the tag stack
for (i = 0; i < win->w_tagstacklen; i++) {
if (win->w_tagstack[i].fmark.fnum == fnum) {
one_adjust_nodel(&(win->w_tagstack[i].fmark.mark.lnum));
@@ -1042,7 +1076,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
}
}
- /* the displayed Visual area */
+ // the displayed Visual area
if (win->w_old_cursor_lnum != 0) {
one_adjust_nodel(&(win->w_old_cursor_lnum));
one_adjust_nodel(&(win->w_old_visual_lnum));
@@ -1052,13 +1086,13 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
* other than the current window */
if (win != curwin) {
if (win->w_topline >= line1 && win->w_topline <= line2) {
- if (amount == MAXLNUM) { /* topline is deleted */
+ if (amount == MAXLNUM) { // topline is deleted
if (line1 <= 1) {
win->w_topline = 1;
} else {
win->w_topline = line1 - 1;
}
- } else { /* keep topline on the same line */
+ } else { // keep topline on the same line
win->w_topline += amount;
}
win->w_topfill = 0;
@@ -1067,14 +1101,14 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
win->w_topfill = 0;
}
if (win->w_cursor.lnum >= line1 && win->w_cursor.lnum <= line2) {
- if (amount == MAXLNUM) { /* line with cursor is deleted */
+ if (amount == MAXLNUM) { // line with cursor is deleted
if (line1 <= 1) {
win->w_cursor.lnum = 1;
} else {
win->w_cursor.lnum = line1 - 1;
}
win->w_cursor.col = 0;
- } else { /* keep cursor on the same line */
+ } else { // keep cursor on the same line
win->w_cursor.lnum += amount;
}
} else if (amount_after && win->w_cursor.lnum > line2) {
@@ -1088,11 +1122,11 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
}
}
- /* adjust diffs */
+ // adjust diffs
diff_mark_adjust(line1, line2, amount, amount_after);
}
-/* This code is used often, needs to be fast. */
+// This code is used often, needs to be fast.
#define col_adjust(pp) \
{ \
posp = pp; \
@@ -1115,56 +1149,58 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
// position.
// "spaces_removed" is the number of spaces that were removed, matters when the
// cursor is inside them.
-void mark_col_adjust(
- linenr_T lnum, colnr_T mincol, long lnum_amount, long col_amount,
- int spaces_removed)
+void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_amount,
+ int spaces_removed)
{
int i;
int fnum = curbuf->b_fnum;
- pos_T *posp;
+ pos_T *posp;
- if ((col_amount == 0L && lnum_amount == 0L) || cmdmod.lockmarks)
- return; /* nothing to do */
-
- /* named marks, lower case and upper case */
+ if ((col_amount == 0L && lnum_amount == 0L) || cmdmod.lockmarks) {
+ return; // nothing to do
+ }
+ // named marks, lower case and upper case
for (i = 0; i < NMARKS; i++) {
col_adjust(&(curbuf->b_namedm[i].mark));
- if (namedfm[i].fmark.fnum == fnum)
+ if (namedfm[i].fmark.fnum == fnum) {
col_adjust(&(namedfm[i].fmark.mark));
+ }
}
for (i = NMARKS; i < NGLOBALMARKS; i++) {
- if (namedfm[i].fmark.fnum == fnum)
+ if (namedfm[i].fmark.fnum == fnum) {
col_adjust(&(namedfm[i].fmark.mark));
+ }
}
- /* last Insert position */
+ // last Insert position
col_adjust(&(curbuf->b_last_insert.mark));
- /* last change position */
+ // last change position
col_adjust(&(curbuf->b_last_change.mark));
- /* list of change positions */
- for (i = 0; i < curbuf->b_changelistlen; ++i)
+ // list of change positions
+ for (i = 0; i < curbuf->b_changelistlen; ++i) {
col_adjust(&(curbuf->b_changelist[i].mark));
+ }
- /* Visual area */
+ // Visual area
col_adjust(&(curbuf->b_visual.vi_start));
col_adjust(&(curbuf->b_visual.vi_end));
- /* previous context mark */
+ // previous context mark
col_adjust(&(curwin->w_pcmark));
- /* previous pcmark */
+ // previous pcmark
col_adjust(&(curwin->w_prev_pcmark));
- /* saved cursor for formatting */
+ // saved cursor for formatting
col_adjust(&saved_cursor);
/*
* Adjust items in all windows related to the current buffer.
*/
FOR_ALL_WINDOWS_IN_TAB(win, curtab) {
- /* marks in the jumplist */
+ // marks in the jumplist
for (i = 0; i < win->w_jumplistlen; ++i) {
if (win->w_jumplist[i].fmark.fnum == fnum) {
col_adjust(&(win->w_jumplist[i].fmark.mark));
@@ -1172,14 +1208,14 @@ void mark_col_adjust(
}
if (win->w_buffer == curbuf) {
- /* marks in the tag stack */
+ // marks in the tag stack
for (i = 0; i < win->w_tagstacklen; i++) {
if (win->w_tagstack[i].fmark.fnum == fnum) {
col_adjust(&(win->w_tagstack[i].fmark.mark));
}
}
- /* cursor position for other windows with the same buffer */
+ // cursor position for other windows with the same buffer
if (win != curwin) {
col_adjust(&win->w_cursor);
}
@@ -1269,8 +1305,9 @@ void copy_jumplist(win_T *from, win_T *to)
for (i = 0; i < from->w_jumplistlen; ++i) {
to->w_jumplist[i] = from->w_jumplist[i];
- if (from->w_jumplist[i].fname != NULL)
+ if (from->w_jumplist[i].fname != NULL) {
to->w_jumplist[i].fname = vim_strsave(from->w_jumplist[i].fname);
+ }
}
to->w_jumplistlen = from->w_jumplistlen;
to->w_jumplistidx = from->w_jumplistidx;
@@ -1287,18 +1324,17 @@ void copy_jumplist(win_T *from, win_T *to)
///
/// @return Pointer that needs to be passed to next `mark_jumplist_iter` call or
/// NULL if iteration is over.
-const void *mark_jumplist_iter(const void *const iter, const win_T *const win,
- xfmark_T *const fm)
+const void *mark_jumplist_iter(const void *const iter, const win_T *const win, xfmark_T *const fm)
FUNC_ATTR_NONNULL_ARG(2, 3) FUNC_ATTR_WARN_UNUSED_RESULT
{
if (iter == NULL && win->w_jumplistlen == 0) {
- *fm = (xfmark_T) {{{0, 0, 0}, 0, 0, NULL}, NULL};
+ *fm = (xfmark_T) { { { 0, 0, 0 }, 0, 0, NULL }, NULL };
return NULL;
}
const xfmark_T *const iter_mark =
- (iter == NULL
+ (iter == NULL
? &(win->w_jumplist[0])
- : (const xfmark_T *const) iter);
+ : (const xfmark_T *const)iter);
*fm = *iter_mark;
if (iter_mark == &(win->w_jumplist[win->w_jumplistlen - 1])) {
return NULL;
@@ -1318,30 +1354,29 @@ const void *mark_jumplist_iter(const void *const iter, const win_T *const win,
///
/// @return Pointer that needs to be passed to next `mark_global_iter` call or
/// NULL if iteration is over.
-const void *mark_global_iter(const void *const iter, char *const name,
- xfmark_T *const fm)
+const void *mark_global_iter(const void *const iter, char *const name, xfmark_T *const fm)
FUNC_ATTR_NONNULL_ARG(2, 3) FUNC_ATTR_WARN_UNUSED_RESULT
{
*name = NUL;
const xfmark_T *iter_mark = (iter == NULL
? &(namedfm[0])
- : (const xfmark_T *const) iter);
- while ((size_t) (iter_mark - &(namedfm[0])) < ARRAY_SIZE(namedfm)
+ : (const xfmark_T *const)iter);
+ while ((size_t)(iter_mark - &(namedfm[0])) < ARRAY_SIZE(namedfm)
&& !iter_mark->fmark.mark.lnum) {
iter_mark++;
}
- if ((size_t) (iter_mark - &(namedfm[0])) == ARRAY_SIZE(namedfm)
+ if ((size_t)(iter_mark - &(namedfm[0])) == ARRAY_SIZE(namedfm)
|| !iter_mark->fmark.mark.lnum) {
return NULL;
}
- size_t iter_off = (size_t) (iter_mark - &(namedfm[0]));
- *name = (char) (iter_off < NMARKS
- ? 'A' + (char) iter_off
- : '0' + (char) (iter_off - NMARKS));
+ size_t iter_off = (size_t)(iter_mark - &(namedfm[0]));
+ *name = (char)(iter_off < NMARKS
+ ? 'A' + (char)iter_off
+ : '0' + (char)(iter_off - NMARKS));
*fm = *iter_mark;
- while ((size_t) (++iter_mark - &(namedfm[0])) < ARRAY_SIZE(namedfm)) {
+ while ((size_t)(++iter_mark - &(namedfm[0])) < ARRAY_SIZE(namedfm)) {
if (iter_mark->fmark.mark.lnum) {
- return (const void *) iter_mark;
+ return (const void *)iter_mark;
}
}
return NULL;
@@ -1358,34 +1393,27 @@ const void *mark_global_iter(const void *const iter, char *const name,
/// behaviour is undefined.
///
/// @return Pointer to the next mark or NULL.
-static inline const fmark_T *next_buffer_mark(const buf_T *const buf,
- char *const mark_name)
+static inline const fmark_T *next_buffer_mark(const buf_T *const buf, char *const mark_name)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
switch (*mark_name) {
- case NUL: {
- *mark_name = '"';
- return &(buf->b_last_cursor);
- }
- case '"': {
- *mark_name = '^';
- return &(buf->b_last_insert);
- }
- case '^': {
- *mark_name = '.';
- return &(buf->b_last_change);
- }
- case '.': {
- *mark_name = 'a';
- return &(buf->b_namedm[0]);
- }
- case 'z': {
- return NULL;
- }
- default: {
- (*mark_name)++;
- return &(buf->b_namedm[*mark_name - 'a']);
- }
+ case NUL:
+ *mark_name = '"';
+ return &(buf->b_last_cursor);
+ case '"':
+ *mark_name = '^';
+ return &(buf->b_last_insert);
+ case '^':
+ *mark_name = '.';
+ return &(buf->b_last_change);
+ case '.':
+ *mark_name = 'a';
+ return &(buf->b_namedm[0]);
+ case 'z':
+ return NULL;
+ default:
+ (*mark_name)++;
+ return &(buf->b_namedm[*mark_name - 'a']);
}
}
@@ -1401,12 +1429,12 @@ static inline const fmark_T *next_buffer_mark(const buf_T *const buf,
///
/// @return Pointer that needs to be passed to next `mark_buffer_iter` call or
/// NULL if iteration is over.
-const void *mark_buffer_iter(const void *const iter, const buf_T *const buf,
- char *const name, fmark_T *const fm)
+const void *mark_buffer_iter(const void *const iter, const buf_T *const buf, char *const name,
+ fmark_T *const fm)
FUNC_ATTR_NONNULL_ARG(2, 3, 4) FUNC_ATTR_WARN_UNUSED_RESULT
{
*name = NUL;
- char mark_name = (char) (iter == NULL
+ char mark_name = (char)(iter == NULL
? NUL
: (iter == &(buf->b_last_cursor)
? '"'
@@ -1414,8 +1442,8 @@ const void *mark_buffer_iter(const void *const iter, const buf_T *const buf,
? '^'
: (iter == &(buf->b_last_change)
? '.'
- : 'a' + (char) ((const fmark_T *)iter
- - &(buf->b_namedm[0]))))));
+ : 'a' + (char)((const fmark_T *)iter
+ - &(buf->b_namedm[0]))))));
const fmark_T *iter_mark = next_buffer_mark(buf, &mark_name);
while (iter_mark != NULL && iter_mark->mark.lnum == 0) {
iter_mark = next_buffer_mark(buf, &mark_name);
@@ -1423,14 +1451,14 @@ const void *mark_buffer_iter(const void *const iter, const buf_T *const buf,
if (iter_mark == NULL) {
return NULL;
}
- size_t iter_off = (size_t) (iter_mark - &(buf->b_namedm[0]));
+ size_t iter_off = (size_t)(iter_mark - &(buf->b_namedm[0]));
if (mark_name) {
*name = mark_name;
} else {
- *name = (char) ('a' + (char) iter_off);
+ *name = (char)('a' + (char)iter_off);
}
*fm = *iter_mark;
- return (const void *) iter_mark;
+ return (const void *)iter_mark;
}
/// Set global mark
@@ -1467,8 +1495,7 @@ bool mark_set_global(const char name, const xfmark_T fm, const bool update)
/// later then existing one.
///
/// @return true on success, false on failure.
-bool mark_set_local(const char name, buf_T *const buf,
- const fmark_T fm, const bool update)
+bool mark_set_local(const char name, buf_T *const buf, const fmark_T fm, const bool update)
FUNC_ATTR_NONNULL_ALL
{
fmark_T *fm_tgt = NULL;
@@ -1556,8 +1583,7 @@ void mark_mb_adjustpos(buf_T *buf, pos_T *lp)
// Add information about mark 'mname' to list 'l'
-static int add_mark(list_T *l, const char *mname, const pos_T *pos, int bufnr,
- const char *fname)
+static int add_mark(list_T *l, const char *mname, const pos_T *pos, int bufnr, const char *fname)
FUNC_ATTR_NONNULL_ARG(1, 2, 3)
{
if (pos->lnum <= 0) {
diff --git a/src/nvim/marktree.c b/src/nvim/marktree.c
index a04f250fc3..ebe4478bc8 100644
--- a/src/nvim/marktree.c
+++ b/src/nvim/marktree.c
@@ -49,9 +49,9 @@
#include <assert.h>
-#include "nvim/marktree.h"
-#include "nvim/lib/kvec.h"
#include "nvim/garray.h"
+#include "nvim/lib/kvec.h"
+#include "nvim/marktree.h"
#define T MT_BRANCH_FACTOR
#define ILEN (sizeof(mtnode_t)+(2 * T) * sizeof(void *))
@@ -137,7 +137,9 @@ static inline int marktree_getp_aux(const mtnode_t *x, mtkey_t k, int *r)
end = mid;
}
}
- if (begin == x->n) { *rr = 1; return x->n - 1; }
+ if (begin == x->n) {
+ *rr = 1; return x->n - 1;
+ }
if ((*rr = key_cmp(k, x->key[begin])) < 0) {
begin--;
}
@@ -232,9 +234,8 @@ uint64_t marktree_put(MarkTree *b, int row, int col, bool right_gravity)
return id;
}
-uint64_t marktree_put_pair(MarkTree *b,
- int start_row, int start_col, bool start_right,
- int end_row, int end_col, bool end_right)
+uint64_t marktree_put_pair(MarkTree *b, int start_row, int start_col, bool start_right, int end_row,
+ int end_col, bool end_right)
{
uint64_t id = (b->next_id+=ID_INCR)|PAIRED;
uint64_t start_id = id|(start_right?RIGHT_GRAVITY:0);
@@ -594,8 +595,8 @@ bool marktree_itr_get(MarkTree *b, int row, int col, MarkTreeIter *itr)
itr, false, false, NULL);
}
-bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr,
- bool last, bool gravity, mtpos_t *oldbase)
+bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr, bool last, bool gravity,
+ mtpos_t *oldbase)
{
mtkey_t k = { .pos = p, .id = gravity ? RIGHT_GRAVITY : 0 };
if (last && !gravity) {
@@ -695,8 +696,7 @@ bool marktree_itr_next(MarkTree *b, MarkTreeIter *itr)
return marktree_itr_next_skip(b, itr, false, NULL);
}
-static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip,
- mtpos_t oldbase[])
+static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip, mtpos_t oldbase[])
{
if (!itr->node) {
return false;
@@ -819,8 +819,8 @@ mtmark_t marktree_itr_current(MarkTreeIter *itr)
mtpos_t pos = marktree_itr_pos(itr);
mtmark_t mark = { .row = pos.row,
.col = pos.col,
- .id = ANTIGRAVITY(keyid),
- .right_gravity = keyid & RIGHT_GRAVITY };
+ .id = ANTIGRAVITY(keyid),
+ .right_gravity = keyid & RIGHT_GRAVITY };
return mark;
}
return (mtmark_t){ -1, -1, 0, false };
@@ -833,10 +833,8 @@ static void swap_id(uint64_t *id1, uint64_t *id2)
*id2 = temp;
}
-bool marktree_splice(MarkTree *b,
- int start_line, int start_col,
- int old_extent_line, int old_extent_col,
- int new_extent_line, int new_extent_col)
+bool marktree_splice(MarkTree *b, int start_line, int start_col, int old_extent_line,
+ int old_extent_col, int new_extent_line, int new_extent_col)
{
mtpos_t start = { start_line, start_col };
mtpos_t old_extent = { (int)old_extent_line, old_extent_col };
@@ -903,7 +901,7 @@ continue_same_node:
refkey(b, itr->node, itr->i);
refkey(b, enditr->node, enditr->i);
} else {
- past_right = true; // NOLINT
+ past_right = true; // NOLINT
(void)past_right;
break;
}
@@ -994,10 +992,8 @@ past_continue_same_node:
return moved;
}
-void marktree_move_region(MarkTree *b,
- int start_row, colnr_T start_col,
- int extent_row, colnr_T extent_col,
- int new_row, colnr_T new_col)
+void marktree_move_region(MarkTree *b, int start_row, colnr_T start_col, int extent_row,
+ colnr_T extent_col, int new_row, colnr_T new_col)
{
mtpos_t start = { start_row, start_col }, size = { extent_row, extent_col };
mtpos_t end = size;
@@ -1114,8 +1110,7 @@ void marktree_check(MarkTree *b)
}
#ifndef NDEBUG
-static size_t check_node(MarkTree *b, mtnode_t *x,
- mtpos_t *last, bool *last_right)
+static size_t check_node(MarkTree *b, mtnode_t *x, mtpos_t *last, bool *last_right)
{
assert(x->n <= 2 * T - 1);
// TODO(bfredl): too strict if checking "in repair" post-delete tree.
diff --git a/src/nvim/math.c b/src/nvim/math.c
index 63309b6f7a..791f1f9373 100644
--- a/src/nvim/math.c
+++ b/src/nvim/math.c
@@ -2,6 +2,7 @@
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <math.h>
+
#include <stdint.h>
#include <string.h>
@@ -21,9 +22,12 @@ int xfpclassify(double d)
m = 0xfffffffffffffULL & m;
switch (e) {
- default: return FP_NORMAL;
- case 0x000: return m ? FP_SUBNORMAL : FP_ZERO;
- case 0x7ff: return m ? FP_NAN : FP_INFINITE;
+ default:
+ return FP_NORMAL;
+ case 0x000:
+ return m ? FP_SUBNORMAL : FP_ZERO;
+ case 0x7ff:
+ return m ? FP_NAN : FP_INFINITE;
}
}
int xisinf(double d)
diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c
index 7bed644da3..438340e0c4 100644
--- a/src/nvim/memfile.c
+++ b/src/nvim/memfile.c
@@ -39,24 +39,24 @@
/// mf_fullname() make file name full path (use before first :cd)
#include <assert.h>
+#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
-#include <string.h>
#include <stdbool.h>
-#include <fcntl.h>
+#include <string.h>
-#include "nvim/vim.h"
#include "nvim/ascii.h"
-#include "nvim/memfile.h"
+#include "nvim/assert.h"
#include "nvim/fileio.h"
+#include "nvim/memfile.h"
#include "nvim/memline.h"
-#include "nvim/message.h"
#include "nvim/memory.h"
+#include "nvim/message.h"
+#include "nvim/os/input.h"
+#include "nvim/os/os.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
-#include "nvim/assert.h"
-#include "nvim/os/os.h"
-#include "nvim/os/input.h"
+#include "nvim/vim.h"
#define MEMFILE_PAGE_SIZE 4096 /// default page size
@@ -168,7 +168,7 @@ void mf_close(memfile_T *mfp, bool del_file)
return;
}
if (mfp->mf_fd >= 0 && close(mfp->mf_fd) < 0) {
- EMSG(_(e_swapclose));
+ EMSG(_(e_swapclose));
}
if (del_file && mfp->mf_fname != NULL) {
os_remove((char *)mfp->mf_fname);
@@ -282,14 +282,16 @@ bhdr_T *mf_new(memfile_T *mfp, bool negative, unsigned page_count)
bhdr_T *mf_get(memfile_T *mfp, blocknr_T nr, unsigned page_count)
{
// check block number exists
- if (nr >= mfp->mf_blocknr_max || nr <= mfp->mf_blocknr_min)
+ if (nr >= mfp->mf_blocknr_max || nr <= mfp->mf_blocknr_min) {
return NULL;
+ }
// see if it is in the cache
bhdr_T *hp = mf_find_hash(mfp, nr);
if (hp == NULL) { // not in the hash list
- if (nr < 0 || nr >= mfp->mf_infile_count) // can't be in the file
+ if (nr < 0 || nr >= mfp->mf_infile_count) { // can't be in the file
return NULL;
+ }
// could check here if the block is in the free list
@@ -331,8 +333,9 @@ void mf_put(memfile_T *mfp, bhdr_T *hp, bool dirty, bool infile)
mfp->mf_dirty = true;
}
hp->bh_flags = flags;
- if (infile)
+ if (infile) {
mf_trans_add(mfp, hp); // may translate negative in positive nr
+ }
}
/// Signal block as no longer used (may put it in the free list).
@@ -381,32 +384,38 @@ int mf_sync(memfile_T *mfp, int flags)
// fails then we give up.
int status = OK;
bhdr_T *hp;
- for (hp = mfp->mf_used_last; hp != NULL; hp = hp->bh_prev)
+ for (hp = mfp->mf_used_last; hp != NULL; hp = hp->bh_prev) {
if (((flags & MFS_ALL) || hp->bh_bnum >= 0)
&& (hp->bh_flags & BH_DIRTY)
&& (status == OK || (hp->bh_bnum >= 0
&& hp->bh_bnum < mfp->mf_infile_count))) {
- if ((flags & MFS_ZERO) && hp->bh_bnum != 0)
+ if ((flags & MFS_ZERO) && hp->bh_bnum != 0) {
continue;
+ }
if (mf_write(mfp, hp) == FAIL) {
- if (status == FAIL) // double error: quit syncing
+ if (status == FAIL) { // double error: quit syncing
break;
+ }
status = FAIL;
}
if (flags & MFS_STOP) { // Stop when char available now.
- if (os_char_avail())
+ if (os_char_avail()) {
break;
+ }
} else {
os_breakcheck();
}
- if (got_int)
+ if (got_int) {
break;
+ }
}
+ }
// If the whole list is flushed, the memfile is not dirty anymore.
// In case of an error, dirty flag is also set, to avoid trying all the time.
- if (hp == NULL || status == FAIL)
+ if (hp == NULL || status == FAIL) {
mfp->mf_dirty = false;
+ }
if (flags & MFS_FLUSH) {
if (os_fsync(mfp->mf_fd)) {
@@ -465,15 +474,17 @@ static void mf_ins_used(memfile_T *mfp, bhdr_T *hp)
/// Remove block from memfile's used list.
static void mf_rem_used(memfile_T *mfp, bhdr_T *hp)
{
- if (hp->bh_next == NULL) // last block in used list
+ if (hp->bh_next == NULL) { // last block in used list
mfp->mf_used_last = hp->bh_prev;
- else
+ } else {
hp->bh_next->bh_prev = hp->bh_prev;
+ }
- if (hp->bh_prev == NULL) // first block in used list
+ if (hp->bh_prev == NULL) { // first block in used list
mfp->mf_used_first = hp->bh_next;
- else
+ } else {
hp->bh_prev->bh_next = hp->bh_next;
+ }
}
/// Release as many blocks as possible.
@@ -554,8 +565,9 @@ static bhdr_T *mf_rem_free(memfile_T *mfp)
/// - Error reading file.
static int mf_read(memfile_T *mfp, bhdr_T *hp)
{
- if (mfp->mf_fd < 0) // there is no file, can't read
+ if (mfp->mf_fd < 0) { // there is no file, can't read
return FAIL;
+ }
unsigned page_size = mfp->mf_page_size;
// TODO(elmart): Check (page_size * hp->bh_bnum) within off_T bounds.
@@ -592,12 +604,15 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
unsigned page_count; // number of pages written
unsigned size; // number of bytes written
- if (mfp->mf_fd < 0) // there is no file, can't write
+ if (mfp->mf_fd < 0) { // there is no file, can't write
return FAIL;
+ }
- if (hp->bh_bnum < 0) // must assign file block number
- if (mf_trans_add(mfp, hp) == FAIL)
+ if (hp->bh_bnum < 0) { // must assign file block number
+ if (mf_trans_add(mfp, hp) == FAIL) {
return FAIL;
+ }
+ }
page_size = mfp->mf_page_size;
@@ -620,10 +635,11 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
PERROR(_("E296: Seek error in swap file write"));
return FAIL;
}
- if (hp2 == NULL) // freed block, fill with dummy data
+ if (hp2 == NULL) { // freed block, fill with dummy data
page_count = 1;
- else
+ } else {
page_count = hp2->bh_page_count;
+ }
size = page_size * page_count;
void *data = (hp2 == NULL) ? hp->bh_data : hp2->bh_data;
if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size) {
@@ -631,18 +647,22 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
/// disk is full. We give the message again only after a successful
/// write or when hitting a key. We keep on trying, in case some
/// space becomes available.
- if (!did_swapwrite_msg)
+ if (!did_swapwrite_msg) {
EMSG(_("E297: Write error in swap file"));
+ }
did_swapwrite_msg = true;
return FAIL;
}
did_swapwrite_msg = false;
- if (hp2 != NULL) // written a non-dummy block
+ if (hp2 != NULL) { // written a non-dummy block
hp2->bh_flags &= ~BH_DIRTY;
- if (nr + (blocknr_T)page_count > mfp->mf_infile_count) // appended to file
+ }
+ if (nr + (blocknr_T)page_count > mfp->mf_infile_count) { // appended to file
mfp->mf_infile_count = nr + page_count;
- if (nr == hp->bh_bnum) // written the desired block
+ }
+ if (nr == hp->bh_bnum) { // written the desired block
break;
+ }
}
return OK;
}
@@ -653,8 +673,9 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
/// FAIL On failure.
static int mf_trans_add(memfile_T *mfp, bhdr_T *hp)
{
- if (hp->bh_bnum >= 0) // it's already positive
+ if (hp->bh_bnum >= 0) { // it's already positive
return OK;
+ }
mf_blocknr_trans_item_T *np = xmalloc(sizeof(mf_blocknr_trans_item_T));
@@ -702,8 +723,9 @@ blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr)
mf_blocknr_trans_item_T *np =
(mf_blocknr_trans_item_T *)mf_hash_find(&mfp->mf_trans, old_nr);
- if (np == NULL) // not found
+ if (np == NULL) { // not found
return old_nr;
+ }
mfp->mf_neg_count--;
blocknr_T new_bnum = np->nt_new_bnum;
@@ -834,8 +856,9 @@ static void mf_hash_free_all(mf_hashtab_T *mht)
static mf_hashitem_T *mf_hash_find(mf_hashtab_T *mht, blocknr_T key)
{
mf_hashitem_T *mhi = mht->mht_buckets[(size_t)key & mht->mht_mask];
- while (mhi != NULL && mhi->mhi_key != key)
+ while (mhi != NULL && mhi->mhi_key != key) {
mhi = mhi->mhi_next;
+ }
return mhi;
}
@@ -845,8 +868,9 @@ static void mf_hash_add_item(mf_hashtab_T *mht, mf_hashitem_T *mhi)
size_t idx = (size_t)mhi->mhi_key & mht->mht_mask;
mhi->mhi_next = mht->mht_buckets[idx];
mhi->mhi_prev = NULL;
- if (mhi->mhi_next != NULL)
+ if (mhi->mhi_next != NULL) {
mhi->mhi_next->mhi_prev = mhi;
+ }
mht->mht_buckets[idx] = mhi;
mht->mht_count++;
@@ -861,14 +885,16 @@ static void mf_hash_add_item(mf_hashtab_T *mht, mf_hashitem_T *mhi)
/// Remove item from hashtable. Item must be non NULL and within hashtable.
static void mf_hash_rem_item(mf_hashtab_T *mht, mf_hashitem_T *mhi)
{
- if (mhi->mhi_prev == NULL)
+ if (mhi->mhi_prev == NULL) {
mht->mht_buckets[(size_t)mhi->mhi_key & mht->mht_mask] =
mhi->mhi_next;
- else
+ } else {
mhi->mhi_prev->mhi_next = mhi->mhi_next;
+ }
- if (mhi->mhi_next != NULL)
+ if (mhi->mhi_next != NULL) {
mhi->mhi_next->mhi_prev = mhi->mhi_prev;
+ }
mht->mht_count--;
@@ -884,8 +910,9 @@ static void mf_hash_grow(mf_hashtab_T *mht)
mf_hashitem_T **buckets = xcalloc(1, size);
int shift = 0;
- while ((mht->mht_mask >> shift) != 0)
+ while ((mht->mht_mask >> shift) != 0) {
shift++;
+ }
for (size_t i = 0; i <= mht->mht_mask; i++) {
/// Traverse the items in the i-th original bucket and move them into
@@ -914,13 +941,16 @@ static void mf_hash_grow(mf_hashtab_T *mht)
}
}
- for (size_t j = 0; j < MHT_GROWTH_FACTOR; j++)
- if (tails[j] != NULL)
+ for (size_t j = 0; j < MHT_GROWTH_FACTOR; j++) {
+ if (tails[j] != NULL) {
tails[j]->mhi_next = NULL;
+ }
+ }
}
- if (mht->mht_buckets != mht->mht_small_buckets)
+ if (mht->mht_buckets != mht->mht_small_buckets) {
xfree(mht->mht_buckets);
+ }
mht->mht_buckets = buckets;
mht->mht_mask = (mht->mht_mask + 1) * MHT_GROWTH_FACTOR - 1;
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index 4ccbb31e2c..69598bbdda 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -38,29 +38,31 @@
#include <assert.h>
#include <errno.h>
+#include <fcntl.h>
#include <inttypes.h>
-#include <string.h>
#include <stdbool.h>
-#include <fcntl.h>
+#include <string.h>
#include "nvim/ascii.h"
-#include "nvim/vim.h"
-#include "nvim/memline.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/cursor.h"
#include "nvim/eval.h"
-#include "nvim/getchar.h"
#include "nvim/fileio.h"
#include "nvim/func_attr.h"
+#include "nvim/getchar.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memfile.h"
+#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/option.h"
+#include "nvim/os/input.h"
+#include "nvim/os/os.h"
+#include "nvim/os/process.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/screen.h"
@@ -68,44 +70,42 @@
#include "nvim/spell.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
-#include "nvim/version.h"
#include "nvim/undo.h"
+#include "nvim/version.h"
+#include "nvim/vim.h"
#include "nvim/window.h"
-#include "nvim/os/os.h"
-#include "nvim/os/process.h"
-#include "nvim/os/input.h"
-#ifndef UNIX /* it's in os/unix_defs.h for Unix */
+#ifndef UNIX // it's in os/unix_defs.h for Unix
# include <time.h>
#endif
-typedef struct block0 ZERO_BL; /* contents of the first block */
-typedef struct pointer_block PTR_BL; /* contents of a pointer block */
-typedef struct data_block DATA_BL; /* contents of a data block */
-typedef struct pointer_entry PTR_EN; /* block/line-count pair */
+typedef struct block0 ZERO_BL; // contents of the first block
+typedef struct pointer_block PTR_BL; // contents of a pointer block
+typedef struct data_block DATA_BL; // contents of a data block
+typedef struct pointer_entry PTR_EN; // block/line-count pair
-#define DATA_ID (('d' << 8) + 'a') /* data block id */
-#define PTR_ID (('p' << 8) + 't') /* pointer block id */
-#define BLOCK0_ID0 'b' /* block 0 id 0 */
-#define BLOCK0_ID1 '0' /* block 0 id 1 */
+#define DATA_ID (('d' << 8) + 'a') // data block id
+#define PTR_ID (('p' << 8) + 't') // pointer block id
+#define BLOCK0_ID0 'b' // block 0 id 0
+#define BLOCK0_ID1 '0' // block 0 id 1
/*
* pointer to a block, used in a pointer block
*/
struct pointer_entry {
- blocknr_T pe_bnum; /* block number */
- linenr_T pe_line_count; /* number of lines in this branch */
- linenr_T pe_old_lnum; /* lnum for this block (for recovery) */
- int pe_page_count; /* number of pages in block pe_bnum */
+ blocknr_T pe_bnum; // block number
+ linenr_T pe_line_count; // number of lines in this branch
+ linenr_T pe_old_lnum; // lnum for this block (for recovery)
+ int pe_page_count; // number of pages in block pe_bnum
};
/*
* A pointer block contains a list of branches in the tree.
*/
struct pointer_block {
- uint16_t pb_id; /* ID for pointer block: PTR_ID */
- uint16_t pb_count; /* number of pointers in this block */
- uint16_t pb_count_max; /* maximum value for pb_count */
+ uint16_t pb_id; // ID for pointer block: PTR_ID
+ uint16_t pb_count; // number of pointers in this block
+ uint16_t pb_count_max; // maximum value for pb_count
PTR_EN pb_pointer[1]; /* list of pointers to blocks (actually longer)
* followed by empty space until end of page */
};
@@ -140,12 +140,12 @@ struct data_block {
#define DB_MARKED ((unsigned)1 << ((sizeof(unsigned) * 8) - 1))
#define DB_INDEX_MASK (~DB_MARKED)
-#define INDEX_SIZE (sizeof(unsigned)) /* size of one db_index entry */
-#define HEADER_SIZE (sizeof(DATA_BL) - INDEX_SIZE) /* size of data block header */
+#define INDEX_SIZE (sizeof(unsigned)) // size of one db_index entry
+#define HEADER_SIZE (sizeof(DATA_BL) - INDEX_SIZE) // size of data block header
-#define B0_FNAME_SIZE_ORG 900 /* what it was in older versions */
-#define B0_FNAME_SIZE_NOCRYPT 898 /* 2 bytes used for other things */
-#define B0_FNAME_SIZE_CRYPT 890 /* 10 bytes used for other things */
+#define B0_FNAME_SIZE_ORG 900 // what it was in older versions
+#define B0_FNAME_SIZE_NOCRYPT 898 // 2 bytes used for other things
+#define B0_FNAME_SIZE_CRYPT 890 // 10 bytes used for other things
#define B0_UNAME_SIZE 40
#define B0_HNAME_SIZE 40
/*
@@ -172,18 +172,18 @@ struct data_block {
*/
struct block0 {
char_u b0_id[2]; ///< ID for block 0: BLOCK0_ID0 and BLOCK0_ID1.
- char_u b0_version[10]; /* Vim version string */
- char_u b0_page_size[4]; /* number of bytes per page */
- char_u b0_mtime[4]; /* last modification time of file */
- char_u b0_ino[4]; /* inode of b0_fname */
- char_u b0_pid[4]; /* process id of creator (or 0) */
- char_u b0_uname[B0_UNAME_SIZE]; /* name of user (uid if no name) */
- char_u b0_hname[B0_HNAME_SIZE]; /* host name (if it has a name) */
- char_u b0_fname[B0_FNAME_SIZE_ORG]; /* name of file being edited */
- long b0_magic_long; /* check for byte order of long */
- int b0_magic_int; /* check for byte order of int */
- short b0_magic_short; /* check for byte order of short */
- char_u b0_magic_char; /* check for last char */
+ char_u b0_version[10]; // Vim version string
+ char_u b0_page_size[4]; // number of bytes per page
+ char_u b0_mtime[4]; // last modification time of file
+ char_u b0_ino[4]; // inode of b0_fname
+ char_u b0_pid[4]; // process id of creator (or 0)
+ char_u b0_uname[B0_UNAME_SIZE]; // name of user (uid if no name)
+ char_u b0_hname[B0_HNAME_SIZE]; // host name (if it has a name)
+ char_u b0_fname[B0_FNAME_SIZE_ORG]; // name of file being edited
+ long b0_magic_long; // check for byte order of long
+ int b0_magic_int; // check for byte order of int
+ short b0_magic_short; // check for byte order of short
+ char_u b0_magic_char; // check for last char
};
/*
@@ -213,7 +213,7 @@ struct block0 {
* When empty there is only the NUL. */
#define B0_HAS_FENC 8
-#define STACK_INCR 5 /* nr of entries added to ml_stack at a time */
+#define STACK_INCR 5 // nr of entries added to ml_stack at a time
/*
* The line number where the first mark may be is remembered.
@@ -226,16 +226,16 @@ static linenr_T lowest_marked = 0;
/*
* arguments for ml_find_line()
*/
-#define ML_DELETE 0x11 /* delete line */
-#define ML_INSERT 0x12 /* insert line */
-#define ML_FIND 0x13 /* just find the line */
-#define ML_FLUSH 0x02 /* flush locked block */
-#define ML_SIMPLE(x) (x & 0x10) /* DEL, INS or FIND */
+#define ML_DELETE 0x11 // delete line
+#define ML_INSERT 0x12 // insert line
+#define ML_FIND 0x13 // just find the line
+#define ML_FLUSH 0x02 // flush locked block
+#define ML_SIMPLE(x) (x & 0x10) // DEL, INS or FIND
-/* argument for ml_upd_block0() */
+// argument for ml_upd_block0()
typedef enum {
- UB_FNAME = 0 /* update timestamp and filename */
- , UB_SAME_DIR /* update the B0_SAME_DIR flag */
+ UB_FNAME = 0 // update timestamp and filename
+ , UB_SAME_DIR // update the B0_SAME_DIR flag
} upd_block0_T;
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -249,10 +249,10 @@ typedef enum {
*/
int ml_open(buf_T *buf)
{
- bhdr_T *hp = NULL;
- ZERO_BL *b0p;
- PTR_BL *pp;
- DATA_BL *dp;
+ bhdr_T *hp = NULL;
+ ZERO_BL *b0p;
+ PTR_BL *pp;
+ DATA_BL *dp;
/*
* init fields in memline struct
@@ -307,7 +307,7 @@ int ml_open(buf_T *buf)
b0p->b0_magic_int = (int)B0_MAGIC_INT;
b0p->b0_magic_short = (short)B0_MAGIC_SHORT;
b0p->b0_magic_char = B0_MAGIC_CHAR;
- xstrlcpy(xstpcpy((char *) b0p->b0_version, "VIM "), Version, 6);
+ xstrlcpy(xstpcpy((char *)b0p->b0_version, "VIM "), Version, 6);
long_to_char((long)mfp->mf_page_size, b0p->b0_page_size);
if (!buf->b_spell) {
@@ -329,14 +329,16 @@ int ml_open(buf_T *buf)
* is created.
*/
mf_put(mfp, hp, true, false);
- if (!buf->b_help && !B_SPELL(buf))
+ if (!buf->b_help && !B_SPELL(buf)) {
(void)mf_sync(mfp, 0);
+ }
/*
* Fill in root pointer block and write page 1.
*/
- if ((hp = ml_new_ptr(mfp)) == NULL)
+ if ((hp = ml_new_ptr(mfp)) == NULL) {
goto error;
+ }
if (hp->bh_bnum != 1) {
IEMSG(_("E298: Didn't get block nr 1?"));
goto error;
@@ -346,7 +348,7 @@ int ml_open(buf_T *buf)
pp->pb_pointer[0].pe_bnum = 2;
pp->pb_pointer[0].pe_page_count = 1;
pp->pb_pointer[0].pe_old_lnum = 1;
- pp->pb_pointer[0].pe_line_count = 1; /* line count after insertion */
+ pp->pb_pointer[0].pe_line_count = 1; // line count after insertion
mf_put(mfp, hp, true, false);
/*
@@ -359,10 +361,10 @@ int ml_open(buf_T *buf)
}
dp = hp->bh_data;
- dp->db_index[0] = --dp->db_txt_start; /* at end of block */
+ dp->db_index[0] = --dp->db_txt_start; // at end of block
dp->db_free -= 1 + INDEX_SIZE;
dp->db_line_count = 1;
- *((char_u *)dp + dp->db_txt_start) = NUL; /* empty line */
+ *((char_u *)dp + dp->db_txt_start) = NUL; // empty line
return OK;
@@ -384,18 +386,18 @@ error:
void ml_setname(buf_T *buf)
{
bool success = false;
- memfile_T *mfp;
- char_u *fname;
- char_u *dirp;
+ memfile_T *mfp;
+ char_u *fname;
+ char_u *dirp;
mfp = buf->b_ml.ml_mfp;
- if (mfp->mf_fd < 0) { /* there is no swap file yet */
+ if (mfp->mf_fd < 0) { // there is no swap file yet
/*
* When 'updatecount' is 0 and 'noswapfile' there is no swap file.
* For help files we will make a swap file now.
*/
if (p_uc != 0 && !cmdmod.noswapfile) {
- ml_open_file(buf); /* create a swap file */
+ ml_open_file(buf); // create a swap file
}
return;
}
@@ -406,29 +408,32 @@ void ml_setname(buf_T *buf)
dirp = p_dir;
bool found_existing_dir = false;
for (;; ) {
- if (*dirp == NUL) /* tried all directories, fail */
+ if (*dirp == NUL) { // tried all directories, fail
break;
+ }
fname = (char_u *)findswapname(buf, (char **)&dirp, (char *)mfp->mf_fname,
&found_existing_dir);
- /* alloc's fname */
- if (dirp == NULL) /* out of memory */
+ // alloc's fname
+ if (dirp == NULL) { // out of memory
break;
- if (fname == NULL) /* no file name found for this dir */
+ }
+ if (fname == NULL) { // no file name found for this dir
continue;
+ }
- /* if the file name is the same we don't have to do anything */
+ // if the file name is the same we don't have to do anything
if (fnamecmp(fname, mfp->mf_fname) == 0) {
xfree(fname);
success = true;
break;
}
- /* need to close the swap file before renaming */
+ // need to close the swap file before renaming
if (mfp->mf_fd >= 0) {
close(mfp->mf_fd);
mfp->mf_fd = -1;
}
- /* try to rename the swap file */
+ // try to rename the swap file
if (vim_rename(mfp->mf_fname, fname) == 0) {
success = true;
mf_free_fnames(mfp);
@@ -436,20 +441,21 @@ void ml_setname(buf_T *buf)
ml_upd_block0(buf, UB_SAME_DIR);
break;
}
- xfree(fname); /* this fname didn't work, try another */
+ xfree(fname); // this fname didn't work, try another
}
- if (mfp->mf_fd == -1) { /* need to (re)open the swap file */
+ if (mfp->mf_fd == -1) { // need to (re)open the swap file
mfp->mf_fd = os_open((char *)mfp->mf_fname, O_RDWR, 0);
if (mfp->mf_fd < 0) {
- /* could not (re)open the swap file, what can we do???? */
+ // could not (re)open the swap file, what can we do????
EMSG(_("E301: Oops, lost the swap file!!!"));
return;
}
(void)os_set_cloexec(mfp->mf_fd);
}
- if (!success)
+ if (!success) {
EMSG(_("E302: Could not rename swap file"));
+ }
}
/*
@@ -473,21 +479,22 @@ void ml_open_files(void)
*/
void ml_open_file(buf_T *buf)
{
- memfile_T *mfp;
- char_u *fname;
- char_u *dirp;
+ memfile_T *mfp;
+ char_u *fname;
+ char_u *dirp;
mfp = buf->b_ml.ml_mfp;
if (mfp == NULL || mfp->mf_fd >= 0 || !buf->b_p_swf || cmdmod.noswapfile
|| buf->terminal) {
- return; /* nothing to do */
+ return; // nothing to do
}
- /* For a spell buffer use a temp file name. */
+ // For a spell buffer use a temp file name.
if (buf->b_spell) {
fname = vim_tempname();
- if (fname != NULL)
- (void)mf_open_file(mfp, fname); /* consumes fname! */
+ if (fname != NULL) {
+ (void)mf_open_file(mfp, fname); // consumes fname!
+ }
buf->b_may_swap = false;
return;
}
@@ -498,21 +505,24 @@ void ml_open_file(buf_T *buf)
dirp = p_dir;
bool found_existing_dir = false;
for (;; ) {
- if (*dirp == NUL)
+ if (*dirp == NUL) {
break;
+ }
// There is a small chance that between choosing the swap file name
// and creating it, another Vim creates the file. In that case the
// creation will fail and we will use another directory.
fname = (char_u *)findswapname(buf, (char **)&dirp, NULL,
&found_existing_dir);
- if (dirp == NULL)
- break; /* out of memory */
- if (fname == NULL)
+ if (dirp == NULL) {
+ break; // out of memory
+ }
+ if (fname == NULL) {
continue;
- if (mf_open_file(mfp, fname) == OK) { /* consumes fname! */
+ }
+ if (mf_open_file(mfp, fname) == OK) { // consumes fname!
ml_upd_block0(buf, UB_SAME_DIR);
- /* Flush block zero, so others can read it */
+ // Flush block zero, so others can read it
if (mf_sync(mfp, MFS_ZERO) == OK) {
/* Mark all blocks that should be in the swapfile as dirty.
* Needed for when the 'swapfile' option was reset, so that
@@ -520,7 +530,7 @@ void ml_open_file(buf_T *buf)
mf_set_dirty(mfp);
break;
}
- /* Writing block 0 failed: close the file and try another dir */
+ // Writing block 0 failed: close the file and try another dir
mf_close_file(buf, false);
}
}
@@ -528,13 +538,12 @@ void ml_open_file(buf_T *buf)
if (*p_dir != NUL && mfp->mf_fname == NULL) {
need_wait_return = true; // call wait_return later
no_wait_return++;
- (void)EMSG2(_(
- "E303: Unable to open swap file for \"%s\", recovery impossible"),
- buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname);
+ (void)EMSG2(_("E303: Unable to open swap file for \"%s\", recovery impossible"),
+ buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname);
--no_wait_return;
}
- /* don't try to open a swap file again */
+ // don't try to open a swap file again
buf->b_may_swap = false;
}
@@ -560,11 +569,13 @@ void check_need_swap(bool newfile)
*/
void ml_close(buf_T *buf, int del_file)
{
- if (buf->b_ml.ml_mfp == NULL) /* not open */
+ if (buf->b_ml.ml_mfp == NULL) { // not open
return;
- mf_close(buf->b_ml.ml_mfp, del_file); /* close the .swp file */
- if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY))
+ }
+ mf_close(buf->b_ml.ml_mfp, del_file); // close the .swp file
+ if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY)) {
xfree(buf->b_ml.ml_line_ptr);
+ }
xfree(buf->b_ml.ml_stack);
XFREE_CLEAR(buf->b_ml.ml_chunksize);
buf->b_ml.ml_mfp = NULL;
@@ -585,8 +596,8 @@ void ml_close_all(int del_file)
FOR_ALL_BUFFERS(buf) {
ml_close(buf, del_file && ((buf->b_flags & BF_PRESERVED) == 0));
}
- spell_delete_wordlist(); /* delete the internal wordlist */
- vim_deltempdir(); /* delete created temp directory */
+ spell_delete_wordlist(); // delete the internal wordlist
+ vim_deltempdir(); // delete created temp directory
}
/*
@@ -597,7 +608,7 @@ void ml_close_notmod(void)
{
FOR_ALL_BUFFERS(buf) {
if (!bufIsChanged(buf)) {
- ml_close(buf, TRUE); /* close all not-modified buffers */
+ ml_close(buf, TRUE); // close all not-modified buffers
}
}
}
@@ -633,13 +644,14 @@ static bool ml_check_b0_strings(ZERO_BL *b0p)
*/
static void ml_upd_block0(buf_T *buf, upd_block0_T what)
{
- memfile_T *mfp;
- bhdr_T *hp;
- ZERO_BL *b0p;
+ memfile_T *mfp;
+ bhdr_T *hp;
+ ZERO_BL *b0p;
mfp = buf->b_ml.ml_mfp;
- if (mfp == NULL || (hp = mf_get(mfp, 0, 1)) == NULL)
+ if (mfp == NULL || (hp = mf_get(mfp, 0, 1)) == NULL) {
return;
+ }
b0p = hp->bh_data;
if (ml_check_b0_id(b0p) == FAIL) {
IEMSG(_("E304: ml_upd_block0(): Didn't get block 0??"));
@@ -660,9 +672,9 @@ static void ml_upd_block0(buf_T *buf, upd_block0_T what)
*/
static void set_b0_fname(ZERO_BL *b0p, buf_T *buf)
{
- if (buf->b_ffname == NULL)
+ if (buf->b_ffname == NULL) {
b0p->b0_fname[0] = NUL;
- else {
+ } else {
char uname[B0_UNAME_SIZE];
/*
@@ -673,9 +685,9 @@ static void set_b0_fname(ZERO_BL *b0p, buf_T *buf)
* Then insert the user name to get "~user/".
*/
home_replace(NULL, buf->b_ffname, b0p->b0_fname,
- B0_FNAME_SIZE_CRYPT, TRUE);
+ B0_FNAME_SIZE_CRYPT, TRUE);
if (b0p->b0_fname[0] == '~') {
- /* If there is no user name or it is too long, don't use "~/" */
+ // If there is no user name or it is too long, don't use "~/"
int retval = os_get_user_name(uname, B0_UNAME_SIZE);
size_t ulen = STRLEN(uname);
size_t flen = STRLEN(b0p->b0_fname);
@@ -702,7 +714,7 @@ static void set_b0_fname(ZERO_BL *b0p, buf_T *buf)
}
}
- /* Also add the 'fileencoding' if there is room. */
+ // Also add the 'fileencoding' if there is room.
add_b0_fenc(b0p, curbuf);
}
@@ -714,10 +726,11 @@ static void set_b0_fname(ZERO_BL *b0p, buf_T *buf)
*/
static void set_b0_dir_flag(ZERO_BL *b0p, buf_T *buf)
{
- if (same_directory(buf->b_ml.ml_mfp->mf_fname, buf->b_ffname))
+ if (same_directory(buf->b_ml.ml_mfp->mf_fname, buf->b_ffname)) {
b0p->b0_flags |= B0_SAME_DIR;
- else
+ } else {
b0p->b0_flags &= ~B0_SAME_DIR;
+ }
}
/*
@@ -729,11 +742,11 @@ static void add_b0_fenc(ZERO_BL *b0p, buf_T *buf)
int size = B0_FNAME_SIZE_NOCRYPT;
n = (int)STRLEN(buf->b_p_fenc);
- if ((int)STRLEN(b0p->b0_fname) + n + 1 > size)
+ if ((int)STRLEN(b0p->b0_fname) + n + 1 > size) {
b0p->b0_flags &= ~B0_HAS_FENC;
- else {
+ } else {
memmove((char *)b0p->b0_fname + size - n,
- (char *)buf->b_p_fenc, (size_t)n);
+ (char *)buf->b_p_fenc, (size_t)n);
*(b0p->b0_fname + size - n - 1) = NUL;
b0p->b0_flags |= B0_HAS_FENC;
}
@@ -745,23 +758,23 @@ static void add_b0_fenc(ZERO_BL *b0p, buf_T *buf)
/// swap file.
void ml_recover(bool checkext)
{
- buf_T *buf = NULL;
- memfile_T *mfp = NULL;
- char_u *fname;
- char_u *fname_used = NULL;
- bhdr_T *hp = NULL;
- ZERO_BL *b0p;
+ buf_T *buf = NULL;
+ memfile_T *mfp = NULL;
+ char_u *fname;
+ char_u *fname_used = NULL;
+ bhdr_T *hp = NULL;
+ ZERO_BL *b0p;
int b0_ff;
- char_u *b0_fenc = NULL;
- PTR_BL *pp;
- DATA_BL *dp;
- infoptr_T *ip;
+ char_u *b0_fenc = NULL;
+ PTR_BL *pp;
+ DATA_BL *dp;
+ infoptr_T *ip;
blocknr_T bnum;
int page_count;
int len;
bool directly;
linenr_T lnum;
- char_u *p;
+ char_u *p;
int i;
long error;
bool cannot_open;
@@ -784,8 +797,9 @@ void ml_recover(bool checkext)
// If the file name ends in ".s[a-w][a-z]" we assume this is the swap file.
// Otherwise a search is done to find the swap file(s).
fname = curbuf->b_fname;
- if (fname == NULL) /* When there is no file name */
+ if (fname == NULL) { // When there is no file name
fname = (char_u *)"";
+ }
len = (int)STRLEN(fname);
if (checkext && len >= 4
&& STRNICMP(fname + len - 4, ".s", 2) == 0
@@ -797,32 +811,34 @@ void ml_recover(bool checkext)
} else {
directly = false;
- /* count the number of matching swap files */
+ // count the number of matching swap files
len = recover_names(fname, FALSE, 0, NULL);
- if (len == 0) { /* no swap files found */
+ if (len == 0) { // no swap files found
EMSG2(_("E305: No swap file found for %s"), fname);
goto theend;
}
- if (len == 1) /* one swap file found, use it */
+ if (len == 1) { // one swap file found, use it
i = 1;
- else { /* several swap files found, choose */
- /* list the names of the swap files */
+ } else { // several swap files found, choose
+ // list the names of the swap files
(void)recover_names(fname, TRUE, 0, NULL);
msg_putchar('\n');
MSG_PUTS(_("Enter number of swap file to use (0 to quit): "));
i = get_number(FALSE, NULL);
- if (i < 1 || i > len)
+ if (i < 1 || i > len) {
goto theend;
+ }
}
- /* get the swap file name that will be used */
+ // get the swap file name that will be used
(void)recover_names(fname, FALSE, i, &fname_used);
}
- if (fname_used == NULL)
+ if (fname_used == NULL) {
goto theend; // user chose invalid number.
-
- /* When called from main() still need to initialize storage structure */
- if (called_from_main && ml_open(curbuf) == FAIL)
+ }
+ // When called from main() still need to initialize storage structure
+ if (called_from_main && ml_open(curbuf) == FAIL) {
getout(1);
+ }
/*
* Allocate a buffer structure for the swap file that is used for recovery.
@@ -869,9 +885,8 @@ void ml_recover(bool checkext)
msg_start();
MSG_PUTS_ATTR(_("Unable to read block 0 from "), attr | MSG_HIST);
msg_outtrans_attr(mfp->mf_fname, attr | MSG_HIST);
- MSG_PUTS_ATTR(_(
- "\nMaybe no changes were made or Vim did not update the swap file."),
- attr | MSG_HIST);
+ MSG_PUTS_ATTR(_("\nMaybe no changes were made or Vim did not update the swap file."),
+ attr | MSG_HIST);
msg_end();
goto theend;
}
@@ -880,7 +895,7 @@ void ml_recover(bool checkext)
msg_start();
msg_outtrans_attr(mfp->mf_fname, MSG_HIST);
MSG_PUTS_ATTR(_(" cannot be used with this version of Vim.\n"),
- MSG_HIST);
+ MSG_HIST);
MSG_PUTS_ATTR(_("Use Vim version 3.0.\n"), MSG_HIST);
msg_end();
goto theend;
@@ -893,9 +908,9 @@ void ml_recover(bool checkext)
msg_start();
msg_outtrans_attr(mfp->mf_fname, attr | MSG_HIST);
MSG_PUTS_ATTR(_(" cannot be used on this computer.\n"),
- attr | MSG_HIST);
+ attr | MSG_HIST);
MSG_PUTS_ATTR(_("The file was created on "), attr | MSG_HIST);
- /* avoid going past the end of a corrupted hostname */
+ // avoid going past the end of a corrupted hostname
b0p->b0_fname[0] = NUL;
MSG_PUTS_ATTR(b0p->b0_hname, attr | MSG_HIST);
MSG_PUTS_ATTR(_(",\nor the file has been damaged."), attr | MSG_HIST);
@@ -914,9 +929,8 @@ void ml_recover(bool checkext)
if (mfp->mf_page_size < previous_page_size) {
msg_start();
msg_outtrans_attr(mfp->mf_fname, attr | MSG_HIST);
- MSG_PUTS_ATTR(_(
- " has been damaged (page size is smaller than minimum value).\n"),
- attr | MSG_HIST);
+ MSG_PUTS_ATTR(_(" has been damaged (page size is smaller than minimum value).\n"),
+ attr | MSG_HIST);
msg_end();
goto theend;
}
@@ -927,7 +941,7 @@ void ml_recover(bool checkext)
}
mfp->mf_infile_count = mfp->mf_blocknr_max;
- /* need to reallocate the memory used to store the data */
+ // need to reallocate the memory used to store the data
p = xmalloc(mfp->mf_page_size);
memmove(p, hp->bh_data, previous_page_size);
xfree(hp->bh_data);
@@ -948,10 +962,11 @@ void ml_recover(bool checkext)
home_replace(NULL, mfp->mf_fname, NameBuff, MAXPATHL, TRUE);
smsg(_("Using swap file \"%s\""), NameBuff);
- if (buf_spname(curbuf) != NULL)
+ if (buf_spname(curbuf) != NULL) {
STRLCPY(NameBuff, buf_spname(curbuf), MAXPATHL);
- else
+ } else {
home_replace(NULL, curbuf->b_ffname, NameBuff, MAXPATHL, TRUE);
+ }
smsg(_("Original file \"%s\""), NameBuff);
msg_putchar('\n');
@@ -965,13 +980,13 @@ void ml_recover(bool checkext)
&& os_fileinfo((char *)curbuf->b_ffname, &org_file_info)
&& ((os_fileinfo((char *)mfp->mf_fname, &swp_file_info)
&& org_file_info.stat.st_mtim.tv_sec
- > swp_file_info.stat.st_mtim.tv_sec)
+ > swp_file_info.stat.st_mtim.tv_sec)
|| org_file_info.stat.st_mtim.tv_sec != mtime)) {
EMSG(_("E308: Warning: Original file may have been changed"));
}
ui_flush();
- /* Get the 'fileformat' and 'fileencoding' from block zero. */
+ // Get the 'fileformat' and 'fileencoding' from block zero.
b0_ff = (b0p->b0_flags & B0_FF_MASK);
if (b0p->b0_flags & B0_HAS_FENC) {
int fnsize = B0_FNAME_SIZE_NOCRYPT;
@@ -981,7 +996,7 @@ void ml_recover(bool checkext)
b0_fenc = vim_strnsave(p, b0p->b0_fname + fnsize - p);
}
- mf_put(mfp, hp, false, false); /* release block 0 */
+ mf_put(mfp, hp, false, false); // release block 0
hp = NULL;
/*
@@ -996,28 +1011,30 @@ void ml_recover(bool checkext)
* Try reading the original file to obtain the values of 'fileformat',
* 'fileencoding', etc. Ignore errors. The text itself is not used.
*/
- if (curbuf->b_ffname != NULL)
+ if (curbuf->b_ffname != NULL) {
orig_file_status = readfile(curbuf->b_ffname, NULL, (linenr_T)0,
- (linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW);
+ (linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW);
+ }
- /* Use the 'fileformat' and 'fileencoding' as stored in the swap file. */
- if (b0_ff != 0)
+ // Use the 'fileformat' and 'fileencoding' as stored in the swap file.
+ if (b0_ff != 0) {
set_fileformat(b0_ff - 1, OPT_LOCAL);
+ }
if (b0_fenc != NULL) {
set_option_value("fenc", 0L, (char *)b0_fenc, OPT_LOCAL);
xfree(b0_fenc);
}
unchanged(curbuf, true, true);
- bnum = 1; /* start with block 1 */
- page_count = 1; /* which is 1 page */
- lnum = 0; /* append after line 0 in curbuf */
+ bnum = 1; // start with block 1
+ page_count = 1; // which is 1 page
+ lnum = 0; // append after line 0 in curbuf
line_count = 0;
- idx = 0; /* start with first index in block 1 */
+ idx = 0; // start with first index in block 1
error = 0;
buf->b_ml.ml_stack_top = 0;
buf->b_ml.ml_stack = NULL;
- buf->b_ml.ml_stack_size = 0; /* no stack yet */
+ buf->b_ml.ml_stack_size = 0; // no stack yet
if (curbuf->b_ffname == NULL) {
cannot_open = true;
@@ -1027,9 +1044,9 @@ void ml_recover(bool checkext)
serious_error = false;
for (; !got_int; line_breakcheck()) {
- if (hp != NULL)
- mf_put(mfp, hp, false, false); /* release previous block */
-
+ if (hp != NULL) {
+ mf_put(mfp, hp, false, false); // release previous block
+ }
/*
* get block
*/
@@ -1043,11 +1060,12 @@ void ml_recover(bool checkext)
(colnr_T)0, true);
} else { // there is a block
pp = hp->bh_data;
- if (pp->pb_id == PTR_ID) { /* it is a pointer block */
- /* check line count when using pointer block first time */
+ if (pp->pb_id == PTR_ID) { // it is a pointer block
+ // check line count when using pointer block first time
if (idx == 0 && line_count != 0) {
- for (i = 0; i < (int)pp->pb_count; ++i)
+ for (i = 0; i < (int)pp->pb_count; ++i) {
line_count -= pp->pb_pointer[i].pe_line_count;
+ }
if (line_count != 0) {
++error;
ml_append(lnum++, (char_u *)_("???LINE COUNT WRONG"),
@@ -1081,7 +1099,7 @@ void ml_recover(bool checkext)
ml_append(lnum++, (char_u *)_("???LINES MISSING"),
(colnr_T)0, true);
}
- ++idx; /* get same block again for next index */
+ ++idx; // get same block again for next index
continue;
}
@@ -1099,12 +1117,12 @@ void ml_recover(bool checkext)
idx = 0;
continue;
}
- } else { /* not a pointer block */
+ } else { // not a pointer block
dp = hp->bh_data;
- if (dp->db_id != DATA_ID) { /* block id wrong */
+ if (dp->db_id != DATA_ID) { // block id wrong
if (bnum == 1) {
EMSG2(_("E310: Block 1 ID wrong (%s not a .swp file?)"),
- mfp->mf_fname);
+ mfp->mf_fname);
goto theend;
}
++error;
@@ -1117,17 +1135,16 @@ void ml_recover(bool checkext)
// check length of block
// if wrong, use length in pointer block
if (page_count * mfp->mf_page_size != dp->db_txt_end) {
- ml_append(
- lnum++,
- (char_u *)_("??? from here until ???END lines"
- " may be messed up"),
- (colnr_T)0, true);
+ ml_append(lnum++,
+ (char_u *)_("??? from here until ???END lines"
+ " may be messed up"),
+ (colnr_T)0, true);
error++;
has_error = true;
dp->db_txt_end = page_count * mfp->mf_page_size;
}
- /* make sure there is a NUL at the end of the block */
+ // make sure there is a NUL at the end of the block
*((char_u *)dp + dp->db_txt_end - 1) = NUL;
/*
@@ -1135,11 +1152,10 @@ void ml_recover(bool checkext)
* if wrong, use count in data block
*/
if (line_count != dp->db_line_count) {
- ml_append(
- lnum++,
- (char_u *)_("??? from here until ???END lines"
- " may have been inserted/deleted"),
- (colnr_T)0, true);
+ ml_append(lnum++,
+ (char_u *)_("??? from here until ???END lines"
+ " may have been inserted/deleted"),
+ (colnr_T)0, true);
error++;
has_error = true;
}
@@ -1150,8 +1166,9 @@ void ml_recover(bool checkext)
|| txt_start >= (int)dp->db_txt_end) {
p = (char_u *)"???";
++error;
- } else
+ } else {
p = (char_u *)dp + txt_start;
+ }
ml_append(lnum++, p, (colnr_T)0, true);
}
if (has_error) {
@@ -1161,15 +1178,16 @@ void ml_recover(bool checkext)
}
}
- if (buf->b_ml.ml_stack_top == 0) /* finished */
+ if (buf->b_ml.ml_stack_top == 0) { // finished
break;
+ }
/*
* go one block up in the tree
*/
ip = &(buf->b_ml.ml_stack[--(buf->b_ml.ml_stack_top)]);
bnum = ip->ip_bnum;
- idx = ip->ip_index + 1; /* go to next index */
+ idx = ip->ip_index + 1; // go to next index
page_count = 1;
}
@@ -1189,7 +1207,7 @@ void ml_recover(bool checkext)
}
} else {
for (idx = 1; idx <= lnum; ++idx) {
- /* Need to copy one line, fetching the other one may flush it. */
+ // Need to copy one line, fetching the other one may flush it.
p = vim_strsave(ml_get(idx));
i = STRCMP(p, ml_get(idx + lnum));
xfree(p);
@@ -1206,30 +1224,30 @@ void ml_recover(bool checkext)
* empty buffer. These will now be after the last line in the buffer.
*/
while (curbuf->b_ml.ml_line_count > lnum
- && !(curbuf->b_ml.ml_flags & ML_EMPTY))
+ && !(curbuf->b_ml.ml_flags & ML_EMPTY)) {
ml_delete(curbuf->b_ml.ml_line_count, false);
+ }
curbuf->b_flags |= BF_RECOVERED;
check_cursor();
recoverymode = FALSE;
- if (got_int)
+ if (got_int) {
EMSG(_("E311: Recovery Interrupted"));
- else if (error) {
+ } else if (error) {
++no_wait_return;
MSG(">>>>>>>>>>>>>");
- EMSG(_(
- "E312: Errors detected while recovering; look for lines starting with ???"));
+ EMSG(_( "E312: Errors detected while recovering; look for lines starting with ???"));
--no_wait_return;
MSG(_("See \":help E312\" for more information."));
MSG(">>>>>>>>>>>>>");
} else {
if (curbuf->b_changed) {
MSG(_("Recovery completed. You should check if everything is OK."));
- MSG_PUTS(_(
- "\n(You might want to write out this file under another name\n"));
+ MSG_PUTS(_("\n(You might want to write out this file under another name\n"));
MSG_PUTS(_("and run diff with the original file to check for changes)"));
- } else
+ } else {
MSG(_("Recovery completed. Buffer contents equals file contents."));
+ }
MSG_PUTS(_("\nYou may want to delete the .swp file now.\n\n"));
cmdline_row = msg_row;
}
@@ -1239,51 +1257,49 @@ theend:
xfree(fname_used);
recoverymode = FALSE;
if (mfp != NULL) {
- if (hp != NULL)
+ if (hp != NULL) {
mf_put(mfp, hp, false, false);
- mf_close(mfp, false); /* will also xfree(mfp->mf_fname) */
+ }
+ mf_close(mfp, false); // will also xfree(mfp->mf_fname)
}
if (buf != NULL) { //may be NULL if swap file not found.
xfree(buf->b_ml.ml_stack);
xfree(buf);
}
- if (serious_error && called_from_main)
+ if (serious_error && called_from_main) {
ml_close(curbuf, TRUE);
- else {
+ } else {
apply_autocmds(EVENT_BUFREADPOST, NULL, curbuf->b_fname, FALSE, curbuf);
apply_autocmds(EVENT_BUFWINENTER, NULL, curbuf->b_fname, FALSE, curbuf);
}
return;
}
-/*
- * Find the names of swap files in current directory and the directory given
- * with the 'directory' option.
- *
- * Used to:
- * - list the swap files for "vim -r"
- * - count the number of swap files when recovering
- * - list the swap files when recovering
- * - find the name of the n'th swap file when recovering
- */
-int
-recover_names (
- char_u *fname, /* base for swap file name */
- int list, /* when TRUE, list the swap file names */
- int nr, /* when non-zero, return nr'th swap file name */
- char_u **fname_out /* result when "nr" > 0 */
-)
+/// Find the names of swap files in current directory and the directory given
+/// with the 'directory' option.
+///
+/// Used to:
+/// - list the swap files for "vim -r"
+/// - count the number of swap files when recovering
+/// - list the swap files when recovering
+/// - find the name of the n'th swap file when recovering
+///
+/// @param fname base for swap file name
+/// @param list when TRUE, list the swap file names
+/// @param nr when non-zero, return nr'th swap file name
+/// @param fname_out result when "nr" > 0
+int recover_names(char_u *fname, int list, int nr, char_u **fname_out)
{
int num_names;
- char_u *(names[6]);
- char_u *tail;
- char_u *p;
+ char_u *(names[6]);
+ char_u *tail;
+ char_u *p;
int num_files;
int file_count = 0;
- char_u **files;
- char_u *dirp;
- char_u *dir_name;
- char_u *fname_res = NULL;
+ char_u **files;
+ char_u *dirp;
+ char_u *dir_name;
+ char_u *fname_res = NULL;
#ifdef HAVE_READLINK
char_u fname_buf[MAXPATHL];
#endif
@@ -1292,15 +1308,15 @@ recover_names (
#ifdef HAVE_READLINK
/* Expand symlink in the file name, because the swap file is created
* with the actual file instead of with the symlink. */
- if (resolve_symlink(fname, fname_buf) == OK)
+ if (resolve_symlink(fname, fname_buf) == OK) {
fname_res = fname_buf;
- else
+ } else
#endif
fname_res = fname;
}
if (list) {
- /* use msg() to start the scrolling properly */
+ // use msg() to start the scrolling properly
msg((char_u *)_("Swap files found:"));
msg_putchar('\n');
}
@@ -1315,7 +1331,7 @@ recover_names (
// Advance dirp to next directory name.
(void)copy_option_part(&dirp, dir_name, 31000, ",");
- if (dir_name[0] == '.' && dir_name[1] == NUL) { /* check current dir */
+ if (dir_name[0] == '.' && dir_name[1] == NUL) { // check current dir
if (fname == NULL) {
names[0] = vim_strsave((char_u *)"*.sw?");
/* For Unix names starting with a dot are special. MS-Windows
@@ -1323,9 +1339,10 @@ recover_names (
names[1] = vim_strsave((char_u *)".*.sw?");
names[2] = vim_strsave((char_u *)".sw?");
num_names = 3;
- } else
+ } else {
num_names = recov_file_names(names, fname_res, TRUE);
- } else { /* check directory dir_name */
+ }
+ } else { // check directory dir_name
if (fname == NULL) {
names[0] = (char_u *)concat_fnames((char *)dir_name, "*.sw?", TRUE);
/* For Unix names starting with a dot are special. MS-Windows
@@ -1351,11 +1368,12 @@ recover_names (
}
}
- if (num_names == 0)
+ if (num_names == 0) {
num_files = 0;
- else if (expand_wildcards(num_names, names, &num_files, &files,
- EW_KEEPALL|EW_FILE|EW_SILENT) == FAIL)
+ } else if (expand_wildcards(num_names, names, &num_files, &files,
+ EW_KEEPALL|EW_FILE|EW_SILENT) == FAIL) {
num_files = 0;
+ }
/*
* When no swap file found, wildcard expansion might have failed (e.g.
@@ -1388,27 +1406,29 @@ recover_names (
// down. When the array becomes empty free it here, since
// FreeWild() won't be called below.
xfree(files[i]);
- if (--num_files == 0)
+ if (--num_files == 0) {
xfree(files);
- else
- for (; i < num_files; ++i)
+ } else {
+ for (; i < num_files; ++i) {
files[i] = files[i + 1];
+ }
+ }
}
}
}
if (nr > 0) {
file_count += num_files;
if (nr <= file_count) {
- *fname_out = vim_strsave(
- files[nr - 1 + num_files - file_count]);
- dirp = (char_u *)""; /* stop searching */
+ *fname_out = vim_strsave(files[nr - 1 + num_files - file_count]);
+ dirp = (char_u *)""; // stop searching
}
} else if (list) {
if (dir_name[0] == '.' && dir_name[1] == NUL) {
- if (fname == NULL)
+ if (fname == NULL) {
MSG_PUTS(_(" In current directory:\n"));
- else
+ } else {
MSG_PUTS(_(" Using specified name:\n"));
+ }
} else {
MSG_PUTS(_(" In directory "));
msg_home_replace(dir_name);
@@ -1417,23 +1437,27 @@ recover_names (
if (num_files) {
for (int i = 0; i < num_files; ++i) {
- /* print the swap file name */
+ // print the swap file name
msg_outnum((long)++file_count);
msg_puts(". ");
msg_puts((const char *)path_tail(files[i]));
msg_putchar('\n');
(void)swapfile_info(files[i]);
}
- } else
+ } else {
MSG_PUTS(_(" -- none --\n"));
+ }
ui_flush();
- } else
+ } else {
file_count += num_files;
+ }
- for (int i = 0; i < num_names; ++i)
+ for (int i = 0; i < num_names; ++i) {
xfree(names[i]);
- if (num_files > 0)
+ }
+ if (num_files > 0) {
FreeWild(num_files, files);
+ }
}
xfree(dir_name);
return file_count;
@@ -1544,10 +1568,11 @@ static time_t swapfile_info(char_u *fname)
MSG_PUTS(_(" [garbled strings (not nul terminated)]"));
} else {
MSG_PUTS(_(" file name: "));
- if (b0.b0_fname[0] == NUL)
+ if (b0.b0_fname[0] == NUL) {
MSG_PUTS(_("[No Name]"));
- else
+ } else {
msg_outtrans(b0.b0_fname);
+ }
MSG_PUTS(_("\n modified: "));
MSG_PUTS(b0.b0_dirty ? _("YES") : _("no"));
@@ -1558,10 +1583,11 @@ static time_t swapfile_info(char_u *fname)
}
if (*(b0.b0_hname) != NUL) {
- if (*(b0.b0_uname) != NUL)
+ if (*(b0.b0_uname) != NUL) {
MSG_PUTS(_(" host name: "));
- else
+ } else {
MSG_PUTS(_("\n host name: "));
+ }
msg_outtrans(b0.b0_hname);
}
@@ -1578,11 +1604,13 @@ static time_t swapfile_info(char_u *fname)
MSG_PUTS(_("\n [not usable on this computer]"));
}
}
- } else
+ } else {
MSG_PUTS(_(" [cannot be read]"));
+ }
close(fd);
- } else
+ } else {
MSG_PUTS(_(" [cannot be opened]"));
+ }
msg_putchar('\n');
return x;
@@ -1650,18 +1678,20 @@ static int recov_file_names(char_u **names, char_u *path, int prepend_dot)
// Form the normal swap file name pattern by appending ".sw?".
names[num_names] = (char_u *)concat_fnames((char *)path, ".sw?", FALSE);
- if (num_names >= 1) { /* check if we have the same name twice */
+ if (num_names >= 1) { // check if we have the same name twice
char_u *p = names[num_names - 1];
int i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]);
- if (i > 0)
- p += i; /* file name has been expanded to full path */
-
- if (STRCMP(p, names[num_names]) != 0)
+ if (i > 0) {
+ p += i; // file name has been expanded to full path
+ }
+ if (STRCMP(p, names[num_names]) != 0) {
++num_names;
- else
+ } else {
xfree(names[num_names]);
- } else
+ }
+ } else {
++num_names;
+ }
return num_names;
}
@@ -1676,11 +1706,11 @@ static int recov_file_names(char_u **names, char_u *path, int prepend_dot)
void ml_sync_all(int check_file, int check_char, bool do_fsync)
{
FOR_ALL_BUFFERS(buf) {
- if (buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp->mf_fname == NULL)
- continue; /* no file */
-
- ml_flush_line(buf); /* flush buffered line */
- /* flush locked block */
+ if (buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp->mf_fname == NULL) {
+ continue; // no file
+ }
+ ml_flush_line(buf); // flush buffered line
+ // flush locked block
(void)ml_find_line(buf, (linenr_T)0, ML_FLUSH);
if (bufIsChanged(buf) && check_file && mf_need_trans(buf->b_ml.ml_mfp)
&& buf->b_ffname != NULL) {
@@ -1719,15 +1749,16 @@ void ml_sync_all(int check_file, int check_char, bool do_fsync)
*/
void ml_preserve(buf_T *buf, int message, bool do_fsync)
{
- bhdr_T *hp;
+ bhdr_T *hp;
linenr_T lnum;
- memfile_T *mfp = buf->b_ml.ml_mfp;
+ memfile_T *mfp = buf->b_ml.ml_mfp;
int status;
int got_int_save = got_int;
if (mfp == NULL || mfp->mf_fname == NULL) {
- if (message)
+ if (message) {
EMSG(_("E313: Cannot preserve, there is no swap file"));
+ }
return;
}
@@ -1739,7 +1770,7 @@ void ml_preserve(buf_T *buf, int message, bool do_fsync)
(void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); // flush locked block
status = mf_sync(mfp, MFS_ALL | (do_fsync ? MFS_FLUSH : 0));
- /* stack is invalid after mf_sync(.., MFS_ALL) */
+ // stack is invalid after mf_sync(.., MFS_ALL)
buf->b_ml.ml_stack_top = 0;
/*
@@ -1776,10 +1807,11 @@ theend:
got_int |= got_int_save;
if (message) {
- if (status == OK)
+ if (status == OK) {
MSG(_("File preserved"));
- else
+ } else {
EMSG(_("E314: Preserve failed"));
+ }
}
}
@@ -1787,7 +1819,7 @@ theend:
* NOTE: The pointer returned by the ml_get_*() functions only remains valid
* until the next call!
* line1 = ml_get(1);
- * line2 = ml_get(2); // line1 is now invalid!
+ * line2 = ml_get(2); // line1 is now invalid!
* Make a copy of the line if necessary.
*/
/*
@@ -1810,26 +1842,18 @@ char_u *ml_get_pos(const pos_T *pos)
return ml_get_buf(curbuf, pos->lnum, false) + pos->col;
}
-/*
- * Return a pointer to a line in a specific buffer
- *
- * "will_change": if TRUE mark the buffer dirty (chars in the line will be
- * changed)
- */
-char_u *
-ml_get_buf (
- buf_T *buf,
- linenr_T lnum,
- bool will_change // line will be changed
-)
+/// Return a pointer to a line in a specific buffer
+///
+/// @param will_change true mark the buffer dirty (chars in the line will be changed)
+char_u *ml_get_buf(buf_T *buf, linenr_T lnum, bool will_change)
FUNC_ATTR_NONNULL_ALL
{
- bhdr_T *hp;
- DATA_BL *dp;
- char_u *ptr;
+ bhdr_T *hp;
+ DATA_BL *dp;
+ char_u *ptr;
static int recursive = 0;
- if (lnum > buf->b_ml.ml_line_count) { /* invalid line number */
+ if (lnum > buf->b_ml.ml_line_count) { // invalid line number
if (recursive == 0) {
// Avoid giving this message for a recursive call, may happen when
// the GUI redraws part of the text.
@@ -1841,11 +1865,13 @@ errorret:
STRCPY(IObuff, "???");
return IObuff;
}
- if (lnum <= 0) /* pretend line 0 is line 1 */
+ if (lnum <= 0) { // pretend line 0 is line 1
lnum = 1;
+ }
- if (buf->b_ml.ml_mfp == NULL) /* there are no lines */
+ if (buf->b_ml.ml_mfp == NULL) { // there are no lines
return (char_u *)"";
+ }
/*
* See if it is the same line as requested last time.
@@ -1900,88 +1926,89 @@ int ml_line_alloced(void)
return curbuf->b_ml.ml_flags & ML_LINE_DIRTY;
}
-/*
- * Append a line after lnum (may be 0 to insert a line in front of the file).
- * "line" does not need to be allocated, but can't be another line in a
- * buffer, unlocking may make it invalid.
- *
- * newfile: TRUE when starting to edit a new file, meaning that pe_old_lnum
- * will be set for recovery
- * Check: The caller of this function should probably also call
- * appended_lines().
- *
- * return FAIL for failure, OK otherwise
- */
-int ml_append(
- linenr_T lnum, // append after this line (can be 0)
- char_u *line, // text of the new line
- colnr_T len, // length of new line, including NUL, or 0
- bool newfile // flag, see above
-)
+/// Append a line after lnum (may be 0 to insert a line in front of the file).
+/// "line" does not need to be allocated, but can't be another line in a
+/// buffer, unlocking may make it invalid.
+///
+/// newfile: TRUE when starting to edit a new file, meaning that pe_old_lnum
+/// will be set for recovery
+/// Check: The caller of this function should probably also call
+/// appended_lines().
+///
+/// @param lnum append after this line (can be 0)
+/// @param line text of the new line
+/// @param len length of new line, including NUL, or 0
+/// @param newfile flag, see above
+///
+/// @return FAIL for failure, OK otherwise
+int ml_append(linenr_T lnum, char_u *line, colnr_T len, bool newfile)
{
- /* When starting up, we might still need to create the memfile */
- if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL)
+ // When starting up, we might still need to create the memfile
+ if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) {
return FAIL;
+ }
- if (curbuf->b_ml.ml_line_lnum != 0)
+ if (curbuf->b_ml.ml_line_lnum != 0) {
ml_flush_line(curbuf);
+ }
return ml_append_int(curbuf, lnum, line, len, newfile, FALSE);
}
-/*
- * Like ml_append() but for an arbitrary buffer. The buffer must already have
- * a memline.
- */
-int ml_append_buf(
- buf_T *buf,
- linenr_T lnum, // append after this line (can be 0)
- char_u *line, // text of the new line
- colnr_T len, // length of new line, including NUL, or 0
- bool newfile // flag, see above
-)
+/// Like ml_append() but for an arbitrary buffer. The buffer must already have
+/// a memline.
+///
+/// @param lnum append after this line (can be 0)
+/// @param line text of the new line
+/// @param len length of new line, including NUL, or 0
+/// @param newfile flag, see above
+int ml_append_buf(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, bool newfile)
FUNC_ATTR_NONNULL_ARG(1)
{
- if (buf->b_ml.ml_mfp == NULL)
+ if (buf->b_ml.ml_mfp == NULL) {
return FAIL;
+ }
- if (buf->b_ml.ml_line_lnum != 0)
+ if (buf->b_ml.ml_line_lnum != 0) {
ml_flush_line(buf);
+ }
return ml_append_int(buf, lnum, line, len, newfile, FALSE);
}
-static int ml_append_int(
- buf_T *buf,
- linenr_T lnum, // append after this line (can be 0)
- char_u *line, // text of the new line
- colnr_T len, // length of line, including NUL, or 0
- bool newfile, // flag, see above
- int mark // mark the new line
-)
+/// @param lnum append after this line (can be 0)
+/// @param line text of the new line
+/// @param len length of line, including NUL, or 0
+/// @param newfile flag, see above
+/// @param mark mark the new line
+static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, bool newfile,
+ int mark)
{
int i;
- int line_count; /* number of indexes in current block */
+ int line_count; // number of indexes in current block
int offset;
int from, to;
- int space_needed; /* space needed for new line */
+ int space_needed; // space needed for new line
int page_size;
int page_count;
- int db_idx; /* index for lnum in data block */
- bhdr_T *hp;
- memfile_T *mfp;
- DATA_BL *dp;
- PTR_BL *pp;
- infoptr_T *ip;
-
- /* lnum out of range */
- if (lnum > buf->b_ml.ml_line_count || buf->b_ml.ml_mfp == NULL)
+ int db_idx; // index for lnum in data block
+ bhdr_T *hp;
+ memfile_T *mfp;
+ DATA_BL *dp;
+ PTR_BL *pp;
+ infoptr_T *ip;
+
+ // lnum out of range
+ if (lnum > buf->b_ml.ml_line_count || buf->b_ml.ml_mfp == NULL) {
return FAIL;
+ }
- if (lowest_marked && lowest_marked > lnum)
+ if (lowest_marked && lowest_marked > lnum) {
lowest_marked = lnum + 1;
+ }
- if (len == 0)
- len = (colnr_T)STRLEN(line) + 1; /* space needed for the text */
- space_needed = len + INDEX_SIZE; /* space needed for text + index */
+ if (len == 0) {
+ len = (colnr_T)STRLEN(line) + 1; // space needed for the text
+ }
+ space_needed = len + INDEX_SIZE; // space needed for text + index
mfp = buf->b_ml.ml_mfp;
page_size = mfp->mf_page_size;
@@ -1992,16 +2019,18 @@ static int ml_append_int(
* This also releases any locked block.
*/
if ((hp = ml_find_line(buf, lnum == 0 ? (linenr_T)1 : lnum,
- ML_INSERT)) == NULL)
+ ML_INSERT)) == NULL) {
return FAIL;
+ }
buf->b_ml.ml_flags &= ~ML_EMPTY;
- if (lnum == 0) /* got line one instead, correct db_idx */
- db_idx = -1; /* careful, it is negative! */
- else
+ if (lnum == 0) { // got line one instead, correct db_idx
+ db_idx = -1; // careful, it is negative!
+ } else {
db_idx = lnum - buf->b_ml.ml_locked_low;
- /* get line count before the insertion */
+ }
+ // get line count before the insertion
line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low;
dp = hp->bh_data;
@@ -2022,11 +2051,12 @@ static int ml_append_int(
*/
--(buf->b_ml.ml_locked_lineadd);
--(buf->b_ml.ml_locked_high);
- if ((hp = ml_find_line(buf, lnum + 1, ML_INSERT)) == NULL)
+ if ((hp = ml_find_line(buf, lnum + 1, ML_INSERT)) == NULL) {
return FAIL;
+ }
- db_idx = -1; /* careful, it is negative! */
- /* get line count before the insertion */
+ db_idx = -1; // careful, it is negative!
+ // get line count before the insertion
line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low;
CHECK(buf->b_ml.ml_locked_low != lnum + 1, "locked_low != lnum + 1");
@@ -2035,7 +2065,7 @@ static int ml_append_int(
++buf->b_ml.ml_line_count;
- if ((int)dp->db_free >= space_needed) { /* enough room in data block */
+ if ((int)dp->db_free >= space_needed) { // enough room in data block
/*
* Insert new line in existing data block, or in data block allocated above.
*/
@@ -2047,38 +2077,43 @@ static int ml_append_int(
* move the text of the lines that follow to the front
* adjust the indexes of the lines that follow
*/
- if (line_count > db_idx + 1) { /* if there are following lines */
+ if (line_count > db_idx + 1) { // if there are following lines
/*
* Offset is the start of the previous line.
* This will become the character just after the new line.
*/
- if (db_idx < 0)
+ if (db_idx < 0) {
offset = dp->db_txt_end;
- else
+ } else {
offset = ((dp->db_index[db_idx]) & DB_INDEX_MASK);
+ }
memmove((char *)dp + dp->db_txt_start,
- (char *)dp + dp->db_txt_start + len,
- (size_t)(offset - (dp->db_txt_start + len)));
- for (i = line_count - 1; i > db_idx; --i)
+ (char *)dp + dp->db_txt_start + len,
+ (size_t)(offset - (dp->db_txt_start + len)));
+ for (i = line_count - 1; i > db_idx; --i) {
dp->db_index[i + 1] = dp->db_index[i] - len;
+ }
dp->db_index[db_idx + 1] = offset - len;
- } else /* add line at the end */
+ } else { // add line at the end
dp->db_index[db_idx + 1] = dp->db_txt_start;
+ }
/*
* copy the text into the block
*/
memmove((char *)dp + dp->db_index[db_idx + 1], line, (size_t)len);
- if (mark)
+ if (mark) {
dp->db_index[db_idx + 1] |= DB_MARKED;
+ }
/*
* Mark the block dirty.
*/
buf->b_ml.ml_flags |= ML_LOCKED_DIRTY;
- if (!newfile)
+ if (!newfile) {
buf->b_ml.ml_flags |= ML_LOCKED_POS;
- } else { /* not enough space in data block */
+ }
+ } else { // not enough space in data block
/*
* If there is not enough room we have to create a new data block and copy some
* lines into it.
@@ -2090,20 +2125,20 @@ static int ml_append_int(
*/
long line_count_left, line_count_right;
int page_count_left, page_count_right;
- bhdr_T *hp_left;
- bhdr_T *hp_right;
- bhdr_T *hp_new;
+ bhdr_T *hp_left;
+ bhdr_T *hp_right;
+ bhdr_T *hp_new;
int lines_moved;
- int data_moved = 0; /* init to shut up gcc */
- int total_moved = 0; /* init to shut up gcc */
- DATA_BL *dp_right, *dp_left;
+ int data_moved = 0; // init to shut up gcc
+ int total_moved = 0; // init to shut up gcc
+ DATA_BL *dp_right, *dp_left;
int stack_idx;
bool in_left;
int lineadd;
blocknr_T bnum_left, bnum_right;
linenr_T lnum_left, lnum_right;
int pb_idx;
- PTR_BL *pp_new;
+ PTR_BL *pp_new;
/*
* We are going to allocate a new data block. Depending on the
@@ -2113,7 +2148,7 @@ static int ml_append_int(
* also put in the right block. This method is more efficient when
* inserting a lot of lines at one place.
*/
- if (db_idx < 0) { /* left block is new, right block is existing */
+ if (db_idx < 0) { // left block is new, right block is existing
lines_moved = 0;
in_left = true;
// space_needed does not change
@@ -2138,12 +2173,12 @@ static int ml_append_int(
page_count = ((space_needed + HEADER_SIZE) + page_size - 1) / page_size;
hp_new = ml_new_data(mfp, newfile, page_count);
- if (db_idx < 0) { /* left block is new */
+ if (db_idx < 0) { // left block is new
hp_left = hp_new;
hp_right = hp;
line_count_left = 0;
line_count_right = line_count;
- } else { /* right block is new */
+ } else { // right block is new
hp_left = hp;
hp_right = hp_new;
line_count_left = line_count;
@@ -2163,11 +2198,12 @@ static int ml_append_int(
dp_right->db_txt_start -= len;
dp_right->db_free -= len + INDEX_SIZE;
dp_right->db_index[0] = dp_right->db_txt_start;
- if (mark)
+ if (mark) {
dp_right->db_index[0] |= DB_MARKED;
+ }
memmove((char *)dp_right + dp_right->db_txt_start,
- line, (size_t)len);
+ line, (size_t)len);
++line_count_right;
}
/*
@@ -2179,8 +2215,8 @@ static int ml_append_int(
dp_right->db_txt_start -= data_moved;
dp_right->db_free -= total_moved;
memmove((char *)dp_right + dp_right->db_txt_start,
- (char *)dp_left + dp_left->db_txt_start,
- (size_t)data_moved);
+ (char *)dp_left + dp_left->db_txt_start,
+ (size_t)data_moved);
offset = dp_right->db_txt_start - dp_left->db_txt_start;
dp_left->db_txt_start += data_moved;
dp_left->db_free += total_moved;
@@ -2189,8 +2225,9 @@ static int ml_append_int(
* update indexes in the new block
*/
for (to = line_count_right, from = db_idx + 1;
- from < line_count_left; ++from, ++to)
+ from < line_count_left; ++from, ++to) {
dp_right->db_index[to] = dp->db_index[from] + offset;
+ }
line_count_right += lines_moved;
line_count_left -= lines_moved;
}
@@ -2202,22 +2239,24 @@ static int ml_append_int(
dp_left->db_txt_start -= len;
dp_left->db_free -= len + INDEX_SIZE;
dp_left->db_index[line_count_left] = dp_left->db_txt_start;
- if (mark)
+ if (mark) {
dp_left->db_index[line_count_left] |= DB_MARKED;
+ }
memmove((char *)dp_left + dp_left->db_txt_start,
- line, (size_t)len);
+ line, (size_t)len);
++line_count_left;
}
- if (db_idx < 0) { /* left block is new */
+ if (db_idx < 0) { // left block is new
lnum_left = lnum + 1;
lnum_right = 0;
- } else { /* right block is new */
+ } else { // right block is new
lnum_left = 0;
- if (in_left)
+ if (in_left) {
lnum_right = lnum + 2;
- else
+ } else {
lnum_right = lnum + 1;
+ }
}
dp_left->db_line_count = line_count_left;
dp_right->db_line_count = line_count_right;
@@ -2228,10 +2267,12 @@ static int ml_append_int(
* The old one (hp, in ml_locked) gets a positive blocknumber if
* we changed it and we are not editing a new file.
*/
- if (lines_moved || in_left)
+ if (lines_moved || in_left) {
buf->b_ml.ml_flags |= ML_LOCKED_DIRTY;
- if (!newfile && db_idx >= 0 && in_left)
+ }
+ if (!newfile && db_idx >= 0 && in_left) {
buf->b_ml.ml_flags |= ML_LOCKED_POS;
+ }
mf_put(mfp, hp_new, true, false);
/*
@@ -2250,9 +2291,10 @@ static int ml_append_int(
--stack_idx) {
ip = &(buf->b_ml.ml_stack[stack_idx]);
pb_idx = ip->ip_index;
- if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL)
+ if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) {
return FAIL;
- pp = hp->bh_data; /* must be pointer block */
+ }
+ pp = hp->bh_data; // must be pointer block
if (pp->pb_id != PTR_ID) {
IEMSG(_("E317: pointer block id wrong 3"));
mf_put(mfp, hp, false, false);
@@ -2262,12 +2304,13 @@ static int ml_append_int(
* TODO: If the pointer block is full and we are adding at the end
* try to insert in front of the next block
*/
- /* block not full, add one entry */
+ // block not full, add one entry
if (pp->pb_count < pp->pb_count_max) {
- if (pb_idx + 1 < (int)pp->pb_count)
+ if (pb_idx + 1 < (int)pp->pb_count) {
memmove(&pp->pb_pointer[pb_idx + 2],
- &pp->pb_pointer[pb_idx + 1],
- (size_t)(pp->pb_count - pb_idx - 1) * sizeof(PTR_EN));
+ &pp->pb_pointer[pb_idx + 1],
+ (size_t)(pp->pb_count - pb_idx - 1) * sizeof(PTR_EN));
+ }
++pp->pb_count;
pp->pb_pointer[pb_idx].pe_line_count = line_count_left;
pp->pb_pointer[pb_idx].pe_bnum = bnum_left;
@@ -2276,19 +2319,21 @@ static int ml_append_int(
pp->pb_pointer[pb_idx + 1].pe_bnum = bnum_right;
pp->pb_pointer[pb_idx + 1].pe_page_count = page_count_right;
- if (lnum_left != 0)
+ if (lnum_left != 0) {
pp->pb_pointer[pb_idx].pe_old_lnum = lnum_left;
- if (lnum_right != 0)
+ }
+ if (lnum_right != 0) {
pp->pb_pointer[pb_idx + 1].pe_old_lnum = lnum_right;
+ }
mf_put(mfp, hp, true, false);
- buf->b_ml.ml_stack_top = stack_idx + 1; /* truncate stack */
+ buf->b_ml.ml_stack_top = stack_idx + 1; // truncate stack
if (lineadd) {
--(buf->b_ml.ml_stack_top);
- /* fix line count for rest of blocks in the stack */
+ // fix line count for rest of blocks in the stack
ml_lineadd(buf, lineadd);
- /* fix stack itself */
+ // fix stack itself
buf->b_ml.ml_stack[buf->b_ml.ml_stack_top].ip_high +=
lineadd;
++(buf->b_ml.ml_stack_top);
@@ -2298,21 +2343,23 @@ static int ml_append_int(
* We are finished, break the loop here.
*/
break;
- } else { /* pointer block full */
+ } else { // pointer block full
/*
* split the pointer block
* allocate a new pointer block
* move some of the pointer into the new block
* prepare for updating the parent block
*/
- for (;; ) { /* do this twice when splitting block 1 */
+ for (;; ) { // do this twice when splitting block 1
hp_new = ml_new_ptr(mfp);
- if (hp_new == NULL) /* TODO: try to fix tree */
+ if (hp_new == NULL) { // TODO: try to fix tree
return FAIL;
+ }
pp_new = hp_new->bh_data;
- if (hp->bh_bnum != 1)
+ if (hp->bh_bnum != 1) {
break;
+ }
/*
* if block 1 becomes full the tree is given an extra level
@@ -2326,12 +2373,12 @@ static int ml_append_int(
pp->pb_pointer[0].pe_line_count = buf->b_ml.ml_line_count;
pp->pb_pointer[0].pe_old_lnum = 1;
pp->pb_pointer[0].pe_page_count = 1;
- mf_put(mfp, hp, true, false); /* release block 1 */
- hp = hp_new; /* new block is to be split */
+ mf_put(mfp, hp, true, false); // release block 1
+ hp = hp_new; // new block is to be split
pp = pp_new;
CHECK(stack_idx != 0, _("stack_idx should be 0"));
ip->ip_index = 0;
- ++stack_idx; /* do block 1 again later */
+ ++stack_idx; // do block 1 again later
}
/*
* move the pointers after the current one to the new block
@@ -2340,15 +2387,16 @@ static int ml_append_int(
total_moved = pp->pb_count - pb_idx - 1;
if (total_moved) {
memmove(&pp_new->pb_pointer[0],
- &pp->pb_pointer[pb_idx + 1],
- (size_t)(total_moved) * sizeof(PTR_EN));
+ &pp->pb_pointer[pb_idx + 1],
+ (size_t)(total_moved) * sizeof(PTR_EN));
pp_new->pb_count = total_moved;
pp->pb_count -= total_moved - 1;
pp->pb_pointer[pb_idx + 1].pe_bnum = bnum_right;
pp->pb_pointer[pb_idx + 1].pe_line_count = line_count_right;
pp->pb_pointer[pb_idx + 1].pe_page_count = page_count_right;
- if (lnum_right)
+ if (lnum_right) {
pp->pb_pointer[pb_idx + 1].pe_old_lnum = lnum_right;
+ }
} else {
pp_new->pb_count = 1;
pp_new->pb_pointer[0].pe_bnum = bnum_right;
@@ -2359,8 +2407,9 @@ static int ml_append_int(
pp->pb_pointer[pb_idx].pe_bnum = bnum_left;
pp->pb_pointer[pb_idx].pe_line_count = line_count_left;
pp->pb_pointer[pb_idx].pe_page_count = page_count_left;
- if (lnum_left)
+ if (lnum_left) {
pp->pb_pointer[pb_idx].pe_old_lnum = lnum_left;
+ }
lnum_left = 0;
lnum_right = 0;
@@ -2368,11 +2417,13 @@ static int ml_append_int(
* recompute line counts
*/
line_count_right = 0;
- for (i = 0; i < (int)pp_new->pb_count; ++i)
+ for (i = 0; i < (int)pp_new->pb_count; ++i) {
line_count_right += pp_new->pb_pointer[i].pe_line_count;
+ }
line_count_left = 0;
- for (i = 0; i < (int)pp->pb_count; ++i)
+ for (i = 0; i < (int)pp->pb_count; ++i) {
line_count_left += pp->pb_pointer[i].pe_line_count;
+ }
bnum_left = hp->bh_bnum;
bnum_right = hp_new->bh_bnum;
@@ -2392,7 +2443,7 @@ static int ml_append_int(
}
}
- /* The line was inserted below 'lnum' */
+ // The line was inserted below 'lnum'
ml_updatechunk(buf, lnum + 1, (long)len, ML_CHNK_ADDLINE);
return OK;
}
@@ -2439,8 +2490,9 @@ int ml_replace(linenr_T lnum, char_u *line, bool copy)
// return FAIL for failure, OK otherwise
int ml_replace_buf(buf_T *buf, linenr_T lnum, char_u *line, bool copy)
{
- if (line == NULL) /* just checking... */
+ if (line == NULL) { // just checking...
return FAIL;
+ }
// When starting up, we might still need to create the memfile
if (buf->b_ml.ml_mfp == NULL && open_buffer(false, NULL, 0) == FAIL) {
@@ -2487,12 +2539,12 @@ int ml_delete(linenr_T lnum, bool message)
static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message)
{
- bhdr_T *hp;
- memfile_T *mfp;
- DATA_BL *dp;
- PTR_BL *pp;
- infoptr_T *ip;
- int count; /* number of entries in block */
+ bhdr_T *hp;
+ memfile_T *mfp;
+ DATA_BL *dp;
+ PTR_BL *pp;
+ infoptr_T *ip;
+ int count; // number of entries in block
int idx;
int stack_idx;
int text_start;
@@ -2500,19 +2552,22 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message)
long line_size;
int i;
- if (lnum < 1 || lnum > buf->b_ml.ml_line_count)
+ if (lnum < 1 || lnum > buf->b_ml.ml_line_count) {
return FAIL;
+ }
- if (lowest_marked && lowest_marked > lnum)
+ if (lowest_marked && lowest_marked > lnum) {
lowest_marked--;
+ }
/*
* If the file becomes empty the last line is replaced by an empty line.
*/
- if (buf->b_ml.ml_line_count == 1) { /* file becomes empty */
+ if (buf->b_ml.ml_line_count == 1) { // file becomes empty
if (message
- )
+ ) {
set_keep_msg((char_u *)_(no_lines_msg), 0);
+ }
i = ml_replace((linenr_T)1, (char_u *)"", true);
buf->b_ml.ml_flags |= ML_EMPTY;
@@ -2526,14 +2581,16 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message)
* This also releases any locked block.
*/
mfp = buf->b_ml.ml_mfp;
- if (mfp == NULL)
+ if (mfp == NULL) {
return FAIL;
+ }
- if ((hp = ml_find_line(buf, lnum, ML_DELETE)) == NULL)
+ if ((hp = ml_find_line(buf, lnum, ML_DELETE)) == NULL) {
return FAIL;
+ }
dp = hp->bh_data;
- /* compute line count before the delete */
+ // compute line count before the delete
count = (long)(buf->b_ml.ml_locked_high)
- (long)(buf->b_ml.ml_locked_low) + 2;
idx = lnum - buf->b_ml.ml_locked_low;
@@ -2541,10 +2598,11 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message)
--buf->b_ml.ml_line_count;
line_start = ((dp->db_index[idx]) & DB_INDEX_MASK);
- if (idx == 0) /* first line in block, text at the end */
+ if (idx == 0) { // first line in block, text at the end
line_size = dp->db_txt_end - line_start;
- else
+ } else {
line_size = ((dp->db_index[idx - 1]) & DB_INDEX_MASK) - line_start;
+ }
// Line should always have an NL char internally (represented as NUL),
// even if 'noeol' is set.
@@ -2560,33 +2618,35 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message)
* ml_find_line().
*/
if (count == 1) {
- mf_free(mfp, hp); /* free the data block */
+ mf_free(mfp, hp); // free the data block
buf->b_ml.ml_locked = NULL;
for (stack_idx = buf->b_ml.ml_stack_top - 1; stack_idx >= 0;
--stack_idx) {
- buf->b_ml.ml_stack_top = 0; /* stack is invalid when failing */
+ buf->b_ml.ml_stack_top = 0; // stack is invalid when failing
ip = &(buf->b_ml.ml_stack[stack_idx]);
idx = ip->ip_index;
- if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL)
+ if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) {
return FAIL;
- pp = hp->bh_data; /* must be pointer block */
+ }
+ pp = hp->bh_data; // must be pointer block
if (pp->pb_id != PTR_ID) {
IEMSG(_("E317: pointer block id wrong 4"));
mf_put(mfp, hp, false, false);
return FAIL;
}
count = --(pp->pb_count);
- if (count == 0) /* the pointer block becomes empty! */
+ if (count == 0) { // the pointer block becomes empty!
mf_free(mfp, hp);
- else {
- if (count != idx) /* move entries after the deleted one */
+ } else {
+ if (count != idx) { // move entries after the deleted one
memmove(&pp->pb_pointer[idx], &pp->pb_pointer[idx + 1],
- (size_t)(count - idx) * sizeof(PTR_EN));
+ (size_t)(count - idx) * sizeof(PTR_EN));
+ }
mf_put(mfp, hp, true, false);
- buf->b_ml.ml_stack_top = stack_idx; /* truncate stack */
- /* fix line count for rest of blocks in the stack */
+ buf->b_ml.ml_stack_top = stack_idx; // truncate stack
+ // fix line count for rest of blocks in the stack
if (buf->b_ml.ml_locked_lineadd != 0) {
ml_lineadd(buf, buf->b_ml.ml_locked_lineadd);
buf->b_ml.ml_stack[buf->b_ml.ml_stack_top].ip_high +=
@@ -2604,14 +2664,15 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message)
*/
text_start = dp->db_txt_start;
memmove((char *)dp + text_start + line_size,
- (char *)dp + text_start, (size_t)(line_start - text_start));
+ (char *)dp + text_start, (size_t)(line_start - text_start));
/*
* delete the index by moving the next indexes backwards
* Adjust the indexes for the text movement.
*/
- for (i = idx; i < count - 1; ++i)
+ for (i = idx; i < count - 1; ++i) {
dp->db_index[i] = dp->db_index[i + 1] + line_size;
+ }
dp->db_free += line_size + INDEX_SIZE;
dp->db_txt_start += line_size;
@@ -2632,24 +2693,25 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message)
*/
void ml_setmarked(linenr_T lnum)
{
- bhdr_T *hp;
+ bhdr_T *hp;
DATA_BL *dp;
- /* invalid line number */
+ // invalid line number
if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count
- || curbuf->b_ml.ml_mfp == NULL)
- return; /* give error message? */
-
- if (lowest_marked == 0 || lowest_marked > lnum)
+ || curbuf->b_ml.ml_mfp == NULL) {
+ return; // give error message?
+ }
+ if (lowest_marked == 0 || lowest_marked > lnum) {
lowest_marked = lnum;
+ }
/*
* find the data block containing the line
* This also fills the stack with the blocks from the root to the data block
* This also releases any locked block.
*/
- if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL)
- return; /* give error message? */
-
+ if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) {
+ return; // give error message?
+ }
dp = hp->bh_data;
dp->db_index[lnum - curbuf->b_ml.ml_locked_low] |= DB_MARKED;
curbuf->b_ml.ml_flags |= ML_LOCKED_DIRTY;
@@ -2660,13 +2722,14 @@ void ml_setmarked(linenr_T lnum)
*/
linenr_T ml_firstmarked(void)
{
- bhdr_T *hp;
- DATA_BL *dp;
+ bhdr_T *hp;
+ DATA_BL *dp;
linenr_T lnum;
int i;
- if (curbuf->b_ml.ml_mfp == NULL)
- return (linenr_T) 0;
+ if (curbuf->b_ml.ml_mfp == NULL) {
+ return (linenr_T)0;
+ }
/*
* The search starts with lowest_marked line. This is the last line where
@@ -2678,22 +2741,23 @@ linenr_T ml_firstmarked(void)
* This also fills the stack with the blocks from the root to the data
* block This also releases any locked block.
*/
- if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL)
- return (linenr_T)0; /* give error message? */
-
+ if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) {
+ return (linenr_T)0; // give error message?
+ }
dp = hp->bh_data;
for (i = lnum - curbuf->b_ml.ml_locked_low;
- lnum <= curbuf->b_ml.ml_locked_high; ++i, ++lnum)
+ lnum <= curbuf->b_ml.ml_locked_high; ++i, ++lnum) {
if ((dp->db_index[i]) & DB_MARKED) {
(dp->db_index[i]) &= DB_INDEX_MASK;
curbuf->b_ml.ml_flags |= ML_LOCKED_DIRTY;
lowest_marked = lnum + 1;
return lnum;
}
+ }
}
- return (linenr_T) 0;
+ return (linenr_T)0;
}
/*
@@ -2701,13 +2765,14 @@ linenr_T ml_firstmarked(void)
*/
void ml_clearmarked(void)
{
- bhdr_T *hp;
- DATA_BL *dp;
+ bhdr_T *hp;
+ DATA_BL *dp;
linenr_T lnum;
int i;
- if (curbuf->b_ml.ml_mfp == NULL) /* nothing to do */
+ if (curbuf->b_ml.ml_mfp == NULL) { // nothing to do
return;
+ }
/*
* The search starts with line lowest_marked.
@@ -2718,17 +2783,18 @@ void ml_clearmarked(void)
* This also fills the stack with the blocks from the root to the data
* block and releases any locked block.
*/
- if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL)
- return; /* give error message? */
-
+ if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) {
+ return; // give error message?
+ }
dp = hp->bh_data;
for (i = lnum - curbuf->b_ml.ml_locked_low;
- lnum <= curbuf->b_ml.ml_locked_high; ++i, ++lnum)
+ lnum <= curbuf->b_ml.ml_locked_high; ++i, ++lnum) {
if ((dp->db_index[i]) & DB_MARKED) {
(dp->db_index[i]) &= DB_INDEX_MASK;
curbuf->b_ml.ml_flags |= ML_LOCKED_DIRTY;
}
+ }
}
lowest_marked = 0;
@@ -2751,11 +2817,11 @@ size_t ml_flush_deleted_bytes(buf_T *buf, size_t *codepoints, size_t *codeunits)
*/
static void ml_flush_line(buf_T *buf)
{
- bhdr_T *hp;
- DATA_BL *dp;
+ bhdr_T *hp;
+ DATA_BL *dp;
linenr_T lnum;
- char_u *new_line;
- char_u *old_line;
+ char_u *new_line;
+ char_u *old_line;
colnr_T new_len;
int old_len;
int extra;
@@ -2765,13 +2831,14 @@ static void ml_flush_line(buf_T *buf)
int i;
static bool entered = false;
- if (buf->b_ml.ml_line_lnum == 0 || buf->b_ml.ml_mfp == NULL)
- return; /* nothing to do */
-
+ if (buf->b_ml.ml_line_lnum == 0 || buf->b_ml.ml_mfp == NULL) {
+ return; // nothing to do
+ }
if (buf->b_ml.ml_flags & ML_LINE_DIRTY) {
- /* This code doesn't work recursively. */
- if (entered)
+ // This code doesn't work recursively.
+ if (entered) {
return;
+ }
entered = true;
buf->flush_count++;
@@ -2787,39 +2854,41 @@ static void ml_flush_line(buf_T *buf)
idx = lnum - buf->b_ml.ml_locked_low;
start = ((dp->db_index[idx]) & DB_INDEX_MASK);
old_line = (char_u *)dp + start;
- if (idx == 0) /* line is last in block */
+ if (idx == 0) { // line is last in block
old_len = dp->db_txt_end - start;
- else /* text of previous line follows */
+ } else { // text of previous line follows
old_len = (dp->db_index[idx - 1] & DB_INDEX_MASK) - start;
+ }
new_len = (colnr_T)STRLEN(new_line) + 1;
- extra = new_len - old_len; /* negative if lines gets smaller */
+ extra = new_len - old_len; // negative if lines gets smaller
/*
* if new line fits in data block, replace directly
*/
if ((int)dp->db_free >= extra) {
- /* if the length changes and there are following lines */
+ // if the length changes and there are following lines
count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1;
if (extra != 0 && idx < count - 1) {
- /* move text of following lines */
+ // move text of following lines
memmove((char *)dp + dp->db_txt_start - extra,
- (char *)dp + dp->db_txt_start,
- (size_t)(start - dp->db_txt_start));
+ (char *)dp + dp->db_txt_start,
+ (size_t)(start - dp->db_txt_start));
- /* adjust pointers of this and following lines */
- for (i = idx + 1; i < count; ++i)
+ // adjust pointers of this and following lines
+ for (i = idx + 1; i < count; ++i) {
dp->db_index[i] -= extra;
+ }
}
dp->db_index[idx] -= extra;
- /* adjust free space */
+ // adjust free space
dp->db_free -= extra;
dp->db_txt_start -= extra;
- /* copy new line into the data block */
+ // copy new line into the data block
memmove(old_line - extra, new_line, (size_t)new_len);
buf->b_ml.ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS);
- /* The else case is already covered by the insert and delete */
+ // The else case is already covered by the insert and delete
ml_updatechunk(buf, lnum, (long)extra, ML_CHNK_UPDLINE);
} else {
// Cannot do it in one data block: Delete and append.
@@ -2876,8 +2945,8 @@ static bhdr_T *ml_new_ptr(memfile_T *mfp)
* lookup line 'lnum' in a memline
*
* action: if ML_DELETE or ML_INSERT the line count is updated while searching
- * if ML_FLUSH only flush a locked block
- * if ML_FIND just find the line
+ * if ML_FLUSH only flush a locked block
+ * if ML_FIND just find the line
*
* If the block was found it is locked and put in ml_locked.
* The stack is updated to lead to the locked block. The ip_high field in
@@ -2889,11 +2958,11 @@ static bhdr_T *ml_new_ptr(memfile_T *mfp)
*/
static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
{
- DATA_BL *dp;
- PTR_BL *pp;
- infoptr_T *ip;
- bhdr_T *hp;
- memfile_T *mfp;
+ DATA_BL *dp;
+ PTR_BL *pp;
+ infoptr_T *ip;
+ bhdr_T *hp;
+ memfile_T *mfp;
linenr_T t;
blocknr_T bnum, bnum2;
int dirty;
@@ -2927,58 +2996,63 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
}
mf_put(mfp, buf->b_ml.ml_locked, buf->b_ml.ml_flags & ML_LOCKED_DIRTY,
- buf->b_ml.ml_flags & ML_LOCKED_POS);
+ buf->b_ml.ml_flags & ML_LOCKED_POS);
buf->b_ml.ml_locked = NULL;
/*
* If lines have been added or deleted in the locked block, need to
* update the line count in pointer blocks.
*/
- if (buf->b_ml.ml_locked_lineadd != 0)
+ if (buf->b_ml.ml_locked_lineadd != 0) {
ml_lineadd(buf, buf->b_ml.ml_locked_lineadd);
+ }
}
- if (action == ML_FLUSH) /* nothing else to do */
+ if (action == ML_FLUSH) { // nothing else to do
return NULL;
+ }
- bnum = 1; /* start at the root of the tree */
+ bnum = 1; // start at the root of the tree
page_count = 1;
low = 1;
high = buf->b_ml.ml_line_count;
- if (action == ML_FIND) { /* first try stack entries */
+ if (action == ML_FIND) { // first try stack entries
for (top = buf->b_ml.ml_stack_top - 1; top >= 0; --top) {
ip = &(buf->b_ml.ml_stack[top]);
if (ip->ip_low <= lnum && ip->ip_high >= lnum) {
bnum = ip->ip_bnum;
low = ip->ip_low;
high = ip->ip_high;
- buf->b_ml.ml_stack_top = top; /* truncate stack at prev entry */
+ buf->b_ml.ml_stack_top = top; // truncate stack at prev entry
break;
}
}
- if (top < 0)
- buf->b_ml.ml_stack_top = 0; /* not found, start at the root */
- } else /* ML_DELETE or ML_INSERT */
- buf->b_ml.ml_stack_top = 0; /* start at the root */
-
+ if (top < 0) {
+ buf->b_ml.ml_stack_top = 0; // not found, start at the root
+ }
+ } else { // ML_DELETE or ML_INSERT
+ buf->b_ml.ml_stack_top = 0; // start at the root
+ }
/*
* search downwards in the tree until a data block is found
*/
for (;; ) {
- if ((hp = mf_get(mfp, bnum, page_count)) == NULL)
+ if ((hp = mf_get(mfp, bnum, page_count)) == NULL) {
goto error_noblock;
+ }
/*
* update high for insert/delete
*/
- if (action == ML_INSERT)
+ if (action == ML_INSERT) {
++high;
- else if (action == ML_DELETE)
+ } else if (action == ML_DELETE) {
--high;
+ }
dp = hp->bh_data;
- if (dp->db_id == DATA_ID) { /* data block */
+ if (dp->db_id == DATA_ID) { // data block
buf->b_ml.ml_locked = hp;
buf->b_ml.ml_locked_low = low;
buf->b_ml.ml_locked_high = high;
@@ -2987,7 +3061,7 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
return hp;
}
- pp = (PTR_BL *)(dp); /* must be pointer block */
+ pp = (PTR_BL *)(dp); // must be pointer block
if (pp->pb_id != PTR_ID) {
IEMSG(_("E317: pointer block id wrong"));
goto error_block;
@@ -2998,7 +3072,7 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
ip->ip_bnum = bnum;
ip->ip_low = low;
ip->ip_high = high;
- ip->ip_index = -1; /* index not known yet */
+ ip->ip_index = -1; // index not known yet
dirty = FALSE;
for (idx = 0; idx < (int)pp->pb_count; ++idx) {
@@ -3030,7 +3104,6 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
if (lnum > buf->b_ml.ml_line_count) {
IEMSGN(_("E322: line number out of range: %" PRId64 " past the end"),
lnum - buf->b_ml.ml_line_count);
-
} else {
IEMSGN(_("E323: line count wrong in block %" PRId64), bnum);
}
@@ -3054,10 +3127,11 @@ error_noblock:
* the incremented/decremented line counts, because there won't be a line
* inserted/deleted after all.
*/
- if (action == ML_DELETE)
+ if (action == ML_DELETE) {
ml_lineadd(buf, 1);
- else if (action == ML_INSERT)
+ } else if (action == ML_INSERT) {
ml_lineadd(buf, -1);
+ }
buf->b_ml.ml_stack_top = 0;
return NULL;
}
@@ -3071,9 +3145,9 @@ static int ml_add_stack(buf_T *buf)
{
int top = buf->b_ml.ml_stack_top;
- /* may have to increase the stack size */
+ // may have to increase the stack size
if (top == buf->b_ml.ml_stack_size) {
- CHECK(top > 0, _("Stack size increases")); /* more than 5 levels??? */
+ CHECK(top > 0, _("Stack size increases")); // more than 5 levels???
buf->b_ml.ml_stack_size += STACK_INCR;
size_t new_size = sizeof(infoptr_T) * buf->b_ml.ml_stack_size;
@@ -3097,16 +3171,17 @@ static int ml_add_stack(buf_T *buf)
static void ml_lineadd(buf_T *buf, int count)
{
int idx;
- infoptr_T *ip;
- PTR_BL *pp;
- memfile_T *mfp = buf->b_ml.ml_mfp;
- bhdr_T *hp;
+ infoptr_T *ip;
+ PTR_BL *pp;
+ memfile_T *mfp = buf->b_ml.ml_mfp;
+ bhdr_T *hp;
for (idx = buf->b_ml.ml_stack_top - 1; idx >= 0; --idx) {
ip = &(buf->b_ml.ml_stack[idx]);
- if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL)
+ if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) {
break;
- pp = hp->bh_data; /* must be pointer block */
+ }
+ pp = hp->bh_data; // must be pointer block
if (pp->pb_id != PTR_ID) {
mf_put(mfp, hp, false, false);
IEMSG(_("E317: pointer block id wrong 2"));
@@ -3132,14 +3207,15 @@ int resolve_symlink(const char_u *fname, char_u *buf)
int ret;
int depth = 0;
- if (fname == NULL)
+ if (fname == NULL) {
return FAIL;
+ }
- /* Put the result so far in tmp[], starting with the original name. */
+ // Put the result so far in tmp[], starting with the original name.
STRLCPY(tmp, fname, MAXPATHL);
for (;; ) {
- /* Limit symlink depth to 100, catch recursive loops. */
+ // Limit symlink depth to 100, catch recursive loops.
if (++depth == 100) {
EMSG2(_("E773: Symlink loop for \"%s\""), fname);
return FAIL;
@@ -3151,14 +3227,15 @@ int resolve_symlink(const char_u *fname, char_u *buf)
/* Found non-symlink or not existing file, stop here.
* When at the first level use the unmodified name, skip the
* call to vim_FullName(). */
- if (depth == 1)
+ if (depth == 1) {
return FAIL;
+ }
- /* Use the resolved name in tmp[]. */
+ // Use the resolved name in tmp[].
break;
}
- /* There must be some error reading links, use original name. */
+ // There must be some error reading links, use original name.
return FAIL;
}
buf[ret] = NUL;
@@ -3193,8 +3270,8 @@ int resolve_symlink(const char_u *fname, char_u *buf)
*/
char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name)
{
- char_u *r, *s;
- char_u *fname_res = fname;
+ char_u *r, *s;
+ char_u *fname_res = fname;
#ifdef HAVE_READLINK
char_u fname_buf[MAXPATHL];
@@ -3221,46 +3298,43 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name
// Prepend a '.' to the swap file name for the current directory.
r = (char_u *)modname((char *)fname_res, ".swp",
- dir_name[0] == '.' && dir_name[1] == NUL);
- if (r == NULL) /* out of memory */
+ dir_name[0] == '.' && dir_name[1] == NUL);
+ if (r == NULL) { // out of memory
return NULL;
+ }
s = get_file_in_dir(r, dir_name);
xfree(r);
return s;
}
-/*
- * Get file name to use for swap file or backup file.
- * Use the name of the edited file "fname" and an entry in the 'dir' or 'bdir'
- * option "dname".
- * - If "dname" is ".", return "fname" (swap file in dir of file).
- * - If "dname" starts with "./", insert "dname" in "fname" (swap file
- * relative to dir of file).
- * - Otherwise, prepend "dname" to the tail of "fname" (swap file in specific
- * dir).
- *
- * The return value is an allocated string and can be NULL.
- */
-char_u *
-get_file_in_dir (
- char_u *fname,
- char_u *dname /* don't use "dirname", it is a global for Alpha */
-)
+/// Get file name to use for swap file or backup file.
+/// Use the name of the edited file "fname" and an entry in the 'dir' or 'bdir'
+/// option "dname".
+/// - If "dname" is ".", return "fname" (swap file in dir of file).
+/// - If "dname" starts with "./", insert "dname" in "fname" (swap file
+/// relative to dir of file).
+/// - Otherwise, prepend "dname" to the tail of "fname" (swap file in specific
+/// dir).
+///
+/// The return value is an allocated string and can be NULL.
+///
+/// @param dname don't use "dirname", it is a global for Alpha
+char_u *get_file_in_dir(char_u *fname, char_u *dname)
{
- char_u *t;
- char_u *tail;
- char_u *retval;
+ char_u *t;
+ char_u *tail;
+ char_u *retval;
int save_char;
tail = path_tail(fname);
- if (dname[0] == '.' && dname[1] == NUL)
+ if (dname[0] == '.' && dname[1] == NUL) {
retval = vim_strsave(fname);
- else if (dname[0] == '.' && vim_ispathsep(dname[1])) {
- if (tail == fname) /* no path before file name */
+ } else if (dname[0] == '.' && vim_ispathsep(dname[1])) {
+ if (tail == fname) { // no path before file name
retval = (char_u *)concat_fnames((char *)dname + 2, (char *)tail, TRUE);
- else {
+ } else {
save_char = *tail;
*tail = NUL;
t = (char_u *)concat_fnames((char *)fname, (char *)dname + 2, TRUE);
@@ -3276,14 +3350,11 @@ get_file_in_dir (
}
-/*
- * Print the ATTENTION message: info about an existing swap file.
- */
-static void
-attention_message (
- buf_T *buf, /* buffer being edited */
- char_u *fname /* swap file name */
-)
+/// Print the ATTENTION message: info about an existing swap file.
+///
+/// @param buf buffer being edited
+/// @param fname swap file name
+static void attention_message(buf_T *buf, char_u *fname)
{
assert(buf->b_fname != NULL);
@@ -3339,7 +3410,7 @@ attention_message (
*/
static int do_swapexists(buf_T *buf, char_u *fname)
{
- set_vim_var_string(VV_SWAPNAME, (char *) fname, -1);
+ set_vim_var_string(VV_SWAPNAME, (char *)fname, -1);
set_vim_var_string(VV_SWAPCHOICE, NULL, -1);
// Trigger SwapExists autocommands with <afile> set to the file being
@@ -3351,12 +3422,18 @@ static int do_swapexists(buf_T *buf, char_u *fname)
set_vim_var_string(VV_SWAPNAME, NULL, -1);
switch (*get_vim_var_str(VV_SWAPCHOICE)) {
- case 'o': return 1;
- case 'e': return 2;
- case 'r': return 3;
- case 'd': return 4;
- case 'q': return 5;
- case 'a': return 6;
+ case 'o':
+ return 1;
+ case 'e':
+ return 2;
+ case 'r':
+ return 3;
+ case 'd':
+ return 4;
+ case 'q':
+ return 5;
+ case 'a':
+ return 6;
}
return 0;
@@ -3385,14 +3462,13 @@ static int do_swapexists(buf_T *buf, char_u *fname)
/// never set to false.
///
/// @return [allocated] Name of the swap file.
-static char *findswapname(buf_T *buf, char **dirp, char *old_fname,
- bool *found_existing_dir)
+static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_existing_dir)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1, 2, 4)
{
char *fname;
size_t n;
char *dir_name;
- char *buf_fname = (char *) buf->b_fname;
+ char *buf_fname = (char *)buf->b_fname;
/*
* Isolate a directory name from *dirp and put it in dir_name.
@@ -3400,7 +3476,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname,
*/
const size_t dir_len = strlen(*dirp) + 1;
dir_name = xmalloc(dir_len);
- (void)copy_option_part((char_u **) dirp, (char_u *) dir_name, dir_len, ",");
+ (void)copy_option_part((char_u **)dirp, (char_u *)dir_name, dir_len, ",");
/*
* we try different names until we find one that does not exist yet
@@ -3459,7 +3535,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname,
// inode too.
expand_env(b0.b0_fname, NameBuff, MAXPATHL);
if (fnamecmp_ino(buf->b_ffname, NameBuff,
- char_to_long(b0.b0_ino))) {
+ char_to_long(b0.b0_ino))) {
differ = TRUE;
}
}
@@ -3468,7 +3544,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname,
// "~user/path/file". Expand it first.
expand_env(b0.b0_fname, NameBuff, MAXPATHL);
if (fnamecmp_ino(buf->b_ffname, NameBuff,
- char_to_long(b0.b0_ino))) {
+ char_to_long(b0.b0_ino))) {
differ = TRUE;
}
}
@@ -3532,12 +3608,10 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname,
choice = do_dialog(VIM_WARNING, (char_u *)_("VIM - ATTENTION"),
(char_u *)name,
process_still_running
- ? (char_u *)_(
- "&Open Read-Only\n&Edit anyway\n&Recover"
- "\n&Quit\n&Abort") :
- (char_u *)_(
- "&Open Read-Only\n&Edit anyway\n&Recover"
- "\n&Delete it\n&Quit\n&Abort"),
+ ? (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover"
+ "\n&Quit\n&Abort") :
+ (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover"
+ "\n&Delete it\n&Quit\n&Abort"),
1, NULL, false);
if (process_still_running && choice >= 4) {
@@ -3582,7 +3656,6 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname,
need_wait_return = true;
}
}
-
}
}
}
@@ -3593,19 +3666,19 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname,
* If that still isn't enough decrement the last but one char: ".svz"
* Can happen when editing many "No Name" buffers.
*/
- if (fname[n - 1] == 'a') { /* ".s?a" */
- if (fname[n - 2] == 'a') { /* ".saa": tried enough, give up */
+ if (fname[n - 1] == 'a') { // ".s?a"
+ if (fname[n - 2] == 'a') { // ".saa": tried enough, give up
EMSG(_("E326: Too many swap files found"));
XFREE_CLEAR(fname);
break;
}
- --fname[n - 2]; /* ".svz", ".suz", etc. */
+ --fname[n - 2]; // ".svz", ".suz", etc.
fname[n - 1] = 'z' + 1;
}
- --fname[n - 1]; /* ".swo", ".swn", etc. */
+ --fname[n - 1]; // ".swo", ".swn", etc.
}
- if (os_isdir((char_u *) dir_name)) {
+ if (os_isdir((char_u *)dir_name)) {
*found_existing_dir = true;
} else if (!*found_existing_dir && **dirp == NUL) {
int ret;
@@ -3630,66 +3703,62 @@ static int b0_magic_wrong(ZERO_BL *b0p)
|| b0p->b0_magic_char != B0_MAGIC_CHAR;
}
-/*
- * Compare current file name with file name from swap file.
- * Try to use inode numbers when possible.
- * Return non-zero when files are different.
- *
- * When comparing file names a few things have to be taken into consideration:
- * - When working over a network the full path of a file depends on the host.
- * We check the inode number if possible. It is not 100% reliable though,
- * because the device number cannot be used over a network.
- * - When a file does not exist yet (editing a new file) there is no inode
- * number.
- * - The file name in a swap file may not be valid on the current host. The
- * "~user" form is used whenever possible to avoid this.
- *
- * This is getting complicated, let's make a table:
- *
- * ino_c ino_s fname_c fname_s differ =
- *
- * both files exist -> compare inode numbers:
- * != 0 != 0 X X ino_c != ino_s
- *
- * inode number(s) unknown, file names available -> compare file names
- * == 0 X OK OK fname_c != fname_s
- * X == 0 OK OK fname_c != fname_s
- *
- * current file doesn't exist, file for swap file exist, file name(s) not
- * available -> probably different
- * == 0 != 0 FAIL X TRUE
- * == 0 != 0 X FAIL TRUE
- *
- * current file exists, inode for swap unknown, file name(s) not
- * available -> probably different
- * != 0 == 0 FAIL X TRUE
- * != 0 == 0 X FAIL TRUE
- *
- * current file doesn't exist, inode for swap unknown, one file name not
- * available -> probably different
- * == 0 == 0 FAIL OK TRUE
- * == 0 == 0 OK FAIL TRUE
- *
- * current file doesn't exist, inode for swap unknown, both file names not
- * available -> compare file names
- * == 0 == 0 FAIL FAIL fname_c != fname_s
- *
- * Only the last 32 bits of the inode will be used. This can't be changed
- * without making the block 0 incompatible with 32 bit versions.
- */
-
-static bool fnamecmp_ino(
- char_u *fname_c, // current file name
- char_u *fname_s, // file name from swap file
- long ino_block0
-)
+/// Compare current file name with file name from swap file.
+/// Try to use inode numbers when possible.
+/// Return non-zero when files are different.
+///
+/// When comparing file names a few things have to be taken into consideration:
+/// - When working over a network the full path of a file depends on the host.
+/// We check the inode number if possible. It is not 100% reliable though,
+/// because the device number cannot be used over a network.
+/// - When a file does not exist yet (editing a new file) there is no inode
+/// number.
+/// - The file name in a swap file may not be valid on the current host. The
+/// "~user" form is used whenever possible to avoid this.
+///
+/// This is getting complicated, let's make a table:
+///
+/// ino_c ino_s fname_c fname_s differ =
+///
+/// both files exist -> compare inode numbers:
+/// != 0 != 0 X X ino_c != ino_s
+///
+/// inode number(s) unknown, file names available -> compare file names
+/// == 0 X OK OK fname_c != fname_s
+/// X == 0 OK OK fname_c != fname_s
+///
+/// current file doesn't exist, file for swap file exist, file name(s) not
+/// available -> probably different
+/// == 0 != 0 FAIL X TRUE
+/// == 0 != 0 X FAIL TRUE
+///
+/// current file exists, inode for swap unknown, file name(s) not
+/// available -> probably different
+/// != 0 == 0 FAIL X TRUE
+/// != 0 == 0 X FAIL TRUE
+///
+/// current file doesn't exist, inode for swap unknown, one file name not
+/// available -> probably different
+/// == 0 == 0 FAIL OK TRUE
+/// == 0 == 0 OK FAIL TRUE
+///
+/// current file doesn't exist, inode for swap unknown, both file names not
+/// available -> compare file names
+/// == 0 == 0 FAIL FAIL fname_c != fname_s
+///
+/// Only the last 32 bits of the inode will be used. This can't be changed
+/// without making the block 0 incompatible with 32 bit versions.
+///
+/// @param fname_c current file name
+/// @param fname_s file name from swap file
+static bool fnamecmp_ino(char_u *fname_c, char_u *fname_s, long ino_block0)
{
- uint64_t ino_c = 0; /* ino of current file */
- uint64_t ino_s; /* ino of file from swap file */
- char_u buf_c[MAXPATHL]; /* full path of fname_c */
- char_u buf_s[MAXPATHL]; /* full path of fname_s */
- int retval_c; /* flag: buf_c valid */
- int retval_s; /* flag: buf_s valid */
+ uint64_t ino_c = 0; // ino of current file
+ uint64_t ino_s; // ino of file from swap file
+ char_u buf_c[MAXPATHL]; // full path of fname_c
+ char_u buf_s[MAXPATHL]; // full path of fname_s
+ int retval_c; // flag: buf_c valid
+ int retval_s; // flag: buf_s valid
FileInfo file_info;
if (os_fileinfo((char *)fname_c, &file_info)) {
@@ -3707,8 +3776,9 @@ static bool fnamecmp_ino(
ino_s = (uint64_t)ino_block0;
}
- if (ino_c && ino_s)
+ if (ino_c && ino_s) {
return ino_c != ino_s;
+ }
/*
* One of the inode numbers is unknown, try a forced vim_FullName() and
@@ -3716,8 +3786,9 @@ static bool fnamecmp_ino(
*/
retval_c = vim_FullName((char *)fname_c, (char *)buf_c, MAXPATHL, TRUE);
retval_s = vim_FullName((char *)fname_s, (char *)buf_s, MAXPATHL, TRUE);
- if (retval_c == OK && retval_s == OK)
+ if (retval_c == OK && retval_s == OK) {
return STRCMP(buf_c, buf_s) != 0;
+ }
/*
* Can't compare inodes or file names, guess that the files are different,
@@ -3768,11 +3839,12 @@ static long char_to_long(char_u *s)
*/
void ml_setflags(buf_T *buf)
{
- bhdr_T *hp;
- ZERO_BL *b0p;
+ bhdr_T *hp;
+ ZERO_BL *b0p;
- if (!buf->b_ml.ml_mfp)
+ if (!buf->b_ml.ml_mfp) {
return;
+ }
for (hp = buf->b_ml.ml_mfp->mf_used_last; hp != NULL; hp = hp->bh_prev) {
if (hp->bh_bnum == 0) {
b0p = hp->bh_data;
@@ -3787,19 +3859,19 @@ void ml_setflags(buf_T *buf)
}
}
-#define MLCS_MAXL 800 /* max no of lines in chunk */
-#define MLCS_MINL 400 /* should be half of MLCS_MAXL */
+#define MLCS_MAXL 800 // max no of lines in chunk
+#define MLCS_MINL 400 // should be half of MLCS_MAXL
/*
* Keep information for finding byte offset of a line, updtype may be one of:
* ML_CHNK_ADDLINE: Add len to parent chunk, possibly splitting it
- * Careful: ML_CHNK_ADDLINE may cause ml_find_line() to be called.
+ * Careful: ML_CHNK_ADDLINE may cause ml_find_line() to be called.
* ML_CHNK_DELLINE: Subtract len from parent chunk, possibly deleting it
* ML_CHNK_UPDLINE: Add len to parent chunk, as a signed entity.
*/
static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
{
- static buf_T *ml_upd_lastbuf = NULL;
+ static buf_T *ml_upd_lastbuf = NULL;
static linenr_T ml_upd_lastline;
static linenr_T ml_upd_lastcurline;
static int ml_upd_lastcurix;
@@ -3807,13 +3879,14 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
linenr_T curline = ml_upd_lastcurline;
int curix = ml_upd_lastcurix;
long size;
- chunksize_T *curchnk;
+ chunksize_T *curchnk;
int rest;
- bhdr_T *hp;
- DATA_BL *dp;
+ bhdr_T *hp;
+ DATA_BL *dp;
- if (buf->b_ml.ml_usedchunks == -1 || len == 0)
+ if (buf->b_ml.ml_usedchunks == -1 || len == 0) {
return;
+ }
if (buf->b_ml.ml_chunksize == NULL) {
buf->b_ml.ml_chunksize = xmalloc(sizeof(chunksize_T) * 100);
buf->b_ml.ml_numchunks = 100;
@@ -3841,8 +3914,8 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
|| updtype != ML_CHNK_ADDLINE) {
for (curline = 1, curix = 0;
curix < buf->b_ml.ml_usedchunks - 1
- && line >= curline +
- buf->b_ml.ml_chunksize[curix].mlcs_numlines;
+ && line >= curline +
+ buf->b_ml.ml_chunksize[curix].mlcs_numlines;
curix++) {
curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines;
}
@@ -3854,31 +3927,31 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
}
curchnk = buf->b_ml.ml_chunksize + curix;
- if (updtype == ML_CHNK_DELLINE)
+ if (updtype == ML_CHNK_DELLINE) {
len = -len;
+ }
curchnk->mlcs_totalsize += len;
if (updtype == ML_CHNK_ADDLINE) {
curchnk->mlcs_numlines++;
- /* May resize here so we don't have to do it in both cases below */
+ // May resize here so we don't have to do it in both cases below
if (buf->b_ml.ml_usedchunks + 1 >= buf->b_ml.ml_numchunks) {
buf->b_ml.ml_numchunks = buf->b_ml.ml_numchunks * 3 / 2;
- buf->b_ml.ml_chunksize = xrealloc(
- buf->b_ml.ml_chunksize,
- sizeof(chunksize_T) * buf->b_ml.ml_numchunks);
+ buf->b_ml.ml_chunksize = xrealloc(buf->b_ml.ml_chunksize,
+ sizeof(chunksize_T) * buf->b_ml.ml_numchunks);
}
if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MAXL) {
- int count; /* number of entries in block */
+ int count; // number of entries in block
int idx;
int text_end;
int linecnt;
memmove(buf->b_ml.ml_chunksize + curix + 1,
- buf->b_ml.ml_chunksize + curix,
- (buf->b_ml.ml_usedchunks - curix) *
- sizeof(chunksize_T));
- /* Compute length of first half of lines in the split chunk */
+ buf->b_ml.ml_chunksize + curix,
+ (buf->b_ml.ml_usedchunks - curix) *
+ sizeof(chunksize_T));
+ // Compute length of first half of lines in the split chunk
size = 0;
linecnt = 0;
while (curline < buf->b_ml.ml_line_count
@@ -3892,11 +3965,12 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
(long)(buf->b_ml.ml_locked_low) + 1;
idx = curline - buf->b_ml.ml_locked_low;
curline = buf->b_ml.ml_locked_high + 1;
- if (idx == 0) /* first line in block, text at the end */
+ if (idx == 0) { // first line in block, text at the end
text_end = dp->db_txt_end;
- else
+ } else {
text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
- /* Compute index of last line to use in this MEMLINE */
+ }
+ // Compute index of last line to use in this MEMLINE
rest = count - idx;
if (linecnt + rest > MLCS_MINL) {
idx += MLCS_MINL - linecnt - 1;
@@ -3912,7 +3986,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
buf->b_ml.ml_chunksize[curix].mlcs_totalsize = size;
buf->b_ml.ml_chunksize[curix + 1].mlcs_totalsize -= size;
buf->b_ml.ml_usedchunks++;
- ml_upd_lastbuf = NULL; /* Force recalc of curix & curline */
+ ml_upd_lastbuf = NULL; // Force recalc of curix & curline
return;
} else if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MINL
&& curix == buf->b_ml.ml_usedchunks - 1
@@ -3937,12 +4011,13 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
return;
}
dp = hp->bh_data;
- if (dp->db_line_count == 1)
+ if (dp->db_line_count == 1) {
rest = dp->db_txt_end - dp->db_txt_start;
- else
+ } else {
rest =
((dp->db_index[dp->db_line_count - 2]) & DB_INDEX_MASK)
- dp->db_txt_start;
+ }
curchnk->mlcs_totalsize = rest;
curchnk->mlcs_numlines = 1;
curchnk[-1].mlcs_totalsize -= rest;
@@ -3951,7 +4026,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
}
} else if (updtype == ML_CHNK_DELLINE) {
curchnk->mlcs_numlines--;
- ml_upd_lastbuf = NULL; /* Force recalc of curix & curline */
+ ml_upd_lastbuf = NULL; // Force recalc of curix & curline
if (curix < (buf->b_ml.ml_usedchunks - 1)
&& (curchnk->mlcs_numlines + curchnk[1].mlcs_numlines)
<= MLCS_MINL) {
@@ -3960,7 +4035,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
} else if (curix == 0 && curchnk->mlcs_numlines <= 0) {
buf->b_ml.ml_usedchunks--;
memmove(buf->b_ml.ml_chunksize, buf->b_ml.ml_chunksize + 1,
- buf->b_ml.ml_usedchunks * sizeof(chunksize_T));
+ buf->b_ml.ml_usedchunks * sizeof(chunksize_T));
return;
} else if (curix == 0 || (curchnk->mlcs_numlines > 10
&& (curchnk->mlcs_numlines +
@@ -3969,15 +4044,15 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
return;
}
- /* Collapse chunks */
+ // Collapse chunks
curchnk[-1].mlcs_numlines += curchnk->mlcs_numlines;
curchnk[-1].mlcs_totalsize += curchnk->mlcs_totalsize;
buf->b_ml.ml_usedchunks--;
if (curix < buf->b_ml.ml_usedchunks) {
memmove(buf->b_ml.ml_chunksize + curix,
- buf->b_ml.ml_chunksize + curix + 1,
- (buf->b_ml.ml_usedchunks - curix) *
- sizeof(chunksize_T));
+ buf->b_ml.ml_chunksize + curix + 1,
+ (buf->b_ml.ml_usedchunks - curix) *
+ sizeof(chunksize_T));
}
return;
}
@@ -4002,9 +4077,9 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
linenr_T curline;
int curix;
long size;
- bhdr_T *hp;
- DATA_BL *dp;
- int count; /* number of entries in block */
+ bhdr_T *hp;
+ DATA_BL *dp;
+ int count; // number of entries in block
int idx;
int start_idx;
int text_end;
@@ -4032,15 +4107,18 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
if (buf->b_ml.ml_usedchunks == -1
|| buf->b_ml.ml_chunksize == NULL
- || lnum < 0)
+ || lnum < 0) {
return -1;
+ }
- if (offp == NULL)
+ if (offp == NULL) {
offset = 0;
- else
+ } else {
offset = *offp;
- if (lnum == 0 && offset <= 0)
- return 1; /* Not a "find offset" and offset 0 _must_ be in line 1 */
+ }
+ if (lnum == 0 && offset <= 0) {
+ return 1; // Not a "find offset" and offset 0 _must_ be in line 1
+ }
/*
* Find the last chunk before the one containing our line. Last chunk is
* special because it will never qualify
@@ -4056,36 +4134,41 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
+ ffdos * buf->b_ml.ml_chunksize[curix].mlcs_numlines))) {
curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines;
size += buf->b_ml.ml_chunksize[curix].mlcs_totalsize;
- if (offset && ffdos)
+ if (offset && ffdos) {
size += buf->b_ml.ml_chunksize[curix].mlcs_numlines;
+ }
curix++;
}
while ((lnum != 0 && curline < lnum) || (offset != 0 && size < offset)) {
if (curline > buf->b_ml.ml_line_count
- || (hp = ml_find_line(buf, curline, ML_FIND)) == NULL)
+ || (hp = ml_find_line(buf, curline, ML_FIND)) == NULL) {
return -1;
+ }
dp = hp->bh_data;
count = (long)(buf->b_ml.ml_locked_high) -
(long)(buf->b_ml.ml_locked_low) + 1;
start_idx = idx = curline - buf->b_ml.ml_locked_low;
- if (idx == 0) /* first line in block, text at the end */
+ if (idx == 0) { // first line in block, text at the end
text_end = dp->db_txt_end;
- else
+ } else {
text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
- /* Compute index of last line to use in this MEMLINE */
+ }
+ // Compute index of last line to use in this MEMLINE
if (lnum != 0) {
- if (curline + (count - idx) >= lnum)
+ if (curline + (count - idx) >= lnum) {
idx += lnum - curline - 1;
- else
+ } else {
idx = count - 1;
+ }
} else {
extra = 0;
while (offset >= size
+ text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK)
+ ffdos) {
- if (ffdos)
+ if (ffdos) {
size++;
+ }
if (idx == count - 1) {
extra = 1;
break;
@@ -4096,25 +4179,28 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK);
size += len;
if (offset != 0 && size >= offset) {
- if (size + ffdos == offset)
+ if (size + ffdos == offset) {
*offp = 0;
- else if (idx == start_idx)
+ } else if (idx == start_idx) {
*offp = offset - size + len;
- else
+ } else {
*offp = offset - size + len
- (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK));
+ }
curline += idx - start_idx + extra;
- if (curline > buf->b_ml.ml_line_count)
- return -1; /* exactly one byte beyond the end */
+ if (curline > buf->b_ml.ml_line_count) {
+ return -1; // exactly one byte beyond the end
+ }
return curline;
}
curline = buf->b_ml.ml_locked_high + 1;
}
if (lnum != 0) {
- /* Count extra CR characters. */
- if (ffdos)
+ // Count extra CR characters.
+ if (ffdos) {
size += lnum - 1;
+ }
/* Don't count the last line break if 'noeol' and ('bin' or
* 'nofixeol'). */
diff --git a/src/nvim/memory.c b/src/nvim/memory.c
index 7a8fc4da75..cc9c047fa0 100644
--- a/src/nvim/memory.c
+++ b/src/nvim/memory.c
@@ -1,26 +1,26 @@
// 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
- // Various routines dealing with allocation and deallocation of memory.
+// Various routines dealing with allocation and deallocation of memory.
#include <assert.h>
#include <inttypes.h>
-#include <string.h>
#include <stdbool.h>
+#include <string.h>
-#include "nvim/vim.h"
+#include "nvim/api/vim.h"
#include "nvim/context.h"
+#include "nvim/decoration.h"
#include "nvim/eval.h"
#include "nvim/highlight.h"
+#include "nvim/lua/executor.h"
#include "nvim/memfile.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/ui.h"
#include "nvim/sign.h"
-#include "nvim/api/vim.h"
-#include "nvim/lua/executor.h"
-#include "nvim/decoration.h"
+#include "nvim/ui.h"
+#include "nvim/vim.h"
#ifdef UNIT_TESTING
# define malloc(size) mem_malloc(size)
@@ -47,8 +47,9 @@ void try_to_free_memory(void)
{
static bool trying_to_free = false;
// avoid recursive calls
- if (trying_to_free)
+ if (trying_to_free) {
return;
+ }
trying_to_free = true;
// free any scrollback text
@@ -182,7 +183,7 @@ void *xmallocz(size_t size)
}
void *ret = xmalloc(total_size);
- ((char*)ret)[size] = 0;
+ ((char *)ret)[size] = 0;
return ret;
}
@@ -339,16 +340,16 @@ char *xstpcpy(char *restrict dst, const char *restrict src)
char *xstpncpy(char *restrict dst, const char *restrict src, size_t maxlen)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
- const char *p = memchr(src, '\0', maxlen);
- if (p) {
- size_t srclen = (size_t)(p - src);
- memcpy(dst, src, srclen);
- memset(dst + srclen, 0, maxlen - srclen);
- return dst + srclen;
- } else {
- memcpy(dst, src, maxlen);
- return dst + maxlen;
- }
+ const char *p = memchr(src, '\0', maxlen);
+ if (p) {
+ size_t srclen = (size_t)(p - src);
+ memcpy(dst, src, srclen);
+ memset(dst + srclen, 0, maxlen - srclen);
+ return dst + srclen;
+ } else {
+ memcpy(dst, src, maxlen);
+ return dst + maxlen;
+ }
}
/// xstrlcpy - Copy a NUL-terminated string into a sized buffer
@@ -447,7 +448,7 @@ void *xmemrchr(const void *src, uint8_t c, size_t len)
{
while (len--) {
if (((uint8_t *)src)[len] == c) {
- return (uint8_t *) src + len;
+ return (uint8_t *)src + len;
}
}
return NULL;
@@ -500,7 +501,7 @@ bool striequal(const char *a, const char *b)
void do_outofmem_msg(size_t size)
{
if (!did_outofmem_msg) {
- /* Don't hide this message */
+ // Don't hide this message
emsg_silent = 0;
/* Must come first to avoid coming back here when printing the error
@@ -523,14 +524,15 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
#if defined(EXITFREE)
-#include "nvim/file_search.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
+#include "nvim/eval/typval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
+#include "nvim/file_search.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
@@ -538,8 +540,9 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/move.h"
-#include "nvim/option.h"
#include "nvim/ops.h"
+#include "nvim/option.h"
+#include "nvim/os/os.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/quickfix.h"
@@ -550,8 +553,6 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
#include "nvim/syntax.h"
#include "nvim/tag.h"
#include "nvim/window.h"
-#include "nvim/os/os.h"
-#include "nvim/eval/typval.h"
/*
* Free everything that we allocated.
@@ -562,7 +563,7 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
*/
void free_all_mem(void)
{
- buf_T *buf, *nextbuf;
+ buf_T *buf, *nextbuf;
// When we cause a crash here it is caught and Vim tries to exit cleanly.
// Don't try freeing everything again.
@@ -574,10 +575,11 @@ void free_all_mem(void)
// Don't want to trigger autocommands from here on.
block_autocmds();
- /* Close all tabs and windows. Reset 'equalalways' to avoid redraws. */
+ // Close all tabs and windows. Reset 'equalalways' to avoid redraws.
p_ea = false;
- if (first_tabpage->tp_next != NULL)
+ if (first_tabpage->tp_next != NULL) {
do_cmdline_cmd("tabonly!");
+ }
if (!ONE_WINDOW) {
// to keep things simple, don't perform this
@@ -586,17 +588,17 @@ void free_all_mem(void)
do_cmdline_cmd("only!");
}
- /* Free all spell info. */
+ // Free all spell info.
spell_free_all();
- /* Clear user commands (before deleting buffers). */
+ // Clear user commands (before deleting buffers).
ex_comclear(NULL);
- /* Clear menus. */
+ // Clear menus.
do_cmdline_cmd("aunmenu *");
do_cmdline_cmd("menutranslate clear");
- /* Clear mappings, abbreviations, breakpoints. */
+ // Clear mappings, abbreviations, breakpoints.
do_cmdline_cmd("lmapclear");
do_cmdline_cmd("xmapclear");
do_cmdline_cmd("mapclear");
@@ -609,7 +611,7 @@ void free_all_mem(void)
free_titles();
free_findfile();
- /* Obviously named calls. */
+ // Obviously named calls.
free_all_autocmds();
free_all_marks();
alist_clear(&global_alist);
@@ -627,25 +629,25 @@ void free_all_mem(void)
diff_clear(curtab);
clear_sb_text(true); // free any scrollback text
- /* Free some global vars. */
+ // Free some global vars.
xfree(last_cmdline);
xfree(new_last_cmdline);
set_keep_msg(NULL, 0);
- /* Clear cmdline history. */
+ // Clear cmdline history.
p_hi = 0;
init_history();
qf_free_all(NULL);
- /* Free all location lists */
+ // Free all location lists
FOR_ALL_TAB_WINDOWS(tab, win) {
qf_free_all(win);
}
- /* Close all script inputs. */
+ // Close all script inputs.
close_all_scripts();
- /* Destroy all windows. Must come before freeing buffers. */
+ // Destroy all windows. Must come before freeing buffers.
win_free_all();
// Free all option values. Must come after closing windows.
@@ -653,13 +655,13 @@ void free_all_mem(void)
free_arshape_buf();
- /* Clear registers. */
+ // Clear registers.
clear_registers();
ResetRedobuff();
ResetRedobuff();
- /* highlight info */
+ // highlight info
free_highlight();
reset_last_sourcing();
@@ -667,10 +669,12 @@ void free_all_mem(void)
free_tabpage(first_tabpage);
first_tabpage = NULL;
- /* message history */
- for (;; )
- if (delete_first_msg() == FAIL)
+ // message history
+ for (;; ) {
+ if (delete_first_msg() == FAIL) {
break;
+ }
+ }
eval_clear();
api_vim_free_all_mem();
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index 5c07f87bd5..2b1a250604 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -10,27 +10,27 @@
#include <inttypes.h>
#include <string.h>
-#include "nvim/vim.h"
#include "nvim/ascii.h"
-#include "nvim/menu.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/eval.h"
+#include "nvim/eval/typval.h"
#include "nvim/ex_docmd.h"
+#include "nvim/garray.h"
#include "nvim/getchar.h"
+#include "nvim/keymap.h"
#include "nvim/memory.h"
+#include "nvim/menu.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/keymap.h"
-#include "nvim/garray.h"
+#include "nvim/screen.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
-#include "nvim/eval/typval.h"
-#include "nvim/screen.h"
+#include "nvim/vim.h"
#include "nvim/window.h"
-#define MENUDEPTH 10 /* maximum depth of menus */
+#define MENUDEPTH 10 // maximum depth of menus
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -43,8 +43,7 @@
/// The character for each menu mode
static char_u menu_mode_chars[] = { 'n', 'v', 's', 'o', 'i', 'c', 't' };
-static char_u e_notsubmenu[] = N_(
- "E327: Part of menu-item path is not sub-menu");
+static char_u e_notsubmenu[] = N_("E327: Part of menu-item path is not sub-menu");
static char_u e_othermode[] = N_("E328: Menu only exists in another mode");
static char_u e_nomenu[] = N_("E329: No menu \"%s\"");
@@ -63,18 +62,17 @@ static vimmenu_T **get_root_menu(const char_u *const name)
/// Do the :menu command and relatives.
/// @param eap Ex command arguments
-void
-ex_menu(exarg_T *eap)
+void ex_menu(exarg_T *eap)
{
- char_u *menu_path;
+ char_u *menu_path;
int modes;
- char_u *map_to; // command mapped to the menu entry
+ char_u *map_to; // command mapped to the menu entry
int noremap;
bool silent = false;
int unmenu;
- char_u *map_buf;
- char_u *arg;
- char_u *p;
+ char_u *map_buf;
+ char_u *arg;
+ char_u *p;
int i;
long pri_tab[MENUDEPTH + 1];
TriState enable = kNone; // kTrue for "menu enable",
@@ -109,8 +107,9 @@ ex_menu(exarg_T *eap)
if (STRNCMP(arg, "icon=", 5) == 0) {
arg += 5;
while (*arg != NUL && *arg != ' ') {
- if (*arg == '\\')
+ if (*arg == '\\') {
STRMOVE(arg, arg + 1);
+ }
MB_PTR_ADV(arg);
}
if (*arg != NUL) {
@@ -139,11 +138,13 @@ ex_menu(exarg_T *eap)
} else if (eap->addr_count && eap->line2 != 0) {
pri_tab[0] = eap->line2;
i = 1;
- } else
+ } else {
i = 0;
- while (i < MENUDEPTH)
+ }
+ while (i < MENUDEPTH) {
pri_tab[i++] = 500;
- pri_tab[MENUDEPTH] = -1; /* mark end of the table */
+ }
+ pri_tab[MENUDEPTH] = -1; // mark end of the table
/*
* Check for "disable" or "enable" argument.
@@ -195,31 +196,34 @@ ex_menu(exarg_T *eap)
}
if (menu_is_popup(menu_path)) {
- for (i = 0; i < MENU_INDEX_TIP; ++i)
+ for (i = 0; i < MENU_INDEX_TIP; ++i) {
if (modes & (1 << i)) {
p = popup_mode_name(menu_path, i);
menu_enable_recurse(*root_menu_ptr, p, MENU_ALL_MODES, enable);
xfree(p);
}
+ }
}
menu_enable_recurse(*root_menu_ptr, menu_path, modes, enable);
} else if (unmenu) {
/*
* Delete menu(s).
*/
- if (STRCMP(menu_path, "*") == 0) /* meaning: remove all menus */
+ if (STRCMP(menu_path, "*") == 0) { // meaning: remove all menus
menu_path = (char_u *)"";
+ }
/*
* For the PopUp menu, remove a menu for each mode separately.
*/
if (menu_is_popup(menu_path)) {
- for (i = 0; i < MENU_INDEX_TIP; ++i)
+ for (i = 0; i < MENU_INDEX_TIP; ++i) {
if (modes & (1 << i)) {
p = popup_mode_name(menu_path, i);
remove_menu(root_menu_ptr, p, MENU_ALL_MODES, true);
xfree(p);
}
+ }
}
// Careful: remove_menu() changes menu_path
@@ -229,7 +233,7 @@ ex_menu(exarg_T *eap)
* Add menu(s).
* Replace special key codes.
*/
- if (STRICMP(map_to, "<nop>") == 0) { /* "<Nop>" means nothing */
+ if (STRICMP(map_to, "<nop>") == 0) { // "<Nop>" means nothing
map_to = (char_u *)"";
map_buf = NULL;
} else if (modes & MENU_TIP_MODE) {
@@ -247,7 +251,7 @@ ex_menu(exarg_T *eap)
* For the PopUp menu, add a menu for each mode separately.
*/
if (menu_is_popup(menu_path)) {
- for (i = 0; i < MENU_INDEX_TIP; ++i)
+ for (i = 0; i < MENU_INDEX_TIP; ++i) {
if (modes & (1 << i)) {
p = popup_mode_name(menu_path, i);
// Include all modes, to make ":amenu" work
@@ -255,6 +259,7 @@ ex_menu(exarg_T *eap)
add_menu_path(p, &menuarg, pri_tab, map_to);
xfree(p);
}
+ }
}
xfree(map_buf);
@@ -272,33 +277,28 @@ theend:
/// @param[out] menuarg menu entry
/// @param[] pri_tab priority table
/// @param[in] call_data Right hand side command
-static int
-add_menu_path(
- const char_u *const menu_path,
- vimmenu_T *menuarg,
- const long *const pri_tab,
- const char_u *const call_data
-)
+static int add_menu_path(const char_u *const menu_path, vimmenu_T *menuarg,
+ const long *const pri_tab, const char_u *const call_data)
{
- char_u *path_name;
+ char_u *path_name;
int modes = menuarg->modes;
- vimmenu_T *menu = NULL;
- vimmenu_T *parent;
- vimmenu_T **lower_pri;
- char_u *p;
- char_u *name;
- char_u *dname;
- char_u *next_name;
+ vimmenu_T *menu = NULL;
+ vimmenu_T *parent;
+ vimmenu_T **lower_pri;
+ char_u *p;
+ char_u *name;
+ char_u *dname;
+ char_u *next_name;
char_u c;
char_u d;
int i;
int pri_idx = 0;
int old_modes = 0;
int amenu;
- char_u *en_name;
- char_u *map_to = NULL;
+ char_u *en_name;
+ char_u *map_to = NULL;
- /* Make a copy so we can stuff around with it, since it could be const */
+ // Make a copy so we can stuff around with it, since it could be const
path_name = vim_strsave(menu_path);
vimmenu_T **root_menu_ptr = get_root_menu(menu_path);
vimmenu_T **menup = root_menu_ptr;
@@ -317,12 +317,12 @@ add_menu_path(
}
dname = menu_text(name, NULL, NULL);
if (*dname == NUL) {
- /* Only a mnemonic or accelerator is not valid. */
+ // Only a mnemonic or accelerator is not valid.
EMSG(_("E792: Empty menu name"));
goto erret;
}
- /* See if it's already there */
+ // See if it's already there
lower_pri = menup;
menu = *menup;
while (menu != NULL) {
@@ -364,7 +364,7 @@ add_menu_path(
goto erret;
}
- /* Not already there, so lets add it */
+ // Not already there, so lets add it
menu = xcalloc(1, sizeof(vimmenu_T));
menu->modes = modes;
@@ -387,7 +387,6 @@ add_menu_path(
*lower_pri = menu;
old_modes = 0;
-
} else {
old_modes = menu->modes;
@@ -419,16 +418,17 @@ add_menu_path(
*/
amenu = ((modes & (MENU_NORMAL_MODE | MENU_INSERT_MODE)) ==
(MENU_NORMAL_MODE | MENU_INSERT_MODE));
- if (sys_menu)
+ if (sys_menu) {
modes &= ~old_modes;
+ }
if (menu != NULL && modes) {
p = (call_data == NULL) ? NULL : vim_strsave(call_data);
- /* loop over all modes, may add more than one */
+ // loop over all modes, may add more than one
for (i = 0; i < MENU_MODES; ++i) {
if (modes & (1 << i)) {
- /* free any old menu */
+ // free any old menu
free_menu_string(menu, i);
// For "amenu", may insert an extra character.
@@ -462,7 +462,7 @@ add_menu_path(
if (c == Ctrl_C) {
int len = (int)STRLEN(menu->strings[i]);
- /* Append CTRL-\ CTRL-G to obey 'insertmode'. */
+ // Append CTRL-\ CTRL-G to obey 'insertmode'.
menu->strings[i][len] = Ctrl_BSL;
menu->strings[i][len + 1] = Ctrl_G;
menu->strings[i][len + 2] = NUL;
@@ -504,20 +504,17 @@ erret:
* Set the (sub)menu with the given name to enabled or disabled.
* Called recursively.
*/
-static int menu_enable_recurse(vimmenu_T *menu,
- char_u *name,
- int modes,
- int enable)
+static int menu_enable_recurse(vimmenu_T *menu, char_u *name, int modes, int enable)
{
- char_u *p;
-
- if (menu == NULL)
- return OK; /* Got to bottom of hierarchy */
+ char_u *p;
- /* Get name of this element in the menu hierarchy */
+ if (menu == NULL) {
+ return OK; // Got to bottom of hierarchy
+ }
+ // Get name of this element in the menu hierarchy
p = menu_name_skip(name);
- /* Find the menu */
+ // Find the menu
while (menu != NULL) {
if (*name == NUL || *name == '*' || menu_name_equal(name, menu)) {
if (*p != NUL) {
@@ -539,8 +536,9 @@ static int menu_enable_recurse(vimmenu_T *menu,
* modes, so keep looping, otherwise we are just doing the named
* menu item (which has been found) so break here.
*/
- if (*name != NUL && *name != '*')
+ if (*name != NUL && *name != '*') {
break;
+ }
}
menu = menu->next;
}
@@ -553,42 +551,39 @@ static int menu_enable_recurse(vimmenu_T *menu,
return OK;
}
-/*
- * Remove the (sub)menu with the given name from the menu hierarchy
- * Called recursively.
- */
-static int
-remove_menu (
- vimmenu_T **menup,
- char_u *name,
- int modes,
- bool silent /* don't give error messages */
-)
+/// Remove the (sub)menu with the given name from the menu hierarchy
+/// Called recursively.
+///
+/// @param silent don't give error messages
+static int remove_menu(vimmenu_T **menup, char_u *name, int modes, bool silent)
{
- vimmenu_T *menu;
- vimmenu_T *child;
- char_u *p;
-
- if (*menup == NULL)
- return OK; /* Got to bottom of hierarchy */
+ vimmenu_T *menu;
+ vimmenu_T *child;
+ char_u *p;
- /* Get name of this element in the menu hierarchy */
+ if (*menup == NULL) {
+ return OK; // Got to bottom of hierarchy
+ }
+ // Get name of this element in the menu hierarchy
p = menu_name_skip(name);
- /* Find the menu */
+ // Find the menu
while ((menu = *menup) != NULL) {
if (*name == NUL || menu_name_equal(name, menu)) {
if (*p != NUL && menu->children == NULL) {
- if (!silent)
+ if (!silent) {
EMSG(_(e_notsubmenu));
+ }
return FAIL;
}
if ((menu->modes & modes) != 0x0) {
- if (remove_menu(&menu->children, p, modes, silent) == FAIL)
+ if (remove_menu(&menu->children, p, modes, silent) == FAIL) {
return FAIL;
+ }
} else if (*name != NUL) {
- if (!silent)
+ if (!silent) {
EMSG(_(e_othermode));
+ }
return FAIL;
}
@@ -597,39 +592,45 @@ remove_menu (
* modes, so keep looping, otherwise we are just removing the named
* menu item (which has been found) so break here.
*/
- if (*name != NUL)
+ if (*name != NUL) {
break;
+ }
/* Remove the menu item for the given mode[s]. If the menu item
* is no longer valid in ANY mode, delete it */
menu->modes &= ~modes;
- if (modes & MENU_TIP_MODE)
+ if (modes & MENU_TIP_MODE) {
free_menu_string(menu, MENU_INDEX_TIP);
- if ((menu->modes & MENU_ALL_MODES) == 0)
+ }
+ if ((menu->modes & MENU_ALL_MODES) == 0) {
free_menu(menup);
- else
+ } else {
menup = &menu->next;
- } else
+ }
+ } else {
menup = &menu->next;
+ }
}
if (*name != NUL) {
if (menu == NULL) {
- if (!silent)
+ if (!silent) {
EMSG2(_(e_nomenu), name);
+ }
return FAIL;
}
- /* Recalculate modes for menu based on the new updated children */
+ // Recalculate modes for menu based on the new updated children
menu->modes &= ~modes;
child = menu->children;
- for (; child != NULL; child = child->next)
+ for (; child != NULL; child = child->next) {
menu->modes |= child->modes;
+ }
if (modes & MENU_TIP_MODE) {
free_menu_string(menu, MENU_INDEX_TIP);
}
if ((menu->modes & MENU_ALL_MODES) == 0) {
- /* The menu item is no longer valid in ANY mode, so delete it */
+ // The menu item is no longer valid in ANY mode, so delete it
*menup = menu;
free_menu(menup);
}
@@ -644,7 +645,7 @@ remove_menu (
static void free_menu(vimmenu_T **menup)
{
int i;
- vimmenu_T *menu;
+ vimmenu_T *menu;
menu = *menup;
@@ -657,10 +658,10 @@ static void free_menu(vimmenu_T **menup)
xfree(menu->en_name);
xfree(menu->en_dname);
xfree(menu->actext);
- for (i = 0; i < MENU_MODES; i++)
+ for (i = 0; i < MENU_MODES; i++) {
free_menu_string(menu, i);
+ }
xfree(menu);
-
}
/*
@@ -671,11 +672,14 @@ static void free_menu_string(vimmenu_T *menu, int idx)
int count = 0;
int i;
- for (i = 0; i < MENU_MODES; i++)
- if (menu->strings[i] == menu->strings[idx])
+ for (i = 0; i < MENU_MODES; i++) {
+ if (menu->strings[i] == menu->strings[idx]) {
count++;
- if (count == 1)
+ }
+ }
+ if (count == 1) {
xfree(menu->strings[idx]);
+ }
menu->strings[idx] = NULL;
}
@@ -793,8 +797,8 @@ static vimmenu_T *find_menu(vimmenu_T *menu, char_u *name, int modes)
if (menu_name_equal(name, menu)) {
// Found menu
if (*p != NUL && menu->children == NULL) {
- EMSG(_(e_notsubmenu));
- return NULL;
+ EMSG(_(e_notsubmenu));
+ return NULL;
} else if ((menu->modes & modes) == 0x0) {
EMSG(_(e_othermode));
return NULL;
@@ -826,8 +830,8 @@ static int show_menus(char_u *const path_name, int modes)
return FAIL;
}
- /* Now we have found the matching menu, and we list the mappings */
- /* Highlight title */
+ // Now we have found the matching menu, and we list the mappings
+ // Highlight title
MSG_PUTS_TITLE(_("\n--- Menus ---"));
show_menus_recursive(menu->parent, modes, 0);
@@ -840,15 +844,18 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth)
int i;
int bit;
- if (menu != NULL && (menu->modes & modes) == 0x0)
+ if (menu != NULL && (menu->modes & modes) == 0x0) {
return;
+ }
if (menu != NULL) {
msg_putchar('\n');
- if (got_int) /* "q" hit for "--more--" */
+ if (got_int) { // "q" hit for "--more--"
return;
- for (i = 0; i < depth; i++)
+ }
+ for (i = 0; i < depth; i++) {
MSG_PUTS(" ");
+ }
if (menu->priority) {
msg_outnum((long)menu->priority);
MSG_PUTS(" ");
@@ -858,28 +865,33 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth)
}
if (menu != NULL && menu->children == NULL) {
- for (bit = 0; bit < MENU_MODES; bit++)
+ for (bit = 0; bit < MENU_MODES; bit++) {
if ((menu->modes & modes & (1 << bit)) != 0) {
msg_putchar('\n');
- if (got_int) /* "q" hit for "--more--" */
+ if (got_int) { // "q" hit for "--more--"
return;
- for (i = 0; i < depth + 2; i++)
+ }
+ for (i = 0; i < depth + 2; i++) {
MSG_PUTS(" ");
+ }
msg_putchar(menu_mode_chars[bit]);
- if (menu->noremap[bit] == REMAP_NONE)
+ if (menu->noremap[bit] == REMAP_NONE) {
msg_putchar('*');
- else if (menu->noremap[bit] == REMAP_SCRIPT)
+ } else if (menu->noremap[bit] == REMAP_SCRIPT) {
msg_putchar('&');
- else
+ } else {
msg_putchar(' ');
- if (menu->silent[bit])
+ }
+ if (menu->silent[bit]) {
msg_putchar('s');
- else
+ } else {
msg_putchar(' ');
- if ((menu->modes & menu->enabled & (1 << bit)) == 0)
+ }
+ if ((menu->modes & menu->enabled & (1 << bit)) == 0) {
msg_putchar('-');
- else
+ } else {
msg_putchar(' ');
+ }
MSG_PUTS(" ");
if (*menu->strings[bit] == NUL) {
msg_puts_attr("<Nop>", HL_ATTR(HLF_8));
@@ -887,17 +899,21 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth)
msg_outtrans_special(menu->strings[bit], false, 0);
}
}
+ }
} else {
if (menu == NULL) {
menu = root_menu;
depth--;
- } else
+ } else {
menu = menu->children;
+ }
- /* recursively show all children. Skip PopUp[nvoci]. */
- for (; menu != NULL && !got_int; menu = menu->next)
- if (!menu_is_hidden(menu->dname))
+ // recursively show all children. Skip PopUp[nvoci].
+ for (; menu != NULL && !got_int; menu = menu->next) {
+ if (!menu_is_hidden(menu->dname)) {
show_menus_recursive(menu, modes, depth + 1);
+ }
+ }
}
}
@@ -905,54 +921,58 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth)
/*
* Used when expanding menu names.
*/
-static vimmenu_T *expand_menu = NULL;
+static vimmenu_T *expand_menu = NULL;
static int expand_modes = 0x0;
-static int expand_emenu; /* TRUE for ":emenu" command */
+static int expand_emenu; // TRUE for ":emenu" command
/*
* Work out what to complete when doing command line completion of menu names.
*/
-char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg,
- bool forceit)
+char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg, bool forceit)
FUNC_ATTR_NONNULL_ALL
{
- char_u *after_dot;
- char_u *p;
- char_u *path_name = NULL;
- char_u *name;
+ char_u *after_dot;
+ char_u *p;
+ char_u *path_name = NULL;
+ char_u *name;
int unmenu;
- vimmenu_T *menu;
+ vimmenu_T *menu;
int expand_menus;
xp->xp_context = EXPAND_UNSUCCESSFUL;
- /* Check for priority numbers, enable and disable */
- for (p = arg; *p; ++p)
- if (!ascii_isdigit(*p) && *p != '.')
+ // Check for priority numbers, enable and disable
+ for (p = arg; *p; ++p) {
+ if (!ascii_isdigit(*p) && *p != '.') {
break;
+ }
+ }
if (!ascii_iswhite(*p)) {
if (STRNCMP(arg, "enable", 6) == 0
- && (arg[6] == NUL || ascii_iswhite(arg[6])))
+ && (arg[6] == NUL || ascii_iswhite(arg[6]))) {
p = arg + 6;
- else if (STRNCMP(arg, "disable", 7) == 0
- && (arg[7] == NUL || ascii_iswhite(arg[7])))
+ } else if (STRNCMP(arg, "disable", 7) == 0
+ && (arg[7] == NUL || ascii_iswhite(arg[7]))) {
p = arg + 7;
- else
+ } else {
p = arg;
+ }
}
- while (*p != NUL && ascii_iswhite(*p))
+ while (*p != NUL && ascii_iswhite(*p)) {
++p;
+ }
arg = after_dot = p;
for (; *p && !ascii_iswhite(*p); ++p) {
- if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL)
+ if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL) {
p++;
- else if (*p == '.')
+ } else if (*p == '.') {
after_dot = p + 1;
+ }
}
// ":popup" only uses menus, not entries
@@ -966,12 +986,13 @@ char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg,
// With :menu though you might want to add a menu with the same name as
// one in another mode, so match menus from other modes too.
expand_modes = get_menu_cmd_modes(cmd, forceit, NULL, &unmenu);
- if (!unmenu)
+ if (!unmenu) {
expand_modes = MENU_ALL_MODES;
+ }
menu = root_menu;
if (after_dot > arg) {
- size_t path_len = (size_t) (after_dot - arg);
+ size_t path_len = (size_t)(after_dot - arg);
path_name = xmalloc(path_len);
STRLCPY(path_name, arg, path_len);
}
@@ -980,7 +1001,7 @@ char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg,
p = menu_name_skip(name);
while (menu != NULL) {
if (menu_name_equal(name, menu)) {
- /* Found menu */
+ // Found menu
if ((*p != NUL && menu->children == NULL)
|| ((menu->modes & expand_modes) == 0x0)) {
/*
@@ -995,7 +1016,7 @@ char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg,
menu = menu->next;
}
if (menu == NULL) {
- /* No menu found with the name we were looking for */
+ // No menu found with the name we were looking for
xfree(path_name);
return NULL;
}
@@ -1019,35 +1040,38 @@ char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg,
*/
char_u *get_menu_name(expand_T *xp, int idx)
{
- static vimmenu_T *menu = NULL;
- char_u *str;
+ static vimmenu_T *menu = NULL;
+ char_u *str;
static int should_advance = FALSE;
- if (idx == 0) { /* first call: start at first item */
+ if (idx == 0) { // first call: start at first item
menu = expand_menu;
should_advance = false;
}
- /* Skip PopUp[nvoci]. */
+ // Skip PopUp[nvoci].
while (menu != NULL && (menu_is_hidden(menu->dname)
|| menu_is_separator(menu->dname)
|| menu->children == NULL)) {
menu = menu->next;
}
- if (menu == NULL) /* at end of linked list */
+ if (menu == NULL) { // at end of linked list
return NULL;
+ }
- if (menu->modes & expand_modes)
- if (should_advance)
+ if (menu->modes & expand_modes) {
+ if (should_advance) {
str = menu->en_dname;
- else {
+ } else {
str = menu->dname;
- if (menu->en_dname == NULL)
+ if (menu->en_dname == NULL) {
should_advance = TRUE;
+ }
}
- else
+ } else {
str = (char_u *)"";
+ }
if (should_advance) {
// Advance to next menu entry.
@@ -1065,18 +1089,18 @@ char_u *get_menu_name(expand_T *xp, int idx)
*/
char_u *get_menu_names(expand_T *xp, int idx)
{
- static vimmenu_T *menu = NULL;
+ static vimmenu_T *menu = NULL;
#define TBUFFER_LEN 256
- static char_u tbuffer[TBUFFER_LEN]; /*hack*/
- char_u *str;
+ static char_u tbuffer[TBUFFER_LEN]; //hack
+ char_u *str;
static bool should_advance = false;
- if (idx == 0) { /* first call: start at first item */
+ if (idx == 0) { // first call: start at first item
menu = expand_menu;
should_advance = false;
}
- /* Skip Browse-style entries, popup menus and separators. */
+ // Skip Browse-style entries, popup menus and separators.
while (menu != NULL
&& (menu_is_hidden(menu->dname)
|| (expand_emenu && menu_is_separator(menu->dname))
@@ -1084,8 +1108,9 @@ char_u *get_menu_names(expand_T *xp, int idx)
menu = menu->next;
}
- if (menu == NULL) /* at end of linked list */
+ if (menu == NULL) { // at end of linked list
return NULL;
+ }
if (menu->modes & expand_modes) {
if (menu->children != NULL) {
@@ -1102,17 +1127,18 @@ char_u *get_menu_names(expand_T *xp, int idx)
STRCAT(tbuffer, "\001");
str = tbuffer;
} else {
- if (should_advance)
+ if (should_advance) {
str = menu->en_dname;
- else {
+ } else {
str = menu->dname;
if (menu->en_dname == NULL) {
should_advance = true;
}
}
}
- } else
+ } else {
str = (char_u *)"";
+ }
if (should_advance) {
// Advance to next menu entry.
@@ -1132,17 +1158,19 @@ char_u *get_menu_names(expand_T *xp, int idx)
/// @return start of the next element
char_u *menu_name_skip(char_u *const name)
{
- char_u *p;
+ char_u *p;
for (p = name; *p && *p != '.'; MB_PTR_ADV(p)) {
if (*p == '\\' || *p == Ctrl_V) {
STRMOVE(p, p + 1);
- if (*p == NUL)
+ if (*p == NUL) {
break;
+ }
}
}
- if (*p)
+ if (*p) {
*p++ = NUL;
+ }
return p;
}
@@ -1154,8 +1182,9 @@ static bool menu_name_equal(const char_u *const name, vimmenu_T *const menu)
{
if (menu->en_name != NULL
&& (menu_namecmp(name, menu->en_name)
- || menu_namecmp(name, menu->en_dname)))
+ || menu_namecmp(name, menu->en_dname))) {
return true;
+ }
return menu_namecmp(name, menu->name) || menu_namecmp(name, menu->dname);
}
@@ -1163,9 +1192,11 @@ static bool menu_namecmp(const char_u *const name, const char_u *const mname)
{
int i;
- for (i = 0; name[i] != NUL && name[i] != TAB; ++i)
- if (name[i] != mname[i])
+ for (i = 0; name[i] != NUL && name[i] != TAB; ++i) {
+ if (name[i] != mname[i]) {
break;
+ }
+ }
return (name[i] == NUL || name[i] == TAB)
&& (mname[i] == NUL || mname[i] == TAB);
}
@@ -1180,45 +1211,39 @@ static bool menu_namecmp(const char_u *const name, const char_u *const mname)
/// to whether the command is a "nore" command.
/// @param[out] unmenu If not NULL, the flag it points to is set according
/// to whether the command is an "unmenu" command.
-int
-get_menu_cmd_modes(
- const char *cmd,
- bool forceit,
- int *noremap,
- int *unmenu
-)
+int get_menu_cmd_modes(const char *cmd, bool forceit, int *noremap, int *unmenu)
{
int modes;
switch (*cmd++) {
- case 'v': /* vmenu, vunmenu, vnoremenu */
+ case 'v': // vmenu, vunmenu, vnoremenu
modes = MENU_VISUAL_MODE | MENU_SELECT_MODE;
break;
- case 'x': /* xmenu, xunmenu, xnoremenu */
+ case 'x': // xmenu, xunmenu, xnoremenu
modes = MENU_VISUAL_MODE;
break;
- case 's': /* smenu, sunmenu, snoremenu */
+ case 's': // smenu, sunmenu, snoremenu
modes = MENU_SELECT_MODE;
break;
- case 'o': /* omenu */
+ case 'o': // omenu
modes = MENU_OP_PENDING_MODE;
break;
- case 'i': /* imenu */
+ case 'i': // imenu
modes = MENU_INSERT_MODE;
break;
case 't':
- modes = MENU_TIP_MODE; /* tmenu */
+ modes = MENU_TIP_MODE; // tmenu
break;
- case 'c': /* cmenu */
+ case 'c': // cmenu
modes = MENU_CMDLINE_MODE;
break;
- case 'a': /* amenu */
+ case 'a': // amenu
modes = MENU_INSERT_MODE | MENU_CMDLINE_MODE | MENU_NORMAL_MODE
| MENU_VISUAL_MODE | MENU_SELECT_MODE
| MENU_OP_PENDING_MODE;
break;
case 'n':
- if (*cmd != 'o') { /* nmenu, not noremenu */
+ if (*cmd != 'o') { // nmenu, not noremenu
modes = MENU_NORMAL_MODE;
break;
}
@@ -1235,10 +1260,12 @@ get_menu_cmd_modes(
}
}
- if (noremap != NULL)
+ if (noremap != NULL) {
*noremap = (*cmd == 'n' ? REMAP_NONE : REMAP_YES);
- if (unmenu != NULL)
+ }
+ if (unmenu != NULL) {
*unmenu = (*cmd == 'u');
+ }
return modes;
}
@@ -1274,27 +1301,31 @@ static char_u *menu_text(const char_u *str, int *mnemonic, char_u **actext)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
FUNC_ATTR_NONNULL_ARG(1)
{
- char_u *p;
- char_u *text;
+ char_u *p;
+ char_u *text;
- /* Locate accelerator text, after the first TAB */
+ // Locate accelerator text, after the first TAB
p = vim_strchr(str, TAB);
if (p != NULL) {
- if (actext != NULL)
+ if (actext != NULL) {
*actext = vim_strsave(p + 1);
+ }
assert(p >= str);
text = vim_strnsave(str, (size_t)(p - str));
- } else
+ } else {
text = vim_strsave(str);
+ }
- /* Find mnemonic characters "&a" and reduce "&&" to "&". */
+ // Find mnemonic characters "&a" and reduce "&&" to "&".
for (p = text; p != NULL; ) {
p = vim_strchr(p, '&');
if (p != NULL) {
- if (p[1] == NUL) /* trailing "&" */
+ if (p[1] == NUL) { // trailing "&"
break;
- if (mnemonic != NULL && p[1] != '&')
+ }
+ if (mnemonic != NULL && p[1] != '&') {
*mnemonic = p[1];
+ }
STRMOVE(p, p + 1);
p = p + 1;
}
@@ -1343,7 +1374,7 @@ int menu_is_separator(char_u *name)
static int menu_is_hidden(char_u *name)
{
return (name[0] == MNU_HIDDEN_CHAR)
- || (menu_is_popup(name) && name[5] != NUL);
+ || (menu_is_popup(name) && name[5] != NUL);
}
// Execute "menu". Use by ":emenu" and the window toolbar.
@@ -1359,8 +1390,8 @@ static void execute_menu(const exarg_T *eap, vimmenu_T *menu)
mode = (char_u *)"Insert";
idx = MENU_INDEX_INSERT;
} else if (State & CMDLINE) {
- mode = (char_u *)"Command";
- idx = MENU_INDEX_CMDLINE;
+ mode = (char_u *)"Command";
+ idx = MENU_INDEX_CMDLINE;
} else if (get_real_state() & VISUAL) {
/* Detect real visual mode -- if we are really in visual mode we
* don't need to do any guesswork to figure out what the selection
@@ -1379,13 +1410,13 @@ static void execute_menu(const exarg_T *eap, vimmenu_T *menu)
* select start and end. */
if ((curbuf->b_visual.vi_start.lnum == eap->line1)
&& (curbuf->b_visual.vi_end.lnum) == eap->line2) {
- /* Set it up for visual mode - equivalent to gv. */
+ // Set it up for visual mode - equivalent to gv.
VIsual_mode = curbuf->b_visual.vi_mode;
tpos = curbuf->b_visual.vi_end;
curwin->w_cursor = curbuf->b_visual.vi_start;
curwin->w_curswant = curbuf->b_visual.vi_curswant;
} else {
- /* Set it up for line-wise visual mode */
+ // Set it up for line-wise visual mode
VIsual_mode = 'V';
curwin->w_cursor.lnum = eap->line1;
curwin->w_cursor.col = 1;
@@ -1394,7 +1425,7 @@ static void execute_menu(const exarg_T *eap, vimmenu_T *menu)
tpos.coladd = 0;
}
- /* Activate visual mode */
+ // Activate visual mode
VIsual_active = TRUE;
VIsual_reselect = TRUE;
check_cursor();
@@ -1484,15 +1515,15 @@ void ex_emenu(exarg_T *eap)
*/
typedef struct {
- char_u *from; /* English name */
- char_u *from_noamp; /* same, without '&' */
- char_u *to; /* translated name */
+ char_u *from; // English name
+ char_u *from_noamp; // same, without '&'
+ char_u *to; // translated name
} menutrans_T;
static garray_T menutrans_ga = GA_EMPTY_INIT_VALUE;
#define FREE_MENUTRANS(mt) \
- menutrans_T* _mt = (mt); \
+ menutrans_T * _mt = (mt); \
xfree(_mt->from); \
xfree(_mt->from_noamp); \
xfree(_mt->to)
@@ -1504,11 +1535,12 @@ static garray_T menutrans_ga = GA_EMPTY_INIT_VALUE;
*/
void ex_menutranslate(exarg_T *eap)
{
- char_u *arg = eap->arg;
- char_u *from, *from_noamp, *to;
+ char_u *arg = eap->arg;
+ char_u *from, *from_noamp, *to;
- if (menutrans_ga.ga_itemsize == 0)
+ if (menutrans_ga.ga_itemsize == 0) {
ga_init(&menutrans_ga, (int)sizeof(menutrans_T), 5);
+ }
/*
* ":menutrans clear": clear all translations.
@@ -1516,18 +1548,18 @@ void ex_menutranslate(exarg_T *eap)
if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) {
GA_DEEP_CLEAR(&menutrans_ga, menutrans_T, FREE_MENUTRANS);
- /* Delete all "menutrans_" global variables. */
+ // Delete all "menutrans_" global variables.
del_menutrans_vars();
} else {
- /* ":menutrans from to": add translation */
+ // ":menutrans from to": add translation
from = arg;
arg = menu_skip_part(arg);
to = skipwhite(arg);
*arg = NUL;
arg = menu_skip_part(to);
- if (arg == to)
+ if (arg == to) {
EMSG(_(e_invarg));
- else {
+ } else {
from = vim_strsave(from);
from_noamp = menu_text(from, NULL, NULL);
assert(arg >= to);
@@ -1536,7 +1568,7 @@ void ex_menutranslate(exarg_T *eap)
menu_translate_tab_and_shift(to);
menu_unescape_name(from);
menu_unescape_name(to);
- menutrans_T* tp = GA_APPEND_VIA_PTR(menutrans_T, &menutrans_ga);
+ menutrans_T * tp = GA_APPEND_VIA_PTR(menutrans_T, &menutrans_ga);
tp->from = from;
tp->from_noamp = from_noamp;
tp->to = to;
@@ -1550,8 +1582,9 @@ void ex_menutranslate(exarg_T *eap)
static char_u *menu_skip_part(char_u *p)
{
while (*p != NUL && *p != '.' && !ascii_iswhite(*p)) {
- if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL)
+ if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL) {
++p;
+ }
++p;
}
return p;
@@ -1563,8 +1596,8 @@ static char_u *menu_skip_part(char_u *p)
*/
static char_u *menutrans_lookup(char_u *name, int len)
{
- menutrans_T *tp = (menutrans_T *)menutrans_ga.ga_data;
- char_u *dname;
+ menutrans_T *tp = (menutrans_T *)menutrans_ga.ga_data;
+ char_u *dname;
for (int i = 0; i < menutrans_ga.ga_len; i++) {
if (STRNICMP(name, tp[i].from, len) == 0 && tp[i].from[len] == NUL) {
@@ -1572,7 +1605,7 @@ static char_u *menutrans_lookup(char_u *name, int len)
}
}
- /* Now try again while ignoring '&' characters. */
+ // Now try again while ignoring '&' characters.
char_u c = name[len];
name[len] = NUL;
dname = menu_text(name, NULL, NULL);
@@ -1593,7 +1626,7 @@ static char_u *menutrans_lookup(char_u *name, int len)
*/
static void menu_unescape_name(char_u *name)
{
- char_u *p;
+ char_u *p;
for (p = name; *p && *p != '.'; MB_PTR_ADV(p)) {
if (*p == '\\') {
@@ -1608,19 +1641,20 @@ static void menu_unescape_name(char_u *name)
*/
static char_u *menu_translate_tab_and_shift(char_u *arg_start)
{
- char_u *arg = arg_start;
+ char_u *arg = arg_start;
while (*arg && !ascii_iswhite(*arg)) {
- if ((*arg == '\\' || *arg == Ctrl_V) && arg[1] != NUL)
+ if ((*arg == '\\' || *arg == Ctrl_V) && arg[1] != NUL) {
arg++;
- else if (STRNICMP(arg, "<TAB>", 5) == 0) {
+ } else if (STRNICMP(arg, "<TAB>", 5) == 0) {
*arg = TAB;
STRMOVE(arg + 1, arg + 5);
}
arg++;
}
- if (*arg != NUL)
+ if (*arg != NUL) {
*arg++ = NUL;
+ }
arg = skipwhite(arg);
return arg;
diff --git a/src/nvim/message.c b/src/nvim/message.c
index f9ed9f3004..f9fe7774f6 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -7,42 +7,42 @@
#include <assert.h>
#include <inttypes.h>
-#include <stdbool.h>
#include <stdarg.h>
+#include <stdbool.h>
#include <string.h>
-#include "nvim/vim.h"
+#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/assert.h"
-#include "nvim/message.h"
#include "nvim/charset.h"
#include "nvim/eval.h"
-#include "nvim/ex_eval.h"
#include "nvim/ex_docmd.h"
+#include "nvim/ex_eval.h"
#include "nvim/fileio.h"
#include "nvim/func_attr.h"
+#include "nvim/garray.h"
#include "nvim/getchar.h"
+#include "nvim/highlight.h"
+#include "nvim/keymap.h"
#include "nvim/main.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
+#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/keymap.h"
-#include "nvim/garray.h"
+#include "nvim/mouse.h"
+#include "nvim/normal.h"
#include "nvim/ops.h"
#include "nvim/option.h"
-#include "nvim/normal.h"
+#include "nvim/os/input.h"
+#include "nvim/os/os.h"
+#include "nvim/os/time.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
-#include "nvim/highlight.h"
#include "nvim/ui.h"
#include "nvim/ui_compositor.h"
-#include "nvim/mouse.h"
-#include "nvim/os/os.h"
-#include "nvim/os/input.h"
-#include "nvim/os/time.h"
-#include "nvim/api/private/helpers.h"
+#include "nvim/vim.h"
/*
* To be able to scroll back at the "more" and "hit-enter" prompts we need to
@@ -50,24 +50,24 @@
*/
typedef struct msgchunk_S msgchunk_T;
struct msgchunk_S {
- msgchunk_T *sb_next;
- msgchunk_T *sb_prev;
- char sb_eol; /* TRUE when line ends after this text */
- int sb_msg_col; /* column in which text starts */
- int sb_attr; /* text attributes */
- char_u sb_text[1]; /* text to be displayed, actually longer */
+ msgchunk_T *sb_next;
+ msgchunk_T *sb_prev;
+ char sb_eol; // TRUE when line ends after this text
+ int sb_msg_col; // column in which text starts
+ int sb_attr; // text attributes
+ char_u sb_text[1]; // text to be displayed, actually longer
};
-/* Magic chars used in confirm dialog strings */
+// Magic chars used in confirm dialog strings
#define DLG_BUTTON_SEP '\n'
#define DLG_HOTKEY_CHAR '&'
-static int confirm_msg_used = FALSE; /* displaying confirm_msg */
+static int confirm_msg_used = FALSE; // displaying confirm_msg
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "message.c.generated.h"
#endif
-static char_u *confirm_msg = NULL; /* ":confirm" message */
-static char_u *confirm_msg_tail; /* tail of confirm_msg */
+static char_u *confirm_msg = NULL; // ":confirm" message
+static char_u *confirm_msg_tail; // tail of confirm_msg
MessageHistoryEntry *first_msg_hist = NULL;
MessageHistoryEntry *last_msg_hist = NULL;
@@ -79,37 +79,37 @@ static int verbose_did_open = FALSE;
/*
* When writing messages to the screen, there are many different situations.
* A number of variables is used to remember the current state:
- * msg_didany true when messages were written since the last time the
- * user reacted to a prompt.
- * Reset: After hitting a key for the hit-return prompt,
- * hitting <CR> for the command line or input().
- * Set: When any message is written to the screen.
- * msg_didout true when something was written to the current line.
- * Reset: When advancing to the next line, when the current
- * text can be overwritten.
- * Set: When any message is written to the screen.
- * msg_nowait No extra delay for the last drawn message.
- * Used in normal_cmd() before the mode message is drawn.
+ * msg_didany true when messages were written since the last time the
+ * user reacted to a prompt.
+ * Reset: After hitting a key for the hit-return prompt,
+ * hitting <CR> for the command line or input().
+ * Set: When any message is written to the screen.
+ * msg_didout true when something was written to the current line.
+ * Reset: When advancing to the next line, when the current
+ * text can be overwritten.
+ * Set: When any message is written to the screen.
+ * msg_nowait No extra delay for the last drawn message.
+ * Used in normal_cmd() before the mode message is drawn.
* emsg_on_display There was an error message recently. Indicates that there
- * should be a delay before redrawing.
- * msg_scroll The next message should not overwrite the current one.
- * msg_scrolled How many lines the screen has been scrolled (because of
- * messages). Used in update_screen() to scroll the screen
- * back. Incremented each time the screen scrolls a line.
+ * should be a delay before redrawing.
+ * msg_scroll The next message should not overwrite the current one.
+ * msg_scrolled How many lines the screen has been scrolled (because of
+ * messages). Used in update_screen() to scroll the screen
+ * back. Incremented each time the screen scrolls a line.
* msg_scrolled_ign TRUE when msg_scrolled is non-zero and msg_puts_attr()
- * writes something without scrolling should not make
- * need_wait_return to be set. This is a hack to make ":ts"
- * work without an extra prompt.
- * lines_left Number of lines available for messages before the
- * more-prompt is to be given. -1 when not set.
+ * writes something without scrolling should not make
+ * need_wait_return to be set. This is a hack to make ":ts"
+ * work without an extra prompt.
+ * lines_left Number of lines available for messages before the
+ * more-prompt is to be given. -1 when not set.
* need_wait_return true when the hit-return prompt is needed.
- * Reset: After giving the hit-return prompt, when the user
- * has answered some other prompt.
- * Set: When the ruler or typeahead display is overwritten,
- * scrolling the screen for some message.
- * keep_msg Message to be displayed after redrawing the screen, in
- * main_loop().
- * This is an allocated string or NULL when not used.
+ * Reset: After giving the hit-return prompt, when the user
+ * has answered some other prompt.
+ * Set: When the ruler or typeahead display is overwritten,
+ * scrolling the screen for some message.
+ * keep_msg Message to be displayed after redrawing the screen, in
+ * main_loop().
+ * This is an allocated string or NULL when not used.
*/
@@ -231,8 +231,7 @@ int msg_attr(const char *s, const int attr)
}
/// similar to msg_outtrans_attr, but support newlines and tabs.
-void msg_multiline_attr(const char *s, int attr,
- bool check_int, bool *need_clear)
+void msg_multiline_attr(const char *s, int attr, bool check_int, bool *need_clear)
FUNC_ATTR_NONNULL_ALL
{
const char *next_spec = s;
@@ -287,16 +286,17 @@ bool msg_attr_keep(char_u *s, int attr, bool keep, bool multiline)
}
if (attr == 0) {
- set_vim_var_string(VV_STATUSMSG, (char *) s, -1);
+ set_vim_var_string(VV_STATUSMSG, (char *)s, -1);
}
/*
* It is possible that displaying a messages causes a problem (e.g.,
- * when redrawing the window), which causes another message, etc.. To
+ * when redrawing the window), which causes another message, etc.. To
* break this loop, limit the recursiveness to 3 levels.
*/
- if (entered >= 3)
+ if (entered >= 3) {
return TRUE;
+ }
++entered;
/* Add message to history (unless it's a repeated kept message or a
@@ -309,11 +309,12 @@ bool msg_attr_keep(char_u *s, int attr, bool keep, bool multiline)
add_msg_hist((const char *)s, -1, attr, multiline);
}
- /* Truncate the message if needed. */
+ // Truncate the message if needed.
msg_start();
buf = msg_strtrunc(s, FALSE);
- if (buf != NULL)
+ if (buf != NULL) {
s = buf;
+ }
bool need_clear = true;
if (multiline) {
@@ -336,31 +337,28 @@ bool msg_attr_keep(char_u *s, int attr, bool keep, bool multiline)
return retval;
}
-/*
- * Truncate a string such that it can be printed without causing a scroll.
- * Returns an allocated string or NULL when no truncating is done.
- */
-char_u *
-msg_strtrunc (
- char_u *s,
- int force /* always truncate */
-)
+/// Truncate a string such that it can be printed without causing a scroll.
+/// Returns an allocated string or NULL when no truncating is done.
+///
+/// @param force always truncate
+char_u *msg_strtrunc(char_u *s, int force)
{
- char_u *buf = NULL;
+ char_u *buf = NULL;
int len;
int room;
- /* May truncate message to avoid a hit-return prompt */
+ // May truncate message to avoid a hit-return prompt
if ((!msg_scroll && !need_wait_return && shortmess(SHM_TRUNCALL)
&& !exmode_active && msg_silent == 0 && !ui_has(kUIMessages))
|| force) {
len = vim_strsize(s);
- if (msg_scrolled != 0)
- /* Use all the columns. */
+ if (msg_scrolled != 0) {
+ // Use all the columns.
room = (int)(Rows - msg_row) * Columns - 1;
- else
- /* Use up to 'showcmd' column. */
+ } else {
+ // Use up to 'showcmd' column.
room = (int)(Rows - msg_row - 1) * Columns + sc_col - 1;
+ }
if (len > room && room > 0) {
// may have up to 18 bytes per cell (6 per char, up to two
// composing chars)
@@ -390,10 +388,10 @@ void trunc_string(char_u *s, char_u *buf, int room_in, int buflen)
}
half = room / 2;
- /* First part: Start of the string. */
+ // First part: Start of the string.
for (e = 0; len < half && e < buflen; ++e) {
if (s[e] == NUL) {
- /* text fits without truncating! */
+ // text fits without truncating!
buf[e] = NUL;
return;
}
@@ -497,7 +495,7 @@ int smsg_attr_keep(int attr, char *s, ...)
* isn't printed each time when it didn't change.
*/
static int last_sourcing_lnum = 0;
-static char_u *last_sourcing_name = NULL;
+static char_u *last_sourcing_name = NULL;
/*
* Reset the last used sourcing name/lnum. Makes sure it is displayed again
@@ -515,8 +513,9 @@ void reset_last_sourcing(void)
static int other_sourcing_name(void)
{
if (sourcing_name != NULL) {
- if (last_sourcing_name != NULL)
+ if (last_sourcing_name != NULL) {
return STRCMP(sourcing_name, last_sourcing_name) != 0;
+ }
return TRUE;
}
return FALSE;
@@ -577,16 +576,17 @@ void msg_source(int attr)
if (p != NULL) {
msg_attr(p, HL_ATTR(HLF_N));
xfree(p);
- last_sourcing_lnum = sourcing_lnum; /* only once for each line */
+ last_sourcing_lnum = sourcing_lnum; // only once for each line
}
- /* remember the last sourcing name printed, also when it's empty */
+ // remember the last sourcing name printed, also when it's empty
if (sourcing_name == NULL || other_sourcing_name()) {
xfree(last_sourcing_name);
- if (sourcing_name == NULL)
+ if (sourcing_name == NULL) {
last_sourcing_name = NULL;
- else
+ } else {
last_sourcing_name = vim_strsave(sourcing_name);
+ }
}
--no_wait_return;
}
@@ -601,9 +601,9 @@ int emsg_not_now(void)
{
if ((emsg_off > 0 && vim_strchr(p_debug, 'm') == NULL
&& vim_strchr(p_debug, 't') == NULL)
- || emsg_skip > 0
- )
+ || emsg_skip > 0) {
return TRUE;
+ }
return FALSE;
}
@@ -794,9 +794,9 @@ static bool emsgfv(const char *fmt, va_list ap)
/// detected when fuzzing vim.
void iemsg(const char *s)
{
- emsg((char_u *)s);
+ emsg((char_u *)s);
#ifdef ABORT_ON_INTERNAL_ERROR
- abort();
+ abort();
#endif
}
@@ -805,19 +805,19 @@ void iemsg(const char *s)
/// detected when fuzzing vim.
void iemsgf(const char *s, ...)
{
- va_list ap;
- va_start(ap, s);
- (void)emsgfv(s, ap);
- va_end(ap);
+ va_list ap;
+ va_start(ap, s);
+ (void)emsgfv(s, ap);
+ va_end(ap);
#ifdef ABORT_ON_INTERNAL_ERROR
- abort();
+ abort();
#endif
}
/// Give an "Internal error" message.
void internal_error(char *where)
{
- IEMSG2(_(e_intern2), where);
+ IEMSG2(_(e_intern2), where);
}
static void msg_emsgf_event(void **argv)
@@ -858,8 +858,9 @@ char_u *msg_trunc_attr(char_u *s, int force, int attr)
n = msg_attr((const char *)s, attr);
msg_hist_off = false;
- if (n)
+ if (n) {
return s;
+ }
return NULL;
}
@@ -930,18 +931,21 @@ void add_hl_msg_hist(HlMessage hl_msg)
/// @param[in] len Length of s or -1.
static void add_msg_hist(const char *s, int len, int attr, bool multiline)
{
- if (msg_hist_off || msg_silent != 0)
+ if (msg_hist_off || msg_silent != 0) {
return;
+ }
- /* Don't let the message history get too big */
- while (msg_hist_len > MAX_MSG_HIST_LEN)
+ // Don't let the message history get too big
+ while (msg_hist_len > MAX_MSG_HIST_LEN) {
(void)delete_first_msg();
+ }
- /* allocate an entry and add the message at the end of the history */
+ // allocate an entry and add the message at the end of the history
struct msg_hist *p = xmalloc(sizeof(struct msg_hist));
- if (len < 0)
+ if (len < 0) {
len = (int)STRLEN(s);
- /* remove leading and trailing newlines */
+ }
+ // remove leading and trailing newlines
while (len > 0 && *s == '\n') {
++s;
--len;
@@ -972,11 +976,12 @@ int delete_first_msg(void)
{
struct msg_hist *p;
- if (msg_hist_len <= 0)
+ if (msg_hist_len <= 0) {
return FAIL;
+ }
p = first_msg_hist;
first_msg_hist = p->next;
- if (first_msg_hist == NULL) { /* history is becoming empty */
+ if (first_msg_hist == NULL) { // history is becoming empty
assert(msg_hist_len == 1);
last_msg_hist = NULL;
}
@@ -1078,7 +1083,7 @@ void wait_return(int redraw)
int oldState;
int tmpState;
int had_got_int;
- FILE *save_scriptout;
+ FILE *save_scriptout;
if (redraw == true) {
redraw_all_later(NOT_VALID);
@@ -1086,8 +1091,9 @@ void wait_return(int redraw)
/* If using ":silent cmd", don't wait for a return. Also don't set
* need_wait_return to do it later. */
- if (msg_silent != 0)
+ if (msg_silent != 0) {
return;
+ }
/*
* When inside vgetc(), we can't wait for a typed character at all.
@@ -1095,24 +1101,26 @@ void wait_return(int redraw)
* the end. Adjust cmdline_row to avoid the next message overwriting the
* last one.
*/
- if (vgetc_busy > 0)
+ if (vgetc_busy > 0) {
return;
+ }
need_wait_return = true;
if (no_wait_return) {
- if (!exmode_active)
+ if (!exmode_active) {
cmdline_row = msg_row;
+ }
return;
}
redir_off = true; // don't redirect this message
oldState = State;
if (quit_more) {
- c = CAR; /* just pretend CR was hit */
+ c = CAR; // just pretend CR was hit
quit_more = FALSE;
got_int = FALSE;
} else if (exmode_active) {
- MSG_PUTS(" "); /* make sure the cursor is on the right line */
- c = CAR; /* no need for a return in ex mode */
+ MSG_PUTS(" "); // make sure the cursor is on the right line
+ c = CAR; // no need for a return in ex mode
got_int = FALSE;
} else {
// Make sure the hit-return prompt is on screen when 'guioptions' was
@@ -1176,7 +1184,7 @@ void wait_return(int redraw)
0;
}
if (quit_more) {
- c = CAR; /* just pretend CR was hit */
+ c = CAR; // just pretend CR was hit
quit_more = FALSE;
got_int = FALSE;
} else if (c != K_IGNORE) {
@@ -1185,8 +1193,9 @@ void wait_return(int redraw)
}
} else if (msg_scrolled > Rows - 2
&& (c == 'j' || c == 'd' || c == 'f'
- || c == K_DOWN || c == K_PAGEDOWN))
+ || c == K_DOWN || c == K_PAGEDOWN)) {
c = K_IGNORE;
+ }
}
} while ((had_got_int && c == Ctrl_C)
|| c == K_IGNORE
@@ -1201,9 +1210,9 @@ void wait_return(int redraw)
* Avoid that the mouse-up event causes visual mode to start.
*/
if (c == K_LEFTMOUSE || c == K_MIDDLEMOUSE || c == K_RIGHTMOUSE
- || c == K_X1MOUSE || c == K_X2MOUSE)
+ || c == K_X1MOUSE || c == K_X2MOUSE) {
(void)jump_to_mouse(MOUSE_SETPOS, NULL, 0);
- else if (vim_strchr((char_u *)"\r\n ", c) == NULL && c != Ctrl_C) {
+ } else if (vim_strchr((char_u *)"\r\n ", c) == NULL && c != Ctrl_C) {
/* Put the character back in the typeahead buffer. Don't use the
* stuff buffer, because lmaps wouldn't work. */
ins_char_typebuf(c);
@@ -1216,8 +1225,9 @@ void wait_return(int redraw)
// If the user hits ':', '?' or '/' we get a command line from the next
// line.
if (c == ':' || c == '?' || c == '/') {
- if (!exmode_active)
+ if (!exmode_active) {
cmdline_row = msg_row;
+ }
skip_redraw = true; // skip redraw once
do_redraw = false;
msg_ext_keep_after_cmdline = true;
@@ -1240,7 +1250,7 @@ void wait_return(int redraw)
XFREE_CLEAR(keep_msg); // don't redisplay message, it's too long
}
- if (tmpState == SETWSIZE) { /* got resize event while in vgetc() */
+ if (tmpState == SETWSIZE) { // got resize event while in vgetc()
ui_refresh();
} else if (!skip_redraw) {
if (redraw == true || (msg_scrolled != 0 && redraw != -1)) {
@@ -1259,9 +1269,10 @@ static void hit_return_msg(void)
{
int save_p_more = p_more;
- p_more = FALSE; /* don't want see this message when scrolling back */
- if (msg_didout) /* start on a new line */
+ p_more = FALSE; // don't want see this message when scrolling back
+ if (msg_didout) { // start on a new line
msg_putchar('\n');
+ }
msg_ext_set_kind("return_prompt");
if (got_int) {
MSG_PUTS(_("Interrupt: "));
@@ -1280,10 +1291,11 @@ static void hit_return_msg(void)
void set_keep_msg(char_u *s, int attr)
{
xfree(keep_msg);
- if (s != NULL && msg_silent == 0)
+ if (s != NULL && msg_silent == 0) {
keep_msg = vim_strsave(s);
- else
+ } else {
keep_msg = NULL;
+ }
keep_msg_more = false;
keep_msg_attr = attr;
}
@@ -1327,8 +1339,9 @@ void msg_start(void)
did_return = true;
cmdline_row = msg_row;
}
- if (!msg_didany || lines_left < 0)
+ if (!msg_didany || lines_left < 0) {
msg_starthere();
+ }
if (msg_silent == 0) {
msg_didout = false; // no output on current line yet
}
@@ -1396,7 +1409,7 @@ void msg_home_replace_hl(char_u *fname)
static void msg_home_replace_attr(char_u *fname, int attr)
{
- char_u *name;
+ char_u *name;
name = home_replace_save(NULL, fname);
msg_outtrans_attr(name, attr);
@@ -1449,7 +1462,7 @@ int msg_outtrans_len_attr(const char_u *msgstr, int len, int attr)
int mb_l;
int c;
- /* if MSG_HIST flag set, add message to history */
+ // if MSG_HIST flag set, add message to history
if (attr & MSG_HIST) {
add_msg_hist(str, len, attr, false);
attr &= ~MSG_HIST;
@@ -1518,13 +1531,16 @@ void msg_make(char_u *arg)
static char_u *str = (char_u *)"eeffoc", *rs = (char_u *)"Plon#dqg#vxjduB";
arg = skipwhite(arg);
- for (i = 5; *arg && i >= 0; --i)
- if (*arg++ != str[i])
+ for (i = 5; *arg && i >= 0; --i) {
+ if (*arg++ != str[i]) {
break;
+ }
+ }
if (i < 0) {
msg_putchar('\n');
- for (i = 0; rs[i]; ++i)
+ for (i = 0; rs[i]; ++i) {
msg_putchar(rs[i] - 3);
+ }
}
}
@@ -1540,11 +1556,10 @@ void msg_make(char_u *arg)
/// Otherwise characters are not highlighted.
/// This function is used to show mappings, where we want to see how to type
/// the character/string -- webb
-int msg_outtrans_special(
- const char_u *strstart,
- bool from, ///< true for LHS of a mapping
- int maxlen ///< screen columns, 0 for unlimeted
-)
+///
+/// @param from true for LHS of a mapping
+/// @param maxlen screen columns, 0 for unlimeted
+int msg_outtrans_special(const char_u *strstart, bool from, int maxlen)
{
if (strstart == NULL) {
return 0; // Do nothing.
@@ -1585,8 +1600,7 @@ int msg_outtrans_special(
/// @param[in] replace_lt Convert `<` into `<lt>`.
///
/// @return [allocated] Converted string.
-char *str2special_save(const char *const str, const bool replace_spaces,
- const bool replace_lt)
+char *str2special_save(const char *const str, const bool replace_spaces, const bool replace_lt)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
FUNC_ATTR_NONNULL_RET
{
@@ -1611,8 +1625,7 @@ char *str2special_save(const char *const str, const bool replace_spaces,
/// @return Converted key code, in a static buffer. Buffer is always one and the
/// same, so save converted string somewhere before running str2special
/// for the second time.
-const char *str2special(const char **const sp, const bool replace_spaces,
- const bool replace_lt)
+const char *str2special(const char **const sp, const bool replace_spaces, const bool replace_lt)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET
{
static char buf[7];
@@ -1834,8 +1847,9 @@ void msg_prt_line(char_u *s, int list)
}
}
- if (c == NUL)
+ if (c == NUL) {
break;
+ }
msg_putchar_attr(c, attr);
col++;
@@ -2022,8 +2036,7 @@ static void msg_ext_emit_chunk(void)
* The display part of msg_puts_attr_len().
* May be called recursively to display scroll-back text.
*/
-static void msg_puts_display(const char_u *str, int maxlen, int attr,
- int recurse)
+static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurse)
{
const char_u *s = str;
const char_u *t_s = str; // String from "t_s" to "s" is still todo.
@@ -2076,17 +2089,19 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr,
t_puts(&t_col, t_s, s, attr);
}
- /* When no more prompt and no more room, truncate here */
- if (msg_no_more && lines_left == 0)
+ // When no more prompt and no more room, truncate here
+ if (msg_no_more && lines_left == 0) {
break;
+ }
// Scroll the screen up one line.
bool has_last_char = (*s >= ' ' && !cmdmsg_rl);
msg_scroll_up(!has_last_char);
msg_row = Rows - 2;
- if (msg_col >= Columns) /* can happen after screen resize */
+ if (msg_col >= Columns) { // can happen after screen resize
msg_col = Columns - 1;
+ }
// Display char in last column before showing more-prompt.
if (has_last_char) {
@@ -2127,20 +2142,24 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr,
* If screen is completely filled and 'more' is set then wait
* for a character.
*/
- if (lines_left > 0)
+ if (lines_left > 0) {
--lines_left;
+ }
if (p_more && lines_left == 0 && State != HITRETURN
&& !msg_no_more && !exmode_active) {
- if (do_more_prompt(NUL))
+ if (do_more_prompt(NUL)) {
s = confirm_msg_tail;
- if (quit_more)
+ }
+ if (quit_more) {
return;
+ }
}
/* When we displayed a char in last column need to check if there
* is still more. */
- if (did_last_char)
+ if (did_last_char) {
continue;
+ }
}
wrap = *s == '\n'
@@ -2171,10 +2190,11 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr,
}
} else if (*s == '\r') { // go to column 0
msg_col = 0;
- } else if (*s == '\b') { /* go to previous char */
- if (msg_col)
+ } else if (*s == '\b') { // go to previous char
+ if (msg_col) {
--msg_col;
- } else if (*s == TAB) { /* translate Tab into spaces */
+ }
+ } else if (*s == TAB) { // translate Tab into spaces
do {
msg_screen_putchar(' ', attr);
} while (msg_col & 7);
@@ -2198,9 +2218,10 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr,
msg_screen_putchar(*s, attr);
}
} else {
- /* postpone this character until later */
- if (t_col == 0)
+ // postpone this character until later
+ if (t_col == 0) {
t_s = s;
+ }
t_col += cw;
s += l - 1;
}
@@ -2358,7 +2379,7 @@ void msg_reset_scroll(void)
static void inc_msg_scrolled(void)
{
if (*get_vim_var_str(VV_SCROLLSTART) == NUL) {
- char *p = (char *) sourcing_name;
+ char *p = (char *)sourcing_name;
char *tofree = NULL;
// v:scrollstart is empty, set it to the script/function name and line
@@ -2369,7 +2390,7 @@ static void inc_msg_scrolled(void)
size_t len = strlen(p) + 40;
tofree = xmalloc(len);
vim_snprintf(tofree, len, _("%s line %" PRId64),
- p, (int64_t) sourcing_lnum);
+ p, (int64_t)sourcing_lnum);
p = tofree;
}
set_vim_var_string(VV_SCROLLSTART, p, -1);
@@ -2394,15 +2415,13 @@ typedef enum {
static sb_clear_T do_clear_sb_text = SB_CLEAR_NONE;
/// Store part of a printed message for displaying when scrolling back.
-static void store_sb_text(
- char_u **sb_str, // start of string
- char_u *s, // just after string
- int attr,
- int *sb_col,
- int finish // line ends
-)
+///
+/// @param sb_str start of string
+/// @param s just after string
+/// @param finish line ends
+static void store_sb_text(char_u **sb_str, char_u *s, int attr, int *sb_col, int finish)
{
- msgchunk_T *mp;
+ msgchunk_T *mp;
if (do_clear_sb_text == SB_CLEAR_ALL
|| do_clear_sb_text == SB_CLEAR_CMDLINE_DONE) {
@@ -2427,8 +2446,9 @@ static void store_sb_text(
last_msgchunk = mp;
}
mp->sb_next = NULL;
- } else if (finish && last_msgchunk != NULL)
+ } else if (finish && last_msgchunk != NULL) {
last_msgchunk->sb_eol = TRUE;
+ }
*sb_str = s;
*sb_col = 0;
@@ -2460,8 +2480,8 @@ void sb_text_end_cmdline(void)
/// Called when redrawing the screen.
void clear_sb_text(int all)
{
- msgchunk_T *mp;
- msgchunk_T **lastp;
+ msgchunk_T *mp;
+ msgchunk_T **lastp;
if (all) {
lastp = &last_msgchunk;
@@ -2484,7 +2504,7 @@ void clear_sb_text(int all)
*/
void show_sb_text(void)
{
- msgchunk_T *mp;
+ msgchunk_T *mp;
/* Only show something if there is more than one line, otherwise it looks
* weird, typing a command without output results in one line. */
@@ -2504,8 +2524,9 @@ static msgchunk_T *msg_sb_start(msgchunk_T *mps)
{
msgchunk_T *mp = mps;
- while (mp != NULL && mp->sb_prev != NULL && !mp->sb_prev->sb_eol)
+ while (mp != NULL && mp->sb_prev != NULL && !mp->sb_prev->sb_eol) {
mp = mp->sb_prev;
+ }
return mp;
}
@@ -2514,8 +2535,9 @@ static msgchunk_T *msg_sb_start(msgchunk_T *mps)
*/
void msg_sb_eol(void)
{
- if (last_msgchunk != NULL)
+ if (last_msgchunk != NULL) {
last_msgchunk->sb_eol = TRUE;
+ }
}
/*
@@ -2524,18 +2546,20 @@ void msg_sb_eol(void)
*/
static msgchunk_T *disp_sb_line(int row, msgchunk_T *smp)
{
- msgchunk_T *mp = smp;
- char_u *p;
+ msgchunk_T *mp = smp;
+ char_u *p;
for (;; ) {
msg_row = row;
msg_col = mp->sb_msg_col;
p = mp->sb_text;
- if (*p == '\n') /* don't display the line break */
+ if (*p == '\n') { // don't display the line break
++p;
+ }
msg_puts_display(p, -1, mp->sb_attr, TRUE);
- if (mp->sb_eol || mp->sb_next == NULL)
+ if (mp->sb_eol || mp->sb_next == NULL) {
break;
+ }
mp = mp->sb_next;
}
@@ -2633,8 +2657,8 @@ static int do_more_prompt(int typed_char)
int retval = FALSE;
int toscroll;
bool to_redraw = false;
- msgchunk_T *mp_last = NULL;
- msgchunk_T *mp;
+ msgchunk_T *mp_last = NULL;
+ msgchunk_T *mp;
int i;
// If headless mode is enabled and no input is required, this variable
@@ -2651,23 +2675,25 @@ static int do_more_prompt(int typed_char)
entered = true;
if (typed_char == 'G') {
- /* "g<": Find first line on the last page. */
+ // "g<": Find first line on the last page.
mp_last = msg_sb_start(last_msgchunk);
for (i = 0; i < Rows - 2 && mp_last != NULL
- && mp_last->sb_prev != NULL; ++i)
+ && mp_last->sb_prev != NULL; ++i) {
mp_last = msg_sb_start(mp_last->sb_prev);
+ }
}
State = ASKMORE;
setmouse();
- if (typed_char == NUL)
+ if (typed_char == NUL) {
msg_moremsg(FALSE);
+ }
for (;; ) {
/*
* Get a typed character directly from the user.
*/
if (used_typed_char != NUL) {
- c = used_typed_char; /* was typed at hit-enter prompt */
+ c = used_typed_char; // was typed at hit-enter prompt
used_typed_char = NUL;
} else {
c = get_keystroke(resize_events);
@@ -2676,50 +2702,50 @@ static int do_more_prompt(int typed_char)
toscroll = 0;
switch (c) {
- case BS: /* scroll one line back */
+ case BS: // scroll one line back
case K_BS:
case 'k':
case K_UP:
toscroll = -1;
break;
- case CAR: /* one extra line */
+ case CAR: // one extra line
case NL:
case 'j':
case K_DOWN:
toscroll = 1;
break;
- case 'u': /* Up half a page */
+ case 'u': // Up half a page
toscroll = -(Rows / 2);
break;
- case 'd': /* Down half a page */
+ case 'd': // Down half a page
toscroll = Rows / 2;
break;
- case 'b': /* one page back */
+ case 'b': // one page back
case K_PAGEUP:
toscroll = -(Rows - 1);
break;
- case ' ': /* one extra page */
+ case ' ': // one extra page
case 'f':
case K_PAGEDOWN:
case K_LEFTMOUSE:
toscroll = Rows - 1;
break;
- case 'g': /* all the way back to the start */
+ case 'g': // all the way back to the start
toscroll = -999999;
break;
- case 'G': /* all the way to the end */
+ case 'G': // all the way to the end
toscroll = 999999;
lines_left = 999999;
break;
- case ':': /* start new command line */
+ case ':': // start new command line
if (!confirm_msg_used) {
/* Since got_int is set all typeahead will be flushed, but we
* want to keep this ':', remember that in a special way. */
@@ -2733,7 +2759,7 @@ static int do_more_prompt(int typed_char)
case Ctrl_C:
case ESC:
if (confirm_msg_used) {
- /* Jump to the choices of the dialog. */
+ // Jump to the choices of the dialog.
retval = TRUE;
} else {
got_int = TRUE;
@@ -2752,7 +2778,7 @@ static int do_more_prompt(int typed_char)
to_redraw = true;
break;
- default: /* no valid response */
+ default: // no valid response
msg_moremsg(TRUE);
continue;
}
@@ -2771,10 +2797,11 @@ static int do_more_prompt(int typed_char)
mp = NULL;
}
- /* go to start of line at top of the screen */
+ // go to start of line at top of the screen
for (i = 0; i < Rows - 2 && mp != NULL && mp->sb_prev != NULL;
- ++i)
+ ++i) {
mp = msg_sb_start(mp->sb_prev);
+ }
if (mp != NULL && (mp->sb_prev != NULL || to_redraw)) {
// Find line to be displayed at top
@@ -2783,10 +2810,11 @@ static int do_more_prompt(int typed_char)
break;
}
mp = msg_sb_start(mp->sb_prev);
- if (mp_last == NULL)
+ if (mp_last == NULL) {
mp_last = msg_sb_start(last_msgchunk);
- else
+ } else {
mp_last = msg_sb_start(mp_last->sb_prev);
+ }
}
if (toscroll == -1 && !to_redraw) {
@@ -2810,7 +2838,7 @@ static int do_more_prompt(int typed_char)
toscroll = 0;
}
} else {
- /* First display any text that we scrolled back. */
+ // First display any text that we scrolled back.
while (toscroll > 0 && mp_last != NULL) {
if (msg_do_throttle() && !msg_grid.throttled) {
// Tricky: we redraw at one line higher than usual. Therefore
@@ -2836,7 +2864,7 @@ static int do_more_prompt(int typed_char)
continue;
}
- /* display more text, return to caller */
+ // display more text, return to caller
lines_left = toscroll;
}
@@ -2917,7 +2945,7 @@ static void msg_screen_putchar(int c, int attr)
void msg_moremsg(int full)
{
int attr;
- char_u *s = (char_u *)_("-- More --");
+ char_u *s = (char_u *)_("-- More --");
attr = hl_combine_attr(HL_ATTR(HLF_MSG), HL_ATTR(HLF_M));
grid_puts(&msg_grid_adj, s, Rows - 1, 0, attr);
@@ -2935,13 +2963,13 @@ void msg_moremsg(int full)
void repeat_message(void)
{
if (State == ASKMORE) {
- msg_moremsg(TRUE); /* display --more-- message again */
+ msg_moremsg(TRUE); // display --more-- message again
msg_row = Rows - 1;
} else if (State == CONFIRM) {
- display_confirm_msg(); /* display ":confirm" message again */
+ display_confirm_msg(); // display ":confirm" message again
msg_row = Rows - 1;
} else if (State == EXTERNCMD) {
- ui_cursor_goto(msg_row, msg_col); /* put cursor back */
+ ui_cursor_goto(msg_row, msg_col); // put cursor back
} else if (State == HITRETURN || State == SETWSIZE) {
if (msg_row == Rows - 1) {
/* Avoid drawing the "hit-enter" prompt below the previous one,
@@ -2962,8 +2990,9 @@ void repeat_message(void)
*/
void msg_clr_eos(void)
{
- if (msg_silent == 0)
+ if (msg_silent == 0) {
msg_clr_eos_force();
+ }
}
/*
@@ -3129,16 +3158,18 @@ static void redir_write(const char *const str, const ptrdiff_t maxlen)
return;
}
- /* Don't do anything for displaying prompts and the like. */
- if (redir_off)
+ // Don't do anything for displaying prompts and the like.
+ if (redir_off) {
return;
+ }
- /* If 'verbosefile' is set prepare for writing in that file. */
- if (*p_vfile != NUL && verbose_fd == NULL)
+ // If 'verbosefile' is set prepare for writing in that file.
+ if (*p_vfile != NUL && verbose_fd == NULL) {
verbose_open();
+ }
if (redirecting()) {
- /* If the string doesn't start with CR or NL, go to msg_col */
+ // If the string doesn't start with CR or NL, go to msg_col
if (*s != '\n' && *s != '\r') {
while (cur_col < msg_col) {
if (capture_ga) {
@@ -3190,8 +3221,9 @@ static void redir_write(const char *const str, const ptrdiff_t maxlen)
s++;
}
- if (msg_silent != 0) /* should update msg_col */
+ if (msg_silent != 0) { // should update msg_col
msg_col = cur_col;
+ }
}
}
@@ -3207,8 +3239,9 @@ int redirecting(void)
*/
void verbose_enter(void)
{
- if (*p_vfile != NUL)
+ if (*p_vfile != NUL) {
++msg_silent;
+ }
}
/*
@@ -3217,9 +3250,11 @@ void verbose_enter(void)
*/
void verbose_leave(void)
{
- if (*p_vfile != NUL)
- if (--msg_silent < 0)
+ if (*p_vfile != NUL) {
+ if (--msg_silent < 0) {
msg_silent = 0;
+ }
+ }
}
/*
@@ -3227,11 +3262,12 @@ void verbose_leave(void)
*/
void verbose_enter_scroll(void)
{
- if (*p_vfile != NUL)
+ if (*p_vfile != NUL) {
++msg_silent;
- else
- /* always scroll up, don't overwrite */
+ } else {
+ // always scroll up, don't overwrite
msg_scroll = TRUE;
+ }
}
/*
@@ -3240,10 +3276,12 @@ void verbose_enter_scroll(void)
void verbose_leave_scroll(void)
{
if (*p_vfile != NUL) {
- if (--msg_silent < 0)
+ if (--msg_silent < 0) {
msg_silent = 0;
- } else
+ }
+ } else {
cmdline_row = msg_row;
+ }
}
/*
@@ -3265,7 +3303,7 @@ void verbose_stop(void)
int verbose_open(void)
{
if (verbose_fd == NULL && !verbose_did_open) {
- /* Only give the error message once. */
+ // Only give the error message once.
verbose_did_open = TRUE;
verbose_fd = os_fopen((char *)p_vfile, "a");
@@ -3324,8 +3362,8 @@ void give_warning2(char_u *const message, char_u *const a1, bool hl)
*/
void msg_advance(int col)
{
- if (msg_silent != 0) { /* nothing to advance to */
- msg_col = col; /* for redirection, may fill it up later */
+ if (msg_silent != 0) { // nothing to advance to
+ msg_col = col; // for redirection, may fill it up later
return;
}
if (ui_has(kUIMessages)) {
@@ -3336,49 +3374,44 @@ void msg_advance(int col)
}
return;
}
- if (col >= Columns) /* not enough room */
+ if (col >= Columns) { // not enough room
col = Columns - 1;
- if (cmdmsg_rl)
- while (msg_col > Columns - col)
+ }
+ if (cmdmsg_rl) {
+ while (msg_col > Columns - col) {
msg_putchar(' ');
- else
- while (msg_col < col)
+ }
+ } else {
+ while (msg_col < col) {
msg_putchar(' ');
+ }
+ }
}
-/*
- * Used for "confirm()" function, and the :confirm command prefix.
- * Versions which haven't got flexible dialogs yet, and console
- * versions, get this generic handler which uses the command line.
- *
- * type = one of:
- * VIM_QUESTION, VIM_INFO, VIM_WARNING, VIM_ERROR or VIM_GENERIC
- * title = title string (can be NULL for default)
- * (neither used in console dialogs at the moment)
- *
- * Format of the "buttons" string:
- * "Button1Name\nButton2Name\nButton3Name"
- * The first button should normally be the default/accept
- * The second button should be the 'Cancel' button
- * Other buttons- use your imagination!
- * A '&' in a button name becomes a shortcut, so each '&' should be before a
- * different letter.
- */
-int
-do_dialog (
- int type,
- char_u *title,
- char_u *message,
- char_u *buttons,
- int dfltbutton,
- char_u *textfield, /* IObuff for inputdialog(), NULL
- otherwise */
- int ex_cmd /* when TRUE pressing : accepts default and starts
- Ex command */
-)
+/// Used for "confirm()" function, and the :confirm command prefix.
+/// Versions which haven't got flexible dialogs yet, and console
+/// versions, get this generic handler which uses the command line.
+///
+/// type = one of:
+/// VIM_QUESTION, VIM_INFO, VIM_WARNING, VIM_ERROR or VIM_GENERIC
+/// title = title string (can be NULL for default)
+/// (neither used in console dialogs at the moment)
+///
+/// Format of the "buttons" string:
+/// "Button1Name\nButton2Name\nButton3Name"
+/// The first button should normally be the default/accept
+/// The second button should be the 'Cancel' button
+/// Other buttons- use your imagination!
+/// A '&' in a button name becomes a shortcut, so each '&' should be before a
+/// different letter.
+///
+/// @param textfiel IObuff for inputdialog(), NULL otherwise
+/// @param ex_cmd when TRUE pressing : accepts default and starts Ex command
+int do_dialog(int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton,
+ char_u *textfield, int ex_cmd)
{
int retval = 0;
- char_u *hotkeys;
+ char_u *hotkeys;
int c;
int i;
@@ -3407,16 +3440,16 @@ do_dialog (
// Get a typed character directly from the user.
c = get_keystroke(NULL);
switch (c) {
- case CAR: /* User accepts default option */
+ case CAR: // User accepts default option
case NL:
retval = dfltbutton;
break;
- case Ctrl_C: /* User aborts/cancels */
+ case Ctrl_C: // User aborts/cancels
case ESC:
retval = 0;
break;
- default: /* Could be a hotkey? */
- if (c < 0) { /* special keys are ignored here */
+ default: // Could be a hotkey?
+ if (c < 0) { // special keys are ignored here
continue;
}
if (c == ':' && ex_cmd) {
@@ -3435,9 +3468,10 @@ do_dialog (
i += utfc_ptr2len(hotkeys + i) - 1;
retval++;
}
- if (hotkeys[i])
+ if (hotkeys[i]) {
break;
- /* No hotkey match, so keep waiting */
+ }
+ // No hotkey match, so keep waiting
continue;
}
break;
@@ -3455,15 +3489,11 @@ do_dialog (
}
-/*
- * Copy one character from "*from" to "*to", taking care of multi-byte
- * characters. Return the length of the character in bytes.
- */
-static int copy_char(
- const char_u *from,
- char_u *to,
- bool lowercase // make character lower case
-)
+/// Copy one character from "*from" to "*to", taking care of multi-byte
+/// characters. Return the length of the character in bytes.
+///
+/// @param lowercase make character lower case
+static int copy_char(const char_u *from, char_u *to, bool lowercase)
FUNC_ATTR_NONNULL_ALL
{
if (lowercase) {
@@ -3490,9 +3520,7 @@ static int copy_char(
/// corresponding button has a hotkey
///
/// @return Pointer to memory allocated for storing hotkeys
-static char_u * console_dialog_alloc(const char_u *message,
- char_u *buttons,
- bool has_hotkey[])
+static char_u *console_dialog_alloc(const char_u *message, char_u *buttons, bool has_hotkey[])
{
int lenhotkey = HOTK_LEN; // count first button
has_hotkey[0] = false;
@@ -3521,9 +3549,9 @@ static char_u * console_dialog_alloc(const char_u *message,
}
len += (int)(STRLEN(message)
- + 2 // for the NL's
- + STRLEN(buttons)
- + 3); // for the ": " and NUL
+ + 2 // for the NL's
+ + STRLEN(buttons)
+ + 3); // for the ": " and NUL
lenhotkey++; // for the NUL
// If no hotkey is specified, first char is used.
@@ -3552,7 +3580,7 @@ static char_u * console_dialog_alloc(const char_u *message,
static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfltbutton)
FUNC_ATTR_NONNULL_RET
{
- bool has_hotkey[HAS_HOTKEY_LEN] = {false};
+ bool has_hotkey[HAS_HOTKEY_LEN] = { false };
char_u *hotk = console_dialog_alloc(message, buttons, has_hotkey);
copy_hotkeys_and_msg(message, buttons, dfltbutton, has_hotkey, hotk);
@@ -3569,9 +3597,8 @@ static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfl
/// @param has_hotkey An element in this array is true if corresponding button
/// has a hotkey
/// @param[out] hotkeys_ptr Pointer to the memory location where hotkeys will be copied
-static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,
- int default_button_idx, const bool has_hotkey[],
- char_u *hotkeys_ptr)
+static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons, int default_button_idx,
+ const bool has_hotkey[], char_u *hotkeys_ptr)
{
*confirm_msg = '\n';
STRCPY(confirm_msg + 1, message);
@@ -3611,7 +3638,6 @@ static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,
if (idx < HAS_HOTKEY_LEN - 1 && !has_hotkey[++idx]) {
first_hotkey = true;
}
-
} else if (*r == DLG_HOTKEY_CHAR || first_hotkey) {
if (*r == DLG_HOTKEY_CHAR) {
++r;
@@ -3660,21 +3686,24 @@ void display_confirm_msg(void)
int vim_dialog_yesno(int type, char_u *title, char_u *message, int dflt)
{
if (do_dialog(type,
- title == NULL ? (char_u *)_("Question") : title,
- message,
- (char_u *)_("&Yes\n&No"), dflt, NULL, FALSE) == 1)
+ title == NULL ? (char_u *)_("Question") : title,
+ message,
+ (char_u *)_("&Yes\n&No"), dflt, NULL, FALSE) == 1) {
return VIM_YES;
+ }
return VIM_NO;
}
int vim_dialog_yesnocancel(int type, char_u *title, char_u *message, int dflt)
{
switch (do_dialog(type,
- title == NULL ? (char_u *)_("Question") : title,
- message,
- (char_u *)_("&Yes\n&No\n&Cancel"), dflt, NULL, FALSE)) {
- case 1: return VIM_YES;
- case 2: return VIM_NO;
+ title == NULL ? (char_u *)_("Question") : title,
+ message,
+ (char_u *)_("&Yes\n&No\n&Cancel"), dflt, NULL, FALSE)) {
+ case 1:
+ return VIM_YES;
+ case 2:
+ return VIM_NO;
}
return VIM_CANCEL;
}
@@ -3682,14 +3711,18 @@ int vim_dialog_yesnocancel(int type, char_u *title, char_u *message, int dflt)
int vim_dialog_yesnoallcancel(int type, char_u *title, char_u *message, int dflt)
{
switch (do_dialog(type,
- title == NULL ? (char_u *)"Question" : title,
- message,
- (char_u *)_("&Yes\n&No\nSave &All\n&Discard All\n&Cancel"),
- dflt, NULL, FALSE)) {
- case 1: return VIM_YES;
- case 2: return VIM_NO;
- case 3: return VIM_ALL;
- case 4: return VIM_DISCARDALL;
+ title == NULL ? (char_u *)"Question" : title,
+ message,
+ (char_u *)_("&Yes\n&No\nSave &All\n&Discard All\n&Cancel"),
+ dflt, NULL, FALSE)) {
+ case 1:
+ return VIM_YES;
+ case 2:
+ return VIM_NO;
+ case 3:
+ return VIM_ALL;
+ case 4:
+ return VIM_DISCARDALL;
}
return VIM_CANCEL;
}
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index 6d94632687..2166631767 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -7,37 +7,43 @@
#include <assert.h>
#include <inttypes.h>
+#include <limits.h>
#include <stdbool.h>
#include <string.h>
-#include <limits.h>
-#include "nvim/vim.h"
#include "nvim/ascii.h"
-#include "nvim/misc1.h"
+#include "nvim/buffer.h"
+#include "nvim/buffer_updates.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
+#include "nvim/event/stream.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
-#include "nvim/func_attr.h"
#include "nvim/fold.h"
+#include "nvim/func_attr.h"
+#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
-#include "nvim/buffer_updates.h"
#include "nvim/main.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
-#include "nvim/garray.h"
-#include "nvim/move.h"
+#include "nvim/misc1.h"
#include "nvim/mouse.h"
+#include "nvim/move.h"
#include "nvim/option.h"
+#include "nvim/os/input.h"
+#include "nvim/os/os.h"
+#include "nvim/os/shell.h"
+#include "nvim/os/signal.h"
+#include "nvim/os/time.h"
#include "nvim/os_unix.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
@@ -48,14 +54,8 @@
#include "nvim/tag.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
+#include "nvim/vim.h"
#include "nvim/window.h"
-#include "nvim/os/os.h"
-#include "nvim/os/shell.h"
-#include "nvim/os/signal.h"
-#include "nvim/os/input.h"
-#include "nvim/os/time.h"
-#include "nvim/event/stream.h"
-#include "nvim/buffer.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "misc1.c.generated.h"
@@ -73,23 +73,23 @@ static garray_T ga_users = GA_EMPTY_INIT_VALUE;
* If "include_space" is set, include trailing whitespace while calculating the
* length.
*/
-int get_leader_len(char_u *line, char_u **flags,
- bool backward, bool include_space)
+int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_space)
{
int i, j;
int result;
int got_com = FALSE;
int found_one;
- char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
- char_u *string; /* pointer to comment string */
- char_u *list;
+ char_u part_buf[COM_MAX_LEN]; // buffer for one option part
+ char_u *string; // pointer to comment string
+ char_u *list;
int middle_match_len = 0;
- char_u *prev_list;
- char_u *saved_flags = NULL;
+ char_u *prev_list;
+ char_u *saved_flags = NULL;
result = i = 0;
- while (ascii_iswhite(line[i])) /* leading white space is ignored */
+ while (ascii_iswhite(line[i])) { // leading white space is ignored
++i;
+ }
/*
* Repeat to match several nested comment strings.
@@ -102,51 +102,60 @@ int get_leader_len(char_u *line, char_u **flags,
for (list = curbuf->b_p_com; *list; ) {
/* Get one option part into part_buf[]. Advance "list" to next
* one. Put "string" at start of string. */
- if (!got_com && flags != NULL)
- *flags = list; /* remember where flags started */
+ if (!got_com && flags != NULL) {
+ *flags = list; // remember where flags started
+ }
prev_list = list;
(void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
string = vim_strchr(part_buf, ':');
- if (string == NULL) /* missing ':', ignore this part */
+ if (string == NULL) { // missing ':', ignore this part
continue;
- *string++ = NUL; /* isolate flags from string */
+ }
+ *string++ = NUL; // isolate flags from string
/* If we found a middle match previously, use that match when this
* is not a middle or end. */
if (middle_match_len != 0
&& vim_strchr(part_buf, COM_MIDDLE) == NULL
- && vim_strchr(part_buf, COM_END) == NULL)
+ && vim_strchr(part_buf, COM_END) == NULL) {
break;
+ }
/* When we already found a nested comment, only accept further
* nested comments. */
- if (got_com && vim_strchr(part_buf, COM_NEST) == NULL)
+ if (got_com && vim_strchr(part_buf, COM_NEST) == NULL) {
continue;
+ }
- /* When 'O' flag present and using "O" command skip this one. */
- if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL)
+ // When 'O' flag present and using "O" command skip this one.
+ if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL) {
continue;
+ }
/* Line contents and string must match.
* When string starts with white space, must have some white space
* (but the amount does not need to match, there might be a mix of
* TABs and spaces). */
if (ascii_iswhite(string[0])) {
- if (i == 0 || !ascii_iswhite(line[i - 1]))
- continue; /* missing white space */
- while (ascii_iswhite(string[0]))
+ if (i == 0 || !ascii_iswhite(line[i - 1])) {
+ continue; // missing white space
+ }
+ while (ascii_iswhite(string[0])) {
++string;
+ }
}
- for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
+ for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) {
;
- if (string[j] != NUL)
- continue; /* string doesn't match */
-
+ }
+ if (string[j] != NUL) {
+ continue; // string doesn't match
+ }
/* When 'b' flag used, there must be white space or an
* end-of-line after the string in the line. */
if (vim_strchr(part_buf, COM_BLANK) != NULL
- && !ascii_iswhite(line[i + j]) && line[i + j] != NUL)
+ && !ascii_iswhite(line[i + j]) && line[i + j] != NUL) {
continue;
+ }
/* We have found a match, stop searching unless this is a middle
* comment. The middle comment can be a substring of the end
@@ -160,13 +169,15 @@ int get_leader_len(char_u *line, char_u **flags,
}
continue;
}
- if (middle_match_len != 0 && j > middle_match_len)
+ if (middle_match_len != 0 && j > middle_match_len) {
/* Use this match instead of the middle match, since it's a
* longer thus better match. */
middle_match_len = 0;
+ }
- if (middle_match_len == 0)
+ if (middle_match_len == 0) {
i += j;
+ }
found_one = TRUE;
break;
}
@@ -174,29 +185,34 @@ int get_leader_len(char_u *line, char_u **flags,
if (middle_match_len != 0) {
/* Use the previously found middle match after failing to find a
* match with an end. */
- if (!got_com && flags != NULL)
+ if (!got_com && flags != NULL) {
*flags = saved_flags;
+ }
i += middle_match_len;
found_one = TRUE;
}
- /* No match found, stop scanning. */
- if (!found_one)
+ // No match found, stop scanning.
+ if (!found_one) {
break;
+ }
result = i;
- /* Include any trailing white space. */
- while (ascii_iswhite(line[i]))
+ // Include any trailing white space.
+ while (ascii_iswhite(line[i])) {
++i;
+ }
- if (include_space)
+ if (include_space) {
result = i;
+ }
- /* If this comment doesn't nest, stop here. */
+ // If this comment doesn't nest, stop here.
got_com = TRUE;
- if (vim_strchr(part_buf, COM_NEST) == NULL)
+ if (vim_strchr(part_buf, COM_NEST) == NULL) {
break;
+ }
}
return result;
}
@@ -213,12 +229,12 @@ int get_last_leader_offset(char_u *line, char_u **flags)
int result = -1;
int i, j;
int lower_check_bound = 0;
- char_u *string;
- char_u *com_leader;
- char_u *com_flags;
- char_u *list;
+ char_u *string;
+ char_u *com_leader;
+ char_u *com_flags;
+ char_u *list;
int found_one;
- char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
+ char_u part_buf[COM_MAX_LEN]; // buffer for one option part
/*
* Repeat to match several nested comment strings.
@@ -242,7 +258,7 @@ int get_last_leader_offset(char_u *line, char_u **flags)
* happen. */
continue;
}
- *string++ = NUL; /* Isolate flags from string. */
+ *string++ = NUL; // Isolate flags from string.
com_leader = string;
/*
@@ -252,16 +268,19 @@ int get_last_leader_offset(char_u *line, char_u **flags)
* TABs and spaces).
*/
if (ascii_iswhite(string[0])) {
- if (i == 0 || !ascii_iswhite(line[i - 1]))
+ if (i == 0 || !ascii_iswhite(line[i - 1])) {
continue;
+ }
while (ascii_iswhite(*string)) {
string++;
}
}
- for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
+ for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) {
/* do nothing */;
- if (string[j] != NUL)
+ }
+ if (string[j] != NUL) {
continue;
+ }
/*
* When 'b' flag used, there must be white space or an
@@ -290,23 +309,25 @@ int get_last_leader_offset(char_u *line, char_u **flags)
*/
found_one = TRUE;
- if (flags)
+ if (flags) {
*flags = flags_save;
+ }
com_flags = flags_save;
break;
}
if (found_one) {
- char_u part_buf2[COM_MAX_LEN]; /* buffer for one option part */
+ char_u part_buf2[COM_MAX_LEN]; // buffer for one option part
int len1, len2, off;
result = i;
/*
* If this comment nests, continue searching.
*/
- if (vim_strchr(part_buf, COM_NEST) != NULL)
+ if (vim_strchr(part_buf, COM_NEST) != NULL) {
continue;
+ }
lower_check_bound = i;
@@ -316,31 +337,36 @@ int get_last_leader_offset(char_u *line, char_u **flags)
* the comment leader correctly.
*/
- while (ascii_iswhite(*com_leader))
+ while (ascii_iswhite(*com_leader)) {
++com_leader;
+ }
len1 = (int)STRLEN(com_leader);
for (list = curbuf->b_p_com; *list; ) {
char_u *flags_save = list;
(void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ",");
- if (flags_save == com_flags)
+ if (flags_save == com_flags) {
continue;
+ }
string = vim_strchr(part_buf2, ':');
++string;
- while (ascii_iswhite(*string))
+ while (ascii_iswhite(*string)) {
++string;
+ }
len2 = (int)STRLEN(string);
- if (len2 == 0)
+ if (len2 == 0) {
continue;
+ }
/* Now we have to verify whether string ends with a substring
* beginning the com_leader. */
for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2; ) {
--off;
if (!STRNCMP(string + off, com_leader, len2 - off)) {
- if (i - off < lower_check_bound)
+ if (i - off < lower_check_bound) {
lower_check_bound = i - off;
+ }
}
}
}
@@ -361,7 +387,7 @@ int gchar_pos(pos_T *pos)
/*
* check_status: called when the status bars for the buffer 'buf'
- * need to be updated
+ * need to be updated
*/
void check_status(buf_T *buf)
{
@@ -459,7 +485,7 @@ int is_mouse_key(int c)
*/
int get_keystroke(MultiQueue *events)
{
- char_u *buf = NULL;
+ char_u *buf = NULL;
int buflen = 150;
int maxlen;
int len = 0;
@@ -493,9 +519,9 @@ int get_keystroke(MultiQueue *events)
n = fix_input_buffer(buf + len, n);
len += n;
waited = 0;
- } else if (len > 0)
- ++waited; /* keep track of the waiting time */
-
+ } else if (len > 0) {
+ ++waited; // keep track of the waiting time
+ }
if (n > 0) { // found a termcode: adjust length
len = n;
}
@@ -503,19 +529,20 @@ int get_keystroke(MultiQueue *events)
continue;
}
- /* Handle modifier and/or special key code. */
+ // Handle modifier and/or special key code.
n = buf[0];
if (n == K_SPECIAL) {
n = TO_SPECIAL(buf[1], buf[2]);
if (buf[1] == KS_MODIFIER
|| n == K_IGNORE
- || (is_mouse_key(n) && n != K_LEFTMOUSE)
- ) {
- if (buf[1] == KS_MODIFIER)
+ || (is_mouse_key(n) && n != K_LEFTMOUSE)) {
+ if (buf[1] == KS_MODIFIER) {
mod_mask = buf[2];
+ }
len -= 3;
- if (len > 0)
+ if (len > 0) {
memmove(buf, buf + 3, (size_t)len);
+ }
continue;
}
break;
@@ -534,27 +561,25 @@ int get_keystroke(MultiQueue *events)
return n;
}
-/*
- * Get a number from the user.
- * When "mouse_used" is not NULL allow using the mouse.
- */
-int
-get_number (
- int colon, /* allow colon to abort */
- int *mouse_used
-)
+/// Get a number from the user.
+/// When "mouse_used" is not NULL allow using the mouse.
+///
+/// @param colon allow colon to abort
+int get_number(int colon, int *mouse_used)
{
int n = 0;
int c;
int typed = 0;
- if (mouse_used != NULL)
+ if (mouse_used != NULL) {
*mouse_used = FALSE;
+ }
/* When not printing messages, the user won't know what to type, return a
* zero (as if CR was hit). */
- if (msg_silent != 0)
+ if (msg_silent != 0) {
return 0;
+ }
no_mapping++;
for (;; ) {
@@ -576,8 +601,9 @@ get_number (
break;
} else if (n == 0 && c == ':' && colon) {
stuffcharReadbuff(':');
- if (!exmode_active)
+ if (!exmode_active) {
cmdline_row = msg_row;
+ }
skip_redraw = true; // skip redraw once
do_redraw = false;
break;
@@ -643,34 +669,39 @@ void msgmore(long n)
{
long pn;
- if (global_busy /* no messages now, wait until global is finished */
- || !messaging()) /* 'lazyredraw' set, don't do messages now */
+ if (global_busy // no messages now, wait until global is finished
+ || !messaging()) { // 'lazyredraw' set, don't do messages now
return;
+ }
/* We don't want to overwrite another important message, but do overwrite
* a previous "more lines" or "fewer lines" message, so that "5dd" and
* then "put" reports the last action. */
- if (keep_msg != NULL && !keep_msg_more)
+ if (keep_msg != NULL && !keep_msg_more) {
return;
+ }
- if (n > 0)
+ if (n > 0) {
pn = n;
- else
+ } else {
pn = -n;
+ }
if (pn > p_report) {
if (pn == 1) {
- if (n > 0)
+ if (n > 0) {
STRLCPY(msg_buf, _("1 more line"), MSG_BUF_LEN);
- else
+ } else {
STRLCPY(msg_buf, _("1 line less"), MSG_BUF_LEN);
+ }
} else {
- if (n > 0)
+ if (n > 0) {
vim_snprintf((char *)msg_buf, MSG_BUF_LEN,
- _("%" PRId64 " more lines"), (int64_t)pn);
- else
+ _("%" PRId64 " more lines"), (int64_t)pn);
+ } else {
vim_snprintf((char *)msg_buf, MSG_BUF_LEN,
- _("%" PRId64 " fewer lines"), (int64_t)pn);
+ _("%" PRId64 " fewer lines"), (int64_t)pn);
+ }
}
if (got_int) {
xstrlcat((char *)msg_buf, _(" (Interrupted)"), MSG_BUF_LEN);
@@ -752,7 +783,7 @@ static void init_users(void)
}
lazy_init_done = TRUE;
-
+
os_get_usernames(&ga_users);
}
@@ -762,8 +793,9 @@ static void init_users(void)
char_u *get_users(expand_T *xp, int idx)
{
init_users();
- if (idx < ga_users.ga_len)
+ if (idx < ga_users.ga_len) {
return ((char_u **)ga_users.ga_data)[idx];
+ }
return NULL;
}
@@ -780,10 +812,12 @@ int match_user(char_u *name)
init_users();
for (int i = 0; i < ga_users.ga_len; i++) {
- if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0)
- return 2; /* full match */
- if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0)
- result = 1; /* partial match */
+ if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0) {
+ return 2; // full match
+ }
+ if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) {
+ result = 1; // partial match
+ }
}
return result;
}
@@ -921,8 +955,7 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
/// @param ret_len length of the stdout
///
/// @return an allocated string, or NULL for error.
-char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags,
- size_t *ret_len)
+char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, size_t *ret_len)
{
char_u *buffer = NULL;
@@ -970,12 +1003,14 @@ char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags,
EMSG2(_(e_notread), tempname);
XFREE_CLEAR(buffer);
} else if (ret_len == NULL) {
- /* Change NUL into SOH, otherwise the string is truncated. */
- for (i = 0; i < len; ++i)
- if (buffer[i] == NUL)
+ // Change NUL into SOH, otherwise the string is truncated.
+ for (i = 0; i < len; ++i) {
+ if (buffer[i] == NUL) {
buffer[i] = 1;
+ }
+ }
- buffer[len] = NUL; /* make sure the buffer is terminated */
+ buffer[len] = NUL; // make sure the buffer is terminated
} else {
*ret_len = len;
}
@@ -991,10 +1026,12 @@ done:
*/
void FreeWild(int count, char_u **files)
{
- if (count <= 0 || files == NULL)
+ if (count <= 0 || files == NULL) {
return;
- while (count--)
+ }
+ while (count--) {
xfree(files[count]);
+ }
xfree(files);
}
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c
index c4fa269851..b65d87e617 100644
--- a/src/nvim/mouse.c
+++ b/src/nvim/mouse.c
@@ -3,26 +3,26 @@
#include <stdbool.h>
-#include "nvim/mouse.h"
-#include "nvim/vim.h"
#include "nvim/ascii.h"
-#include "nvim/window.h"
+#include "nvim/buffer_defs.h"
+#include "nvim/charset.h"
+#include "nvim/cursor.h"
+#include "nvim/diff.h"
+#include "nvim/fold.h"
+#include "nvim/memline.h"
+#include "nvim/misc1.h"
+#include "nvim/mouse.h"
+#include "nvim/move.h"
+#include "nvim/os_unix.h"
+#include "nvim/plines.h"
+#include "nvim/screen.h"
#include "nvim/state.h"
#include "nvim/strings.h"
-#include "nvim/screen.h"
#include "nvim/syntax.h"
#include "nvim/ui.h"
#include "nvim/ui_compositor.h"
-#include "nvim/os_unix.h"
-#include "nvim/fold.h"
-#include "nvim/diff.h"
-#include "nvim/move.h"
-#include "nvim/misc1.h"
-#include "nvim/plines.h"
-#include "nvim/cursor.h"
-#include "nvim/buffer_defs.h"
-#include "nvim/memline.h"
-#include "nvim/charset.h"
+#include "nvim/vim.h"
+#include "nvim/window.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "mouse.c.generated.h"
@@ -31,33 +31,34 @@
static linenr_T orig_topline = 0;
static int orig_topfill = 0;
-// Move the cursor to the specified row and column on the screen.
-// Change current window if necessary. Returns an integer with the
-// CURSOR_MOVED bit set if the cursor has moved or unset otherwise.
-//
-// The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column.
-// The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column.
-//
-// If flags has MOUSE_FOCUS, then the current window will not be changed, and
-// if the mouse is outside the window then the text will scroll, or if the
-// mouse was previously on a status line, then the status line may be dragged.
-//
-// If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the
-// cursor is moved unless the cursor was on a status line.
-// This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or
-// IN_SEP_LINE depending on where the cursor was clicked.
-//
-// If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless
-// the mouse is on the status line of the same window.
-//
-// If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since
-// the last call.
-//
-// If flags has MOUSE_SETPOS, nothing is done, only the current position is
-// remembered.
-int jump_to_mouse(int flags,
- bool *inclusive, // used for inclusive operator, can be NULL
- int which_button) // MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE
+/// Move the cursor to the specified row and column on the screen.
+/// Change current window if necessary. Returns an integer with the
+/// CURSOR_MOVED bit set if the cursor has moved or unset otherwise.
+///
+/// The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column.
+/// The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column.
+///
+/// If flags has MOUSE_FOCUS, then the current window will not be changed, and
+/// if the mouse is outside the window then the text will scroll, or if the
+/// mouse was previously on a status line, then the status line may be dragged.
+///
+/// If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the
+/// cursor is moved unless the cursor was on a status line.
+/// This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or
+/// IN_SEP_LINE depending on where the cursor was clicked.
+///
+/// If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless
+/// the mouse is on the status line of the same window.
+///
+/// If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since
+/// the last call.
+///
+/// If flags has MOUSE_SETPOS, nothing is done, only the current position is
+/// remembered.
+///
+/// @param inclusive used for inclusive operator, can be NULL
+/// @param which_button MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE
+int jump_to_mouse(int flags, bool *inclusive, int which_button)
{
static int on_status_line = 0; // #lines below bottom of window
static int on_sep_line = 0; // on separator right of window
@@ -66,7 +67,7 @@ int jump_to_mouse(int flags,
static win_T *dragwin = NULL; // window being dragged
static int did_drag = false; // drag was noticed
- win_T *wp, *old_curwin;
+ win_T *wp, *old_curwin;
pos_T old_cursor;
int count;
bool first;
@@ -81,8 +82,9 @@ int jump_to_mouse(int flags,
if (flags & MOUSE_RELEASED) {
// On button release we may change window focus if positioned on a
// status line and no dragging happened.
- if (dragwin != NULL && !did_drag)
+ if (dragwin != NULL && !did_drag) {
flags &= ~(MOUSE_FOCUS | MOUSE_DID_MOVE);
+ }
dragwin = NULL;
did_drag = false;
}
@@ -109,15 +111,16 @@ retnomove:
prev_row = mouse_row;
prev_col = mouse_col;
- if (flags & MOUSE_SETPOS)
+ if (flags & MOUSE_SETPOS) {
goto retnomove; // ugly goto...
-
+ }
old_curwin = curwin;
old_cursor = curwin->w_cursor;
if (!(flags & MOUSE_FOCUS)) {
- if (row < 0 || col < 0) // check if it makes sense
+ if (row < 0 || col < 0) { // check if it makes sense
return IN_UNKNOWN;
+ }
// find the window where the row is in
wp = mouse_find_win(&grid, &row, &col);
@@ -151,10 +154,11 @@ retnomove:
// The rightmost character of the status line might be a vertical
// separator character if there is no connecting window to the right.
if (on_status_line && on_sep_line) {
- if (stl_connected(wp))
+ if (stl_connected(wp)) {
on_sep_line = 0;
- else
+ } else {
on_status_line = 0;
+ }
}
// Before jumping to another buffer, or moving the cursor for a left
@@ -181,28 +185,32 @@ retnomove:
// Only change window focus when not clicking on or dragging the
// status line. Do change focus when releasing the mouse button
// (MOUSE_FOCUS was set above if we dragged first).
- if (dragwin == NULL || (flags & MOUSE_RELEASED))
+ if (dragwin == NULL || (flags & MOUSE_RELEASED)) {
win_enter(wp, true); // can make wp invalid!
+ }
// set topline, to be able to check for double click ourselves
- if (curwin != old_curwin)
+ if (curwin != old_curwin) {
set_mouse_topline(curwin);
+ }
if (on_status_line) { // In (or below) status line
// Don't use start_arrow() if we're in the same window
- if (curwin == old_curwin)
+ if (curwin == old_curwin) {
return IN_STATUS_LINE;
- else
+ } else {
return IN_STATUS_LINE | CURSOR_MOVED;
+ }
}
if (on_sep_line) { // In (or below) status line
// Don't use start_arrow() if we're in the same window
- if (curwin == old_curwin)
+ if (curwin == old_curwin) {
return IN_SEP_LINE;
- else
+ } else {
return IN_SEP_LINE | CURSOR_MOVED;
+ }
}
curwin->w_cursor.lnum = curwin->w_topline;
- } else if (on_status_line && which_button == MOUSE_LEFT) {
+ } else if (on_status_line && which_button == MOUSE_LEFT) {
if (dragwin != NULL) {
// Drag the status line
count = row - dragwin->w_winrow - dragwin->w_height + 1
@@ -211,7 +219,7 @@ retnomove:
did_drag |= count;
}
return IN_STATUS_LINE; // Cursor didn't move
- } else if (on_sep_line && which_button == MOUSE_LEFT) {
+ } else if (on_sep_line && which_button == MOUSE_LEFT) {
if (dragwin != NULL) {
// Drag the separator column
count = col - dragwin->w_wincol - dragwin->w_width + 1
@@ -255,7 +263,7 @@ retnomove:
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
redraw_later(curwin, VALID);
row = 0;
- } else if (row >= curwin->w_height_inner) {
+ } else if (row >= curwin->w_height_inner) {
count = 0;
for (first = true; curwin->w_topline < curbuf->b_ml.ml_line_count; ) {
if (curwin->w_topfill > 0) {
@@ -287,7 +295,7 @@ retnomove:
curwin->w_valid &=
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
row = curwin->w_height_inner - 1;
- } else if (row == 0) {
+ } else if (row == 0) {
// When dragging the mouse, while the text has been scrolled up as
// far as it goes, moving the mouse in the top line should scroll
// the text down (done later when recomputing w_topline).
@@ -394,8 +402,9 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump)
if (!retval) {
// Compute the column without wrapping.
off = win_col_off(win) - win_col_off2(win);
- if (col < off)
+ if (col < off) {
col = off;
+ }
col += row * (win->w_width_inner - off);
// add skip column (for long wrapping line)
col += win->w_skipcol;
@@ -431,23 +440,26 @@ win_T *mouse_find_win(int *gridp, int *rowp, int *colp)
}
- frame_T *fp;
+ frame_T *fp;
fp = topframe;
*rowp -= firstwin->w_winrow;
for (;; ) {
- if (fp->fr_layout == FR_LEAF)
+ if (fp->fr_layout == FR_LEAF) {
break;
+ }
if (fp->fr_layout == FR_ROW) {
for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) {
- if (*colp < fp->fr_width)
+ if (*colp < fp->fr_width) {
break;
+ }
*colp -= fp->fr_width;
}
} else { // fr_layout == FR_COL
for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) {
- if (*rowp < fp->fr_height)
+ if (*rowp < fp->fr_height) {
break;
+ }
*rowp -= fp->fr_height;
}
}
@@ -574,21 +586,21 @@ static linenr_T find_longest_lnum(void)
bool mouse_scroll_horiz(int dir)
{
if (curwin->w_p_wrap) {
- return false;
+ return false;
}
int step = 6;
if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) {
- step = curwin->w_width_inner;
+ step = curwin->w_width_inner;
}
int leftcol = curwin->w_leftcol + (dir == MSCR_RIGHT ? -step : +step);
if (leftcol < 0) {
- leftcol = 0;
+ leftcol = 0;
}
if (curwin->w_leftcol == leftcol) {
- return false;
+ return false;
}
curwin->w_leftcol = (colnr_T)leftcol;
@@ -597,8 +609,8 @@ bool mouse_scroll_horiz(int dir)
// longest visible line.
if (!virtual_active()
&& (colnr_T)leftcol > scroll_line_len(curwin->w_cursor.lnum)) {
- curwin->w_cursor.lnum = find_longest_lnum();
- curwin->w_cursor.col = 0;
+ curwin->w_cursor.lnum = find_longest_lnum();
+ curwin->w_cursor.col = 0;
}
return leftcol_changed();
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 9fc434923f..3a5b2fb211 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -18,7 +18,6 @@
#include "nvim/ascii.h"
#include "nvim/buffer.h"
-#include "nvim/move.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
@@ -27,17 +26,18 @@
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/misc1.h"
-#include "nvim/plines.h"
+#include "nvim/move.h"
#include "nvim/option.h"
+#include "nvim/plines.h"
#include "nvim/popupmnu.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
#include "nvim/window.h"
typedef struct {
- linenr_T lnum; /* line number */
- int fill; /* filler lines */
- int height; /* height of added line */
+ linenr_T lnum; // line number
+ int fill; // filler lines
+ int height; // height of added line
} lineoff_T;
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -85,7 +85,7 @@ static void comp_botline(win_T *wp)
lnum = last;
}
- /* wp->w_botline is the line that is just below the window */
+ // wp->w_botline is the line that is just below the window
wp->w_botline = lnum;
wp->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
wp->w_viewport_invalid = true;
@@ -274,8 +274,7 @@ void update_topline(win_T *wp)
n += wp->w_filler_rows;
loff.height = 0;
while (loff.lnum < wp->w_botline
- && (loff.lnum + 1 < wp->w_botline || loff.fill == 0)
- ) {
+ && (loff.lnum + 1 < wp->w_botline || loff.fill == 0)) {
n += loff.height;
if (n >= *so_ptr) {
break;
@@ -287,7 +286,7 @@ void update_topline(win_T *wp)
check_botline = false;
}
} else {
- /* sufficient context, no need to scroll */
+ // sufficient context, no need to scroll
check_botline = false;
}
}
@@ -325,8 +324,7 @@ void update_topline(win_T *wp)
* Need to redraw when topline changed.
*/
if (wp->w_topline != old_topline
- || wp->w_topfill != old_topfill
- ) {
+ || wp->w_topfill != old_topfill) {
dollar_vcol = -1;
if (wp->w_skipcol != 0) {
wp->w_skipcol = 0;
@@ -346,7 +344,7 @@ void update_topline(win_T *wp)
/*
* Update win->w_topline to move the cursor onto the screen.
*/
-void update_topline_win(win_T* win)
+void update_topline_win(win_T * win)
{
win_T *save_curwin;
switch_win(&save_curwin, NULL, win, NULL, true);
@@ -374,8 +372,7 @@ static bool check_top_offset(void)
{
long so = get_scrolloff_value(curwin);
if (curwin->w_cursor.lnum < curwin->w_topline + so
- || hasAnyFolding(curwin)
- ) {
+ || hasAnyFolding(curwin)) {
lineoff_T loff;
loff.lnum = curwin->w_cursor.lnum;
loff.fill = 0;
@@ -385,8 +382,8 @@ static bool check_top_offset(void)
topline_back(curwin, &loff);
// Stop when included a line above the window.
if (loff.lnum < curwin->w_topline
- || (loff.lnum == curwin->w_topline && loff.fill > 0)
- ) {
+ || (loff.lnum == curwin->w_topline &&
+ loff.fill > 0)) {
break;
}
n += loff.height;
@@ -420,8 +417,8 @@ void check_cursor_moved(win_T *wp)
wp->w_viewport_invalid = true;
} else if (wp->w_cursor.col != wp->w_valid_cursor.col
|| wp->w_leftcol != wp->w_valid_leftcol
- || wp->w_cursor.coladd != wp->w_valid_cursor.coladd
- ) {
+ || wp->w_cursor.coladd !=
+ wp->w_valid_cursor.coladd) {
wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
wp->w_valid_cursor.col = wp->w_cursor.col;
wp->w_valid_leftcol = wp->w_leftcol;
@@ -560,7 +557,7 @@ void validate_cursor(void)
*/
static void curs_rows(win_T *wp)
{
- /* Check if wp->w_lines[].wl_size is invalid */
+ // Check if wp->w_lines[].wl_size is invalid
int all_invalid = (!redrawing()
|| wp->w_lines_valid == 0
|| wp->w_lines[0].wl_lnum > wp->w_topline);
@@ -569,27 +566,29 @@ static void curs_rows(win_T *wp)
for (linenr_T lnum = wp->w_topline; lnum < wp->w_cursor.lnum; ++i) {
bool valid = false;
if (!all_invalid && i < wp->w_lines_valid) {
- if (wp->w_lines[i].wl_lnum < lnum || !wp->w_lines[i].wl_valid)
- continue; /* skip changed or deleted lines */
+ if (wp->w_lines[i].wl_lnum < lnum || !wp->w_lines[i].wl_valid) {
+ continue; // skip changed or deleted lines
+ }
if (wp->w_lines[i].wl_lnum == lnum) {
/* Check for newly inserted lines below this row, in which
* case we need to check for folded lines. */
if (!wp->w_buffer->b_mod_set
|| wp->w_lines[i].wl_lastlnum < wp->w_cursor.lnum
- || wp->w_buffer->b_mod_top
- > wp->w_lines[i].wl_lastlnum + 1)
+ || wp->w_buffer->b_mod_top
+ > wp->w_lines[i].wl_lastlnum + 1) {
valid = true;
+ }
} else if (wp->w_lines[i].wl_lnum > lnum) {
- --i; /* hold at inserted lines */
+ --i; // hold at inserted lines
}
}
if (valid
- && (lnum != wp->w_topline || !wp->w_p_diff)
- ) {
+ && (lnum != wp->w_topline || !wp->w_p_diff)) {
lnum = wp->w_lines[i].wl_lastlnum + 1;
- /* Cursor inside folded lines, don't count this row */
- if (lnum > wp->w_cursor.lnum)
+ // Cursor inside folded lines, don't count this row
+ if (lnum > wp->w_cursor.lnum) {
break;
+ }
wp->w_cline_row += wp->w_lines[i].wl_size;
} else {
linenr_T last = lnum;
@@ -613,7 +612,7 @@ static void curs_rows(win_T *wp)
wp->w_cline_height = plines_win_full(wp, wp->w_cursor.lnum, NULL,
&wp->w_cline_folded, true);
} else if (i > wp->w_lines_valid) {
- /* a line that is too long to fit on the last screen line */
+ // a line that is too long to fit on the last screen line
wp->w_cline_height = 0;
wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, NULL,
NULL, true, NULL);
@@ -645,9 +644,9 @@ void validate_virtcol_win(win_T *wp)
getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL);
wp->w_valid |= VALID_VIRTCOL;
if (wp->w_p_cuc
- && !pum_visible()
- )
+ && !pum_visible()) {
redraw_later(wp, SOME_VALID);
+ }
}
}
@@ -718,8 +717,9 @@ int curwin_col_off(void)
*/
int win_col_off2(win_T *wp)
{
- if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL)
+ if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL) {
return number_width(wp) + 1;
+ }
return 0;
}
@@ -732,10 +732,7 @@ int curwin_col_off2(void)
// Also updates curwin->w_wrow and curwin->w_cline_row.
// Also updates curwin->w_leftcol.
// @param may_scroll when true, may scroll horizontally
-void curs_columns(
- win_T *wp,
- int may_scroll
-)
+void curs_columns(win_T *wp, int may_scroll)
{
int n;
int width = 0;
@@ -765,9 +762,10 @@ void curs_columns(
getvvcol(wp, &wp->w_cursor, &startcol, &(wp->w_virtcol), &endcol);
}
- /* remove '$' from change command when cursor moves onto it */
- if (startcol > dollar_vcol)
+ // remove '$' from change command when cursor moves onto it
+ if (startcol > dollar_vcol) {
dollar_vcol = -1;
+ }
int extra = win_col_off(wp);
wp->w_wcol = wp->w_virtcol + extra;
@@ -782,8 +780,7 @@ void curs_columns(
wp->w_wcol = wp->w_width_inner - 1;
wp->w_wrow = wp->w_height_inner - 1;
} else if (wp->w_p_wrap
- && wp->w_width_inner != 0
- ) {
+ && wp->w_width_inner != 0) {
width = textwidth + win_col_off2(wp);
// long line wrapping, adjust wp->w_wrow
@@ -803,8 +800,7 @@ void curs_columns(
}
}
} else if (may_scroll
- && !wp->w_cline_folded
- ) {
+ && !wp->w_cline_folded) {
// No line wrapping: compute wp->w_leftcol if scrolling is on and line
// is not folded.
// If scrolling is off, wp->w_leftcol is assumed to be 0
@@ -816,7 +812,7 @@ void curs_columns(
assert(siso <= INT_MAX);
int off_left = startcol - wp->w_leftcol - (int)siso;
int off_right =
- endcol - wp->w_leftcol - wp->w_width_inner + (int)siso + 1;
+ endcol - wp->w_leftcol - wp->w_width_inner + (int)siso + 1;
if (off_left < 0 || off_right > 0) {
int diff = (off_left < 0) ? -off_left: off_right;
@@ -836,8 +832,9 @@ void curs_columns(
new_leftcol = wp->w_leftcol + diff;
}
}
- if (new_leftcol < 0)
+ if (new_leftcol < 0) {
new_leftcol = 0;
+ }
if (new_leftcol != (int)wp->w_leftcol) {
wp->w_leftcol = new_leftcol;
win_check_anchored_floats(wp);
@@ -867,13 +864,12 @@ void curs_columns(
|| ((prev_skipcol > 0
|| wp->w_wrow + so >= wp->w_height_inner)
&& (plines =
- plines_win_nofill(wp, wp->w_cursor.lnum, false)) - 1
+ plines_win_nofill(wp, wp->w_cursor.lnum, false)) - 1
>= wp->w_height_inner))
&& wp->w_height_inner != 0
&& wp->w_cursor.lnum == wp->w_topline
&& width > 0
- && wp->w_width_inner != 0
- ) {
+ && wp->w_width_inner != 0) {
/* Cursor past end of screen. Happens with a single line that does
* not fit on screen. Find a skipcol to show the text around the
* cursor. Avoid scrolling all the time. compute value of "extra":
@@ -972,8 +968,8 @@ void curs_columns(
/// @param[out] scolp start screen column
/// @param[out] ccolp cursor screen column
/// @param[out] ecolp end screen column
-void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp,
- int *ccolp, int *ecolp, bool local)
+void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp, int *ecolp,
+ bool local)
{
colnr_T scol = 0, ccol = 0, ecol = 0;
int row = 0;
@@ -1041,39 +1037,42 @@ bool scrolldown(long line_count, int byfold)
{
int done = 0; // total # of physical lines done
- /* Make sure w_topline is at the first of a sequence of folded lines. */
+ // Make sure w_topline is at the first of a sequence of folded lines.
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
- validate_cursor(); /* w_wrow needs to be valid */
+ validate_cursor(); // w_wrow needs to be valid
while (line_count-- > 0) {
if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)
&& curwin->w_topfill < curwin->w_height_inner - 1) {
curwin->w_topfill++;
done++;
} else {
- if (curwin->w_topline == 1)
+ if (curwin->w_topline == 1) {
break;
+ }
--curwin->w_topline;
curwin->w_topfill = 0;
- /* A sequence of folded lines only counts for one logical line */
+ // A sequence of folded lines only counts for one logical line
linenr_T first;
if (hasFolding(curwin->w_topline, &first, NULL)) {
++done;
- if (!byfold)
+ if (!byfold) {
line_count -= curwin->w_topline - first - 1;
+ }
curwin->w_botline -= curwin->w_topline - first;
curwin->w_topline = first;
} else {
done += plines_win_nofill(curwin, curwin->w_topline, true);
}
}
- --curwin->w_botline; /* approximate w_botline */
+ --curwin->w_botline; // approximate w_botline
invalidate_botline();
}
- curwin->w_wrow += done; /* keep w_wrow updated */
- curwin->w_cline_row += done; /* keep w_cline_row updated */
+ curwin->w_wrow += done; // keep w_wrow updated
+ curwin->w_cline_row += done; // keep w_cline_row updated
- if (curwin->w_cursor.lnum == curwin->w_topline)
+ if (curwin->w_cursor.lnum == curwin->w_topline) {
curwin->w_cline_row = 0;
+ }
check_topfill(curwin, true);
/*
@@ -1082,8 +1081,7 @@ bool scrolldown(long line_count, int byfold)
*/
int wrow = curwin->w_wrow;
if (curwin->w_p_wrap
- && curwin->w_width_inner != 0
- ) {
+ && curwin->w_width_inner != 0) {
validate_virtcol();
validate_cheight();
wrow += curwin->w_cline_height - 1 -
@@ -1094,10 +1092,11 @@ bool scrolldown(long line_count, int byfold)
linenr_T first;
if (hasFolding(curwin->w_cursor.lnum, &first, NULL)) {
--wrow;
- if (first == 1)
+ if (first == 1) {
curwin->w_cursor.lnum = 1;
- else
+ } else {
curwin->w_cursor.lnum = first - 1;
+ }
} else {
wrow -= plines_win(curwin, curwin->w_cursor.lnum--, true);
}
@@ -1106,7 +1105,7 @@ bool scrolldown(long line_count, int byfold)
moved = true;
}
if (moved) {
- /* Move cursor to first line of closed fold. */
+ // Move cursor to first line of closed fold.
foldAdjustCursor();
coladvance(curwin->w_curswant);
}
@@ -1127,35 +1126,40 @@ bool scrollup(long line_count, int byfold)
// count each sequence of folded lines as one logical line
linenr_T lnum = curwin->w_topline;
while (line_count--) {
- if (curwin->w_topfill > 0)
+ if (curwin->w_topfill > 0) {
--curwin->w_topfill;
- else {
- if (byfold)
+ } else {
+ if (byfold) {
(void)hasFolding(lnum, NULL, &lnum);
- if (lnum >= curbuf->b_ml.ml_line_count)
+ }
+ if (lnum >= curbuf->b_ml.ml_line_count) {
break;
+ }
++lnum;
curwin->w_topfill = diff_check_fill(curwin, lnum);
}
}
- /* approximate w_botline */
+ // approximate w_botline
curwin->w_botline += lnum - curwin->w_topline;
curwin->w_topline = lnum;
} else {
curwin->w_topline += line_count;
- curwin->w_botline += line_count; /* approximate w_botline */
+ curwin->w_botline += line_count; // approximate w_botline
}
- if (curwin->w_topline > curbuf->b_ml.ml_line_count)
+ if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
curwin->w_topline = curbuf->b_ml.ml_line_count;
- if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1)
+ }
+ if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1) {
curwin->w_botline = curbuf->b_ml.ml_line_count + 1;
+ }
check_topfill(curwin, false);
- if (hasAnyFolding(curwin))
- /* Make sure w_topline is at the first of a sequence of folded lines. */
+ if (hasAnyFolding(curwin)) {
+ // Make sure w_topline is at the first of a sequence of folded lines.
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
+ }
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
if (curwin->w_cursor.lnum < curwin->w_topline) {
@@ -1166,19 +1170,15 @@ bool scrollup(long line_count, int byfold)
}
bool moved = topline != curwin->w_topline
- || botline != curwin->w_botline;
+ || botline != curwin->w_botline;
return moved;
}
-/*
- * Don't end up with too many filler lines in the window.
- */
-void
-check_topfill (
- win_T *wp,
- bool down /* when true scroll down when not enough space */
-)
+/// Don't end up with too many filler lines in the window.
+///
+/// @param down when true scroll down when not enough space
+void check_topfill(win_T *wp, bool down)
{
if (wp->w_topfill > 0) {
int n = plines_win_nofill(wp, wp->w_topline, true);
@@ -1224,11 +1224,11 @@ void scrolldown_clamp(void)
< diff_check_fill(curwin, curwin->w_topline));
if (curwin->w_topline <= 1
- && !can_fill
- )
+ && !can_fill) {
return;
+ }
- validate_cursor(); /* w_wrow needs to be valid */
+ validate_cursor(); // w_wrow needs to be valid
// Compute the row number of the last row of the cursor line
// and make sure it doesn't go off the screen. Make sure the cursor
@@ -1254,7 +1254,7 @@ void scrolldown_clamp(void)
curwin->w_topfill = 0;
}
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
- --curwin->w_botline; /* approximate w_botline */
+ --curwin->w_botline; // approximate w_botline
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
}
}
@@ -1266,11 +1266,11 @@ void scrolldown_clamp(void)
void scrollup_clamp(void)
{
if (curwin->w_topline == curbuf->b_ml.ml_line_count
- && curwin->w_topfill == 0
- )
+ && curwin->w_topfill == 0) {
return;
+ }
- validate_cursor(); /* w_wrow needs to be valid */
+ validate_cursor(); // w_wrow needs to be valid
// Compute the row number of the first row of the cursor line
// and make sure it doesn't go off the screen. Make sure the cursor
@@ -1381,15 +1381,16 @@ static void topline_botline(lineoff_T *lp)
void scroll_cursor_top(int min_scroll, int always)
{
int scrolled = 0;
- linenr_T top; /* just above displayed lines */
- linenr_T bot; /* just below displayed lines */
+ linenr_T top; // just above displayed lines
+ linenr_T bot; // just below displayed lines
linenr_T old_topline = curwin->w_topline;
linenr_T old_topfill = curwin->w_topfill;
linenr_T new_topline;
int off = (int)get_scrolloff_value(curwin);
- if (mouse_dragging > 0)
+ if (mouse_dragging > 0) {
off = mouse_dragging - 1;
+ }
/*
* Decrease topline until:
@@ -1446,8 +1447,9 @@ void scroll_cursor_top(int min_scroll, int always)
* If scrolling is needed, scroll at least 'sj' lines.
*/
if ((new_topline >= curwin->w_topline || scrolled > min_scroll)
- && extra >= off)
+ && extra >= off) {
break;
+ }
extra += i;
new_topline = top;
@@ -1467,22 +1469,25 @@ void scroll_cursor_top(int min_scroll, int always)
* If "always" is false, only adjust topline to a lower value, higher
* value may happen with wrapping lines
*/
- if (new_topline < curwin->w_topline || always)
+ if (new_topline < curwin->w_topline || always) {
curwin->w_topline = new_topline;
- if (curwin->w_topline > curwin->w_cursor.lnum)
+ }
+ if (curwin->w_topline > curwin->w_cursor.lnum) {
curwin->w_topline = curwin->w_cursor.lnum;
+ }
curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline);
if (curwin->w_topfill > 0 && extra > off) {
curwin->w_topfill -= extra - off;
- if (curwin->w_topfill < 0)
+ if (curwin->w_topfill < 0) {
curwin->w_topfill = 0;
+ }
}
check_topfill(curwin, false);
if (curwin->w_topline != old_topline
- || curwin->w_topfill != old_topfill
- )
+ || curwin->w_topfill != old_topfill) {
curwin->w_valid &=
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
+ }
curwin->w_valid |= VALID_TOPLINE;
curwin->w_viewport_invalid = true;
}
@@ -1501,9 +1506,9 @@ void set_empty_rows(win_T *wp, int used)
wp->w_empty_rows = wp->w_height_inner - used;
if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) {
wp->w_filler_rows = diff_check_fill(wp, wp->w_botline);
- if (wp->w_empty_rows > wp->w_filler_rows)
+ if (wp->w_empty_rows > wp->w_filler_rows) {
wp->w_empty_rows -= wp->w_filler_rows;
- else {
+ } else {
wp->w_filler_rows = wp->w_empty_rows;
wp->w_empty_rows = 0;
}
@@ -1552,9 +1557,9 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
set_empty_rows(curwin, used);
curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
if (curwin->w_topline != old_topline
- || curwin->w_topfill != old_topfill
- )
+ || curwin->w_topfill != old_topfill) {
curwin->w_valid &= ~(VALID_WROW|VALID_CROW);
+ }
} else {
validate_botline(curwin);
}
@@ -1567,8 +1572,9 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
// botline.
if (cln >= curwin->w_botline) {
scrolled = used;
- if (cln == curwin->w_botline)
+ if (cln == curwin->w_botline) {
scrolled -= curwin->w_empty_rows;
+ }
}
/*
@@ -1595,8 +1601,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
|| boff.lnum + 1 > curbuf->b_ml.ml_line_count)
&& loff.lnum <= curwin->w_botline
&& (loff.lnum < curwin->w_botline
- || loff.fill >= fill_below_window)
- ) {
+ || loff.fill >= fill_below_window)) {
break;
}
@@ -1612,9 +1617,8 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
}
if (loff.lnum >= curwin->w_botline
&& (loff.lnum > curwin->w_botline
- || loff.fill <= fill_below_window)
- ) {
- /* Count screen lines that are below the window. */
+ || loff.fill <= fill_below_window)) {
+ // Count screen lines that are below the window.
scrolled += loff.height;
if (loff.lnum == curwin->w_botline
&& loff.fill == 0) {
@@ -1634,14 +1638,13 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
extra += boff.height;
if (boff.lnum >= curwin->w_botline
|| (boff.lnum + 1 == curwin->w_botline
- && boff.fill > curwin->w_filler_rows)
- ) {
- /* Count screen lines that are below the window. */
+ && boff.fill > curwin->w_filler_rows)) {
+ // Count screen lines that are below the window.
scrolled += boff.height;
if (boff.lnum == curwin->w_botline
- && boff.fill == 0
- )
+ && boff.fill == 0) {
scrolled -= curwin->w_empty_rows;
+ }
}
}
}
@@ -1651,10 +1654,10 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
// curwin->w_empty_rows is larger, no need to scroll
if (scrolled <= 0) {
line_count = 0;
- // more than a screenfull, don't scroll but redraw
+ // more than a screenfull, don't scroll but redraw
} else if (used > curwin->w_height_inner) {
line_count = used;
- // scroll minimal number of lines
+ // scroll minimal number of lines
} else {
line_count = 0;
boff.fill = curwin->w_topfill;
@@ -1665,8 +1668,9 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
i += boff.height;
++line_count;
}
- if (i < scrolled) /* below curwin->w_botline, don't scroll */
+ if (i < scrolled) { // below curwin->w_botline, don't scroll
line_count = 9999;
+ }
}
/*
@@ -1713,7 +1717,7 @@ void scroll_cursor_halfway(int atend)
boff.fill = 0;
linenr_T topline = loff.lnum;
while (topline > 1) {
- if (below <= above) { /* add a line below the cursor first */
+ if (below <= above) { // add a line below the cursor first
if (boff.lnum < curbuf->b_ml.ml_line_count) {
botline_forw(curwin, &boff);
used += boff.height;
@@ -1722,9 +1726,10 @@ void scroll_cursor_halfway(int atend)
}
below += boff.height;
} else {
- ++below; /* count a "~" line */
- if (atend)
+ ++below; // count a "~" line
+ if (atend) {
++used;
+ }
}
}
@@ -1743,8 +1748,9 @@ void scroll_cursor_halfway(int atend)
topfill = loff.fill;
}
}
- if (!hasFolding(topline, &curwin->w_topline, NULL))
+ if (!hasFolding(topline, &curwin->w_topline, NULL)) {
curwin->w_topline = topline;
+ }
curwin->w_topfill = topfill;
if (old_topline > curwin->w_topline + curwin->w_height_inner) {
curwin->w_botfill = false;
@@ -1793,12 +1799,12 @@ void cursor_correct(void)
* If there are sufficient file-lines above and below the cursor, we can
* return now.
*/
- linenr_T cln = curwin->w_cursor.lnum; /* Cursor Line Number */
+ linenr_T cln = curwin->w_cursor.lnum; // Cursor Line Number
if (cln >= curwin->w_topline + above_wanted
&& cln < curwin->w_botline - below_wanted
- && !hasAnyFolding(curwin)
- )
+ && !hasAnyFolding(curwin)) {
return;
+ }
/*
* Narrow down the area where the cursor can be put by taking lines from
@@ -1808,9 +1814,9 @@ void cursor_correct(void)
*/
linenr_T topline = curwin->w_topline;
linenr_T botline = curwin->w_botline - 1;
- /* count filler lines as context */
- int above = curwin->w_topfill; /* screen lines above topline */
- int below = curwin->w_filler_rows; /* screen lines below botline */
+ // count filler lines as context
+ int above = curwin->w_topfill; // screen lines above topline
+ int below = curwin->w_filler_rows; // screen lines below botline
while ((above < above_wanted || below < below_wanted) && topline < botline) {
if (below < below_wanted && (below <= above || above >= above_wanted)) {
if (hasFolding(botline, &botline, NULL)) {
@@ -1827,17 +1833,18 @@ void cursor_correct(void)
above += plines_win_nofill(curwin, topline, true);
}
- /* Count filler lines below this line as context. */
- if (topline < botline)
+ // Count filler lines below this line as context.
+ if (topline < botline) {
above += diff_check_fill(curwin, topline + 1);
+ }
++topline;
}
}
- if (topline == botline || botline == 0)
+ if (topline == botline || botline == 0) {
curwin->w_cursor.lnum = topline;
- else if (topline > botline)
+ } else if (topline > botline) {
curwin->w_cursor.lnum = botline;
- else {
+ } else {
if (cln < topline && curwin->w_topline > 1) {
curwin->w_cursor.lnum = topline;
curwin->w_valid &=
@@ -1867,7 +1874,7 @@ int onepage(Direction dir, long count)
linenr_T old_topline = curwin->w_topline;
long so = get_scrolloff_value(curwin);
- if (curbuf->b_ml.ml_line_count == 1) { /* nothing to do */
+ if (curbuf->b_ml.ml_line_count == 1) { // nothing to do
beep_flush();
return FAIL;
}
@@ -1893,16 +1900,18 @@ int onepage(Direction dir, long count)
loff.fill = 0;
if (dir == FORWARD) {
if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) {
- /* Vi compatible scrolling */
- if (p_window <= 2)
+ // Vi compatible scrolling
+ if (p_window <= 2) {
++curwin->w_topline;
- else
+ } else {
curwin->w_topline += p_window - 2;
- if (curwin->w_topline > curbuf->b_ml.ml_line_count)
+ }
+ if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
curwin->w_topline = curbuf->b_ml.ml_line_count;
+ }
curwin->w_cursor.lnum = curwin->w_topline;
} else if (curwin->w_botline > curbuf->b_ml.ml_line_count) {
- /* at end of file */
+ // at end of file
curwin->w_topline = curbuf->b_ml.ml_line_count;
curwin->w_topfill = 0;
curwin->w_valid &= ~(VALID_WROW|VALID_CROW);
@@ -1920,23 +1929,26 @@ int onepage(Direction dir, long count)
curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW|
VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
}
- } else { /* dir == BACKWARDS */
+ } else { // dir == BACKWARDS
if (curwin->w_topline == 1) {
- /* Include max number of filler lines */
+ // Include max number of filler lines
max_topfill();
continue;
}
if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) {
- /* Vi compatible scrolling (sort of) */
- if (p_window <= 2)
+ // Vi compatible scrolling (sort of)
+ if (p_window <= 2) {
--curwin->w_topline;
- else
+ } else {
curwin->w_topline -= p_window - 2;
- if (curwin->w_topline < 1)
+ }
+ if (curwin->w_topline < 1) {
curwin->w_topline = 1;
+ }
curwin->w_cursor.lnum = curwin->w_topline + p_window - 1;
- if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
+ if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ }
continue;
}
@@ -1967,12 +1979,12 @@ int onepage(Direction dir, long count)
n += loff.height;
}
}
- if (loff.lnum < 1) { /* at begin of file */
+ if (loff.lnum < 1) { // at begin of file
curwin->w_topline = 1;
max_topfill();
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
} else {
- /* Go two lines forward again. */
+ // Go two lines forward again.
topline_botline(&loff);
botline_forw(curwin, &loff);
botline_forw(curwin, &loff);
@@ -1984,14 +1996,14 @@ int onepage(Direction dir, long count)
* very long lines. */
if (loff.lnum >= curwin->w_topline
&& (loff.lnum > curwin->w_topline
- || loff.fill >= curwin->w_topfill)
- ) {
+ || loff.fill >= curwin->w_topfill)) {
/* First try using the maximum number of filler lines. If
* that's not enough, backup one line. */
loff.fill = curwin->w_topfill;
if (curwin->w_topfill < diff_check_fill(curwin,
- curwin->w_topline))
+ curwin->w_topline)) {
max_topfill();
+ }
if (curwin->w_topfill == loff.fill) {
--curwin->w_topline;
curwin->w_topfill = 0;
@@ -2042,12 +2054,12 @@ int onepage(Direction dir, long count)
* This is symmetric, so that doing both keeps the same lines displayed.
* Three lines are examined:
*
- * before CTRL-F after CTRL-F / before CTRL-B
- * etc. l1
- * l1 last but one line ------------
- * l2 last text line l2 top text line
- * ------------- l3 second text line
- * l3 etc.
+ * before CTRL-F after CTRL-F / before CTRL-B
+ * etc. l1
+ * l1 last but one line ------------
+ * l2 last text line l2 top text line
+ * ------------- l3 second text line
+ * l3 etc.
*/
static void get_scroll_overlap(lineoff_T *lp, int dir)
{
@@ -2059,9 +2071,9 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
lp->height = plines_win_nofill(curwin, lp->lnum, true);
}
int h1 = lp->height;
- if (h1 > min_height)
- return; /* no overlap */
-
+ if (h1 > min_height) {
+ return; // no overlap
+ }
lineoff_T loff0 = *lp;
if (dir > 0) {
botline_forw(curwin, lp);
@@ -2070,7 +2082,7 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
}
int h2 = lp->height;
if (h2 == MAXCOL || h2 + h1 > min_height) {
- *lp = loff0; /* no overlap */
+ *lp = loff0; // no overlap
return;
}
@@ -2082,7 +2094,7 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
}
int h3 = lp->height;
if (h3 == MAXCOL || h3 + h2 > min_height) {
- *lp = loff0; /* no overlap */
+ *lp = loff0; // no overlap
return;
}
@@ -2093,10 +2105,11 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
topline_back(curwin, lp);
}
int h4 = lp->height;
- if (h4 == MAXCOL || h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height)
- *lp = loff1; /* 1 line overlap */
- else
- *lp = loff2; /* 2 lines overlap */
+ if (h4 == MAXCOL || h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height) {
+ *lp = loff1; // 1 line overlap
+ } else {
+ *lp = loff2; // 2 lines overlap
+ }
return;
}
@@ -2108,11 +2121,11 @@ void halfpage(bool flag, linenr_T Prenum)
if (Prenum) {
curwin->w_p_scr = (Prenum > curwin->w_height_inner) ? curwin->w_height_inner
- : Prenum;
+ : Prenum;
}
assert(curwin->w_p_scr <= INT_MAX);
int n = curwin->w_p_scr <= curwin->w_height_inner ? (int)curwin->w_p_scr
- : curwin->w_height_inner;
+ : curwin->w_height_inner;
update_topline(curwin);
validate_botline(curwin);
@@ -2129,8 +2142,9 @@ void halfpage(bool flag, linenr_T Prenum)
} else {
i = plines_win_nofill(curwin, curwin->w_topline, true);
n -= i;
- if (n < 0 && scrolled > 0)
+ if (n < 0 && scrolled > 0) {
break;
+ }
(void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline);
++curwin->w_topline;
curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline);
@@ -2148,9 +2162,9 @@ void halfpage(bool flag, linenr_T Prenum)
* Correct w_botline for changed w_topline.
* Won't work when there are filler lines.
*/
- if (curwin->w_p_diff)
+ if (curwin->w_p_diff) {
curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP);
- else {
+ } else {
room += i;
do {
i = plines_win(curwin, curwin->w_botline, true);
@@ -2170,11 +2184,12 @@ void halfpage(bool flag, linenr_T Prenum)
while (--n >= 0
&& curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) {
(void)hasFolding(curwin->w_cursor.lnum, NULL,
- &curwin->w_cursor.lnum);
+ &curwin->w_cursor.lnum);
++curwin->w_cursor.lnum;
}
- } else
+ } else {
curwin->w_cursor.lnum += n;
+ }
check_cursor_lnum();
}
} else {
@@ -2189,8 +2204,9 @@ void halfpage(bool flag, linenr_T Prenum)
} else {
i = plines_win_nofill(curwin, curwin->w_topline - 1, true);
n -= i;
- if (n < 0 && scrolled > 0)
+ if (n < 0 && scrolled > 0) {
break;
+ }
--curwin->w_topline;
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
curwin->w_topfill = 0;
@@ -2206,19 +2222,20 @@ void halfpage(bool flag, linenr_T Prenum)
// When hit top of the file: move cursor up.
if (n > 0) {
- if (curwin->w_cursor.lnum <= (linenr_T)n)
+ if (curwin->w_cursor.lnum <= (linenr_T)n) {
curwin->w_cursor.lnum = 1;
- else if (hasAnyFolding(curwin)) {
+ } else if (hasAnyFolding(curwin)) {
while (--n >= 0 && curwin->w_cursor.lnum > 1) {
--curwin->w_cursor.lnum;
(void)hasFolding(curwin->w_cursor.lnum,
- &curwin->w_cursor.lnum, NULL);
+ &curwin->w_cursor.lnum, NULL);
}
- } else
+ } else {
curwin->w_cursor.lnum -= n;
+ }
}
}
- /* Move cursor to first line of closed fold. */
+ // Move cursor to first line of closed fold.
foldAdjustCursor();
check_topfill(curwin, !flag);
cursor_correct();
@@ -2245,7 +2262,7 @@ void do_check_cursorbind(void)
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
curwin = wp;
curbuf = curwin->w_buffer;
- /* skip original window and windows with 'noscrollbind' */
+ // skip original window and windows with 'noscrollbind'
if (curwin != old_curwin && curwin->w_p_crb) {
if (curwin->w_p_diff) {
curwin->w_cursor.lnum =