aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2020-02-02 22:07:16 -0800
committerJustin M. Keyes <justinkz@gmail.com>2020-02-02 22:14:40 -0800
commit2af04e199740d5d2eaab38e272ecf1f9146335f5 (patch)
tree484ecae3687ff9a1b3f02300228476fa53e72464
parentefa5af904387d8ece68c84a568d60e071350c6cb (diff)
downloadrneovim-2af04e199740d5d2eaab38e272ecf1f9146335f5.tar.gz
rneovim-2af04e199740d5d2eaab38e272ecf1f9146335f5.tar.bz2
rneovim-2af04e199740d5d2eaab38e272ecf1f9146335f5.zip
lint
-rw-r--r--src/nvim/main.c94
-rw-r--r--src/nvim/os/shell.c55
2 files changed, 69 insertions, 80 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c
index bdaa20773c..56d9030a7f 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -293,8 +293,8 @@ int main(int argc, char **argv)
if (params.diff_mode && params.window_count == -1)
params.window_count = 0; /* open up to 3 windows */
- /* Don't redraw until much later. */
- ++RedrawingDisabled;
+ // Don't redraw until much later.
+ RedrawingDisabled++;
setbuf(stdout, NULL);
@@ -384,22 +384,16 @@ int main(int argc, char **argv)
syn_maybe_on();
}
- /*
- * Read all the plugin files.
- * Only when compiled with +eval, since most plugins need it.
- */
+ // Read all the plugin files.
load_plugins();
// Decide about window layout for diff mode after reading vimrc.
set_window_layout(&params);
- /*
- * Recovery mode without a file name: List swap files.
- * This uses the 'dir' option, therefore it must be after the
- * initializations.
- */
+ // Recovery mode without a file name: List swap files.
+ // Uses the 'dir' option, therefore it must be after the initializations.
if (recoverymode && fname == NULL) {
- recover_names(NULL, TRUE, 0, NULL);
+ recover_names(NULL, true, 0, NULL);
os_exit(0);
}
@@ -431,17 +425,15 @@ int main(int argc, char **argv)
set_vim_var_list(VV_OLDFILES, tv_list_alloc(0));
}
- /*
- * "-q errorfile": Load the error file now.
- * If the error file can't be read, exit before doing anything else.
- */
+ // "-q errorfile": Load the error file now.
+ // If the error file can't be read, exit before doing anything else.
handle_quickfix(&params);
- /*
- * Start putting things on the screen.
- * Scroll screen down before drawing over it
- * Clear screen now, so file message will not be cleared.
- */
+ //
+ // Start putting things on the screen.
+ // Scroll screen down before drawing over it
+ // Clear screen now, so file message will not be cleared.
+ //
starting = NO_BUFFERS;
no_wait_return = false;
if (!exmode_active) {
@@ -473,27 +465,26 @@ int main(int argc, char **argv)
no_wait_return = true;
- /*
- * Create the requested number of windows and edit buffers in them.
- * Also does recovery if "recoverymode" set.
- */
+ //
+ // Create the requested number of windows and edit buffers in them.
+ // Also does recovery if "recoverymode" set.
+ //
create_windows(&params);
TIME_MSG("opening buffers");
- /* clear v:swapcommand */
+ // Clear v:swapcommand
set_vim_var_string(VV_SWAPCOMMAND, NULL, -1);
- /* Ex starts at last line of the file */
- if (exmode_active)
+ // Ex starts at last line of the file.
+ if (exmode_active) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ }
apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
TIME_MSG("BufEnter autocommands");
setpcmark();
- /*
- * When started with "-q errorfile" jump to first error now.
- */
+ // When started with "-q errorfile" jump to first error now.
if (params.edit_type == EDIT_QF) {
qf_jump(NULL, 0, 0, FALSE);
TIME_MSG("jump to first error");
@@ -505,26 +496,23 @@ int main(int argc, char **argv)
xfree(cwd);
if (params.diff_mode) {
- /* set options in each window for "nvim -d". */
+ // set options in each window for "nvim -d".
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
diff_win_options(wp, TRUE);
}
}
- /*
- * Shorten any of the filenames, but only when absolute.
- */
- shorten_fnames(FALSE);
+ // Shorten any of the filenames, but only when absolute.
+ shorten_fnames(false);
- /*
- * Need to jump to the tag before executing the '-c command'.
- * Makes "vim -c '/return' -t main" work.
- */
+ // Need to jump to the tag before executing the '-c command'.
+ // Makes "vim -c '/return' -t main" work.
handle_tag(params.tagname);
- /* Execute any "+", "-c" and "-S" arguments. */
- if (params.n_commands > 0)
+ // Execute any "+", "-c" and "-S" arguments.
+ if (params.n_commands > 0) {
exe_commands(&params);
+ }
starting = 0;
@@ -535,9 +523,10 @@ int main(int argc, char **argv)
// 'autochdir' has been postponed.
do_autochdir();
- /* start in insert mode */
- if (p_im)
- need_start_insertmode = TRUE;
+ // start in insert mode
+ if (p_im) {
+ need_start_insertmode = true;
+ }
set_vim_var_nr(VV_VIM_DID_ENTER, 1L);
apply_autocmds(EVENT_VIMENTER, NULL, NULL, false, curbuf);
@@ -553,18 +542,19 @@ int main(int argc, char **argv)
// main loop.
set_reg_var(get_default_register_name());
- /* When a startup script or session file setup for diff'ing and
- * scrollbind, sync the scrollbind now. */
+ // When a startup script or session file setup for diff'ing and
+ // scrollbind, sync the scrollbind now.
if (curwin->w_p_diff && curwin->w_p_scb) {
update_topline();
check_scrollbind((linenr_T)0, 0L);
TIME_MSG("diff scrollbinding");
}
- /* If ":startinsert" command used, stuff a dummy command to be able to
- * call normal_cmd(), which will then start Insert mode. */
- if (restart_edit != 0)
+ // If ":startinsert" command used, stuff a dummy command to be able to
+ // call normal_cmd(), which will then start Insert mode.
+ if (restart_edit != 0) {
stuffcharReadbuff(K_NOP);
+ }
// WORKAROUND(mhi): #3023
if (cb_flags & CB_UNNAMEDMASK) {
@@ -574,9 +564,7 @@ int main(int argc, char **argv)
TIME_MSG("before starting main loop");
ILOG("starting main loop");
- /*
- * Call the main command loop. This never returns.
- */
+ // Main loop: never returns.
normal_enter(false, false);
#if defined(WIN32) && !defined(MAKE_LIB)
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index ecca88f656..3b8470182a 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -100,7 +100,8 @@ static bool have_dollars(int num, char_u **file)
///
/// @returns OK for success or FAIL for error.
int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
- char_u ***file, int flags) FUNC_ATTR_NONNULL_ARG(3)
+ char_u ***file, int flags)
+ FUNC_ATTR_NONNULL_ARG(3)
FUNC_ATTR_NONNULL_ARG(4)
{
int i;
@@ -114,12 +115,11 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
char_u *command;
FILE *fd;
char_u *buffer;
-#define STYLE_ECHO 0 /* use "echo", the default */
-#define STYLE_GLOB 1 /* use "glob", for csh */
-#define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */
-#define STYLE_PRINT 3 /* use "print -N", for zsh */
-#define STYLE_BT 4 /* `cmd` expansion, execute the pattern
- * directly */
+#define STYLE_ECHO 0 // use "echo", the default
+#define STYLE_GLOB 1 // use "glob", for csh
+#define STYLE_VIMGLOB 2 // use "vimglob", for Posix sh
+#define STYLE_PRINT 3 // use "print -N", for zsh
+#define STYLE_BT 4 // `cmd` expansion, execute the pattern directly
int shell_style = STYLE_ECHO;
int check_spaces;
static bool did_find_nul = false;
@@ -189,16 +189,18 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
shell_style = STYLE_PRINT;
}
}
- if (shell_style == STYLE_ECHO && strstr((char *)path_tail(p_sh),
- "sh") != NULL)
+ if (shell_style == STYLE_ECHO
+ && strstr((char *)path_tail(p_sh), "sh") != NULL) {
shell_style = STYLE_VIMGLOB;
+ }
// Compute the length of the command. We need 2 extra bytes: for the
// optional '&' and for the NUL.
// Worst case: "unset nonomatch; print -N >" plus two is 29
len = STRLEN(tempname) + 29;
- if (shell_style == STYLE_VIMGLOB)
+ if (shell_style == STYLE_VIMGLOB) {
len += STRLEN(sh_vimglob_func);
+ }
for (i = 0; i < num_pat; i++) {
// Count the length of the patterns in the same way as they are put in
@@ -248,18 +250,20 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
}
STRCAT(command, ">");
} else {
- if (flags & EW_NOTFOUND)
+ if (flags & EW_NOTFOUND) {
STRCPY(command, "set nonomatch; ");
- else
+ } else {
STRCPY(command, "unset nonomatch; ");
- if (shell_style == STYLE_GLOB)
+ }
+ if (shell_style == STYLE_GLOB) {
STRCAT(command, "glob >");
- else if (shell_style == STYLE_PRINT)
+ } else if (shell_style == STYLE_PRINT) {
STRCAT(command, "print -N >");
- else if (shell_style == STYLE_VIMGLOB)
+ } else if (shell_style == STYLE_VIMGLOB) {
STRCAT(command, sh_vimglob_func);
- else
+ } else {
STRCAT(command, "echo >");
+ }
}
STRCAT(command, tempname);
@@ -323,11 +327,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
}
// execute the shell command
- i = call_shell(
- command,
- shellopts,
- extra_shell_arg
- );
+ i = call_shell(command, shellopts, extra_shell_arg);
// When running in the background, give it some time to create the temp
// file, but don't wait for it to finish.
@@ -380,7 +380,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
return FAIL;
}
#if SIZEOF_LONG_LONG > SIZEOF_SIZE_T
- assert(templen <= (long long)SIZE_MAX);
+ assert(templen <= (long long)SIZE_MAX); // NOLINT(runtime/int)
#endif
len = (size_t)templen;
fseek(fd, 0L, SEEK_SET);
@@ -434,10 +434,11 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
if (shell_style == STYLE_PRINT && !did_find_nul) {
// If there is a NUL, set did_find_nul, else set check_spaces
buffer[len] = NUL;
- if (len && (int)STRLEN(buffer) < (int)len)
+ if (len && (int)STRLEN(buffer) < (int)len) {
did_find_nul = true;
- else
+ } else {
check_spaces = true;
+ }
}
// Make sure the buffer ends with a NUL. For STYLE_PRINT there
@@ -472,7 +473,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
// Isolate the individual file names.
p = buffer;
- for (i = 0; i < *num_file; ++i) {
+ for (i = 0; i < *num_file; i++) {
(*file)[i] = p;
// Space or NL separates
if (shell_style == STYLE_ECHO || shell_style == STYLE_BT
@@ -504,8 +505,9 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
// check if this entry should be included
dir = (os_isdir((*file)[i]));
- if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE)))
+ if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) {
continue;
+ }
// Skip files that are not executable if we check for that.
if (!dir && (flags & EW_EXEC)
@@ -536,7 +538,6 @@ notfound:
return OK;
}
return FAIL;
-
}
/// Builds the argument vector for running the user-configured 'shell' (p_sh)