This commit is contained in:
Justin M. Keyes 2018-05-24 11:51:35 +02:00
parent 4b70ebe013
commit d00ef758c3
5 changed files with 307 additions and 321 deletions

View File

@ -115,7 +115,7 @@ static void read_cb(uv_stream_t *uvstream, ssize_t cnt, const uv_buf_t *buf)
if (cnt == UV_ENOBUFS || cnt == 0) { if (cnt == UV_ENOBUFS || cnt == 0) {
return; return;
} else if (cnt == UV_EOF && uvstream->type == UV_TTY) { } else if (cnt == UV_EOF && uvstream->type == UV_TTY) {
// The TTY driver might signal TTY without closing the stream // The TTY driver might signal EOF without closing the stream
invoke_read_cb(stream, 0, true); invoke_read_cb(stream, 0, true);
} else { } else {
DLOG("Closing Stream (%p): %s (%s)", stream, DLOG("Closing Stream (%p): %s (%s)", stream,

View File

@ -290,13 +290,11 @@ EXTERN int vgetc_busy INIT(= 0); /* when inside vgetc() then > 0 */
EXTERN int didset_vim INIT(= FALSE); /* did set $VIM ourselves */ EXTERN int didset_vim INIT(= FALSE); /* did set $VIM ourselves */
EXTERN int didset_vimruntime INIT(= FALSE); /* idem for $VIMRUNTIME */ EXTERN int didset_vimruntime INIT(= FALSE); /* idem for $VIMRUNTIME */
/* /// Lines left before a "more" message. Ex mode needs to be able to reset this
* Lines left before a "more" message. Ex mode needs to be able to reset this /// after you type something.
* after you type something. EXTERN int lines_left INIT(= -1); // lines left for listing
*/ EXTERN int msg_no_more INIT(= false); // don't use more prompt, truncate
EXTERN int lines_left INIT(= -1); /* lines left for listing */ // messages
EXTERN int msg_no_more INIT(= FALSE); /* don't use more prompt, truncate
messages */
EXTERN char_u *sourcing_name INIT( = NULL); /* name of error message source */ EXTERN char_u *sourcing_name INIT( = NULL); /* name of error message source */
EXTERN linenr_T sourcing_lnum INIT(= 0); /* line number of the source file */ EXTERN linenr_T sourcing_lnum INIT(= 0); /* line number of the source file */
@ -307,88 +305,71 @@ EXTERN int debug_did_msg INIT(= false); // did "debug mode" message
EXTERN int debug_tick INIT(= 0); // breakpoint change count EXTERN int debug_tick INIT(= 0); // breakpoint change count
EXTERN int debug_backtrace_level INIT(= 0); // breakpoint backtrace level EXTERN int debug_backtrace_level INIT(= 0); // breakpoint backtrace level
/* Values for "do_profiling". */ // Values for "do_profiling".
#define PROF_NONE 0 /* profiling not started */ #define PROF_NONE 0 ///< profiling not started
#define PROF_YES 1 /* profiling busy */ #define PROF_YES 1 ///< profiling busy
#define PROF_PAUSED 2 /* profiling paused */ #define PROF_PAUSED 2 ///< profiling paused
EXTERN int do_profiling INIT(= PROF_NONE); /* PROF_ values */ EXTERN int do_profiling INIT(= PROF_NONE); ///< PROF_ values
/* /// Exception currently being thrown. Used to pass an exception to a different
* The exception currently being thrown. Used to pass an exception to /// cstack. Also used for discarding an exception before it is caught or made
* a different cstack. Also used for discarding an exception before it is /// pending.
* caught or made pending.
*/
EXTERN except_T *current_exception; EXTERN except_T *current_exception;
/* /// Set when a throw that cannot be handled in do_cmdline() must be propagated
* need_rethrow: set to TRUE when a throw that cannot be handled in do_cmdline() /// to the cstack of the previously called do_cmdline().
* must be propagated to the cstack of the previously called do_cmdline(). EXTERN int need_rethrow INIT(= false);
*/
EXTERN int need_rethrow INIT(= FALSE);
/* /// Set when a ":finish" or ":return" that cannot be handled in do_cmdline()
* check_cstack: set to TRUE when a ":finish" or ":return" that cannot be /// must be propagated to the cstack of the previously called do_cmdline().
* handled in do_cmdline() must be propagated to the cstack of the previously EXTERN int check_cstack INIT(= false);
* called do_cmdline().
*/
EXTERN int check_cstack INIT(= FALSE);
/* /// Number of nested try conditionals (across function calls and ":source"
* Number of nested try conditionals (across function calls and ":source" /// commands).
* commands).
*/
EXTERN int trylevel INIT(= 0); EXTERN int trylevel INIT(= 0);
/* /// When "force_abort" is TRUE, always skip commands after an error message,
* When "force_abort" is TRUE, always skip commands after an error message, /// even after the outermost ":endif", ":endwhile" or ":endfor" or for a
* even after the outermost ":endif", ":endwhile" or ":endfor" or for a /// function without the "abort" flag. It is set to TRUE when "trylevel" is
* function without the "abort" flag. It is set to TRUE when "trylevel" is /// non-zero (and ":silent!" was not used) or an exception is being thrown at
* non-zero (and ":silent!" was not used) or an exception is being thrown at /// the time an error is detected. It is set to FALSE when "trylevel" gets
* the time an error is detected. It is set to FALSE when "trylevel" gets /// zero again and there was no error or interrupt or throw.
* zero again and there was no error or interrupt or throw. EXTERN int force_abort INIT(= false);
*/
EXTERN int force_abort INIT(= FALSE);
/* /// "msg_list" points to a variable in the stack of do_cmdline() which keeps
* "msg_list" points to a variable in the stack of do_cmdline() which keeps /// the list of arguments of several emsg() calls, one of which is to be
* the list of arguments of several emsg() calls, one of which is to be /// converted to an error exception immediately after the failing command
* converted to an error exception immediately after the failing command /// returns. The message to be used for the exception value is pointed to by
* returns. The message to be used for the exception value is pointed to by /// the "throw_msg" field of the first element in the list. It is usually the
* the "throw_msg" field of the first element in the list. It is usually the /// same as the "msg" field of that element, but can be identical to the "msg"
* same as the "msg" field of that element, but can be identical to the "msg" /// field of a later list element, when the "emsg_severe" flag was set when the
* field of a later list element, when the "emsg_severe" flag was set when the /// emsg() call was made.
* emsg() call was made.
*/
EXTERN struct msglist **msg_list INIT(= NULL); EXTERN struct msglist **msg_list INIT(= NULL);
/* /// When set, don't convert an error to an exception. Used when displaying the
* suppress_errthrow: When TRUE, don't convert an error to an exception. Used /// interrupt message or reporting an exception that is still uncaught at the
* when displaying the interrupt message or reporting an exception that is still /// top level (which has already been discarded then). Also used for the error
* uncaught at the top level (which has already been discarded then). Also used /// message when no exception can be thrown.
* for the error message when no exception can be thrown. EXTERN int suppress_errthrow INIT(= false);
*/
EXTERN int suppress_errthrow INIT(= FALSE);
/* /// The stack of all caught and not finished exceptions. The exception on the
* The stack of all caught and not finished exceptions. The exception on the /// top of the stack is the one got by evaluation of v:exception. The complete
* top of the stack is the one got by evaluation of v:exception. The complete /// stack of all caught and pending exceptions is embedded in the various
* stack of all caught and pending exceptions is embedded in the various /// cstacks; the pending exceptions, however, are not on the caught stack.
* cstacks; the pending exceptions, however, are not on the caught stack.
*/
EXTERN except_T *caught_stack INIT(= NULL); EXTERN except_T *caught_stack INIT(= NULL);
/* ///
* Garbage collection can only take place when we are sure there are no Lists /// Garbage collection can only take place when we are sure there are no Lists
* or Dictionaries being used internally. This is flagged with /// or Dictionaries being used internally. This is flagged with
* "may_garbage_collect" when we are at the toplevel. /// "may_garbage_collect" when we are at the toplevel.
* "want_garbage_collect" is set by the garbagecollect() function, which means /// "want_garbage_collect" is set by the garbagecollect() function, which means
* we do garbage collection before waiting for a char at the toplevel. /// we do garbage collection before waiting for a char at the toplevel.
* "garbage_collect_at_exit" indicates garbagecollect(1) was called. /// "garbage_collect_at_exit" indicates garbagecollect(1) was called.
*/ ///
EXTERN int may_garbage_collect INIT(= FALSE); EXTERN int may_garbage_collect INIT(= false);
EXTERN int want_garbage_collect INIT(= FALSE); EXTERN int want_garbage_collect INIT(= false);
EXTERN int garbage_collect_at_exit INIT(= FALSE); EXTERN int garbage_collect_at_exit INIT(= false);
// Special values for current_SID. // Special values for current_SID.
#define SID_MODELINE -1 // when using a modeline #define SID_MODELINE -1 // when using a modeline
@ -574,57 +555,50 @@ EXTERN int stdout_isatty INIT(= true);
// volatile because it is used in a signal handler. // volatile because it is used in a signal handler.
EXTERN volatile int full_screen INIT(= false); EXTERN volatile int full_screen INIT(= false);
EXTERN int restricted INIT(= FALSE); // When started in restricted mode (-Z).
// TRUE when started in restricted mode (-Z) EXTERN int restricted INIT(= false);
EXTERN int secure INIT(= FALSE);
/* non-zero when only "safe" commands are
* allowed, e.g. when sourcing .exrc or .vimrc
* in current directory */
/// Non-zero when only "safe" commands are allowed, e.g. when sourcing .exrc or
/// .vimrc in current directory.
EXTERN int secure INIT(= false);
/// Non-zero when changing text and jumping to another window/buffer is not
/// allowed.
EXTERN int textlock INIT(= 0); EXTERN int textlock INIT(= 0);
/* non-zero when changing text and jumping to
* another window or buffer is not allowed */
/// Non-zero when the current buffer can't be changed. Used for FileChangedRO.
EXTERN int curbuf_lock INIT(= 0); EXTERN int curbuf_lock INIT(= 0);
/* non-zero when the current buffer can't be
* changed. Used for FileChangedRO. */ /// Non-zero when no buffer name can be changed, no buffer can be deleted and
/// current directory can't be changed. Used for SwapExists et al.
EXTERN int allbuf_lock INIT(= 0); EXTERN int allbuf_lock INIT(= 0);
/* non-zero when no buffer name can be
* changed, no buffer can be deleted and /// Non-zero when evaluating an expression in a "sandbox". Several things are
* current directory can't be changed. /// not allowed then.
* Used for SwapExists et al. */
EXTERN int sandbox INIT(= 0); EXTERN int sandbox INIT(= 0);
/* Non-zero when evaluating an expression in a
* "sandbox". Several things are not allowed
* then. */
EXTERN int silent_mode INIT(= FALSE); /// Batch-mode: "-es" or "-Es" commandline argument was given.
/* set to TRUE when "-s" commandline argument EXTERN int silent_mode INIT(= false);
* used for ex */
// Set to true when sourcing of startup scripts (init.vim) is done. /// Set to true when sourcing of startup scripts (init.vim) is done.
// Used for options that cannot be changed after startup scripts. /// Used for options that cannot be changed after startup scripts.
EXTERN bool did_source_startup_scripts INIT(= false); EXTERN bool did_source_startup_scripts INIT(= false);
EXTERN pos_T VIsual; /* start position of active Visual selection */ /// Start position of active Visual selection.
EXTERN int VIsual_active INIT(= FALSE); EXTERN pos_T VIsual;
/* whether Visual mode is active */ /// Whether Visual mode is active.
EXTERN int VIsual_select INIT(= FALSE); EXTERN int VIsual_active INIT(= false);
/* whether Select mode is active */ /// Whether Select mode is active.
EXTERN int VIsual_select INIT(= false);
/// Whether to restart the selection after a Select-mode mapping or menu.
EXTERN int VIsual_reselect; EXTERN int VIsual_reselect;
/* whether to restart the selection after a /// Type of Visual mode.
* Select mode mapping or menu */
EXTERN int VIsual_mode INIT(= 'v'); EXTERN int VIsual_mode INIT(= 'v');
/* type of Visual mode */ /// TRUE when redoing Visual.
EXTERN int redo_VIsual_busy INIT(= false);
EXTERN int redo_VIsual_busy INIT(= FALSE); /// When pasting text with the middle mouse button in visual mode with
/* TRUE when redoing Visual */ /// restart_edit set, remember where it started so we can set Insstart.
/*
* When pasting text with the middle mouse button in visual mode with
* restart_edit set, remember where it started so we can set Insstart.
*/
EXTERN pos_T where_paste_started; EXTERN pos_T where_paste_started;
/* /*
@ -732,25 +706,23 @@ EXTERN int (*iconvctl)(iconv_t cd, int request, void *argument);
EXTERN int* (*iconv_errno)(void); EXTERN int* (*iconv_errno)(void);
# endif # endif
/* /// "State" is the main state of Vim.
* "State" is the main state of Vim. /// There are other variables that modify the state:
* There are other variables that modify the state: /// Visual_mode: When State is NORMAL or INSERT.
* "Visual_mode" When State is NORMAL or INSERT. /// finish_op : When State is NORMAL, after typing the operator and
* "finish_op" When State is NORMAL, after typing the operator and before /// before typing the motion command.
* typing the motion command. EXTERN int State INIT(= NORMAL); // This is the current state of the
*/ // command interpreter.
EXTERN int State INIT(= NORMAL); /* This is the current state of the
* command interpreter. */
EXTERN bool finish_op INIT(= false); // true while an operator is pending EXTERN bool finish_op INIT(= false); // true while an operator is pending
EXTERN long opcount INIT(= 0); // count for pending operator EXTERN long opcount INIT(= 0); // count for pending operator
// Ex Mode (Q) state // Ex Mode (Q) state
EXTERN int exmode_active INIT(= 0); // zero, EXMODE_NORMAL or EXMODE_VIM EXTERN int exmode_active INIT(= 0); // Zero, EXMODE_NORMAL or EXMODE_VIM.
EXTERN int ex_no_reprint INIT(= false); // no need to print after z or p EXTERN int ex_no_reprint INIT(=false); // No need to print after z or p.
EXTERN int Recording INIT(= FALSE); /* TRUE when recording into a reg. */ EXTERN int Recording INIT(= false); // TRUE when recording into a reg.
EXTERN int Exec_reg INIT(= FALSE); /* TRUE when executing a register */ EXTERN int Exec_reg INIT(= false); // TRUE when executing a register.
EXTERN int no_mapping INIT(= false); // currently no mapping allowed EXTERN int no_mapping INIT(= false); // currently no mapping allowed
EXTERN int no_zero_mapping INIT(= 0); // mapping zero not allowed EXTERN int no_zero_mapping INIT(= 0); // mapping zero not allowed
@ -1164,10 +1136,9 @@ EXTERN FILE *time_fd INIT(= NULL); /* where to write startup timing */
EXTERN int ignored; EXTERN int ignored;
EXTERN char *ignoredp; EXTERN char *ignoredp;
// If a msgpack-rpc channel should be started over stdin/stdout // Start a msgpack-rpc channel over stdin/stdout.
EXTERN bool embedded_mode INIT(= false); EXTERN bool embedded_mode INIT(= false);
// Dont try to start an user interface // Do not start a UI nor read/write to stdio (unless embedding).
// or read/write to stdio (unless embedding)
EXTERN bool headless_mode INIT(= false); EXTERN bool headless_mode INIT(= false);
/// Used to track the status of external functions. /// Used to track the status of external functions.

View File

@ -281,14 +281,13 @@ int main(int argc, char **argv)
full_screen = true; full_screen = true;
/* // Set the default values for the options that use Rows and Columns.
* Set the default values for the options that use Rows and Columns.
*/
win_init_size(); win_init_size();
// Set the 'diff' option now, so that it can be checked for in a vimrc // Set the 'diff' option now, so that it can be checked for in a vimrc
// file. There is no buffer yet though. // file. There is no buffer yet though.
if (params.diff_mode) if (params.diff_mode) {
diff_win_options(firstwin, FALSE); diff_win_options(firstwin, false);
}
assert(p_ch >= 0 && Rows >= p_ch && Rows - p_ch <= INT_MAX); assert(p_ch >= 0 && Rows >= p_ch && Rows - p_ch <= INT_MAX);
cmdline_row = (int)(Rows - p_ch); cmdline_row = (int)(Rows - p_ch);
@ -297,13 +296,13 @@ int main(int argc, char **argv)
set_init_2(headless_mode); set_init_2(headless_mode);
TIME_MSG("inits 2"); TIME_MSG("inits 2");
msg_scroll = TRUE; msg_scroll = true;
no_wait_return = TRUE; no_wait_return = true;
init_highlight(TRUE, FALSE); /* set the default highlight groups */ init_highlight(true, false); // Default highlight groups.
TIME_MSG("init highlight"); TIME_MSG("init highlight");
/* Set the break level after the terminal is initialized. */ // Set the break level after the terminal is initialized.
debug_break_level = params.use_debug_break_level; debug_break_level = params.use_debug_break_level;
bool reading_input = !headless_mode bool reading_input = !headless_mode
@ -340,18 +339,18 @@ int main(int argc, char **argv)
// Reset 'loadplugins' for "-u NONE" before "--cmd" arguments. // Reset 'loadplugins' for "-u NONE" before "--cmd" arguments.
// Allows for setting 'loadplugins' there. // Allows for setting 'loadplugins' there.
if (params.use_vimrc != NULL && strcmp(params.use_vimrc, "NONE") == 0) { if (params.use_vimrc != NULL && strequal(params.use_vimrc, "NONE")) {
p_lpl = false; p_lpl = false;
} }
/* Execute --cmd arguments. */ // Execute --cmd arguments.
exe_pre_commands(&params); exe_pre_commands(&params);
/* Source startup scripts. */ // Source startup scripts.
source_startup_scripts(&params); source_startup_scripts(&params);
// If using the runtime (-u is not NONE), enable syntax & filetype plugins. // If using the runtime (-u is not NONE), enable syntax & filetype plugins.
if (params.use_vimrc == NULL || strcmp(params.use_vimrc, "NONE") != 0) { if (params.use_vimrc == NULL || !strequal(params.use_vimrc, "NONE")) {
// Does ":filetype plugin indent on". // Does ":filetype plugin indent on".
filetype_maybe_enable(); filetype_maybe_enable();
// Sources syntax/syntax.vim, which calls `:filetype on`. // Sources syntax/syntax.vim, which calls `:filetype on`.
@ -425,9 +424,9 @@ int main(int argc, char **argv)
msg_scroll = false; msg_scroll = false;
} }
// Read file from stdin: // Read file (text, not commands) from stdin if:
// - If "-" argument was given as a file arg. // - stdin is not a tty
// - If stdin is a pipe and "-es"/"-Es"/"-s -" were not given. // - and -e/-es was not given
// //
// Do this before starting Raw mode, because it may change things that the // Do this before starting Raw mode, because it may change things that the
// writing end of the pipe doesn't like, e.g., in case stdin and stderr // writing end of the pipe doesn't like, e.g., in case stdin and stderr
@ -438,16 +437,15 @@ int main(int argc, char **argv)
} }
if (reading_input && (need_wait_return || msg_didany)) { if (reading_input && (need_wait_return || msg_didany)) {
// Since at this point there's no UI instance running yet, error messages // Because there's no UI yet, error messages would have been printed to
// would have been printed to stdout. Before starting (which can result in // stdout. Before starting we need confirmation that the user has seen the
// a alternate screen buffer being shown) we need confirmation that the // messages and that is done with a call to wait_return.
// user has seen the messages and that is done with a call to wait_return.
TIME_MSG("waiting for return"); TIME_MSG("waiting for return");
wait_return(TRUE); wait_return(true);
} }
if (!headless_mode) { if (!headless_mode) {
// Stop reading from input stream, the UI layer will take over now. // Stop reading from input stream. UI (if any) will take over.
input_stop(); input_stop();
ui_builtin_start(); ui_builtin_start();
} }
@ -455,15 +453,14 @@ int main(int argc, char **argv)
setmouse(); // may start using the mouse setmouse(); // may start using the mouse
ui_reset_scroll_region(); // In case Rows changed ui_reset_scroll_region(); // In case Rows changed
// Don't clear the screen when starting in Ex mode, unless using the GUI.
if (exmode_active) if (exmode_active)
must_redraw = CLEAR; must_redraw = CLEAR; // Don't clear the screen when starting in Ex mode.
else { else {
screenclear(); /* clear screen */ screenclear(); // clear screen
TIME_MSG("clearing screen"); TIME_MSG("clearing screen");
} }
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.
@ -738,56 +735,54 @@ static bool edit_stdin(mparm_T *parmp)
static void command_line_scan(mparm_T *parmp) static void command_line_scan(mparm_T *parmp)
{ {
int argc = parmp->argc; int argc = parmp->argc;
char **argv = parmp->argv; char **argv = parmp->argv;
int argv_idx; /* index in argv[n][] */ int argv_idx; // index in argv[n][]
int had_minmin = FALSE; /* found "--" argument */ int had_minmin = false; // found "--" argument
int want_argument; /* option argument with argument */ int want_argument; // option argument with argument
int c; int c;
char_u *p = NULL; char_u *p = NULL;
long n; long n;
--argc; argc--;
++argv; argv++;
argv_idx = 1; /* active option letter is argv[0][argv_idx] */ argv_idx = 1; // active option letter is argv[0][argv_idx]
while (argc > 0) { while (argc > 0) {
/* // "+" or "+{number}" or "+/{pat}" or "+{command}" argument.
* "+" or "+{number}" or "+/{pat}" or "+{command}" argument.
*/
if (argv[0][0] == '+' && !had_minmin) { if (argv[0][0] == '+' && !had_minmin) {
if (parmp->n_commands >= MAX_ARG_CMDS) if (parmp->n_commands >= MAX_ARG_CMDS) {
mainerr(err_extra_cmd, NULL); mainerr(err_extra_cmd, NULL);
argv_idx = -1; /* skip to next argument */ }
if (argv[0][1] == NUL) argv_idx = -1; // skip to next argument
if (argv[0][1] == NUL) {
parmp->commands[parmp->n_commands++] = "$"; parmp->commands[parmp->n_commands++] = "$";
else } else {
parmp->commands[parmp->n_commands++] = &(argv[0][1]); parmp->commands[parmp->n_commands++] = &(argv[0][1]);
} }
/*
* Optional argument. // Optional argument.
*/ } else if (argv[0][0] == '-' && !had_minmin) {
else if (argv[0][0] == '-' && !had_minmin) { want_argument = false;
want_argument = FALSE;
c = argv[0][argv_idx++]; c = argv[0][argv_idx++];
switch (c) { switch (c) {
case NUL: /* "vim -" read from stdin */ case NUL: { // "nvim -" read from stdin
if (exmode_active) { if (exmode_active) {
// "ex -" silent mode // "nvim -e -" silent mode
silent_mode = TRUE; silent_mode = true;
} else { } else {
if (parmp->edit_type != EDIT_NONE) { if (parmp->edit_type != EDIT_NONE) {
mainerr(err_too_many_args, argv[0]); mainerr(err_too_many_args, argv[0]);
} }
parmp->edit_type = EDIT_STDIN; parmp->edit_type = EDIT_STDIN;
} }
argv_idx = -1; /* skip to next argument */ argv_idx = -1; // skip to next argument
break; break;
}
case '-': /* "--" don't take any more option arguments */ case '-': { // "--" don't take any more option arguments
/* "--help" give help message */ // "--help" give help message
/* "--version" give version message */ // "--version" give version message
/* "--literal" take files literally */ // "--literal" take files literally
/* "--noplugin[s]" skip plugins */ // "--noplugin[s]" skip plugins
/* "--cmd <cmd>" execute cmd before vimrc */ // "--cmd <cmd>" execute cmd before vimrc
if (STRICMP(argv[0] + argv_idx, "help") == 0) { if (STRICMP(argv[0] + argv_idx, "help") == 0) {
usage(); usage();
mch_exit(0); mch_exit(0);
@ -831,25 +826,26 @@ static void command_line_scan(mparm_T *parmp)
argv_idx += 6; argv_idx += 6;
} else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) { } else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) {
#if !defined(UNIX) #if !defined(UNIX)
parmp->literal = TRUE; parmp->literal = true;
#endif #endif
} else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) } else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) {
p_lpl = FALSE; p_lpl = false;
else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0) { } else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0) {
want_argument = TRUE; want_argument = true;
argv_idx += 3; argv_idx += 3;
} else if (STRNICMP(argv[0] + argv_idx, "startuptime", 11) == 0) { } else if (STRNICMP(argv[0] + argv_idx, "startuptime", 11) == 0) {
want_argument = TRUE; want_argument = true;
argv_idx += 11; argv_idx += 11;
} else { } else {
if (argv[0][argv_idx]) if (argv[0][argv_idx])
mainerr(err_opt_unknown, argv[0]); mainerr(err_opt_unknown, argv[0]);
had_minmin = TRUE; had_minmin = true;
}
if (!want_argument) {
argv_idx = -1; // skip to next argument
} }
if (!want_argument)
argv_idx = -1; /* skip to next argument */
break; break;
}
case 'A': { // "-A" start in Arabic mode. case 'A': { // "-A" start in Arabic mode.
set_option_value("arabic", 1L, NULL, 0); set_option_value("arabic", 1L, NULL, 0);
break; break;
@ -863,168 +859,176 @@ static void command_line_scan(mparm_T *parmp)
break; break;
} }
case 'e': /* "-e" Ex mode */ 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 = EXMODE_NORMAL; exmode_active = EXMODE_NORMAL;
break; break;
}
case 'E': /* "-E" Improved Ex mode */ case 'E': { // "-E" Improved Ex mode
exmode_active = EXMODE_VIM; exmode_active = EXMODE_VIM;
break; break;
}
case 'f': /* "-f" GUI: run in foreground. */ case 'f': { // "-f" GUI: run in foreground.
break; break;
}
case 'F': { // "-F" start in Farsi mode: rl + fkmap set. case 'F': { // "-F" start in Farsi mode: rl + fkmap set.
p_fkmap = true; p_fkmap = true;
set_option_value("rl", 1L, NULL, 0); set_option_value("rl", 1L, NULL, 0);
break; break;
} }
case 'h': { // "-h" give help message
case 'h': /* "-h" give help message */
usage(); usage();
mch_exit(0); mch_exit(0);
}
case 'H': { // "-H" start in Hebrew mode: rl + hkmap set. case 'H': { // "-H" start in Hebrew mode: rl + hkmap set.
p_hkmap = true; p_hkmap = true;
set_option_value("rl", 1L, NULL, 0); set_option_value("rl", 1L, NULL, 0);
break; break;
} }
case 'l': { // "-l" lisp mode, 'lisp' and 'showmatch' on. case 'l': { // "-l" lisp mode, 'lisp' and 'showmatch' on.
set_option_value("lisp", 1L, NULL, 0); set_option_value("lisp", 1L, NULL, 0);
p_sm = true; p_sm = true;
break; break;
} }
case 'M': { // "-M" no changes or writing of files
case 'M': /* "-M" no changes or writing of files */
reset_modifiable(); reset_modifiable();
/* FALLTHROUGH */ // FALLTHROUGH
}
case 'm': /* "-m" no writing of files */ case 'm': { // "-m" no writing of files
p_write = FALSE; p_write = false;
break; break;
}
case 'N': // "-N" Nocompatible case 'N': // "-N" Nocompatible
case 'X': // "-X" Do not connect to X server case 'X': // "-X" Do not connect to X server
// No-op // No-op
break; break;
case 'n': /* "-n" no swap file */ case 'n': { // "-n" no swap file
parmp->no_swap_file = TRUE; parmp->no_swap_file = true;
break; break;
}
case 'p': // "-p[N]" open N tab pages case 'p': { // "-p[N]" open N tab pages
// default is 0: open window for each file // default is 0: open window for each file
parmp->window_count = get_number_arg(argv[0], &argv_idx, 0); parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
parmp->window_layout = WIN_TABS; parmp->window_layout = WIN_TABS;
break; break;
}
case 'o': /* "-o[N]" open N horizontal split windows */ case 'o': { // "-o[N]" open N horizontal split windows
/* default is 0: open window for each file */ // default is 0: open window for each file
parmp->window_count = get_number_arg(argv[0], &argv_idx, 0); parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
parmp->window_layout = WIN_HOR; parmp->window_layout = WIN_HOR;
break; break;
}
case 'O': /* "-O[N]" open N vertical split windows */ case 'O': { // "-O[N]" open N vertical split windows
/* default is 0: open window for each file */ // default is 0: open window for each file
parmp->window_count = get_number_arg(argv[0], &argv_idx, 0); parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
parmp->window_layout = WIN_VER; parmp->window_layout = WIN_VER;
break; break;
}
case 'q': /* "-q" QuickFix mode */ case 'q': { // "-q" QuickFix mode
if (parmp->edit_type != EDIT_NONE) if (parmp->edit_type != EDIT_NONE) {
mainerr(err_too_many_args, argv[0]); mainerr(err_too_many_args, argv[0]);
}
parmp->edit_type = EDIT_QF; parmp->edit_type = EDIT_QF;
if (argv[0][argv_idx]) { /* "-q{errorfile}" */ if (argv[0][argv_idx]) { // "-q{errorfile}"
parmp->use_ef = (char_u *)argv[0] + argv_idx; parmp->use_ef = (char_u *)argv[0] + argv_idx;
argv_idx = -1; argv_idx = -1;
} else if (argc > 1) /* "-q {errorfile}" */ } else if (argc > 1) { // "-q {errorfile}"
want_argument = TRUE; want_argument = true;
}
break; break;
}
case 'R': /* "-R" readonly mode */ case 'R': { // "-R" readonly mode
readonlymode = TRUE; readonlymode = true;
curbuf->b_p_ro = TRUE; curbuf->b_p_ro = true;
p_uc = 10000; /* don't update very often */ p_uc = 10000; // don't update very often
break; break;
}
case 'r': /* "-r" recovery mode */ case 'r': // "-r" recovery mode
case 'L': /* "-L" recovery mode */ case 'L': { // "-L" recovery mode
recoverymode = 1; recoverymode = 1;
break; break;
}
case 's': case 's': {
if (exmode_active) { // "-es" silent (batch) mode if (exmode_active) { // "-es" silent (batch) Ex-mode
silent_mode = true; silent_mode = true;
} else { // "-s {scriptin}" read from script file } else { // "-s {scriptin}" read from script file
want_argument = true; want_argument = true;
} }
break; break;
}
case 't': /* "-t {tag}" or "-t{tag}" jump to tag */ case 't': { // "-t {tag}" or "-t{tag}" jump to tag
if (parmp->edit_type != EDIT_NONE) if (parmp->edit_type != EDIT_NONE) {
mainerr(err_too_many_args, argv[0]); mainerr(err_too_many_args, argv[0]);
}
parmp->edit_type = EDIT_TAG; parmp->edit_type = EDIT_TAG;
if (argv[0][argv_idx]) { /* "-t{tag}" */ if (argv[0][argv_idx]) { // "-t{tag}"
parmp->tagname = (char_u *)argv[0] + argv_idx; parmp->tagname = (char_u *)argv[0] + argv_idx;
argv_idx = -1; argv_idx = -1;
} else /* "-t {tag}" */ } else { // "-t {tag}"
want_argument = TRUE; want_argument = true;
}
break; break;
}
case 'D': /* "-D" Debugging */ case 'v': {
parmp->use_debug_break_level = 9999;
break;
case 'd': /* "-d" 'diff' */
parmp->diff_mode = TRUE;
break;
case 'v':
version(); version();
mch_exit(0); mch_exit(0);
case 'V': /* "-V{N}" Verbose level */ }
/* default is 10: a little bit verbose */ case 'V': { // "-V{N}" Verbose level
// default is 10: a little bit verbose
p_verbose = get_number_arg(argv[0], &argv_idx, 10); p_verbose = get_number_arg(argv[0], &argv_idx, 10);
if (argv[0][argv_idx] != NUL) { if (argv[0][argv_idx] != NUL) {
set_option_value("verbosefile", 0L, argv[0] + argv_idx, 0); set_option_value("verbosefile", 0L, argv[0] + argv_idx, 0);
argv_idx = (int)STRLEN(argv[0]); argv_idx = (int)STRLEN(argv[0]);
} }
break; break;
}
case 'w': /* "-w{number}" set window height */ case 'w': { // "-w{number}" set window height
/* "-w {scriptout}" write to script */ // "-w {scriptout}" write to script
if (ascii_isdigit(((char_u *)argv[0])[argv_idx])) { if (ascii_isdigit(((char_u *)argv[0])[argv_idx])) {
n = get_number_arg(argv[0], &argv_idx, 10); n = get_number_arg(argv[0], &argv_idx, 10);
set_option_value("window", n, NULL, 0); set_option_value("window", n, NULL, 0);
break; break;
} }
want_argument = TRUE; want_argument = true;
break; break;
}
case 'Z': /* "-Z" restricted mode */ case 'Z': { // "-Z" restricted mode
restricted = TRUE; restricted = true;
break; break;
}
case 'c': /* "-c{command}" or "-c {command}" execute case 'c': { // "-c{command}" or "-c {command}" exec command
command */
if (argv[0][argv_idx] != NUL) { if (argv[0][argv_idx] != NUL) {
if (parmp->n_commands >= MAX_ARG_CMDS) if (parmp->n_commands >= MAX_ARG_CMDS) {
mainerr(err_extra_cmd, NULL); mainerr(err_extra_cmd, NULL);
parmp->commands[parmp->n_commands++] = argv[0] }
+ argv_idx; parmp->commands[parmp->n_commands++] = argv[0] + argv_idx;
argv_idx = -1; argv_idx = -1;
break; break;
} }
/*FALLTHROUGH*/ // FALLTHROUGH
case 'S': /* "-S {file}" execute Vim script */ }
case 'i': /* "-i {shada}" use for ShaDa file */ case 'S': // "-S {file}" execute Vim script
case 'u': /* "-u {vimrc}" vim inits file */ case 'i': // "-i {shada}" use for ShaDa file
case 'U': /* "-U {gvimrc}" gvim inits file */ case 'u': // "-u {vimrc}" vim inits file
case 'W': /* "-W {scriptout}" overwrite */ case 'U': // "-U {gvimrc}" gvim inits file
want_argument = TRUE; case 'W': { // "-W {scriptout}" overwrite
want_argument = true;
break; break;
}
default: default: {
mainerr(err_opt_unknown, argv[0]); mainerr(err_opt_unknown, argv[0]);
}
} }
// Handle option arguments with argument. // Handle option arguments with argument.
@ -1034,43 +1038,45 @@ static void command_line_scan(mparm_T *parmp)
mainerr(err_opt_garbage, argv[0]); mainerr(err_opt_garbage, argv[0]);
} }
--argc; argc--;
if (argc < 1 && c != 'S') /* -S has an optional argument */ if (argc < 1 && c != 'S') { // -S has an optional argument
mainerr(err_arg_missing, argv[0]); mainerr(err_arg_missing, argv[0]);
++argv; }
argv++;
argv_idx = -1; argv_idx = -1;
switch (c) { switch (c) {
case 'c': /* "-c {command}" execute command */ case 'c': // "-c {command}" execute command
case 'S': /* "-S {file}" execute Vim script */ case 'S': { // "-S {file}" execute Vim script
if (parmp->n_commands >= MAX_ARG_CMDS) if (parmp->n_commands >= MAX_ARG_CMDS) {
mainerr(err_extra_cmd, NULL); mainerr(err_extra_cmd, NULL);
}
if (c == 'S') { if (c == 'S') {
char *a; char *a;
if (argc < 1) if (argc < 1) {
/* "-S" without argument: use default session file // "-S" without argument: use default session file name.
* name. */
a = SESSION_FILE; a = SESSION_FILE;
else if (argv[0][0] == '-') { } else if (argv[0][0] == '-') {
/* "-S" followed by another option: use default // "-S" followed by another option: use default session file.
* session file name. */
a = SESSION_FILE; a = SESSION_FILE;
++argc; ++argc;
--argv; --argv;
} else { } else {
a = argv[0]; a = argv[0];
} }
char *s = xmalloc(STRLEN(a) + 4); size_t s_size = STRLEN(a) + 4;
sprintf(s, "so %s", a); char *s = xmalloc(s_size);
parmp->cmds_tofree[parmp->n_commands] = TRUE; snprintf(s, s_size, "so %s", a);
parmp->cmds_tofree[parmp->n_commands] = true;
parmp->commands[parmp->n_commands++] = s; parmp->commands[parmp->n_commands++] = s;
} else { } else {
parmp->commands[parmp->n_commands++] = argv[0]; parmp->commands[parmp->n_commands++] = argv[0];
} }
break; break;
}
case '-': case '-': {
if (strequal(argv[-1], "--cmd")) { if (strequal(argv[-1], "--cmd")) {
// "--cmd {command}" execute command // "--cmd {command}" execute command
if (parmp->n_pre_commands >= MAX_ARG_CMDS) { if (parmp->n_pre_commands >= MAX_ARG_CMDS) {
@ -1083,16 +1089,19 @@ static void command_line_scan(mparm_T *parmp)
} }
// "--startuptime <file>" already handled // "--startuptime <file>" already handled
break; break;
}
case 'q': /* "-q {errorfile}" QuickFix mode */ case 'q': { // "-q {errorfile}" QuickFix mode
parmp->use_ef = (char_u *)argv[0]; parmp->use_ef = (char_u *)argv[0];
break; break;
}
case 'i': /* "-i {shada}" use for shada */ case 'i': { // "-i {shada}" use for shada
used_shada_file = argv[0]; used_shada_file = argv[0];
break; break;
}
case 's': /* "-s {scriptin}" read from script file */ case 's': { // "-s {scriptin}" read from script file
if (scriptin[0] != NULL) { if (scriptin[0] != NULL) {
scripterror: scripterror:
vim_snprintf((char *)IObuff, IOSIZE, vim_snprintf((char *)IObuff, IOSIZE,
@ -1105,8 +1114,7 @@ scripterror:
if (strequal(argv[0], "-")) { if (strequal(argv[0], "-")) {
const int stdin_dup_fd = os_dup(STDIN_FILENO); const int stdin_dup_fd = os_dup(STDIN_FILENO);
#ifdef WIN32 #ifdef WIN32
// On Windows, replace the original stdin with the // Replace the original stdin with the console input handle.
// console input handle.
close(STDIN_FILENO); close(STDIN_FILENO);
const HANDLE conin_handle = const HANDLE conin_handle =
CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
@ -1129,20 +1137,22 @@ scripterror:
} }
save_typebuf(); save_typebuf();
break; break;
}
case 't': /* "-t {tag}" */ case 't': { // "-t {tag}"
parmp->tagname = (char_u *)argv[0]; parmp->tagname = (char_u *)argv[0];
break; break;
}
case 'u': /* "-u {vimrc}" vim inits file */ case 'u': { // "-u {vimrc}" vim inits file
parmp->use_vimrc = argv[0]; parmp->use_vimrc = argv[0];
break; break;
}
case 'U': /* "-U {gvimrc}" gvim inits file */ case 'U': { // "-U {gvimrc}" gvim inits file
break; break;
}
case 'w': /* "-w {nr}" 'window' value */ case 'w': { // "-w {nr}" 'window' value
/* "-w {scriptout}" append to script file */ // "-w {scriptout}" append to script file
if (ascii_isdigit(*((char_u *)argv[0]))) { if (ascii_isdigit(*((char_u *)argv[0]))) {
argv_idx = 0; argv_idx = 0;
n = get_number_arg(argv[0], &argv_idx, 10); n = get_number_arg(argv[0], &argv_idx, 10);
@ -1150,10 +1160,12 @@ scripterror:
argv_idx = -1; argv_idx = -1;
break; break;
} }
/*FALLTHROUGH*/ // FALLTHROUGH
case 'W': /* "-W {scriptout}" overwrite script file */ }
if (scriptout != NULL) case 'W': { // "-W {scriptout}" overwrite script file
if (scriptout != NULL) {
goto scripterror; goto scripterror;
}
if ((scriptout = mch_fopen(argv[0], if ((scriptout = mch_fopen(argv[0],
c == 'w' ? APPENDBIN : WRITEBIN)) == NULL) { c == 'w' ? APPENDBIN : WRITEBIN)) == NULL) {
mch_errmsg(_("Cannot open for script output: \"")); mch_errmsg(_("Cannot open for script output: \""));
@ -1162,7 +1174,7 @@ scripterror:
mch_exit(2); mch_exit(2);
} }
break; break;
}
} }
} }
} else { // File name argument. } else { // File name argument.
@ -1759,14 +1771,15 @@ static bool do_user_initialization(void)
static void source_startup_scripts(const mparm_T *const parmp) static void source_startup_scripts(const mparm_T *const parmp)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
// If -u argument given, use only the initializations from that file and // If -u given, use only the initializations from that file and nothing else.
// nothing else.
if (parmp->use_vimrc != NULL) { if (parmp->use_vimrc != NULL) {
if (strcmp(parmp->use_vimrc, "NONE") == 0 if (strequal(parmp->use_vimrc, "NONE")
|| strcmp(parmp->use_vimrc, "NORC") == 0) { || strequal(parmp->use_vimrc, "NORC")) {
// Do nothing.
} else { } else {
if (do_source((char_u *)parmp->use_vimrc, FALSE, DOSO_NONE) != OK) if (do_source((char_u *)parmp->use_vimrc, FALSE, DOSO_NONE) != OK) {
EMSG2(_("E282: Cannot read from \"%s\""), parmp->use_vimrc); EMSG2(_("E282: Cannot read from \"%s\""), parmp->use_vimrc);
}
} }
} else if (!silent_mode) { } else if (!silent_mode) {
#ifdef SYS_VIMRC_FILE #ifdef SYS_VIMRC_FILE

View File

@ -2076,8 +2076,9 @@ static void t_puts(int *t_col, const char_u *t_s, const char_u *s, int attr)
} }
} }
// Returns TRUE when messages should be printed to stdout/stderr, which // Returns TRUE when messages should be printed to stdout/stderr:
// happens when no UIs are attached and nvim is not being embedded // - "batch mode" ("silent mode", -es/-Es)
// - no UI and not embedded
int msg_use_printf(void) int msg_use_printf(void)
{ {
return !embedded_mode && !ui_active(); return !embedded_mode && !ui_active();

View File

@ -50,7 +50,7 @@ void input_init(void)
input_buffer = rbuffer_new(INPUT_BUFFER_SIZE + MAX_KEY_CODE_LEN); input_buffer = rbuffer_new(INPUT_BUFFER_SIZE + MAX_KEY_CODE_LEN);
} }
/// Gets the file from which input was gathered at startup. /// File (set at startup) used to read user-input (or commands for -e/-es).
int input_global_fd(void) int input_global_fd(void)
{ {
return global_fd; return global_fd;
@ -438,8 +438,9 @@ static bool input_ready(void)
// Exit because of an input read error. // Exit because of an input read error.
static void read_error_exit(void) static void read_error_exit(void)
{ {
if (silent_mode) /* Normal way to exit for "ex -s" */ if (silent_mode) { // Normal way to exit for "nvim -es".
getout(0); getout(0);
}
STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); STRCPY(IObuff, _("Vim: Error reading input, exiting...\n"));
preserve_exit(); preserve_exit();
} }