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