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