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