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