This commit is contained in:
Justin M. Keyes
2020-02-02 22:07:16 -08:00
parent efa5af9043
commit 2af04e1997
2 changed files with 69 additions and 80 deletions

View File

@@ -293,8 +293,8 @@ int main(int argc, char **argv)
if (params.diff_mode && params.window_count == -1) if (params.diff_mode && params.window_count == -1)
params.window_count = 0; /* open up to 3 windows */ params.window_count = 0; /* open up to 3 windows */
/* Don't redraw until much later. */ // Don't redraw until much later.
++RedrawingDisabled; RedrawingDisabled++;
setbuf(stdout, NULL); setbuf(stdout, NULL);
@@ -384,22 +384,16 @@ int main(int argc, char **argv)
syn_maybe_on(); syn_maybe_on();
} }
/* // Read all the plugin files.
* Read all the plugin files.
* Only when compiled with +eval, since most plugins need it.
*/
load_plugins(); load_plugins();
// Decide about window layout for diff mode after reading vimrc. // Decide about window layout for diff mode after reading vimrc.
set_window_layout(&params); set_window_layout(&params);
/* // Recovery mode without a file name: List swap files.
* Recovery mode without a file name: List swap files. // Uses the 'dir' option, therefore it must be after the initializations.
* This uses the 'dir' option, therefore it must be after the
* initializations.
*/
if (recoverymode && fname == NULL) { if (recoverymode && fname == NULL) {
recover_names(NULL, TRUE, 0, NULL); recover_names(NULL, true, 0, NULL);
os_exit(0); os_exit(0);
} }
@@ -431,17 +425,15 @@ int main(int argc, char **argv)
set_vim_var_list(VV_OLDFILES, tv_list_alloc(0)); set_vim_var_list(VV_OLDFILES, tv_list_alloc(0));
} }
/* // "-q errorfile": Load the error file now.
* "-q errorfile": Load the error file now. // If the error file can't be read, exit before doing anything else.
* If the error file can't be read, exit before doing anything else.
*/
handle_quickfix(&params); handle_quickfix(&params);
/* //
* Start putting things on the screen. // Start putting things on the screen.
* Scroll screen down before drawing over it // Scroll screen down before drawing over it
* Clear screen now, so file message will not be cleared. // Clear screen now, so file message will not be cleared.
*/ //
starting = NO_BUFFERS; starting = NO_BUFFERS;
no_wait_return = false; no_wait_return = false;
if (!exmode_active) { if (!exmode_active) {
@@ -473,27 +465,26 @@ int main(int argc, char **argv)
no_wait_return = true; no_wait_return = true;
/* //
* Create the requested number of windows and edit buffers in them. // Create the requested number of windows and edit buffers in them.
* Also does recovery if "recoverymode" set. // Also does recovery if "recoverymode" set.
*/ //
create_windows(&params); create_windows(&params);
TIME_MSG("opening buffers"); TIME_MSG("opening buffers");
/* clear v:swapcommand */ // Clear v:swapcommand
set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); set_vim_var_string(VV_SWAPCOMMAND, NULL, -1);
/* Ex starts at last line of the file */ // Ex starts at last line of the file.
if (exmode_active) if (exmode_active) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
}
apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
TIME_MSG("BufEnter autocommands"); TIME_MSG("BufEnter autocommands");
setpcmark(); 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) { if (params.edit_type == EDIT_QF) {
qf_jump(NULL, 0, 0, FALSE); qf_jump(NULL, 0, 0, FALSE);
TIME_MSG("jump to first error"); TIME_MSG("jump to first error");
@@ -505,26 +496,23 @@ int main(int argc, char **argv)
xfree(cwd); xfree(cwd);
if (params.diff_mode) { 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) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
diff_win_options(wp, TRUE); diff_win_options(wp, TRUE);
} }
} }
/* // Shorten any of the filenames, but only when absolute.
* Shorten any of the filenames, but only when absolute. shorten_fnames(false);
*/
shorten_fnames(FALSE);
/* // Need to jump to the tag before executing the '-c command'.
* Need to jump to the tag before executing the '-c command'. // Makes "vim -c '/return' -t main" work.
* Makes "vim -c '/return' -t main" work.
*/
handle_tag(params.tagname); handle_tag(params.tagname);
/* Execute any "+", "-c" and "-S" arguments. */ // Execute any "+", "-c" and "-S" arguments.
if (params.n_commands > 0) if (params.n_commands > 0) {
exe_commands(&params); exe_commands(&params);
}
starting = 0; starting = 0;
@@ -535,9 +523,10 @@ int main(int argc, char **argv)
// 'autochdir' has been postponed. // 'autochdir' has been postponed.
do_autochdir(); do_autochdir();
/* start in insert mode */ // start in insert mode
if (p_im) if (p_im) {
need_start_insertmode = TRUE; need_start_insertmode = true;
}
set_vim_var_nr(VV_VIM_DID_ENTER, 1L); set_vim_var_nr(VV_VIM_DID_ENTER, 1L);
apply_autocmds(EVENT_VIMENTER, NULL, NULL, false, curbuf); apply_autocmds(EVENT_VIMENTER, NULL, NULL, false, curbuf);
@@ -553,18 +542,19 @@ int main(int argc, char **argv)
// main loop. // main loop.
set_reg_var(get_default_register_name()); set_reg_var(get_default_register_name());
/* When a startup script or session file setup for diff'ing and // When a startup script or session file setup for diff'ing and
* scrollbind, sync the scrollbind now. */ // scrollbind, sync the scrollbind now.
if (curwin->w_p_diff && curwin->w_p_scb) { if (curwin->w_p_diff && curwin->w_p_scb) {
update_topline(); update_topline();
check_scrollbind((linenr_T)0, 0L); check_scrollbind((linenr_T)0, 0L);
TIME_MSG("diff scrollbinding"); TIME_MSG("diff scrollbinding");
} }
/* If ":startinsert" command used, stuff a dummy command to be able to // If ":startinsert" command used, stuff a dummy command to be able to
* call normal_cmd(), which will then start Insert mode. */ // call normal_cmd(), which will then start Insert mode.
if (restart_edit != 0) if (restart_edit != 0) {
stuffcharReadbuff(K_NOP); stuffcharReadbuff(K_NOP);
}
// WORKAROUND(mhi): #3023 // WORKAROUND(mhi): #3023
if (cb_flags & CB_UNNAMEDMASK) { if (cb_flags & CB_UNNAMEDMASK) {
@@ -574,9 +564,7 @@ int main(int argc, char **argv)
TIME_MSG("before starting main loop"); TIME_MSG("before starting main loop");
ILOG("starting main loop"); ILOG("starting main loop");
/* // Main loop: never returns.
* Call the main command loop. This never returns.
*/
normal_enter(false, false); normal_enter(false, false);
#if defined(WIN32) && !defined(MAKE_LIB) #if defined(WIN32) && !defined(MAKE_LIB)

View File

@@ -100,7 +100,8 @@ static bool have_dollars(int num, char_u **file)
/// ///
/// @returns OK for success or FAIL for error. /// @returns OK for success or FAIL for error.
int os_expand_wildcards(int num_pat, char_u **pat, int *num_file, 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) FUNC_ATTR_NONNULL_ARG(4)
{ {
int i; int i;
@@ -114,12 +115,11 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
char_u *command; char_u *command;
FILE *fd; FILE *fd;
char_u *buffer; char_u *buffer;
#define STYLE_ECHO 0 /* use "echo", the default */ #define STYLE_ECHO 0 // use "echo", the default
#define STYLE_GLOB 1 /* use "glob", for csh */ #define STYLE_GLOB 1 // use "glob", for csh
#define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */ #define STYLE_VIMGLOB 2 // use "vimglob", for Posix sh
#define STYLE_PRINT 3 /* use "print -N", for zsh */ #define STYLE_PRINT 3 // use "print -N", for zsh
#define STYLE_BT 4 /* `cmd` expansion, execute the pattern #define STYLE_BT 4 // `cmd` expansion, execute the pattern directly
* directly */
int shell_style = STYLE_ECHO; int shell_style = STYLE_ECHO;
int check_spaces; int check_spaces;
static bool did_find_nul = false; 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; shell_style = STYLE_PRINT;
} }
} }
if (shell_style == STYLE_ECHO && strstr((char *)path_tail(p_sh), if (shell_style == STYLE_ECHO
"sh") != NULL) && strstr((char *)path_tail(p_sh), "sh") != NULL) {
shell_style = STYLE_VIMGLOB; shell_style = STYLE_VIMGLOB;
}
// Compute the length of the command. We need 2 extra bytes: for the // Compute the length of the command. We need 2 extra bytes: for the
// optional '&' and for the NUL. // optional '&' and for the NUL.
// Worst case: "unset nonomatch; print -N >" plus two is 29 // Worst case: "unset nonomatch; print -N >" plus two is 29
len = STRLEN(tempname) + 29; len = STRLEN(tempname) + 29;
if (shell_style == STYLE_VIMGLOB) if (shell_style == STYLE_VIMGLOB) {
len += STRLEN(sh_vimglob_func); len += STRLEN(sh_vimglob_func);
}
for (i = 0; i < num_pat; i++) { for (i = 0; i < num_pat; i++) {
// Count the length of the patterns in the same way as they are put in // Count the length of the patterns in the same way as they are put in
@@ -248,19 +250,21 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
} }
STRCAT(command, ">"); STRCAT(command, ">");
} else { } else {
if (flags & EW_NOTFOUND) if (flags & EW_NOTFOUND) {
STRCPY(command, "set nonomatch; "); STRCPY(command, "set nonomatch; ");
else } else {
STRCPY(command, "unset nonomatch; "); STRCPY(command, "unset nonomatch; ");
if (shell_style == STYLE_GLOB) }
if (shell_style == STYLE_GLOB) {
STRCAT(command, "glob >"); STRCAT(command, "glob >");
else if (shell_style == STYLE_PRINT) } else if (shell_style == STYLE_PRINT) {
STRCAT(command, "print -N >"); STRCAT(command, "print -N >");
else if (shell_style == STYLE_VIMGLOB) } else if (shell_style == STYLE_VIMGLOB) {
STRCAT(command, sh_vimglob_func); STRCAT(command, sh_vimglob_func);
else } else {
STRCAT(command, "echo >"); STRCAT(command, "echo >");
} }
}
STRCAT(command, tempname); STRCAT(command, tempname);
@@ -323,11 +327,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
} }
// execute the shell command // execute the shell command
i = call_shell( i = call_shell(command, shellopts, extra_shell_arg);
command,
shellopts,
extra_shell_arg
);
// When running in the background, give it some time to create the temp // When running in the background, give it some time to create the temp
// file, but don't wait for it to finish. // 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; return FAIL;
} }
#if SIZEOF_LONG_LONG > SIZEOF_SIZE_T #if SIZEOF_LONG_LONG > SIZEOF_SIZE_T
assert(templen <= (long long)SIZE_MAX); assert(templen <= (long long)SIZE_MAX); // NOLINT(runtime/int)
#endif #endif
len = (size_t)templen; len = (size_t)templen;
fseek(fd, 0L, SEEK_SET); fseek(fd, 0L, SEEK_SET);
@@ -434,11 +434,12 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
if (shell_style == STYLE_PRINT && !did_find_nul) { if (shell_style == STYLE_PRINT && !did_find_nul) {
// If there is a NUL, set did_find_nul, else set check_spaces // If there is a NUL, set did_find_nul, else set check_spaces
buffer[len] = NUL; buffer[len] = NUL;
if (len && (int)STRLEN(buffer) < (int)len) if (len && (int)STRLEN(buffer) < (int)len) {
did_find_nul = true; did_find_nul = true;
else } else {
check_spaces = true; check_spaces = true;
} }
}
// Make sure the buffer ends with a NUL. For STYLE_PRINT there // Make sure the buffer ends with a NUL. For STYLE_PRINT there
// already is one, for STYLE_GLOB it needs to be added. // already is one, for STYLE_GLOB it needs to be added.
@@ -472,7 +473,7 @@ int os_expand_wildcards(int num_pat, char_u **pat, int *num_file,
// Isolate the individual file names. // Isolate the individual file names.
p = buffer; p = buffer;
for (i = 0; i < *num_file; ++i) { for (i = 0; i < *num_file; i++) {
(*file)[i] = p; (*file)[i] = p;
// Space or NL separates // Space or NL separates
if (shell_style == STYLE_ECHO || shell_style == STYLE_BT 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 // check if this entry should be included
dir = (os_isdir((*file)[i])); dir = (os_isdir((*file)[i]));
if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) {
continue; continue;
}
// Skip files that are not executable if we check for that. // Skip files that are not executable if we check for that.
if (!dir && (flags & EW_EXEC) if (!dir && (flags & EW_EXEC)
@@ -536,7 +538,6 @@ notfound:
return OK; return OK;
} }
return FAIL; return FAIL;
} }
/// Builds the argument vector for running the user-configured 'shell' (p_sh) /// Builds the argument vector for running the user-configured 'shell' (p_sh)