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) {
return;
} 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);
} else {
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_vimruntime INIT(= FALSE); /* idem for $VIMRUNTIME */
/*
* Lines left before a "more" message. Ex mode needs to be able to reset this
* 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
messages */
/// Lines left before a "more" message. Ex mode needs to be able to reset this
/// 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
// messages
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 */
@ -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_backtrace_level INIT(= 0); // breakpoint backtrace level
/* Values for "do_profiling". */
#define PROF_NONE 0 /* profiling not started */
#define PROF_YES 1 /* profiling busy */
#define PROF_PAUSED 2 /* profiling paused */
EXTERN int do_profiling INIT(= PROF_NONE); /* PROF_ values */
// Values for "do_profiling".
#define PROF_NONE 0 ///< profiling not started
#define PROF_YES 1 ///< profiling busy
#define PROF_PAUSED 2 ///< profiling paused
EXTERN int do_profiling INIT(= PROF_NONE); ///< PROF_ values
/*
* The exception currently being thrown. Used to pass an exception to
* a different cstack. Also used for discarding an exception before it is
* caught or made pending.
*/
/// Exception currently being thrown. Used to pass an exception to a different
/// cstack. Also used for discarding an exception before it is caught or made
/// pending.
EXTERN except_T *current_exception;
/*
* need_rethrow: set to TRUE when a throw that cannot be handled in do_cmdline()
* must be propagated to the cstack of the previously called do_cmdline().
*/
EXTERN int need_rethrow INIT(= FALSE);
/// Set when a throw that cannot be handled in do_cmdline() must be propagated
/// to the cstack of the previously called do_cmdline().
EXTERN int need_rethrow INIT(= false);
/*
* check_cstack: set to TRUE when a ":finish" or ":return" that cannot be
* handled in do_cmdline() must be propagated to the cstack of the previously
* called do_cmdline().
*/
EXTERN int check_cstack INIT(= FALSE);
/// Set when a ":finish" or ":return" that cannot be handled in do_cmdline()
/// must be propagated to the cstack of the previously called do_cmdline().
EXTERN int check_cstack INIT(= false);
/*
* Number of nested try conditionals (across function calls and ":source"
* commands).
*/
/// Number of nested try conditionals (across function calls and ":source"
/// commands).
EXTERN int trylevel INIT(= 0);
/*
* When "force_abort" is TRUE, always skip commands after an error message,
* even after the outermost ":endif", ":endwhile" or ":endfor" or for a
* 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
* 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.
*/
EXTERN int force_abort INIT(= FALSE);
/// When "force_abort" is TRUE, always skip commands after an error message,
/// even after the outermost ":endif", ":endwhile" or ":endfor" or for a
/// 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
/// 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.
EXTERN int force_abort INIT(= false);
/*
* "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
* converted to an error exception immediately after the failing command
* 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
* 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
* emsg() call was made.
*/
/// "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
/// converted to an error exception immediately after the failing command
/// 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
/// 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
/// emsg() call was made.
EXTERN struct msglist **msg_list INIT(= NULL);
/*
* suppress_errthrow: When TRUE, don't convert an error to an exception. Used
* when displaying the interrupt message or reporting an exception that is still
* uncaught at the top level (which has already been discarded then). Also used
* for the error message when no exception can be thrown.
*/
EXTERN int suppress_errthrow INIT(= FALSE);
/// When set, don't convert an error to an exception. Used when displaying the
/// interrupt message or reporting an exception that is still uncaught at the
/// top level (which has already been discarded then). Also used for the error
/// message when no exception can be thrown.
EXTERN int suppress_errthrow INIT(= false);
/*
* 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
* stack of all caught and pending exceptions is embedded in the various
* cstacks; the pending exceptions, however, are not on the caught stack.
*/
/// 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
/// stack of all caught and pending exceptions is embedded in the various
/// cstacks; the pending exceptions, however, are not on the caught stack.
EXTERN except_T *caught_stack INIT(= NULL);
/*
* Garbage collection can only take place when we are sure there are no Lists
* or Dictionaries being used internally. This is flagged with
* "may_garbage_collect" when we are at the toplevel.
* "want_garbage_collect" is set by the garbagecollect() function, which means
* we do garbage collection before waiting for a char at the toplevel.
* "garbage_collect_at_exit" indicates garbagecollect(1) was called.
*/
EXTERN int may_garbage_collect INIT(= FALSE);
EXTERN int want_garbage_collect INIT(= FALSE);
EXTERN int garbage_collect_at_exit INIT(= FALSE);
///
/// Garbage collection can only take place when we are sure there are no Lists
/// or Dictionaries being used internally. This is flagged with
/// "may_garbage_collect" when we are at the toplevel.
/// "want_garbage_collect" is set by the garbagecollect() function, which means
/// we do garbage collection before waiting for a char at the toplevel.
/// "garbage_collect_at_exit" indicates garbagecollect(1) was called.
///
EXTERN int may_garbage_collect INIT(= false);
EXTERN int want_garbage_collect INIT(= false);
EXTERN int garbage_collect_at_exit INIT(= false);
// Special values for current_SID.
#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.
EXTERN volatile int full_screen INIT(= false);
EXTERN int restricted INIT(= FALSE);
// TRUE when started in restricted mode (-Z)
EXTERN int secure INIT(= FALSE);
/* non-zero when only "safe" commands are
* allowed, e.g. when sourcing .exrc or .vimrc
* in current directory */
// When started in restricted mode (-Z).
EXTERN int restricted INIT(= false);
/// 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);
/* 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);
/* 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);
/* 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. */
/// Non-zero when evaluating an expression in a "sandbox". Several things are
/// not allowed then.
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);
/* set to TRUE when "-s" commandline argument
* used for ex */
/// Batch-mode: "-es" or "-Es" commandline argument was given.
EXTERN int silent_mode INIT(= false);
// Set to true when sourcing of startup scripts (init.vim) is done.
// Used for options that cannot be changed after startup scripts.
/// Set to true when sourcing of startup scripts (init.vim) is done.
/// Used for options that cannot be changed after startup scripts.
EXTERN bool did_source_startup_scripts INIT(= false);
EXTERN pos_T VIsual; /* start position of active Visual selection */
EXTERN int VIsual_active INIT(= FALSE);
/* whether Visual mode is active */
EXTERN int VIsual_select INIT(= FALSE);
/* whether Select mode is active */
/// Start position of active Visual selection.
EXTERN pos_T VIsual;
/// Whether Visual mode is active.
EXTERN int VIsual_active INIT(= false);
/// 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;
/* whether to restart the selection after a
* Select mode mapping or menu */
/// Type of Visual mode.
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);
/* TRUE when redoing Visual */
/*
* When pasting text with the middle mouse button in visual mode with
* 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;
/*
@ -732,25 +706,23 @@ EXTERN int (*iconvctl)(iconv_t cd, int request, void *argument);
EXTERN int* (*iconv_errno)(void);
# endif
/*
* "State" is the main state of Vim.
* There are other variables that modify the state:
* "Visual_mode" When State is NORMAL or INSERT.
* "finish_op" When State is NORMAL, after typing the operator and before
* typing the motion command.
*/
EXTERN int State INIT(= NORMAL); /* This is the current state of the
* command interpreter. */
/// "State" is the main state of Vim.
/// There are other variables that modify the state:
/// Visual_mode: When State is NORMAL or INSERT.
/// finish_op : When State is NORMAL, after typing the operator and
/// before typing the motion command.
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 long opcount INIT(= 0); // count for pending operator
// Ex Mode (Q) state
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 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 Recording INIT(= FALSE); /* TRUE when recording into a reg. */
EXTERN int Exec_reg INIT(= FALSE); /* TRUE when executing a register */
EXTERN int Recording INIT(= false); // TRUE when recording into a reg.
EXTERN int Exec_reg INIT(= false); // TRUE when executing a register.
EXTERN int no_mapping INIT(= false); // currently no mapping 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 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);
// Dont try to start an user interface
// or read/write to stdio (unless embedding)
// Do not start a UI nor read/write to stdio (unless embedding).
EXTERN bool headless_mode INIT(= false);
/// Used to track the status of external functions.

View File

@ -281,14 +281,13 @@ int main(int argc, char **argv)
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();
// Set the 'diff' option now, so that it can be checked for in a vimrc
// file. There is no buffer yet though.
if (params.diff_mode)
diff_win_options(firstwin, FALSE);
if (params.diff_mode) {
diff_win_options(firstwin, false);
}
assert(p_ch >= 0 && Rows >= p_ch && Rows - p_ch <= INT_MAX);
cmdline_row = (int)(Rows - p_ch);
@ -297,13 +296,13 @@ int main(int argc, char **argv)
set_init_2(headless_mode);
TIME_MSG("inits 2");
msg_scroll = TRUE;
no_wait_return = TRUE;
msg_scroll = 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");
/* 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;
bool reading_input = !headless_mode
@ -340,18 +339,18 @@ int main(int argc, char **argv)
// Reset 'loadplugins' for "-u NONE" before "--cmd" arguments.
// 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;
}
/* Execute --cmd arguments. */
// Execute --cmd arguments.
exe_pre_commands(&params);
/* Source startup scripts. */
// Source startup scripts.
source_startup_scripts(&params);
// 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".
filetype_maybe_enable();
// Sources syntax/syntax.vim, which calls `:filetype on`.
@ -425,9 +424,9 @@ int main(int argc, char **argv)
msg_scroll = false;
}
// Read file from stdin:
// - If "-" argument was given as a file arg.
// - If stdin is a pipe and "-es"/"-Es"/"-s -" were not given.
// Read file (text, not commands) from stdin if:
// - stdin is not a tty
// - and -e/-es was not given
//
// 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
@ -438,16 +437,15 @@ int main(int argc, char **argv)
}
if (reading_input && (need_wait_return || msg_didany)) {
// Since at this point there's no UI instance running yet, error messages
// would have been printed to stdout. Before starting (which can result in
// a alternate screen buffer being shown) we need confirmation that the
// user has seen the messages and that is done with a call to wait_return.
// Because there's no UI yet, error messages would have been printed to
// stdout. Before starting we need confirmation that the user has seen the
// messages and that is done with a call to wait_return.
TIME_MSG("waiting for return");
wait_return(TRUE);
wait_return(true);
}
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();
ui_builtin_start();
}
@ -455,15 +453,14 @@ int main(int argc, char **argv)
setmouse(); // may start using the mouse
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)
must_redraw = CLEAR;
must_redraw = CLEAR; // Don't clear the screen when starting in Ex mode.
else {
screenclear(); /* clear screen */
screenclear(); // clear screen
TIME_MSG("clearing screen");
}
no_wait_return = TRUE;
no_wait_return = true;
/*
* Create the requested number of windows and edit buffers in them.
@ -739,55 +736,53 @@ static void command_line_scan(mparm_T *parmp)
{
int argc = parmp->argc;
char **argv = parmp->argv;
int argv_idx; /* index in argv[n][] */
int had_minmin = FALSE; /* found "--" argument */
int want_argument; /* option argument with argument */
int argv_idx; // index in argv[n][]
int had_minmin = false; // found "--" argument
int want_argument; // option argument with argument
int c;
char_u *p = NULL;
long n;
--argc;
++argv;
argv_idx = 1; /* active option letter is argv[0][argv_idx] */
argc--;
argv++;
argv_idx = 1; // active option letter is argv[0][argv_idx]
while (argc > 0) {
/*
* "+" or "+{number}" or "+/{pat}" or "+{command}" argument.
*/
// "+" or "+{number}" or "+/{pat}" or "+{command}" argument.
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);
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++] = "$";
else
} else {
parmp->commands[parmp->n_commands++] = &(argv[0][1]);
}
/*
* Optional argument.
*/
else if (argv[0][0] == '-' && !had_minmin) {
want_argument = FALSE;
// Optional argument.
} else if (argv[0][0] == '-' && !had_minmin) {
want_argument = false;
c = argv[0][argv_idx++];
switch (c) {
case NUL: /* "vim -" read from stdin */
case NUL: { // "nvim -" read from stdin
if (exmode_active) {
// "ex -" silent mode
silent_mode = TRUE;
// "nvim -e -" silent mode
silent_mode = true;
} else {
if (parmp->edit_type != EDIT_NONE) {
mainerr(err_too_many_args, argv[0]);
}
parmp->edit_type = EDIT_STDIN;
}
argv_idx = -1; /* skip to next argument */
argv_idx = -1; // skip to next argument
break;
case '-': /* "--" don't take any more option arguments */
/* "--help" give help message */
/* "--version" give version message */
/* "--literal" take files literally */
/* "--noplugin[s]" skip plugins */
/* "--cmd <cmd>" execute cmd before vimrc */
}
case '-': { // "--" don't take any more option arguments
// "--help" give help message
// "--version" give version message
// "--literal" take files literally
// "--noplugin[s]" skip plugins
// "--cmd <cmd>" execute cmd before vimrc
if (STRICMP(argv[0] + argv_idx, "help") == 0) {
usage();
mch_exit(0);
@ -831,25 +826,26 @@ static void command_line_scan(mparm_T *parmp)
argv_idx += 6;
} else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) {
#if !defined(UNIX)
parmp->literal = TRUE;
parmp->literal = true;
#endif
} 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;
} 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;
want_argument = true;
argv_idx += 11;
} else {
if (argv[0][argv_idx])
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;
}
case 'A': { // "-A" start in Arabic mode.
set_option_value("arabic", 1L, NULL, 0);
break;
@ -863,169 +859,177 @@ static void command_line_scan(mparm_T *parmp)
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;
break;
case 'E': /* "-E" Improved Ex mode */
}
case 'E': { // "-E" Improved Ex mode
exmode_active = EXMODE_VIM;
break;
case 'f': /* "-f" GUI: run in foreground. */
}
case 'f': { // "-f" GUI: run in foreground.
break;
}
case 'F': { // "-F" start in Farsi mode: rl + fkmap set.
p_fkmap = true;
set_option_value("rl", 1L, NULL, 0);
break;
}
case 'h': /* "-h" give help message */
case 'h': { // "-h" give help message
usage();
mch_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 */
case 'M': { // "-M" no changes or writing of files
reset_modifiable();
/* FALLTHROUGH */
case 'm': /* "-m" no writing of files */
p_write = FALSE;
// 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" no swap file */
parmp->no_swap_file = TRUE;
case 'n': { // "-n" no swap file
parmp->no_swap_file = true;
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
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 */
}
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 */
}
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)
}
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}" */
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;
} 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 */
}
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 */
}
case 'r': // "-r" recovery mode
case 'L': { // "-L" recovery mode
recoverymode = 1;
break;
case 's':
if (exmode_active) { // "-es" silent (batch) mode
}
case 's': {
if (exmode_active) { // "-es" silent (batch) Ex-mode
silent_mode = true;
} else { // "-s {scriptin}" read from script file
want_argument = true;
}
break;
case 't': /* "-t {tag}" or "-t{tag}" jump to tag */
if (parmp->edit_type != EDIT_NONE)
}
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}" */
if (argv[0][argv_idx]) { // "-t{tag}"
parmp->tagname = (char_u *)argv[0] + argv_idx;
argv_idx = -1;
} else /* "-t {tag}" */
want_argument = TRUE;
} else { // "-t {tag}"
want_argument = true;
}
break;
case 'D': /* "-D" Debugging */
parmp->use_debug_break_level = 9999;
break;
case 'd': /* "-d" 'diff' */
parmp->diff_mode = TRUE;
break;
case 'v':
}
case 'v': {
version();
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);
if (argv[0][argv_idx] != NUL) {
set_option_value("verbosefile", 0L, argv[0] + argv_idx, 0);
argv_idx = (int)STRLEN(argv[0]);
}
break;
case 'w': /* "-w{number}" set window height */
/* "-w {scriptout}" write to script */
}
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;
want_argument = true;
break;
case 'Z': /* "-Z" restricted mode */
restricted = TRUE;
}
case 'Z': { // "-Z" restricted mode
restricted = true;
break;
}
case 'c': /* "-c{command}" or "-c {command}" execute
command */
case 'c': { // "-c{command}" or "-c {command}" exec command
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);
parmp->commands[parmp->n_commands++] = argv[0]
+ argv_idx;
}
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;
// 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:
default: {
mainerr(err_opt_unknown, argv[0]);
}
}
// Handle option arguments with argument.
if (want_argument) {
@ -1034,43 +1038,45 @@ static void command_line_scan(mparm_T *parmp)
mainerr(err_opt_garbage, argv[0]);
}
--argc;
if (argc < 1 && c != 'S') /* -S has an optional argument */
argc--;
if (argc < 1 && c != 'S') { // -S has an optional argument
mainerr(err_arg_missing, argv[0]);
++argv;
}
argv++;
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)
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. */
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 name. */
} else if (argv[0][0] == '-') {
// "-S" followed by another option: use default session file.
a = SESSION_FILE;
++argc;
--argv;
} else {
a = argv[0];
}
char *s = xmalloc(STRLEN(a) + 4);
sprintf(s, "so %s", a);
parmp->cmds_tofree[parmp->n_commands] = TRUE;
size_t s_size = STRLEN(a) + 4;
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 '-':
case '-': {
if (strequal(argv[-1], "--cmd")) {
// "--cmd {command}" execute command
if (parmp->n_pre_commands >= MAX_ARG_CMDS) {
@ -1083,16 +1089,19 @@ static void command_line_scan(mparm_T *parmp)
}
// "--startuptime <file>" already handled
break;
}
case 'q': /* "-q {errorfile}" QuickFix mode */
case 'q': { // "-q {errorfile}" QuickFix mode
parmp->use_ef = (char_u *)argv[0];
break;
}
case 'i': /* "-i {shada}" use for shada */
case 'i': { // "-i {shada}" use for shada
used_shada_file = argv[0];
break;
}
case 's': /* "-s {scriptin}" read from script file */
case 's': { // "-s {scriptin}" read from script file
if (scriptin[0] != NULL) {
scripterror:
vim_snprintf((char *)IObuff, IOSIZE,
@ -1105,8 +1114,7 @@ scripterror:
if (strequal(argv[0], "-")) {
const int stdin_dup_fd = os_dup(STDIN_FILENO);
#ifdef WIN32
// On Windows, replace the original stdin with the
// console input handle.
// Replace the original stdin with the console input handle.
close(STDIN_FILENO);
const HANDLE conin_handle =
CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
@ -1129,20 +1137,22 @@ scripterror:
}
save_typebuf();
break;
}
case 't': /* "-t {tag}" */
case 't': { // "-t {tag}"
parmp->tagname = (char_u *)argv[0];
break;
case 'u': /* "-u {vimrc}" vim inits file */
}
case 'u': { // "-u {vimrc}" vim inits file
parmp->use_vimrc = argv[0];
break;
case 'U': /* "-U {gvimrc}" gvim inits file */
}
case 'U': { // "-U {gvimrc}" gvim inits file
break;
}
case 'w': /* "-w {nr}" 'window' value */
/* "-w {scriptout}" append to script file */
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);
@ -1150,10 +1160,12 @@ scripterror:
argv_idx = -1;
break;
}
/*FALLTHROUGH*/
case 'W': /* "-W {scriptout}" overwrite script file */
if (scriptout != NULL)
// FALLTHROUGH
}
case 'W': { // "-W {scriptout}" overwrite script file
if (scriptout != NULL) {
goto scripterror;
}
if ((scriptout = mch_fopen(argv[0],
c == 'w' ? APPENDBIN : WRITEBIN)) == NULL) {
mch_errmsg(_("Cannot open for script output: \""));
@ -1162,7 +1174,7 @@ scripterror:
mch_exit(2);
}
break;
}
}
}
} else { // File name argument.
@ -1759,15 +1771,16 @@ static bool do_user_initialization(void)
static void source_startup_scripts(const mparm_T *const parmp)
FUNC_ATTR_NONNULL_ALL
{
// If -u argument given, use only the initializations from that file and
// nothing else.
// If -u given, use only the initializations from that file and nothing else.
if (parmp->use_vimrc != NULL) {
if (strcmp(parmp->use_vimrc, "NONE") == 0
|| strcmp(parmp->use_vimrc, "NORC") == 0) {
if (strequal(parmp->use_vimrc, "NONE")
|| strequal(parmp->use_vimrc, "NORC")) {
// Do nothing.
} 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);
}
}
} else if (!silent_mode) {
#ifdef SYS_VIMRC_FILE
// Get system wide defaults, if the file name is defined.

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
// happens when no UIs are attached and nvim is not being embedded
// Returns TRUE when messages should be printed to stdout/stderr:
// - "batch mode" ("silent mode", -es/-Es)
// - no UI and not embedded
int msg_use_printf(void)
{
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);
}
/// 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)
{
return global_fd;
@ -438,8 +438,9 @@ static bool input_ready(void)
// Exit because of an input read error.
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);
}
STRCPY(IObuff, _("Vim: Error reading input, exiting...\n"));
preserve_exit();
}