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