aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-06-10 15:10:59 +0200
committerGitHub <noreply@github.com>2018-06-10 15:10:59 +0200
commitb8363283faac5e02cd9961119da7accb3d35d420 (patch)
tree7c7007656dd04dcc8b950c5fb00d98c2c060b39f /src
parent23d172a948e77c4e1d03db3b06efac6e9edd3695 (diff)
parentd8c7ff13352d7182826b5716ff3b6a66df241231 (diff)
downloadrneovim-b8363283faac5e02cd9961119da7accb3d35d420.tar.gz
rneovim-b8363283faac5e02cd9961119da7accb3d35d420.tar.bz2
rneovim-b8363283faac5e02cd9961119da7accb3d35d420.zip
Merge #7679 'startup: treat stdin as text instead of commands'
Diffstat (limited to 'src')
-rw-r--r--src/nvim/event/rstream.c2
-rw-r--r--src/nvim/globals.h235
-rw-r--r--src/nvim/main.c639
-rw-r--r--src/nvim/message.c5
-rw-r--r--src/nvim/os/input.c20
5 files changed, 415 insertions, 486 deletions
diff --git a/src/nvim/event/rstream.c b/src/nvim/event/rstream.c
index 2fbe7f6773..6812b342bf 100644
--- a/src/nvim/event/rstream.c
+++ b/src/nvim/event/rstream.c
@@ -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,
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 2860817f79..51bc3f1289 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -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);
-
-/*
- * "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.
- */
+/// 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.
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,46 @@ 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 */
-
-// 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 */
-EXTERN int VIsual_reselect;
-/* whether to restart the selection after a
- * Select mode mapping or menu */
-EXTERN int VIsual_mode INIT(= 'v');
-/* type of Visual mode */
+/// Batch-mode: "-es" or "-Es" commandline argument was given.
+EXTERN int silent_mode INIT(= false);
-EXTERN int redo_VIsual_busy INIT(= FALSE);
-/* TRUE when redoing Visual */
+/// 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;
+/// Type of Visual mode.
+EXTERN int VIsual_mode INIT(= 'v');
+/// TRUE when redoing Visual.
+EXTERN int redo_VIsual_busy INIT(= false);
-/*
- * 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 +702,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 +1132,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.
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 8b0d3bb2cc..e1a01fdba6 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -97,7 +97,6 @@ typedef struct {
char_u *tagname; // tag from -t argument
char_u *use_ef; // 'errorfile' from -q argument
- int want_full_screen;
bool input_isatty; // stdin is a terminal
bool output_isatty; // stdout is a terminal
bool err_isatty; // stderr is a terminal
@@ -106,9 +105,6 @@ typedef struct {
int window_count; // number of windows to use
int window_layout; // 0, WIN_HOR, WIN_VER or WIN_TABS
-#if !defined(UNIX)
- int literal; // don't expand file names
-#endif
int diff_mode; // start with 'diff' set
char *listen_addr; // --listen {address}
@@ -159,6 +155,7 @@ void event_init(void)
bool event_teardown(void)
{
if (!main_loop.events) {
+ input_stop();
return true;
}
@@ -271,25 +268,17 @@ int main(int argc, char **argv)
/* Don't redraw until much later. */
++RedrawingDisabled;
- /*
- * When listing swap file names, don't do cursor positioning et. al.
- */
- if (recoverymode && fname == NULL)
- params.want_full_screen = FALSE;
-
setbuf(stdout, NULL);
- full_screen = true;
- check_tty(&params);
+ full_screen = !silent_mode;
- /*
- * 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);
@@ -298,26 +287,31 @@ 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
- && (params.input_isatty || params.output_isatty
- || params.err_isatty);
-
- if (reading_input) {
+ //
+ // Read user-input if any TTY is connected.
+ // Read ex-commands if invoked with "-es".
+ //
+ bool reading_tty = !headless_mode
+ && (params.input_isatty || params.output_isatty
+ || params.err_isatty);
+ bool reading_excmds = !params.input_isatty && silent_mode
+ && exmode_active == EXMODE_NORMAL;
+ if (reading_tty || reading_excmds) {
// One of the startup commands (arguments, sourced scripts or plugins) may
// prompt the user, so start reading from a tty now.
- int fd = fileno(stdin);
- if (!params.input_isatty || params.edit_type == EDIT_STDIN) {
- // Use stderr or stdout since stdin is not a tty and/or could be used to
- // read the "-" file (eg: cat file | nvim -)
+ int fd = STDIN_FILENO;
+ if (!silent_mode
+ && (!params.input_isatty || params.edit_type == EDIT_STDIN)) {
+ // Use stderr or stdout since stdin is being used to read commands.
fd = params.err_isatty ? fileno(stderr) : fileno(stdout);
}
input_start(fd);
@@ -341,18 +335,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`.
@@ -378,17 +372,21 @@ int main(int argc, char **argv)
mch_exit(0);
}
- // Set a few option defaults after reading vimrc files:
- // 'title' and 'icon', Unix: 'shellpipe' and 'shellredir'.
+ // Set a few option defaults after reading vimrc files: 'title', 'icon',
+ // 'shellpipe', 'shellredir'.
set_init_3();
TIME_MSG("inits 3");
- /*
- * "-n" argument: Disable swap file by setting 'updatecount' to 0.
- * Note that this overrides anything from a vimrc file.
- */
- if (params.no_swap_file)
+ // "-n" argument: Disable swap file by setting 'updatecount' to 0.
+ // Note that this overrides anything from a vimrc file.
+ if (params.no_swap_file) {
p_uc = 0;
+ }
+
+ // XXX: Minimize 'updatetime' for -es/-Es. #7679
+ if (silent_mode) {
+ p_ut = 1;
+ }
if (curwin->w_p_rl && p_altkeymap) {
p_hkmap = FALSE; /* Reset the Hebrew keymap mode */
@@ -421,48 +419,47 @@ int main(int argc, char **argv)
* Clear screen now, so file message will not be cleared.
*/
starting = NO_BUFFERS;
- no_wait_return = FALSE;
- if (!exmode_active)
- msg_scroll = FALSE;
+ no_wait_return = false;
+ if (!exmode_active) {
+ msg_scroll = false;
+ }
- /*
- * If "-" argument given: Read file from stdin.
- * 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
- * are the same terminal: "cat | vim -".
- * Using autocommands here may cause trouble...
- */
- if (params.edit_type == EDIT_STDIN && !recoverymode)
+ // 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
+ // are the same terminal: "cat | vim -".
+ // Using autocommands here may cause trouble...
+ if (params.edit_type == EDIT_STDIN && !recoverymode) {
read_stdin();
+ }
-
- 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.
+ if (reading_tty && (need_wait_return || msg_didany)) {
+ // 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.
- input_stop();
+ if (!headless_mode && !silent_mode) {
+ input_stop(); // Stop reading input, let the UI take over.
ui_builtin_start();
}
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;
- else {
- screenclear(); /* clear screen */
+ if (exmode_active) {
+ must_redraw = CLEAR; // Don't clear the screen when starting in Ex mode.
+ } else {
+ 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.
@@ -691,9 +688,7 @@ static int get_number_arg(const char *p, int *idx, int def)
}
#if defined(HAVE_LOCALE_H)
-/*
- * Setup to use the current locale (for ctype() and many other things).
- */
+/// Setup to use the current locale (for ctype() and many other things).
static void init_locale(void)
{
setlocale(LC_ALL, "");
@@ -724,61 +719,73 @@ static void init_locale(void)
}
#endif
+/// Decides whether text (as opposed to commands) will be read from stdin.
+/// @see EDIT_STDIN
+static bool edit_stdin(bool explicit, mparm_T *parmp)
+{
+ bool implicit = !headless_mode
+ && !embedded_mode
+ && exmode_active != EXMODE_NORMAL // -E/-Es but not -e/-es.
+ && !parmp->input_isatty
+ && scriptin[0] == NULL; // `-s -` was not given.
+ return explicit || implicit;
+}
/// Scan the command line arguments.
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 */
+ char **argv = parmp->argv;
+ int argv_idx; // index in argv[n][]
+ bool had_stdin_file = false; // found explicit "-" argument
+ bool had_minmin = false; // found "--" argument
+ int want_argument; // option argument with argument
int c;
- char_u *p = NULL;
+ 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) {
+ if (parmp->edit_type != EDIT_NONE
+ && parmp->edit_type != EDIT_FILE
+ && parmp->edit_type != EDIT_STDIN) {
mainerr(err_too_many_args, argv[0]);
}
+ had_stdin_file = true;
parmp->edit_type = EDIT_STDIN;
}
- 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
+ // "--noplugin[s]" skip plugins
+ // "--cmd <cmd>" execute cmd before vimrc
if (STRICMP(argv[0] + argv_idx, "help") == 0) {
usage();
mch_exit(0);
@@ -821,26 +828,25 @@ static void command_line_scan(mparm_T *parmp)
want_argument = true;
argv_idx += 6;
} else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) {
-#if !defined(UNIX)
- 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;
+ // Do nothing: file args are always literal. #7679
+ } else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) {
+ p_lpl = false;
+ } else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0) {
+ want_argument = true;
argv_idx += 3;
} else if (STRNICMP(argv[0] + argv_idx, "startuptime", 11) == 0) {
- want_argument = TRUE;
+ 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;
@@ -854,168 +860,176 @@ 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
+ 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;
- break;
-
- case 'D': /* "-D" Debugging */
- parmp->use_debug_break_level = 9999;
- break;
- case 'd': /* "-d" 'diff' */
- parmp->diff_mode = TRUE;
+ } else { // "-t {tag}"
+ want_argument = 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