Mercurial > vim
annotate src/main.c @ 4857:84a8d1ba81c3 v7.3.1175
updated for version 7.3.1175
Problem: Using isalpha() and isalnum() can be slow.
Solution: Use range checks. (Mike Williams)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 12 Jun 2013 17:12:24 +0200 |
parents | c9820396afb9 |
children | c4d4f0fc12b9 |
rev | line source |
---|---|
6 | 1 /* 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 #define EXTERN | |
11 #include "vim.h" | |
12 | |
13 #ifdef SPAWNO | |
242 | 14 # include <spawno.h> /* special MS-DOS swapping library */ |
6 | 15 #endif |
16 | |
17 #ifdef __CYGWIN__ | |
18 # ifndef WIN32 | |
1657 | 19 # include <cygwin/version.h> |
20 # include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() and/or | |
21 * cygwin_conv_path() */ | |
6 | 22 # endif |
23 # include <limits.h> | |
24 #endif | |
25 | |
443 | 26 /* Maximum number of commands from + or -c arguments. */ |
27 #define MAX_ARG_CMDS 10 | |
28 | |
673 | 29 /* values for "window_layout" */ |
30 #define WIN_HOR 1 /* "-o" horizontally split windows */ | |
31 #define WIN_VER 2 /* "-O" vertically split windows */ | |
32 #define WIN_TABS 3 /* "-p" windows on tab pages */ | |
33 | |
440 | 34 /* Struct for various parameters passed between main() and other functions. */ |
35 typedef struct | |
36 { | |
443 | 37 int argc; |
38 char **argv; | |
39 | |
40 int evim_mode; /* started as "evim" */ | |
41 char_u *use_vimrc; /* vimrc from -u argument */ | |
42 | |
43 int n_commands; /* no. of commands from + or -c */ | |
44 char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c arg. */ | |
45 char_u cmds_tofree[MAX_ARG_CMDS]; /* commands that need free() */ | |
46 int n_pre_commands; /* no. of commands from --cmd */ | |
47 char_u *pre_commands[MAX_ARG_CMDS]; /* commands from --cmd argument */ | |
48 | |
49 int edit_type; /* type of editing to do */ | |
50 char_u *tagname; /* tag from -t argument */ | |
51 #ifdef FEAT_QUICKFIX | |
52 char_u *use_ef; /* 'errorfile' from -q argument */ | |
53 #endif | |
54 | |
55 int want_full_screen; | |
56 int stdout_isatty; /* is stdout a terminal? */ | |
57 char_u *term; /* specified terminal name */ | |
58 #ifdef FEAT_CRYPT | |
59 int ask_for_key; /* -x argument */ | |
60 #endif | |
61 int no_swap_file; /* "-n" argument used */ | |
62 #ifdef FEAT_EVAL | |
63 int use_debug_break_level; | |
64 #endif | |
65 #ifdef FEAT_WINDOWS | |
66 int window_count; /* number of windows to use */ | |
673 | 67 int window_layout; /* 0, WIN_HOR, WIN_VER or WIN_TABS */ |
443 | 68 #endif |
69 | |
70 #ifdef FEAT_CLIENTSERVER | |
440 | 71 int serverArg; /* TRUE when argument for a server */ |
72 char_u *serverName_arg; /* cmdline arg for server name */ | |
443 | 73 char_u *serverStr; /* remote server command */ |
74 char_u *serverStrEnc; /* encoding of serverStr */ | |
75 char_u *servername; /* allocated name for our server */ | |
76 #endif | |
77 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) | |
78 int literal; /* don't expand file names */ | |
79 #endif | |
80 #ifdef MSWIN | |
81 int full_path; /* file name argument was full path */ | |
82 #endif | |
83 #ifdef FEAT_DIFF | |
84 int diff_mode; /* start with 'diff' set */ | |
85 #endif | |
440 | 86 } mparm_T; |
87 | |
443 | 88 /* Values for edit_type. */ |
89 #define EDIT_NONE 0 /* no edit type yet */ | |
90 #define EDIT_FILE 1 /* file name argument[s] given, use argument list */ | |
91 #define EDIT_STDIN 2 /* read file from stdin */ | |
92 #define EDIT_TAG 3 /* tag name argument given, use tagname */ | |
93 #define EDIT_QF 4 /* start in quickfix mode */ | |
94 | |
2730 | 95 #if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN) |
6 | 96 static int file_owned __ARGS((char *fname)); |
97 #endif | |
98 static void mainerr __ARGS((int, char_u *)); | |
2730 | 99 #ifndef NO_VIM_MAIN |
6 | 100 static void main_msg __ARGS((char *s)); |
101 static void usage __ARGS((void)); | |
102 static int get_number_arg __ARGS((char_u *p, int *idx, int def)); | |
2730 | 103 # if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
443 | 104 static void init_locale __ARGS((void)); |
2730 | 105 # endif |
443 | 106 static void parse_command_name __ARGS((mparm_T *parmp)); |
107 static void early_arg_scan __ARGS((mparm_T *parmp)); | |
108 static void command_line_scan __ARGS((mparm_T *parmp)); | |
109 static void check_tty __ARGS((mparm_T *parmp)); | |
110 static void read_stdin __ARGS((void)); | |
111 static void create_windows __ARGS((mparm_T *parmp)); | |
2730 | 112 # ifdef FEAT_WINDOWS |
443 | 113 static void edit_buffers __ARGS((mparm_T *parmp)); |
2730 | 114 # endif |
443 | 115 static void exe_pre_commands __ARGS((mparm_T *parmp)); |
116 static void exe_commands __ARGS((mparm_T *parmp)); | |
440 | 117 static void source_startup_scripts __ARGS((mparm_T *parmp)); |
6 | 118 static void main_start_gui __ARGS((void)); |
2730 | 119 # if defined(HAS_SWAP_EXISTS_ACTION) |
6 | 120 static void check_swap_exists_action __ARGS((void)); |
2730 | 121 # endif |
122 # if defined(FEAT_CLIENTSERVER) || defined(PROTO) | |
443 | 123 static void exec_on_server __ARGS((mparm_T *parmp)); |
124 static void prepare_server __ARGS((mparm_T *parmp)); | |
6 | 125 static void cmdsrv_main __ARGS((int *argc, char **argv, char_u *serverName_arg, char_u **serverStr)); |
126 static char_u *serverMakeName __ARGS((char_u *arg, char *cmd)); | |
2730 | 127 # endif |
6 | 128 #endif |
129 | |
130 | |
131 /* | |
132 * Different types of error messages. | |
133 */ | |
134 static char *(main_errors[]) = | |
135 { | |
443 | 136 N_("Unknown option argument"), |
6 | 137 #define ME_UNKNOWN_OPTION 0 |
138 N_("Too many edit arguments"), | |
139 #define ME_TOO_MANY_ARGS 1 | |
140 N_("Argument missing after"), | |
141 #define ME_ARG_MISSING 2 | |
443 | 142 N_("Garbage after option argument"), |
6 | 143 #define ME_GARBAGE 3 |
144 N_("Too many \"+command\", \"-c command\" or \"--cmd command\" arguments"), | |
145 #define ME_EXTRA_CMD 4 | |
146 N_("Invalid argument for"), | |
147 #define ME_INVALID_ARG 5 | |
148 }; | |
149 | |
3955 | 150 #ifndef PROTO /* don't want a prototype for main() */ |
2730 | 151 #ifndef NO_VIM_MAIN /* skip this for unittests */ |
6 | 152 int |
153 # ifdef VIMDLL | |
154 _export | |
155 # endif | |
156 # ifdef FEAT_GUI_MSWIN | |
157 # ifdef __BORLANDC__ | |
158 _cdecl | |
159 # endif | |
160 VimMain | |
161 # else | |
162 main | |
163 # endif | |
164 (argc, argv) | |
165 int argc; | |
166 char **argv; | |
167 { | |
168 char_u *fname = NULL; /* file name from command line */ | |
440 | 169 mparm_T params; /* various parameters passed between |
170 * main() and other functions. */ | |
1972 | 171 #ifdef STARTUPTIME |
172 int i; | |
173 #endif | |
6 | 174 |
175 /* | |
176 * Do any system-specific initialisations. These can NOT use IObuff or | |
177 * NameBuff. Thus emsg2() cannot be called! | |
178 */ | |
179 mch_early_init(); | |
180 | |
443 | 181 /* Many variables are in "params" so that we can pass them to invoked |
182 * functions without a lot of arguments. "argc" and "argv" are also | |
183 * copied, so that they can be changed. */ | |
440 | 184 vim_memset(¶ms, 0, sizeof(params)); |
443 | 185 params.argc = argc; |
186 params.argv = argv; | |
187 params.want_full_screen = TRUE; | |
188 #ifdef FEAT_EVAL | |
189 params.use_debug_break_level = -1; | |
190 #endif | |
191 #ifdef FEAT_WINDOWS | |
192 params.window_count = -1; | |
193 #endif | |
440 | 194 |
4369 | 195 #ifdef FEAT_RUBY |
196 { | |
197 int ruby_stack_start; | |
198 vim_ruby_init((void *)&ruby_stack_start); | |
199 } | |
200 #endif | |
201 | |
6 | 202 #ifdef FEAT_TCL |
443 | 203 vim_tcl_init(params.argv[0]); |
6 | 204 #endif |
205 | |
206 #ifdef MEM_PROFILE | |
207 atexit(vim_mem_profile_dump); | |
208 #endif | |
209 | |
210 #ifdef STARTUPTIME | |
1972 | 211 for (i = 1; i < argc; ++i) |
212 { | |
1989 | 213 if (STRICMP(argv[i], "--startuptime") == 0 && i + 1 < argc) |
1972 | 214 { |
1989 | 215 time_fd = mch_fopen(argv[i + 1], "a"); |
1972 | 216 TIME_MSG("--- VIM STARTING ---"); |
217 break; | |
218 } | |
219 } | |
6 | 220 #endif |
777 | 221 starttime = time(NULL); |
6 | 222 |
223 #ifdef __EMX__ | |
443 | 224 _wildcard(¶ms.argc, ¶ms.argv); |
6 | 225 #endif |
226 | |
227 #ifdef FEAT_MBYTE | |
228 (void)mb_init(); /* init mb_bytelen_tab[] to ones */ | |
229 #endif | |
123 | 230 #ifdef FEAT_EVAL |
231 eval_init(); /* init global variables */ | |
232 #endif | |
6 | 233 |
234 #ifdef __QNXNTO__ | |
235 qnx_init(); /* PhAttach() for clipboard, (and gui) */ | |
236 #endif | |
237 | |
238 #ifdef MAC_OS_CLASSIC | |
443 | 239 /* Prepare for possibly starting GUI sometime */ |
6 | 240 /* Macintosh needs this before any memory is allocated. */ |
443 | 241 gui_prepare(¶ms.argc, params.argv); |
6 | 242 TIME_MSG("GUI prepared"); |
243 #endif | |
244 | |
245 /* Init the table of Normal mode commands. */ | |
246 init_normal_cmds(); | |
247 | |
248 #if defined(HAVE_DATE_TIME) && defined(VMS) && defined(VAXC) | |
440 | 249 make_version(); /* Construct the long version string. */ |
6 | 250 #endif |
251 | |
252 /* | |
253 * Allocate space for the generic buffers (needed for set_init_1() and | |
254 * EMSG2()). | |
255 */ | |
256 if ((IObuff = alloc(IOSIZE)) == NULL | |
257 || (NameBuff = alloc(MAXPATHL)) == NULL) | |
258 mch_exit(0); | |
259 TIME_MSG("Allocated generic buffers"); | |
260 | |
22 | 261 #ifdef NBDEBUG |
262 /* Wait a moment for debugging NetBeans. Must be after allocating | |
263 * NameBuff. */ | |
264 nbdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL"); | |
265 nbdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20); | |
443 | 266 TIME_MSG("NetBeans debug wait"); |
22 | 267 #endif |
268 | |
6 | 269 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
270 /* | |
271 * Setup to use the current locale (for ctype() and many other things). | |
272 * NOTE: Translated messages with encodings other than latin1 will not | |
273 * work until set_init_1() has been called! | |
274 */ | |
443 | 275 init_locale(); |
6 | 276 TIME_MSG("locale set"); |
277 #endif | |
278 | |
279 #ifdef FEAT_GUI | |
280 gui.dofork = TRUE; /* default is to use fork() */ | |
281 #endif | |
282 | |
283 /* | |
440 | 284 * Do a first scan of the arguments in "argv[]": |
443 | 285 * -display or --display |
440 | 286 * --server... |
287 * --socketid | |
1376 | 288 * --windowid |
6 | 289 */ |
443 | 290 early_arg_scan(¶ms); |
6 | 291 |
292 #ifdef FEAT_SUN_WORKSHOP | |
443 | 293 findYourself(params.argv[0]); |
6 | 294 #endif |
295 #if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC) | |
443 | 296 /* Prepare for possibly starting GUI sometime */ |
297 gui_prepare(¶ms.argc, params.argv); | |
6 | 298 TIME_MSG("GUI prepared"); |
299 #endif | |
300 | |
301 #ifdef FEAT_CLIPBOARD | |
302 clip_init(FALSE); /* Initialise clipboard stuff */ | |
303 TIME_MSG("clipboard setup"); | |
304 #endif | |
305 | |
306 /* | |
307 * Check if we have an interactive window. | |
308 * On the Amiga: If there is no window, we open one with a newcli command | |
309 * (needed for :! to * work). mch_check_win() will also handle the -d or | |
310 * -dev argument. | |
311 */ | |
443 | 312 params.stdout_isatty = (mch_check_win(params.argc, params.argv) != FAIL); |
6 | 313 TIME_MSG("window checked"); |
314 | |
315 /* | |
667 | 316 * Allocate the first window and buffer. |
317 * Can't do anything without it, exit when it fails. | |
6 | 318 */ |
667 | 319 if (win_alloc_first() == FAIL) |
320 mch_exit(0); | |
6 | 321 |
322 init_yank(); /* init yank buffers */ | |
323 | |
443 | 324 alist_init(&global_alist); /* Init the argument list to empty. */ |
6 | 325 |
326 /* | |
327 * Set the default values for the options. | |
328 * NOTE: Non-latin1 translated messages are working only after this, | |
329 * because this is where "has_mbyte" will be set, which is used by | |
330 * msg_outtrans_len_attr(). | |
331 * First find out the home directory, needed to expand "~" in options. | |
332 */ | |
333 init_homedir(); /* find real value of $HOME */ | |
334 set_init_1(); | |
335 TIME_MSG("inits 1"); | |
336 | |
337 #ifdef FEAT_EVAL | |
338 set_lang_var(); /* set v:lang and v:ctype */ | |
339 #endif | |
340 | |
341 #ifdef FEAT_CLIENTSERVER | |
342 /* | |
343 * Do the client-server stuff, unless "--servername ''" was used. | |
443 | 344 * This may exit Vim if the command was sent to the server. |
6 | 345 */ |
443 | 346 exec_on_server(¶ms); |
6 | 347 #endif |
348 | |
349 /* | |
443 | 350 * Figure out the way to work from the command name argv[0]. |
351 * "vimdiff" starts diff mode, "rvim" sets "restricted", etc. | |
6 | 352 */ |
443 | 353 parse_command_name(¶ms); |
6 | 354 |
355 /* | |
443 | 356 * Process the command line arguments. File names are put in the global |
357 * argument list "global_alist". | |
6 | 358 */ |
443 | 359 command_line_scan(¶ms); |
6 | 360 TIME_MSG("parsing arguments"); |
361 | |
362 /* | |
363 * On some systems, when we compile with the GUI, we always use it. On Mac | |
443 | 364 * there is no terminal version, and on Windows we can't fork one off with |
365 * :gui. | |
6 | 366 */ |
367 #ifdef ALWAYS_USE_GUI | |
368 gui.starting = TRUE; | |
369 #else | |
575 | 370 # if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) |
6 | 371 /* |
372 * Check if the GUI can be started. Reset gui.starting if not. | |
373 * Don't know about other systems, stay on the safe side and don't check. | |
374 */ | |
2021 | 375 if (gui.starting) |
6 | 376 { |
2021 | 377 if (gui_init_check() == FAIL) |
378 { | |
379 gui.starting = FALSE; | |
380 | |
381 /* When running "evim" or "gvim -y" we need the menus, exit if we | |
382 * don't have them. */ | |
383 if (params.evim_mode) | |
384 mch_exit(1); | |
385 } | |
6 | 386 } |
387 # endif | |
388 #endif | |
389 | |
390 if (GARGCOUNT > 0) | |
391 { | |
392 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) | |
393 /* | |
394 * Expand wildcards in file names. | |
395 */ | |
443 | 396 if (!params.literal) |
6 | 397 { |
398 /* Temporarily add '(' and ')' to 'isfname'. These are valid | |
399 * filename characters but are excluded from 'isfname' to make | |
400 * "gf" work on a file name in parenthesis (e.g.: see vim.h). */ | |
401 do_cmdline_cmd((char_u *)":set isf+=(,)"); | |
41 | 402 alist_expand(NULL, 0); |
6 | 403 do_cmdline_cmd((char_u *)":set isf&"); |
404 } | |
405 #endif | |
406 fname = alist_name(&GARGLIST[0]); | |
407 } | |
23 | 408 |
409 #if defined(WIN32) && defined(FEAT_MBYTE) | |
410 { | |
411 extern void set_alist_count(void); | |
412 | |
413 /* Remember the number of entries in the argument list. If it changes | |
414 * we don't react on setting 'encoding'. */ | |
415 set_alist_count(); | |
416 } | |
417 #endif | |
418 | |
6 | 419 #ifdef MSWIN |
443 | 420 if (GARGCOUNT == 1 && params.full_path) |
6 | 421 { |
422 /* | |
423 * If there is one filename, fully qualified, we have very probably | |
424 * been invoked from explorer, so change to the file's directory. | |
425 * Hint: to avoid this when typing a command use a forward slash. | |
426 * If the cd fails, it doesn't matter. | |
427 */ | |
428 (void)vim_chdirfile(fname); | |
429 } | |
430 #endif | |
431 TIME_MSG("expanding arguments"); | |
432 | |
433 #ifdef FEAT_DIFF | |
769 | 434 if (params.diff_mode && params.window_count == -1) |
435 params.window_count = 0; /* open up to 3 windows */ | |
6 | 436 #endif |
437 | |
443 | 438 /* Don't redraw until much later. */ |
6 | 439 ++RedrawingDisabled; |
440 | |
441 /* | |
442 * When listing swap file names, don't do cursor positioning et. al. | |
443 */ | |
444 if (recoverymode && fname == NULL) | |
443 | 445 params.want_full_screen = FALSE; |
6 | 446 |
447 /* | |
448 * When certain to start the GUI, don't check capabilities of terminal. | |
449 * For GTK we can't be sure, but when started from the desktop it doesn't | |
450 * make sense to try using a terminal. | |
451 */ | |
575 | 452 #if defined(ALWAYS_USE_GUI) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) |
6 | 453 if (gui.starting |
454 # ifdef FEAT_GUI_GTK | |
455 && !isatty(2) | |
456 # endif | |
457 ) | |
443 | 458 params.want_full_screen = FALSE; |
6 | 459 #endif |
460 | |
461 #if defined(FEAT_GUI_MAC) && defined(MACOS_X_UNIX) | |
462 /* When the GUI is started from Finder, need to display messages in a | |
463 * message box. isatty(2) returns TRUE anyway, thus we need to check the | |
464 * name to know we're not started from a terminal. */ | |
465 if (gui.starting && (!isatty(2) || strcmp("/dev/console", ttyname(2)) == 0)) | |
816 | 466 { |
443 | 467 params.want_full_screen = FALSE; |
816 | 468 |
469 /* Avoid always using "/" as the current directory. Note that when | |
470 * started from Finder the arglist will be filled later in | |
471 * HandleODocAE() and "fname" will be NULL. */ | |
472 if (getcwd((char *)NameBuff, MAXPATHL) != NULL | |
473 && STRCMP(NameBuff, "/") == 0) | |
474 { | |
475 if (fname != NULL) | |
476 (void)vim_chdirfile(fname); | |
477 else | |
478 { | |
479 expand_env((char_u *)"$HOME", NameBuff, MAXPATHL); | |
480 vim_chdir(NameBuff); | |
481 } | |
482 } | |
483 } | |
6 | 484 #endif |
485 | |
486 /* | |
487 * mch_init() sets up the terminal (window) for use. This must be | |
488 * done after resetting full_screen, otherwise it may move the cursor | |
489 * (MSDOS). | |
490 * Note that we may use mch_exit() before mch_init()! | |
491 */ | |
492 mch_init(); | |
493 TIME_MSG("shell init"); | |
494 | |
495 #ifdef USE_XSMP | |
496 /* | |
497 * For want of anywhere else to do it, try to connect to xsmp here. | |
498 * Fitting it in after gui_mch_init, but before gui_init (via termcapinit). | |
499 * Hijacking -X 'no X connection' to also disable XSMP connection as that | |
500 * has a similar delay upon failure. | |
501 * Only try if SESSION_MANAGER is set to something non-null. | |
502 */ | |
503 if (!x_no_connect) | |
504 { | |
443 | 505 char *p = getenv("SESSION_MANAGER"); |
506 | |
6 | 507 if (p != NULL && *p != NUL) |
508 { | |
509 xsmp_init(); | |
510 TIME_MSG("xsmp init"); | |
511 } | |
512 } | |
513 #endif | |
514 | |
515 /* | |
516 * Print a warning if stdout is not a terminal. | |
517 */ | |
443 | 518 check_tty(¶ms); |
6 | 519 |
169 | 520 /* This message comes before term inits, but after setting "silent_mode" |
521 * when the input is not a tty. */ | |
522 if (GARGCOUNT > 1 && !silent_mode) | |
523 printf(_("%d files to edit\n"), GARGCOUNT); | |
524 | |
443 | 525 if (params.want_full_screen && !silent_mode) |
6 | 526 { |
443 | 527 termcapinit(params.term); /* set terminal name and get terminal |
6 | 528 capabilities (will set full_screen) */ |
529 screen_start(); /* don't know where cursor is now */ | |
530 TIME_MSG("Termcap init"); | |
531 } | |
532 | |
533 /* | |
534 * Set the default values for the options that use Rows and Columns. | |
535 */ | |
536 ui_get_shellsize(); /* inits Rows and Columns */ | |
667 | 537 win_init_size(); |
6 | 538 #ifdef FEAT_DIFF |
539 /* Set the 'diff' option now, so that it can be checked for in a .vimrc | |
540 * file. There is no buffer yet though. */ | |
443 | 541 if (params.diff_mode) |
6 | 542 diff_win_options(firstwin, FALSE); |
543 #endif | |
544 | |
545 cmdline_row = Rows - p_ch; | |
546 msg_row = cmdline_row; | |
547 screenalloc(FALSE); /* allocate screen buffers */ | |
548 set_init_2(); | |
549 TIME_MSG("inits 2"); | |
550 | |
551 msg_scroll = TRUE; | |
552 no_wait_return = TRUE; | |
553 | |
554 init_mappings(); /* set up initial mappings */ | |
555 | |
556 init_highlight(TRUE, FALSE); /* set the default highlight groups */ | |
557 TIME_MSG("init highlight"); | |
558 | |
559 #ifdef FEAT_EVAL | |
560 /* Set the break level after the terminal is initialized. */ | |
443 | 561 debug_break_level = params.use_debug_break_level; |
6 | 562 #endif |
563 | |
3348 | 564 #ifdef FEAT_MZSCHEME |
565 /* | |
566 * Newer version of MzScheme (Racket) require earlier (trampolined) | |
567 * initialisation via scheme_main_setup. | |
568 * Implement this by initialising it as early as possible | |
569 * and splitting off remaining Vim main into vim_main2 | |
570 */ | |
571 { | |
572 /* Pack up preprocessed command line arguments. | |
573 * It is safe because Scheme does not access argc/argv. */ | |
574 char *args[2]; | |
575 args[0] = (char *)fname; | |
576 args[1] = (char *)¶ms; | |
577 return mzscheme_main(2, args); | |
578 } | |
579 } | |
3955 | 580 #endif |
581 #endif /* NO_VIM_MAIN */ | |
582 | |
583 /* vim_main2() needs to be produced when FEAT_MZSCHEME is defined even when | |
584 * NO_VIM_MAIN is defined. */ | |
585 #ifdef FEAT_MZSCHEME | |
586 int | |
587 vim_main2(int argc UNUSED, char **argv UNUSED) | |
3348 | 588 { |
3955 | 589 # ifndef NO_VIM_MAIN |
3348 | 590 char_u *fname = (char_u *)argv[0]; |
591 mparm_T params; | |
592 | |
593 memcpy(¶ms, argv[1], sizeof(params)); | |
3955 | 594 # else |
595 return 0; | |
596 } | |
597 # endif | |
3348 | 598 #endif |
599 | |
3955 | 600 #ifndef NO_VIM_MAIN |
440 | 601 /* Execute --cmd arguments. */ |
443 | 602 exe_pre_commands(¶ms); |
440 | 603 |
604 /* Source startup scripts. */ | |
605 source_startup_scripts(¶ms); | |
6 | 606 |
607 #ifdef FEAT_EVAL | |
608 /* | |
609 * Read all the plugin files. | |
610 * Only when compiled with +eval, since most plugins need it. | |
611 */ | |
612 if (p_lpl) | |
613 { | |
892 | 614 # ifdef VMS /* Somehow VMS doesn't handle the "**". */ |
615 source_runtime((char_u *)"plugin/*.vim", TRUE); | |
616 # else | |
541 | 617 source_runtime((char_u *)"plugin/**/*.vim", TRUE); |
892 | 618 # endif |
6 | 619 TIME_MSG("loading plugins"); |
620 } | |
621 #endif | |
622 | |
769 | 623 #ifdef FEAT_DIFF |
624 /* Decide about window layout for diff mode after reading vimrc. */ | |
625 if (params.diff_mode && params.window_layout == 0) | |
626 { | |
627 if (diffopt_horizontal()) | |
628 params.window_layout = WIN_HOR; /* use horizontal split */ | |
629 else | |
630 params.window_layout = WIN_VER; /* use vertical split */ | |
631 } | |
632 #endif | |
633 | |
6 | 634 /* |
635 * Recovery mode without a file name: List swap files. | |
636 * This uses the 'dir' option, therefore it must be after the | |
637 * initializations. | |
638 */ | |
639 if (recoverymode && fname == NULL) | |
640 { | |
2267 | 641 recover_names(NULL, TRUE, 0, NULL); |
6 | 642 mch_exit(0); |
643 } | |
644 | |
645 /* | |
646 * Set a few option defaults after reading .vimrc files: | |
647 * 'title' and 'icon', Unix: 'shellpipe' and 'shellredir'. | |
648 */ | |
649 set_init_3(); | |
650 TIME_MSG("inits 3"); | |
651 | |
652 /* | |
653 * "-n" argument: Disable swap file by setting 'updatecount' to 0. | |
654 * Note that this overrides anything from a vimrc file. | |
655 */ | |
443 | 656 if (params.no_swap_file) |
6 | 657 p_uc = 0; |
658 | |
659 #ifdef FEAT_FKMAP | |
660 if (curwin->w_p_rl && p_altkeymap) | |
661 { | |
662 p_hkmap = FALSE; /* Reset the Hebrew keymap mode */ | |
663 # ifdef FEAT_ARABIC | |
664 curwin->w_p_arab = FALSE; /* Reset the Arabic keymap mode */ | |
665 # endif | |
666 p_fkmap = TRUE; /* Set the Farsi keymap mode */ | |
667 } | |
668 #endif | |
669 | |
670 #ifdef FEAT_GUI | |
671 if (gui.starting) | |
672 { | |
673 #if defined(UNIX) || defined(VMS) | |
674 /* When something caused a message from a vimrc script, need to output | |
675 * an extra newline before the shell prompt. */ | |
676 if (did_emsg || msg_didout) | |
677 putchar('\n'); | |
678 #endif | |
679 | |
680 gui_start(); /* will set full_screen to TRUE */ | |
681 TIME_MSG("starting GUI"); | |
682 | |
683 /* When running "evim" or "gvim -y" we need the menus, exit if we | |
684 * don't have them. */ | |
440 | 685 if (!gui.in_use && params.evim_mode) |
6 | 686 mch_exit(1); |
687 } | |
688 #endif | |
689 | |
690 #ifdef SPAWNO /* special MSDOS swapping library */ | |
691 init_SPAWNO("", SWAP_ANY); | |
692 #endif | |
693 | |
694 #ifdef FEAT_VIMINFO | |
695 /* | |
1733 | 696 * Read in registers, history etc, but not marks, from the viminfo file. |
697 * This is where v:oldfiles gets filled. | |
6 | 698 */ |
699 if (*p_viminfo != NUL) | |
700 { | |
1733 | 701 read_viminfo(NULL, VIF_WANT_INFO | VIF_GET_OLDFILES); |
6 | 702 TIME_MSG("reading viminfo"); |
703 } | |
704 #endif | |
705 | |
706 #ifdef FEAT_QUICKFIX | |
707 /* | |
708 * "-q errorfile": Load the error file now. | |
709 * If the error file can't be read, exit before doing anything else. | |
710 */ | |
443 | 711 if (params.edit_type == EDIT_QF) |
6 | 712 { |
443 | 713 if (params.use_ef != NULL) |
714 set_string_option_direct((char_u *)"ef", -1, | |
694 | 715 params.use_ef, OPT_FREE, SID_CARG); |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
716 vim_snprintf((char *)IObuff, IOSIZE, "cfile %s", p_ef); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
717 if (qf_init(NULL, p_ef, p_efm, TRUE, IObuff) < 0) |
6 | 718 { |
719 out_char('\n'); | |
720 mch_exit(3); | |
721 } | |
722 TIME_MSG("reading errorfile"); | |
723 } | |
724 #endif | |
725 | |
726 /* | |
727 * Start putting things on the screen. | |
728 * Scroll screen down before drawing over it | |
729 * Clear screen now, so file message will not be cleared. | |
730 */ | |
731 starting = NO_BUFFERS; | |
732 no_wait_return = FALSE; | |
733 if (!exmode_active) | |
734 msg_scroll = FALSE; | |
735 | |
736 #ifdef FEAT_GUI | |
737 /* | |
738 * This seems to be required to make callbacks to be called now, instead | |
739 * of after things have been put on the screen, which then may be deleted | |
740 * when getting a resize callback. | |
741 * For the Mac this handles putting files dropped on the Vim icon to | |
742 * global_alist. | |
743 */ | |
744 if (gui.in_use) | |
745 { | |
746 # ifdef FEAT_SUN_WORKSHOP | |
747 if (!usingSunWorkShop) | |
748 # endif | |
749 gui_wait_for_chars(50L); | |
750 TIME_MSG("GUI delay"); | |
751 } | |
752 #endif | |
753 | |
754 #if defined(FEAT_GUI_PHOTON) && defined(FEAT_CLIPBOARD) | |
755 qnx_clip_init(); | |
756 #endif | |
757 | |
2312
bbd6f5539378
Missing piece for Mac console clipboard support. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
758 #if defined(MACOS_X) && defined(FEAT_CLIPBOARD) |
bbd6f5539378
Missing piece for Mac console clipboard support. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
759 clip_init(TRUE); |
bbd6f5539378
Missing piece for Mac console clipboard support. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
760 #endif |
bbd6f5539378
Missing piece for Mac console clipboard support. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
761 |
6 | 762 #ifdef FEAT_XCLIPBOARD |
763 /* Start using the X clipboard, unless the GUI was started. */ | |
764 # ifdef FEAT_GUI | |
765 if (!gui.in_use) | |
766 # endif | |
767 { | |
768 setup_term_clip(); | |
769 TIME_MSG("setup clipboard"); | |
770 } | |
771 #endif | |
772 | |
773 #ifdef FEAT_CLIENTSERVER | |
443 | 774 /* Prepare for being a Vim server. */ |
775 prepare_server(¶ms); | |
6 | 776 #endif |
777 | |
778 /* | |
779 * If "-" argument given: Read file from stdin. | |
780 * Do this before starting Raw mode, because it may change things that the | |
781 * writing end of the pipe doesn't like, e.g., in case stdin and stderr | |
782 * are the same terminal: "cat | vim -". | |
783 * Using autocommands here may cause trouble... | |
784 */ | |
443 | 785 if (params.edit_type == EDIT_STDIN && !recoverymode) |
786 read_stdin(); | |
6 | 787 |
788 #if defined(UNIX) || defined(VMS) | |
789 /* When switching screens and something caused a message from a vimrc | |
790 * script, need to output an extra newline on exit. */ | |
791 if ((did_emsg || msg_didout) && *T_TI != NUL) | |
792 newline_on_exit = TRUE; | |
793 #endif | |
794 | |
795 /* | |
796 * When done something that is not allowed or error message call | |
797 * wait_return. This must be done before starttermcap(), because it may | |
798 * switch to another screen. It must be done after settmode(TMODE_RAW), | |
799 * because we want to react on a single key stroke. | |
800 * Call settmode and starttermcap here, so the T_KS and T_TI may be | |
1226 | 801 * defined by termcapinit and redefined in .exrc. |
6 | 802 */ |
803 settmode(TMODE_RAW); | |
804 TIME_MSG("setting raw mode"); | |
805 | |
806 if (need_wait_return || msg_didany) | |
807 { | |
808 wait_return(TRUE); | |
809 TIME_MSG("waiting for return"); | |
810 } | |
811 | |
812 starttermcap(); /* start termcap if not done by wait_return() */ | |
813 TIME_MSG("start termcap"); | |
4215 | 814 #if defined(FEAT_TERMRESPONSE) && defined(FEAT_MBYTE) |
815 may_req_ambiguous_character_width(); | |
816 #endif | |
6 | 817 |
818 #ifdef FEAT_MOUSE | |
819 setmouse(); /* may start using the mouse */ | |
820 #endif | |
821 if (scroll_region) | |
822 scroll_region_reset(); /* In case Rows changed */ | |
440 | 823 scroll_start(); /* may scroll the screen to the right position */ |
6 | 824 |
825 /* | |
826 * Don't clear the screen when starting in Ex mode, unless using the GUI. | |
827 */ | |
828 if (exmode_active | |
829 #ifdef FEAT_GUI | |
830 && !gui.in_use | |
831 #endif | |
832 ) | |
833 must_redraw = CLEAR; | |
834 else | |
835 { | |
836 screenclear(); /* clear screen */ | |
837 TIME_MSG("clearing screen"); | |
838 } | |
839 | |
840 #ifdef FEAT_CRYPT | |
443 | 841 if (params.ask_for_key) |
6 | 842 { |
2180
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2133
diff
changeset
|
843 (void)blowfish_self_test(); |
6 | 844 (void)get_crypt_key(TRUE, TRUE); |
845 TIME_MSG("getting crypt key"); | |
846 } | |
847 #endif | |
848 | |
849 no_wait_return = TRUE; | |
850 | |
851 /* | |
443 | 852 * Create the requested number of windows and edit buffers in them. |
853 * Also does recovery if "recoverymode" set. | |
6 | 854 */ |
443 | 855 create_windows(¶ms); |
6 | 856 TIME_MSG("opening buffers"); |
857 | |
1093 | 858 #ifdef FEAT_EVAL |
859 /* clear v:swapcommand */ | |
860 set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); | |
861 #endif | |
862 | |
6 | 863 /* Ex starts at last line of the file */ |
864 if (exmode_active) | |
865 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
866 | |
867 #ifdef FEAT_AUTOCMD | |
868 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | |
869 TIME_MSG("BufEnter autocommands"); | |
870 #endif | |
871 setpcmark(); | |
872 | |
873 #ifdef FEAT_QUICKFIX | |
874 /* | |
875 * When started with "-q errorfile" jump to first error now. | |
876 */ | |
443 | 877 if (params.edit_type == EDIT_QF) |
6 | 878 { |
644 | 879 qf_jump(NULL, 0, 0, FALSE); |
6 | 880 TIME_MSG("jump to first error"); |
881 } | |
882 #endif | |
883 | |
884 #ifdef FEAT_WINDOWS | |
885 /* | |
886 * If opened more than one window, start editing files in the other | |
443 | 887 * windows. |
6 | 888 */ |
443 | 889 edit_buffers(¶ms); |
890 #endif | |
6 | 891 |
892 #ifdef FEAT_DIFF | |
443 | 893 if (params.diff_mode) |
6 | 894 { |
895 win_T *wp; | |
896 | |
897 /* set options in each window for "vimdiff". */ | |
898 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
899 diff_win_options(wp, TRUE); | |
900 } | |
901 #endif | |
902 | |
903 /* | |
904 * Shorten any of the filenames, but only when absolute. | |
905 */ | |
906 shorten_fnames(FALSE); | |
907 | |
908 /* | |
909 * Need to jump to the tag before executing the '-c command'. | |
910 * Makes "vim -c '/return' -t main" work. | |
911 */ | |
443 | 912 if (params.tagname != NULL) |
6 | 913 { |
604 | 914 #if defined(HAS_SWAP_EXISTS_ACTION) |
915 swap_exists_did_quit = FALSE; | |
916 #endif | |
917 | |
443 | 918 vim_snprintf((char *)IObuff, IOSIZE, "ta %s", params.tagname); |
6 | 919 do_cmdline_cmd(IObuff); |
920 TIME_MSG("jumping to tag"); | |
604 | 921 |
922 #if defined(HAS_SWAP_EXISTS_ACTION) | |
923 /* If the user doesn't want to edit the file then we quit here. */ | |
924 if (swap_exists_did_quit) | |
925 getout(1); | |
926 #endif | |
6 | 927 } |
928 | |
443 | 929 /* Execute any "+", "-c" and "-S" arguments. */ |
930 if (params.n_commands > 0) | |
931 exe_commands(¶ms); | |
6 | 932 |
933 RedrawingDisabled = 0; | |
934 redraw_all_later(NOT_VALID); | |
935 no_wait_return = FALSE; | |
936 starting = 0; | |
937 | |
626 | 938 #ifdef FEAT_TERMRESPONSE |
939 /* Requesting the termresponse is postponed until here, so that a "-c q" | |
940 * argument doesn't make it appear in the shell Vim was started from. */ | |
941 may_req_termresponse(); | |
942 #endif | |
943 | |
6 | 944 /* start in insert mode */ |
945 if (p_im) | |
946 need_start_insertmode = TRUE; | |
947 | |
948 #ifdef FEAT_AUTOCMD | |
949 apply_autocmds(EVENT_VIMENTER, NULL, NULL, FALSE, curbuf); | |
950 TIME_MSG("VimEnter autocommands"); | |
951 #endif | |
952 | |
3488 | 953 #if defined(FEAT_EVAL) && defined(FEAT_CLIPBOARD) |
954 /* Adjust default register name for "unnamed" in 'clipboard'. Can only be | |
955 * done after the clipboard is available and all initial commands that may | |
956 * modify the 'clipboard' setting have run; i.e. just before entering the | |
957 * main loop. */ | |
958 { | |
959 int default_regname = 0; | |
960 adjust_clip_reg(&default_regname); | |
961 set_reg_var(default_regname); | |
962 } | |
963 #endif | |
964 | |
6 | 965 #if defined(FEAT_DIFF) && defined(FEAT_SCROLLBIND) |
966 /* When a startup script or session file setup for diff'ing and | |
967 * scrollbind, sync the scrollbind now. */ | |
968 if (curwin->w_p_diff && curwin->w_p_scb) | |
969 { | |
970 update_topline(); | |
971 check_scrollbind((linenr_T)0, 0L); | |
972 TIME_MSG("diff scrollbinding"); | |
973 } | |
974 #endif | |
975 | |
976 #if defined(WIN3264) && !defined(FEAT_GUI_W32) | |
977 mch_set_winsize_now(); /* Allow winsize changes from now on */ | |
978 #endif | |
979 | |
685 | 980 #if defined(FEAT_GUI) && defined(FEAT_WINDOWS) |
981 /* When tab pages were created, may need to update the tab pages line and | |
982 * scrollbars. This is skipped while creating them. */ | |
983 if (first_tabpage->tp_next != NULL) | |
984 { | |
985 out_flush(); | |
986 gui_init_which_components(NULL); | |
987 gui_update_scrollbars(TRUE); | |
988 } | |
989 need_mouse_correct = TRUE; | |
990 #endif | |
991 | |
6 | 992 /* If ":startinsert" command used, stuff a dummy command to be able to |
993 * call normal_cmd(), which will then start Insert mode. */ | |
994 if (restart_edit != 0) | |
620 | 995 stuffcharReadbuff(K_NOP); |
6 | 996 |
997 #ifdef FEAT_NETBEANS_INTG | |
2210 | 998 if (netbeansArg != NULL && strncmp("-nb", netbeansArg, 3) == 0) |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
999 { |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1000 # ifdef FEAT_GUI |
2592 | 1001 # if !defined(FEAT_GUI_X11) && !defined(FEAT_GUI_GTK) \ |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1002 && !defined(FEAT_GUI_W32) |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1003 if (gui.in_use) |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1004 { |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1005 mch_errmsg(_("netbeans is not supported with this GUI\n")); |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1006 mch_exit(2); |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1007 } |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1008 # endif |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1009 # endif |
6 | 1010 /* Tell the client that it can start sending commands. */ |
2210 | 1011 netbeans_open(netbeansArg + 3, TRUE); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1012 } |
6 | 1013 #endif |
1014 | |
1015 TIME_MSG("before starting main loop"); | |
1016 | |
1017 /* | |
1018 * Call the main command loop. This never returns. | |
3348 | 1019 */ |
169 | 1020 main_loop(FALSE, FALSE); |
6 | 1021 |
1022 return 0; | |
1023 } | |
3955 | 1024 #endif /* NO_VIM_MAIN */ |
6 | 1025 #endif /* PROTO */ |
1026 | |
1027 /* | |
1028 * Main loop: Execute Normal mode commands until exiting Vim. | |
1029 * Also used to handle commands in the command-line window, until the window | |
1030 * is closed. | |
169 | 1031 * Also used to handle ":visual" command after ":global": execute Normal mode |
1032 * commands, return when entering Ex mode. "noexmode" is TRUE then. | |
6 | 1033 */ |
1034 void | |
169 | 1035 main_loop(cmdwin, noexmode) |
1036 int cmdwin; /* TRUE when working in the command-line window */ | |
1037 int noexmode; /* TRUE when return on entering Ex mode */ | |
6 | 1038 { |
1345 | 1039 oparg_T oa; /* operator arguments */ |
1040 int previous_got_int = FALSE; /* "got_int" was TRUE */ | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1041 #ifdef FEAT_CONCEAL |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1042 linenr_T conceal_old_cursor_line = 0; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1043 linenr_T conceal_new_cursor_line = 0; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1044 int conceal_update_lines = FALSE; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1045 #endif |
6 | 1046 |
1047 #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) | |
1048 /* Setup to catch a terminating error from the X server. Just ignore | |
1049 * it, restore the state and continue. This might not always work | |
1050 * properly, but at least we don't exit unexpectedly when the X server | |
1051 * exists while Vim is running in a console. */ | |
169 | 1052 if (!cmdwin && !noexmode && SETJMP(x_jump_env)) |
6 | 1053 { |
1054 State = NORMAL; | |
1055 # ifdef FEAT_VISUAL | |
1056 VIsual_active = FALSE; | |
1057 # endif | |
1058 got_int = TRUE; | |
1059 need_wait_return = FALSE; | |
1060 global_busy = FALSE; | |
1061 exmode_active = 0; | |
1062 skip_redraw = FALSE; | |
1063 RedrawingDisabled = 0; | |
1064 no_wait_return = 0; | |
3119 | 1065 vgetc_busy = 0; |
6 | 1066 # ifdef FEAT_EVAL |
1067 emsg_skip = 0; | |
1068 # endif | |
1069 emsg_off = 0; | |
1070 # ifdef FEAT_MOUSE | |
1071 setmouse(); | |
1072 # endif | |
1073 settmode(TMODE_RAW); | |
1074 starttermcap(); | |
1075 scroll_start(); | |
1076 redraw_later_clear(); | |
1077 } | |
1078 #endif | |
1079 | |
1080 clear_oparg(&oa); | |
1081 while (!cmdwin | |
1082 #ifdef FEAT_CMDWIN | |
1083 || cmdwin_result == 0 | |
1084 #endif | |
1085 ) | |
1086 { | |
1087 if (stuff_empty()) | |
1088 { | |
1089 did_check_timestamps = FALSE; | |
1090 if (need_check_timestamps) | |
1091 check_timestamps(FALSE); | |
1092 if (need_wait_return) /* if wait_return still needed ... */ | |
1093 wait_return(FALSE); /* ... call it now */ | |
1094 if (need_start_insertmode && goto_im() | |
1095 #ifdef FEAT_VISUAL | |
1096 && !VIsual_active | |
1097 #endif | |
1098 ) | |
1099 { | |
1100 need_start_insertmode = FALSE; | |
1101 stuffReadbuff((char_u *)"i"); /* start insert mode next */ | |
1102 /* skip the fileinfo message now, because it would be shown | |
1103 * after insert mode finishes! */ | |
1104 need_fileinfo = FALSE; | |
1105 } | |
1106 } | |
1345 | 1107 |
1108 /* Reset "got_int" now that we got back to the main loop. Except when | |
1109 * inside a ":g/pat/cmd" command, then the "got_int" needs to abort | |
1110 * the ":g" command. | |
1111 * For ":g/pat/vi" we reset "got_int" when used once. When used | |
1112 * a second time we go back to Ex mode and abort the ":g" command. */ | |
1113 if (got_int) | |
6 | 1114 { |
1345 | 1115 if (noexmode && global_busy && !exmode_active && previous_got_int) |
1116 { | |
1117 /* Typed two CTRL-C in a row: go back to ex mode as if "Q" was | |
1118 * used and keep "got_int" set, so that it aborts ":g". */ | |
1119 exmode_active = EXMODE_NORMAL; | |
1120 State = NORMAL; | |
1121 } | |
1122 else if (!global_busy || !exmode_active) | |
1123 { | |
1124 if (!quit_more) | |
1125 (void)vgetc(); /* flush all buffers */ | |
1126 got_int = FALSE; | |
1127 } | |
1128 previous_got_int = TRUE; | |
6 | 1129 } |
1345 | 1130 else |
1131 previous_got_int = FALSE; | |
1132 | |
6 | 1133 if (!exmode_active) |
1134 msg_scroll = FALSE; | |
1135 quit_more = FALSE; | |
1136 | |
1137 /* | |
1138 * If skip redraw is set (for ":" in wait_return()), don't redraw now. | |
1139 * If there is nothing in the stuff_buffer or do_redraw is TRUE, | |
1140 * update cursor and redraw. | |
1141 */ | |
1142 if (skip_redraw || exmode_active) | |
1143 skip_redraw = FALSE; | |
1144 else if (do_redraw || stuff_empty()) | |
1145 { | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1146 #if defined(FEAT_AUTOCMD) || defined(FEAT_CONCEAL) |
662 | 1147 /* Trigger CursorMoved if the cursor moved. */ |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1148 if (!finish_op && ( |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1149 # ifdef FEAT_AUTOCMD |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1150 has_cursormoved() |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1151 # endif |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1152 # if defined(FEAT_AUTOCMD) && defined(FEAT_CONCEAL) |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1153 || |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1154 # endif |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1155 # ifdef FEAT_CONCEAL |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1156 curwin->w_p_cole > 0 |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1157 # endif |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1158 ) |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1159 && !equalpos(last_cursormoved, curwin->w_cursor)) |
662 | 1160 { |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1161 # ifdef FEAT_AUTOCMD |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1162 if (has_cursormoved()) |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1163 apply_autocmds(EVENT_CURSORMOVED, NULL, NULL, |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1164 FALSE, curbuf); |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1165 # endif |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1166 # ifdef FEAT_CONCEAL |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1167 if (curwin->w_p_cole > 0) |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1168 { |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1169 conceal_old_cursor_line = last_cursormoved.lnum; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1170 conceal_new_cursor_line = curwin->w_cursor.lnum; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1171 conceal_update_lines = TRUE; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1172 } |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1173 # endif |
662 | 1174 last_cursormoved = curwin->w_cursor; |
1175 } | |
1176 #endif | |
1177 | |
4232 | 1178 #ifdef FEAT_AUTOCMD |
1179 /* Trigger TextChanged if b_changedtick differs. */ | |
1180 if (!finish_op && has_textchanged() | |
1181 && last_changedtick != curbuf->b_changedtick) | |
1182 { | |
1183 if (last_changedtick_buf == curbuf) | |
1184 apply_autocmds(EVENT_TEXTCHANGED, NULL, NULL, | |
1185 FALSE, curbuf); | |
1186 last_changedtick_buf = curbuf; | |
1187 last_changedtick = curbuf->b_changedtick; | |
1188 } | |
1189 #endif | |
1190 | |
640 | 1191 #if defined(FEAT_DIFF) && defined(FEAT_SCROLLBIND) |
1192 /* Scroll-binding for diff mode may have been postponed until | |
1193 * here. Avoids doing it for every change. */ | |
1194 if (diff_need_scrollbind) | |
1195 { | |
1196 check_scrollbind((linenr_T)0, 0L); | |
1197 diff_need_scrollbind = FALSE; | |
1198 } | |
1199 #endif | |
6 | 1200 #if defined(FEAT_FOLDING) && defined(FEAT_VISUAL) |
1201 /* Include a closed fold completely in the Visual area. */ | |
1202 foldAdjustVisual(); | |
1203 #endif | |
1204 #ifdef FEAT_FOLDING | |
1205 /* | |
1206 * When 'foldclose' is set, apply 'foldlevel' to folds that don't | |
1207 * contain the cursor. | |
1208 * When 'foldopen' is "all", open the fold(s) under the cursor. | |
1209 * This may mark the window for redrawing. | |
1210 */ | |
1211 if (hasAnyFolding(curwin) && !char_avail()) | |
1212 { | |
1213 foldCheckClose(); | |
1214 if (fdo_flags & FDO_ALL) | |
1215 foldOpenCursor(); | |
1216 } | |
1217 #endif | |
1218 | |
1219 /* | |
1220 * Before redrawing, make sure w_topline is correct, and w_leftcol | |
1221 * if lines don't wrap, and w_skipcol if lines wrap. | |
1222 */ | |
1223 update_topline(); | |
1224 validate_cursor(); | |
1225 | |
1226 #ifdef FEAT_VISUAL | |
1227 if (VIsual_active) | |
1228 update_curbuf(INVERTED);/* update inverted part */ | |
1229 else | |
1230 #endif | |
1231 if (must_redraw) | |
1232 update_screen(0); | |
1233 else if (redraw_cmdline || clear_cmdline) | |
1234 showmode(); | |
1235 #ifdef FEAT_WINDOWS | |
1236 redraw_statuslines(); | |
1237 #endif | |
1238 #ifdef FEAT_TITLE | |
1239 if (need_maketitle) | |
1240 maketitle(); | |
1241 #endif | |
1242 /* display message after redraw */ | |
1243 if (keep_msg != NULL) | |
1244 { | |
1245 char_u *p; | |
1246 | |
1247 /* msg_attr_keep() will set keep_msg to NULL, must free the | |
1248 * string here. */ | |
1249 p = keep_msg; | |
680 | 1250 keep_msg = NULL; |
6 | 1251 msg_attr(p, keep_msg_attr); |
1252 vim_free(p); | |
1253 } | |
1254 if (need_fileinfo) /* show file info after redraw */ | |
1255 { | |
1256 fileinfo(FALSE, TRUE, FALSE); | |
1257 need_fileinfo = FALSE; | |
1258 } | |
1259 | |
1260 emsg_on_display = FALSE; /* can delete error message now */ | |
1261 did_emsg = FALSE; | |
1262 msg_didany = FALSE; /* reset lines_left in msg_start() */ | |
448 | 1263 may_clear_sb_text(); /* clear scroll-back text on next msg */ |
6 | 1264 showruler(FALSE); |
1265 | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1266 # if defined(FEAT_CONCEAL) |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1267 if (conceal_update_lines |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1268 && (conceal_old_cursor_line != conceal_new_cursor_line |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1269 || conceal_cursor_line(curwin) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1270 || need_cursor_line_redraw)) |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1271 { |
2706 | 1272 if (conceal_old_cursor_line != conceal_new_cursor_line |
1273 && conceal_old_cursor_line | |
1274 <= curbuf->b_ml.ml_line_count) | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1275 update_single_line(curwin, conceal_old_cursor_line); |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1276 update_single_line(curwin, conceal_new_cursor_line); |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1277 curwin->w_valid &= ~VALID_CROW; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1278 } |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1279 # endif |
6 | 1280 setcursor(); |
1281 cursor_on(); | |
1282 | |
1283 do_redraw = FALSE; | |
1972 | 1284 |
1285 #ifdef STARTUPTIME | |
1286 /* Now that we have drawn the first screen all the startup stuff | |
1287 * has been done, close any file for startup messages. */ | |
1288 if (time_fd != NULL) | |
1289 { | |
1290 TIME_MSG("first screen update"); | |
1291 TIME_MSG("--- VIM STARTED ---"); | |
1292 fclose(time_fd); | |
1293 time_fd = NULL; | |
1294 } | |
1295 #endif | |
6 | 1296 } |
1297 #ifdef FEAT_GUI | |
1298 if (need_mouse_correct) | |
1299 gui_mouse_correct(); | |
1300 #endif | |
1301 | |
1302 /* | |
1303 * Update w_curswant if w_set_curswant has been set. | |
1304 * Postponed until here to avoid computing w_virtcol too often. | |
1305 */ | |
1306 update_curswant(); | |
1307 | |
958 | 1308 #ifdef FEAT_EVAL |
1309 /* | |
1310 * May perform garbage collection when waiting for a character, but | |
1311 * only at the very toplevel. Otherwise we may be using a List or | |
1312 * Dict internally somewhere. | |
1313 * "may_garbage_collect" is reset in vgetc() which is invoked through | |
1314 * do_exmode() and normal_cmd(). | |
1315 */ | |
1316 may_garbage_collect = (!cmdwin && !noexmode); | |
1317 #endif | |
6 | 1318 /* |
1319 * If we're invoked as ex, do a round of ex commands. | |
1320 * Otherwise, get and execute a normal mode command. | |
1321 */ | |
1322 if (exmode_active) | |
169 | 1323 { |
1324 if (noexmode) /* End of ":global/path/visual" commands */ | |
1325 return; | |
6 | 1326 do_exmode(exmode_active == EXMODE_VIM); |
169 | 1327 } |
6 | 1328 else |
1329 normal_cmd(&oa, TRUE); | |
1330 } | |
1331 } | |
1332 | |
1333 | |
1334 #if defined(USE_XSMP) || defined(FEAT_GUI_MSWIN) || defined(PROTO) | |
1335 /* | |
1336 * Exit, but leave behind swap files for modified buffers. | |
1337 */ | |
1338 void | |
1339 getout_preserve_modified(exitval) | |
1340 int exitval; | |
1341 { | |
39 | 1342 # if defined(SIGHUP) && defined(SIG_IGN) |
1343 /* Ignore SIGHUP, because a dropped connection causes a read error, which | |
1344 * makes Vim exit and then handling SIGHUP causes various reentrance | |
1345 * problems. */ | |
36 | 1346 signal(SIGHUP, SIG_IGN); |
39 | 1347 # endif |
36 | 1348 |
6 | 1349 ml_close_notmod(); /* close all not-modified buffers */ |
1350 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
1351 ml_close_all(FALSE); /* close all memfiles, without deleting */ | |
1352 getout(exitval); /* exit Vim properly */ | |
1353 } | |
1354 #endif | |
1355 | |
1356 | |
1357 /* Exit properly */ | |
1358 void | |
1359 getout(exitval) | |
1360 int exitval; | |
1361 { | |
1362 #ifdef FEAT_AUTOCMD | |
1363 buf_T *buf; | |
1364 win_T *wp; | |
671 | 1365 tabpage_T *tp, *next_tp; |
6 | 1366 #endif |
1367 | |
1368 exiting = TRUE; | |
1369 | |
169 | 1370 /* When running in Ex mode an error causes us to exit with a non-zero exit |
1371 * code. POSIX requires this, although it's not 100% clear from the | |
1372 * standard. */ | |
1373 if (exmode_active) | |
1374 exitval += ex_exitval; | |
1375 | |
6 | 1376 /* Position the cursor on the last screen line, below all the text */ |
1377 #ifdef FEAT_GUI | |
1378 if (!gui.in_use) | |
1379 #endif | |
1380 windgoto((int)Rows - 1, 0); | |
1381 | |
242 | 1382 #if defined(FEAT_EVAL) || defined(FEAT_SYN_HL) |
1383 /* Optionally print hashtable efficiency. */ | |
1384 hash_debug_results(); | |
1385 #endif | |
1386 | |
6 | 1387 #ifdef FEAT_GUI |
1388 msg_didany = FALSE; | |
1389 #endif | |
1390 | |
1391 #ifdef FEAT_AUTOCMD | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1392 if (get_vim_var_nr(VV_DYING) <= 1) |
6 | 1393 { |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1394 /* Trigger BufWinLeave for all windows, but only once per buffer. */ |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1395 # if defined FEAT_WINDOWS |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1396 for (tp = first_tabpage; tp != NULL; tp = next_tp) |
6 | 1397 { |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1398 next_tp = tp->tp_next; |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1399 for (wp = (tp == curtab) |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1400 ? firstwin : tp->tp_firstwin; wp != NULL; wp = wp->w_next) |
671 | 1401 { |
4021 | 1402 if (wp->w_buffer == NULL) |
1403 /* Autocmd must have close the buffer already, skip. */ | |
1404 continue; | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1405 buf = wp->w_buffer; |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1406 if (buf->b_changedtick != -1) |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1407 { |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1408 apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1409 buf->b_fname, FALSE, buf); |
3488 | 1410 buf->b_changedtick = -1; /* note that we did it already */ |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1411 /* start all over, autocommands may mess up the lists */ |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1412 next_tp = first_tabpage; |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1413 break; |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1414 } |
671 | 1415 } |
6 | 1416 } |
640 | 1417 # else |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1418 apply_autocmds(EVENT_BUFWINLEAVE, curbuf, curbuf->b_fname, |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1419 FALSE, curbuf); |
640 | 1420 # endif |
1421 | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1422 /* Trigger BufUnload for buffers that are loaded */ |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1423 for (buf = firstbuf; buf != NULL; buf = buf->b_next) |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1424 if (buf->b_ml.ml_mfp != NULL) |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1425 { |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1426 apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, |
6 | 1427 FALSE, buf); |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1428 if (!buf_valid(buf)) /* autocmd may delete the buffer */ |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1429 break; |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1430 } |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1431 apply_autocmds(EVENT_VIMLEAVEPRE, NULL, NULL, FALSE, curbuf); |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1432 } |
6 | 1433 #endif |
1434 | |
1435 #ifdef FEAT_VIMINFO | |
1436 if (*p_viminfo != NUL) | |
1437 /* Write out the registers, history, marks etc, to the viminfo file */ | |
1438 write_viminfo(NULL, FALSE); | |
1439 #endif | |
1440 | |
1441 #ifdef FEAT_AUTOCMD | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1442 if (get_vim_var_nr(VV_DYING) <= 1) |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1443 apply_autocmds(EVENT_VIMLEAVE, NULL, NULL, FALSE, curbuf); |
6 | 1444 #endif |
1445 | |
170 | 1446 #ifdef FEAT_PROFILE |
1447 profile_dump(); | |
1448 #endif | |
1449 | |
6 | 1450 if (did_emsg |
1451 #ifdef FEAT_GUI | |
1452 || (gui.in_use && msg_didany && p_verbose > 0) | |
1453 #endif | |
1454 ) | |
1455 { | |
1456 /* give the user a chance to read the (error) message */ | |
1457 no_wait_return = FALSE; | |
1458 wait_return(FALSE); | |
1459 } | |
1460 | |
1461 #ifdef FEAT_AUTOCMD | |
1462 /* Position the cursor again, the autocommands may have moved it */ | |
1463 # ifdef FEAT_GUI | |
1464 if (!gui.in_use) | |
1465 # endif | |
1466 windgoto((int)Rows - 1, 0); | |
1467 #endif | |
1468 | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2312
diff
changeset
|
1469 #ifdef FEAT_LUA |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2312
diff
changeset
|
1470 lua_end(); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2312
diff
changeset
|
1471 #endif |
14 | 1472 #ifdef FEAT_MZSCHEME |
1473 mzscheme_end(); | |
1474 #endif | |
6 | 1475 #ifdef FEAT_TCL |
1476 tcl_end(); | |
1477 #endif | |
1478 #ifdef FEAT_RUBY | |
1479 ruby_end(); | |
1480 #endif | |
1481 #ifdef FEAT_PYTHON | |
1482 python_end(); | |
1483 #endif | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
1484 #ifdef FEAT_PYTHON3 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
1485 python3_end(); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
1486 #endif |
6 | 1487 #ifdef FEAT_PERL |
1488 perl_end(); | |
1489 #endif | |
1490 #if defined(USE_ICONV) && defined(DYNAMIC_ICONV) | |
1491 iconv_end(); | |
1492 #endif | |
1493 #ifdef FEAT_NETBEANS_INTG | |
1494 netbeans_end(); | |
1495 #endif | |
1385 | 1496 #ifdef FEAT_CSCOPE |
1497 cs_end(); | |
1498 #endif | |
1405 | 1499 #ifdef FEAT_EVAL |
1500 if (garbage_collect_at_exit) | |
1501 garbage_collect(); | |
1502 #endif | |
6 | 1503 |
1504 mch_exit(exitval); | |
1505 } | |
1506 | |
2730 | 1507 #ifndef NO_VIM_MAIN |
6 | 1508 /* |
1509 * Get a (optional) count for a Vim argument. | |
1510 */ | |
1511 static int | |
1512 get_number_arg(p, idx, def) | |
1513 char_u *p; /* pointer to argument */ | |
1514 int *idx; /* index in argument, is incremented */ | |
1515 int def; /* default value */ | |
1516 { | |
1517 if (vim_isdigit(p[*idx])) | |
1518 { | |
1519 def = atoi((char *)&(p[*idx])); | |
1520 while (vim_isdigit(p[*idx])) | |
1521 *idx = *idx + 1; | |
1522 } | |
1523 return def; | |
1524 } | |
1525 | |
443 | 1526 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
1527 /* | |
1528 * Setup to use the current locale (for ctype() and many other things). | |
1529 */ | |
1530 static void | |
1531 init_locale() | |
1532 { | |
1533 setlocale(LC_ALL, ""); | |
1624 | 1534 |
2201
4c6b4298852f
Other solution for GTK not changing the locale.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
1535 # ifdef FEAT_GUI_GTK |
4c6b4298852f
Other solution for GTK not changing the locale.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
1536 /* Tell Gtk not to change our locale settings. */ |
4c6b4298852f
Other solution for GTK not changing the locale.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
1537 gtk_disable_setlocale(); |
4c6b4298852f
Other solution for GTK not changing the locale.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
1538 # endif |
1624 | 1539 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
1540 /* Make sure strtod() uses a decimal point, not a comma. */ | |
1541 setlocale(LC_NUMERIC, "C"); | |
1542 # endif | |
1543 | |
534 | 1544 # ifdef WIN32 |
1545 /* Apparently MS-Windows printf() may cause a crash when we give it 8-bit | |
1546 * text while it's expecting text in the current locale. This call avoids | |
1547 * that. */ | |
1548 setlocale(LC_CTYPE, "C"); | |
1549 # endif | |
443 | 1550 |
1551 # ifdef FEAT_GETTEXT | |
1552 { | |
1553 int mustfree = FALSE; | |
1554 char_u *p; | |
1555 | |
1556 # ifdef DYNAMIC_GETTEXT | |
1557 /* Initialize the gettext library */ | |
1558 dyn_libintl_init(NULL); | |
1559 # endif | |
1560 /* expand_env() doesn't work yet, because chartab[] is not initialized | |
1561 * yet, call vim_getenv() directly */ | |
1562 p = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); | |
1563 if (p != NULL && *p != NUL) | |
1564 { | |
1297 | 1565 vim_snprintf((char *)NameBuff, MAXPATHL, "%s/lang", p); |
443 | 1566 bindtextdomain(VIMPACKAGE, (char *)NameBuff); |
1567 } | |
1568 if (mustfree) | |
1569 vim_free(p); | |
1570 textdomain(VIMPACKAGE); | |
1571 } | |
1572 # endif | |
1573 } | |
1574 #endif | |
1575 | |
1576 /* | |
1577 * Check for: [r][e][g][vi|vim|view][diff][ex[im]] | |
1578 * If the executable name starts with "r" we disable shell commands. | |
1579 * If the next character is "e" we run in Easy mode. | |
1580 * If the next character is "g" we run the GUI version. | |
1581 * If the next characters are "view" we start in readonly mode. | |
1582 * If the next characters are "diff" or "vimdiff" we start in diff mode. | |
1583 * If the next characters are "ex" we start in Ex mode. If it's followed | |
1584 * by "im" use improved Ex mode. | |
1585 */ | |
1586 static void | |
1587 parse_command_name(parmp) | |
1588 mparm_T *parmp; | |
1589 { | |
1590 char_u *initstr; | |
1591 | |
1592 initstr = gettail((char_u *)parmp->argv[0]); | |
1593 | |
1594 #ifdef MACOS_X_UNIX | |
1595 /* An issue has been seen when launching Vim in such a way that | |
1596 * $PWD/$ARGV[0] or $ARGV[0] is not the absolute path to the | |
1597 * executable or a symbolic link of it. Until this issue is resolved | |
1598 * we prohibit the GUI from being used. | |
1599 */ | |
1600 if (STRCMP(initstr, parmp->argv[0]) == 0) | |
1601 disallow_gui = TRUE; | |
1602 | |
1603 /* TODO: On MacOS X default to gui if argv[0] ends in: | |
769 | 1604 * /Vim.app/Contents/MacOS/Vim */ |
443 | 1605 #endif |
1606 | |
1607 #ifdef FEAT_EVAL | |
1608 set_vim_var_string(VV_PROGNAME, initstr, -1); | |
1609 #endif | |
1610 | |
1611 if (TOLOWER_ASC(initstr[0]) == 'r') | |
1612 { | |
1613 restricted = TRUE; | |
1614 ++initstr; | |
1615 } | |
1616 | |
2133
2b273c71a14b
updated for version 7.2.415
Bram Moolenaar <bram@zimbu.org>
parents:
2021
diff
changeset
|
1617 /* Use evim mode for "evim" and "egvim", not for "editor". */ |
443 | 1618 if (TOLOWER_ASC(initstr[0]) == 'e' |
1619 && (TOLOWER_ASC(initstr[1]) == 'v' | |
1620 || TOLOWER_ASC(initstr[1]) == 'g')) | |
1621 { | |
1622 #ifdef FEAT_GUI | |
1623 gui.starting = TRUE; | |
1624 #endif | |
1625 parmp->evim_mode = TRUE; | |
1626 ++initstr; | |
1627 } | |
1628 | |
1722 | 1629 /* "gvim" starts the GUI. Also accept "Gvim" for MS-Windows. */ |
1630 if (TOLOWER_ASC(initstr[0]) == 'g') | |
443 | 1631 { |
1632 main_start_gui(); | |
1633 #ifdef FEAT_GUI | |
1634 ++initstr; | |
1635 #endif | |
1636 } | |
1637 | |
1638 if (STRNICMP(initstr, "view", 4) == 0) | |
1639 { | |
1640 readonlymode = TRUE; | |
1641 curbuf->b_p_ro = TRUE; | |
1642 p_uc = 10000; /* don't update very often */ | |
1643 initstr += 4; | |
1644 } | |
1645 else if (STRNICMP(initstr, "vim", 3) == 0) | |
1646 initstr += 3; | |
1647 | |
1648 /* Catch "[r][g]vimdiff" and "[r][g]viewdiff". */ | |
1649 if (STRICMP(initstr, "diff") == 0) | |
1650 { | |
1651 #ifdef FEAT_DIFF | |
1652 parmp->diff_mode = TRUE; | |
1653 #else | |
1654 mch_errmsg(_("This Vim was not compiled with the diff feature.")); | |
1655 mch_errmsg("\n"); | |
1656 mch_exit(2); | |
1657 #endif | |
1658 } | |
1659 | |
1660 if (STRNICMP(initstr, "ex", 2) == 0) | |
1661 { | |
1662 if (STRNICMP(initstr + 2, "im", 2) == 0) | |
1663 exmode_active = EXMODE_VIM; | |
1664 else | |
1665 exmode_active = EXMODE_NORMAL; | |
1666 change_compatible(TRUE); /* set 'compatible' */ | |
1667 } | |
1668 } | |
1669 | |
6 | 1670 /* |
440 | 1671 * Get the name of the display, before gui_prepare() removes it from |
1672 * argv[]. Used for the xterm-clipboard display. | |
1673 * | |
1376 | 1674 * Also find the --server... arguments and --socketid and --windowid |
440 | 1675 */ |
1676 static void | |
443 | 1677 early_arg_scan(parmp) |
1883 | 1678 mparm_T *parmp UNUSED; |
440 | 1679 { |
1750 | 1680 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_CLIENTSERVER) \ |
1681 || !defined(FEAT_NETBEANS_INTG) | |
443 | 1682 int argc = parmp->argc; |
1683 char **argv = parmp->argv; | |
440 | 1684 int i; |
1685 | |
1686 for (i = 1; i < argc; i++) | |
1687 { | |
1688 if (STRCMP(argv[i], "--") == 0) | |
1689 break; | |
1690 # ifdef FEAT_XCLIPBOARD | |
1691 else if (STRICMP(argv[i], "-display") == 0 | |
575 | 1692 # if defined(FEAT_GUI_GTK) |
440 | 1693 || STRICMP(argv[i], "--display") == 0 |
1694 # endif | |
1695 ) | |
1696 { | |
1697 if (i == argc - 1) | |
1698 mainerr_arg_missing((char_u *)argv[i]); | |
1699 xterm_display = argv[++i]; | |
1700 } | |
1701 # endif | |
1702 # ifdef FEAT_CLIENTSERVER | |
1703 else if (STRICMP(argv[i], "--servername") == 0) | |
1704 { | |
1705 if (i == argc - 1) | |
1706 mainerr_arg_missing((char_u *)argv[i]); | |
1707 parmp->serverName_arg = (char_u *)argv[++i]; | |
1708 } | |
734 | 1709 else if (STRICMP(argv[i], "--serverlist") == 0) |
440 | 1710 parmp->serverArg = TRUE; |
734 | 1711 else if (STRNICMP(argv[i], "--remote", 8) == 0) |
440 | 1712 { |
1713 parmp->serverArg = TRUE; | |
734 | 1714 # ifdef FEAT_GUI |
1715 if (strstr(argv[i], "-wait") != 0) | |
1716 /* don't fork() when starting the GUI to edit files ourself */ | |
1717 gui.dofork = FALSE; | |
1718 # endif | |
440 | 1719 } |
1720 # endif | |
1376 | 1721 |
1722 # if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32) | |
1723 # ifdef FEAT_GUI_W32 | |
1724 else if (STRICMP(argv[i], "--windowid") == 0) | |
1725 # else | |
440 | 1726 else if (STRICMP(argv[i], "--socketid") == 0) |
1376 | 1727 # endif |
440 | 1728 { |
1570 | 1729 long_u id; |
1730 int count; | |
440 | 1731 |
1732 if (i == argc - 1) | |
1733 mainerr_arg_missing((char_u *)argv[i]); | |
1734 if (STRNICMP(argv[i+1], "0x", 2) == 0) | |
1570 | 1735 count = sscanf(&(argv[i + 1][2]), SCANF_HEX_LONG_U, &id); |
440 | 1736 else |
1570 | 1737 count = sscanf(argv[i + 1], SCANF_DECIMAL_LONG_U, &id); |
440 | 1738 if (count != 1) |
1739 mainerr(ME_INVALID_ARG, (char_u *)argv[i]); | |
1740 else | |
1376 | 1741 # ifdef FEAT_GUI_W32 |
1742 win_socket_id = id; | |
1743 # else | |
1744 gtk_socket_id = id; | |
1745 # endif | |
440 | 1746 i++; |
1747 } | |
1376 | 1748 # endif |
1749 # ifdef FEAT_GUI_GTK | |
440 | 1750 else if (STRICMP(argv[i], "--echo-wid") == 0) |
1751 echo_wid_arg = TRUE; | |
1752 # endif | |
1750 | 1753 # ifndef FEAT_NETBEANS_INTG |
1754 else if (strncmp(argv[i], "-nb", (size_t)3) == 0) | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1755 { |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1756 mch_errmsg(_("'-nb' cannot be used: not enabled at compile time\n")); |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1757 mch_exit(2); |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1758 } |
1750 | 1759 # endif |
1760 | |
440 | 1761 } |
1762 #endif | |
1763 } | |
1764 | |
1765 /* | |
443 | 1766 * Scan the command line arguments. |
1767 */ | |
1768 static void | |
1769 command_line_scan(parmp) | |
1770 mparm_T *parmp; | |
1771 { | |
1772 int argc = parmp->argc; | |
1773 char **argv = parmp->argv; | |
1774 int argv_idx; /* index in argv[n][] */ | |
1775 int had_minmin = FALSE; /* found "--" argument */ | |
1776 int want_argument; /* option argument with argument */ | |
1777 int c; | |
445 | 1778 char_u *p = NULL; |
443 | 1779 long n; |
1780 | |
1781 --argc; | |
1782 ++argv; | |
1783 argv_idx = 1; /* active option letter is argv[0][argv_idx] */ | |
1784 while (argc > 0) | |
1785 { | |
1786 /* | |
1787 * "+" or "+{number}" or "+/{pat}" or "+{command}" argument. | |
1788 */ | |
1789 if (argv[0][0] == '+' && !had_minmin) | |
1790 { | |
1791 if (parmp->n_commands >= MAX_ARG_CMDS) | |
1792 mainerr(ME_EXTRA_CMD, NULL); | |
1793 argv_idx = -1; /* skip to next argument */ | |
1794 if (argv[0][1] == NUL) | |
1795 parmp->commands[parmp->n_commands++] = (char_u *)"$"; | |
1796 else | |
1797 parmp->commands[parmp->n_commands++] = (char_u *)&(argv[0][1]); | |
1798 } | |
1799 | |
1800 /* | |
1801 * Optional argument. | |
1802 */ | |
1803 else if (argv[0][0] == '-' && !had_minmin) | |
1804 { | |
1805 want_argument = FALSE; | |
1806 c = argv[0][argv_idx++]; | |
1807 #ifdef VMS | |
1808 /* | |
1809 * VMS only uses upper case command lines. Interpret "-X" as "-x" | |
1810 * and "-/X" as "-X". | |
1811 */ | |
1812 if (c == '/') | |
1813 { | |
1814 c = argv[0][argv_idx++]; | |
1815 c = TOUPPER_ASC(c); | |
1816 } | |
1817 else | |
1818 c = TOLOWER_ASC(c); | |
1819 #endif | |
1820 switch (c) | |
1821 { | |
1822 case NUL: /* "vim -" read from stdin */ | |
1823 /* "ex -" silent mode */ | |
1824 if (exmode_active) | |
1825 silent_mode = TRUE; | |
1826 else | |
1827 { | |
1828 if (parmp->edit_type != EDIT_NONE) | |
1829 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); | |
1830 parmp->edit_type = EDIT_STDIN; | |
1831 read_cmd_fd = 2; /* read from stderr instead of stdin */ | |
1832 } | |
1833 argv_idx = -1; /* skip to next argument */ | |
1834 break; | |
1835 | |
1836 case '-': /* "--" don't take any more option arguments */ | |
1837 /* "--help" give help message */ | |
1838 /* "--version" give version message */ | |
1839 /* "--literal" take files literally */ | |
1840 /* "--nofork" don't fork */ | |
1841 /* "--noplugin[s]" skip plugins */ | |
1842 /* "--cmd <cmd>" execute cmd before vimrc */ | |
1843 if (STRICMP(argv[0] + argv_idx, "help") == 0) | |
1844 usage(); | |
1845 else if (STRICMP(argv[0] + argv_idx, "version") == 0) | |
1846 { | |
1847 Columns = 80; /* need to init Columns */ | |
1848 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ | |
1849 list_version(); | |
1850 msg_putchar('\n'); | |
1851 msg_didout = FALSE; | |
1852 mch_exit(0); | |
1853 } | |
1854 else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) | |
1855 { | |
1856 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) | |
1857 parmp->literal = TRUE; | |
1858 #endif | |
1859 } | |
1860 else if (STRNICMP(argv[0] + argv_idx, "nofork", 6) == 0) | |
1861 { | |
1862 #ifdef FEAT_GUI | |
1863 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
1864 #endif | |
1865 } | |
1866 else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) | |
1867 p_lpl = FALSE; | |
1868 else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0) | |
1869 { | |
1870 want_argument = TRUE; | |
1871 argv_idx += 3; | |
1872 } | |
1989 | 1873 else if (STRNICMP(argv[0] + argv_idx, "startuptime", 11) == 0) |
1874 { | |
1875 want_argument = TRUE; | |
1876 argv_idx += 11; | |
1877 } | |
443 | 1878 #ifdef FEAT_CLIENTSERVER |
1879 else if (STRNICMP(argv[0] + argv_idx, "serverlist", 10) == 0) | |
1880 ; /* already processed -- no arg */ | |
1881 else if (STRNICMP(argv[0] + argv_idx, "servername", 10) == 0 | |
1882 || STRNICMP(argv[0] + argv_idx, "serversend", 10) == 0) | |
1883 { | |
1884 /* already processed -- snatch the following arg */ | |
1885 if (argc > 1) | |
1886 { | |
1887 --argc; | |
1888 ++argv; | |
1889 } | |
1890 } | |
1891 #endif | |
1376 | 1892 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32) |
1893 # ifdef FEAT_GUI_GTK | |
443 | 1894 else if (STRNICMP(argv[0] + argv_idx, "socketid", 8) == 0) |
1376 | 1895 # else |
1896 else if (STRNICMP(argv[0] + argv_idx, "windowid", 8) == 0) | |
1897 # endif | |
443 | 1898 { |
1899 /* already processed -- snatch the following arg */ | |
1900 if (argc > 1) | |
1901 { | |
1902 --argc; | |
1903 ++argv; | |
1904 } | |
1905 } | |
1376 | 1906 #endif |
1907 #ifdef FEAT_GUI_GTK | |
443 | 1908 else if (STRNICMP(argv[0] + argv_idx, "echo-wid", 8) == 0) |
1909 { | |
1910 /* already processed, skip */ | |
1911 } | |
1912 #endif | |
1913 else | |
1914 { | |
1915 if (argv[0][argv_idx]) | |
1916 mainerr(ME_UNKNOWN_OPTION, (char_u *)argv[0]); | |
1917 had_minmin = TRUE; | |
1918 } | |
1919 if (!want_argument) | |
1920 argv_idx = -1; /* skip to next argument */ | |
1921 break; | |
1922 | |
1923 case 'A': /* "-A" start in Arabic mode */ | |
1924 #ifdef FEAT_ARABIC | |
1925 set_option_value((char_u *)"arabic", 1L, NULL, 0); | |
1926 #else | |
1927 mch_errmsg(_(e_noarabic)); | |
1928 mch_exit(2); | |
1929 #endif | |
1930 break; | |
1931 | |
1932 case 'b': /* "-b" binary mode */ | |
445 | 1933 /* Needs to be effective before expanding file names, because |
1934 * for Win32 this makes us edit a shortcut file itself, | |
1935 * instead of the file it links to. */ | |
1936 set_options_bin(curbuf->b_p_bin, 1, 0); | |
1937 curbuf->b_p_bin = 1; /* binary file I/O */ | |
443 | 1938 break; |
1939 | |
1940 case 'C': /* "-C" Compatible */ | |
1941 change_compatible(TRUE); | |
1942 break; | |
1943 | |
1944 case 'e': /* "-e" Ex mode */ | |
1945 exmode_active = EXMODE_NORMAL; | |
1946 break; | |
1947 | |
1948 case 'E': /* "-E" Improved Ex mode */ | |
1949 exmode_active = EXMODE_VIM; | |
1950 break; | |
1951 | |
1952 case 'f': /* "-f" GUI: run in foreground. Amiga: open | |
1953 window directly, not with newcli */ | |
1954 #ifdef FEAT_GUI | |
1955 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
1956 #endif | |
1957 break; | |
1958 | |
1959 case 'g': /* "-g" start GUI */ | |
1960 main_start_gui(); | |
1961 break; | |
1962 | |
1963 case 'F': /* "-F" start in Farsi mode: rl + fkmap set */ | |
1964 #ifdef FEAT_FKMAP | |
1509 | 1965 p_fkmap = TRUE; |
1966 set_option_value((char_u *)"rl", 1L, NULL, 0); | |
443 | 1967 #else |
1968 mch_errmsg(_(e_nofarsi)); | |
1969 mch_exit(2); | |
1970 #endif | |
1971 break; | |
1972 | |
1973 case 'h': /* "-h" give help message */ | |
1974 #ifdef FEAT_GUI_GNOME | |
1975 /* Tell usage() to exit for "gvim". */ | |
1976 gui.starting = FALSE; | |
1977 #endif | |
1978 usage(); | |
1979 break; | |
1980 | |
1981 case 'H': /* "-H" start in Hebrew mode: rl + hkmap set */ | |
1982 #ifdef FEAT_RIGHTLEFT | |
1509 | 1983 p_hkmap = TRUE; |
1984 set_option_value((char_u *)"rl", 1L, NULL, 0); | |
443 | 1985 #else |
1986 mch_errmsg(_(e_nohebrew)); | |
1987 mch_exit(2); | |
1988 #endif | |
1989 break; | |
1990 | |
1991 case 'l': /* "-l" lisp mode, 'lisp' and 'showmatch' on */ | |
1992 #ifdef FEAT_LISP | |
1993 set_option_value((char_u *)"lisp", 1L, NULL, 0); | |
1994 p_sm = TRUE; | |
1995 #endif | |
1996 break; | |
1997 | |
1998 case 'M': /* "-M" no changes or writing of files */ | |
1999 reset_modifiable(); | |
2000 /* FALLTHROUGH */ | |
2001 | |
2002 case 'm': /* "-m" no writing of files */ | |
2003 p_write = FALSE; | |
2004 break; | |
2005 | |
2006 case 'y': /* "-y" easy mode */ | |
2007 #ifdef FEAT_GUI | |
2008 gui.starting = TRUE; /* start GUI a bit later */ | |
2009 #endif | |
2010 parmp->evim_mode = TRUE; | |
2011 break; | |
2012 | |
2013 case 'N': /* "-N" Nocompatible */ | |
2014 change_compatible(FALSE); | |
2015 break; | |
2016 | |
2017 case 'n': /* "-n" no swap file */ | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2018 #ifdef FEAT_NETBEANS_INTG |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2019 /* checking for "-nb", netbeans parameters */ |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2020 if (argv[0][argv_idx] == 'b') |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2021 { |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2022 netbeansArg = argv[0]; |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2023 argv_idx = -1; /* skip to next argument */ |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2024 } |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2025 else |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2026 #endif |
443 | 2027 parmp->no_swap_file = TRUE; |
2028 break; | |
2029 | |
673 | 2030 case 'p': /* "-p[N]" open N tab pages */ |
674 | 2031 #ifdef TARGET_API_MAC_OSX |
2032 /* For some reason on MacOS X, an argument like: | |
2033 -psn_0_10223617 is passed in when invoke from Finder | |
2034 or with the 'open' command */ | |
2035 if (argv[0][argv_idx] == 's') | |
2036 { | |
2037 argv_idx = -1; /* bypass full -psn */ | |
2038 main_start_gui(); | |
2039 break; | |
2040 } | |
2041 #endif | |
673 | 2042 #ifdef FEAT_WINDOWS |
2043 /* default is 0: open window for each file */ | |
2044 parmp->window_count = get_number_arg((char_u *)argv[0], | |
2045 &argv_idx, 0); | |
2046 parmp->window_layout = WIN_TABS; | |
2047 #endif | |
2048 break; | |
2049 | |
443 | 2050 case 'o': /* "-o[N]" open N horizontal split windows */ |
2051 #ifdef FEAT_WINDOWS | |
2052 /* default is 0: open window for each file */ | |
445 | 2053 parmp->window_count = get_number_arg((char_u *)argv[0], |
2054 &argv_idx, 0); | |
673 | 2055 parmp->window_layout = WIN_HOR; |
443 | 2056 #endif |
2057 break; | |
2058 | |
2059 case 'O': /* "-O[N]" open N vertical split windows */ | |
2060 #if defined(FEAT_VERTSPLIT) && defined(FEAT_WINDOWS) | |
2061 /* default is 0: open window for each file */ | |
445 | 2062 parmp->window_count = get_number_arg((char_u *)argv[0], |
2063 &argv_idx, 0); | |
673 | 2064 parmp->window_layout = WIN_VER; |
443 | 2065 #endif |
2066 break; | |
2067 | |
2068 #ifdef FEAT_QUICKFIX | |
2069 case 'q': /* "-q" QuickFix mode */ | |
2070 if (parmp->edit_type != EDIT_NONE) | |
2071 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); | |
2072 parmp->edit_type = EDIT_QF; | |
2073 if (argv[0][argv_idx]) /* "-q{errorfile}" */ | |
2074 { | |
2075 parmp->use_ef = (char_u *)argv[0] + argv_idx; | |
2076 argv_idx = -1; | |
2077 } | |
2078 else if (argc > 1) /* "-q {errorfile}" */ | |
2079 want_argument = TRUE; | |
2080 break; | |
2081 #endif | |
2082 | |
2083 case 'R': /* "-R" readonly mode */ | |
2084 readonlymode = TRUE; | |
2085 curbuf->b_p_ro = TRUE; | |
2086 p_uc = 10000; /* don't update very often */ | |
2087 break; | |
2088 | |
2089 case 'r': /* "-r" recovery mode */ | |
2090 case 'L': /* "-L" recovery mode */ | |
2091 recoverymode = 1; | |
2092 break; | |
2093 | |
2094 case 's': | |
2095 if (exmode_active) /* "-s" silent (batch) mode */ | |
2096 silent_mode = TRUE; | |
2097 else /* "-s {scriptin}" read from script file */ | |
2098 want_argument = TRUE; | |
2099 break; | |
2100 | |
2101 case 't': /* "-t {tag}" or "-t{tag}" jump to tag */ | |
2102 if (parmp->edit_type != EDIT_NONE) | |
2103 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); | |
2104 parmp->edit_type = EDIT_TAG; | |
2105 if (argv[0][argv_idx]) /* "-t{tag}" */ | |
2106 { | |
2107 parmp->tagname = (char_u *)argv[0] + argv_idx; | |
2108 argv_idx = -1; | |
2109 } | |
2110 else /* "-t {tag}" */ | |
2111 want_argument = TRUE; | |
2112 break; | |
2113 | |
2114 #ifdef FEAT_EVAL | |
2115 case 'D': /* "-D" Debugging */ | |
2116 parmp->use_debug_break_level = 9999; | |
2117 break; | |
2118 #endif | |
2119 #ifdef FEAT_DIFF | |
2120 case 'd': /* "-d" 'diff' */ | |
2121 # ifdef AMIGA | |
2122 /* check for "-dev {device}" */ | |
2123 if (argv[0][argv_idx] == 'e' && argv[0][argv_idx + 1] == 'v') | |
2124 want_argument = TRUE; | |
2125 else | |
2126 # endif | |
2127 parmp->diff_mode = TRUE; | |
2128 break; | |
2129 #endif | |
2130 case 'V': /* "-V{N}" Verbose level */ | |
2131 /* default is 10: a little bit verbose */ | |
2132 p_verbose = get_number_arg((char_u *)argv[0], &argv_idx, 10); | |
2133 if (argv[0][argv_idx] != NUL) | |
2134 { | |
2135 set_option_value((char_u *)"verbosefile", 0L, | |
2136 (char_u *)argv[0] + argv_idx, 0); | |
835 | 2137 argv_idx = (int)STRLEN(argv[0]); |
443 | 2138 } |
2139 break; | |
2140 | |
2141 case 'v': /* "-v" Vi-mode (as if called "vi") */ | |
2142 exmode_active = 0; | |
2143 #ifdef FEAT_GUI | |
2144 gui.starting = FALSE; /* don't start GUI */ | |
2145 #endif | |
2146 break; | |
2147 | |
2148 case 'w': /* "-w{number}" set window height */ | |
2149 /* "-w {scriptout}" write to script */ | |
2150 if (vim_isdigit(((char_u *)argv[0])[argv_idx])) | |
2151 { | |
2152 n = get_number_arg((char_u *)argv[0], &argv_idx, 10); | |
2153 set_option_value((char_u *)"window", n, NULL, 0); | |
2154 break; | |
2155 } | |
2156 want_argument = TRUE; | |
2157 break; | |
2158 | |
2159 #ifdef FEAT_CRYPT | |
2160 case 'x': /* "-x" encrypted reading/writing of files */ | |
2161 parmp->ask_for_key = TRUE; | |
2162 break; | |
2163 #endif | |
2164 | |
2165 case 'X': /* "-X" don't connect to X server */ | |
2166 #if (defined(UNIX) || defined(VMS)) && defined(FEAT_X11) | |
2167 x_no_connect = TRUE; | |
2168 #endif | |
2169 break; | |
2170 | |
2171 case 'Z': /* "-Z" restricted mode */ | |
2172 restricted = TRUE; | |
2173 break; | |
2174 | |
2175 case 'c': /* "-c{command}" or "-c {command}" execute | |
2176 command */ | |
2177 if (argv[0][argv_idx] != NUL) | |
2178 { | |
2179 if (parmp->n_commands >= MAX_ARG_CMDS) | |
2180 mainerr(ME_EXTRA_CMD, NULL); | |
445 | 2181 parmp->commands[parmp->n_commands++] = (char_u *)argv[0] |
2182 + argv_idx; | |
443 | 2183 argv_idx = -1; |
2184 break; | |
2185 } | |
2186 /*FALLTHROUGH*/ | |
2187 case 'S': /* "-S {file}" execute Vim script */ | |
2188 case 'i': /* "-i {viminfo}" use for viminfo */ | |
2189 #ifndef FEAT_DIFF | |
2190 case 'd': /* "-d {device}" device (for Amiga) */ | |
2191 #endif | |
2192 case 'T': /* "-T {terminal}" terminal name */ | |
2193 case 'u': /* "-u {vimrc}" vim inits file */ | |
2194 case 'U': /* "-U {gvimrc}" gvim inits file */ | |
2195 case 'W': /* "-W {scriptout}" overwrite */ | |
2196 #ifdef FEAT_GUI_W32 | |
2197 case 'P': /* "-P {parent title}" MDI parent */ | |
2198 #endif | |
2199 want_argument = TRUE; | |
2200 break; | |
2201 | |
2202 default: | |
2203 mainerr(ME_UNKNOWN_OPTION, (char_u *)argv[0]); | |
2204 } | |
2205 | |
2206 /* | |
2207 * Handle option arguments with argument. | |
2208 */ | |
2209 if (want_argument) | |
2210 { | |
2211 /* | |
2212 * Check for garbage immediately after the option letter. | |
2213 */ | |
2214 if (argv[0][argv_idx] != NUL) | |
2215 mainerr(ME_GARBAGE, (char_u *)argv[0]); | |
2216 | |
2217 --argc; | |
1989 | 2218 if (argc < 1 && c != 'S') /* -S has an optional argument */ |
443 | 2219 mainerr_arg_missing((char_u *)argv[0]); |
2220 ++argv; | |
2221 argv_idx = -1; | |
2222 | |
2223 switch (c) | |
2224 { | |
2225 case 'c': /* "-c {command}" execute command */ | |
2226 case 'S': /* "-S {file}" execute Vim script */ | |
2227 if (parmp->n_commands >= MAX_ARG_CMDS) | |
2228 mainerr(ME_EXTRA_CMD, NULL); | |
2229 if (c == 'S') | |
2230 { | |
2231 char *a; | |
2232 | |
2233 if (argc < 1) | |
2234 /* "-S" without argument: use default session file | |
2235 * name. */ | |
2236 a = SESSION_FILE; | |
2237 else if (argv[0][0] == '-') | |
2238 { | |
2239 /* "-S" followed by another option: use default | |
2240 * session file name. */ | |
2241 a = SESSION_FILE; | |
2242 ++argc; | |
2243 --argv; | |
2244 } | |
2245 else | |
2246 a = argv[0]; | |
2247 p = alloc((unsigned)(STRLEN(a) + 4)); | |
2248 if (p == NULL) | |
2249 mch_exit(2); | |
2250 sprintf((char *)p, "so %s", a); | |
2251 parmp->cmds_tofree[parmp->n_commands] = TRUE; | |
2252 parmp->commands[parmp->n_commands++] = p; | |
2253 } | |
2254 else | |
445 | 2255 parmp->commands[parmp->n_commands++] = |
2256 (char_u *)argv[0]; | |
443 | 2257 break; |
2258 | |
1989 | 2259 case '-': |
2260 if (argv[-1][2] == 'c') | |
2261 { | |
2262 /* "--cmd {command}" execute command */ | |
2263 if (parmp->n_pre_commands >= MAX_ARG_CMDS) | |
2264 mainerr(ME_EXTRA_CMD, NULL); | |
2265 parmp->pre_commands[parmp->n_pre_commands++] = | |
445 | 2266 (char_u *)argv[0]; |
1989 | 2267 } |
2268 /* "--startuptime <file>" already handled */ | |
443 | 2269 break; |
2270 | |
2271 /* case 'd': -d {device} is handled in mch_check_win() for the | |
2272 * Amiga */ | |
2273 | |
2274 #ifdef FEAT_QUICKFIX | |
2275 case 'q': /* "-q {errorfile}" QuickFix mode */ | |
2276 parmp->use_ef = (char_u *)argv[0]; | |
2277 break; | |
2278 #endif | |
2279 | |
2280 case 'i': /* "-i {viminfo}" use for viminfo */ | |
2281 use_viminfo = (char_u *)argv[0]; | |
2282 break; | |
2283 | |
2284 case 's': /* "-s {scriptin}" read from script file */ | |
2285 if (scriptin[0] != NULL) | |
2286 { | |
2287 scripterror: | |
2288 mch_errmsg(_("Attempt to open script file again: \"")); | |
2289 mch_errmsg(argv[-1]); | |
2290 mch_errmsg(" "); | |
2291 mch_errmsg(argv[0]); | |
2292 mch_errmsg("\"\n"); | |
2293 mch_exit(2); | |
2294 } | |
2295 if ((scriptin[0] = mch_fopen(argv[0], READBIN)) == NULL) | |
2296 { | |
2297 mch_errmsg(_("Cannot open for reading: \"")); | |
2298 mch_errmsg(argv[0]); | |
2299 mch_errmsg("\"\n"); | |
2300 mch_exit(2); | |
2301 } | |
2302 if (save_typebuf() == FAIL) | |
2303 mch_exit(2); /* out of memory */ | |
2304 break; | |
2305 | |
2306 case 't': /* "-t {tag}" */ | |
2307 parmp->tagname = (char_u *)argv[0]; | |
2308 break; | |
2309 | |
2310 case 'T': /* "-T {terminal}" terminal name */ | |
2311 /* | |
2312 * The -T term argument is always available and when | |
2313 * HAVE_TERMLIB is supported it overrides the environment | |
2314 * variable TERM. | |
2315 */ | |
2316 #ifdef FEAT_GUI | |
2317 if (term_is_gui((char_u *)argv[0])) | |
2318 gui.starting = TRUE; /* start GUI a bit later */ | |
2319 else | |
2320 #endif | |
2321 parmp->term = (char_u *)argv[0]; | |
2322 break; | |
2323 | |
2324 case 'u': /* "-u {vimrc}" vim inits file */ | |
2325 parmp->use_vimrc = (char_u *)argv[0]; | |
2326 break; | |
2327 | |
2328 case 'U': /* "-U {gvimrc}" gvim inits file */ | |
2329 #ifdef FEAT_GUI | |
2330 use_gvimrc = (char_u *)argv[0]; | |
2331 #endif | |
2332 break; | |
2333 | |
2334 case 'w': /* "-w {nr}" 'window' value */ | |
2335 /* "-w {scriptout}" append to script file */ | |
2336 if (vim_isdigit(*((char_u *)argv[0]))) | |
2337 { | |
2338 argv_idx = 0; | |
2339 n = get_number_arg((char_u *)argv[0], &argv_idx, 10); | |
2340 set_option_value((char_u *)"window", n, NULL, 0); | |
2341 argv_idx = -1; | |
2342 break; | |
2343 } | |
2344 /*FALLTHROUGH*/ | |
2345 case 'W': /* "-W {scriptout}" overwrite script file */ | |
2346 if (scriptout != NULL) | |
2347 goto scripterror; | |
2348 if ((scriptout = mch_fopen(argv[0], | |
2349 c == 'w' ? APPENDBIN : WRITEBIN)) == NULL) | |
2350 { | |
2351 mch_errmsg(_("Cannot open for script output: \"")); | |
2352 mch_errmsg(argv[0]); | |
2353 mch_errmsg("\"\n"); | |
2354 mch_exit(2); | |
2355 } | |
2356 break; | |
2357 | |
2358 #ifdef FEAT_GUI_W32 | |
2359 case 'P': /* "-P {parent title}" MDI parent */ | |
2360 gui_mch_set_parent(argv[0]); | |
2361 break; | |
2362 #endif | |
2363 } | |
2364 } | |
2365 } | |
2366 | |
2367 /* | |
2368 * File name argument. | |
2369 */ | |
2370 else | |
2371 { | |
2372 argv_idx = -1; /* skip to next argument */ | |
2373 | |
2374 /* Check for only one type of editing. */ | |
2375 if (parmp->edit_type != EDIT_NONE && parmp->edit_type != EDIT_FILE) | |
2376 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); | |
2377 parmp->edit_type = EDIT_FILE; | |
2378 | |
2379 #ifdef MSWIN | |
2380 /* Remember if the argument was a full path before changing | |
2381 * slashes to backslashes. */ | |
2382 if (argv[0][0] != NUL && argv[0][1] == ':' && argv[0][2] == '\\') | |
2383 parmp->full_path = TRUE; | |
2384 #endif | |
2385 | |
2386 /* Add the file to the global argument list. */ | |
2387 if (ga_grow(&global_alist.al_ga, 1) == FAIL | |
2388 || (p = vim_strsave((char_u *)argv[0])) == NULL) | |
2389 mch_exit(2); | |
2390 #ifdef FEAT_DIFF | |
2391 if (parmp->diff_mode && mch_isdir(p) && GARGCOUNT > 0 | |
2392 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
2393 { | |
2394 char_u *r; | |
2395 | |
2396 r = concat_fnames(p, gettail(alist_name(&GARGLIST[0])), TRUE); | |
2397 if (r != NULL) | |
2398 { | |
2399 vim_free(p); | |
2400 p = r; | |
2401 } | |
2402 } | |
2403 #endif | |
2404 #if defined(__CYGWIN32__) && !defined(WIN32) | |
2405 /* | |
2406 * If vim is invoked by non-Cygwin tools, convert away any | |
2407 * DOS paths, so things like .swp files are created correctly. | |
2408 * Look for evidence of non-Cygwin paths before we bother. | |
2409 * This is only for when using the Unix files. | |
2410 */ | |
2133
2b273c71a14b
updated for version 7.2.415
Bram Moolenaar <bram@zimbu.org>
parents:
2021
diff
changeset
|
2411 if (strpbrk(p, "\\:") != NULL && !path_with_url(p)) |
443 | 2412 { |
2413 char posix_path[PATH_MAX]; | |
2414 | |
1657 | 2415 # if CYGWIN_VERSION_DLL_MAJOR >= 1007 |
2416 cygwin_conv_path(CCP_WIN_A_TO_POSIX, p, posix_path, PATH_MAX); | |
2417 # else | |
443 | 2418 cygwin_conv_to_posix_path(p, posix_path); |
1657 | 2419 # endif |
443 | 2420 vim_free(p); |
2421 p = vim_strsave(posix_path); | |
2422 if (p == NULL) | |
2423 mch_exit(2); | |
2424 } | |
2425 #endif | |
587 | 2426 |
2427 #ifdef USE_FNAME_CASE | |
2428 /* Make the case of the file name match the actual file. */ | |
2429 fname_case(p, 0); | |
2430 #endif | |
2431 | |
443 | 2432 alist_add(&global_alist, p, |
2433 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) | |
445 | 2434 parmp->literal ? 2 : 0 /* add buffer nr after exp. */ |
443 | 2435 #else |
2436 2 /* add buffer number now and use curbuf */ | |
2437 #endif | |
2438 ); | |
2439 | |
2440 #if defined(FEAT_MBYTE) && defined(WIN32) | |
2441 { | |
2442 /* Remember this argument has been added to the argument list. | |
2443 * Needed when 'encoding' is changed. */ | |
819 | 2444 used_file_arg(argv[0], parmp->literal, parmp->full_path, |
1680 | 2445 # ifdef FEAT_DIFF |
2446 parmp->diff_mode | |
2447 # else | |
2448 FALSE | |
2449 # endif | |
2450 ); | |
443 | 2451 } |
2452 #endif | |
2453 } | |
2454 | |
2455 /* | |
2456 * If there are no more letters after the current "-", go to next | |
2457 * argument. argv_idx is set to -1 when the current argument is to be | |
2458 * skipped. | |
2459 */ | |
2460 if (argv_idx <= 0 || argv[0][argv_idx] == NUL) | |
2461 { | |
2462 --argc; | |
2463 ++argv; | |
2464 argv_idx = 1; | |
2465 } | |
2466 } | |
1093 | 2467 |
2468 #ifdef FEAT_EVAL | |
2469 /* If there is a "+123" or "-c" command, set v:swapcommand to the first | |
2470 * one. */ | |
2471 if (parmp->n_commands > 0) | |
2472 { | |
2473 p = alloc((unsigned)STRLEN(parmp->commands[0]) + 3); | |
2474 if (p != NULL) | |
2475 { | |
2476 sprintf((char *)p, ":%s\r", parmp->commands[0]); | |
2477 set_vim_var_string(VV_SWAPCOMMAND, p, -1); | |
2478 vim_free(p); | |
2479 } | |
2480 } | |
2481 #endif | |
443 | 2482 } |
2483 | |
2484 /* | |
2485 * Print a warning if stdout is not a terminal. | |
2486 * When starting in Ex mode and commands come from a file, set Silent mode. | |
2487 */ | |
2488 static void | |
2489 check_tty(parmp) | |
2490 mparm_T *parmp; | |
2491 { | |
2492 int input_isatty; /* is active input a terminal? */ | |
2493 | |
2494 input_isatty = mch_input_isatty(); | |
2495 if (exmode_active) | |
2496 { | |
2497 if (!input_isatty) | |
2498 silent_mode = TRUE; | |
2499 } | |
2500 else if (parmp->want_full_screen && (!parmp->stdout_isatty || !input_isatty) | |
2501 #ifdef FEAT_GUI | |
2502 /* don't want the delay when started from the desktop */ | |
2503 && !gui.starting | |
2504 #endif | |
2505 ) | |
2506 { | |
2507 #ifdef NBDEBUG | |
2508 /* | |
2509 * This shouldn't be necessary. But if I run netbeans with the log | |
2510 * output coming to the console and XOpenDisplay fails, I get vim | |
2511 * trying to start with input/output to my console tty. This fills my | |
2512 * input buffer so fast I can't even kill the process in under 2 | |
1226 | 2513 * minutes (and it beeps continuously the whole time :-) |
443 | 2514 */ |
2210 | 2515 if (netbeans_active() && (!parmp->stdout_isatty || !input_isatty)) |
443 | 2516 { |
2517 mch_errmsg(_("Vim: Error: Failure to start gvim from NetBeans\n")); | |
2518 exit(1); | |
2519 } | |
2520 #endif | |
2521 if (!parmp->stdout_isatty) | |
2522 mch_errmsg(_("Vim: Warning: Output is not to a terminal\n")); | |
2523 if (!input_isatty) | |
2524 mch_errmsg(_("Vim: Warning: Input is not from a terminal\n")); | |
2525 out_flush(); | |
2526 if (scriptin[0] == NULL) | |
2527 ui_delay(2000L, TRUE); | |
2528 TIME_MSG("Warning delay"); | |
2529 } | |
2530 } | |
2531 | |
2532 /* | |
2533 * Read text from stdin. | |
2534 */ | |
2535 static void | |
2536 read_stdin() | |
2537 { | |
2538 int i; | |
2539 | |
580 | 2540 #if defined(HAS_SWAP_EXISTS_ACTION) |
443 | 2541 /* When getting the ATTENTION prompt here, use a dialog */ |
2542 swap_exists_action = SEA_DIALOG; | |
2543 #endif | |
2544 no_wait_return = TRUE; | |
2545 i = msg_didany; | |
2546 set_buflisted(TRUE); | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
2547 (void)open_buffer(TRUE, NULL, 0); /* create memfile and read file */ |
443 | 2548 no_wait_return = FALSE; |
2549 msg_didany = i; | |
2550 TIME_MSG("reading stdin"); | |
580 | 2551 #if defined(HAS_SWAP_EXISTS_ACTION) |
443 | 2552 check_swap_exists_action(); |
2553 #endif | |
2554 #if !(defined(AMIGA) || defined(MACOS)) | |
2555 /* | |
2556 * Close stdin and dup it from stderr. Required for GPM to work | |
2557 * properly, and for running external commands. | |
2558 * Is there any other system that cannot do this? | |
2559 */ | |
2560 close(0); | |
1757 | 2561 ignored = dup(2); |
443 | 2562 #endif |
2563 } | |
2564 | |
2565 /* | |
2566 * Create the requested number of windows and edit buffers in them. | |
2567 * Also does recovery if "recoverymode" set. | |
2568 */ | |
2569 static void | |
2570 create_windows(parmp) | |
1883 | 2571 mparm_T *parmp UNUSED; |
443 | 2572 { |
2573 #ifdef FEAT_WINDOWS | |
944 | 2574 int dorewind; |
673 | 2575 int done = 0; |
2576 | |
443 | 2577 /* |
2578 * Create the number of windows that was requested. | |
2579 */ | |
2580 if (parmp->window_count == -1) /* was not set */ | |
2581 parmp->window_count = 1; | |
2582 if (parmp->window_count == 0) | |
2583 parmp->window_count = GARGCOUNT; | |
2584 if (parmp->window_count > 1) | |
2585 { | |
2586 /* Don't change the windows if there was a command in .vimrc that | |
2587 * already split some windows */ | |
673 | 2588 if (parmp->window_layout == 0) |
2589 parmp->window_layout = WIN_HOR; | |
2590 if (parmp->window_layout == WIN_TABS) | |
2591 { | |
2592 parmp->window_count = make_tabpages(parmp->window_count); | |
2593 TIME_MSG("making tab pages"); | |
2594 } | |
2595 else if (firstwin->w_next == NULL) | |
443 | 2596 { |
2597 parmp->window_count = make_windows(parmp->window_count, | |
673 | 2598 parmp->window_layout == WIN_VER); |
443 | 2599 TIME_MSG("making windows"); |
2600 } | |
2601 else | |
2602 parmp->window_count = win_count(); | |
2603 } | |
2604 else | |
2605 parmp->window_count = 1; | |
2606 #endif | |
2607 | |
2608 if (recoverymode) /* do recover */ | |
2609 { | |
2610 msg_scroll = TRUE; /* scroll message up */ | |
2611 ml_recover(); | |
2612 if (curbuf->b_ml.ml_mfp == NULL) /* failed */ | |
2613 getout(1); | |
717 | 2614 do_modelines(0); /* do modelines */ |
443 | 2615 } |
2616 else | |
2617 { | |
2618 /* | |
2619 * Open a buffer for windows that don't have one yet. | |
2620 * Commands in the .vimrc might have loaded a file or split the window. | |
2621 * Watch out for autocommands that delete a window. | |
2622 */ | |
2623 #ifdef FEAT_AUTOCMD | |
2624 /* | |
2625 * Don't execute Win/Buf Enter/Leave autocommands here | |
2626 */ | |
2627 ++autocmd_no_enter; | |
2628 ++autocmd_no_leave; | |
2629 #endif | |
2630 #ifdef FEAT_WINDOWS | |
944 | 2631 dorewind = TRUE; |
673 | 2632 while (done++ < 1000) |
2633 { | |
944 | 2634 if (dorewind) |
673 | 2635 { |
2636 if (parmp->window_layout == WIN_TABS) | |
2637 goto_tabpage(1); | |
2638 else | |
2639 curwin = firstwin; | |
2640 } | |
2641 else if (parmp->window_layout == WIN_TABS) | |
2642 { | |
2643 if (curtab->tp_next == NULL) | |
2644 break; | |
2645 goto_tabpage(0); | |
2646 } | |
2647 else | |
2648 { | |
2649 if (curwin->w_next == NULL) | |
2650 break; | |
2651 curwin = curwin->w_next; | |
2652 } | |
944 | 2653 dorewind = FALSE; |
443 | 2654 #endif |
2655 curbuf = curwin->w_buffer; | |
2656 if (curbuf->b_ml.ml_mfp == NULL) | |
2657 { | |
2658 #ifdef FEAT_FOLDING | |
2659 /* Set 'foldlevel' to 'foldlevelstart' if it's not negative. */ | |
2660 if (p_fdls >= 0) | |
2661 curwin->w_p_fdl = p_fdls; | |
2662 #endif | |
580 | 2663 #if defined(HAS_SWAP_EXISTS_ACTION) |
443 | 2664 /* When getting the ATTENTION prompt here, use a dialog */ |
2665 swap_exists_action = SEA_DIALOG; | |
2666 #endif | |
2667 set_buflisted(TRUE); | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
2668 |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
2669 /* create memfile, read file */ |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
2670 (void)open_buffer(FALSE, NULL, 0); |
443 | 2671 |
580 | 2672 #if defined(HAS_SWAP_EXISTS_ACTION) |
1036 | 2673 if (swap_exists_action == SEA_QUIT) |
2674 { | |
2675 if (got_int || only_one_window()) | |
2676 { | |
2677 /* abort selected or quit and only one window */ | |
2678 did_emsg = FALSE; /* avoid hit-enter prompt */ | |
2679 getout(1); | |
2680 } | |
2681 /* We can't close the window, it would disturb what | |
2682 * happens next. Clear the file name and set the arg | |
2683 * index to -1 to delete it later. */ | |
2684 setfname(curbuf, NULL, NULL, FALSE); | |
2685 curwin->w_arg_idx = -1; | |
2686 swap_exists_action = SEA_NONE; | |
2687 } | |
2688 else | |
2689 handle_swap_exists(NULL); | |
443 | 2690 #endif |
2691 #ifdef FEAT_AUTOCMD | |
944 | 2692 dorewind = TRUE; /* start again */ |
443 | 2693 #endif |
2694 } | |
2695 #ifdef FEAT_WINDOWS | |
2696 ui_breakcheck(); | |
2697 if (got_int) | |
2698 { | |
2699 (void)vgetc(); /* only break the file loading, not the rest */ | |
2700 break; | |
2701 } | |
673 | 2702 } |
443 | 2703 #endif |
673 | 2704 #ifdef FEAT_WINDOWS |
2705 if (parmp->window_layout == WIN_TABS) | |
2706 goto_tabpage(1); | |
2707 else | |
2708 curwin = firstwin; | |
2709 curbuf = curwin->w_buffer; | |
2710 #endif | |
443 | 2711 #ifdef FEAT_AUTOCMD |
2712 --autocmd_no_enter; | |
2713 --autocmd_no_leave; | |
2714 #endif | |
2715 } | |
2716 } | |
2717 | |
2718 #ifdef FEAT_WINDOWS | |
2719 /* | |
2720 * If opened more than one window, start editing files in the other | |
2721 * windows. make_windows() has already opened the windows. | |
2722 */ | |
2723 static void | |
2724 edit_buffers(parmp) | |
2725 mparm_T *parmp; | |
2726 { | |
2727 int arg_idx; /* index in argument list */ | |
2728 int i; | |
1036 | 2729 int advance = TRUE; |
443 | 2730 |
2731 # ifdef FEAT_AUTOCMD | |
2732 /* | |
2733 * Don't execute Win/Buf Enter/Leave autocommands here | |
2734 */ | |
2735 ++autocmd_no_enter; | |
2736 ++autocmd_no_leave; | |
2737 # endif | |
1036 | 2738 |
2739 /* When w_arg_idx is -1 remove the window (see create_windows()). */ | |
2740 if (curwin->w_arg_idx == -1) | |
2741 { | |
2742 win_close(curwin, TRUE); | |
2743 advance = FALSE; | |
2744 } | |
2745 | |
443 | 2746 arg_idx = 1; |
2747 for (i = 1; i < parmp->window_count; ++i) | |
2748 { | |
1036 | 2749 /* When w_arg_idx is -1 remove the window (see create_windows()). */ |
2750 if (curwin->w_arg_idx == -1) | |
673 | 2751 { |
1036 | 2752 ++arg_idx; |
2753 win_close(curwin, TRUE); | |
2754 advance = FALSE; | |
2755 continue; | |
673 | 2756 } |
1036 | 2757 |
2758 if (advance) | |
673 | 2759 { |
1036 | 2760 if (parmp->window_layout == WIN_TABS) |
2761 { | |
2762 if (curtab->tp_next == NULL) /* just checking */ | |
2763 break; | |
2764 goto_tabpage(0); | |
2765 } | |
2766 else | |
2767 { | |
2768 if (curwin->w_next == NULL) /* just checking */ | |
2769 break; | |
2770 win_enter(curwin->w_next, FALSE); | |
2771 } | |
673 | 2772 } |
1036 | 2773 advance = TRUE; |
443 | 2774 |
2775 /* Only open the file if there is no file in this window yet (that can | |
1036 | 2776 * happen when .vimrc contains ":sall"). */ |
443 | 2777 if (curbuf == firstwin->w_buffer || curbuf->b_ffname == NULL) |
2778 { | |
2779 curwin->w_arg_idx = arg_idx; | |
1036 | 2780 /* Edit file from arg list, if there is one. When "Quit" selected |
2781 * at the ATTENTION prompt close the window. */ | |
1684 | 2782 # ifdef HAS_SWAP_EXISTS_ACTION |
2783 swap_exists_did_quit = FALSE; | |
2784 # endif | |
443 | 2785 (void)do_ecmd(0, arg_idx < GARGCOUNT |
2786 ? alist_name(&GARGLIST[arg_idx]) : NULL, | |
1743 | 2787 NULL, NULL, ECMD_LASTL, ECMD_HIDE, curwin); |
1684 | 2788 # ifdef HAS_SWAP_EXISTS_ACTION |
2789 if (swap_exists_did_quit) | |
1036 | 2790 { |
1684 | 2791 /* abort or quit selected */ |
1036 | 2792 if (got_int || only_one_window()) |
2793 { | |
1684 | 2794 /* abort selected and only one window */ |
1036 | 2795 did_emsg = FALSE; /* avoid hit-enter prompt */ |
2796 getout(1); | |
2797 } | |
2798 win_close(curwin, TRUE); | |
2799 advance = FALSE; | |
2800 } | |
1684 | 2801 # endif |
443 | 2802 if (arg_idx == GARGCOUNT - 1) |
2803 arg_had_last = TRUE; | |
2804 ++arg_idx; | |
2805 } | |
2806 ui_breakcheck(); | |
2807 if (got_int) | |
2808 { | |
2809 (void)vgetc(); /* only break the file loading, not the rest */ | |
2810 break; | |
2811 } | |
2812 } | |
673 | 2813 |
2814 if (parmp->window_layout == WIN_TABS) | |
2815 goto_tabpage(1); | |
443 | 2816 # ifdef FEAT_AUTOCMD |
2817 --autocmd_no_enter; | |
2818 # endif | |
2819 win_enter(firstwin, FALSE); /* back to first window */ | |
2820 # ifdef FEAT_AUTOCMD | |
2821 --autocmd_no_leave; | |
2822 # endif | |
2823 TIME_MSG("editing files in windows"); | |
673 | 2824 if (parmp->window_count > 1 && parmp->window_layout != WIN_TABS) |
443 | 2825 win_equal(curwin, FALSE, 'b'); /* adjust heights */ |
2826 } | |
2827 #endif /* FEAT_WINDOWS */ | |
2828 | |
2829 /* | |
440 | 2830 * Execute the commands from --cmd arguments "cmds[cnt]". |
2831 */ | |
2832 static void | |
443 | 2833 exe_pre_commands(parmp) |
2834 mparm_T *parmp; | |
440 | 2835 { |
443 | 2836 char_u **cmds = parmp->pre_commands; |
2837 int cnt = parmp->n_pre_commands; | |
440 | 2838 int i; |
2839 | |
2840 if (cnt > 0) | |
2841 { | |
2842 curwin->w_cursor.lnum = 0; /* just in case.. */ | |
2843 sourcing_name = (char_u *)_("pre-vimrc command line"); | |
2844 # ifdef FEAT_EVAL | |
2845 current_SID = SID_CMDARG; | |
2846 # endif | |
2847 for (i = 0; i < cnt; ++i) | |
2848 do_cmdline_cmd(cmds[i]); | |
2849 sourcing_name = NULL; | |
2850 # ifdef FEAT_EVAL | |
2851 current_SID = 0; | |
2852 # endif | |
2853 TIME_MSG("--cmd commands"); | |
2854 } | |
2855 } | |
2856 | |
2857 /* | |
443 | 2858 * Execute "+", "-c" and "-S" arguments. |
2859 */ | |
2860 static void | |
2861 exe_commands(parmp) | |
2862 mparm_T *parmp; | |
2863 { | |
2864 int i; | |
2865 | |
2866 /* | |
2867 * We start commands on line 0, make "vim +/pat file" match a | |
2868 * pattern on line 1. But don't move the cursor when an autocommand | |
2869 * with g`" was used. | |
2870 */ | |
2871 msg_scroll = TRUE; | |
2872 if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1) | |
2873 curwin->w_cursor.lnum = 0; | |
2874 sourcing_name = (char_u *)"command line"; | |
2875 #ifdef FEAT_EVAL | |
2876 current_SID = SID_CARG; | |
2877 #endif | |
2878 for (i = 0; i < parmp->n_commands; ++i) | |
2879 { | |
2880 do_cmdline_cmd(parmp->commands[i]); | |
2881 if (parmp->cmds_tofree[i]) | |
2882 vim_free(parmp->commands[i]); | |
2883 } | |
2884 sourcing_name = NULL; | |
2885 #ifdef FEAT_EVAL | |
2886 current_SID = 0; | |
2887 #endif | |
2888 if (curwin->w_cursor.lnum == 0) | |
2889 curwin->w_cursor.lnum = 1; | |
2890 | |
2891 if (!exmode_active) | |
2892 msg_scroll = FALSE; | |
2893 | |
2894 #ifdef FEAT_QUICKFIX | |
2895 /* When started with "-q errorfile" jump to first error again. */ | |
2896 if (parmp->edit_type == EDIT_QF) | |
644 | 2897 qf_jump(NULL, 0, 0, FALSE); |
443 | 2898 #endif |
2899 TIME_MSG("executing command arguments"); | |
2900 } | |
2901 | |
2902 /* | |
440 | 2903 * Source startup scripts. |
2904 */ | |
2905 static void | |
2906 source_startup_scripts(parmp) | |
2907 mparm_T *parmp; | |
2908 { | |
2909 int i; | |
2910 | |
2911 /* | |
2912 * For "evim" source evim.vim first of all, so that the user can overrule | |
2913 * any things he doesn't like. | |
2914 */ | |
2915 if (parmp->evim_mode) | |
2916 { | |
819 | 2917 (void)do_source((char_u *)EVIM_FILE, FALSE, DOSO_NONE); |
440 | 2918 TIME_MSG("source evim file"); |
2919 } | |
2920 | |
2921 /* | |
443 | 2922 * If -u argument given, use only the initializations from that file and |
440 | 2923 * nothing else. |
2924 */ | |
2925 if (parmp->use_vimrc != NULL) | |
2926 { | |
445 | 2927 if (STRCMP(parmp->use_vimrc, "NONE") == 0 |
2928 || STRCMP(parmp->use_vimrc, "NORC") == 0) | |
440 | 2929 { |
2930 #ifdef FEAT_GUI | |
2931 if (use_gvimrc == NULL) /* don't load gvimrc either */ | |
2932 use_gvimrc = parmp->use_vimrc; | |
2933 #endif | |
2934 if (parmp->use_vimrc[2] == 'N') | |
2935 p_lpl = FALSE; /* don't load plugins either */ | |
2936 } | |
2937 else | |
2938 { | |
819 | 2939 if (do_source(parmp->use_vimrc, FALSE, DOSO_NONE) != OK) |
440 | 2940 EMSG2(_("E282: Cannot read from \"%s\""), parmp->use_vimrc); |
2941 } | |
2942 } | |
2943 else if (!silent_mode) | |
2944 { | |
2945 #ifdef AMIGA | |
2946 struct Process *proc = (struct Process *)FindTask(0L); | |
2947 APTR save_winptr = proc->pr_WindowPtr; | |
2948 | |
2949 /* Avoid a requester here for a volume that doesn't exist. */ | |
2950 proc->pr_WindowPtr = (APTR)-1L; | |
2951 #endif | |
2952 | |
2953 /* | |
2954 * Get system wide defaults, if the file name is defined. | |
2955 */ | |
2956 #ifdef SYS_VIMRC_FILE | |
819 | 2957 (void)do_source((char_u *)SYS_VIMRC_FILE, FALSE, DOSO_NONE); |
440 | 2958 #endif |
720 | 2959 #ifdef MACOS_X |
819 | 2960 (void)do_source((char_u *)"$VIMRUNTIME/macmap.vim", FALSE, DOSO_NONE); |
720 | 2961 #endif |
440 | 2962 |
2963 /* | |
2964 * Try to read initialization commands from the following places: | |
2965 * - environment variable VIMINIT | |
2966 * - user vimrc file (s:.vimrc for Amiga, ~/.vimrc otherwise) | |
2967 * - second user vimrc file ($VIM/.vimrc for Dos) | |
2968 * - environment variable EXINIT | |
2969 * - user exrc file (s:.exrc for Amiga, ~/.exrc otherwise) | |
2970 * - second user exrc file ($VIM/.exrc for Dos) | |
2971 * The first that exists is used, the rest is ignored. | |
2972 */ | |
2973 if (process_env((char_u *)"VIMINIT", TRUE) != OK) | |
2974 { | |
819 | 2975 if (do_source((char_u *)USR_VIMRC_FILE, TRUE, DOSO_VIMRC) == FAIL |
440 | 2976 #ifdef USR_VIMRC_FILE2 |
819 | 2977 && do_source((char_u *)USR_VIMRC_FILE2, TRUE, |
2978 DOSO_VIMRC) == FAIL | |
440 | 2979 #endif |
2980 #ifdef USR_VIMRC_FILE3 | |
819 | 2981 && do_source((char_u *)USR_VIMRC_FILE3, TRUE, |
2982 DOSO_VIMRC) == FAIL | |
440 | 2983 #endif |
2984 && process_env((char_u *)"EXINIT", FALSE) == FAIL | |
819 | 2985 && do_source((char_u *)USR_EXRC_FILE, FALSE, DOSO_NONE) == FAIL) |
440 | 2986 { |
2987 #ifdef USR_EXRC_FILE2 | |
819 | 2988 (void)do_source((char_u *)USR_EXRC_FILE2, FALSE, DOSO_NONE); |
440 | 2989 #endif |
2990 } | |
2991 } | |
2992 | |
2993 /* | |
2994 * Read initialization commands from ".vimrc" or ".exrc" in current | |
2995 * directory. This is only done if the 'exrc' option is set. | |
2996 * Because of security reasons we disallow shell and write commands | |
2997 * now, except for unix if the file is owned by the user or 'secure' | |
2998 * option has been reset in environment of global ".exrc" or ".vimrc". | |
2999 * Only do this if VIMRC_FILE is not the same as USR_VIMRC_FILE or | |
3000 * SYS_VIMRC_FILE. | |
3001 */ | |
3002 if (p_exrc) | |
3003 { | |
3004 #if defined(UNIX) || defined(VMS) | |
3005 /* If ".vimrc" file is not owned by user, set 'secure' mode. */ | |
3006 if (!file_owned(VIMRC_FILE)) | |
3007 #endif | |
3008 secure = p_secure; | |
3009 | |
3010 i = FAIL; | |
3011 if (fullpathcmp((char_u *)USR_VIMRC_FILE, | |
3012 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME | |
3013 #ifdef USR_VIMRC_FILE2 | |
3014 && fullpathcmp((char_u *)USR_VIMRC_FILE2, | |
3015 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME | |
3016 #endif | |
3017 #ifdef USR_VIMRC_FILE3 | |
3018 && fullpathcmp((char_u *)USR_VIMRC_FILE3, | |
3019 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME | |
3020 #endif | |
3021 #ifdef SYS_VIMRC_FILE | |
3022 && fullpathcmp((char_u *)SYS_VIMRC_FILE, | |
3023 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME | |
3024 #endif | |
3025 ) | |
819 | 3026 i = do_source((char_u *)VIMRC_FILE, TRUE, DOSO_VIMRC); |
440 | 3027 |
3028 if (i == FAIL) | |
3029 { | |
3030 #if defined(UNIX) || defined(VMS) | |
3031 /* if ".exrc" is not owned by user set 'secure' mode */ | |
3032 if (!file_owned(EXRC_FILE)) | |
3033 secure = p_secure; | |
3034 else | |
3035 secure = 0; | |
3036 #endif | |
3037 if ( fullpathcmp((char_u *)USR_EXRC_FILE, | |
3038 (char_u *)EXRC_FILE, FALSE) != FPC_SAME | |
3039 #ifdef USR_EXRC_FILE2 | |
3040 && fullpathcmp((char_u *)USR_EXRC_FILE2, | |
3041 (char_u *)EXRC_FILE, FALSE) != FPC_SAME | |
3042 #endif | |
3043 ) | |
819 | 3044 (void)do_source((char_u *)EXRC_FILE, FALSE, DOSO_NONE); |
440 | 3045 } |
3046 } | |
3047 if (secure == 2) | |
3048 need_wait_return = TRUE; | |
3049 secure = 0; | |
3050 #ifdef AMIGA | |
3051 proc->pr_WindowPtr = save_winptr; | |
3052 #endif | |
3053 } | |
3054 TIME_MSG("sourcing vimrc file(s)"); | |
3055 } | |
3056 | |
3057 /* | |
6 | 3058 * Setup to start using the GUI. Exit with an error when not available. |
3059 */ | |
3060 static void | |
3061 main_start_gui() | |
3062 { | |
3063 #ifdef FEAT_GUI | |
3064 gui.starting = TRUE; /* start GUI a bit later */ | |
3065 #else | |
3066 mch_errmsg(_(e_nogvim)); | |
3067 mch_errmsg("\n"); | |
3068 mch_exit(2); | |
3069 #endif | |
3070 } | |
3071 | |
2730 | 3072 #endif /* NO_VIM_MAIN */ |
3073 | |
6 | 3074 /* |
1226 | 3075 * Get an environment variable, and execute it as Ex commands. |
6 | 3076 * Returns FAIL if the environment variable was not executed, OK otherwise. |
3077 */ | |
3078 int | |
3079 process_env(env, is_viminit) | |
3080 char_u *env; | |
3081 int is_viminit; /* when TRUE, called for VIMINIT */ | |
3082 { | |
3083 char_u *initstr; | |
3084 char_u *save_sourcing_name; | |
3085 linenr_T save_sourcing_lnum; | |
3086 #ifdef FEAT_EVAL | |
3087 scid_T save_sid; | |
3088 #endif | |
3089 | |
3090 if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL) | |
3091 { | |
3092 if (is_viminit) | |
819 | 3093 vimrc_found(NULL, NULL); |
6 | 3094 save_sourcing_name = sourcing_name; |
3095 save_sourcing_lnum = sourcing_lnum; | |
3096 sourcing_name = env; | |
3097 sourcing_lnum = 0; | |
3098 #ifdef FEAT_EVAL | |
3099 save_sid = current_SID; | |
3100 current_SID = SID_ENV; | |
3101 #endif | |
3102 do_cmdline_cmd(initstr); | |
3103 sourcing_name = save_sourcing_name; | |
3104 sourcing_lnum = save_sourcing_lnum; | |
3105 #ifdef FEAT_EVAL | |
3106 current_SID = save_sid;; | |
3107 #endif | |
3108 return OK; | |
3109 } | |
3110 return FAIL; | |
3111 } | |
3112 | |
2730 | 3113 #if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN) |
6 | 3114 /* |
3115 * Return TRUE if we are certain the user owns the file "fname". | |
3116 * Used for ".vimrc" and ".exrc". | |
3117 * Use both stat() and lstat() for extra security. | |
3118 */ | |
3119 static int | |
3120 file_owned(fname) | |
3121 char *fname; | |
3122 { | |
3123 struct stat s; | |
3124 # ifdef UNIX | |
3125 uid_t uid = getuid(); | |
3126 # else /* VMS */ | |
3127 uid_t uid = ((getgid() << 16) | getuid()); | |
3128 # endif | |
3129 | |
3130 return !(mch_stat(fname, &s) != 0 || s.st_uid != uid | |
3131 # ifdef HAVE_LSTAT | |
3132 || mch_lstat(fname, &s) != 0 || s.st_uid != uid | |
3133 # endif | |
3134 ); | |
3135 } | |
3136 #endif | |
3137 | |
3138 /* | |
3139 * Give an error message main_errors["n"] and exit. | |
3140 */ | |
3141 static void | |
3142 mainerr(n, str) | |
3143 int n; /* one of the ME_ defines */ | |
3144 char_u *str; /* extra argument or NULL */ | |
3145 { | |
3146 #if defined(UNIX) || defined(__EMX__) || defined(VMS) | |
3147 reset_signals(); /* kill us with CTRL-C here, if you like */ | |
3148 #endif | |
3149 | |
3150 mch_errmsg(longVersion); | |
159 | 3151 mch_errmsg("\n"); |
6 | 3152 mch_errmsg(_(main_errors[n])); |
3153 if (str != NULL) | |
3154 { | |
3155 mch_errmsg(": \""); | |
3156 mch_errmsg((char *)str); | |
3157 mch_errmsg("\""); | |
3158 } | |
159 | 3159 mch_errmsg(_("\nMore info with: \"vim -h\"\n")); |
6 | 3160 |
3161 mch_exit(1); | |
3162 } | |
3163 | |
3164 void | |
3165 mainerr_arg_missing(str) | |
3166 char_u *str; | |
3167 { | |
3168 mainerr(ME_ARG_MISSING, str); | |
3169 } | |
3170 | |
2730 | 3171 #ifndef NO_VIM_MAIN |
6 | 3172 /* |
3173 * print a message with three spaces prepended and '\n' appended. | |
3174 */ | |
3175 static void | |
3176 main_msg(s) | |
3177 char *s; | |
3178 { | |
3179 mch_msg(" "); | |
3180 mch_msg(s); | |
3181 mch_msg("\n"); | |
3182 } | |
3183 | |
3184 /* | |
3185 * Print messages for "vim -h" or "vim --help" and exit. | |
3186 */ | |
3187 static void | |
3188 usage() | |
3189 { | |
3190 int i; | |
3191 static char *(use[]) = | |
3192 { | |
3193 N_("[file ..] edit specified file(s)"), | |
3194 N_("- read text from stdin"), | |
3195 N_("-t tag edit file where tag is defined"), | |
3196 #ifdef FEAT_QUICKFIX | |
3197 N_("-q [errorfile] edit file with first error") | |
3198 #endif | |
3199 }; | |
3200 | |
3201 #if defined(UNIX) || defined(__EMX__) || defined(VMS) | |
3202 reset_signals(); /* kill us with CTRL-C here, if you like */ | |
3203 #endif | |
3204 | |
3205 mch_msg(longVersion); | |
3206 mch_msg(_("\n\nusage:")); | |
3207 for (i = 0; ; ++i) | |
3208 { | |
3209 mch_msg(_(" vim [arguments] ")); | |
3210 mch_msg(_(use[i])); | |
3211 if (i == (sizeof(use) / sizeof(char_u *)) - 1) | |
3212 break; | |
3213 mch_msg(_("\n or:")); | |
3214 } | |
22 | 3215 #ifdef VMS |
1164 | 3216 mch_msg(_("\nWhere case is ignored prepend / to make flag upper case")); |
22 | 3217 #endif |
6 | 3218 |
3219 mch_msg(_("\n\nArguments:\n")); | |
3220 main_msg(_("--\t\t\tOnly file names after this")); | |
3221 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) | |
3222 main_msg(_("--literal\t\tDon't expand wildcards")); | |
3223 #endif | |
3224 #ifdef FEAT_OLE | |
3225 main_msg(_("-register\t\tRegister this gvim for OLE")); | |
3226 main_msg(_("-unregister\t\tUnregister gvim for OLE")); | |
3227 #endif | |
3228 #ifdef FEAT_GUI | |
3229 main_msg(_("-g\t\t\tRun using GUI (like \"gvim\")")); | |
3230 main_msg(_("-f or --nofork\tForeground: Don't fork when starting GUI")); | |
3231 #endif | |
3232 main_msg(_("-v\t\t\tVi mode (like \"vi\")")); | |
3233 main_msg(_("-e\t\t\tEx mode (like \"ex\")")); | |
3437 | 3234 main_msg(_("-E\t\t\tImproved Ex mode")); |
6 | 3235 main_msg(_("-s\t\t\tSilent (batch) mode (only for \"ex\")")); |
3236 #ifdef FEAT_DIFF | |
3237 main_msg(_("-d\t\t\tDiff mode (like \"vimdiff\")")); | |
3238 #endif | |
3239 main_msg(_("-y\t\t\tEasy mode (like \"evim\", modeless)")); | |
3240 main_msg(_("-R\t\t\tReadonly mode (like \"view\")")); | |
3241 main_msg(_("-Z\t\t\tRestricted mode (like \"rvim\")")); | |
3242 main_msg(_("-m\t\t\tModifications (writing files) not allowed")); | |
3243 main_msg(_("-M\t\t\tModifications in text not allowed")); | |
3244 main_msg(_("-b\t\t\tBinary mode")); | |
3245 #ifdef FEAT_LISP | |
3246 main_msg(_("-l\t\t\tLisp mode")); | |
3247 #endif | |
3248 main_msg(_("-C\t\t\tCompatible with Vi: 'compatible'")); | |
3249 main_msg(_("-N\t\t\tNot fully Vi compatible: 'nocompatible'")); | |
1164 | 3250 main_msg(_("-V[N][fname]\t\tBe verbose [level N] [log messages to fname]")); |
3251 #ifdef FEAT_EVAL | |
6 | 3252 main_msg(_("-D\t\t\tDebugging mode")); |
1164 | 3253 #endif |
6 | 3254 main_msg(_("-n\t\t\tNo swap file, use memory only")); |
3255 main_msg(_("-r\t\t\tList swap files and exit")); | |
3256 main_msg(_("-r (with file name)\tRecover crashed session")); | |
3257 main_msg(_("-L\t\t\tSame as -r")); | |
3258 #ifdef AMIGA | |
3259 main_msg(_("-f\t\t\tDon't use newcli to open window")); | |
3260 main_msg(_("-dev <device>\t\tUse <device> for I/O")); | |
3261 #endif | |
3262 #ifdef FEAT_ARABIC | |
3263 main_msg(_("-A\t\t\tstart in Arabic mode")); | |
3264 #endif | |
3265 #ifdef FEAT_RIGHTLEFT | |
3266 main_msg(_("-H\t\t\tStart in Hebrew mode")); | |
3267 #endif | |
3268 #ifdef FEAT_FKMAP | |
3269 main_msg(_("-F\t\t\tStart in Farsi mode")); | |
3270 #endif | |
3271 main_msg(_("-T <terminal>\tSet terminal type to <terminal>")); | |
3272 main_msg(_("-u <vimrc>\t\tUse <vimrc> instead of any .vimrc")); | |
3273 #ifdef FEAT_GUI | |
3274 main_msg(_("-U <gvimrc>\t\tUse <gvimrc> instead of any .gvimrc")); | |
3275 #endif | |
3276 main_msg(_("--noplugin\t\tDon't load plugin scripts")); | |
1164 | 3277 #ifdef FEAT_WINDOWS |
673 | 3278 main_msg(_("-p[N]\t\tOpen N tab pages (default: one for each file)")); |
6 | 3279 main_msg(_("-o[N]\t\tOpen N windows (default: one for each file)")); |
3280 main_msg(_("-O[N]\t\tLike -o but split vertically")); | |
1164 | 3281 #endif |
6 | 3282 main_msg(_("+\t\t\tStart at end of file")); |
3283 main_msg(_("+<lnum>\t\tStart at line <lnum>")); | |
3284 main_msg(_("--cmd <command>\tExecute <command> before loading any vimrc file")); | |
3285 main_msg(_("-c <command>\t\tExecute <command> after loading the first file")); | |
3286 main_msg(_("-S <session>\t\tSource file <session> after loading the first file")); | |
3287 main_msg(_("-s <scriptin>\tRead Normal mode commands from file <scriptin>")); | |
3288 main_msg(_("-w <scriptout>\tAppend all typed commands to file <scriptout>")); | |
3289 main_msg(_("-W <scriptout>\tWrite all typed commands to file <scriptout>")); | |
3290 #ifdef FEAT_CRYPT | |
3291 main_msg(_("-x\t\t\tEdit encrypted files")); | |
3292 #endif | |
3293 #if (defined(UNIX) || defined(VMS)) && defined(FEAT_X11) | |
3294 # if defined(FEAT_GUI_X11) && !defined(FEAT_GUI_GTK) | |
3295 main_msg(_("-display <display>\tConnect vim to this particular X-server")); | |
3296 # endif | |
3297 main_msg(_("-X\t\t\tDo not connect to X server")); | |
3298 #endif | |
3299 #ifdef FEAT_CLIENTSERVER | |
3300 main_msg(_("--remote <files>\tEdit <files> in a Vim server if possible")); | |
3301 main_msg(_("--remote-silent <files> Same, don't complain if there is no server")); | |
3302 main_msg(_("--remote-wait <files> As --remote but wait for files to have been edited")); | |
3303 main_msg(_("--remote-wait-silent <files> Same, don't complain if there is no server")); | |
754 | 3304 # ifdef FEAT_WINDOWS |
1501 | 3305 main_msg(_("--remote-tab[-wait][-silent] <files> As --remote but use tab page per file")); |
754 | 3306 # endif |
6 | 3307 main_msg(_("--remote-send <keys>\tSend <keys> to a Vim server and exit")); |
3308 main_msg(_("--remote-expr <expr>\tEvaluate <expr> in a Vim server and print result")); | |
3309 main_msg(_("--serverlist\t\tList available Vim server names and exit")); | |
3310 main_msg(_("--servername <name>\tSend to/become the Vim server <name>")); | |
3311 #endif | |
1989 | 3312 #ifdef STARTUPTIME |
1999 | 3313 main_msg(_("--startuptime <file>\tWrite startup timing messages to <file>")); |
1989 | 3314 #endif |
6 | 3315 #ifdef FEAT_VIMINFO |
3316 main_msg(_("-i <viminfo>\t\tUse <viminfo> instead of .viminfo")); | |
3317 #endif | |
3318 main_msg(_("-h or --help\tPrint Help (this message) and exit")); | |
3319 main_msg(_("--version\t\tPrint version information and exit")); | |
3320 | |
3321 #ifdef FEAT_GUI_X11 | |
3322 # ifdef FEAT_GUI_MOTIF | |
3323 mch_msg(_("\nArguments recognised by gvim (Motif version):\n")); | |
3324 # else | |
3325 # ifdef FEAT_GUI_ATHENA | |
3326 # ifdef FEAT_GUI_NEXTAW | |
3327 mch_msg(_("\nArguments recognised by gvim (neXtaw version):\n")); | |
3328 # else | |
3329 mch_msg(_("\nArguments recognised by gvim (Athena version):\n")); | |
3330 # endif | |
3331 # endif | |
3332 # endif | |
3333 main_msg(_("-display <display>\tRun vim on <display>")); | |
3334 main_msg(_("-iconic\t\tStart vim iconified")); | |
3335 main_msg(_("-background <color>\tUse <color> for the background (also: -bg)")); | |
3336 main_msg(_("-foreground <color>\tUse <color> for normal text (also: -fg)")); | |
3337 main_msg(_("-font <font>\t\tUse <font> for normal text (also: -fn)")); | |
3338 main_msg(_("-boldfont <font>\tUse <font> for bold text")); | |
3339 main_msg(_("-italicfont <font>\tUse <font> for italic text")); | |
3340 main_msg(_("-geometry <geom>\tUse <geom> for initial geometry (also: -geom)")); | |
3341 main_msg(_("-borderwidth <width>\tUse a border width of <width> (also: -bw)")); | |
3342 main_msg(_("-scrollbarwidth <width> Use a scrollbar width of <width> (also: -sw)")); | |
3343 # ifdef FEAT_GUI_ATHENA | |
3344 main_msg(_("-menuheight <height>\tUse a menu bar height of <height> (also: -mh)")); | |
3345 # endif | |
3346 main_msg(_("-reverse\t\tUse reverse video (also: -rv)")); | |
3347 main_msg(_("+reverse\t\tDon't use reverse video (also: +rv)")); | |
3348 main_msg(_("-xrm <resource>\tSet the specified resource")); | |
3349 #endif /* FEAT_GUI_X11 */ | |
3350 #ifdef FEAT_GUI_GTK | |
3351 mch_msg(_("\nArguments recognised by gvim (GTK+ version):\n")); | |
3352 main_msg(_("-font <font>\t\tUse <font> for normal text (also: -fn)")); | |
3353 main_msg(_("-geometry <geom>\tUse <geom> for initial geometry (also: -geom)")); | |
3354 main_msg(_("-reverse\t\tUse reverse video (also: -rv)")); | |
3355 main_msg(_("-display <display>\tRun vim on <display> (also: --display)")); | |
3356 main_msg(_("--role <role>\tSet a unique role to identify the main window")); | |
3357 main_msg(_("--socketid <xid>\tOpen Vim inside another GTK widget")); | |
3437 | 3358 main_msg(_("--echo-wid\t\tMake gvim echo the Window ID on stdout")); |
6 | 3359 #endif |
3360 #ifdef FEAT_GUI_W32 | |
3361 main_msg(_("-P <parent title>\tOpen Vim inside parent application")); | |
1376 | 3362 main_msg(_("--windowid <HWND>\tOpen Vim inside another win32 widget")); |
6 | 3363 #endif |
3364 | |
3365 #ifdef FEAT_GUI_GNOME | |
3366 /* Gnome gives extra messages for --help if we continue, but not for -h. */ | |
3367 if (gui.starting) | |
3198 | 3368 { |
6 | 3369 mch_msg("\n"); |
3198 | 3370 gui.dofork = FALSE; |
3371 } | |
6 | 3372 else |
3373 #endif | |
3374 mch_exit(0); | |
3375 } | |
3376 | |
580 | 3377 #if defined(HAS_SWAP_EXISTS_ACTION) |
6 | 3378 /* |
3379 * Check the result of the ATTENTION dialog: | |
3380 * When "Quit" selected, exit Vim. | |
3381 * When "Recover" selected, recover the file. | |
3382 */ | |
3383 static void | |
3384 check_swap_exists_action() | |
3385 { | |
3386 if (swap_exists_action == SEA_QUIT) | |
3387 getout(1); | |
3388 handle_swap_exists(NULL); | |
3389 } | |
3390 #endif | |
3391 | |
2730 | 3392 #endif |
3393 | |
6 | 3394 #if defined(STARTUPTIME) || defined(PROTO) |
3395 static void time_diff __ARGS((struct timeval *then, struct timeval *now)); | |
3396 | |
3397 static struct timeval prev_timeval; | |
3398 | |
1972 | 3399 # ifdef WIN3264 |
3400 /* | |
3401 * Windows doesn't have gettimeofday(), although it does have struct timeval. | |
3402 */ | |
3403 static int | |
3404 gettimeofday(struct timeval *tv, char *dummy) | |
3405 { | |
3406 long t = clock(); | |
3407 tv->tv_sec = t / CLOCKS_PER_SEC; | |
3408 tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC; | |
3409 return 0; | |
3410 } | |
3411 # endif | |
3412 | |
6 | 3413 /* |
3414 * Save the previous time before doing something that could nest. | |
3415 * set "*tv_rel" to the time elapsed so far. | |
3416 */ | |
3417 void | |
3418 time_push(tv_rel, tv_start) | |
3419 void *tv_rel, *tv_start; | |
3420 { | |
3421 *((struct timeval *)tv_rel) = prev_timeval; | |
3422 gettimeofday(&prev_timeval, NULL); | |
3423 ((struct timeval *)tv_rel)->tv_usec = prev_timeval.tv_usec | |
3424 - ((struct timeval *)tv_rel)->tv_usec; | |
3425 ((struct timeval *)tv_rel)->tv_sec = prev_timeval.tv_sec | |
3426 - ((struct timeval *)tv_rel)->tv_sec; | |
3427 if (((struct timeval *)tv_rel)->tv_usec < 0) | |
3428 { | |
3429 ((struct timeval *)tv_rel)->tv_usec += 1000000; | |
3430 --((struct timeval *)tv_rel)->tv_sec; | |
3431 } | |
3432 *(struct timeval *)tv_start = prev_timeval; | |
3433 } | |
3434 | |
3435 /* | |
3436 * Compute the previous time after doing something that could nest. | |
3437 * Subtract "*tp" from prev_timeval; | |
3438 * Note: The arguments are (void *) to avoid trouble with systems that don't | |
3439 * have struct timeval. | |
3440 */ | |
3441 void | |
3442 time_pop(tp) | |
3443 void *tp; /* actually (struct timeval *) */ | |
3444 { | |
3445 prev_timeval.tv_usec -= ((struct timeval *)tp)->tv_usec; | |
3446 prev_timeval.tv_sec -= ((struct timeval *)tp)->tv_sec; | |
3447 if (prev_timeval.tv_usec < 0) | |
3448 { | |
3449 prev_timeval.tv_usec += 1000000; | |
3450 --prev_timeval.tv_sec; | |
3451 } | |
3452 } | |
3453 | |
3454 static void | |
3455 time_diff(then, now) | |
3456 struct timeval *then; | |
3457 struct timeval *now; | |
3458 { | |
3459 long usec; | |
3460 long msec; | |
3461 | |
3462 usec = now->tv_usec - then->tv_usec; | |
3463 msec = (now->tv_sec - then->tv_sec) * 1000L + usec / 1000L, | |
3464 usec = usec % 1000L; | |
3465 fprintf(time_fd, "%03ld.%03ld", msec, usec >= 0 ? usec : usec + 1000L); | |
3466 } | |
3467 | |
3468 void | |
2271
2b33a7678e7b
Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
3469 time_msg(mesg, tv_start) |
2b33a7678e7b
Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
3470 char *mesg; |
6 | 3471 void *tv_start; /* only for do_source: start time; actually |
3472 (struct timeval *) */ | |
3473 { | |
3474 static struct timeval start; | |
3475 struct timeval now; | |
3476 | |
3477 if (time_fd != NULL) | |
3478 { | |
2271
2b33a7678e7b
Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
3479 if (strstr(mesg, "STARTING") != NULL) |
6 | 3480 { |
3481 gettimeofday(&start, NULL); | |
3482 prev_timeval = start; | |
3483 fprintf(time_fd, "\n\ntimes in msec\n"); | |
3484 fprintf(time_fd, " clock self+sourced self: sourced script\n"); | |
3485 fprintf(time_fd, " clock elapsed: other lines\n\n"); | |
3486 } | |
3487 gettimeofday(&now, NULL); | |
3488 time_diff(&start, &now); | |
3489 if (((struct timeval *)tv_start) != NULL) | |
3490 { | |
3491 fprintf(time_fd, " "); | |
3492 time_diff(((struct timeval *)tv_start), &now); | |
3493 } | |
3494 fprintf(time_fd, " "); | |
3495 time_diff(&prev_timeval, &now); | |
3496 prev_timeval = now; | |
2271
2b33a7678e7b
Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
3497 fprintf(time_fd, ": %s\n", mesg); |
6 | 3498 } |
3499 } | |
3500 | |
3501 #endif | |
3502 | |
2730 | 3503 #if (defined(FEAT_CLIENTSERVER) && !defined(NO_VIM_MAIN)) || defined(PROTO) |
6 | 3504 |
3505 /* | |
3506 * Common code for the X command server and the Win32 command server. | |
3507 */ | |
3508 | |
734 | 3509 static char_u *build_drop_cmd __ARGS((int filec, char **filev, int tabs, int sendReply)); |
6 | 3510 |
443 | 3511 /* |
3512 * Do the client-server stuff, unless "--servername ''" was used. | |
3513 */ | |
3514 static void | |
3515 exec_on_server(parmp) | |
3516 mparm_T *parmp; | |
3517 { | |
3518 if (parmp->serverName_arg == NULL || *parmp->serverName_arg != NUL) | |
3519 { | |
3520 # ifdef WIN32 | |
3521 /* Initialise the client/server messaging infrastructure. */ | |
3522 serverInitMessaging(); | |
3523 # endif | |
3524 | |
3525 /* | |
3526 * When a command server argument was found, execute it. This may | |
3527 * exit Vim when it was successful. Otherwise it's executed further | |
3528 * on. Remember the encoding used here in "serverStrEnc". | |
3529 */ | |
3530 if (parmp->serverArg) | |
3531 { | |
3532 cmdsrv_main(&parmp->argc, parmp->argv, | |
3533 parmp->serverName_arg, &parmp->serverStr); | |
3534 # ifdef FEAT_MBYTE | |
3535 parmp->serverStrEnc = vim_strsave(p_enc); | |
3536 # endif | |
3537 } | |
3538 | |
3539 /* If we're still running, get the name to register ourselves. | |
3540 * On Win32 can register right now, for X11 need to setup the | |
3541 * clipboard first, it's further down. */ | |
3542 parmp->servername = serverMakeName(parmp->serverName_arg, | |
3543 parmp->argv[0]); | |
3544 # ifdef WIN32 | |
3545 if (parmp->servername != NULL) | |
3546 { | |
3547 serverSetName(parmp->servername); | |
3548 vim_free(parmp->servername); | |
3549 } | |
3550 # endif | |
3551 } | |
3552 } | |
3553 | |
3554 /* | |
3555 * Prepare for running as a Vim server. | |
3556 */ | |
3557 static void | |
3558 prepare_server(parmp) | |
3559 mparm_T *parmp; | |
3560 { | |
3561 # if defined(FEAT_X11) | |
3562 /* | |
3563 * Register for remote command execution with :serversend and --remote | |
3564 * unless there was a -X or a --servername '' on the command line. | |
3565 * Only register nongui-vim's with an explicit --servername argument. | |
926 | 3566 * When running as root --servername is also required. |
443 | 3567 */ |
3568 if (X_DISPLAY != NULL && parmp->servername != NULL && ( | |
3569 # ifdef FEAT_GUI | |
926 | 3570 (gui.in_use |
3571 # ifdef UNIX | |
1076 | 3572 && getuid() != ROOT_UID |
926 | 3573 # endif |
3574 ) || | |
443 | 3575 # endif |
3576 parmp->serverName_arg != NULL)) | |
3577 { | |
3578 (void)serverRegisterName(X_DISPLAY, parmp->servername); | |
3579 vim_free(parmp->servername); | |
3580 TIME_MSG("register server name"); | |
3581 } | |
3582 else | |
3583 serverDelayedStartName = parmp->servername; | |
3584 # endif | |
3585 | |
3586 /* | |
3587 * Execute command ourselves if we're here because the send failed (or | |
3588 * else we would have exited above). | |
3589 */ | |
3590 if (parmp->serverStr != NULL) | |
3591 { | |
3592 char_u *p; | |
3593 | |
3594 server_to_input_buf(serverConvert(parmp->serverStrEnc, | |
3595 parmp->serverStr, &p)); | |
3596 vim_free(p); | |
3597 } | |
3598 } | |
3599 | |
6 | 3600 static void |
3601 cmdsrv_main(argc, argv, serverName_arg, serverStr) | |
3602 int *argc; | |
3603 char **argv; | |
3604 char_u *serverName_arg; | |
3605 char_u **serverStr; | |
3606 { | |
3607 char_u *res; | |
3608 int i; | |
3609 char_u *sname; | |
3610 int ret; | |
3611 int didone = FALSE; | |
3612 int exiterr = 0; | |
3613 char **newArgV = argv + 1; | |
3614 int newArgC = 1, | |
3615 Argc = *argc; | |
3616 int argtype; | |
3617 #define ARGTYPE_OTHER 0 | |
3618 #define ARGTYPE_EDIT 1 | |
3619 #define ARGTYPE_EDIT_WAIT 2 | |
3620 #define ARGTYPE_SEND 3 | |
3621 int silent = FALSE; | |
734 | 3622 int tabs = FALSE; |
6 | 3623 # ifndef FEAT_X11 |
3624 HWND srv; | |
3625 # else | |
3626 Window srv; | |
3627 | |
3628 setup_term_clip(); | |
3629 # endif | |
3630 | |
3631 sname = serverMakeName(serverName_arg, argv[0]); | |
3632 if (sname == NULL) | |
3633 return; | |
3634 | |
3635 /* | |
3636 * Execute the command server related arguments and remove them | |
3637 * from the argc/argv array; We may have to return into main() | |
3638 */ | |
3639 for (i = 1; i < Argc; i++) | |
3640 { | |
3641 res = NULL; | |
443 | 3642 if (STRCMP(argv[i], "--") == 0) /* end of option arguments */ |
6 | 3643 { |
3644 for (; i < *argc; i++) | |
3645 { | |
3646 *newArgV++ = argv[i]; | |
3647 newArgC++; | |
3648 } | |
3649 break; | |
3650 } | |
3651 | |
734 | 3652 if (STRICMP(argv[i], "--remote-send") == 0) |
3653 argtype = ARGTYPE_SEND; | |
3654 else if (STRNICMP(argv[i], "--remote", 8) == 0) | |
3655 { | |
3656 char *p = argv[i] + 8; | |
3657 | |
6 | 3658 argtype = ARGTYPE_EDIT; |
734 | 3659 while (*p != NUL) |
3660 { | |
3661 if (STRNICMP(p, "-wait", 5) == 0) | |
3662 { | |
3663 argtype = ARGTYPE_EDIT_WAIT; | |
3664 p += 5; | |
3665 } | |
3666 else if (STRNICMP(p, "-silent", 7) == 0) | |
3667 { | |
3668 silent = TRUE; | |
3669 p += 7; | |
3670 } | |
3671 else if (STRNICMP(p, "-tab", 4) == 0) | |
3672 { | |
3673 tabs = TRUE; | |
3674 p += 4; | |
3675 } | |
3676 else | |
3677 { | |
3678 argtype = ARGTYPE_OTHER; | |
3679 break; | |
3680 } | |
3681 } | |
6 | 3682 } |
3683 else | |
3684 argtype = ARGTYPE_OTHER; | |
734 | 3685 |
6 | 3686 if (argtype != ARGTYPE_OTHER) |
3687 { | |
3688 if (i == *argc - 1) | |
3689 mainerr_arg_missing((char_u *)argv[i]); | |
3690 if (argtype == ARGTYPE_SEND) | |
3691 { | |
3692 *serverStr = (char_u *)argv[i + 1]; | |
3693 i++; | |
3694 } | |
3695 else | |
3696 { | |
3697 *serverStr = build_drop_cmd(*argc - i - 1, argv + i + 1, | |
734 | 3698 tabs, argtype == ARGTYPE_EDIT_WAIT); |
6 | 3699 if (*serverStr == NULL) |
3700 { | |
3701 /* Probably out of memory, exit. */ | |
3702 didone = TRUE; | |
3703 exiterr = 1; | |
3704 break; | |
3705 } | |
3706 Argc = i; | |
3707 } | |
3708 # ifdef FEAT_X11 | |
3709 if (xterm_dpy == NULL) | |
3710 { | |
3711 mch_errmsg(_("No display")); | |
3712 ret = -1; | |
3713 } | |
3714 else | |
3715 ret = serverSendToVim(xterm_dpy, sname, *serverStr, | |
3716 NULL, &srv, 0, 0, silent); | |
3717 # else | |
3718 /* Win32 always works? */ | |
3719 ret = serverSendToVim(sname, *serverStr, NULL, &srv, 0, silent); | |
3720 # endif | |
3721 if (ret < 0) | |
3722 { | |
3723 if (argtype == ARGTYPE_SEND) | |
3724 { | |
3725 /* Failed to send, abort. */ | |
3726 mch_errmsg(_(": Send failed.\n")); | |
3727 didone = TRUE; | |
3728 exiterr = 1; | |
3729 } | |
3730 else if (!silent) | |
3731 /* Let vim start normally. */ | |
3732 mch_errmsg(_(": Send failed. Trying to execute locally\n")); | |
3733 break; | |
3734 } | |
3735 | |
3736 # ifdef FEAT_GUI_W32 | |
3737 /* Guess that when the server name starts with "g" it's a GUI | |
3738 * server, which we can bring to the foreground here. | |
3739 * Foreground() in the server doesn't work very well. */ | |
3740 if (argtype != ARGTYPE_SEND && TOUPPER_ASC(*sname) == 'G') | |
3741 SetForegroundWindow(srv); | |
3742 # endif | |
3743 | |
3744 /* | |
3745 * For --remote-wait: Wait until the server did edit each | |
3746 * file. Also detect that the server no longer runs. | |
3747 */ | |
3748 if (ret >= 0 && argtype == ARGTYPE_EDIT_WAIT) | |
3749 { | |
3750 int numFiles = *argc - i - 1; | |
3751 int j; | |
3752 char_u *done = alloc(numFiles); | |
3753 char_u *p; | |
3754 # ifdef FEAT_GUI_W32 | |
3755 NOTIFYICONDATA ni; | |
3756 int count = 0; | |
3757 extern HWND message_window; | |
3758 # endif | |
3759 | |
3760 if (numFiles > 0 && argv[i + 1][0] == '+') | |
3761 /* Skip "+cmd" argument, don't wait for it to be edited. */ | |
3762 --numFiles; | |
3763 | |
3764 # ifdef FEAT_GUI_W32 | |
3765 ni.cbSize = sizeof(ni); | |
3766 ni.hWnd = message_window; | |
3767 ni.uID = 0; | |
3768 ni.uFlags = NIF_ICON|NIF_TIP; | |
3769 ni.hIcon = LoadIcon((HINSTANCE)GetModuleHandle(0), "IDR_VIM"); | |
3770 sprintf(ni.szTip, _("%d of %d edited"), count, numFiles); | |
3771 Shell_NotifyIcon(NIM_ADD, &ni); | |
3772 # endif | |
3773 | |
3774 /* Wait for all files to unload in remote */ | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3775 vim_memset(done, 0, numFiles); |
6 | 3776 while (memchr(done, 0, numFiles) != NULL) |
3777 { | |
3778 # ifdef WIN32 | |
3779 p = serverGetReply(srv, NULL, TRUE, TRUE); | |
3780 if (p == NULL) | |
3781 break; | |
3782 # else | |
3783 if (serverReadReply(xterm_dpy, srv, &p, TRUE) < 0) | |
3784 break; | |
3785 # endif | |
3786 j = atoi((char *)p); | |
3787 if (j >= 0 && j < numFiles) | |
3788 { | |
3789 # ifdef FEAT_GUI_W32 | |
3790 ++count; | |
3791 sprintf(ni.szTip, _("%d of %d edited"), | |
3792 count, numFiles); | |
3793 Shell_NotifyIcon(NIM_MODIFY, &ni); | |
3794 # endif | |
3795 done[j] = 1; | |
3796 } | |
3797 } | |
3798 # ifdef FEAT_GUI_W32 | |
3799 Shell_NotifyIcon(NIM_DELETE, &ni); | |
3800 # endif | |
3801 } | |
3802 } | |
3803 else if (STRICMP(argv[i], "--remote-expr") == 0) | |
3804 { | |
3805 if (i == *argc - 1) | |
3806 mainerr_arg_missing((char_u *)argv[i]); | |
3807 # ifdef WIN32 | |
3808 /* Win32 always works? */ | |
3809 if (serverSendToVim(sname, (char_u *)argv[i + 1], | |
3810 &res, NULL, 1, FALSE) < 0) | |
3811 # else | |
3812 if (xterm_dpy == NULL) | |
3813 mch_errmsg(_("No display: Send expression failed.\n")); | |
3814 else if (serverSendToVim(xterm_dpy, sname, (char_u *)argv[i + 1], | |
3815 &res, NULL, 1, 1, FALSE) < 0) | |
3816 # endif | |
3817 { | |
3818 if (res != NULL && *res != NUL) | |
3819 { | |
3820 /* Output error from remote */ | |
3821 mch_errmsg((char *)res); | |
3822 vim_free(res); | |
3823 res = NULL; | |
3824 } | |
3825 mch_errmsg(_(": Send expression failed.\n")); | |
3826 } | |
3827 } | |
3828 else if (STRICMP(argv[i], "--serverlist") == 0) | |
3829 { | |
3830 # ifdef WIN32 | |
3831 /* Win32 always works? */ | |
3832 res = serverGetVimNames(); | |
3833 # else | |
3834 if (xterm_dpy != NULL) | |
3835 res = serverGetVimNames(xterm_dpy); | |
3836 # endif | |
3837 if (called_emsg) | |
3838 mch_errmsg("\n"); | |
3839 } | |
3840 else if (STRICMP(argv[i], "--servername") == 0) | |
3841 { | |
2021 | 3842 /* Already processed. Take it out of the command line */ |
6 | 3843 i++; |
3844 continue; | |
3845 } | |
3846 else | |
3847 { | |
3848 *newArgV++ = argv[i]; | |
3849 newArgC++; | |
3850 continue; | |
3851 } | |
3852 didone = TRUE; | |
3853 if (res != NULL && *res != NUL) | |
3854 { | |
3855 mch_msg((char *)res); | |
3856 if (res[STRLEN(res) - 1] != '\n') | |
3857 mch_msg("\n"); | |
3858 } | |
3859 vim_free(res); | |
3860 } | |
3861 | |
3862 if (didone) | |
3863 { | |
3864 display_errors(); /* display any collected messages */ | |
3865 exit(exiterr); /* Mission accomplished - get out */ | |
3866 } | |
3867 | |
3868 /* Return back into main() */ | |
3869 *argc = newArgC; | |
3870 vim_free(sname); | |
3871 } | |
3872 | |
3873 /* | |
3874 * Build a ":drop" command to send to a Vim server. | |
3875 */ | |
3876 static char_u * | |
734 | 3877 build_drop_cmd(filec, filev, tabs, sendReply) |
6 | 3878 int filec; |
3879 char **filev; | |
734 | 3880 int tabs; /* Use ":tab drop" instead of ":drop". */ |
6 | 3881 int sendReply; |
3882 { | |
3883 garray_T ga; | |
3884 int i; | |
3885 char_u *inicmd = NULL; | |
3886 char_u *p; | |
2770 | 3887 char_u *cwd; |
6 | 3888 |
3889 if (filec > 0 && filev[0][0] == '+') | |
3890 { | |
3891 inicmd = (char_u *)filev[0] + 1; | |
3892 filev++; | |
3893 filec--; | |
3894 } | |
3895 /* Check if we have at least one argument. */ | |
3896 if (filec <= 0) | |
3897 mainerr_arg_missing((char_u *)filev[-1]); | |
2640 | 3898 |
3899 /* Temporarily cd to the current directory to handle relative file names. */ | |
2770 | 3900 cwd = alloc(MAXPATHL); |
3901 if (cwd == NULL) | |
6 | 3902 return NULL; |
2770 | 3903 if (mch_dirname(cwd, MAXPATHL) != OK) |
3904 { | |
3905 vim_free(cwd); | |
3906 return NULL; | |
3907 } | |
3908 p = vim_strsave_escaped_ext(cwd, | |
1385 | 3909 #ifdef BACKSLASH_IN_FILENAME |
3910 "", /* rem_backslash() will tell what chars to escape */ | |
3911 #else | |
3912 PATH_ESC_CHARS, | |
3913 #endif | |
2770 | 3914 '\\', TRUE); |
3915 vim_free(cwd); | |
3916 if (p == NULL) | |
6 | 3917 return NULL; |
3918 ga_init2(&ga, 1, 100); | |
3919 ga_concat(&ga, (char_u *)"<C-\\><C-N>:cd "); | |
3920 ga_concat(&ga, p); | |
734 | 3921 vim_free(p); |
3922 | |
6 | 3923 /* Call inputsave() so that a prompt for an encryption key works. */ |
734 | 3924 ga_concat(&ga, (char_u *)"<CR>:if exists('*inputsave')|call inputsave()|endif|"); |
3925 if (tabs) | |
3926 ga_concat(&ga, (char_u *)"tab "); | |
3927 ga_concat(&ga, (char_u *)"drop"); | |
6 | 3928 for (i = 0; i < filec; i++) |
3929 { | |
3930 /* On Unix the shell has already expanded the wildcards, don't want to | |
40 | 3931 * do it again in the Vim server. On MS-Windows only escape |
3932 * non-wildcard characters. */ | |
6 | 3933 p = vim_strsave_escaped((char_u *)filev[i], |
3934 #ifdef UNIX | |
3935 PATH_ESC_CHARS | |
3936 #else | |
40 | 3937 (char_u *)" \t%#" |
6 | 3938 #endif |
3939 ); | |
3940 if (p == NULL) | |
3941 { | |
3942 vim_free(ga.ga_data); | |
3943 return NULL; | |
3944 } | |
3945 ga_concat(&ga, (char_u *)" "); | |
3946 ga_concat(&ga, p); | |
3947 vim_free(p); | |
3948 } | |
2640 | 3949 ga_concat(&ga, (char_u *)"|if exists('*inputrestore')|call inputrestore()|endif<CR>"); |
3950 | |
6 | 3951 /* The :drop commands goes to Insert mode when 'insertmode' is set, use |
3952 * CTRL-\ CTRL-N again. */ | |
2640 | 3953 ga_concat(&ga, (char_u *)"<C-\\><C-N>"); |
3954 | |
3955 /* Switch back to the correct current directory (prior to temporary path | |
3956 * switch) unless 'autochdir' is set, in which case it will already be | |
3957 * correct after the :drop command. */ | |
3958 ga_concat(&ga, (char_u *)":if !exists('+acd')||!&acd|cd -|endif<CR>"); | |
3959 | |
6 | 3960 if (sendReply) |
2640 | 3961 ga_concat(&ga, (char_u *)":call SetupRemoteReplies()<CR>"); |
3962 ga_concat(&ga, (char_u *)":"); | |
6 | 3963 if (inicmd != NULL) |
3964 { | |
3965 /* Can't use <CR> after "inicmd", because an "startinsert" would cause | |
3966 * the following commands to be inserted as text. Use a "|", | |
3967 * hopefully "inicmd" does allow this... */ | |
3968 ga_concat(&ga, inicmd); | |
3969 ga_concat(&ga, (char_u *)"|"); | |
3970 } | |
3971 /* Bring the window to the foreground, goto Insert mode when 'im' set and | |
3972 * clear command line. */ | |
46 | 3973 ga_concat(&ga, (char_u *)"cal foreground()|if &im|star|en|redr|f<CR>"); |
6 | 3974 ga_append(&ga, NUL); |
3975 return ga.ga_data; | |
3976 } | |
3977 | |
3978 /* | |
2730 | 3979 * Make our basic server name: use the specified "arg" if given, otherwise use |
3980 * the tail of the command "cmd" we were started with. | |
3981 * Return the name in allocated memory. This doesn't include a serial number. | |
3982 */ | |
3983 static char_u * | |
3984 serverMakeName(arg, cmd) | |
3985 char_u *arg; | |
3986 char *cmd; | |
3987 { | |
3988 char_u *p; | |
3989 | |
3990 if (arg != NULL && *arg != NUL) | |
3991 p = vim_strsave_up(arg); | |
3992 else | |
3993 { | |
3994 p = vim_strsave_up(gettail((char_u *)cmd)); | |
3995 /* Remove .exe or .bat from the name. */ | |
3996 if (p != NULL && vim_strchr(p, '.') != NULL) | |
3997 *vim_strchr(p, '.') = NUL; | |
3998 } | |
3999 return p; | |
4000 } | |
4001 #endif /* FEAT_CLIENTSERVER */ | |
4002 | |
4003 #if defined(FEAT_CLIENTSERVER) || defined(PROTO) | |
4004 /* | |
6 | 4005 * Replace termcodes such as <CR> and insert as key presses if there is room. |
4006 */ | |
4007 void | |
4008 server_to_input_buf(str) | |
4009 char_u *str; | |
4010 { | |
4011 char_u *ptr = NULL; | |
4012 char_u *cpo_save = p_cpo; | |
4013 | |
4014 /* Set 'cpoptions' the way we want it. | |
4015 * B set - backslashes are *not* treated specially | |
4016 * k set - keycodes are *not* reverse-engineered | |
4017 * < unset - <Key> sequences *are* interpreted | |
860 | 4018 * The last but one parameter of replace_termcodes() is TRUE so that the |
4019 * <lt> sequence is recognised - needed for a real backslash. | |
6 | 4020 */ |
4021 p_cpo = (char_u *)"Bk"; | |
860 | 4022 str = replace_termcodes((char_u *)str, &ptr, FALSE, TRUE, FALSE); |
6 | 4023 p_cpo = cpo_save; |
4024 | |
4025 if (*ptr != NUL) /* trailing CTRL-V results in nothing */ | |
4026 { | |
4027 /* | |
4028 * Add the string to the input stream. | |
4029 * Can't use add_to_input_buf() here, we now have K_SPECIAL bytes. | |
4030 * | |
4031 * First clear typed characters from the typeahead buffer, there could | |
4032 * be half a mapping there. Then append to the existing string, so | |
4033 * that multiple commands from a client are concatenated. | |
4034 */ | |
4035 if (typebuf.tb_maplen < typebuf.tb_len) | |
4036 del_typebuf(typebuf.tb_len - typebuf.tb_maplen, typebuf.tb_maplen); | |
4037 (void)ins_typebuf(str, REMAP_NONE, typebuf.tb_len, TRUE, FALSE); | |
4038 | |
4039 /* Let input_available() know we inserted text in the typeahead | |
4040 * buffer. */ | |
841 | 4041 typebuf_was_filled = TRUE; |
6 | 4042 } |
4043 vim_free((char_u *)ptr); | |
4044 } | |
4045 | |
4046 /* | |
4047 * Evaluate an expression that the client sent to a string. | |
4048 */ | |
4049 char_u * | |
4050 eval_client_expr_to_string(expr) | |
4051 char_u *expr; | |
4052 { | |
4053 char_u *res; | |
4054 int save_dbl = debug_break_level; | |
4055 int save_ro = redir_off; | |
4056 | |
4217 | 4057 /* Disable debugging, otherwise Vim hangs, waiting for "cont" to be |
4058 * typed. */ | |
6 | 4059 debug_break_level = -1; |
4060 redir_off = 0; | |
4217 | 4061 /* Do not display error message, otherwise Vim hangs, waiting for "cont" |
4062 * to be typed. Do generate errors so that try/catch works. */ | |
4063 ++emsg_silent; | |
6 | 4064 |
714 | 4065 res = eval_to_string(expr, NULL, TRUE); |
6 | 4066 |
4067 debug_break_level = save_dbl; | |
4068 redir_off = save_ro; | |
4217 | 4069 --emsg_silent; |
4070 if (emsg_silent < 0) | |
4071 emsg_silent = 0; | |
6 | 4072 |
591 | 4073 /* A client can tell us to redraw, but not to display the cursor, so do |
4074 * that here. */ | |
4075 setcursor(); | |
4076 out_flush(); | |
4077 #ifdef FEAT_GUI | |
4078 if (gui.in_use) | |
4079 gui_update_cursor(FALSE, FALSE); | |
4080 #endif | |
4081 | |
6 | 4082 return res; |
4083 } | |
4084 | |
39 | 4085 /* |
4086 * If conversion is needed, convert "data" from "client_enc" to 'encoding' and | |
4087 * return an allocated string. Otherwise return "data". | |
4088 * "*tofree" is set to the result when it needs to be freed later. | |
4089 */ | |
4090 char_u * | |
4091 serverConvert(client_enc, data, tofree) | |
1883 | 4092 char_u *client_enc UNUSED; |
39 | 4093 char_u *data; |
4094 char_u **tofree; | |
4095 { | |
4096 char_u *res = data; | |
4097 | |
4098 *tofree = NULL; | |
4099 # ifdef FEAT_MBYTE | |
4100 if (client_enc != NULL && p_enc != NULL) | |
4101 { | |
4102 vimconv_T vimconv; | |
4103 | |
4104 vimconv.vc_type = CONV_NONE; | |
4105 if (convert_setup(&vimconv, client_enc, p_enc) != FAIL | |
4106 && vimconv.vc_type != CONV_NONE) | |
4107 { | |
4108 res = string_convert(&vimconv, data, NULL); | |
4109 if (res == NULL) | |
4110 res = data; | |
4111 else | |
4112 *tofree = res; | |
4113 } | |
4114 convert_setup(&vimconv, NULL, NULL); | |
4115 } | |
4116 # endif | |
4117 return res; | |
4118 } | |
2730 | 4119 #endif |
6 | 4120 |
4121 /* | |
4122 * When FEAT_FKMAP is defined, also compile the Farsi source code. | |
4123 */ | |
4124 #if defined(FEAT_FKMAP) || defined(PROTO) | |
4125 # include "farsi.c" | |
4126 #endif | |
4127 | |
4128 /* | |
4129 * When FEAT_ARABIC is defined, also compile the Arabic source code. | |
4130 */ | |
4131 #if defined(FEAT_ARABIC) || defined(PROTO) | |
4132 # include "arabic.c" | |
4133 #endif |