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