summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2005-07-24 21:18:31 +0000
committerBram Moolenaar <Bram@vim.org>2005-07-24 21:18:31 +0000
commitc013cb66a6f2403e90a43203e4059b4bb531a8e8 (patch)
tree11c73e39404969508df07336fac99597b5f8dd5e
parent81366db6d6668a753c44cacbbe7669b7f37cac37 (diff)
updated for version 7.0115v7.0115
-rw-r--r--runtime/doc/todo.txt6
-rw-r--r--src/main.c2453
2 files changed, 1307 insertions, 1152 deletions
diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt
index 359058de63..264a06dc22 100644
--- a/runtime/doc/todo.txt
+++ b/runtime/doc/todo.txt
@@ -1,4 +1,4 @@
-*todo.txt* For Vim version 7.0aa. Last change: 2005 Jul 23
+*todo.txt* For Vim version 7.0aa. Last change: 2005 Jul 24
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -58,9 +58,7 @@ Win32: Crash when pasting Simplified Chinese in utf-8. (rainux, 2005 June 20)
PLANNED FOR VERSION 7.0:
-- REFACTORING: The main() function is very long. Move parts to separate
- functions, especially loops. Ideas from Walter Briscoe (2003 Apr 3, 2004
- Feb 9).
+- REFACTORING:
Improve the interface between the generic GUI code and the system-specific
code. Generic code handles text window with scrollbars, system-specific
code menu, toolbar, etc.
diff --git a/src/main.c b/src/main.c
index 0e274adf5d..1beaca47f9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,15 +29,71 @@
# include <limits.h>
#endif
+/* Maximum number of commands from + or -c arguments. */
+#define MAX_ARG_CMDS 10
+
/* Struct for various parameters passed between main() and other functions. */
typedef struct
{
+ int argc;
+ char **argv;
+
+ int evim_mode; /* started as "evim" */
+ int bin_mode; /* -b argument used */
+ char_u *use_vimrc; /* vimrc from -u argument */
+
+ int n_commands; /* no. of commands from + or -c */
+ char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c arg. */
+ char_u cmds_tofree[MAX_ARG_CMDS]; /* commands that need free() */
+ int n_pre_commands; /* no. of commands from --cmd */
+ char_u *pre_commands[MAX_ARG_CMDS]; /* commands from --cmd argument */
+
+ int edit_type; /* type of editing to do */
+ char_u *tagname; /* tag from -t argument */
+#ifdef FEAT_QUICKFIX
+ char_u *use_ef; /* 'errorfile' from -q argument */
+#endif
+
+ int want_full_screen;
+ int stdout_isatty; /* is stdout a terminal? */
+ char_u *term; /* specified terminal name */
+#ifdef FEAT_CRYPT
+ int ask_for_key; /* -x argument */
+#endif
+ int no_swap_file; /* "-n" argument used */
+#ifdef FEAT_EVAL
+ int use_debug_break_level;
+#endif
+#ifdef FEAT_WINDOWS
+ int window_count; /* number of windows to use */
+ int vert_windows; /* "-O" used instead of "-o" */
+#endif
+
+#ifdef FEAT_CLIENTSERVER
int serverArg; /* TRUE when argument for a server */
char_u *serverName_arg; /* cmdline arg for server name */
- int evim_mode; /* started as "evim" */
- char_u *use_vimrc; /* vimrc from -u option */
+ char_u *serverStr; /* remote server command */
+ char_u *serverStrEnc; /* encoding of serverStr */
+ char_u *servername; /* allocated name for our server */
+#endif
+#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
+ int literal; /* don't expand file names */
+#endif
+#ifdef MSWIN
+ int full_path; /* file name argument was full path */
+#endif
+#ifdef FEAT_DIFF
+ int diff_mode; /* start with 'diff' set */
+#endif
} mparm_T;
+/* Values for edit_type. */
+#define EDIT_NONE 0 /* no edit type yet */
+#define EDIT_FILE 1 /* file name argument[s] given, use argument list */
+#define EDIT_STDIN 2 /* read file from stdin */
+#define EDIT_TAG 3 /* tag name argument given, use tagname */
+#define EDIT_QF 4 /* start in quickfix mode */
+
#if defined(UNIX) || defined(VMS)
static int file_owned __ARGS((char *fname));
#endif
@@ -45,14 +101,28 @@ static void mainerr __ARGS((int, char_u *));
static void main_msg __ARGS((char *s));
static void usage __ARGS((void));
static int get_number_arg __ARGS((char_u *p, int *idx, int def));
-static void early_arg_scan __ARGS((int argc, char **argv, mparm_T *parmp));
-static void exe_pre_commands __ARGS((char_u **cmds, int cnt));
+#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
+static void init_locale __ARGS((void));
+#endif
+static void parse_command_name __ARGS((mparm_T *parmp));
+static void early_arg_scan __ARGS((mparm_T *parmp));
+static void command_line_scan __ARGS((mparm_T *parmp));
+static void check_tty __ARGS((mparm_T *parmp));
+static void read_stdin __ARGS((void));
+static void create_windows __ARGS((mparm_T *parmp));
+#ifdef FEAT_WINDOWS
+static void edit_buffers __ARGS((mparm_T *parmp));
+#endif
+static void exe_pre_commands __ARGS((mparm_T *parmp));
+static void exe_commands __ARGS((mparm_T *parmp));
static void source_startup_scripts __ARGS((mparm_T *parmp));
static void main_start_gui __ARGS((void));
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
static void check_swap_exists_action __ARGS((void));
#endif
#ifdef FEAT_CLIENTSERVER
+static void exec_on_server __ARGS((mparm_T *parmp));
+static void prepare_server __ARGS((mparm_T *parmp));
static void cmdsrv_main __ARGS((int *argc, char **argv, char_u *serverName_arg, char_u **serverStr));
static char_u *serverMakeName __ARGS((char_u *arg, char *cmd));
#endif
@@ -67,13 +137,13 @@ static FILE *time_fd = NULL;
*/
static char *(main_errors[]) =
{
- N_("Unknown option"),
+ N_("Unknown option argument"),
#define ME_UNKNOWN_OPTION 0
N_("Too many edit arguments"),
#define ME_TOO_MANY_ARGS 1
N_("Argument missing after"),
#define ME_ARG_MISSING 2
- N_("Garbage after option"),
+ N_("Garbage after option argument"),
#define ME_GARBAGE 3
N_("Too many \"+command\", \"-c command\" or \"--cmd command\" arguments"),
#define ME_EXTRA_CMD 4
@@ -81,9 +151,6 @@ static char *(main_errors[]) =
#define ME_INVALID_ARG 5
};
-/* Maximum number of commands from + or -c options */
-#define MAX_ARG_CMDS 10
-
#ifndef PROTO /* don't want a prototype for main() */
int
# ifdef VIMDLL
@@ -101,60 +168,7 @@ main
int argc;
char **argv;
{
- char_u *initstr; /* init string from environment */
- char_u *term = NULL; /* specified terminal name */
char_u *fname = NULL; /* file name from command line */
- char_u *tagname = NULL; /* tag from -t option */
-#ifdef FEAT_QUICKFIX
- char_u *use_ef = NULL; /* 'errorfile' from -q option */
-#endif
-#ifdef FEAT_CRYPT
- int ask_for_key = FALSE; /* -x argument */
-#endif
- int n_commands = 0; /* no. of commands from + or -c */
- char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c option */
- char_u cmds_tofree[MAX_ARG_CMDS]; /* commands that need free() */
- int n_pre_commands = 0; /* no. of commands from --cmd */
- char_u *pre_commands[MAX_ARG_CMDS]; /* commands from --cmd option */
- int no_swap_file = FALSE; /* "-n" option used */
- int c;
- int i;
- char_u *p = NULL;
- int bin_mode = FALSE; /* -b option used */
-#ifdef FEAT_EVAL
- int use_debug_break_level = -1;
-#endif
-#ifdef FEAT_WINDOWS
- int window_count = -1; /* number of windows to use */
- int arg_idx; /* index in argument list */
- int vert_windows = MAYBE; /* "-O" used instead of "-o" */
-#endif
- int had_minmin = FALSE; /* found "--" option */
- int argv_idx; /* index in argv[n][] */
- int want_full_screen = TRUE;
- int want_argument; /* option with argument */
-#define EDIT_NONE 0 /* no edit type yet */
-#define EDIT_FILE 1 /* file name argument[s] given, use argument list */
-#define EDIT_STDIN 2 /* read file from stdin */
-#define EDIT_TAG 3 /* tag name argument given, use tagname */
-#define EDIT_QF 4 /* start in quickfix mode */
- int edit_type = EDIT_NONE; /* type of editing to do */
-#ifdef FEAT_DIFF
- int diff_mode = FALSE; /* start with 'diff' set */
-#endif
- int stdout_isatty; /* is stdout a terminal? */
- int input_isatty; /* is active input a terminal? */
-#ifdef MSWIN
- int full_path = FALSE;
-#endif
-#ifdef FEAT_CLIENTSERVER
- char_u *serverStr = NULL; /* remote server command */
- char_u *serverStrEnc = NULL; /* encoding of serverStr */
- char_u *servername = NULL; /* allocated name for our server */
-#endif
-#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
- int literal = FALSE; /* don't expand file names */
-#endif
mparm_T params; /* various parameters passed between
* main() and other functions. */
@@ -164,10 +178,23 @@ main
*/
mch_early_init();
+ /* Many variables are in "params" so that we can pass them to invoked
+ * functions without a lot of arguments. "argc" and "argv" are also
+ * copied, so that they can be changed. */
vim_memset(&params, 0, sizeof(params));
+ params.argc = argc;
+ params.argv = argv;
+ params.want_full_screen = TRUE;
+#ifdef FEAT_EVAL
+ params.use_debug_break_level = -1;
+#endif
+#ifdef FEAT_WINDOWS
+ params.window_count = -1;
+ params.vert_windows = MAYBE;
+#endif
#ifdef FEAT_TCL
- vim_tcl_init(argv[0]);
+ vim_tcl_init(params.argv[0]);
#endif
#ifdef MEM_PROFILE
@@ -180,7 +207,7 @@ main
#endif
#ifdef __EMX__
- _wildcard(&argc, &argv);
+ _wildcard(&params.argc, &params.argv);
#endif
#ifdef FEAT_MBYTE
@@ -195,13 +222,12 @@ main
#endif
#ifdef MAC_OS_CLASSIC
+ /* Prepare for possibly starting GUI sometime */
/* Macintosh needs this before any memory is allocated. */
- gui_prepare(&argc, argv); /* Prepare for possibly starting GUI sometime */
+ gui_prepare(&params.argc, params.argv);
TIME_MSG("GUI prepared");
#endif
- vim_memset(cmds_tofree, 0, sizeof(cmds_tofree));
-
/* Init the table of Normal mode commands. */
init_normal_cmds();
@@ -216,7 +242,6 @@ main
if ((IObuff = alloc(IOSIZE)) == NULL
|| (NameBuff = alloc(MAXPATHL)) == NULL)
mch_exit(0);
-
TIME_MSG("Allocated generic buffers");
#ifdef NBDEBUG
@@ -224,6 +249,7 @@ main
* NameBuff. */
nbdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL");
nbdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20);
+ TIME_MSG("NetBeans debug wait");
#endif
#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
@@ -232,30 +258,7 @@ main
* NOTE: Translated messages with encodings other than latin1 will not
* work until set_init_1() has been called!
*/
- setlocale(LC_ALL, "");
-
-# ifdef FEAT_GETTEXT
- {
- int mustfree = FALSE;
-
-# ifdef DYNAMIC_GETTEXT
- /* Initialize the gettext library */
- dyn_libintl_init(NULL);
-# endif
- /* expand_env() doesn't work yet, because chartab[] is not initialized
- * yet, call vim_getenv() directly */
- p = vim_getenv((char_u *)"VIMRUNTIME", &mustfree);
- if (p != NULL && *p != NUL)
- {
- STRCPY(NameBuff, p);
- STRCAT(NameBuff, "/lang");
- bindtextdomain(VIMPACKAGE, (char *)NameBuff);
- }
- if (mustfree)
- vim_free(p);
- textdomain(VIMPACKAGE);
- }
-# endif
+ init_locale();
TIME_MSG("locale set");
#endif
@@ -265,17 +268,18 @@ main
/*
* Do a first scan of the arguments in "argv[]":
- * -display
+ * -display or --display
* --server...
* --socketid
*/
- early_arg_scan(argc, argv, &params);
+ early_arg_scan(&params);
#ifdef FEAT_SUN_WORKSHOP
- findYourself(argv[0]);
+ findYourself(params.argv[0]);
#endif
#if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC)
- gui_prepare(&argc, argv); /* Prepare for possibly starting GUI sometime */
+ /* Prepare for possibly starting GUI sometime */
+ gui_prepare(&params.argc, params.argv);
TIME_MSG("GUI prepared");
#endif
@@ -290,7 +294,7 @@ main
* (needed for :! to * work). mch_check_win() will also handle the -d or
* -dev argument.
*/
- stdout_isatty = (mch_check_win(argc, argv) != FAIL);
+ params.stdout_isatty = (mch_check_win(params.argc, params.argv) != FAIL);
TIME_MSG("window checked");
/*
@@ -300,8 +304,7 @@ main
init_yank(); /* init yank buffers */
- /* Init the argument list to empty. */
- alist_init(&global_alist);
+ alist_init(&global_alist); /* Init the argument list to empty. */
/*
* Set the default values for the options.
@@ -321,763 +324,28 @@ main
#ifdef FEAT_CLIENTSERVER
/*
* Do the client-server stuff, unless "--servername ''" was used.
+ * This may exit Vim if the command was sent to the server.
*/
- if (params.serverName_arg == NULL || *params.serverName_arg != NUL)
- {
-# ifdef WIN32
- /* Initialise the client/server messaging infrastructure. */
- serverInitMessaging();
-# endif
-
- /*
- * When a command server argument was found, execute it. This may
- * exit Vim when it was successful. Otherwise it's executed further
- * on. Remember the encoding used here in "serverStrEnc".
- */
- if (params.serverArg)
- {
- cmdsrv_main(&argc, argv, params.serverName_arg, &serverStr);
-# ifdef FEAT_MBYTE
- serverStrEnc = vim_strsave(p_enc);
-# endif
- }
-
- /* If we're still running, get the name to register ourselves.
- * On Win32 can register right now, for X11 need to setup the
- * clipboard first, it's further down. */
- servername = serverMakeName(params.serverName_arg, argv[0]);
-# ifdef WIN32
- if (servername != NULL)
- {
- serverSetName(servername);
- vim_free(servername);
- }
-# endif
- }
+ exec_on_server(&params);
#endif
/*
- * Check for: [r][e][g][vi|vim|view][diff][ex[im]]
- * If the executable name starts with "r" we disable shell commands.
- * If the next character is "e" we run in Easy mode.
- * If the next character is "g" we run the GUI version.
- * If the next characters are "view" we start in readonly mode.
- * If the next characters are "diff" or "vimdiff" we start in diff mode.
- * If the next characters are "ex" we start in Ex mode. If it's followed
- * by "im" use improved Ex mode.
+ * Figure out the way to work from the command name argv[0].
+ * "vimdiff" starts diff mode, "rvim" sets "restricted", etc.
*/
- initstr = gettail((char_u *)argv[0]);
-
-#ifdef MACOS_X_UNIX
- /* An issue has been seen when launching Vim in such a way that
- * $PWD/$ARGV[0] or $ARGV[0] is not the absolute path to the
- * executable or a symbolic link of it. Until this issue is resolved
- * we prohibit the GUI from being used.
- */
- if (STRCMP(initstr, argv[0]) == 0)
- disallow_gui = TRUE;
-#endif
-
-#ifdef FEAT_EVAL
- set_vim_var_string(VV_PROGNAME, initstr, -1);
-#endif
-
- /* TODO: On MacOS X default to gui if argv[0] ends in:
- * /vim.app/Contents/MacOS/Vim */
-
- if (TOLOWER_ASC(initstr[0]) == 'r')
- {
- restricted = TRUE;
- ++initstr;
- }
-
- /* Avoid using evim mode for "editor". */
- if (TOLOWER_ASC(initstr[0]) == 'e'
- && (TOLOWER_ASC(initstr[1]) == 'v'
- || TOLOWER_ASC(initstr[1]) == 'g'))
- {
-#ifdef FEAT_GUI
- gui.starting = TRUE;
-#endif
- params.evim_mode = TRUE;
- ++initstr;
- }
-
- if (TOLOWER_ASC(initstr[0]) == 'g' || initstr[0] == 'k')
- {
- main_start_gui();
-#ifdef FEAT_GUI
- ++initstr;
-#endif
- }
-
- if (STRNICMP(initstr, "view", 4) == 0)
- {
- readonlymode = TRUE;
- curbuf->b_p_ro = TRUE;
- p_uc = 10000; /* don't update very often */
- initstr += 4;
- }
- else if (STRNICMP(initstr, "vim", 3) == 0)
- initstr += 3;
-
- /* Catch "[r][g]vimdiff" and "[r][g]viewdiff". */
- if (STRICMP(initstr, "diff") == 0)
- {
-#ifdef FEAT_DIFF
- diff_mode = TRUE;
-#else
- mch_errmsg(_("This Vim was not compiled with the diff feature."));
- mch_errmsg("\n");
- mch_exit(2);
-#endif
- }
-
- if (STRNICMP(initstr, "ex", 2) == 0)
- {
- if (STRNICMP(initstr + 2, "im", 2) == 0)
- exmode_active = EXMODE_VIM;
- else
- exmode_active = EXMODE_NORMAL;
- change_compatible(TRUE); /* set 'compatible' */
- }
-
- initstr = gettail((char_u *)argv[0]);
- ++argv;
- --argc;
+ parse_command_name(&params);
/*
- * Process the command line arguments.
+ * Process the command line arguments. File names are put in the global
+ * argument list "global_alist".
*/
- argv_idx = 1; /* active option letter is argv[0][argv_idx] */
- while (argc > 0)
- {
- /*
- * "+" or "+{number}" or "+/{pat}" or "+{command}" argument.
- */
- if (argv[0][0] == '+' && !had_minmin)
- {
- if (n_commands >= MAX_ARG_CMDS)
- mainerr(ME_EXTRA_CMD, NULL);
- argv_idx = -1; /* skip to next argument */
- if (argv[0][1] == NUL)
- commands[n_commands++] = (char_u *)"$";
- else
- commands[n_commands++] = (char_u *)&(argv[0][1]);
- }
-
- /*
- * Optional argument.
- */
- else if (argv[0][0] == '-' && !had_minmin)
- {
- want_argument = FALSE;
- c = argv[0][argv_idx++];
-#ifdef VMS
- /*
- * VMS only uses upper case command lines. Interpret "-X" as "-x"
- * and "-/X" as "-X".
- */
- if (c == '/')
- {
- c = argv[0][argv_idx++];
- c = TOUPPER_ASC(c);
- }
- else
- c = TOLOWER_ASC(c);
-#endif
- switch (c)
- {
- case NUL: /* "vim -" read from stdin */
- /* "ex -" silent mode */
- if (exmode_active)
- silent_mode = TRUE;
- else
- {
- if (edit_type != EDIT_NONE)
- mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]);
- edit_type = EDIT_STDIN;
- read_cmd_fd = 2; /* read from stderr instead of stdin */
- }
- argv_idx = -1; /* skip to next argument */
- break;
-
- case '-': /* "--" don't take any more options */
- /* "--help" give help message */
- /* "--version" give version message */
- /* "--literal" take files literally */
- /* "--nofork" don't fork */
- /* "--noplugin[s]" skip plugins */
- /* "--cmd <cmd>" execute cmd before vimrc */
- if (STRICMP(argv[0] + argv_idx, "help") == 0)
- usage();
- else if (STRICMP(argv[0] + argv_idx, "version") == 0)
- {
- Columns = 80; /* need to init Columns */
- info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
- list_version();
- msg_putchar('\n');
- msg_didout = FALSE;
- mch_exit(0);
- }
- else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0)
- {
-#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
- literal = TRUE;
-#endif
- }
- else if (STRNICMP(argv[0] + argv_idx, "nofork", 6) == 0)
- {
-#ifdef FEAT_GUI
- gui.dofork = FALSE; /* don't fork() when starting GUI */
-#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;
- argv_idx += 3;
- }
-#ifdef FEAT_CLIENTSERVER
- else if (STRNICMP(argv[0] + argv_idx, "serverlist", 10) == 0)
- ; /* already processed -- no arg */
- else if (STRNICMP(argv[0] + argv_idx, "servername", 10) == 0
- || STRNICMP(argv[0] + argv_idx, "serversend", 10) == 0)
- {
- /* already processed -- snatch the following arg */
- if (argc > 1)
- {
- --argc;
- ++argv;
- }
- }
-#endif
-#ifdef FEAT_GUI_GTK
- else if (STRNICMP(argv[0] + argv_idx, "socketid", 8) == 0)
- {
- /* already processed -- snatch the following arg */
- if (argc > 1)
- {
- --argc;
- ++argv;
- }
- }
- else if (STRNICMP(argv[0] + argv_idx, "echo-wid", 8) == 0)
- {
- /* already processed, skip */
- }
-#endif
- else
- {
- if (argv[0][argv_idx])
- mainerr(ME_UNKNOWN_OPTION, (char_u *)argv[0]);
- had_minmin = TRUE;
- }
- if (!want_argument)
- argv_idx = -1; /* skip to next argument */
- break;
-
- case 'A': /* "-A" start in Arabic mode */
-#ifdef FEAT_ARABIC
- set_option_value((char_u *)"arabic", 1L, NULL, 0);
-#else
- mch_errmsg(_(e_noarabic));
- mch_exit(2);
-#endif
- break;
-
- case 'b': /* "-b" binary mode */
- bin_mode = TRUE; /* postpone to after reading .exrc files */
- break;
-
- case 'C': /* "-C" Compatible */
- change_compatible(TRUE);
- break;
-
- case 'e': /* "-e" Ex mode */
- exmode_active = EXMODE_NORMAL;
- break;
-
- case 'E': /* "-E" Improved Ex mode */
- exmode_active = EXMODE_VIM;
- break;
-
- case 'f': /* "-f" GUI: run in foreground. Amiga: open
- window directly, not with newcli */
-#ifdef FEAT_GUI
- gui.dofork = FALSE; /* don't fork() when starting GUI */
-#endif
- break;
-
- case 'g': /* "-g" start GUI */
- main_start_gui();
- break;
-
- case 'F': /* "-F" start in Farsi mode: rl + fkmap set */
-#ifdef FEAT_FKMAP
- curwin->w_p_rl = p_fkmap = TRUE;
-#else
- mch_errmsg(_(e_nofarsi));
- mch_exit(2);
-#endif
- break;
-
- case 'h': /* "-h" give help message */
-#ifdef FEAT_GUI_GNOME
- /* Tell usage() to exit for "gvim". */
- gui.starting = FALSE;
-#endif
- usage();
- break;
-
- case 'H': /* "-H" start in Hebrew mode: rl + hkmap set */
-#ifdef FEAT_RIGHTLEFT
- curwin->w_p_rl = p_hkmap = TRUE;
-#else
- mch_errmsg(_(e_nohebrew));
- mch_exit(2);
-#endif
- break;
-
- case 'l': /* "-l" lisp mode, 'lisp' and 'showmatch' on */
-#ifdef FEAT_LISP
- set_option_value((char_u *)"lisp", 1L, NULL, 0);
- p_sm = TRUE;
-#endif
- break;
-
-#ifdef TARGET_API_MAC_OSX
- /* For some reason on MacOS X, an argument like:
- -psn_0_10223617 is passed in when invoke from Finder
- or with the 'open' command */
- case 'p':
- argv_idx = -1; /* bypass full -psn */
- main_start_gui();
- break;
-#endif
- case 'M': /* "-M" no changes or writing of files */
- reset_modifiable();
- /* FALLTHROUGH */
-
- case 'm': /* "-m" no writing of files */
- p_write = FALSE;
- break;
-
- case 'y': /* "-y" easy mode */
-#ifdef FEAT_GUI
- gui.starting = TRUE; /* start GUI a bit later */
-#endif
- params.evim_mode = TRUE;
- break;
-
- case 'N': /* "-N" Nocompatible */
- change_compatible(FALSE);
- break;
-
- case 'n': /* "-n" no swap file */
- no_swap_file = TRUE;
- break;
-
- case 'o': /* "-o[N]" open N horizontal split windows */
-#ifdef FEAT_WINDOWS
- /* default is 0: open window for each file */
- window_count = get_number_arg((char_u *)argv[0], &argv_idx, 0);
- vert_windows = FALSE;
-#endif
- break;
-
- case 'O': /* "-O[N]" open N vertical split windows */
-#if defined(FEAT_VERTSPLIT) && defined(FEAT_WINDOWS)
- /* default is 0: open window for each file */
- window_count = get_number_arg((char_u *)argv[0], &argv_idx, 0);
- vert_windows = TRUE;
-#endif
- break;
-
-#ifdef FEAT_QUICKFIX
- case 'q': /* "-q" QuickFix mode */
- if (edit_type != EDIT_NONE)
- mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]);
- edit_type = EDIT_QF;
- if (argv[0][argv_idx]) /* "-q{errorfile}" */
- {
- use_ef = (char_u *)argv[0] + argv_idx;
- argv_idx = -1;
- }
- else if (argc > 1) /* "-q {errorfile}" */
- want_argument = TRUE;
- break;
-#endif
-
- 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 */
- recoverymode = 1;
- break;
-
- case 's':
- if (exmode_active) /* "-s" silent (batch) 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 (edit_type != EDIT_NONE)
- mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]);
- edit_type = EDIT_TAG;
- if (argv[0][argv_idx]) /* "-t{tag}" */
- {
- tagname = (char_u *)argv[0] + argv_idx;
- argv_idx = -1;
- }
- else /* "-t {tag}" */
- want_argument = TRUE;
- break;
-
-#ifdef FEAT_EVAL
- case 'D': /* "-D" Debugging */
- use_debug_break_level = 9999;
- break;
-#endif
-#ifdef FEAT_DIFF
- case 'd': /* "-d" 'diff' */
-# ifdef AMIGA
- /* check for "-dev {device}" */
- if (argv[0][argv_idx] == 'e' && argv[0][argv_idx + 1] == 'v')
- want_argument = TRUE;
- else
-# endif
- diff_mode = TRUE;
- break;
-#endif
- case 'V': /* "-V{N}" Verbose level */
- /* default is 10: a little bit verbose */
- p_verbose = get_number_arg((char_u *)argv[0], &argv_idx, 10);
- if (argv[0][argv_idx] != NUL)
- {
- set_option_value((char_u *)"verbosefile", 0L,
- (char_u *)argv[0] + argv_idx, 0);
- argv_idx = STRLEN(argv[0]);
- }
- break;
-
- case 'v': /* "-v" Vi-mode (as if called "vi") */
- exmode_active = 0;
-#ifdef FEAT_GUI
- gui.starting = FALSE; /* don't start GUI */
-#endif
- break;
-
- case 'w': /* "-w{number}" set window height */
- /* "-w {scriptout}" write to script */
- if (vim_isdigit(((char_u *)argv[0])[argv_idx]))
- {
- i = get_number_arg((char_u *)argv[0], &argv_idx, 10);
- set_option_value((char_u *)"window", (long)i, NULL, 0);
- break;
- }
- want_argument = TRUE;
- break;
-
-#ifdef FEAT_CRYPT
- case 'x': /* "-x" encrypted reading/writing of files */
- ask_for_key = TRUE;
- break;
-#endif
-
- case 'X': /* "-X" don't connect to X server */
-#if (defined(UNIX) || defined(VMS)) && defined(FEAT_X11)
- x_no_connect = TRUE;
-#endif
- break;
-
- case 'Z': /* "-Z" restricted mode */
- restricted = TRUE;
- break;
-
- case 'c': /* "-c{command}" or "-c {command}" execute
- command */
- if (argv[0][argv_idx] != NUL)
- {
- if (n_commands >= MAX_ARG_CMDS)
- mainerr(ME_EXTRA_CMD, NULL);
- commands[n_commands++] = (char_u *)argv[0] + argv_idx;
- argv_idx = -1;
- break;
- }
- /*FALLTHROUGH*/
- case 'S': /* "-S {file}" execute Vim script */
- case 'i': /* "-i {viminfo}" use for viminfo */
-#ifndef FEAT_DIFF
- case 'd': /* "-d {device}" device (for Amiga) */
-#endif
- case 'T': /* "-T {terminal}" terminal name */
- case 'u': /* "-u {vimrc}" vim inits file */
- case 'U': /* "-U {gvimrc}" gvim inits file */
- case 'W': /* "-W {scriptout}" overwrite */
-#ifdef FEAT_GUI_W32
- case 'P': /* "-P {parent title}" MDI parent */
-#endif
- want_argument = TRUE;
- break;
-
- default:
- mainerr(ME_UNKNOWN_OPTION, (char_u *)argv[0]);
- }
-
- /*
- * Handle options with argument.
- */
- if (want_argument)
- {
- /*
- * Check for garbage immediately after the option letter.
- */
- if (argv[0][argv_idx] != NUL)
- mainerr(ME_GARBAGE, (char_u *)argv[0]);
-
- --argc;
- if (argc < 1 && c != 'S')
- mainerr_arg_missing((char_u *)argv[0]);
- ++argv;
- argv_idx = -1;
-
- switch (c)
- {
- case 'c': /* "-c {command}" execute command */
- case 'S': /* "-S {file}" execute Vim script */
- if (n_commands >= MAX_ARG_CMDS)
- mainerr(ME_EXTRA_CMD, NULL);
- if (c == 'S')
- {
- char *a;
-
- 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. */
- a = SESSION_FILE;
- ++argc;
- --argv;
- }
- else
- a = argv[0];
- p = alloc((unsigned)(STRLEN(a) + 4));
- if (p == NULL)
- mch_exit(2);
- sprintf((char *)p, "so %s", a);
- cmds_tofree[n_commands] = TRUE;
- commands[n_commands++] = p;
- }
- else
- commands[n_commands++] = (char_u *)argv[0];
- break;
-
- case '-': /* "--cmd {command}" execute command */
- if (n_pre_commands >= MAX_ARG_CMDS)
- mainerr(ME_EXTRA_CMD, NULL);
- pre_commands[n_pre_commands++] = (char_u *)argv[0];
- break;
-
- /* case 'd': -d {device} is handled in mch_check_win() for the
- * Amiga */
-
-#ifdef FEAT_QUICKFIX
- case 'q': /* "-q {errorfile}" QuickFix mode */
- use_ef = (char_u *)argv[0];
- break;
-#endif
-
- case 'i': /* "-i {viminfo}" use for viminfo */
- use_viminfo = (char_u *)argv[0];
- break;
-
- case 's': /* "-s {scriptin}" read from script file */
- if (scriptin[0] != NULL)
- {
-scripterror:
- mch_errmsg(_("Attempt to open script file again: \""));
- mch_errmsg(argv[-1]);
- mch_errmsg(" ");
- mch_errmsg(argv[0]);
- mch_errmsg("\"\n");
- mch_exit(2);
- }
- if ((scriptin[0] = mch_fopen(argv[0], READBIN)) == NULL)
- {
- mch_errmsg(_("Cannot open for reading: \""));
- mch_errmsg(argv[0]);
- mch_errmsg("\"\n");
- mch_exit(2);
- }
- if (save_typebuf() == FAIL)
- mch_exit(2); /* out of memory */
- break;
-
- case 't': /* "-t {tag}" */
- tagname = (char_u *)argv[0];
- break;
-
- case 'T': /* "-T {terminal}" terminal name */
- /*
- * The -T term option is always available and when
- * HAVE_TERMLIB is supported it overrides the environment
- * variable TERM.
- */
-#ifdef FEAT_GUI
- if (term_is_gui((char_u *)argv[0]))
- gui.starting = TRUE; /* start GUI a bit later */
- else
-#endif
- term = (char_u *)argv[0];
- break;
-
- case 'u': /* "-u {vimrc}" vim inits file */
- params.use_vimrc = (char_u *)argv[0];
- break;
-
- case 'U': /* "-U {gvimrc}" gvim inits file */
-#ifdef FEAT_GUI
- use_gvimrc = (char_u *)argv[0];
-#endif
- break;
-
- case 'w': /* "-w {nr}" 'window' value */
- /* "-w {scriptout}" append to script file */
- if (vim_isdigit(*((char_u *)argv[0])))
- {
- argv_idx = 0;
- i = get_number_arg((char_u *)argv[0], &argv_idx, 10);
- set_option_value((char_u *)"window", (long)i, NULL, 0);
- argv_idx = -1;
- break;
- }
- /*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: \""));
- mch_errmsg(argv[0]);
- mch_errmsg("\"\n");
- mch_exit(2);
- }
- break;
-
-#ifdef FEAT_GUI_W32
- case 'P': /* "-P {parent title}" MDI parent */
- gui_mch_set_parent(argv[0]);
- break;
-#endif
- }
- }
- }
-
- /*
- * File name argument.
- */
- else
- {
- argv_idx = -1; /* skip to next argument */
-
- /* Check for only one type of editing. */
- if (edit_type != EDIT_NONE && edit_type != EDIT_FILE)
- mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]);
- edit_type = EDIT_FILE;
-
-#ifdef MSWIN
- /* Remember if the argument was a full path before changing
- * slashes to backslashes. */
- if (argv[0][0] != NUL && argv[0][1] == ':' && argv[0][2] == '\\')
- full_path = TRUE;
-#endif
-
- /* Add the file to the global argument list. */
- if (ga_grow(&global_alist.al_ga, 1) == FAIL
- || (p = vim_strsave((char_u *)argv[0])) == NULL)
- mch_exit(2);
-#ifdef FEAT_DIFF
- if (diff_mode && mch_isdir(p) && GARGCOUNT > 0
- && !mch_isdir(alist_name(&GARGLIST[0])))
- {
- char_u *r;
-
- r = concat_fnames(p, gettail(alist_name(&GARGLIST[0])), TRUE);
- if (r != NULL)
- {
- vim_free(p);
- p = r;
- }
- }
-#endif
-#if defined(__CYGWIN32__) && !defined(WIN32)
- /*
- * If vim is invoked by non-Cygwin tools, convert away any
- * DOS paths, so things like .swp files are created correctly.
- * Look for evidence of non-Cygwin paths before we bother.
- * This is only for when using the Unix files.
- */
- if (strpbrk(p, "\\:") != NULL)
- {
- char posix_path[PATH_MAX];
-
- cygwin_conv_to_posix_path(p, posix_path);
- vim_free(p);
- p = vim_strsave(posix_path);
- if (p == NULL)
- mch_exit(2);
- }
-#endif
- alist_add(&global_alist, p,
-#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
- literal ? 2 : 0 /* add buffer number after expanding */
-#else
- 2 /* add buffer number now and use curbuf */
-#endif
- );
-
-#if defined(FEAT_MBYTE) && defined(WIN32)
- {
- extern void used_file_arg(char *, int, int);
-
- /* Remember this argument has been added to the argument list.
- * Needed when 'encoding' is changed. */
- used_file_arg(argv[0], literal, full_path);
- }
-#endif
- }
-
- /*
- * If there are no more letters after the current "-", go to next
- * argument. argv_idx is set to -1 when the current argument is to be
- * skipped.
- */
- if (argv_idx <= 0 || argv[0][argv_idx] == NUL)
- {
- --argc;
- ++argv;
- argv_idx = 1;
- }
- }
+ command_line_scan(&params);
TIME_MSG("parsing arguments");
/*
* On some systems, when we compile with the GUI, we always use it. On Mac
- * there is no terminal version, and on Windows we can't figure out how to
- * fork one off with :gui.
+ * there is no terminal version, and on Windows we can't fork one off with
+ * :gui.
*/
#ifdef ALWAYS_USE_GUI
gui.starting = TRUE;
@@ -1102,7 +370,7 @@ scripterror:
/* "-b" argument used. Check before expanding file names, because for
* Win32 this makes us edit a shortcut file itself, instead of the file it
* links to. */
- if (bin_mode)
+ if (params.bin_mode)
{
set_options_bin(curbuf->b_p_bin, 1, 0);
curbuf->b_p_bin = 1; /* binary file I/O */
@@ -1114,7 +382,7 @@ scripterror:
/*
* Expand wildcards in file names.
*/
- if (!literal)
+ if (!params.literal)
{
/* Temporarily add '(' and ')' to 'isfname'. These are valid
* filename characters but are excluded from 'isfname' to make
@@ -1138,7 +406,7 @@ scripterror:
#endif
#ifdef MSWIN
- if (GARGCOUNT == 1 && full_path)
+ if (GARGCOUNT == 1 && params.full_path)
{
/*