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