blob: 351225c2ed174e0533036b518fa7438240e87717 [file] [log] [blame]
Bram Moolenaarb4210b32004-06-13 14:51:16 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10#if defined(MSDOS) || defined(WIN32) || defined(_WIN64)
11# include <io.h> /* for close() and dup() */
12#endif
13
14#define EXTERN
15#include "vim.h"
16
17#ifdef SPAWNO
18# include <spawno.h> /* special MSDOS swapping library */
19#endif
20
21#ifdef HAVE_FCNTL_H
22# include <fcntl.h>
23#endif
24
25#ifdef __CYGWIN__
26# ifndef WIN32
27# include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() */
28# endif
29# include <limits.h>
30#endif
31
32#if defined(UNIX) || defined(VMS)
33static int file_owned __ARGS((char *fname));
34#endif
35static void mainerr __ARGS((int, char_u *));
36static void main_msg __ARGS((char *s));
37static void usage __ARGS((void));
38static int get_number_arg __ARGS((char_u *p, int *idx, int def));
39static void main_start_gui __ARGS((void));
40#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
41static void check_swap_exists_action __ARGS((void));
42#endif
43#ifdef FEAT_CLIENTSERVER
44static void cmdsrv_main __ARGS((int *argc, char **argv, char_u *serverName_arg, char_u **serverStr));
45static char_u *serverMakeName __ARGS((char_u *arg, char *cmd));
46#endif
47
48
49#ifdef STARTUPTIME
50static FILE *time_fd = NULL;
51#endif
52
53#define FEAT_PRECOMMANDS
54
55/*
56 * Different types of error messages.
57 */
58static char *(main_errors[]) =
59{
60 N_("Unknown option"),
61#define ME_UNKNOWN_OPTION 0
62 N_("Too many edit arguments"),
63#define ME_TOO_MANY_ARGS 1
64 N_("Argument missing after"),
65#define ME_ARG_MISSING 2
66 N_("Garbage after option"),
67#define ME_GARBAGE 3
68 N_("Too many \"+command\", \"-c command\" or \"--cmd command\" arguments"),
69#define ME_EXTRA_CMD 4
70 N_("Invalid argument for"),
71#define ME_INVALID_ARG 5
72};
73
74/* Maximum number of commands from + or -c options */
75#define MAX_ARG_CMDS 10
76
77#ifndef PROTO /* don't want a prototype for main() */
78 int
79# ifdef VIMDLL
80_export
81# endif
82# ifdef FEAT_GUI_MSWIN
83# ifdef __BORLANDC__
84_cdecl
85# endif
86VimMain
87# else
88main
89# endif
90(argc, argv)
91 int argc;
92 char **argv;
93{
94 char_u *initstr; /* init string from environment */
95 char_u *term = NULL; /* specified terminal name */
96 char_u *fname = NULL; /* file name from command line */
97 char_u *tagname = NULL; /* tag from -t option */
98 char_u *use_vimrc = NULL; /* vimrc from -u option */
99#ifdef FEAT_QUICKFIX
100 char_u *use_ef = NULL; /* 'errorfile' from -q option */
101#endif
102#ifdef FEAT_CRYPT
103 int ask_for_key = FALSE; /* -x argument */
104#endif
105 int n_commands = 0; /* no. of commands from + or -c */
106 char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c option */
107#ifdef FEAT_PRECOMMANDS
108 int p_commands = 0; /* no. of commands from --cmd */
109 char_u *pre_commands[MAX_ARG_CMDS]; /* commands from --cmd option */
110#endif
111 int no_swap_file = FALSE; /* "-n" option used */
112 int c;
113 int i;
114 char_u *p = NULL;
115 int bin_mode = FALSE; /* -b option used */
116#ifdef FEAT_EVAL
117 int use_debug_break_level = -1;
118#endif
119#ifdef FEAT_WINDOWS
120 int window_count = -1; /* number of windows to use */
121 int arg_idx; /* index in argument list */
122 int vert_windows = MAYBE; /* "-O" used instead of "-o" */
123#endif
124 int had_minmin = FALSE; /* found "--" option */
125 int argv_idx; /* index in argv[n][] */
126 int want_full_screen = TRUE;
127 int want_argument; /* option with argument */
128#define EDIT_NONE 0 /* no edit type yet */
129#define EDIT_FILE 1 /* file name argument[s] given, use argument list */
130#define EDIT_STDIN 2 /* read file from stdin */
131#define EDIT_TAG 3 /* tag name argument given, use tagname */
132#define EDIT_QF 4 /* start in quickfix mode */
133 int edit_type = EDIT_NONE; /* type of editing to do */
134#ifdef FEAT_DIFF
135 int diff_mode = FALSE; /* start with 'diff' set */
136#endif
137 int evim_mode = FALSE; /* started as "evim" */
138 int stdout_isatty; /* is stdout a terminal? */
139 int input_isatty; /* is active input a terminal? */
140#ifdef MSWIN
141 int full_path = FALSE;
142#endif
143#ifdef FEAT_CLIENTSERVER
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000144 char_u *serverStr = NULL; /* remote server command */
145 char_u *serverStrEnc = NULL; /* encoding of serverStr */
Bram Moolenaarb4210b32004-06-13 14:51:16 +0000146 char_u *serverName_arg = NULL; /* cmdline arg for server name */
147 int serverArg = FALSE; /* TRUE when argument for a server */
148 char_u *servername = NULL; /* allocated name for our server */
149#endif
150#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
151 int literal = FALSE; /* don't expand file names */
152#endif
153
Bram Moolenaarb4210b32004-06-13 14:51:16 +0000154 /*
155 * Do any system-specific initialisations. These can NOT use IObuff or
156 * NameBuff. Thus emsg2() cannot be called!
157 */
158 mch_early_init();
159
160#ifdef FEAT_TCL
161 vim_tcl_init(argv[0]);
162#endif
163
164#ifdef MEM_PROFILE
165 atexit(vim_mem_profile_dump);
166#endif
167
168#ifdef STARTUPTIME
169 time_fd = fopen(STARTUPTIME, "a");
170 TIME_MSG("--- VIM STARTING ---");
171#endif
172
173#ifdef __EMX__
174 _wildcard(&argc, &argv);
175#endif
176
177#ifdef FEAT_MBYTE
178 (void)mb_init(); /* init mb_bytelen_tab[] to ones */
179#endif
Bram Moolenaardcaf10e2005-01-21 11:55:25 +0000180#ifdef FEAT_EVAL
181 eval_init(); /* init global variables */
182#endif
Bram Moolenaarb4210b32004-06-13 14:51:16 +0000183
184#ifdef __QNXNTO__
185 qnx_init(); /* PhAttach() for clipboard, (and gui) */
186#endif
187
188#ifdef MAC_OS_CLASSIC
189 /* Macintosh needs this before any memory is allocated. */
190 gui_prepare(&argc, argv); /* Prepare for possibly starting GUI sometime */
191 TIME_MSG("GUI prepared");
192#endif
193
194 /* Init the table of Normal mode commands. */
195 init_normal_cmds();
196
197#if defined(HAVE_DATE_TIME) && defined(VMS) && defined(VAXC)
198 make_version();
199#endif
200
201 /*
202 * Allocate space for the generic buffers (needed for set_init_1() and
203 * EMSG2()).
204 */
205 if ((IObuff = alloc(IOSIZE)) == NULL
206 || (NameBuff = alloc(MAXPATHL)) == NULL)
207 mch_exit(0);
208
209 TIME_MSG("Allocated generic buffers");
210
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000211#ifdef NBDEBUG
212 /* Wait a moment for debugging NetBeans. Must be after allocating
213 * NameBuff. */
214 nbdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL");
215 nbdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20);
216#endif
217
Bram Moolenaarb4210b32004-06-13 14:51:16 +0000218#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
219 /*
220 * Setup to use the current locale (for ctype() and many other things).
221 * NOTE: Translated messages with encodings other than latin1 will not
222 * work until set_init_1() has been called!
223 */
224 setlocale(LC_ALL, "");
225
226# ifdef FEAT_GETTEXT
227 {
228 int mustfree = FALSE;
229
230# ifdef DYNAMIC_GETTEXT
231 /* Initialize the gettext library */
232 dyn_libintl_init(NULL);
233# endif
234 /* expand_env() doesn't work yet, because chartab[] is not initialized
235 * yet, call vim_getenv() directly */
236 p = vim_getenv((char_u *)"VIMRUNTIME", &mustfree);
237 if (p != NULL && *p != NUL)
238 {
239 STRCPY(NameBuff, p);
240 STRCAT(NameBuff, "/lang");
241 bindtextdomain(VIMPACKAGE, (char *)NameBuff);
242 }
243 if (mustfree)
244 vim_free(p);
245 textdomain(VIMPACKAGE);
246 }
247# endif
248 TIME_MSG("locale set");
249#endif
250
251#ifdef FEAT_GUI
252 gui.dofork = TRUE; /* default is to use fork() */
253#endif
254
255#if defined(FEAT_XCLIPBOARD) || defined(FEAT_CLIENTSERVER)
256 /*
257 * Get the name of the display, before gui_prepare() removes it from
258 * argv[]. Used for the xterm-clipboard display.
259 *
260 * Also find the --server... arguments
261 */
262 for (i = 1; i < argc; i++)
263 {
264 if (STRCMP(argv[i], "--") == 0)
265 break;
266# ifdef FEAT_XCLIPBOARD
267 else if (STRICMP(argv[i], "-display") == 0
Bram Moolenaar843ee412004-06-30 16:16:41 +0000268# if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
Bram Moolenaarb4210b32004-06-13 14:51:16 +0000269 || STRICMP(argv[i], "--display") == 0
270# endif
271 )
272 {
273 if (i == argc - 1)
274 mainerr_arg_missing((char_u *)argv[i]);
275 xterm_display = argv[++i];
276 }
277# endif
278# ifdef FEAT_CLIENTSERVER
279 else if (STRICMP(argv[i], "--servername") == 0)
280 {
281 if (i == argc - 1)
282 mainerr_arg_missing((char_u *)argv[i]);
283 serverName_arg = (char_u *)argv[++i];
284 }
285 else if (STRICMP(argv[i], "--serverlist") == 0
286 || STRICMP(argv[i], "--remote-send") == 0
287 || STRICMP(argv[i], "--remote-expr") == 0
288 || STRICMP(argv[i], "--remote") == 0
289 || STRICMP(argv[i], "--remote-silent") == 0)
290 serverArg = TRUE;
291 else if (STRICMP(argv[i], "--remote-wait") == 0
292 || STRICMP(argv[i], "--remote-wait-silent") == 0)
293 {
294 serverArg = TRUE;
295#ifdef FEAT_GUI
296 /* don't fork() when starting the GUI to edit the files ourself */
297 gui.dofork = FALSE;
298#endif
299 }
300# endif
301# ifdef FEAT_GUI_GTK
302 else if (STRICMP(argv[i], "--socketid") == 0)
303 {
304 unsigned int socket_id;
305 int count;
306
307 if (i == argc - 1)
308 mainerr_arg_missing((char_u *)argv[i]);
309 if (STRNICMP(argv[i+1], "0x", 2) == 0)
310 count = sscanf(&(argv[i + 1][2]), "%x", &socket_id);
311 else
312 count = sscanf(argv[i+1], "%u", &socket_id);
313 if (count != 1)
314 mainerr(ME_INVALID_ARG, (char_u *)argv[i]);
315 else
316 gtk_socket_id = socket_id;
317 i++;
318 }
319 else if (STRICMP(argv[i], "--echo-wid") == 0)
320 echo_wid_arg = TRUE;
321# endif
322 }
323#endif
324
325#ifdef FEAT_SUN_WORKSHOP
326 findYourself(argv[0]);
327#endif
328#if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC)
329 gui_prepare(&argc, argv); /* Prepare for possibly starting GUI sometime */
330 TIME_MSG("GUI prepared");
331#endif
332
333#ifdef FEAT_CLIPBOARD
334 clip_init(FALSE); /* Initialise clipboard stuff */
335 TIME_MSG("clipboard setup");
336#endif
337
338 /*
339 * Check if we have an interactive window.
340 * On the Amiga: If there is no window, we open one with a newcli command
341 * (needed for :! to * work). mch_check_win() will also handle the -d or
342 * -dev argument.
343 */
344 stdout_isatty = (mch_check_win(argc, argv) != FAIL);
345 TIME_MSG("window checked");
346
347 /*
348 * Allocate the first window and buffer. Can't do much without it.
349 */
350 win_alloc_first();
351
352 init_yank(); /* init yank buffers */
353
354 /* Init the argument list to empty. */
355 alist_init(&global_alist);
356
357 /*
358 * Set the default values for the options.
359 * NOTE: Non-latin1 translated messages are working only after this,
360 * because this is where "has_mbyte" will be set, which is used by
361 * msg_outtrans_len_attr().
362 * First find out the home directory, needed to expand "~" in options.
363 */
364 init_homedir(); /* find real value of $HOME */
365 set_init_1();
366 TIME_MSG("inits 1");
367
368#ifdef FEAT_EVAL
369 set_lang_var(); /* set v:lang and v:ctype */
370#endif
371
372#ifdef FEAT_CLIENTSERVER
373 /*
374 * Do the client-server stuff, unless "--servername ''" was used.
375 */
376 if (serverName_arg == NULL || *serverName_arg != NUL)
377 {
378# ifdef WIN32
379 /* Initialise the client/server messaging infrastructure. */
380 serverInitMessaging();
381# endif
382
383 /*
384 * When a command server argument was found, execute it. This may
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000385 * exit Vim when it was successful. Otherwise it's executed further
386 * on. Remember the encoding used here in "serverStrEnc".
Bram Moolenaarb4210b32004-06-13 14:51:16 +0000387 */
388 if (serverArg)
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000389 {
Bram Moolenaarb4210b32004-06-13 14:51:16 +0000390 cmdsrv_main(&argc, argv, serverName_arg, &serverStr);
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000391# ifdef FEAT_MBYTE
392 serverStrEnc = vim_strsave(p_enc);
393# endif
394 }
Bram Moolenaarb4210b32004-06-13 14:51:16 +0000395
396 /* If we're still running, get the name to register ourselves.
397 * On Win32 can register right now, for X11 need to setup the
398 * clipboard first, it's further down. */
399 servername = serverMakeName(serverName_arg, argv[0]);
400# ifdef WIN32
401 if (servername != NULL)
402 {
403 serverSetName(servername);
404 vim_free(servername);
405 }
406# endif
407 }
408#endif
409
410 /*
411 * Check for: [r][e][g][vi|vim|view][diff][ex[im]]
412 * If the executable name starts with "r" we disable shell commands.
413 * If the next character is "e" we run in Easy mode.
414 * If the next character is "g" we run the GUI version.
415 * If the next characters are "view" we start in readonly mode.
416 * If the next characters are "diff" or "vimdiff" we start in diff mode.
417 * If the next characters are "ex" we start in Ex mode. If it's followed
418 * by "im" use improved Ex mode.
419 */
420 initstr = gettail((char_u *)argv[0]);
421
422#ifdef MACOS_X_UNIX
423 /* An issue has been seen when launching Vim in such a way that
424 * $PWD/$ARGV[0] or $ARGV[0] is not the absolute path to the
425 * executable or a symbolic link of it. Until this issue is resolved
426 * we prohibit the GUI from being used.
427 */
428 if (STRCMP(initstr, argv[0]) == 0)
429 disallow_gui = TRUE;
430#endif
431
432#ifdef FEAT_EVAL
433 set_vim_var_string(VV_PROGNAME, initstr, -1);
434#endif
435
436 /* TODO: On MacOS X default to gui if argv[0] ends in:
437 * /vim.app/Contents/MacOS/Vim */
438
439 if (TOLOWER_ASC(initstr[0]) == 'r')
440 {
441 restricted = TRUE;
442 ++initstr;
443 }
444
445 /* Avoid using evim mode for "editor". */
446 if (TOLOWER_ASC(initstr[0]) == 'e'
447 && (TOLOWER_ASC(initstr[1]) == 'v'
448 || TOLOWER_ASC(initstr[1]) == 'g'))
449 {
450#ifdef FEAT_GUI
451 gui.starting = TRUE;
452#endif
453 evim_mode = TRUE;
454 ++initstr;
455 }
456
Bram Moolenaar843ee412004-06-30 16:16:41 +0000457 if (TOLOWER_ASC(initstr[0]) == 'g' || initstr[0] == 'k')
Bram Moolenaarb4210b32004-06-13 14:51:16 +0000458 {
459 main_start_gui();
460#ifdef FEAT_GUI
461 ++initstr;
462#endif
463 }
464
465 if (STRNICMP(initstr, "view", 4) == 0)
466 {
467 readonlymode = TRUE;
468 curbuf->b_p_ro = TRUE;
469 p_uc = 10000; /* don't update very often */
470 initstr += 4;
471 }
472 else if (STRNICMP(initstr, "vim", 3) == 0)
473 initstr += 3;
474
475 /* Catch "[r][g]vimdiff" and "[r][g]viewdiff". */
476 if (STRICMP(initstr, "diff") == 0)
477 {
478#ifdef FEAT_DIFF
479 diff_mode = TRUE;
480#else
481 mch_errmsg(_("This Vim was not compiled with the diff feature."));
482 mch_errmsg("\n");
483 mch_exit(2);
484#endif
485 }
486
487 if (STRNICMP(initstr, "ex", 2) == 0)
488 {
489 if (STRNICMP(initstr + 2, "im", 2) == 0)
490 exmode_active = EXMODE_VIM;
491 else
492 exmode_active = EXMODE_NORMAL;
493 change_compatible(TRUE); /* set 'compatible' */
494 }
495
496 initstr = gettail((char_u *)argv[0]);
497 ++argv;
498 --argc;
499
500 /*
501 * Process the command line arguments.
502 */
503 argv_idx = 1; /* active option letter is argv[0][argv_idx] */
504 while (argc > 0)
505 {
506 /*
507 * "+" or "+{number}" or "+/{pat}" or "+{command}" argument.
508 */
509 if (argv[0][0] == '+' && !had_minmin)
510 {
511 if (n_commands >= MAX_ARG_CMDS)
512 mainerr(ME_EXTRA_CMD, NULL);
513 argv_idx = -1; /* skip to next argument */
514 if (argv[0][1] == NUL)
515 commands[n_commands++] = (char_u *)"$";
516 else
517 commands[n_commands++] = (char_u *)&(argv[0][1]);
518 }
519
520 /*
521 * Optional argument.
522 */
523 else if (argv[0][0] == '-' && !had_minmin)
524 {
525 want_argument = FALSE;
526 c = argv[0][argv_idx++];
527#ifdef VMS
528 /*
529 * VMS only uses upper case command lines. Interpret "-X" as "-x"
530 * and "-/X" as "-X".
531 */
532 if (c == '/')
533 {
534 c = argv[0][argv_idx++];
535 c = TOUPPER_ASC(c);
536 }
537 else
538 c = TOLOWER_ASC(c);
539#endif
540 switch (c)
541 {
542 case NUL: /* "vim -" read from stdin */
543 /* "ex -" silent mode */
544 if (exmode_active)
545 silent_mode = TRUE;
546 else
547 {
548 if (edit_type != EDIT_NONE)
549 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]);
550 edit_type = EDIT_STDIN;
551 read_cmd_fd = 2; /* read from stderr instead of stdin */
552 }
553 argv_idx = -1; /* skip to next argument */
554 break;
555
556 case '-': /* "--" don't take any more options */
557 /* "--help" give help message */
558 /* "--version" give version message */
559 /* "--literal" take files literally */
560 /* "--nofork" don't fork */
561 /* "--noplugin[s]" skip plugins */
562 /* "--cmd <cmd>" execute cmd before vimrc */
563 if (STRICMP(argv[0] + argv_idx, "help") == 0)
564 usage();
565 else if (STRICMP(argv[0] + argv_idx, "version") == 0)
566 {
567 Columns = 80; /* need to init Columns */
568 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
569 list_version();
570 msg_putchar('\n');
571 msg_didout = FALSE;
572 mch_exit(0);
573 }
574 else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0)
575 {
576#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
577 literal = TRUE;
578#endif
579 }
580 else if (STRNICMP(argv[0] + argv_idx, "nofork", 6) == 0)
581 {
582#ifdef FEAT_GUI
583 gui.dofork = FALSE; /* don't fork() when starting GUI */
584#endif
585 }
586 else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0)
587 p_lpl = FALSE;
588#ifdef FEAT_PRECOMMANDS
589 else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0)
590 {
591 want_argument = TRUE;
592 argv_idx += 3;
593 }
594#endif
595#ifdef FEAT_CLIENTSERVER
596 else if (STRNICMP(argv[0] + argv_idx, "serverlist", 10) == 0)
597 ; /* already processed -- no arg */
598 else if (STRNICMP(argv[0] + argv_idx, "servername", 10) == 0
599 || STRNICMP(argv[0] + argv_idx, "serversend", 10) == 0)
600 {
601 /* already processed -- snatch the following arg */
602 if (argc > 1)
603 {
604 --argc;
605 ++argv;
606 }
607 }
608#endif
609#ifdef FEAT_GUI_GTK
610 else if (STRNICMP(argv[0] + argv_idx, "socketid", 8) == 0)
611 {
612 /* already processed -- snatch the following arg */
613 if (argc > 1)
614 {
615 --argc;
616 ++argv;
617 }
618 }
619 else if (STRNICMP(argv[0] + argv_idx, "echo-wid", 8) == 0)
620 {
621 /* already processed, skip */
622 }
623#endif
624 else
625 {
626 if (argv[0][argv_idx])
627 mainerr(ME_UNKNOWN_OPTION, (char_u *)argv[0]);
628 had_minmin = TRUE;
629 }
630 if (!want_argument)
631 argv_idx = -1; /* skip to next argument */
632 break;
633
634 case 'A': /* "-A" start in Arabic mode */
635#ifdef FEAT_ARABIC
636 set_option_value((char_u *)"arabic", 1L, NULL, 0);
637#else
638 mch_errmsg(_(e_noarabic));
639 mch_exit(2);
640#endif
641 break;
642
643 case 'b': /* "-b" binary mode */
644 bin_mode = TRUE; /* postpone to after reading .exrc files */
645 break;
646
647 case 'C': /* "-C" Compatible */
648 change_compatible(TRUE);
649 break;
650
651 case 'e': /* "-e" Ex mode */
652 exmode_active = EXMODE_NORMAL;
653 break;
654
655 case 'E': /* "-E" Improved Ex mode */
656 exmode_active = EXMODE_VIM;
657 break;
658
659 case 'f': /* "-f" GUI: run in foreground. Amiga: open
660 window directly, not with newcli */
661#ifdef FEAT_GUI
662 gui.dofork = FALSE; /* don't fork() when starting GUI */
663#endif
664 break;
665
666 case 'g': /* "-g" start GUI */
667 main_start_gui();
668 break;
669
670 case 'F': /* "-F" start in Farsi mode: rl + fkmap set */
671#ifdef FEAT_FKMAP
672 curwin->w_p_rl = p_fkmap = TRUE;
673#else
674 mch_errmsg(_(e_nofarsi));
675 mch_exit(2);
676#endif
677 break;
678
679 case 'h': /* "-h" give help message */
680#ifdef FEAT_GUI_GNOME
681 /* Tell usage() to exit for "gvim". */
682 gui.starting = FALSE;
683#endif
684 usage();
685 break;
686
687 case 'H': /* "-H" start in Hebrew mode: rl + hkmap set */
688#ifdef FEAT_RIGHTLEFT
689 curwin->w_p_rl = p_hkmap = TRUE;
690#else
691 mch_errmsg(_(e_nohebrew));
692 mch_exit(2);
693#endif
694 break;
695
696 case 'l': /* "-l" lisp mode, 'lisp' and 'showmatch' on */
697#ifdef FEAT_LISP
698 set_option_value((char_u *)"lisp", 1L, NULL, 0);
699 p_sm = TRUE;
700#endif
701 break;
702
703#ifdef TARGET_API_MAC_OSX
704 /* For some reason on MacOS X, an argument like:
705 -psn_0_10223617 is passed in when invoke from Finder
706 or with the 'open' command */
707 case 'p':
708 argv_idx = -1; /* bypass full -psn */
709 main_start_gui();
710 break;
711#endif
712 case 'M': /* "-M" no changes or writing of files */
713 reset_modifiable();
714 /* FALLTRHOUGH */
715
716 case 'm': /* "-m" no writing of files */
717 p_write = FALSE;
718 break;
719
720 case 'y': /* "-y" easy mode */
721#ifdef FEAT_GUI
722 gui.starting = TRUE; /* start GUI a bit later */
723#endif
724 evim_mode = TRUE;
725 break;
726
727 case 'N': /* "-N" Nocompatible */
728 change_compatible(FALSE);
729 break;
730
731 case 'n': /* "-n" no swap file */
732 no_swap_file = TRUE;
733 break;
734
735 case 'o': /* "-o[N]" open N horizontal split windows */
736#ifdef FEAT_WINDOWS
737 /* default is 0: open window for each file */
738 window_count = get_number_arg((char_u *)argv[0], &argv_idx, 0);
739 vert_windows = FALSE;
740#endif
741 break;
742
743 case 'O': /* "-O[N]" open N vertical split windows */
744#if defined(FEAT_VERTSPLIT) && defined(FEAT_WINDOWS)
745 /* default is 0: open window for each file */
746 window_count = get_number_arg((char_u *)argv[0], &argv_idx, 0);
747 vert_windows = TRUE;
748#endif
749 break;
750
751#ifdef FEAT_QUICKFIX
752 case 'q': /* "-q" QuickFix mode */
753 if (edit_type != EDIT_NONE)
754 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]);
755 edit_type = EDIT_QF;
756 if (argv[0][argv_idx]) /* "-q{errorfile}" */
757 {
758 use_ef = (char_u *)argv[0] + argv_idx;
759 argv_idx = -1;
760 }
761 else if (argc > 1) /* "-q {errorfile}" */
762 want_argument = TRUE;
763 break;
764#endif
765
766 case 'R': /* "-R" readonly mode */
767 readonlymode = TRUE;
768 curbuf->b_p_ro = TRUE;
769 p_uc = 10000; /* don't update very often */
770 break;
771
772 case 'r': /* "-r" recovery mode */
773 case 'L': /* "-L" recovery mode */
774 recoverymode = 1;
775 break;
776
777 case 's':
778 if (exmode_active) /* "-s" silent (batch) mode */
779 silent_mode = TRUE;
780 else /* "-s {scriptin}" read from script file */
781 want_argument = TRUE;
782 break;
783
784 case 't': /* "-t {tag}" or "-t{tag}" jump to tag */
785 if (edit_type != EDIT_NONE)
786 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]);
787 edit_type = EDIT_TAG;
788 if (argv[0][argv_idx]) /* "-t{tag}" */
789 {
790 tagname = (char_u *)argv[0] + argv_idx;
791 argv_idx = -1;
792 }
793 else /* "-t {tag}" */
794 want_argument = TRUE;
795 break;
796
797#ifdef FEAT_EVAL
798 case 'D': /* "-D" Debugging */
799 use_debug_break_level = 9999;
800 break;
801#endif
802#ifdef FEAT_DIFF
803 case 'd': /* "-d" 'diff' */
804# ifdef AMIGA
805 /* check for "-dev {device}" */
806 if (argv[0][argv_idx] == 'e' && argv[0][argv_idx + 1] == 'v')
807 want_argument = TRUE;
808 else
809# endif
810 diff_mode = TRUE;
811 break;
812#endif
813 case 'V': /* "-V{N}" Verbose level */
814 /* default is 10: a little bit verbose */
815 p_verbose = get_number_arg((char_u *)argv[0], &argv_idx, 10);
816 break;
817
818 case 'v': /* "-v" Vi-mode (as if called "vi") */
819 exmode_active = 0;
820#ifdef FEAT_GUI
821 gui.starting = FALSE; /* don't start GUI */
822#endif
823 break;
824
825 case 'w': /* "-w{number}" set window height */
826 /* "-w {scriptout}" write to script */
827 if (vim_isdigit(((char_u *)argv[0])[argv_idx]))
828 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +0000829 i = get_number_arg((char_u *)argv[0], &argv_idx, 10);
830 set_option_value((char_u *)"window", (long)i, NULL, 0);
831 break;
Bram Moolenaarb4210b32004-06-13 14:51:16 +0000832 }
833 want_argument = TRUE;
834 break;
835
836#ifdef FEAT_CRYPT
837 case 'x': /* "-x" encrypted reading/writing of files */
838 ask_for_key = TRUE;
839 break;
840#endif
841
842 case 'X': /* "-X" don't connect to X server */
843#if (defined(UNIX) || defined(VMS)) && defined(FEAT_X11)
844 x_no_connect = TRUE;
845#endif
846 break;
847
848 case 'Z': /* "-Z" restricted mode */
849 restricted = TRUE;
850 break;
851
Bram Moolenaar4399ef42005-02-12 14:29:27 +0000852 case 'c': /* "-c{command}" or "-c {command}" execute
853 command */
854 if (argv[0][argv_idx] != NUL)
855 {
856 if (n_commands >= MAX_ARG_CMDS)
857 mainerr(ME_EXTRA_CMD, NULL);
858 commands[n_commands++] = (char_u *)argv[0] + argv_idx;
859 argv_idx = -1;
860 break;
861 }
862 /*FALLTRHOUGH*/
Bram Moolenaarb4210b32004-06-13 14:51:16 +0000863 case 'S': /* "-S {file}" execute Vim script */
864 case 'i': /* "-i {viminfo}" use for viminfo */
865#ifndef FEAT_DIFF
866 case 'd': /* "-d {device}" device (for Amiga) */
867#endif
868 case 'T': /* "-T {terminal}" terminal name */
869 case 'u': /* "-u {vimrc}" vim inits file */
870 case 'U': /* "-U {gvimrc}" gvim inits file */
871 case 'W': /* "-W {scriptout}" overwrite */
872#ifdef FEAT_GUI_W32
873 case 'P': /* "-P {parent title}" MDI parent */
874#endif
875 want_argument = TRUE;
876 break;
877
878 default:
879 mainerr(ME_UNKNOWN_OPTION, (char_u *)argv[0]);
880 }
881
882 /*
883 * Handle options with argument.
884 */
885 if (want_argument)
886 {
887 /*
888 * Check for garbage immediately after the option letter.
889 */
890 if (argv[0][argv_idx] != NUL)
891 mainerr(ME_GARBAGE, (char_u *)argv[0]);
892
893 --argc;
894 if (argc < 1 && c != 'S')
895 mainerr_arg_missing((char_u *)argv[0]);
896 ++argv;
897 argv_idx = -1;
898
899 switch (c)
900 {
901 case 'c': /* "-c {command}" execute command */
902 case 'S': /* "-S {file}" execute Vim script */
903 if (n_commands >= MAX_ARG_CMDS)
904 mainerr(ME_EXTRA_CMD, NULL);
905 if (c == 'S')
906 {
907 char *a;
908
909 if (argc < 1)
910 /* "-S" without argument: use default session file
911 * name. */
912 a = SESSION_FILE;
913 else if (argv[0][0] == '-')
914 {
915 /* "-S" followed by another option: use default
916 * session file name. */
917 a = SESSION_FILE;
918 ++argc;
919 --argv;
920 }
921 else
922 a = argv[0];
923 p = alloc((unsigned)(STRLEN(a) + 4));
924 if (p == NULL)
925 mch_exit(2);
926 sprintf((char *)p, "so %s", a);
927 commands[n_commands++] = p;
928 }
929 else
930 commands[n_commands++] = (char_u *)argv[0];
931 break;
932
933#ifdef FEAT_PRECOMMANDS
934 case '-': /* "--cmd {command}" execute command */
935 if (p_commands >= MAX_ARG_CMDS)
936 mainerr(ME_EXTRA_CMD, NULL);
937 pre_commands[p_commands++] = (char_u *)argv[0];
938 break;
939#endif
940
941 /* case 'd': -d {device} is handled in mch_check_win() for the
942 * Amiga */
943
944#ifdef FEAT_QUICKFIX
945 case 'q': /* "-q {errorfile}" QuickFix mode */
946 use_ef = (char_u *)argv[0];
947 break;
948#endif
949
950 case 'i': /* "-i {viminfo}" use for viminfo */
951 use_viminfo = (char_u *)argv[0];
952 break;
953
954 case 's': /* "-s {scriptin}" read from script file */
955 if (scriptin[0] != NULL)
956 {
957scripterror:
958 mch_errmsg(_("Attempt to open script file again: \""));
959 mch_errmsg(argv[-1]);
960 mch_errmsg(" ");
961 mch_errmsg(argv[0]);
962 mch_errmsg("\"\n");
963 mch_exit(2);
964 }
965 if ((scriptin[0] = mch_fopen(argv[0], READBIN)) == NULL)
966 {
967 mch_errmsg(_("Cannot open for reading: \""));
968 mch_errmsg(argv[0]);
969 mch_errmsg("\"\n");
970 mch_exit(2);
971 }
972 if (save_typebuf() == FAIL)
973 mch_exit(2); /* out of memory */
974 break;
975
976 case 't': /* "-t {tag}" */
977 tagname = (char_u *)argv[0];
978 break;
979
980 case 'T': /* "-T {terminal}" terminal name */
981 /*
982 * The -T term option is always available and when
983 * HAVE_TERMLIB is supported it overrides the environment
984 * variable TERM.
985 */
986#ifdef FEAT_GUI
987 if (term_is_gui((char_u *)argv[0]))
988 gui.starting = TRUE; /* start GUI a bit later */
989 else
990#endif
991 term = (char_u *)argv[0];
992 break;
993
994 case 'u': /* "-u {vimrc}" vim inits file */
995 use_vimrc = (char_u *)argv[0];
996 break;
997
998 case 'U': /* "-U {gvimrc}" gvim inits file */
999#ifdef FEAT_GUI
1000 use_gvimrc = (char_u *)argv[0];
1001#endif
1002 break;
1003
Bram Moolenaar4399ef42005-02-12 14:29:27 +00001004 case 'w': /* "-w {nr}" 'window' value */
1005 /* "-w {scriptout}" append to script file */
1006 if (vim_isdigit(*((char_u *)argv[0])))
1007 {
1008 argv_idx = 0;
1009 i = get_number_arg((char_u *)argv[0], &argv_idx, 10);
1010 set_option_value((char_u *)"window", (long)i, NULL, 0);
1011 argv_idx = -1;
1012 break;
1013 }
1014 /*FALLTRHOUGH*/
Bram Moolenaarb4210b32004-06-13 14:51:16 +00001015 case 'W': /* "-W {scriptout}" overwrite script file */
1016 if (scriptout != NULL)
1017 goto scripterror;
1018 if ((scriptout = mch_fopen(argv[0],
1019 c == 'w' ? APPENDBIN : WRITEBIN)) == NULL)
1020 {
1021 mch_errmsg(_("Cannot open for script output: \""));
1022 mch_errmsg(argv[0]);
1023 mch_errmsg("\"\n");
1024 mch_exit(2);
1025 }
1026 break;
1027
1028#ifdef FEAT_GUI_W32
1029 case 'P': /* "-P {parent title}" MDI parent */
1030 gui_mch_set_parent(argv[0]);
1031 break;
1032#endif
1033 }
1034 }
1035 }
1036
1037 /*
1038 * File name argument.
1039 */
1040 else
1041 {
1042 argv_idx = -1; /* skip to next argument */
1043
1044 /* Check for only one type of editing. */
1045 if (edit_type != EDIT_NONE && edit_type != EDIT_FILE)
1046 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]);
1047 edit_type = EDIT_FILE;
1048
1049#ifdef MSWIN
1050 /* Remember if the argument was a full path before changing
1051 * slashes to backslashes. */
1052 if (argv[0][0] != NUL && argv[0][1] == ':' && argv[0][2] == '\\')
1053 full_path = TRUE;
1054#endif
1055
1056 /* Add the file to the global argument list. */
1057 if (ga_grow(&global_alist.al_ga, 1) == FAIL
1058 || (p = vim_strsave((char_u *)argv[0])) == NULL)
1059 mch_exit(2);
1060#ifdef FEAT_DIFF
1061 if (diff_mode && mch_isdir(p) && GARGCOUNT > 0
1062 && !mch_isdir(alist_name(&GARGLIST[0])))
1063 {
1064 char_u *r;
1065
1066 r = concat_fnames(p, gettail(alist_name(&GARGLIST[0])), TRUE);
1067 if (r != NULL)
1068 {
1069 vim_free(p);
1070 p = r;
1071 }
1072 }
1073#endif
1074#if defined(__CYGWIN32__) && !defined(WIN32)
1075 /*
1076 * If vim is invoked by non-Cygwin tools, convert away any
1077 * DOS paths, so things like .swp files are created correctly.
1078 * Look for evidence of non-Cygwin paths before we bother.
1079 * This is only for when using the Unix files.
1080 */
1081 if (strpbrk(p, "\\:") != NULL)
1082 {
1083 char posix_path[PATH_MAX];
1084
1085 cygwin_conv_to_posix_path(p, posix_path);
1086 vim_free(p);
1087 p = vim_strsave(posix_path);
1088 if (p == NULL)
1089 mch_exit(2);
1090 }
1091#endif
1092 alist_add(&global_alist, p,
1093#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
1094 literal ? 2 : 0 /* add buffer number after expanding */
1095#else
1096 2 /* add buffer number now and use curbuf */
1097#endif
1098 );
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00001099
1100#if defined(FEAT_MBYTE) && defined(WIN32)
1101 {
1102 extern void used_file_arg(char *, int, int);
1103
1104 /* Remember this argument has been added to the argument list.
1105 * Needed when 'encoding' is changed. */
1106 used_file_arg(argv[0], literal, full_path);
1107 }
1108#endif
Bram Moolenaarb4210b32004-06-13 14:51:16 +00001109 }
1110
1111 /*
1112 * If there are no more letters after the current "-", go to next
1113 * argument. argv_idx is set to -1 when the current argument is to be
1114 * skipped.
1115 */
1116 if (argv_idx <= 0 || argv[0][argv_idx] == NUL)
1117 {
1118 --argc;
1119 ++argv;
1120 argv_idx = 1;
1121 }
1122 }
1123 TIME_MSG("parsing arguments");
1124
1125 /*
1126 * On some systems, when we compile with the GUI, we always use it. On Mac
1127 * there is no terminal version, and on Windows we can't figure out how to
1128 * fork one off with :gui.
1129 */
1130#ifdef ALWAYS_USE_GUI
1131 gui.starting = TRUE;
1132#else
Bram Moolenaar843ee412004-06-30 16:16:41 +00001133# if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
Bram Moolenaarb4210b32004-06-13 14:51:16 +00001134 /*
1135 * Check if the GUI can be started. Reset gui.starting if not.
1136 * Don't know about other systems, stay on the safe side and don't check.
1137 */
1138 if (gui.starting && gui_init_check() == FAIL)
1139 {
1140 gui.starting = FALSE;
1141
1142 /* When running "evim" or "gvim -y" we need the menus, exit if we
1143 * don't have them. */
1144 if (evim_mode)
1145 mch_exit(1);
1146 }
1147# endif
1148#endif
1149
1150 /* "-b" argument used. Check before expanding file names, because for
1151 * Win32 this makes us edit a shortcut file itself, instead of the file it
1152 * links to. */
1153 if (bin_mode)
1154 {
1155 set_options_bin(curbuf->b_p_bin, 1, 0);
1156 curbuf->b_p_bin = 1; /* binary file I/O */
1157 }
1158
1159 if (GARGCOUNT > 0)
1160 {
1161#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
1162 /*
1163 * Expand wildcards in file names.
1164 */
1165 if (!literal)
1166 {
1167 /* Temporarily add '(' and ')' to 'isfname'. These are valid
1168 * filename characters but are excluded from 'isfname' to make
1169 * "gf" work on a file name in parenthesis (e.g.: see vim.h). */
1170 do_cmdline_cmd((char_u *)":set isf+=(,)");
Bram Moolenaar86b68352004-12-27 21:59:20 +00001171 alist_expand(NULL, 0);
Bram Moolenaarb4210b32004-06-13 14:51:16 +00001172 do_cmdline_cmd((char_u *)":set isf&");
1173 }
1174#endif
1175 fname = alist_name(&GARGLIST[0]);
1176 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00001177
1178#if defined(WIN32) && defined(FEAT_MBYTE)
1179 {
1180 extern void set_alist_count(void);
1181
1182 /* Remember the number of entries in the argument list. If it changes
1183 * we don't react on setting 'encoding'. */
1184 set_alist_count();
1185 }
1186#endif
1187
Bram Moolenaarb4210b32004-06-13 14:51:16 +00001188 if (GARGCOUNT > 1)
1189 printf(_("%d files to edit\n"), GARGCOUNT);
1190#ifdef MSWIN
1191 else if (GARGCOUNT == 1 && full_path)
1192 {
1193 /*
1194 * If there is one filename, fully qualified, we have very probably
1195 * been invoked from explorer, so change to the file's directory.
1196 * Hint: to avoid this when typing a command use a forward slash.
1197 * If the cd fails, it doesn't matter.
1198 */
1199 (void)vim_chdirfile(fname);
1200 }
1201#endif
1202 TIME_MSG("expanding arguments");
1203
1204#ifdef FEAT_DIFF
1205 if (diff_mode)
1206 {
1207 if (window_count == -1)
1208 window_count = 0; /* open up to 3 files in a window */
1209 if (vert_windows == MAYBE)
1210 vert_windows = TRUE; /* use vertical split */
1211 }
1212#endif
1213
1214 ++RedrawingDisabled;
1215
1216 /*
1217 * When listing swap file names, don't do cursor positioning et. al.
1218 */
1219 if (recoverymode && fname == NULL)
1220 want_full_screen = FALSE;
1221
1222 /*
1223 * When certain to start the GUI, don't check capabilities of terminal.
1224 * For GTK we can't be sure, but when started from the desktop it doesn't
1225 * make sense to try using a terminal.
1226 */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001227#if defined(ALWAYS_USE_GUI) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
Bram Moolenaarb4210b32004-06-13 14:51:16 +00001228 if (gui.starting
1229# ifdef FEAT_GUI_GTK
1230 && !isatty(2)
1231# endif
1232 )
1233 want_full_screen = FALSE;
1234#endif
1235
1236#if defined(FEAT_GUI_MAC) && defined(MACOS_X_UNIX)
1237 /* When the GUI is started from Finder, need to display messages in a
1238 * message box. isatty(2) returns TRUE anyway, thus we need to check the
1239 * name to know we're not started from a terminal. */
1240 if (gui.starting && (!isatty(2) || strcmp("/dev/console", ttyname(2)) == 0))
1241 want_full_screen = FALSE;
1242#endif
1243
1244 /*
1245 * mch_init() sets up the terminal (window) for use. This must be
1246 * done after resetting full_screen, otherwise it may move the cursor
1247 * (MSDOS).
1248 * Note that we may use mch_exit() before mch_init()!
1249 */
1250 mch_init();
1251 TIME_MSG("shell init");
1252
1253#ifdef USE_XSMP
1254 /*
1255 * For want of anywhere else to do it, try to connect to xsmp here.
1256 * Fitting it in after gui_mch_init, but before gui_init (via termcapinit).
1257 * Hijacking -X 'no X connection' to also disable XSMP connection as that
1258 * has a similar delay upon failure.
1259 * Only try if SESSION_MANAGER is set to something non-null.
1260 */
1261 if (!x_no_connect)
1262 {
1263 p = (char_u *)getenv("SESSION_MANAGER");
1264 if (p != NULL && *p != NUL)
1265 {
1266 xsmp_init();
1267 TIME_MSG("xsmp init");
1268 }
1269 }
1270#endif
1271
1272 /*
1273 * Print a warning if stdout is not a terminal.
1274 * When starting in Ex mode and commands come from a file, set Silent mode.
1275 */
1276 input_isatty = mch_input_isatty();
1277 if (exmode_active)
1278 {
1279 if (!input_isatty)
1280 silent_mode = TRUE;
1281 }
1282 else if (want_full_screen && (!stdout_isatty || !input_isatty)
1283#ifdef FEAT_GUI
1284 /* don't want the delay when started from the desktop */
1285 && !gui.starting
1286#endif
1287 )
1288 {
Bram Moolenaar35a9aaa2004-10-24 19:23:07 +00001289#ifdef NBDEBUG
1290 /*
1291 * This shouldn't be necessary. But if I run netbeans with the log
1292 * output coming to the console and XOpenDisplay fails, I get vim
1293 * trying to start with input/output to my console tty. This fills my
1294 * input buffer so fast I can't even kill the process in under 2
1295 * minutes (and it beeps continuosly the whole time :-)
1296 */
1297 if (usingNetbeans && (!stdout_isatty || !input_isatty))
1298 {
1299 mch_errmsg(_("Vim: Error: Failure to start gvim from NetBeans\n"));
1300 exit(1);
1301 }
1302#endif
Bram Moolenaarb4210b32004-06-13 14:51:16 +00001303 if (!stdout_isatty)
1304 mch_errmsg(_("Vim: Warning: Output is not to a terminal\n"));
1305 if (!input_isatty)
1306 mch_errmsg(_("Vim: Warning: Input is not from a terminal\n"));
1307 out_flush();
1308 if (scriptin[0] == NULL)
1309 ui_delay(2000L, TRUE);
1310 TIME_MSG("Warning delay");
1311 }
1312
1313 if (want_full_screen)
1314 {
1315 termcapinit(term); /* set terminal name and get terminal
1316 capabilities (will set full_screen) */
1317 screen_start(); /* don't know where cursor is now */
1318 TIME_MSG("Termcap init");
1319 }
1320
1321 /*
1322 * Set the default values for the options that use Rows and Columns.
1323 */
1324 ui_get_shellsize(); /* inits Rows and Columns */
1325#ifdef FEAT_NETBEANS_INTG
1326 if (usingNetbeans)
1327 Columns += 2; /* leave room for glyph gutter */
1328#endif
1329 firstwin->w_height = Rows - p_ch;
1330 topframe->fr_height = Rows - p_ch;
1331#ifdef FEAT_VERTSPLIT
1332 firstwin->w_width = Columns;
1333 topframe->fr_width = Columns;
1334#endif
1335#ifdef FEAT_DIFF
1336 /* Set the 'diff' option now, so that it can be checked for in a .vimrc
1337 * file. There is no buffer yet though. */
1338 if (diff_mode)
1339 diff_win_options(firstwin, FALSE);
1340#endif
1341
1342 cmdline_row = Rows - p_ch;
1343 msg_row = cmdline_row;
1344 screenalloc(FALSE); /* allocate screen buffers */
1345 set_init_2();
1346 TIME_MSG("inits 2");
1347
1348 msg_scroll = TRUE;
1349 no_wait_return = TRUE;
1350
1351 init_mappings(); /* set up initial mappings */
1352
1353 init_highlight(TRUE, FALSE); /* set the default highlight groups */
1354 TIME_MSG("init highlight");
1355#ifdef CURSOR_SHAPE
1356 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
1357#endif
1358#ifdef FEAT_MOUSESHAPE
1359 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
1360#endif
1361#ifdef FEAT_PRINTER
1362 parse_list_options(p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS);
1363#endif
1364
1365#ifdef FEAT_EVAL
1366 /* Set the break level after the terminal is initialized. */
1367 debug_break_level = use_debug_break_level;
1368#endif
1369
1370#ifdef FEAT_PRECOMMANDS
1371 if (p_commands > 0)
1372 {
1373 curwin->w_cursor.lnum = 0; /* just in case.. */
1374 sourcing_name = (char_u *)_("pre-vimrc command line");
1375# ifdef FEAT_EVAL
1376 current_SID = SID_CMDARG;
1377# endif
1378 for (i = 0; i < p_commands; ++i)
1379 do_cmdline_cmd(pre_commands[i]);
1380 sourcing_name = NULL;
1381# ifdef FEAT_EVAL
1382 current_SID = 0;
1383# endif
1384 }
1385#endif
1386
1387 /*
1388 * For "evim" source evim.vim first of all, so that the user can overrule
1389 * any things he doesn't like.
1390 */
1391 if (evim_mode)
1392 {
1393 (void)do_source((char_u *)EVIM_FILE, FALSE, FALSE);
1394 TIME_MSG("source evim file");
1395 }
1396
1397 /*
1398 * If -u option given, use only the initializations from that file and
1399 * nothing else.
1400 */
1401 if (use_vimrc != NULL)
1402 {
1403 if (STRCMP(use_vimrc, "NONE") == 0 || STRCMP(use_vimrc, "NORC") == 0)
1404 {
1405#ifdef FEAT_GUI
1406 if (use_gvimrc == NULL) /* don't load gvimrc either */
1407 use_gvimrc = use_vimrc;
1408#endif
1409 if (use_vimrc[2] == 'N')
1410 p_lpl = FALSE; /* don't load plugins either */
1411 }
1412 else
1413 {
1414 if (do_source(use_vimrc, FALSE, FALSE) != OK)
1415 EMSG2(_("E282: Cannot read from \"%s\""), use_vimrc);
1416 }
1417 }
1418 else if (!silent_mode)
1419 {
1420#ifdef AMIGA
1421 struct Process *proc = (struct Process *)FindTask(0L);
1422 APTR save_winptr = proc->pr_WindowPtr;
1423
1424 /* Avoid a requester here for a volume that doesn't exist. */
1425 proc->pr_WindowPtr = (APTR)-1L;
1426#endif
1427
1428 /*
1429 * Get system wide defaults, if the file name is defined.
1430 */
1431#ifdef SYS_VIMRC_FILE
1432 (void)do_source((char_u *)SYS_VIMRC_FILE, FALSE, FALSE);
1433#endif
1434
1435 /*
1436 * Try to read initialization commands from the following places:
1437 * - environment variable VIMINIT
1438 * - user vimrc file (s:.vimrc for Amiga, ~/.vimrc otherwise)
1439 * - second user vimrc file ($VIM/.vimrc for Dos)
1440 * - environment variable EXINIT
1441 * - user exrc file (s:.exrc for Amiga, ~/.exrc otherwise)
1442 * - second user exrc file ($VIM/.exrc for Dos)
1443 * The first that exists is used, the rest is ignored.
1444 */
1445 if (process_env((char_u *)"VIMINIT", TRUE) != OK)
1446 {
1447 if (do_source((char_u *)USR_VIMRC_FILE, TRUE, TRUE) == FAIL
1448#ifdef USR_VIMRC_FILE2
1449 && do_source((char_u *)USR_VIMRC_FILE2, TRUE, TRUE) == FAIL
1450#endif
1451#ifdef USR_VIMRC_FILE3
1452 && do_source((char_u *)USR_VIMRC_FILE3, TRUE, TRUE) == FAIL
1453#endif
1454 && process_env((char_u *)"EXINIT", FALSE) == FAIL
1455 && do_source((char_u *)USR_EXRC_FILE, FALSE, FALSE) == FAIL)
1456 {
1457#ifdef USR_EXRC_FILE2
1458 (void)do_source((char_u *)USR_EXRC_FILE2, FALSE, FALSE);
1459#endif
1460 }
1461 }
1462
1463 /*
1464 * Read initialization commands from ".vimrc" or ".exrc" in current
1465 * directory. This is only done if the 'exrc' option is set.
1466 * Because of security reasons we disallow shell and write commands
1467 * now, except for unix if the file is owned by the user or 'secure'
1468 * option has been reset in environmet of global ".exrc" or ".vimrc".
1469 * Only do this if VIMRC_FILE is not the same as USR_VIMRC_FILE or
1470 * SYS_VIMRC_FILE.
1471 */
1472 if (p_exrc)
1473 {
1474#if defined(UNIX) || defined(VMS)
1475 /* If ".vimrc" file is not owned by user, set 'secure' mode. */
1476 if (!file_owned(VIMRC_FILE))
1477#endif
1478 secure = p_secure;
1479
1480 i = FAIL;
1481 if (fullpathcmp((char_u *)USR_VIMRC_FILE,
1482 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
1483#ifdef USR_VIMRC_FILE2
1484 && fullpathcmp((char_u *)USR_VIMRC_FILE2,
1485 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
1486#endif
1487#ifdef USR_VIMRC_FILE3
1488 && fullpathcmp((char_u *)USR_VIMRC_FILE3,
1489 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
1490#endif
1491#ifdef SYS_VIMRC_FILE
1492 && fullpathcmp((char_u *)SYS_VIMRC_FILE,
1493 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME
1494#endif
1495 )
1496 i = do_source((char_u *)VIMRC_FILE, TRUE, TRUE);
1497
1498 if (i == FAIL)
1499 {
1500#if defined(UNIX) || defined(VMS)
1501 /* if ".exrc" is not owned by user set 'secure' mode */
1502 if (!file_owned(EXRC_FILE))
1503 secure = p_secure;
1504 else
1505 secure = 0;
1506#endif
1507 if ( fullpathcmp((char_u *)USR_EXRC_FILE,
1508 (char_u *)EXRC_FILE, FALSE) != FPC_SAME
1509#ifdef USR_EXRC_FILE2
1510 && fullpathcmp((char_u *)USR_EXRC_FILE2,
1511 (char_u *)EXRC_FILE, FALSE) != FPC_SAME
1512#endif
1513 )
1514 (void)do_source((char_u *)EXRC_FILE, FALSE, FALSE);
1515 }
1516 }
1517 if (secure == 2)
1518 need_wait_return = TRUE;
1519 secure = 0;
1520#ifdef AMIGA
1521 proc->pr_WindowPtr = save_winptr;
1522#endif
1523 }
1524 TIME_MSG("sourcing vimrc file(s)");
1525
1526#ifdef FEAT_EVAL
1527 /*
1528 * Read all the plugin files.
1529 * Only when compiled with +eval, since most plugins need it.
1530 */
1531 if (p_lpl)
1532 {
1533 cmd_runtime((char_u *)"plugin/*.vim", TRUE);
1534 TIME_MSG("loading plugins");
1535 }
1536#endif
1537
1538 /*
1539 * Recovery mode without a file name: List swap files.
1540 * This uses the 'dir' option, therefore it must be after the
1541 * initializations.
1542 */
1543 if (recoverymode && fname == NULL)
1544 {
1545 recover_names(NULL, TRUE, 0);
1546 mch_exit(0);
1547 }
1548
1549 /*
1550 * Set a few option defaults after reading .vimrc files:
1551 * 'title' and 'icon', Unix: 'shellpipe' and 'shellredir'.
1552 */
1553 set_init_3();
1554 TIME_MSG("inits 3");
1555
1556 /*
1557 * "-n" argument: Disable swap file by setting 'updatecount' to 0.
1558 * Note that this overrides anything from a vimrc file.
1559 */
1560 if (no_swap_file)
1561 p_uc = 0;
1562
1563#ifdef FEAT_FKMAP
1564 if (curwin->w_p_rl && p_altkeymap)
1565 {
1566 p_hkmap = FALSE; /* Reset the Hebrew keymap mode */
1567# ifdef FEAT_ARABIC
1568 curwin->w_p_arab = FALSE; /* Reset the Arabic keymap mode */
1569# endif
1570 p_fkmap = TRUE; /* Set the Farsi keymap mode */
1571 }
1572#endif
1573
1574#ifdef FEAT_GUI
1575 if (gui.starting)
1576 {
1577#if defined(UNIX) || defined(VMS)
1578 /* When something caused a message from a vimrc script, need to output
1579 * an extra newline before the shell prompt. */
1580 if (did_emsg || msg_didout)
1581 putchar('\n');
1582#endif
1583
1584 gui_start(); /* will set full_screen to TRUE */
1585 TIME_MSG("starting GUI");
1586
1587 /* When running "evim" or "gvim -y" we need the menus, exit if we
1588 * don't have them. */
1589 if (!gui.in_use && evim_mode)
1590 mch_exit(1);
1591 }
1592#endif
1593
1594#ifdef SPAWNO /* special MSDOS swapping library */
1595 init_SPAWNO("", SWAP_ANY);
1596#endif
1597
1598#ifdef FEAT_VIMINFO
1599 /*
1600 * Read in registers, history etc, but not marks, from the viminfo file
1601 */
1602 if (*p_viminfo != NUL)
1603 {
1604 read_viminfo(NULL, TRUE, FALSE, FALSE);
1605 TIME_MSG("reading viminfo");
1606 }
1607#endif
1608
1609#ifdef FEAT_QUICKFIX
1610 /*
1611 * "-q errorfile": Load the error file now.
1612 * If the error file can't be read, exit before doing anything else.
1613 */
1614 if (edit_type == EDIT_QF)
1615 {
1616 if (use_ef != NULL)
1617 set_string_option_direct((char_u *)"ef", -1, use_ef, OPT_FREE);
1618 if (qf_init(p_ef, p_efm, TRUE) < 0)
1619 {
1620 out_char('\n');
1621 mch_exit(3);
1622 }
1623 TIME_MSG("reading errorfile");
1624 }
1625#endif
1626
1627 /*
1628 * Start putting things on the screen.
1629 * Scroll screen down before drawing over it
1630 * Clear screen now, so file message will not be cleared.
1631 */
1632 starting = NO_BUFFERS;
1633 no_wait_return = FALSE;
1634 if (!exmode_active)
1635 msg_scroll = FALSE;
1636
1637#ifdef FEAT_GUI
1638 /*
1639 * This seems to be required to make callbacks to be called now, instead
1640 * of after things have been put on the screen, which then may be deleted
1641 * when getting a resize callback.
1642 * For the Mac this handles putting files dropped on the Vim icon to
1643 * global_alist.
1644 */
1645 if (gui.in_use)
1646 {
1647# ifdef FEAT_SUN_WORKSHOP
1648 if (!usingSunWorkShop)
1649# endif
1650 gui_wait_for_chars(50L);
1651 TIME_MSG("GUI delay");
1652 }
1653#endif
1654
1655#if defined(FEAT_GUI_PHOTON) && defined(FEAT_CLIPBOARD)
1656 qnx_clip_init();
1657#endif
1658
1659#ifdef FEAT_XCLIPBOARD
1660 /* Start using the X clipboard, unless the GUI was started. */
1661# ifdef FEAT_GUI
1662 if (!gui.in_use)
1663# endif
1664 {
1665 setup_term_clip();
1666 TIME_MSG("setup clipboard");
1667 }
1668#endif
1669
1670#if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11)
1671 /*
1672 * Register for remote command execution with :serversend and --remote
1673 * unless there was a -X or a --servername '' on the command line.
1674 * Only register nongui-vim's with an explicit --servername argument.
1675 */
1676 if (X_DISPLAY != NULL && servername != NULL && (
1677# ifdef FEAT_GUI
1678 gui.in_use ||
1679# endif
1680 serverName_arg != NULL))
1681 {
1682 (void)serverRegisterName(X_DISPLAY, servername);
1683 vim_free(servername);
1684 TIME_MSG("register server name");
1685 }
1686 else
1687 serverDelayedStartName = servername;
1688#endif
1689
1690#ifdef FEAT_CLIENTSERVER
1691 /*
1692 * Execute command ourselves if we're here because the send failed (or
1693 * else we would have exited above).
1694 */
1695 if (serverStr != NULL)
Bram Moolenaar8fc061c2004-12-29 21:03:02 +00001696 {
1697 server_to_input_buf(serverConvert(serverStrEnc, serverStr, &p));
1698 vim_free(p);
1699 }
Bram Moolenaarb4210b32004-06-13 14:51:16 +00001700#endif
1701
1702 /*
1703 * If "-" argument given: Read file from stdin.
1704 * Do this before starting Raw mode, because it may change things that the
1705 * writing end of the pipe doesn't like, e.g., in case stdin and stderr
1706 * are the same terminal: "cat | vim -".
1707 * Using autocommands here may cause trouble...
1708 */
1709 if (edit_type == EDIT_STDIN && !recoverymode)
1710 {
1711#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
1712 /* When getting the ATTENTION prompt here, use a dialog */
1713 swap_exists_action = SEA_DIALOG;
1714#endif
1715 no_wait_return = TRUE;
1716 i = msg_didany;
1717 set_buflisted(TRUE);
1718 (void)open_buffer(TRUE, NULL); /* create memfile and read file */
1719 no_wait_return = FALSE;
1720 msg_didany = i;
1721 TIME_MSG("reading stdin");
1722#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
1723 check_swap_exists_action();
1724#endif
1725#if !(defined(AMIGA) || defined(MACOS))
1726 /*
1727 * Close stdin and dup it from stderr. Required for GPM to work
1728 * properly, and for running external commands.
1729 * Is there any other system that cannot do this?
1730 */
1731 close(0);
1732 dup(2);
1733#endif
1734 }
1735
1736#if defined(UNIX) || defined(VMS)
1737 /* When switching screens and something caused a message from a vimrc
1738 * script, need to output an extra newline on exit. */
1739 if ((did_emsg || msg_didout) && *T_TI != NUL)
1740 newline_on_exit = TRUE;
1741#endif
1742
1743 /*
1744 * When done something that is not allowed or error message call
1745 * wait_return. This must be done before starttermcap(), because it may
1746 * switch to another screen. It must be done after settmode(TMODE_RAW),
1747 * because we want to react on a single key stroke.
1748 * Call settmode and starttermcap here, so the T_KS and T_TI may be
1749 * defined by termcapinit and redifined in .exrc.
1750 */
1751 settmode(TMODE_RAW);
1752 TIME_MSG("setting raw mode");
1753
1754 if (need_wait_return || msg_didany)
1755 {
1756 wait_return(TRUE);
1757 TIME_MSG("waiting for return");
1758 }
1759
1760 starttermcap(); /* start termcap if not done by wait_return() */
1761 TIME_MSG("start termcap");
1762
1763#ifdef FEAT_MOUSE
1764 setmouse(); /* may start using the mouse */
1765#endif
1766 if (scroll_region)
1767 scroll_region_reset(); /* In case Rows changed */
1768
1769 scroll_start();
1770
1771 /*
1772 * Don't clear the screen when starting in Ex mode, unless using the GUI.
1773 */
1774 if (exmode_active
1775#ifdef FEAT_GUI
1776 && !gui.in_use
1777#endif
1778 )
1779 must_redraw = CLEAR;
1780 else
1781 {
1782 screenclear(); /* clear screen */
1783 TIME_MSG("clearing screen");
1784 }
1785
1786#ifdef FEAT_CRYPT
1787 if (ask_for_key)
1788 {
1789 (void)get_crypt_key(TRUE, TRUE);
1790 TIME_MSG("getting crypt key");
1791 }
1792#endif
1793
1794 no_wait_return = TRUE;
1795
1796#ifdef FEAT_WINDOWS
1797 /*
1798 * Create the number of windows that was requested.
1799 */
1800 if (window_count == -1) /* was not set */
1801 window_count = 1;
1802 if (window_count == 0)
1803 window_count = GARGCOUNT;
1804 if (window_count > 1)
1805 {
1806 /* Don't change the windows if there was a command in .vimrc that
1807 * already split some windows */
1808 if (vert_windows == MAYBE)
1809 vert_windows = FALSE;
1810 if (firstwin->w_next == NULL)
1811 {
1812 window_count = make_windows(window_count, vert_windows);
1813 TIME_MSG("making windows");
1814 }
1815 else
1816 window_count = win_count();
1817 }
1818 else
1819 window_count = 1;
1820#endif
1821
1822 if (recoverymode) /* do recover */
1823 {
1824 msg_scroll = TRUE; /* scroll message up */
1825 ml_recover();
1826 if (curbuf->b_ml.ml_mfp == NULL) /* failed */
1827 getout(1);
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00001828 do_modelines(FALSE); /* do modelines */
Bram Moolenaarb4210b32004-06-13 14:51:16 +00001829 }
1830 else
1831 {
1832 /*
1833 * Open a buffer for windows that don't have one yet.
1834 * Commands in the .vimrc might have loaded a file or split the window.
1835 * Watch out for autocommands that delete a window.
1836 */
1837#ifdef FEAT_AUTOCMD
1838 /*
1839 * Don't execute Win/Buf Enter/Leave autocommands here
1840 */
1841 ++autocmd_no_enter;
1842 ++autocmd_no_leave;
1843#endif
1844#ifdef FEAT_WINDOWS
1845 for (curwin = firstwin; curwin != NULL; curwin = W_NEXT(curwin))
1846#endif
1847 {
1848 curbuf = curwin->w_buffer;
1849 if (curbuf->b_ml.ml_mfp == NULL)
1850 {
1851#ifdef FEAT_FOLDING
1852 /* Set 'foldlevel' to 'foldlevelstart' if it's not negative. */
1853 if (p_fdls >= 0)
1854 curwin->w_p_fdl = p_fdls;
1855#endif
1856#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
1857 /* When getting the ATTENTION prompt here, use a dialog */
1858 swap_exists_action = SEA_DIALOG;
1859#endif
1860 set_buflisted(TRUE);
1861 (void)open_buffer(FALSE, NULL); /* create memfile, read file */
1862
1863#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
1864 check_swap_exists_action();
1865#endif
1866#ifdef FEAT_AUTOCMD
1867 curwin = firstwin; /* start again */
1868#endif
1869 }
1870#ifdef FEAT_WINDOWS
1871 ui_breakcheck();
1872 if (got_int)
1873 {
1874 (void)vgetc(); /* only break the file loading, not the rest */
1875 break;
1876 }
1877#endif
1878 }
1879#ifdef FEAT_AUTOCMD
1880 --autocmd_no_enter;
1881 --autocmd_no_leave;
1882#endif
1883#ifdef FEAT_WINDOWS
1884 curwin = firstwin;
1885 curbuf = curwin->w_buffer;
1886#endif
1887 }
1888 TIME_MSG("opening buffers");
1889
1890 /* Ex starts at last line of the file */
1891 if (exmode_active)
1892 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
1893
1894#ifdef FEAT_AUTOCMD
1895 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
1896 TIME_MSG("BufEnter autocommands");
1897#endif
1898 setpcmark();
1899
1900#ifdef FEAT_QUICKFIX
1901 /*
1902 * When started with "-q errorfile" jump to first error now.
1903 */
1904 if (edit_type == EDIT_QF)
1905 {
1906 qf_jump(0, 0, FALSE);
1907 TIME_MSG("jump to first error");
1908 }
1909#endif
1910
1911#ifdef FEAT_WINDOWS
1912 /*
1913 * If opened more than one window, start editing files in the other
1914 * windows. Make_windows() has already opened the windows.
1915 */
1916# ifdef FEAT_AUTOCMD
1917 /*
1918 * Don't execute Win/Buf Enter/Leave autocommands here
1919 */
1920 ++autocmd_no_enter;
1921 ++autocmd_no_leave;
1922# endif
1923 arg_idx = 1;
1924 for (i = 1; i < window_count; ++i)
1925 {
1926 if (curwin->w_next == NULL) /* just checking */
1927 break;
1928 win_enter(curwin->w_next, FALSE);
1929
1930 /* Only open the file if there is no file in this window yet (that can
1931 * happen when .vimrc contains ":sall") */
1932 if (curbuf == firstwin->w_buffer || curbuf->b_ffname == NULL)
1933 {
1934 curwin->w_arg_idx = arg_idx;
1935 /* edit file from arg list, if there is one */
1936 (void)do_ecmd(0, arg_idx < GARGCOUNT
1937 ? alist_name(&GARGLIST[arg_idx]) : NULL,
1938 NULL, NULL, ECMD_LASTL, ECMD_HIDE);
1939 if (arg_idx == GARGCOUNT - 1)
1940 arg_had_last = TRUE;
1941 ++arg_idx;
1942 }
1943 ui_breakcheck();
1944 if (got_int)
1945 {
1946 (void)vgetc(); /* only break the file loading, not the rest */
1947 break;
1948 }
1949 }
1950# ifdef FEAT_AUTOCMD
1951 --autocmd_no_enter;
1952# endif
1953 win_enter(firstwin, FALSE); /* back to first window */
1954# ifdef FEAT_AUTOCMD
1955 --autocmd_no_leave;
1956# endif
1957 TIME_MSG("editing files in windows");
1958 if (window_count > 1)
1959 win_equal(curwin, FALSE, 'b'); /* adjust heights */
1960#endif /* FEAT_WINDOWS */
1961
1962#ifdef FEAT_DIFF
1963 if (diff_mode)
1964 {
1965 win_T *wp;
1966
1967 /* set options in each window for "vimdiff". */
1968 for (wp = firstwin; wp != NULL; wp = wp->w_next)
1969 diff_win_options(wp, TRUE);
1970 }
1971#endif
1972
1973 /*
1974 * Shorten any of the filenames, but only when absolute.
1975 */
1976 shorten_fnames(FALSE);
1977
1978 /*
1979 * Need to jump to the tag before executing the '-c command'.
1980 * Makes "vim -c '/return' -t main" work.
1981 */
1982 if (tagname != NULL)
1983 {
1984 STRCPY(IObuff, "ta ");
1985
1986 STRNCAT(IObuff, tagname, IOSIZE - 4);
1987 IObuff[IOSIZE - 1] = NUL;
1988 do_cmdline_cmd(IObuff);
1989 TIME_MSG("jumping to tag");
1990 }
1991
1992 if (n_commands > 0)
1993 {
1994 /*
1995 * We start commands on line 0, make "vim +/pat file" match a
1996 * pattern on line 1.
1997 */
1998 msg_scroll = TRUE;
1999 if (tagname == NULL)
2000 curwin->w_cursor.lnum = 0;
2001 sourcing_name = (char_u *)"command line";
2002#ifdef FEAT_EVAL
2003 current_SID = SID_CARG;
2004#endif
2005 for (i = 0; i < n_commands; ++i)
2006 do_cmdline_cmd(commands[i]);
2007 sourcing_name = NULL;
2008#ifdef FEAT_EVAL
2009 current_SID = 0;
2010#endif
2011 if (curwin->w_cursor.lnum == 0)
2012 curwin->w_cursor.lnum = 1;
2013
2014 if (!exmode_active)
2015 msg_scroll = FALSE;
2016
2017#ifdef FEAT_QUICKFIX
2018 /* When started with "-q errorfile" jump to first error again. */
2019 if (edit_type == EDIT_QF)
2020 qf_jump(0, 0, FALSE);
2021#endif
2022 TIME_MSG("executing command arguments");
2023 }
2024
2025 RedrawingDisabled = 0;
2026 redraw_all_later(NOT_VALID);
2027 no_wait_return = FALSE;
2028 starting = 0;
2029
2030 /* start in insert mode */
2031 if (p_im)
2032 need_start_insertmode = TRUE;
2033
2034#ifdef FEAT_AUTOCMD
2035 apply_autocmds(EVENT_VIMENTER, NULL, NULL, FALSE, curbuf);
2036 TIME_MSG("VimEnter autocommands");
2037#endif
2038
2039#if defined(FEAT_DIFF) && defined(FEAT_SCROLLBIND)
2040 /* When a startup script or session file setup for diff'ing and
2041 * scrollbind, sync the scrollbind now. */
2042 if (curwin->w_p_diff && curwin->w_p_scb)
2043 {
2044 update_topline();
2045 check_scrollbind((linenr_T)0, 0L);
2046 TIME_MSG("diff scrollbinding");
2047 }
2048#endif
2049
2050#if defined(WIN3264) && !defined(FEAT_GUI_W32)
2051 mch_set_winsize_now(); /* Allow winsize changes from now on */
2052#endif
2053
2054 /* If ":startinsert" command used, stuff a dummy command to be able to
2055 * call normal_cmd(), which will then start Insert mode. */
2056 if (restart_edit != 0)
2057 stuffcharReadbuff(K_IGNORE);
2058
2059#ifdef FEAT_NETBEANS_INTG
2060 if (usingNetbeans)
2061 /* Tell the client that it can start sending commands. */
2062 netbeans_startup_done();
2063#endif
2064
2065 TIME_MSG("before starting main loop");
2066
2067 /*
2068 * Call the main command loop. This never returns.
2069 */
2070 main_loop(FALSE);
2071
2072 return 0;
2073}
2074#endif /* PROTO */
2075
2076/*
2077 * Main loop: Execute Normal mode commands until exiting Vim.
2078 * Also used to handle commands in the command-line window, until the window
2079 * is closed.
2080 */
2081 void
2082main_loop(cmdwin)
2083 int cmdwin; /* TRUE when working in the command-line window */
2084{
2085 oparg_T oa; /* operator arguments */
2086
2087#if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)
2088 /* Setup to catch a terminating error from the X server. Just ignore
2089 * it, restore the state and continue. This might not always work
2090 * properly, but at least we don't exit unexpectedly when the X server
2091 * exists while Vim is running in a console. */
2092 if (!cmdwin && SETJMP(x_jump_env))
2093 {
2094 State = NORMAL;
2095# ifdef FEAT_VISUAL
2096 VIsual_active = FALSE;
2097# endif
2098 got_int = TRUE;
2099 need_wait_return = FALSE;
2100 global_busy = FALSE;
2101 exmode_active = 0;
2102 skip_redraw = FALSE;
2103 RedrawingDisabled = 0;
2104 no_wait_return = 0;
2105# ifdef FEAT_EVAL
2106 emsg_skip = 0;
2107# endif
2108 emsg_off = 0;
2109# ifdef FEAT_MOUSE
2110 setmouse();
2111# endif
2112 settmode(TMODE_RAW);
2113 starttermcap();
2114 scroll_start();
2115 redraw_later_clear();
2116 }
2117#endif
2118
2119 clear_oparg(&oa);
2120 while (!cmdwin
2121#ifdef FEAT_CMDWIN
2122 || cmdwin_result == 0
2123#endif
2124 )
2125 {
2126 if (stuff_empty())
2127 {
2128 did_check_timestamps = FALSE;
2129 if (need_check_timestamps)
2130 check_timestamps(FALSE);
2131 if (need_wait_return) /* if wait_return still needed ... */
2132 wait_return(FALSE); /* ... call it now */
2133 if (need_start_insertmode && goto_im()
2134#ifdef FEAT_VISUAL
2135 && !VIsual_active
2136#endif
2137 )
2138 {
2139 need_start_insertmode = FALSE;
2140 stuffReadbuff((char_u *)"i"); /* start insert mode next */
2141 /* skip the fileinfo message now, because it would be shown
2142 * after insert mode finishes! */
2143 need_fileinfo = FALSE;
2144 }
2145 }
2146 if (got_int && !global_busy)
2147 {
2148 if (!quit_more)
2149 (void)vgetc(); /* flush all buffers */
2150 got_int = FALSE;
2151 }
2152 if (!exmode_active)
2153 msg_scroll = FALSE;
2154 quit_more = FALSE;
2155
2156 /*
2157 * If skip redraw is set (for ":" in wait_return()), don't redraw now.
2158 * If there is nothing in the stuff_buffer or do_redraw is TRUE,
2159 * update cursor and redraw.
2160 */
2161 if (skip_redraw || exmode_active)
2162 skip_redraw = FALSE;
2163 else if (do_redraw || stuff_empty())
2164 {
2165#if defined(FEAT_FOLDING) && defined(FEAT_VISUAL)
2166 /* Include a closed fold completely in the Visual area. */
2167 foldAdjustVisual();
2168#endif
2169#ifdef FEAT_FOLDING
2170 /*
2171 * When 'foldclose' is set, apply 'foldlevel' to folds that don't
2172 * contain the cursor.
2173 * When 'foldopen' is "all", open the fold(s) under the cursor.
2174 * This may mark the window for redrawing.
2175 */
2176 if (hasAnyFolding(curwin) && !char_avail())
2177 {
2178 foldCheckClose();
2179 if (fdo_flags & FDO_ALL)
2180 foldOpenCursor();
2181 }
2182#endif
2183
2184 /*
2185 * Before redrawing, make sure w_topline is correct, and w_leftcol
2186 * if lines don't wrap, and w_skipcol if lines wrap.
2187 */
2188 update_topline();
2189 validate_cursor();
2190
2191#ifdef FEAT_VISUAL
2192 if (VIsual_active)
2193 update_curbuf(INVERTED);/* update inverted part */
2194 else
2195#endif
2196 if (must_redraw)
2197 update_screen(0);
2198 else if (redraw_cmdline || clear_cmdline)
2199 showmode();
2200#ifdef FEAT_WINDOWS
2201 redraw_statuslines();
2202#endif
2203#ifdef FEAT_TITLE
2204 if (need_maketitle)
2205 maketitle();
2206#endif
2207 /* display message after redraw */
2208 if (keep_msg != NULL)
2209 {
2210 char_u *p;
2211
2212 /* msg_attr_keep() will set keep_msg to NULL, must free the
2213 * string here. */
2214 p = keep_msg;
2215 msg_attr(p, keep_msg_attr);
2216 vim_free(p);
2217 }
2218 if (need_fileinfo) /* show file info after redraw */
2219 {
2220 fileinfo(FALSE, TRUE, FALSE);
2221 need_fileinfo = FALSE;
2222 }
2223
2224 emsg_on_display = FALSE; /* can delete error message now */
2225 did_emsg = FALSE;
2226 msg_didany = FALSE; /* reset lines_left in msg_start() */
2227 showruler(FALSE);
2228
2229 setcursor();
2230 cursor_on();
2231
2232 do_redraw = FALSE;
2233 }
2234#ifdef FEAT_GUI
2235 if (need_mouse_correct)
2236 gui_mouse_correct();
2237#endif
2238
2239 /*
2240 * Update w_curswant if w_set_curswant has been set.
2241 * Postponed until here to avoid computing w_virtcol too often.
2242 */
2243 update_curswant();
2244
2245 /*
2246 * If we're invoked as ex, do a round of ex commands.
2247 * Otherwise, get and execute a normal mode command.
2248 */
2249 if (exmode_active)
2250 do_exmode(exmode_active == EXMODE_VIM);
2251 else
2252 normal_cmd(&oa, TRUE);
2253 }
2254}
2255
2256
2257#if defined(USE_XSMP) || defined(FEAT_GUI_MSWIN) || defined(PROTO)
2258/*
2259 * Exit, but leave behind swap files for modified buffers.
2260 */
2261 void
2262getout_preserve_modified(exitval)
2263 int exitval;
2264{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00002265# if defined(SIGHUP) && defined(SIG_IGN)
2266 /* Ignore SIGHUP, because a dropped connection causes a read error, which
2267 * makes Vim exit and then handling SIGHUP causes various reentrance
2268 * problems. */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002269 signal(SIGHUP, SIG_IGN);
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00002270# endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002271
Bram Moolenaarb4210b32004-06-13 14:51:16 +00002272 ml_close_notmod(); /* close all not-modified buffers */
2273 ml_sync_all(FALSE, FALSE); /* preserve all swap files */
2274 ml_close_all(FALSE); /* close all memfiles, without deleting */
2275 getout(exitval); /* exit Vim properly */
2276}
2277#endif
2278
2279
2280/* Exit properly */
2281 void
2282getout(exitval)
2283 int exitval;
2284{
2285#ifdef FEAT_AUTOCMD
2286 buf_T *buf;
2287 win_T *wp;
2288#endif
2289
2290 exiting = TRUE;
2291
2292 /* Position the cursor on the last screen line, below all the text */
2293#ifdef FEAT_GUI
2294 if (!gui.in_use)
2295#endif
2296 windgoto((int)Rows - 1, 0);
2297
2298#ifdef FEAT_GUI
2299 msg_didany = FALSE;
2300#endif
2301
2302#ifdef FEAT_AUTOCMD
2303 /* Trigger BufWinLeave for all windows, but only once per buffer. */
2304 for (wp = firstwin; wp != NULL; )
2305 {
2306 buf = wp->w_buffer;
2307 if (buf->b_changedtick != -1)
2308 {
2309 apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname,
2310 FALSE, buf);
2311 buf->b_changedtick = -1; /* note that we did it already */
2312 wp = firstwin; /* restart, window may be closed */
2313 }
2314 else
2315 wp = wp->w_next;
2316 }
2317 /* Trigger BufUnload for buffers that are loaded */
2318 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
2319 if (buf->b_ml.ml_mfp != NULL)
2320 {
2321 apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname,
2322 FALSE, buf);
2323 if (!buf_valid(buf)) /* autocmd may delete the buffer */
2324 break;
2325 }
2326 apply_autocmds(EVENT_VIMLEAVEPRE, NULL, NULL, FALSE, curbuf);
2327#endif
2328
2329#ifdef FEAT_VIMINFO
2330 if (*p_viminfo != NUL)
2331 /* Write out the registers, history, marks etc, to the viminfo file */
2332 write_viminfo(NULL, FALSE);
2333#endif
2334
2335#ifdef FEAT_AUTOCMD
2336 apply_autocmds(EVENT_VIMLEAVE, NULL, NULL, FALSE, curbuf);
2337#endif
2338
2339 if (did_emsg
2340#ifdef FEAT_GUI
2341 || (gui.in_use && msg_didany && p_verbose > 0)
2342#endif
2343 )
2344 {
2345 /* give the user a chance to read the (error) message */
2346 no_wait_return = FALSE;
2347 wait_return(FALSE);
2348 }
2349
2350#ifdef FEAT_AUTOCMD
2351 /* Position the cursor again, the autocommands may have moved it */
2352# ifdef FEAT_GUI
2353 if (!gui.in_use)
2354# endif
2355 windgoto((int)Rows - 1, 0);
2356#endif
2357
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002358#ifdef FEAT_MZSCHEME
2359 mzscheme_end();
2360#endif
Bram Moolenaarb4210b32004-06-13 14:51:16 +00002361#ifdef FEAT_TCL
2362 tcl_end();
2363#endif
2364#ifdef FEAT_RUBY
2365 ruby_end();
2366#endif
2367#ifdef FEAT_PYTHON
2368 python_end();
2369#endif
2370#ifdef FEAT_PERL
2371 perl_end();
2372#endif
2373#if defined(USE_ICONV) && defined(DYNAMIC_ICONV)
2374 iconv_end();
2375#endif
2376#ifdef FEAT_NETBEANS_INTG
2377 netbeans_end();
2378#endif
2379
2380 mch_exit(exitval);
2381}
2382
2383/*
2384 * Get a (optional) count for a Vim argument.
2385 */
2386 static int
2387get_number_arg(p, idx, def)
2388 char_u *p; /* pointer to argument */
2389 int *idx; /* index in argument, is incremented */
2390 int def; /* default value */
2391{
2392 if (vim_isdigit(p[*idx]))
2393 {
2394 def = atoi((char *)&(p[*idx]));
2395 while (vim_isdigit(p[*idx]))
2396 *idx = *idx + 1;
2397 }
2398 return def;
2399}
2400
2401/*
2402 * Setup to start using the GUI. Exit with an error when not available.
2403 */
2404 static void
2405main_start_gui()
2406{
2407#ifdef FEAT_GUI
2408 gui.starting = TRUE; /* start GUI a bit later */
2409#else
2410 mch_errmsg(_(e_nogvim));
2411 mch_errmsg("\n");
2412 mch_exit(2);
2413#endif
2414}
2415
2416/*
2417 * Get an evironment variable, and execute it as Ex commands.
2418 * Returns FAIL if the environment variable was not executed, OK otherwise.
2419 */
2420 int
2421process_env(env, is_viminit)
2422 char_u *env;
2423 int is_viminit; /* when TRUE, called for VIMINIT */
2424{
2425 char_u *initstr;
2426 char_u *save_sourcing_name;
2427 linenr_T save_sourcing_lnum;
2428#ifdef FEAT_EVAL
2429 scid_T save_sid;
2430#endif
2431
2432 if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL)
2433 {
2434 if (is_viminit)
2435 vimrc_found();
2436 save_sourcing_name = sourcing_name;
2437 save_sourcing_lnum = sourcing_lnum;
2438 sourcing_name = env;
2439 sourcing_lnum = 0;
2440#ifdef FEAT_EVAL
2441 save_sid = current_SID;
2442 current_SID = SID_ENV;
2443#endif
2444 do_cmdline_cmd(initstr);
2445 sourcing_name = save_sourcing_name;
2446 sourcing_lnum = save_sourcing_lnum;
2447#ifdef FEAT_EVAL
2448 current_SID = save_sid;;
2449#endif
2450 return OK;
2451 }
2452 return FAIL;
2453}
2454
2455#if defined(UNIX) || defined(VMS)
2456/*
2457 * Return TRUE if we are certain the user owns the file "fname".
2458 * Used for ".vimrc" and ".exrc".
2459 * Use both stat() and lstat() for extra security.
2460 */
2461 static int
2462file_owned(fname)
2463 char *fname;
2464{
2465 struct stat s;
2466# ifdef UNIX
2467 uid_t uid = getuid();
2468# else /* VMS */
2469 uid_t uid = ((getgid() << 16) | getuid());
2470# endif
2471
2472 return !(mch_stat(fname, &s) != 0 || s.st_uid != uid
2473# ifdef HAVE_LSTAT
2474 || mch_lstat(fname, &s) != 0 || s.st_uid != uid
2475# endif
2476 );
2477}
2478#endif
2479
2480/*
2481 * Give an error message main_errors["n"] and exit.
2482 */
2483 static void
2484mainerr(n, str)
2485 int n; /* one of the ME_ defines */
2486 char_u *str; /* extra argument or NULL */
2487{
2488#if defined(UNIX) || defined(__EMX__) || defined(VMS)
2489 reset_signals(); /* kill us with CTRL-C here, if you like */
2490#endif
2491
2492 mch_errmsg(longVersion);
Bram Moolenaar2a8d1f82005-02-05 21:43:56 +00002493 mch_errmsg("\n");
Bram Moolenaarb4210b32004-06-13 14:51:16 +00002494 mch_errmsg(_(main_errors[n]));
2495 if (str != NULL)
2496 {
2497 mch_errmsg(": \"");
2498 mch_errmsg((char *)str);
2499 mch_errmsg("\"");
2500 }
Bram Moolenaar2a8d1f82005-02-05 21:43:56 +00002501 mch_errmsg(_("\nMore info with: \"vim -h\"\n"));
Bram Moolenaarb4210b32004-06-13 14:51:16 +00002502
2503 mch_exit(1);
2504}
2505
2506 void
2507mainerr_arg_missing(str)
2508 char_u *str;
2509{
2510 mainerr(ME_ARG_MISSING, str);
2511}
2512
2513/*
2514 * print a message with three spaces prepended and '\n' appended.
2515 */
2516 static void
2517main_msg(s)
2518 char *s;
2519{
2520 mch_msg(" ");
2521 mch_msg(s);
2522 mch_msg("\n");
2523}
2524
2525/*
2526 * Print messages for "vim -h" or "vim --help" and exit.
2527 */
2528 static void
2529usage()
2530{
2531 int i;
2532 static char *(use[]) =
2533 {
2534 N_("[file ..] edit specified file(s)"),
2535 N_("- read text from stdin"),
2536 N_("-t tag edit file where tag is defined"),
2537#ifdef FEAT_QUICKFIX
2538 N_("-q [errorfile] edit file with first error")
2539#endif
2540 };
2541
2542#if defined(UNIX) || defined(__EMX__) || defined(VMS)
2543 reset_signals(); /* kill us with CTRL-C here, if you like */
2544#endif
2545
2546 mch_msg(longVersion);
2547 mch_msg(_("\n\nusage:"));
2548 for (i = 0; ; ++i)
2549 {
2550 mch_msg(_(" vim [arguments] "));
2551 mch_msg(_(use[i]));
2552 if (i == (sizeof(use) / sizeof(char_u *)) - 1)
2553 break;
2554 mch_msg(_("\n or:"));
2555 }
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002556#ifdef VMS
2557 mch_msg(_("where case is ignored prepend / to make flag upper case"));
2558#endif
Bram Moolenaarb4210b32004-06-13 14:51:16 +00002559
2560 mch_msg(_("\n\nArguments:\n"));
2561 main_msg(_("--\t\t\tOnly file names after this"));
2562#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
2563 main_msg(_("--literal\t\tDon't expand wildcards"));
2564#endif
2565#ifdef FEAT_OLE
2566 main_msg(_("-register\t\tRegister this gvim for OLE"));
2567 main_msg(_("-unregister\t\tUnregister gvim for OLE"));
2568#endif
2569#ifdef FEAT_GUI
2570 main_msg(_("-g\t\t\tRun using GUI (like \"gvim\")"));
2571 main_msg(_("-f or --nofork\tForeground: Don't fork when starting GUI"));
2572#endif
2573 main_msg(_("-v\t\t\tVi mode (like \"vi\")"));
2574 main_msg(_("-e\t\t\tEx mode (like \"ex\")"));
2575 main_msg(_("-s\t\t\tSilent (batch) mode (only for \"ex\")"));
2576#ifdef FEAT_DIFF
2577 main_msg(_("-d\t\t\tDiff mode (like \"vimdiff\")"));
2578#endif
2579 main_msg(_("-y\t\t\tEasy mode (like \"evim\", modeless)"));
2580 main_msg(_("-R\t\t\tReadonly mode (like \"view\")"));
2581 main_msg(_("-Z\t\t\tRestricted mode (like \"rvim\")"));
2582 main_msg(_("-m\t\t\tModifications (writing files) not allowed"));
2583 main_msg(_("-M\t\t\tModifications in text not allowed"));
2584 main_msg(_("-b\t\t\tBinary mode"));
2585#ifdef FEAT_LISP
2586 main_msg(_("-l\t\t\tLisp mode"));
2587#endif
2588 main_msg(_("-C\t\t\tCompatible with Vi: 'compatible'"));
2589 main_msg(_("-N\t\t\tNot fully Vi compatible: 'nocompatible'"));
2590 main_msg(_("-V[N]\t\tVerbose level"));
2591 main_msg(_("-D\t\t\tDebugging mode"));
2592 main_msg(_("-n\t\t\tNo swap file, use memory only"));
2593 main_msg(_("-r\t\t\tList swap files and exit"));
2594 main_msg(_("-r (with file name)\tRecover crashed session"));
2595 main_msg(_("-L\t\t\tSame as -r"));
2596#ifdef AMIGA
2597 main_msg(_("-f\t\t\tDon't use newcli to open window"));
2598 main_msg(_("-dev <device>\t\tUse <device> for I/O"));
2599#endif
2600#ifdef FEAT_ARABIC
2601 main_msg(_("-A\t\t\tstart in Arabic mode"));
2602#endif
2603#ifdef FEAT_RIGHTLEFT
2604 main_msg(_("-H\t\t\tStart in Hebrew mode"));
2605#endif
2606#ifdef FEAT_FKMAP
2607 main_msg(_("-F\t\t\tStart in Farsi mode"));
2608#endif
2609 main_msg(_("-T <terminal>\tSet terminal type to <terminal>"));
2610 main_msg(_("-u <vimrc>\t\tUse <vimrc> instead of any .vimrc"));
2611#ifdef FEAT_GUI
2612 main_msg(_("-U <gvimrc>\t\tUse <gvimrc> instead of any .gvimrc"));
2613#endif
2614 main_msg(_("--noplugin\t\tDon't load plugin scripts"));
2615 main_msg(_("-o[N]\t\tOpen N windows (default: one for each file)"));
2616 main_msg(_("-O[N]\t\tLike -o but split vertically"));
2617 main_msg(_("+\t\t\tStart at end of file"));
2618 main_msg(_("+<lnum>\t\tStart at line <lnum>"));
2619#ifdef FEAT_PRECOMMANDS
2620 main_msg(_("--cmd <command>\tExecute <command> before loading any vimrc file"));
2621#endif
2622 main_msg(_("-c <command>\t\tExecute <command> after loading the first file"));
2623 main_msg(_("-S <session>\t\tSource file <session> after loading the first file"));
2624 main_msg(_("-s <scriptin>\tRead Normal mode commands from file <scriptin>"));
2625 main_msg(_("-w <scriptout>\tAppend all typed commands to file <scriptout>"));
2626 main_msg(_("-W <scriptout>\tWrite all typed commands to file <scriptout>"));
2627#ifdef FEAT_CRYPT
2628 main_msg(_("-x\t\t\tEdit encrypted files"));
2629#endif
2630#if (defined(UNIX) || defined(VMS)) && defined(FEAT_X11)
2631# if defined(FEAT_GUI_X11) && !defined(FEAT_GUI_GTK)
2632 main_msg(_("-display <display>\tConnect vim to this particular X-server"));
2633# endif
2634 main_msg(_("-X\t\t\tDo not connect to X server"));
2635#endif
2636#ifdef FEAT_CLIENTSERVER
2637 main_msg(_("--remote <files>\tEdit <files> in a Vim server if possible"));
2638 main_msg(_("--remote-silent <files> Same, don't complain if there is no server"));
2639 main_msg(_("--remote-wait <files> As --remote but wait for files to have been edited"));
2640 main_msg(_("--remote-wait-silent <files> Same, don't complain if there is no server"));
2641 main_msg(_("--remote-send <keys>\tSend <keys> to a Vim server and exit"));
2642 main_msg(_("--remote-expr <expr>\tEvaluate <expr> in a Vim server and print result"));
2643 main_msg(_("--serverlist\t\tList available Vim server names and exit"));
2644 main_msg(_("--servername <name>\tSend to/become the Vim server <name>"));
2645#endif
2646#ifdef FEAT_VIMINFO
2647 main_msg(_("-i <viminfo>\t\tUse <viminfo> instead of .viminfo"));
2648#endif
2649 main_msg(_("-h or --help\tPrint Help (this message) and exit"));
2650 main_msg(_("--version\t\tPrint version information and exit"));
2651
2652#ifdef FEAT_GUI_X11
2653# ifdef FEAT_GUI_MOTIF
2654 mch_msg(_("\nArguments recognised by gvim (Motif version):\n"));
2655# else
2656# ifdef FEAT_GUI_ATHENA
2657# ifdef FEAT_GUI_NEXTAW
2658 mch_msg(_("\nArguments recognised by gvim (neXtaw version):\n"));
2659# else
2660 mch_msg(_("\nArguments recognised by gvim (Athena version):\n"));
2661# endif
2662# endif
2663# endif
2664 main_msg(_("-display <display>\tRun vim on <display>"));
2665 main_msg(_("-iconic\t\tStart vim iconified"));
2666# if 0
2667 main_msg(_("-name <name>\t\tUse resource as if vim was <name>"));
2668 mch_msg(_("\t\t\t (Unimplemented)\n"));
2669# endif
2670 main_msg(_("-background <color>\tUse <color> for the background (also: -bg)"));
2671 main_msg(_("-foreground <color>\tUse <color> for normal text (also: -fg)"));
2672 main_msg(_("-font <font>\t\tUse <font> for normal text (also: -fn)"));
2673 main_msg(_("-boldfont <font>\tUse <font> for bold text"));
2674 main_msg(_("-italicfont <font>\tUse <font> for italic text"));
2675 main_msg(_("-geometry <geom>\tUse <geom> for initial geometry (also: -geom)"));
2676 main_msg(_("-borderwidth <width>\tUse a border width of <width> (also: -bw)"));
2677 main_msg(_("-scrollbarwidth <width> Use a scrollbar width of <width> (also: -sw)"));
2678# ifdef FEAT_GUI_ATHENA
2679 main_msg(_("-menuheight <height>\tUse a menu bar height of <height> (also: -mh)"));
2680# endif
2681 main_msg(_("-reverse\t\tUse reverse video (also: -rv)"));
2682 main_msg(_("+reverse\t\tDon't use reverse video (also: +rv)"));
2683 main_msg(_("-xrm <resource>\tSet the specified resource"));
2684#endif /* FEAT_GUI_X11 */
2685#if defined(FEAT_GUI) && defined(RISCOS)
2686 mch_msg(_("\nArguments recognised by gvim (RISC OS version):\n"));
2687 main_msg(_("--columns <number>\tInitial width of window in columns"));
2688 main_msg(_("--rows <number>\tInitial height of window in rows"));
2689#endif
2690#ifdef FEAT_GUI_GTK
2691 mch_msg(_("\nArguments recognised by gvim (GTK+ version):\n"));
2692 main_msg(_("-font <font>\t\tUse <font> for normal text (also: -fn)"));
2693 main_msg(_("-geometry <geom>\tUse <geom> for initial geometry (also: -geom)"));
2694 main_msg(_("-reverse\t\tUse reverse video (also: -rv)"));
2695 main_msg(_("-display <display>\tRun vim on <display> (also: --display)"));
2696# ifdef HAVE_GTK2
2697 main_msg(_("--role <role>\tSet a unique role to identify the main window"));
2698# endif
2699 main_msg(_("--socketid <xid>\tOpen Vim inside another GTK widget"));
2700#endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00002701#ifdef FEAT_GUI_KDE
2702 mch_msg(_("\nArguments recognised by kvim (KDE version):\n"));
2703 main_msg(_("-black\t\tUse reverse video"));
2704#if QT_VERSION>=300
2705 main_msg(_("-tip\t\t\tDisplay the tip dialog on startup"));
2706 main_msg(_("-notip\t\tDisable the tip dialog"));
2707#endif
2708 main_msg(_("-font <font>\t\tUse <font> for normal text (also: -fn)"));
2709 main_msg(_("-geometry <geom>\tUse <geom> for initial geometry (also: -geom)"));
2710 main_msg(_("--display <display>\tRun vim on <display>"));
2711#endif
Bram Moolenaarb4210b32004-06-13 14:51:16 +00002712#ifdef FEAT_GUI_W32
2713 main_msg(_("-P <parent title>\tOpen Vim inside parent application"));
2714#endif
2715
2716#ifdef FEAT_GUI_GNOME
2717 /* Gnome gives extra messages for --help if we continue, but not for -h. */
2718 if (gui.starting)
2719 mch_msg("\n");
2720 else
2721#endif
2722 mch_exit(0);
2723}
2724
2725#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
2726/*
2727 * Check the result of the ATTENTION dialog:
2728 * When "Quit" selected, exit Vim.
2729 * When "Recover" selected, recover the file.
2730 */
2731 static void
2732check_swap_exists_action()
2733{
2734 if (swap_exists_action == SEA_QUIT)
2735 getout(1);
2736 handle_swap_exists(NULL);
2737}
2738#endif
2739
2740#if defined(STARTUPTIME) || defined(PROTO)
2741static void time_diff __ARGS((struct timeval *then, struct timeval *now));
2742
2743static struct timeval prev_timeval;
2744
2745/*
2746 * Save the previous time before doing something that could nest.
2747 * set "*tv_rel" to the time elapsed so far.
2748 */
2749 void
2750time_push(tv_rel, tv_start)
2751 void *tv_rel, *tv_start;
2752{
2753 *((struct timeval *)tv_rel) = prev_timeval;
2754 gettimeofday(&prev_timeval, NULL);
2755 ((struct timeval *)tv_rel)->tv_usec = prev_timeval.tv_usec
2756 - ((struct timeval *)tv_rel)->tv_usec;
2757 ((struct timeval *)tv_rel)->tv_sec = prev_timeval.tv_sec
2758 - ((struct timeval *)tv_rel)->tv_sec;
2759 if (((struct timeval *)tv_rel)->tv_usec < 0)
2760 {
2761 ((struct timeval *)tv_rel)->tv_usec += 1000000;
2762 --((struct timeval *)tv_rel)->tv_sec;
2763 }
2764 *(struct timeval *)tv_start = prev_timeval;
2765}
2766
2767/*
2768 * Compute the previous time after doing something that could nest.
2769 * Subtract "*tp" from prev_timeval;
2770 * Note: The arguments are (void *) to avoid trouble with systems that don't
2771 * have struct timeval.
2772 */
2773 void
2774time_pop(tp)
2775 void *tp; /* actually (struct timeval *) */
2776{
2777 prev_timeval.tv_usec -= ((struct timeval *)tp)->tv_usec;
2778 prev_timeval.tv_sec -= ((struct timeval *)tp)->tv_sec;
2779 if (prev_timeval.tv_usec < 0)
2780 {
2781 prev_timeval.tv_usec += 1000000;
2782 --prev_timeval.tv_sec;
2783 }
2784}
2785
2786 static void
2787time_diff(then, now)
2788 struct timeval *then;
2789 struct timeval *now;
2790{
2791 long usec;
2792 long msec;
2793
2794 usec = now->tv_usec - then->tv_usec;
2795 msec = (now->tv_sec - then->tv_sec) * 1000L + usec / 1000L,
2796 usec = usec % 1000L;
2797 fprintf(time_fd, "%03ld.%03ld", msec, usec >= 0 ? usec : usec + 1000L);
2798}
2799
2800 void
2801time_msg(msg, tv_start)
2802 char *msg;
2803 void *tv_start; /* only for do_source: start time; actually
2804 (struct timeval *) */
2805{
2806 static struct timeval start;
2807 struct timeval now;
2808
2809 if (time_fd != NULL)
2810 {
2811 if (strstr(msg, "STARTING") != NULL)
2812 {
2813 gettimeofday(&start, NULL);
2814 prev_timeval = start;
2815 fprintf(time_fd, "\n\ntimes in msec\n");
2816 fprintf(time_fd, " clock self+sourced self: sourced script\n");
2817 fprintf(time_fd, " clock elapsed: other lines\n\n");
2818 }
2819 gettimeofday(&now, NULL);
2820 time_diff(&start, &now);
2821 if (((struct timeval *)tv_start) != NULL)
2822 {
2823 fprintf(time_fd, " ");
2824 time_diff(((struct timeval *)tv_start), &now);
2825 }
2826 fprintf(time_fd, " ");
2827 time_diff(&prev_timeval, &now);
2828 prev_timeval = now;
2829 fprintf(time_fd, ": %s\n", msg);
2830 }
2831}
2832
2833# ifdef WIN3264
2834/*
2835 * Windows doesn't have gettimeofday(), although it does have struct timeval.
2836 */
2837 int
2838gettimeofday(struct timeval *tv, char *dummy)
2839{
2840 long t = clock();
2841 tv->tv_sec = t / CLOCKS_PER_SEC;
2842 tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC;
2843 return 0;
2844}
2845# endif
2846
2847#endif
2848
2849#if defined(FEAT_CLIENTSERVER) || defined(PROTO)
2850
2851/*
2852 * Common code for the X command server and the Win32 command server.
2853 */
2854
2855static char_u *build_drop_cmd __ARGS((int filec, char **filev, int sendReply));
2856
2857 static void
2858cmdsrv_main(argc, argv, serverName_arg, serverStr)
2859 int *argc;
2860 char **argv;
2861 char_u *serverName_arg;
2862 char_u **serverStr;
2863{
2864 char_u *res;
2865 int i;
2866 char_u *sname;
2867 int ret;
2868 int didone = FALSE;
2869 int exiterr = 0;
2870 char **newArgV = argv + 1;
2871 int newArgC = 1,
2872 Argc = *argc;
2873 int argtype;
2874#define ARGTYPE_OTHER 0
2875#define ARGTYPE_EDIT 1
2876#define ARGTYPE_EDIT_WAIT 2
2877#define ARGTYPE_SEND 3
2878 int silent = FALSE;
2879# ifndef FEAT_X11
2880 HWND srv;
2881# else
2882 Window srv;
2883
2884 setup_term_clip();
2885# endif
2886
2887 sname = serverMakeName(serverName_arg, argv[0]);
2888 if (sname == NULL)
2889 return;
2890
2891 /*
2892 * Execute the command server related arguments and remove them
2893 * from the argc/argv array; We may have to return into main()
2894 */
2895 for (i = 1; i < Argc; i++)
2896 {
2897 res = NULL;
2898 if (STRCMP(argv[i], "--") == 0) /* end of options */
2899 {
2900 for (; i < *argc; i++)
2901 {
2902 *newArgV++ = argv[i];
2903 newArgC++;
2904 }
2905 break;
2906 }
2907
2908 if (STRICMP(argv[i], "--remote") == 0)
2909 argtype = ARGTYPE_EDIT;
2910 else if (STRICMP(argv[i], "--remote-silent") == 0)
2911 {
2912 argtype = ARGTYPE_EDIT;
2913 silent = TRUE;
2914 }
2915 else if (STRICMP(argv[i], "--remote-wait") == 0)
2916 argtype = ARGTYPE_EDIT_WAIT;
2917 else if (STRICMP(argv[i], "--remote-wait-silent") == 0)
2918 {
2919 argtype = ARGTYPE_EDIT_WAIT;
2920 silent = TRUE;
2921 }
2922 else if (STRICMP(argv[i], "--remote-send") == 0)
2923 argtype = ARGTYPE_SEND;
2924 else
2925 argtype = ARGTYPE_OTHER;
2926 if (argtype != ARGTYPE_OTHER)
2927 {
2928 if (i == *argc - 1)
2929 mainerr_arg_missing((char_u *)argv[i]);
2930 if (argtype == ARGTYPE_SEND)
2931 {
2932 *serverStr = (char_u *)argv[i + 1];
2933 i++;
2934 }
2935 else
2936 {
2937 *serverStr = build_drop_cmd(*argc - i - 1, argv + i + 1,
2938 argtype == ARGTYPE_EDIT_WAIT);
2939 if (*serverStr == NULL)
2940 {
2941 /* Probably out of memory, exit. */
2942 didone = TRUE;
2943 exiterr = 1;
2944 break;
2945 }
2946 Argc = i;
2947 }
2948# ifdef FEAT_X11
2949 if (xterm_dpy == NULL)
2950 {
2951 mch_errmsg(_("No display"));
2952 ret = -1;
2953 }
2954 else
2955 ret = serverSendToVim(xterm_dpy, sname, *serverStr,
2956 NULL, &srv, 0, 0, silent);
2957# else
2958 /* Win32 always works? */
2959 ret = serverSendToVim(sname, *serverStr, NULL, &srv, 0, silent);
2960# endif
2961 if (ret < 0)
2962 {
2963 if (argtype == ARGTYPE_SEND)
2964 {
2965 /* Failed to send, abort. */
2966 mch_errmsg(_(": Send failed.\n"));
2967 didone = TRUE;
2968 exiterr = 1;
2969 }
2970 else if (!silent)
2971 /* Let vim start normally. */
2972 mch_errmsg(_(": Send failed. Trying to execute locally\n"));
2973 break;
2974 }
2975
2976# ifdef FEAT_GUI_W32
2977 /* Guess that when the server name starts with "g" it's a GUI
2978 * server, which we can bring to the foreground here.
2979 * Foreground() in the server doesn't work very well. */
2980 if (argtype != ARGTYPE_SEND && TOUPPER_ASC(*sname) == 'G')
2981 SetForegroundWindow(srv);
2982# endif
2983
2984 /*
2985 * For --remote-wait: Wait until the server did edit each
2986 * file. Also detect that the server no longer runs.
2987 */
2988 if (ret >= 0 && argtype == ARGTYPE_EDIT_WAIT)
2989 {
2990 int numFiles = *argc - i - 1;
2991 int j;
2992 char_u *done = alloc(numFiles);
2993 char_u *p;
2994# ifdef FEAT_GUI_W32
2995 NOTIFYICONDATA ni;
2996 int count = 0;
2997 extern HWND message_window;
2998# endif
2999
3000 if (numFiles > 0 && argv[i + 1][0] == '+')
3001 /* Skip "+cmd" argument, don't wait for it to be edited. */
3002 --numFiles;
3003
3004# ifdef FEAT_GUI_W32
3005 ni.cbSize = sizeof(ni);
3006 ni.hWnd = message_window;
3007 ni.uID = 0;
3008 ni.uFlags = NIF_ICON|NIF_TIP;
3009 ni.hIcon = LoadIcon((HINSTANCE)GetModuleHandle(0), "IDR_VIM");
3010 sprintf(ni.szTip, _("%d of %d edited"), count, numFiles);
3011 Shell_NotifyIcon(NIM_ADD, &ni);
3012# endif
3013
3014 /* Wait for all files to unload in remote */
3015 memset(done, 0, numFiles);
3016 while (memchr(done, 0, numFiles) != NULL)
3017 {
3018# ifdef WIN32
3019 p = serverGetReply(srv, NULL, TRUE, TRUE);
3020 if (p == NULL)
3021 break;
3022# else
3023 if (serverReadReply(xterm_dpy, srv, &p, TRUE) < 0)
3024 break;
3025# endif
3026 j = atoi((char *)p);
3027 if (j >= 0 && j < numFiles)
3028 {
3029# ifdef FEAT_GUI_W32
3030 ++count;
3031 sprintf(ni.szTip, _("%d of %d edited"),
3032 count, numFiles);
3033 Shell_NotifyIcon(NIM_MODIFY, &ni);
3034# endif
3035 done[j] = 1;
3036 }
3037 }
3038# ifdef FEAT_GUI_W32
3039 Shell_NotifyIcon(NIM_DELETE, &ni);
3040# endif
3041 }
3042 }
3043 else if (STRICMP(argv[i], "--remote-expr") == 0)
3044 {
3045 if (i == *argc - 1)
3046 mainerr_arg_missing((char_u *)argv[i]);
3047# ifdef WIN32
3048 /* Win32 always works? */
3049 if (serverSendToVim(sname, (char_u *)argv[i + 1],
3050 &res, NULL, 1, FALSE) < 0)
3051# else
3052 if (xterm_dpy == NULL)
3053 mch_errmsg(_("No display: Send expression failed.\n"));
3054 else if (serverSendToVim(xterm_dpy, sname, (char_u *)argv[i + 1],
3055 &res, NULL, 1, 1, FALSE) < 0)
3056# endif
3057 {
3058 if (res != NULL && *res != NUL)
3059 {
3060 /* Output error from remote */
3061 mch_errmsg((char *)res);
3062 vim_free(res);
3063 res = NULL;
3064 }
3065 mch_errmsg(_(": Send expression failed.\n"));
3066 }
3067 }
3068 else if (STRICMP(argv[i], "--serverlist") == 0)
3069 {
3070# ifdef WIN32
3071 /* Win32 always works? */
3072 res = serverGetVimNames();
3073# else
3074 if (xterm_dpy != NULL)
3075 res = serverGetVimNames(xterm_dpy);
3076# endif
3077 if (called_emsg)
3078 mch_errmsg("\n");
3079 }
3080 else if (STRICMP(argv[i], "--servername") == 0)
3081 {
3082 /* Alredy processed. Take it out of the command line */
3083 i++;
3084 continue;
3085 }
3086 else
3087 {
3088 *newArgV++ = argv[i];
3089 newArgC++;
3090 continue;
3091 }
3092 didone = TRUE;
3093 if (res != NULL && *res != NUL)
3094 {
3095 mch_msg((char *)res);
3096 if (res[STRLEN(res) - 1] != '\n')
3097 mch_msg("\n");
3098 }
3099 vim_free(res);
3100 }
3101
3102 if (didone)
3103 {
3104 display_errors(); /* display any collected messages */
3105 exit(exiterr); /* Mission accomplished - get out */
3106 }
3107
3108 /* Return back into main() */
3109 *argc = newArgC;
3110 vim_free(sname);
3111}
3112
3113/*
3114 * Build a ":drop" command to send to a Vim server.
3115 */
3116 static char_u *
3117build_drop_cmd(filec, filev, sendReply)
3118 int filec;
3119 char **filev;
3120 int sendReply;
3121{
3122 garray_T ga;
3123 int i;
3124 char_u *inicmd = NULL;
3125 char_u *p;
3126 char_u cwd[MAXPATHL];
3127
3128 if (filec > 0 && filev[0][0] == '+')
3129 {
3130 inicmd = (char_u *)filev[0] + 1;
3131 filev++;
3132 filec--;
3133 }
3134 /* Check if we have at least one argument. */
3135 if (filec <= 0)
3136 mainerr_arg_missing((char_u *)filev[-1]);
3137 if (mch_dirname(cwd, MAXPATHL) != OK)
3138 return NULL;
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00003139 if ((p = vim_strsave_escaped_ext(cwd, PATH_ESC_CHARS, '\\', TRUE)) == NULL)
Bram Moolenaarb4210b32004-06-13 14:51:16 +00003140 return NULL;
3141 ga_init2(&ga, 1, 100);
3142 ga_concat(&ga, (char_u *)"<C-\\><C-N>:cd ");
3143 ga_concat(&ga, p);
3144 /* Call inputsave() so that a prompt for an encryption key works. */
3145 ga_concat(&ga, (char_u *)"<CR>:if exists('*inputsave')|call inputsave()|endif|drop");
3146 vim_free(p);
3147 for (i = 0; i < filec; i++)
3148 {
3149 /* On Unix the shell has already expanded the wildcards, don't want to
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003150 * do it again in the Vim server. On MS-Windows only escape
3151 * non-wildcard characters. */
Bram Moolenaarb4210b32004-06-13 14:51:16 +00003152 p = vim_strsave_escaped((char_u *)filev[i],
3153#ifdef UNIX
3154 PATH_ESC_CHARS
3155#else
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003156 (char_u *)" \t%#"
Bram Moolenaarb4210b32004-06-13 14:51:16 +00003157#endif
3158 );
3159 if (p == NULL)
3160 {
3161 vim_free(ga.ga_data);
3162 return NULL;
3163 }
3164 ga_concat(&ga, (char_u *)" ");
3165 ga_concat(&ga, p);
3166 vim_free(p);
3167 }
3168 /* The :drop commands goes to Insert mode when 'insertmode' is set, use
3169 * CTRL-\ CTRL-N again. */
3170 ga_concat(&ga, (char_u *)"|if exists('*inputrestore')|call inputrestore()|endif<CR>");
3171 ga_concat(&ga, (char_u *)"<C-\\><C-N>:cd -");
3172 if (sendReply)
3173 ga_concat(&ga, (char_u *)"<CR>:call SetupRemoteReplies()");
3174 ga_concat(&ga, (char_u *)"<CR>:");
3175 if (inicmd != NULL)
3176 {
3177 /* Can't use <CR> after "inicmd", because an "startinsert" would cause
3178 * the following commands to be inserted as text. Use a "|",
3179 * hopefully "inicmd" does allow this... */
3180 ga_concat(&ga, inicmd);
3181 ga_concat(&ga, (char_u *)"|");
3182 }
3183 /* Bring the window to the foreground, goto Insert mode when 'im' set and
3184 * clear command line. */
Bram Moolenaar567e4de2004-12-31 21:01:02 +00003185 ga_concat(&ga, (char_u *)"cal foreground()|if &im|star|en|redr|f<CR>");
Bram Moolenaarb4210b32004-06-13 14:51:16 +00003186 ga_append(&ga, NUL);
3187 return ga.ga_data;
3188}
3189
3190/*
3191 * Replace termcodes such as <CR> and insert as key presses if there is room.
3192 */
3193 void
3194server_to_input_buf(str)
3195 char_u *str;
3196{
3197 char_u *ptr = NULL;
3198 char_u *cpo_save = p_cpo;
3199
3200 /* Set 'cpoptions' the way we want it.
3201 * B set - backslashes are *not* treated specially
3202 * k set - keycodes are *not* reverse-engineered
3203 * < unset - <Key> sequences *are* interpreted
3204 * The last parameter of replace_termcodes() is TRUE so that the <lt>
3205 * sequence is recognised - needed for a real backslash.
3206 */
3207 p_cpo = (char_u *)"Bk";
3208 str = replace_termcodes((char_u *)str, &ptr, FALSE, TRUE);
3209 p_cpo = cpo_save;
3210
3211 if (*ptr != NUL) /* trailing CTRL-V results in nothing */
3212 {
3213 /*
3214 * Add the string to the input stream.
3215 * Can't use add_to_input_buf() here, we now have K_SPECIAL bytes.
3216 *
3217 * First clear typed characters from the typeahead buffer, there could
3218 * be half a mapping there. Then append to the existing string, so
3219 * that multiple commands from a client are concatenated.
3220 */
3221 if (typebuf.tb_maplen < typebuf.tb_len)
3222 del_typebuf(typebuf.tb_len - typebuf.tb_maplen, typebuf.tb_maplen);
3223 (void)ins_typebuf(str, REMAP_NONE, typebuf.tb_len, TRUE, FALSE);
3224
3225 /* Let input_available() know we inserted text in the typeahead
3226 * buffer. */
3227 received_from_client = TRUE;
3228 }
3229 vim_free((char_u *)ptr);
3230}
3231
3232/*
3233 * Evaluate an expression that the client sent to a string.
3234 * Handles disabling error messages and disables debugging, otherwise Vim
3235 * hangs, waiting for "cont" to be typed.
3236 */
3237 char_u *
3238eval_client_expr_to_string(expr)
3239 char_u *expr;
3240{
3241 char_u *res;
3242 int save_dbl = debug_break_level;
3243 int save_ro = redir_off;
3244
3245 debug_break_level = -1;
3246 redir_off = 0;
3247 ++emsg_skip;
3248
3249 res = eval_to_string(expr, NULL);
3250
3251 debug_break_level = save_dbl;
3252 redir_off = save_ro;
3253 --emsg_skip;
3254
3255 return res;
3256}
3257
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00003258/*
3259 * If conversion is needed, convert "data" from "client_enc" to 'encoding' and
3260 * return an allocated string. Otherwise return "data".
3261 * "*tofree" is set to the result when it needs to be freed later.
3262 */
3263/*ARGSUSED*/
3264 char_u *
3265serverConvert(client_enc, data, tofree)
3266 char_u *client_enc;
3267 char_u *data;
3268 char_u **tofree;
3269{
3270 char_u *res = data;
3271
3272 *tofree = NULL;
3273# ifdef FEAT_MBYTE
3274 if (client_enc != NULL && p_enc != NULL)
3275 {
3276 vimconv_T vimconv;
3277
3278 vimconv.vc_type = CONV_NONE;
3279 if (convert_setup(&vimconv, client_enc, p_enc) != FAIL
3280 && vimconv.vc_type != CONV_NONE)
3281 {
3282 res = string_convert(&vimconv, data, NULL);
3283 if (res == NULL)
3284 res = data;
3285 else
3286 *tofree = res;
3287 }
3288 convert_setup(&vimconv, NULL, NULL);
3289 }
3290# endif
3291 return res;
3292}
3293
Bram Moolenaarb4210b32004-06-13 14:51:16 +00003294
3295/*
3296 * Make our basic server name: use the specified "arg" if given, otherwise use
3297 * the tail of the command "cmd" we were started with.
3298 * Return the name in allocated memory. This doesn't include a serial number.
3299 */
3300 static char_u *
3301serverMakeName(arg, cmd)
3302 char_u *arg;
3303 char *cmd;
3304{
3305 char_u *p;
3306
3307 if (arg != NULL && *arg != NUL)
3308 p = vim_strsave_up(arg);
3309 else
3310 {
3311 p = vim_strsave_up(gettail((char_u *)cmd));
3312 /* Remove .exe or .bat from the name. */
3313 if (p != NULL && vim_strchr(p, '.') != NULL)
3314 *vim_strchr(p, '.') = NUL;
3315 }
3316 return p;
3317}
3318#endif /* FEAT_CLIENTSERVER */
3319
3320/*
3321 * When FEAT_FKMAP is defined, also compile the Farsi source code.
3322 */
3323#if defined(FEAT_FKMAP) || defined(PROTO)
3324# include "farsi.c"
3325#endif
3326
3327/*
3328 * When FEAT_ARABIC is defined, also compile the Arabic source code.
3329 */
3330#if defined(FEAT_ARABIC) || defined(PROTO)
3331# include "arabic.c"
3332#endif