-
Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathmain.c
4239 lines (3874 loc) · 110 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
#define EXTERN
#include "vim.h"
#ifdef SPAWNO
# include <spawno.h> /* special MS-DOS swapping library */
#endif
#ifdef __CYGWIN__
# ifndef WIN32
# include <cygwin/version.h>
# include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() and/or
* cygwin_conv_path() */
# endif
# include <limits.h>
#endif
/* Maximum number of commands from + or -c arguments. */
#define MAX_ARG_CMDS 10
/* values for "window_layout" */
#define WIN_HOR 1 /* "-o" horizontally split windows */
#define WIN_VER 2 /* "-O" vertically split windows */
#define WIN_TABS 3 /* "-p" windows on tab pages */
/* Struct for various parameters passed between main() and other functions. */
typedef struct
{
int argc;
char **argv;
int evim_mode; /* started as "evim" */
char_u *use_vimrc; /* vimrc from -u argument */
int n_commands; /* no. of commands from + or -c */
char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c arg. */
char_u cmds_tofree[MAX_ARG_CMDS]; /* commands that need free() */
int n_pre_commands; /* no. of commands from --cmd */
char_u *pre_commands[MAX_ARG_CMDS]; /* commands from --cmd argument */
int edit_type; /* type of editing to do */
char_u *tagname; /* tag from -t argument */
#ifdef FEAT_QUICKFIX
char_u *use_ef; /* 'errorfile' from -q argument */
#endif
int want_full_screen;
int stdout_isatty; /* is stdout a terminal? */
char_u *term; /* specified terminal name */
#ifdef FEAT_CRYPT
int ask_for_key; /* -x argument */
#endif
int no_swap_file; /* "-n" argument used */
#ifdef FEAT_EVAL
int use_debug_break_level;
#endif
#ifdef FEAT_WINDOWS
int window_count; /* number of windows to use */
int window_layout; /* 0, WIN_HOR, WIN_VER or WIN_TABS */
#endif
#ifdef FEAT_CLIENTSERVER
int serverArg; /* TRUE when argument for a server */
char_u *serverName_arg; /* cmdline arg for server name */
char_u *serverStr; /* remote server command */
char_u *serverStrEnc; /* encoding of serverStr */
char_u *servername; /* allocated name for our server */
#endif
#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
int literal; /* don't expand file names */
#endif
#ifdef MSWIN
int full_path; /* file name argument was full path */
#endif
#ifdef FEAT_DIFF
int diff_mode; /* start with 'diff' set */
#endif
} mparm_T;
/* Values for edit_type. */
#define EDIT_NONE 0 /* no edit type yet */
#define EDIT_FILE 1 /* file name argument[s] given, use argument list */
#define EDIT_STDIN 2 /* read file from stdin */
#define EDIT_TAG 3 /* tag name argument given, use tagname */
#define EDIT_QF 4 /* start in quickfix mode */
#if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN)
static int file_owned __ARGS((char *fname));
#endif
static void mainerr __ARGS((int, char_u *));
#ifndef NO_VIM_MAIN
static void main_msg __ARGS((char *s));
static void usage __ARGS((void));
static int get_number_arg __ARGS((char_u *p, int *idx, int def));
# if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
static void init_locale __ARGS((void));
# endif
static void parse_command_name __ARGS((mparm_T *parmp));
static void early_arg_scan __ARGS((mparm_T *parmp));
static void command_line_scan __ARGS((mparm_T *parmp));
static void check_tty __ARGS((mparm_T *parmp));
static void read_stdin __ARGS((void));
static void create_windows __ARGS((mparm_T *parmp));
# ifdef FEAT_WINDOWS
static void edit_buffers __ARGS((mparm_T *parmp));
# endif
static void exe_pre_commands __ARGS((mparm_T *parmp));
static void exe_commands __ARGS((mparm_T *parmp));
static void source_startup_scripts __ARGS((mparm_T *parmp));
static void main_start_gui __ARGS((void));
# if defined(HAS_SWAP_EXISTS_ACTION)
static void check_swap_exists_action __ARGS((void));
# endif
# if defined(FEAT_CLIENTSERVER) || defined(PROTO)
static void exec_on_server __ARGS((mparm_T *parmp));
static void prepare_server __ARGS((mparm_T *parmp));
static void cmdsrv_main __ARGS((int *argc, char **argv, char_u *serverName_arg, char_u **serverStr));
static char_u *serverMakeName __ARGS((char_u *arg, char *cmd));
# endif
#endif
/*
* Different types of error messages.
*/
static char *(main_errors[]) =
{
N_("Unknown option argument"),
#define ME_UNKNOWN_OPTION 0
N_("Too many edit arguments"),
#define ME_TOO_MANY_ARGS 1
N_("Argument missing after"),
#define ME_ARG_MISSING 2
N_("Garbage after option argument"),
#define ME_GARBAGE 3
N_("Too many \"+command\", \"-c command\" or \"--cmd command\" arguments"),
#define ME_EXTRA_CMD 4
N_("Invalid argument for"),
#define ME_INVALID_ARG 5
};
#ifndef PROTO /* don't want a prototype for main() */
#ifndef NO_VIM_MAIN /* skip this for unittests */
int
# ifdef VIMDLL
_export
# endif
# ifdef FEAT_GUI_MSWIN
# ifdef __BORLANDC__
_cdecl
# endif
VimMain
# else
main
# endif
(argc, argv)
int argc;
char **argv;
{
char_u *fname = NULL; /* file name from command line */
mparm_T params; /* various parameters passed between
* main() and other functions. */
#ifdef STARTUPTIME
int i;
#endif
#ifdef FEAT_GUI_MACVIM
// Cocoa needs an NSAutoreleasePool in place or it will leak memory.
// This particular pool will hold autorelease objects created during
// initialization.
void *autoreleasePool = gui_macvim_new_autoreleasepool();
#endif
/*
* Do any system-specific initialisations. These can NOT use IObuff or
* NameBuff. Thus emsg2() cannot be called!
*/
mch_early_init();
/* Many variables are in "params" so that we can pass them to invoked
* functions without a lot of arguments. "argc" and "argv" are also
* copied, so that they can be changed. */
vim_memset(¶ms, 0, sizeof(params));
params.argc = argc;
params.argv = argv;
params.want_full_screen = TRUE;
#ifdef FEAT_EVAL
params.use_debug_break_level = -1;
#endif
#ifdef FEAT_WINDOWS
params.window_count = -1;
#endif
#ifdef FEAT_RUBY
{
int ruby_stack_start;
vim_ruby_init((void *)&ruby_stack_start);
}
#endif
#ifdef FEAT_TCL
vim_tcl_init(params.argv[0]);
#endif
#ifdef MEM_PROFILE
atexit(vim_mem_profile_dump);
#endif
#ifdef STARTUPTIME
for (i = 1; i < argc; ++i)
{
if (STRICMP(argv[i], "--startuptime") == 0 && i + 1 < argc)
{
time_fd = mch_fopen(argv[i + 1], "a");
TIME_MSG("--- VIM STARTING ---");
break;
}
}
#endif
starttime = time(NULL);
#ifdef __EMX__
_wildcard(¶ms.argc, ¶ms.argv);
#endif
#ifdef FEAT_MBYTE
(void)mb_init(); /* init mb_bytelen_tab[] to ones */
#endif
#ifdef FEAT_EVAL
eval_init(); /* init global variables */
#endif
#ifdef __QNXNTO__
qnx_init(); /* PhAttach() for clipboard, (and gui) */
#endif
#ifdef MAC_OS_CLASSIC
/* Prepare for possibly starting GUI sometime */
/* Macintosh needs this before any memory is allocated. */
gui_prepare(¶ms.argc, params.argv);
TIME_MSG("GUI prepared");
#endif
/* Init the table of Normal mode commands. */
init_normal_cmds();
#if defined(HAVE_DATE_TIME) && defined(VMS) && defined(VAXC)
make_version(); /* Construct the long version string. */
#endif
/*
* Allocate space for the generic buffers (needed for set_init_1() and
* EMSG2()).
*/
if ((IObuff = alloc(IOSIZE)) == NULL
|| (NameBuff = alloc(MAXPATHL)) == NULL)
mch_exit(0);
TIME_MSG("Allocated generic buffers");
#ifdef NBDEBUG
/* Wait a moment for debugging NetBeans. Must be after allocating
* NameBuff. */
nbdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL");
nbdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20);
TIME_MSG("NetBeans debug wait");
#endif
#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
/*
* Setup to use the current locale (for ctype() and many other things).
* NOTE: Translated messages with encodings other than latin1 will not
* work until set_init_1() has been called!
*/
init_locale();
TIME_MSG("locale set");
#endif
#ifdef FEAT_GUI
gui.dofork = TRUE; /* default is to use fork() */
#endif
/*
* Do a first scan of the arguments in "argv[]":
* -display or --display
* --server...
* --socketid
* --windowid
*/
early_arg_scan(¶ms);
#ifdef FEAT_SUN_WORKSHOP
findYourself(params.argv[0]);
#endif
#if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC)
/* Prepare for possibly starting GUI sometime */
gui_prepare(¶ms.argc, params.argv);
TIME_MSG("GUI prepared");
#endif
#ifdef FEAT_CLIPBOARD
clip_init(FALSE); /* Initialise clipboard stuff */
TIME_MSG("clipboard setup");
#endif
/*
* Check if we have an interactive window.
* On the Amiga: If there is no window, we open one with a newcli command
* (needed for :! to * work). mch_check_win() will also handle the -d or
* -dev argument.
*/
params.stdout_isatty = (mch_check_win(params.argc, params.argv) != FAIL);
TIME_MSG("window checked");
/*
* Allocate the first window and buffer.
* Can't do anything without it, exit when it fails.
*/
if (win_alloc_first() == FAIL)
mch_exit(0);
init_yank(); /* init yank buffers */
alist_init(&global_alist); /* Init the argument list to empty. */
global_alist.id = 0;
/*
* Set the default values for the options.
* NOTE: Non-latin1 translated messages are working only after this,
* because this is where "has_mbyte" will be set, which is used by
* msg_outtrans_len_attr().
* First find out the home directory, needed to expand "~" in options.
*/
init_homedir(); /* find real value of $HOME */
set_init_1();
TIME_MSG("inits 1");
#ifdef FEAT_EVAL
set_lang_var(); /* set v:lang and v:ctype */
#endif
#ifdef FEAT_CLIENTSERVER
/*
* Do the client-server stuff, unless "--servername ''" was used.
* This may exit Vim if the command was sent to the server.
*/
exec_on_server(¶ms);
#endif
/*
* Figure out the way to work from the command name argv[0].
* "vimdiff" starts diff mode, "rvim" sets "restricted", etc.
*/
parse_command_name(¶ms);
/*
* Process the command line arguments. File names are put in the global
* argument list "global_alist".
*/
command_line_scan(¶ms);
TIME_MSG("parsing arguments");
#if defined(MACOS_X) && defined(FEAT_GUI)
if (gui.starting && gui.dofork)
macosx_fork(); /* Never returns */
# ifdef FEAT_GUI_MACVIM
gui_macvim_after_fork_init();
# endif
#endif
/*
* On some systems, when we compile with the GUI, we always use it. On Mac
* there is no terminal version, and on Windows we can't fork one off with
* :gui.
*/
#ifdef ALWAYS_USE_GUI
gui.starting = TRUE;
#else
# if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
/*
* Check if the GUI can be started. Reset gui.starting if not.
* Don't know about other systems, stay on the safe side and don't check.
*/
if (gui.starting)
{
if (gui_init_check() == FAIL)
{
gui.starting = FALSE;
/* When running "evim" or "gvim -y" we need the menus, exit if we
* don't have them. */
if (params.evim_mode)
mch_exit(1);
}
}
# endif
#endif
if (GARGCOUNT > 0)
{
#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
/*
* Expand wildcards in file names.
*/
if (!params.literal)
{
/* Temporarily add '(' and ')' to 'isfname'. These are valid
* filename characters but are excluded from 'isfname' to make
* "gf" work on a file name in parenthesis (e.g.: see vim.h). */
do_cmdline_cmd((char_u *)":set isf+=(,)");
alist_expand(NULL, 0);
do_cmdline_cmd((char_u *)":set isf&");
}
#endif
fname = alist_name(&GARGLIST[0]);
}
#if defined(WIN32) && defined(FEAT_MBYTE)
{
extern void set_alist_count(void);
/* Remember the number of entries in the argument list. If it changes
* we don't react on setting 'encoding'. */
set_alist_count();
}
#endif
#ifdef MSWIN
if (GARGCOUNT == 1 && params.full_path)
{
/*
* If there is one filename, fully qualified, we have very probably
* been invoked from explorer, so change to the file's directory.
* Hint: to avoid this when typing a command use a forward slash.
* If the cd fails, it doesn't matter.
*/
(void)vim_chdirfile(fname);
}
#endif
TIME_MSG("expanding arguments");
#ifdef FEAT_DIFF
if (params.diff_mode && params.window_count == -1)
params.window_count = 0; /* open up to 3 windows */
#endif
/* Don't redraw until much later. */
++RedrawingDisabled;
/*
* When listing swap file names, don't do cursor positioning et. al.
*/
if (recoverymode && fname == NULL)
params.want_full_screen = FALSE;
/*
* When certain to start the GUI, don't check capabilities of terminal.
* For GTK we can't be sure, but when started from the desktop it doesn't
* make sense to try using a terminal.
*/
#if defined(ALWAYS_USE_GUI) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) \
|| defined(FEAT_GUI_MACVIM)
if (gui.starting
# ifdef FEAT_GUI_GTK
&& !isatty(2)
# endif
)
params.want_full_screen = FALSE;
#endif
#if defined(FEAT_GUI_MAC) && defined(MACOS_X_UNIX)
/* When the GUI is started from Finder, need to display messages in a
* message box. isatty(2) returns TRUE anyway, thus we need to check the
* name to know we're not started from a terminal. */
if (gui.starting && (!isatty(2) || strcmp("/dev/console", ttyname(2)) == 0))
{
params.want_full_screen = FALSE;
/* Avoid always using "/" as the current directory. Note that when
* started from Finder the arglist will be filled later in
* HandleODocAE() and "fname" will be NULL. */
if (getcwd((char *)NameBuff, MAXPATHL) != NULL
&& STRCMP(NameBuff, "/") == 0)
{
if (fname != NULL)
(void)vim_chdirfile(fname);
else
{
expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);
vim_chdir(NameBuff);
}
}
}
#endif
/*
* mch_init() sets up the terminal (window) for use. This must be
* done after resetting full_screen, otherwise it may move the cursor
* (MSDOS).
* Note that we may use mch_exit() before mch_init()!
*/
mch_init();
TIME_MSG("shell init");
#ifdef USE_XSMP
/*
* For want of anywhere else to do it, try to connect to xsmp here.
* Fitting it in after gui_mch_init, but before gui_init (via termcapinit).
* Hijacking -X 'no X connection' to also disable XSMP connection as that
* has a similar delay upon failure.
* Only try if SESSION_MANAGER is set to something non-null.
*/
if (!x_no_connect)
{
char *p = getenv("SESSION_MANAGER");
if (p != NULL && *p != NUL)
{
xsmp_init();
TIME_MSG("xsmp init");
}
}
#endif
/*
* Print a warning if stdout is not a terminal.
*/
check_tty(¶ms);
/* This message comes before term inits, but after setting "silent_mode"
* when the input is not a tty. */
if (GARGCOUNT > 1 && !silent_mode)
printf(_("%d files to edit\n"), GARGCOUNT);
if (params.want_full_screen && !silent_mode)
{
termcapinit(params.term); /* set terminal name and get terminal
capabilities (will set full_screen) */
screen_start(); /* don't know where cursor is now */
TIME_MSG("Termcap init");
}
/*
* Set the default values for the options that use Rows and Columns.
*/
ui_get_shellsize(); /* inits Rows and Columns */
win_init_size();
#ifdef FEAT_DIFF
/* Set the 'diff' option now, so that it can be checked for in a .vimrc
* file. There is no buffer yet though. */
if (params.diff_mode)
diff_win_options(firstwin, FALSE);
#endif
cmdline_row = Rows - p_ch;
msg_row = cmdline_row;
screenalloc(FALSE); /* allocate screen buffers */
set_init_2();
TIME_MSG("inits 2");
msg_scroll = TRUE;
no_wait_return = TRUE;
init_mappings(); /* set up initial mappings */
init_highlight(TRUE, FALSE); /* set the default highlight groups */
TIME_MSG("init highlight");
#ifdef FEAT_EVAL
/* Set the break level after the terminal is initialized. */
debug_break_level = params.use_debug_break_level;
#endif
#ifdef FEAT_MZSCHEME
/*
* Newer version of MzScheme (Racket) require earlier (trampolined)
* initialisation via scheme_main_setup.
* Implement this by initialising it as early as possible
* and splitting off remaining Vim main into vim_main2
*/
{
/* Pack up preprocessed command line arguments.
* It is safe because Scheme does not access argc/argv. */
char *args[2];
args[0] = (char *)fname;
args[1] = (char *)¶ms;
return mzscheme_main(2, args);
}
}
#endif
#endif /* NO_VIM_MAIN */
/* vim_main2() needs to be produced when FEAT_MZSCHEME is defined even when
* NO_VIM_MAIN is defined. */
#ifdef FEAT_MZSCHEME
int
vim_main2(int argc UNUSED, char **argv UNUSED)
{
# ifndef NO_VIM_MAIN
char_u *fname = (char_u *)argv[0];
mparm_T params;
memcpy(¶ms, argv[1], sizeof(params));
# else
return 0;
}
# endif
#endif
#ifndef NO_VIM_MAIN
/* Execute --cmd arguments. */
exe_pre_commands(¶ms);
/* Source startup scripts. */
source_startup_scripts(¶ms);
#ifdef FEAT_EVAL
/*
* Read all the plugin files.
* Only when compiled with +eval, since most plugins need it.
*/
if (p_lpl)
{
# ifdef VMS /* Somehow VMS doesn't handle the "**". */
source_runtime((char_u *)"plugin/*.vim", TRUE);
# else
source_runtime((char_u *)"plugin/**/*.vim", TRUE);
# endif
TIME_MSG("loading plugins");
}
#endif
#ifdef FEAT_DIFF
/* Decide about window layout for diff mode after reading vimrc. */
if (params.diff_mode && params.window_layout == 0)
{
if (diffopt_horizontal())
params.window_layout = WIN_HOR; /* use horizontal split */
else
params.window_layout = WIN_VER; /* use vertical split */
}
#endif
/*
* Recovery mode without a file name: List swap files.
* This uses the 'dir' option, therefore it must be after the
* initializations.
*/
if (recoverymode && fname == NULL)
{
recover_names(NULL, TRUE, 0, NULL);
mch_exit(0);
}
/*
* Set a few option defaults after reading .vimrc files:
* 'title' and 'icon', Unix: 'shellpipe' and 'shellredir'.
*/
set_init_3();
TIME_MSG("inits 3");
/*
* "-n" argument: Disable swap file by setting 'updatecount' to 0.
* Note that this overrides anything from a vimrc file.
*/
if (params.no_swap_file)
p_uc = 0;
#ifdef FEAT_FKMAP
if (curwin->w_p_rl && p_altkeymap)
{
p_hkmap = FALSE; /* Reset the Hebrew keymap mode */
# ifdef FEAT_ARABIC
curwin->w_p_arab = FALSE; /* Reset the Arabic keymap mode */
# endif
p_fkmap = TRUE; /* Set the Farsi keymap mode */
}
#endif
#ifdef FEAT_GUI
if (gui.starting)
{
#if defined(UNIX) || defined(VMS)
/* When something caused a message from a vimrc script, need to output
* an extra newline before the shell prompt. */
if (did_emsg || msg_didout)
putchar('\n');
#endif
gui_start(); /* will set full_screen to TRUE */
TIME_MSG("starting GUI");
/* When running "evim" or "gvim -y" we need the menus, exit if we
* don't have them. */
if (!gui.in_use && params.evim_mode)
mch_exit(1);
}
#endif
#ifdef SPAWNO /* special MSDOS swapping library */
init_SPAWNO("", SWAP_ANY);
#endif
#ifdef FEAT_VIMINFO
/*
* Read in registers, history etc, but not marks, from the viminfo file.
* This is where v:oldfiles gets filled.
*/
if (*p_viminfo != NUL)
{
read_viminfo(NULL, VIF_WANT_INFO | VIF_GET_OLDFILES);
TIME_MSG("reading viminfo");
}
#endif
#ifdef FEAT_EVAL
/* It's better to make v:oldfiles an empty list than NULL. */
if (get_vim_var_list(VV_OLDFILES) == NULL)
set_vim_var_list(VV_OLDFILES, list_alloc());
#endif
#ifdef FEAT_QUICKFIX
/*
* "-q errorfile": Load the error file now.
* If the error file can't be read, exit before doing anything else.
*/
if (params.edit_type == EDIT_QF)
{
if (params.use_ef != NULL)
set_string_option_direct((char_u *)"ef", -1,
params.use_ef, OPT_FREE, SID_CARG);
vim_snprintf((char *)IObuff, IOSIZE, "cfile %s", p_ef);
if (qf_init(NULL, p_ef, p_efm, TRUE, IObuff) < 0)
{
out_char('\n');
mch_exit(3);
}
TIME_MSG("reading errorfile");
}
#endif
/*
* Start putting things on the screen.
* Scroll screen down before drawing over it
* Clear screen now, so file message will not be cleared.
*/
starting = NO_BUFFERS;
no_wait_return = FALSE;
if (!exmode_active)
msg_scroll = FALSE;
#ifdef FEAT_GUI
/*
* This seems to be required to make callbacks to be called now, instead
* of after things have been put on the screen, which then may be deleted
* when getting a resize callback.
* For the Mac this handles putting files dropped on the Vim icon to
* global_alist.
*/
if (gui.in_use)
{
# ifdef FEAT_SUN_WORKSHOP
if (!usingSunWorkShop)
# endif
gui_wait_for_chars(50L);
TIME_MSG("GUI delay");
}
#endif
#if defined(FEAT_GUI_PHOTON) && defined(FEAT_CLIPBOARD)
qnx_clip_init();
#endif
#if defined(MACOS_X) && defined(FEAT_CLIPBOARD)
clip_init(TRUE);
#endif
#ifdef FEAT_XCLIPBOARD
/* Start using the X clipboard, unless the GUI was started. */
# ifdef FEAT_GUI
if (!gui.in_use)
# endif
{
setup_term_clip();
TIME_MSG("setup clipboard");
}
#endif
#ifdef FEAT_CLIENTSERVER
/* Prepare for being a Vim server. */
prepare_server(¶ms);
#endif
/*
* If "-" argument given: Read file from stdin.
* Do this before starting Raw mode, because it may change things that the
* writing end of the pipe doesn't like, e.g., in case stdin and stderr
* are the same terminal: "cat | vim -".
* Using autocommands here may cause trouble...
*/
if (params.edit_type == EDIT_STDIN && !recoverymode)
read_stdin();
#if defined(UNIX) || defined(VMS)
/* When switching screens and something caused a message from a vimrc
* script, need to output an extra newline on exit. */
if ((did_emsg || msg_didout) && *T_TI != NUL)
newline_on_exit = TRUE;
#endif
/*
* When done something that is not allowed or error message call
* wait_return. This must be done before starttermcap(), because it may
* switch to another screen. It must be done after settmode(TMODE_RAW),
* because we want to react on a single key stroke.
* Call settmode and starttermcap here, so the T_KS and T_TI may be
* defined by termcapinit and redefined in .exrc.
*/
settmode(TMODE_RAW);
TIME_MSG("setting raw mode");
if (need_wait_return || msg_didany)
{
wait_return(TRUE);
TIME_MSG("waiting for return");
}
starttermcap(); /* start termcap if not done by wait_return() */
TIME_MSG("start termcap");
#if defined(FEAT_TERMRESPONSE) && defined(FEAT_MBYTE)
may_req_ambiguous_char_width();
#endif
#ifdef FEAT_MOUSE
setmouse(); /* may start using the mouse */
#endif
if (scroll_region)
scroll_region_reset(); /* In case Rows changed */
scroll_start(); /* may scroll the screen to the right position */
/*
* Don't clear the screen when starting in Ex mode, unless using the GUI.
*/
if (exmode_active
#ifdef FEAT_GUI
&& !gui.in_use
#endif
)
must_redraw = CLEAR;
else
{
screenclear(); /* clear screen */
TIME_MSG("clearing screen");
}
#ifdef FEAT_CRYPT
if (params.ask_for_key)
{
(void)blowfish_self_test();
(void)get_crypt_key(TRUE, TRUE);
TIME_MSG("getting crypt key");
}
#endif
no_wait_return = TRUE;
#ifdef FEAT_GUI_MACVIM
/* We want to delay calling this function for as long as possible, since it
* will result in faster startup for cached processes. However, we react
* before create_windows() so that we can open files by adding to the
* arglist. */
gui_macvim_wait_for_startup();
/* Since MacVim may receive the list of files to open via an Apple event
* (as opposed to from the command line) we must manually check to see if
* the window layout should be changed. */
gui_macvim_get_window_layout(¶ms.window_count, ¶ms.window_layout);
# ifdef MAC_CLIENTSERVER
// NOTE: Can't set server name at same time as WIN32 because gui.in_use
// isn't set then. Servers are only supported in GUI mode.
// Also, in case the above call blocks this process another Vim process may
// open in the meantime. If it did then it could be named e.g. VIM3
// whereas this may be VIM2, which looks weird.
if (params.servername != NULL && gui.in_use)
{
serverRegisterName(params.servername);
vim_free(params.servername);
params.servername = NULL;
}
# endif
#endif
/*
* Create the requested number of windows and edit buffers in them.
* Also does recovery if "recoverymode" set.
*/
create_windows(¶ms);
TIME_MSG("opening buffers");
#ifdef FEAT_EVAL
/* clear v:swapcommand */
set_vim_var_string(VV_SWAPCOMMAND, NULL, -1);
#endif
/* Ex starts at last line of the file */
if (exmode_active)
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
#ifdef FEAT_AUTOCMD
apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
TIME_MSG("BufEnter autocommands");
#endif
setpcmark();
#ifdef FEAT_QUICKFIX
/*
* When started with "-q errorfile" jump to first error now.
*/
if (params.edit_type == EDIT_QF)
{
qf_jump(NULL, 0, 0, FALSE);
TIME_MSG("jump to first error");
}
#endif
#ifdef FEAT_WINDOWS
/*
* If opened more than one window, start editing files in the other
* windows.
*/
edit_buffers(¶ms);
#endif
#ifdef FEAT_DIFF
if (params.diff_mode)
{
win_T *wp;
/* set options in each window for "vimdiff". */
for (wp = firstwin; wp != NULL; wp = wp->w_next)
diff_win_options(wp, TRUE);
}
#endif
/*
* Shorten any of the filenames, but only when absolute.
*/
shorten_fnames(FALSE);
/*
* Need to jump to the tag before executing the '-c command'.
* Makes "vim -c '/return' -t main" work.
*/
if (params.tagname != NULL)
{
#if defined(HAS_SWAP_EXISTS_ACTION)
swap_exists_did_quit = FALSE;
#endif
vim_snprintf((char *)IObuff, IOSIZE, "ta %s", params.tagname);
do_cmdline_cmd(IObuff);
TIME_MSG("jumping to tag");
#if defined(HAS_SWAP_EXISTS_ACTION)
/* If the user doesn't want to edit the file then we quit here. */
if (swap_exists_did_quit)
getout(1);
#endif
}
/* Execute any "+", "-c" and "-S" arguments. */
if (params.n_commands > 0)
exe_commands(¶ms);
RedrawingDisabled = 0;
redraw_all_later(NOT_VALID);
no_wait_return = FALSE;
starting = 0;
#ifdef FEAT_TERMRESPONSE
/* Requesting the termresponse is postponed until here, so that a "-c q"
* argument doesn't make it appear in the shell Vim was started from. */
may_req_termresponse();
#endif
/* start in insert mode */
if (p_im)
need_start_insertmode = TRUE;
#ifdef FEAT_AUTOCMD
apply_autocmds(EVENT_VIMENTER, NULL, NULL, FALSE, curbuf);
TIME_MSG("VimEnter autocommands");
#endif