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