comparison src/main.c @ 440:eb531146be0e v7.0114

updated for version 7.0114
author vimboss
date Sat, 23 Jul 2005 22:25:46 +0000
parents 1ec6b77beee0
children 43bf0bcf2110
comparison
equal deleted inserted replaced
439:8d2b705a5a51 440:eb531146be0e
27 # include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() */ 27 # include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() */
28 # endif 28 # endif
29 # include <limits.h> 29 # include <limits.h>
30 #endif 30 #endif
31 31
32 /* Struct for various parameters passed between main() and other functions. */
33 typedef struct
34 {
35 int serverArg; /* TRUE when argument for a server */
36 char_u *serverName_arg; /* cmdline arg for server name */
37 int evim_mode; /* started as "evim" */
38 char_u *use_vimrc; /* vimrc from -u option */
39 } mparm_T;
40
32 #if defined(UNIX) || defined(VMS) 41 #if defined(UNIX) || defined(VMS)
33 static int file_owned __ARGS((char *fname)); 42 static int file_owned __ARGS((char *fname));
34 #endif 43 #endif
35 static void mainerr __ARGS((int, char_u *)); 44 static void mainerr __ARGS((int, char_u *));
36 static void main_msg __ARGS((char *s)); 45 static void main_msg __ARGS((char *s));
37 static void usage __ARGS((void)); 46 static void usage __ARGS((void));
38 static int get_number_arg __ARGS((char_u *p, int *idx, int def)); 47 static int get_number_arg __ARGS((char_u *p, int *idx, int def));
48 static void early_arg_scan __ARGS((int argc, char **argv, mparm_T *parmp));
49 static void exe_pre_commands __ARGS((char_u **cmds, int cnt));
50 static void source_startup_scripts __ARGS((mparm_T *parmp));
39 static void main_start_gui __ARGS((void)); 51 static void main_start_gui __ARGS((void));
40 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) 52 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
41 static void check_swap_exists_action __ARGS((void)); 53 static void check_swap_exists_action __ARGS((void));
42 #endif 54 #endif
43 #ifdef FEAT_CLIENTSERVER 55 #ifdef FEAT_CLIENTSERVER
47 59
48 60
49 #ifdef STARTUPTIME 61 #ifdef STARTUPTIME
50 static FILE *time_fd = NULL; 62 static FILE *time_fd = NULL;
51 #endif 63 #endif
52
53 #define FEAT_PRECOMMANDS
54 64
55 /* 65 /*
56 * Different types of error messages. 66 * Different types of error messages.
57 */ 67 */
58 static char *(main_errors[]) = 68 static char *(main_errors[]) =
93 { 103 {
94 char_u *initstr; /* init string from environment */ 104 char_u *initstr; /* init string from environment */
95 char_u *term = NULL; /* specified terminal name */ 105 char_u *term = NULL; /* specified terminal name */
96 char_u *fname = NULL; /* file name from command line */ 106 char_u *fname = NULL; /* file name from command line */
97 char_u *tagname = NULL; /* tag from -t option */ 107 char_u *tagname = NULL; /* tag from -t option */
98 char_u *use_vimrc = NULL; /* vimrc from -u option */
99 #ifdef FEAT_QUICKFIX 108 #ifdef FEAT_QUICKFIX
100 char_u *use_ef = NULL; /* 'errorfile' from -q option */ 109 char_u *use_ef = NULL; /* 'errorfile' from -q option */
101 #endif 110 #endif
102 #ifdef FEAT_CRYPT 111 #ifdef FEAT_CRYPT
103 int ask_for_key = FALSE; /* -x argument */ 112 int ask_for_key = FALSE; /* -x argument */
104 #endif 113 #endif
105 int n_commands = 0; /* no. of commands from + or -c */ 114 int n_commands = 0; /* no. of commands from + or -c */
106 char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c option */ 115 char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c option */
107 char_u cmds_tofree[MAX_ARG_CMDS]; /* commands that need free() */ 116 char_u cmds_tofree[MAX_ARG_CMDS]; /* commands that need free() */
108 #ifdef FEAT_PRECOMMANDS 117 int n_pre_commands = 0; /* no. of commands from --cmd */
109 int p_commands = 0; /* no. of commands from --cmd */
110 char_u *pre_commands[MAX_ARG_CMDS]; /* commands from --cmd option */ 118 char_u *pre_commands[MAX_ARG_CMDS]; /* commands from --cmd option */
111 #endif
112 int no_swap_file = FALSE; /* "-n" option used */ 119 int no_swap_file = FALSE; /* "-n" option used */
113 int c; 120 int c;
114 int i; 121 int i;
115 char_u *p = NULL; 122 char_u *p = NULL;
116 int bin_mode = FALSE; /* -b option used */ 123 int bin_mode = FALSE; /* -b option used */
133 #define EDIT_QF 4 /* start in quickfix mode */ 140 #define EDIT_QF 4 /* start in quickfix mode */
134 int edit_type = EDIT_NONE; /* type of editing to do */ 141 int edit_type = EDIT_NONE; /* type of editing to do */
135 #ifdef FEAT_DIFF 142 #ifdef FEAT_DIFF
136 int diff_mode = FALSE; /* start with 'diff' set */ 143 int diff_mode = FALSE; /* start with 'diff' set */
137 #endif 144 #endif
138 int evim_mode = FALSE; /* started as "evim" */
139 int stdout_isatty; /* is stdout a terminal? */ 145 int stdout_isatty; /* is stdout a terminal? */
140 int input_isatty; /* is active input a terminal? */ 146 int input_isatty; /* is active input a terminal? */
141 #ifdef MSWIN 147 #ifdef MSWIN
142 int full_path = FALSE; 148 int full_path = FALSE;
143 #endif 149 #endif
144 #ifdef FEAT_CLIENTSERVER 150 #ifdef FEAT_CLIENTSERVER
145 char_u *serverStr = NULL; /* remote server command */ 151 char_u *serverStr = NULL; /* remote server command */
146 char_u *serverStrEnc = NULL; /* encoding of serverStr */ 152 char_u *serverStrEnc = NULL; /* encoding of serverStr */
147 char_u *serverName_arg = NULL; /* cmdline arg for server name */
148 int serverArg = FALSE; /* TRUE when argument for a server */
149 char_u *servername = NULL; /* allocated name for our server */ 153 char_u *servername = NULL; /* allocated name for our server */
150 #endif 154 #endif
151 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) 155 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
152 int literal = FALSE; /* don't expand file names */ 156 int literal = FALSE; /* don't expand file names */
153 #endif 157 #endif
158 mparm_T params; /* various parameters passed between
159 * main() and other functions. */
154 160
155 /* 161 /*
156 * Do any system-specific initialisations. These can NOT use IObuff or 162 * Do any system-specific initialisations. These can NOT use IObuff or
157 * NameBuff. Thus emsg2() cannot be called! 163 * NameBuff. Thus emsg2() cannot be called!
158 */ 164 */
159 mch_early_init(); 165 mch_early_init();
166
167 vim_memset(&params, 0, sizeof(params));
160 168
161 #ifdef FEAT_TCL 169 #ifdef FEAT_TCL
162 vim_tcl_init(argv[0]); 170 vim_tcl_init(argv[0]);
163 #endif 171 #endif
164 172
196 204
197 /* Init the table of Normal mode commands. */ 205 /* Init the table of Normal mode commands. */
198 init_normal_cmds(); 206 init_normal_cmds();
199 207
200 #if defined(HAVE_DATE_TIME) && defined(VMS) && defined(VAXC) 208 #if defined(HAVE_DATE_TIME) && defined(VMS) && defined(VAXC)
201 make_version(); 209 make_version(); /* Construct the long version string. */
202 #endif 210 #endif
203 211
204 /* 212 /*
205 * Allocate space for the generic buffers (needed for set_init_1() and 213 * Allocate space for the generic buffers (needed for set_init_1() and
206 * EMSG2()). 214 * EMSG2()).
253 261
254 #ifdef FEAT_GUI 262 #ifdef FEAT_GUI
255 gui.dofork = TRUE; /* default is to use fork() */ 263 gui.dofork = TRUE; /* default is to use fork() */
256 #endif 264 #endif
257 265
258 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_CLIENTSERVER) 266 /*
259 /* 267 * Do a first scan of the arguments in "argv[]":
260 * Get the name of the display, before gui_prepare() removes it from 268 * -display
261 * argv[]. Used for the xterm-clipboard display. 269 * --server...
262 * 270 * --socketid
263 * Also find the --server... arguments 271 */
264 */ 272 early_arg_scan(argc, argv, &params);
265 for (i = 1; i < argc; i++)
266 {
267 if (STRCMP(argv[i], "--") == 0)
268 break;
269 # ifdef FEAT_XCLIPBOARD
270 else if (STRICMP(argv[i], "-display") == 0
271 # if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
272 || STRICMP(argv[i], "--display") == 0
273 # endif
274 )
275 {
276 if (i == argc - 1)
277 mainerr_arg_missing((char_u *)argv[i]);
278 xterm_display = argv[++i];
279 }
280 # endif
281 # ifdef FEAT_CLIENTSERVER
282 else if (STRICMP(argv[i], "--servername") == 0)
283 {
284 if (i == argc - 1)
285 mainerr_arg_missing((char_u *)argv[i]);
286 serverName_arg = (char_u *)argv[++i];
287 }
288 else if (STRICMP(argv[i], "--serverlist") == 0
289 || STRICMP(argv[i], "--remote-send") == 0
290 || STRICMP(argv[i], "--remote-expr") == 0
291 || STRICMP(argv[i], "--remote") == 0
292 || STRICMP(argv[i], "--remote-silent") == 0)
293 serverArg = TRUE;
294 else if (STRICMP(argv[i], "--remote-wait") == 0
295 || STRICMP(argv[i], "--remote-wait-silent") == 0)
296 {
297 serverArg = TRUE;
298 #ifdef FEAT_GUI
299 /* don't fork() when starting the GUI to edit the files ourself */
300 gui.dofork = FALSE;
301 #endif
302 }
303 # endif
304 # ifdef FEAT_GUI_GTK
305 else if (STRICMP(argv[i], "--socketid") == 0)
306 {
307 unsigned int socket_id;
308 int count;
309
310 if (i == argc - 1)
311 mainerr_arg_missing((char_u *)argv[i]);
312 if (STRNICMP(argv[i+1], "0x", 2) == 0)
313 count = sscanf(&(argv[i + 1][2]), "%x", &socket_id);
314 else
315 count = sscanf(argv[i+1], "%u", &socket_id);
316 if (count != 1)
317 mainerr(ME_INVALID_ARG, (char_u *)argv[i]);
318 else
319 gtk_socket_id = socket_id;
320 i++;
321 }
322 else if (STRICMP(argv[i], "--echo-wid") == 0)
323 echo_wid_arg = TRUE;
324 # endif
325 }
326 #endif
327 273
328 #ifdef FEAT_SUN_WORKSHOP 274 #ifdef FEAT_SUN_WORKSHOP
329 findYourself(argv[0]); 275 findYourself(argv[0]);
330 #endif 276 #endif
331 #if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC) 277 #if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC)
374 320
375 #ifdef FEAT_CLIENTSERVER 321 #ifdef FEAT_CLIENTSERVER
376 /* 322 /*
377 * Do the client-server stuff, unless "--servername ''" was used. 323 * Do the client-server stuff, unless "--servername ''" was used.
378 */ 324 */
379 if (serverName_arg == NULL || *serverName_arg != NUL) 325 if (params.serverName_arg == NULL || *params.serverName_arg != NUL)
380 { 326 {
381 # ifdef WIN32 327 # ifdef WIN32
382 /* Initialise the client/server messaging infrastructure. */ 328 /* Initialise the client/server messaging infrastructure. */
383 serverInitMessaging(); 329 serverInitMessaging();
384 # endif 330 # endif
386 /* 332 /*
387 * When a command server argument was found, execute it. This may 333 * When a command server argument was found, execute it. This may
388 * exit Vim when it was successful. Otherwise it's executed further 334 * exit Vim when it was successful. Otherwise it's executed further
389 * on. Remember the encoding used here in "serverStrEnc". 335 * on. Remember the encoding used here in "serverStrEnc".
390 */ 336 */
391 if (serverArg) 337 if (params.serverArg)
392 { 338 {
393 cmdsrv_main(&argc, argv, serverName_arg, &serverStr); 339 cmdsrv_main(&argc, argv, params.serverName_arg, &serverStr);
394 # ifdef FEAT_MBYTE 340 # ifdef FEAT_MBYTE
395 serverStrEnc = vim_strsave(p_enc); 341 serverStrEnc = vim_strsave(p_enc);
396 # endif 342 # endif
397 } 343 }
398 344
399 /* If we're still running, get the name to register ourselves. 345 /* If we're still running, get the name to register ourselves.
400 * On Win32 can register right now, for X11 need to setup the 346 * On Win32 can register right now, for X11 need to setup the
401 * clipboard first, it's further down. */ 347 * clipboard first, it's further down. */
402 servername = serverMakeName(serverName_arg, argv[0]); 348 servername = serverMakeName(params.serverName_arg, argv[0]);
403 # ifdef WIN32 349 # ifdef WIN32
404 if (servername != NULL) 350 if (servername != NULL)
405 { 351 {
406 serverSetName(servername); 352 serverSetName(servername);
407 vim_free(servername); 353 vim_free(servername);
451 || TOLOWER_ASC(initstr[1]) == 'g')) 397 || TOLOWER_ASC(initstr[1]) == 'g'))
452 { 398 {
453 #ifdef FEAT_GUI 399 #ifdef FEAT_GUI
454 gui.starting = TRUE; 400 gui.starting = TRUE;
455 #endif 401 #endif
456 evim_mode = TRUE; 402 params.evim_mode = TRUE;
457 ++initstr; 403 ++initstr;
458 } 404 }
459 405
460 if (TOLOWER_ASC(initstr[0]) == 'g' || initstr[0] == 'k') 406 if (TOLOWER_ASC(initstr[0]) == 'g' || initstr[0] == 'k')
461 { 407 {
586 gui.dofork = FALSE; /* don't fork() when starting GUI */ 532 gui.dofork = FALSE; /* don't fork() when starting GUI */
587 #endif 533 #endif
588 } 534 }
589 else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) 535 else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0)
590 p_lpl = FALSE; 536 p_lpl = FALSE;
591 #ifdef FEAT_PRECOMMANDS
592 else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0) 537 else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0)
593 { 538 {
594 want_argument = TRUE; 539 want_argument = TRUE;
595 argv_idx += 3; 540 argv_idx += 3;
596 } 541 }
597 #endif
598 #ifdef FEAT_CLIENTSERVER 542 #ifdef FEAT_CLIENTSERVER
599 else if (STRNICMP(argv[0] + argv_idx, "serverlist", 10) == 0) 543 else if (STRNICMP(argv[0] + argv_idx, "serverlist", 10) == 0)
600 ; /* already processed -- no arg */ 544 ; /* already processed -- no arg */
601 else if (STRNICMP(argv[0] + argv_idx, "servername", 10) == 0 545 else if (STRNICMP(argv[0] + argv_idx, "servername", 10) == 0
602 || STRNICMP(argv[0] + argv_idx, "serversend", 10) == 0) 546 || STRNICMP(argv[0] + argv_idx, "serversend", 10) == 0)
722 666
723 case 'y': /* "-y" easy mode */ 667 case 'y': /* "-y" easy mode */
724 #ifdef FEAT_GUI 668 #ifdef FEAT_GUI
725 gui.starting = TRUE; /* start GUI a bit later */ 669 gui.starting = TRUE; /* start GUI a bit later */
726 #endif 670 #endif
727 evim_mode = TRUE; 671 params.evim_mode = TRUE;
728 break; 672 break;
729 673
730 case 'N': /* "-N" Nocompatible */ 674 case 'N': /* "-N" Nocompatible */
731 change_compatible(FALSE); 675 change_compatible(FALSE);
732 break; 676 break;
938 } 882 }
939 else 883 else
940 commands[n_commands++] = (char_u *)argv[0]; 884 commands[n_commands++] = (char_u *)argv[0];
941 break; 885 break;
942 886
943 #ifdef FEAT_PRECOMMANDS
944 case '-': /* "--cmd {command}" execute command */ 887 case '-': /* "--cmd {command}" execute command */
945 if (p_commands >= MAX_ARG_CMDS) 888 if (n_pre_commands >= MAX_ARG_CMDS)
946 mainerr(ME_EXTRA_CMD, NULL); 889 mainerr(ME_EXTRA_CMD, NULL);
947 pre_commands[p_commands++] = (char_u *)argv[0]; 890 pre_commands[n_pre_commands++] = (char_u *)argv[0];
948 break; 891 break;
949 #endif
950 892
951 /* case 'd': -d {device} is handled in mch_check_win() for the 893 /* case 'd': -d {device} is handled in mch_check_win() for the
952 * Amiga */ 894 * Amiga */
953 895
954 #ifdef FEAT_QUICKFIX 896 #ifdef FEAT_QUICKFIX
1000 #endif 942 #endif
1001 term = (char_u *)argv[0]; 943 term = (char_u *)argv[0];
1002 break; 944 break;
1003 945
1004 case 'u': /* "-u {vimrc}" vim inits file */ 946 case 'u': /* "-u {vimrc}" vim inits file */
1005 use_vimrc = (char_u *)argv[0]; 947 params.use_vimrc = (char_u *)argv[0];
1006 break; 948 break;
1007 949
1008 case 'U': /* "-U {gvimrc}" gvim inits file */ 950 case 'U': /* "-U {gvimrc}" gvim inits file */
1009 #ifdef FEAT_GUI 951 #ifdef FEAT_GUI
1010 use_gvimrc = (char_u *)argv[0]; 952 use_gvimrc = (char_u *)argv[0];
1149 { 1091 {
1150 gui.starting = FALSE; 1092 gui.starting = FALSE;
1151 1093
1152 /* When running "evim" or "gvim -y" we need the menus, exit if we 1094 /* When running "evim" or "gvim -y" we need the menus, exit if we
1153 * don't have them. */ 1095 * don't have them. */
1154 if (evim_mode) 1096 if (params.evim_mode)
1155 mch_exit(1); 1097 mch_exit(1);
1156 } 1098 }
1157 # endif 1099 # endif
1158 #endif 1100 #endif
1159 1101
1363 1305
1364 init_mappings(); /* set up initial mappings */ 1306 init_mappings(); /* set up initial mappings */
1365 1307
1366 init_highlight(TRUE, FALSE); /* set the default highlight groups */ 1308 init_highlight(TRUE, FALSE); /* set the default highlight groups */
1367 TIME_MSG("init highlight"); 1309 TIME_MSG("init highlight");
1368 #ifdef CURSOR_SHAPE
1369 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
1370 #endif
1371 #ifdef FEAT_MOUSESHAPE
1372 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
1373 #endif
1374 #ifdef FEAT_PRINTER
1375 parse_list_options(p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS);
1376 #endif
1377 1310
1378 #ifdef FEAT_EVAL 1311 #ifdef FEAT_EVAL
1379 /* Set the break level after the terminal is initialized. */ 1312 /* Set the break level after the terminal is initialized. */
1380 debug_break_level = use_debug_break_level; 1313 debug_break_level = use_debug_break_level;
1381 #endif 1314 #endif
1382 1315
1383 #ifdef FEAT_PRECOMMANDS 1316 /* Execute --cmd arguments. */
1384 if (p_commands > 0) 1317 exe_pre_commands(pre_commands, n_pre_commands);
1385 { 1318
1386 curwin->w_cursor.lnum = 0; /* just in case.. */ 1319 /* Source startup scripts. */
1387 sourcing_name = (char_u *)_("pre-vimrc command line"); 1320 source_startup_scripts(&params);
1388 # ifdef FEAT_EVAL
1389 current_SID = SID_CMDARG;
1390 # endif
1391 for (i = 0; i < p_commands; ++i)
1392 do_cmdline_cmd(pre_commands[i]);
1393 sourcing_name = NULL;
1394 # ifdef FEAT_EVAL
1395 current_SID = 0;
1396 # endif
1397 }
1398 #endif
1399
1400 /*
1401 * For "evim" source evim.vim first of all, so that the user can overrule
1402 * any things he doesn't like.
1403 */
1404 if (evim_mode)
1405 {
1406 (void)do_source((char_u *)EVIM_FILE, FALSE, FALSE);
1407 TIME_MSG("source evim file");
1408 }
1409
1410 /*
1411 * If -u option given, use only the initializations from that file and
1412 * nothing else.
1413 */
1414 if (use_vimrc != NULL)
1415 {
1416 if (STRCMP(use_vimrc, "NONE") == 0 || STRCMP(use_vimrc, "NORC") == 0)
1417 {
1418 #ifdef FEAT_GUI
1419 if (use_gvimrc == NULL) /* don't load gvimrc either */
1420 use_gvimrc = use_vimrc;
1421 #endif
1422 if (use_vimrc[2] == 'N')
1423 p_lpl = FALSE; /* don't load plugins either */
1424 }
1425 else
1426 {
1427 if (do_source(use_vimrc, FALSE, FALSE) != OK)
1428 EMSG2(_("E282: Cannot read from \"%s\""), use_vimrc);
1429 }
1430 }
1431 else if (!silent_mode)
1432 {
1433 #ifdef AMIGA
1434 struct Process *proc = (struct Process *)FindTask(0L);
1435 APTR save_winptr = proc->pr_WindowPtr;
1436
1437 /* Avoid a requester here for a volume that doesn't exist. */
1438 proc->pr_WindowPtr = (APTR)-1L;
1439 #endif
1440
1441 /*
1442 * Get system wide defaults, if the file name is defined.
1443 */
1444 #ifdef SYS_VIMRC_FILE
1445 (void)do_source((char_u *)SYS_VIMRC_FILE, FALSE, FALSE);
1446 #endif
1447
1448 /*
1449 * Try to read initialization commands from the following places:
1450 * - environment variable VIMINIT
1451 * - user vimrc file (s:.vimrc for Amiga, ~/.vimrc otherwise)
1452 * - second user vimrc file ($VIM/.vimrc for Dos)
1453 * - environment variable EXINIT
1454 * - user exrc file (s:.exrc for Amiga, ~/.exrc otherwise)
1455 * - second user exrc file ($VIM/.exrc for Dos)
1456 * The first that exists is used, the rest is ignored.
1457 */
1458 if (process_env((char_u *)"VIMINIT", TRUE) != OK)
1459 {
1460 if (do_source((char_u *)USR_VIMRC_FILE, TRUE, TRUE) == FAIL
1461 #ifdef USR_VIMRC_FILE2
1462 && do_source((char_u *)USR_VIMRC_FILE2, TRUE, TRUE) == FAIL
1463 #endif
1464 #ifdef USR_VIMRC_FILE3
1465 && do_source((char_u *)USR_VIMRC_FILE3, TRUE, TRUE) == FAIL
1466 #endif
1467 && process_env((char_u *)"EXINIT", FALSE) == FAIL
1468 && do_source((char_u *)USR_EXRC_FILE, FALSE, FALSE) == FAIL)
1469 {
1470 #ifdef USR_EXRC_FILE2
1471 (void)do_source((char_u *)USR_EXRC_FILE2, FALSE, FALSE);
1472 #endif
1473 }
1474 }
1475
1476 /*
1477 * Read initialization commands from ".vimrc" or ".exrc" in current
1478 * directory. This is only done if the 'exrc' option is set.
1479 * Because of security reasons we disallow shell and write commands
1480 * now, except for unix if the file is owned by the user or 'secure'
1481 * option has been reset in environment of global ".exrc" or ".vimrc".
1482 * Only do this if VIMRC_FILE is not the same as USR_VIMRC_FILE or
1483 * SYS_VIMRC_FILE.
1484 */
1485 if (p_exrc)
1486 {
1487 #if defined(UNIX) || defined(VMS)
1488 /* If ".vimrc" file is not owned by user, set 'secure' mode. */
1489 if (!file_owned(VIMRC_FILE))
1490 #endif
1491 secure = p_secure;
1492
1493 i = FAIL;
1494 if (fullpathcmp((char_u *)USR_VIMRC_FILE,
1495 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
1496 #ifdef USR_VIMRC_FILE2
1497 && fullpathcmp((char_u *)USR_VIMRC_FILE2,
1498 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
1499 #endif
1500 #ifdef USR_VIMRC_FILE3
1501 && fullpathcmp((char_u *)USR_VIMRC_FILE3,
1502 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
1503 #endif
1504 #ifdef SYS_VIMRC_FILE
1505 && fullpathcmp((char_u *)SYS_VIMRC_FILE,
1506 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
1507 #endif
1508 )
1509 i = do_source((char_u *)VIMRC_FILE, TRUE, TRUE);
1510
1511 if (i == FAIL)
1512 {
1513 #if defined(UNIX) || defined(VMS)
1514 /* if ".exrc" is not owned by user set 'secure' mode */
1515 if (!file_owned(EXRC_FILE))
1516 secure = p_secure;
1517 else
1518 secure = 0;
1519 #endif
1520 if ( fullpathcmp((char_u *)USR_EXRC_FILE,
1521 (char_u *)EXRC_FILE, FALSE) != FPC_SAME
1522 #ifdef USR_EXRC_FILE2
1523 && fullpathcmp((char_u *)USR_EXRC_FILE2,
1524 (char_u *)EXRC_FILE, FALSE) != FPC_SAME
1525 #endif
1526 )
1527 (void)do_source((char_u *)EXRC_FILE, FALSE, FALSE);
1528 }
1529 }
1530 if (secure == 2)
1531 need_wait_return = TRUE;
1532 secure = 0;
1533 #ifdef AMIGA
1534 proc->pr_WindowPtr = save_winptr;
1535 #endif
1536 }
1537 TIME_MSG("sourcing vimrc file(s)");
1538 1321
1539 #ifdef FEAT_EVAL 1322 #ifdef FEAT_EVAL
1540 /* 1323 /*
1541 * Read all the plugin files. 1324 * Read all the plugin files.
1542 * Only when compiled with +eval, since most plugins need it. 1325 * Only when compiled with +eval, since most plugins need it.
1597 gui_start(); /* will set full_screen to TRUE */ 1380 gui_start(); /* will set full_screen to TRUE */
1598 TIME_MSG("starting GUI"); 1381 TIME_MSG("starting GUI");
1599 1382
1600 /* When running "evim" or "gvim -y" we need the menus, exit if we 1383 /* When running "evim" or "gvim -y" we need the menus, exit if we
1601 * don't have them. */ 1384 * don't have them. */
1602 if (!gui.in_use && evim_mode) 1385 if (!gui.in_use && params.evim_mode)
1603 mch_exit(1); 1386 mch_exit(1);
1604 } 1387 }
1605 #endif 1388 #endif
1606 1389
1607 #ifdef SPAWNO /* special MSDOS swapping library */ 1390 #ifdef SPAWNO /* special MSDOS swapping library */
1688 */ 1471 */
1689 if (X_DISPLAY != NULL && servername != NULL && ( 1472 if (X_DISPLAY != NULL && servername != NULL && (
1690 # ifdef FEAT_GUI 1473 # ifdef FEAT_GUI
1691 gui.in_use || 1474 gui.in_use ||
1692 # endif 1475 # endif
1693 serverName_arg != NULL)) 1476 params.serverName_arg != NULL))
1694 { 1477 {
1695 (void)serverRegisterName(X_DISPLAY, servername); 1478 (void)serverRegisterName(X_DISPLAY, servername);
1696 vim_free(servername); 1479 vim_free(servername);
1697 TIME_MSG("register server name"); 1480 TIME_MSG("register server name");
1698 } 1481 }
1776 #ifdef FEAT_MOUSE 1559 #ifdef FEAT_MOUSE
1777 setmouse(); /* may start using the mouse */ 1560 setmouse(); /* may start using the mouse */
1778 #endif 1561 #endif
1779 if (scroll_region) 1562 if (scroll_region)
1780 scroll_region_reset(); /* In case Rows changed */ 1563 scroll_region_reset(); /* In case Rows changed */
1781 1564 scroll_start(); /* may scroll the screen to the right position */
1782 scroll_start();
1783 1565
1784 /* 1566 /*
1785 * Don't clear the screen when starting in Ex mode, unless using the GUI. 1567 * Don't clear the screen when starting in Ex mode, unless using the GUI.
1786 */ 1568 */
1787 if (exmode_active 1569 if (exmode_active
2434 def = atoi((char *)&(p[*idx])); 2216 def = atoi((char *)&(p[*idx]));
2435 while (vim_isdigit(p[*idx])) 2217 while (vim_isdigit(p[*idx]))
2436 *idx = *idx + 1; 2218 *idx = *idx + 1;
2437 } 2219 }
2438 return def; 2220 return def;
2221 }
2222
2223 /*
2224 * Get the name of the display, before gui_prepare() removes it from
2225 * argv[]. Used for the xterm-clipboard display.
2226 *
2227 * Also find the --server... arguments and --socketid
2228 */
2229 /*ARGSUSED*/
2230 static void
2231 early_arg_scan(argc, argv, parmp)
2232 int argc;
2233 char **argv;
2234 mparm_T *parmp;
2235 {
2236 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_CLIENTSERVER)
2237 int i;
2238
2239 for (i = 1; i < argc; i++)
2240 {
2241 if (STRCMP(argv[i], "--") == 0)
2242 break;
2243 # ifdef FEAT_XCLIPBOARD
2244 else if (STRICMP(argv[i], "-display") == 0
2245 # if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
2246 || STRICMP(argv[i], "--display") == 0
2247 # endif
2248 )
2249 {
2250 if (i == argc - 1)
2251 mainerr_arg_missing((char_u *)argv[i]);
2252 xterm_display = argv[++i];
2253 }
2254 # endif
2255 # ifdef FEAT_CLIENTSERVER
2256 else if (STRICMP(argv[i], "--servername") == 0)
2257 {
2258 if (i == argc - 1)
2259 mainerr_arg_missing((char_u *)argv[i]);
2260 parmp->serverName_arg = (char_u *)argv[++i];
2261 }
2262 else if (STRICMP(argv[i], "--serverlist") == 0
2263 || STRICMP(argv[i], "--remote-send") == 0
2264 || STRICMP(argv[i], "--remote-expr") == 0
2265 || STRICMP(argv[i], "--remote") == 0
2266 || STRICMP(argv[i], "--remote-silent") == 0)
2267 parmp->serverArg = TRUE;
2268 else if (STRICMP(argv[i], "--remote-wait") == 0
2269 || STRICMP(argv[i], "--remote-wait-silent") == 0)
2270 {
2271 parmp->serverArg = TRUE;
2272 #ifdef FEAT_GUI
2273 /* don't fork() when starting the GUI to edit the files ourself */
2274 gui.dofork = FALSE;
2275 #endif
2276 }
2277 # endif
2278 # ifdef FEAT_GUI_GTK
2279 else if (STRICMP(argv[i], "--socketid") == 0)
2280 {
2281 unsigned int socket_id;
2282 int count;
2283
2284 if (i == argc - 1)
2285 mainerr_arg_missing((char_u *)argv[i]);
2286 if (STRNICMP(argv[i+1], "0x", 2) == 0)
2287 count = sscanf(&(argv[i + 1][2]), "%x", &socket_id);
2288 else
2289 count = sscanf(argv[i+1], "%u", &socket_id);
2290 if (count != 1)
2291 mainerr(ME_INVALID_ARG, (char_u *)argv[i]);
2292 else
2293 gtk_socket_id = socket_id;
2294 i++;
2295 }
2296 else if (STRICMP(argv[i], "--echo-wid") == 0)
2297 echo_wid_arg = TRUE;
2298 # endif
2299 }
2300 #endif
2301 }
2302
2303 /*
2304 * Execute the commands from --cmd arguments "cmds[cnt]".
2305 */
2306 static void
2307 exe_pre_commands(cmds, cnt)
2308 char_u **cmds;
2309 int cnt;
2310 {
2311 int i;
2312
2313 if (cnt > 0)
2314 {
2315 curwin->w_cursor.lnum = 0; /* just in case.. */
2316 sourcing_name = (char_u *)_("pre-vimrc command line");
2317 # ifdef FEAT_EVAL
2318 current_SID = SID_CMDARG;
2319 # endif
2320 for (i = 0; i < cnt; ++i)
2321 do_cmdline_cmd(cmds[i]);
2322 sourcing_name = NULL;
2323 # ifdef FEAT_EVAL
2324 current_SID = 0;
2325 # endif
2326 TIME_MSG("--cmd commands");
2327 }
2328 }
2329
2330 /*
2331 * Source startup scripts.
2332 */
2333 static void
2334 source_startup_scripts(parmp)
2335 mparm_T *parmp;
2336 {
2337 int i;
2338
2339 /*
2340 * For "evim" source evim.vim first of all, so that the user can overrule
2341 * any things he doesn't like.
2342 */
2343 if (parmp->evim_mode)
2344 {
2345 (void)do_source((char_u *)EVIM_FILE, FALSE, FALSE);
2346 TIME_MSG("source evim file");
2347 }
2348
2349 /*
2350 * If -u option given, use only the initializations from that file and
2351 * nothing else.
2352 */
2353 if (parmp->use_vimrc != NULL)
2354 {
2355 if (STRCMP(parmp->use_vimrc, "NONE") == 0 || STRCMP(parmp->use_vimrc, "NORC") == 0)
2356 {
2357 #ifdef FEAT_GUI
2358 if (use_gvimrc == NULL) /* don't load gvimrc either */
2359 use_gvimrc = parmp->use_vimrc;
2360 #endif
2361 if (parmp->use_vimrc[2] == 'N')
2362 p_lpl = FALSE; /* don't load plugins either */
2363 }
2364 else
2365 {
2366 if (do_source(parmp->use_vimrc, FALSE, FALSE) != OK)
2367 EMSG2(_("E282: Cannot read from \"%s\""), parmp->use_vimrc);
2368 }
2369 }
2370 else if (!silent_mode)
2371 {
2372 #ifdef AMIGA
2373 struct Process *proc = (struct Process *)FindTask(0L);
2374 APTR save_winptr = proc->pr_WindowPtr;
2375
2376 /* Avoid a requester here for a volume that doesn't exist. */
2377 proc->pr_WindowPtr = (APTR)-1L;
2378 #endif
2379
2380 /*
2381 * Get system wide defaults, if the file name is defined.
2382 */
2383 #ifdef SYS_VIMRC_FILE
2384 (void)do_source((char_u *)SYS_VIMRC_FILE, FALSE, FALSE);
2385 #endif
2386
2387 /*
2388 * Try to read initialization commands from the following places:
2389 * - environment variable VIMINIT
2390 * - user vimrc file (s:.vimrc for Amiga, ~/.vimrc otherwise)
2391 * - second user vimrc file ($VIM/.vimrc for Dos)
2392 * - environment variable EXINIT
2393 * - user exrc file (s:.exrc for Amiga, ~/.exrc otherwise)
2394 * - second user exrc file ($VIM/.exrc for Dos)
2395 * The first that exists is used, the rest is ignored.
2396 */
2397 if (process_env((char_u *)"VIMINIT", TRUE) != OK)
2398 {
2399 if (do_source((char_u *)USR_VIMRC_FILE, TRUE, TRUE) == FAIL
2400 #ifdef USR_VIMRC_FILE2
2401 && do_source((char_u *)USR_VIMRC_FILE2, TRUE, TRUE) == FAIL
2402 #endif
2403 #ifdef USR_VIMRC_FILE3
2404 && do_source((char_u *)USR_VIMRC_FILE3, TRUE, TRUE) == FAIL
2405 #endif
2406 && process_env((char_u *)"EXINIT", FALSE) == FAIL
2407 && do_source((char_u *)USR_EXRC_FILE, FALSE, FALSE) == FAIL)
2408 {
2409 #ifdef USR_EXRC_FILE2
2410 (void)do_source((char_u *)USR_EXRC_FILE2, FALSE, FALSE);
2411 #endif
2412 }
2413 }
2414
2415 /*
2416 * Read initialization commands from ".vimrc" or ".exrc" in current
2417 * directory. This is only done if the 'exrc' option is set.
2418 * Because of security reasons we disallow shell and write commands
2419 * now, except for unix if the file is owned by the user or 'secure'
2420 * option has been reset in environment of global ".exrc" or ".vimrc".
2421 * Only do this if VIMRC_FILE is not the same as USR_VIMRC_FILE or
2422 * SYS_VIMRC_FILE.
2423 */
2424 if (p_exrc)
2425 {
2426 #if defined(UNIX) || defined(VMS)
2427 /* If ".vimrc" file is not owned by user, set 'secure' mode. */
2428 if (!file_owned(VIMRC_FILE))
2429 #endif
2430 secure = p_secure;
2431
2432 i = FAIL;
2433 if (fullpathcmp((char_u *)USR_VIMRC_FILE,
2434 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
2435 #ifdef USR_VIMRC_FILE2
2436 && fullpathcmp((char_u *)USR_VIMRC_FILE2,
2437 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
2438 #endif
2439 #ifdef USR_VIMRC_FILE3
2440 && fullpathcmp((char_u *)USR_VIMRC_FILE3,
2441 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
2442 #endif
2443 #ifdef SYS_VIMRC_FILE
2444 && fullpathcmp((char_u *)SYS_VIMRC_FILE,
2445 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
2446 #endif
2447 )
2448 i = do_source((char_u *)VIMRC_FILE, TRUE, TRUE);
2449
2450 if (i == FAIL)
2451 {
2452 #if defined(UNIX) || defined(VMS)
2453 /* if ".exrc" is not owned by user set 'secure' mode */
2454 if (!file_owned(EXRC_FILE))
2455 secure = p_secure;
2456 else
2457 secure = 0;
2458 #endif
2459 if ( fullpathcmp((char_u *)USR_EXRC_FILE,
2460 (char_u *)EXRC_FILE, FALSE) != FPC_SAME
2461 #ifdef USR_EXRC_FILE2
2462 && fullpathcmp((char_u *)USR_EXRC_FILE2,
2463 (char_u *)EXRC_FILE, FALSE) != FPC_SAME
2464 #endif
2465 )
2466 (void)do_source((char_u *)EXRC_FILE, FALSE, FALSE);
2467 }
2468 }
2469 if (secure == 2)
2470 need_wait_return = TRUE;
2471 secure = 0;
2472 #ifdef AMIGA
2473 proc->pr_WindowPtr = save_winptr;
2474 #endif
2475 }
2476 TIME_MSG("sourcing vimrc file(s)");
2439 } 2477 }
2440 2478
2441 /* 2479 /*
2442 * Setup to start using the GUI. Exit with an error when not available. 2480 * Setup to start using the GUI. Exit with an error when not available.
2443 */ 2481 */
2654 main_msg(_("--noplugin\t\tDon't load plugin scripts")); 2692 main_msg(_("--noplugin\t\tDon't load plugin scripts"));
2655 main_msg(_("-o[N]\t\tOpen N windows (default: one for each file)")); 2693 main_msg(_("-o[N]\t\tOpen N windows (default: one for each file)"));
2656 main_msg(_("-O[N]\t\tLike -o but split vertically")); 2694 main_msg(_("-O[N]\t\tLike -o but split vertically"));
2657 main_msg(_("+\t\t\tStart at end of file")); 2695 main_msg(_("+\t\t\tStart at end of file"));
2658 main_msg(_("+<lnum>\t\tStart at line <lnum>")); 2696 main_msg(_("+<lnum>\t\tStart at line <lnum>"));
2659 #ifdef FEAT_PRECOMMANDS
2660 main_msg(_("--cmd <command>\tExecute <command> before loading any vimrc file")); 2697 main_msg(_("--cmd <command>\tExecute <command> before loading any vimrc file"));
2661 #endif
2662 main_msg(_("-c <command>\t\tExecute <command> after loading the first file")); 2698 main_msg(_("-c <command>\t\tExecute <command> after loading the first file"));
2663 main_msg(_("-S <session>\t\tSource file <session> after loading the first file")); 2699 main_msg(_("-S <session>\t\tSource file <session> after loading the first file"));
2664 main_msg(_("-s <scriptin>\tRead Normal mode commands from file <scriptin>")); 2700 main_msg(_("-s <scriptin>\tRead Normal mode commands from file <scriptin>"));
2665 main_msg(_("-w <scriptout>\tAppend all typed commands to file <scriptout>")); 2701 main_msg(_("-w <scriptout>\tAppend all typed commands to file <scriptout>"));
2666 main_msg(_("-W <scriptout>\tWrite all typed commands to file <scriptout>")); 2702 main_msg(_("-W <scriptout>\tWrite all typed commands to file <scriptout>"));