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