Mercurial > vim
annotate src/os_win32.c @ 11054:576238eda5a4 v8.0.0416
patch 8.0.0416: setting v:progpath is not quite right
commit https://github.com/vim/vim/commit/436631969716e056feca47480976100b70283370
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 5 14:29:12 2017 +0100
patch 8.0.0416: setting v:progpath is not quite right
Problem: Setting v:progpath is not quite right.
Solution: On MS-Windows add the extension. On Unix use the full path for a
relative directory. (partly by James McCoy, closes #1531)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 05 Mar 2017 14:30:04 +0100 |
parents | fb2bcfa6a8de |
children | 354593196e20 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10025
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 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 * os_win32.c | |
11 * | |
12 * Used for both the console version and the Win32 GUI. A lot of code is for | |
13 * the console version only, so there is a lot of "#ifndef FEAT_GUI_W32". | |
14 * | |
15 * Win32 (Windows NT and Windows 95) system-dependent routines. | |
16 * Portions lifted from the Win32 SDK samples, the MSDOS-dependent code, | |
17 * NetHack 3.1.3, GNU Emacs 19.30, and Vile 5.5. | |
18 * | |
19 * George V. Reilly <george@reilly.org> wrote most of this. | |
20 * Roger Knobbe <rogerk@wonderware.com> did the initial port of Vim 3.0. | |
21 */ | |
22 | |
23 #include "vim.h" | |
24 | |
14 | 25 #ifdef FEAT_MZSCHEME |
26 # include "if_mzsch.h" | |
27 #endif | |
28 | |
7 | 29 #include <sys/types.h> |
30 #include <signal.h> | |
31 #include <limits.h> | |
3927 | 32 |
33 /* cproto fails on missing include files */ | |
34 #ifndef PROTO | |
35 # include <process.h> | |
36 #endif | |
7 | 37 |
38 #undef chdir | |
39 #ifdef __GNUC__ | |
40 # ifndef __MINGW32__ | |
41 # include <dirent.h> | |
42 # endif | |
43 #else | |
44 # include <direct.h> | |
45 #endif | |
46 | |
3927 | 47 #ifndef PROTO |
48 # if defined(FEAT_TITLE) && !defined(FEAT_GUI_W32) | |
49 # include <shellapi.h> | |
50 # endif | |
7 | 51 #endif |
52 | |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
53 #ifdef FEAT_JOB_CHANNEL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
54 # include <tlhelp32.h> |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
55 #endif |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
56 |
7 | 57 #ifdef __MINGW32__ |
58 # ifndef FROM_LEFT_1ST_BUTTON_PRESSED | |
59 # define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001 | |
60 # endif | |
61 # ifndef RIGHTMOST_BUTTON_PRESSED | |
62 # define RIGHTMOST_BUTTON_PRESSED 0x0002 | |
63 # endif | |
64 # ifndef FROM_LEFT_2ND_BUTTON_PRESSED | |
65 # define FROM_LEFT_2ND_BUTTON_PRESSED 0x0004 | |
66 # endif | |
67 # ifndef FROM_LEFT_3RD_BUTTON_PRESSED | |
68 # define FROM_LEFT_3RD_BUTTON_PRESSED 0x0008 | |
69 # endif | |
70 # ifndef FROM_LEFT_4TH_BUTTON_PRESSED | |
71 # define FROM_LEFT_4TH_BUTTON_PRESSED 0x0010 | |
72 # endif | |
73 | |
74 /* | |
75 * EventFlags | |
76 */ | |
77 # ifndef MOUSE_MOVED | |
78 # define MOUSE_MOVED 0x0001 | |
79 # endif | |
80 # ifndef DOUBLE_CLICK | |
81 # define DOUBLE_CLICK 0x0002 | |
82 # endif | |
83 #endif | |
84 | |
85 /* Record all output and all keyboard & mouse input */ | |
86 /* #define MCH_WRITE_DUMP */ | |
87 | |
88 #ifdef MCH_WRITE_DUMP | |
89 FILE* fdDump = NULL; | |
90 #endif | |
91 | |
92 /* | |
93 * When generating prototypes for Win32 on Unix, these lines make the syntax | |
94 * errors disappear. They do not need to be correct. | |
95 */ | |
96 #ifdef PROTO | |
97 #define WINAPI | |
98 typedef char * LPCSTR; | |
26 | 99 typedef char * LPWSTR; |
7 | 100 typedef int ACCESS_MASK; |
101 typedef int BOOL; | |
102 typedef int COLORREF; | |
103 typedef int CONSOLE_CURSOR_INFO; | |
104 typedef int COORD; | |
105 typedef int DWORD; | |
106 typedef int HANDLE; | |
7668
21b0a39d13ed
commit https://github.com/vim/vim/commit/ef26954a35207c3f17d6ed35d9a40c918d974892
Christian Brabandt <cb@256bit.org>
parents:
7657
diff
changeset
|
107 typedef int LPHANDLE; |
7 | 108 typedef int HDC; |
109 typedef int HFONT; | |
110 typedef int HICON; | |
111 typedef int HINSTANCE; | |
112 typedef int HWND; | |
113 typedef int INPUT_RECORD; | |
114 typedef int KEY_EVENT_RECORD; | |
115 typedef int LOGFONT; | |
116 typedef int LPBOOL; | |
117 typedef int LPCTSTR; | |
118 typedef int LPDWORD; | |
119 typedef int LPSTR; | |
120 typedef int LPTSTR; | |
121 typedef int LPVOID; | |
122 typedef int MOUSE_EVENT_RECORD; | |
123 typedef int PACL; | |
124 typedef int PDWORD; | |
125 typedef int PHANDLE; | |
126 typedef int PRINTDLG; | |
127 typedef int PSECURITY_DESCRIPTOR; | |
128 typedef int PSID; | |
129 typedef int SECURITY_INFORMATION; | |
130 typedef int SHORT; | |
131 typedef int SMALL_RECT; | |
132 typedef int TEXTMETRIC; | |
133 typedef int TOKEN_INFORMATION_CLASS; | |
134 typedef int TRUSTEE; | |
135 typedef int WORD; | |
136 typedef int WCHAR; | |
137 typedef void VOID; | |
3927 | 138 typedef int BY_HANDLE_FILE_INFORMATION; |
5112
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
139 typedef int SE_OBJECT_TYPE; |
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
140 typedef int PSNSECINFO; |
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
141 typedef int PSNSECINFOW; |
6359 | 142 typedef int STARTUPINFO; |
143 typedef int PROCESS_INFORMATION; | |
10025
068f397d0da4
commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
144 typedef int LPSECURITY_ATTRIBUTES; |
068f397d0da4
commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
145 # define __stdcall /* empty */ |
7 | 146 #endif |
147 | |
148 #if defined(__BORLANDC__) | |
149 /* Strangely Borland uses a non-standard name. */ | |
150 # define wcsicmp(a, b) wcscmpi((a), (b)) | |
151 #endif | |
152 | |
153 #ifndef FEAT_GUI_W32 | |
154 /* Win32 Console handles for input and output */ | |
155 static HANDLE g_hConIn = INVALID_HANDLE_VALUE; | |
156 static HANDLE g_hConOut = INVALID_HANDLE_VALUE; | |
157 | |
158 /* Win32 Screen buffer,coordinate,console I/O information */ | |
159 static SMALL_RECT g_srScrollRegion; | |
160 static COORD g_coord; /* 0-based, but external coords are 1-based */ | |
161 | |
162 /* The attribute of the screen when the editor was started */ | |
163 static WORD g_attrDefault = 7; /* lightgray text on black background */ | |
164 static WORD g_attrCurrent; | |
165 | |
166 static int g_fCBrkPressed = FALSE; /* set by ctrl-break interrupt */ | |
167 static int g_fCtrlCPressed = FALSE; /* set when ctrl-C or ctrl-break detected */ | |
168 static int g_fForceExit = FALSE; /* set when forcefully exiting */ | |
169 | |
170 static void termcap_mode_start(void); | |
171 static void termcap_mode_end(void); | |
172 static void clear_chars(COORD coord, DWORD n); | |
173 static void clear_screen(void); | |
174 static void clear_to_end_of_display(void); | |
175 static void clear_to_end_of_line(void); | |
176 static void scroll(unsigned cLines); | |
177 static void set_scroll_region(unsigned left, unsigned top, | |
178 unsigned right, unsigned bottom); | |
179 static void insert_lines(unsigned cLines); | |
180 static void delete_lines(unsigned cLines); | |
181 static void gotoxy(unsigned x, unsigned y); | |
182 static void normvideo(void); | |
183 static void textattr(WORD wAttr); | |
184 static void textcolor(WORD wAttr); | |
185 static void textbackground(WORD wAttr); | |
186 static void standout(void); | |
187 static void standend(void); | |
188 static void visual_bell(void); | |
189 static void cursor_visible(BOOL fVisible); | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
190 static DWORD write_chars(char_u *pchBuf, DWORD cbToWrite); |
7 | 191 static void create_conin(void); |
192 static int s_cursor_visible = TRUE; | |
193 static int did_create_conin = FALSE; | |
194 #else | |
195 static int s_dont_use_vimrun = TRUE; | |
196 static int need_vimrun_warning = FALSE; | |
197 static char *vimrun_path = "vimrun "; | |
198 #endif | |
199 | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
200 static int win32_getattrs(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
201 static int win32_setattrs(char_u *name, int attrs); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
202 static int win32_set_archive(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
203 |
7 | 204 #ifndef FEAT_GUI_W32 |
205 static int suppress_winsize = 1; /* don't fiddle with console */ | |
206 #endif | |
207 | |
2612 | 208 static char_u *exe_path = NULL; |
209 | |
5633 | 210 static BOOL win8_or_later = FALSE; |
211 | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
212 #ifndef FEAT_GUI_W32 |
5580 | 213 /* |
214 * Version of ReadConsoleInput() that works with IME. | |
5590 | 215 * Works around problems on Windows 8. |
5580 | 216 */ |
217 static BOOL | |
218 read_console_input( | |
5590 | 219 HANDLE hInput, |
220 INPUT_RECORD *lpBuffer, | |
221 DWORD nLength, | |
222 LPDWORD lpEvents) | |
5580 | 223 { |
224 enum | |
225 { | |
5590 | 226 IRSIZE = 10 |
5580 | 227 }; |
5590 | 228 static INPUT_RECORD s_irCache[IRSIZE]; |
5580 | 229 static DWORD s_dwIndex = 0; |
230 static DWORD s_dwMax = 0; | |
5590 | 231 DWORD dwEvents; |
5635 | 232 int head; |
233 int tail; | |
234 int i; | |
5580 | 235 |
6981 | 236 if (nLength == -2) |
237 return (s_dwMax > 0) ? TRUE : FALSE; | |
238 | |
5633 | 239 if (!win8_or_later) |
240 { | |
241 if (nLength == -1) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
242 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
243 return ReadConsoleInputW(hInput, lpBuffer, 1, &dwEvents); |
5633 | 244 } |
245 | |
5580 | 246 if (s_dwMax == 0) |
247 { | |
5590 | 248 if (nLength == -1) |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
249 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
250 if (!ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents)) |
5590 | 251 return FALSE; |
5580 | 252 s_dwIndex = 0; |
5590 | 253 s_dwMax = dwEvents; |
254 if (dwEvents == 0) | |
5580 | 255 { |
5590 | 256 *lpEvents = 0; |
257 return TRUE; | |
5580 | 258 } |
5635 | 259 |
260 if (s_dwMax > 1) | |
261 { | |
262 head = 0; | |
263 tail = s_dwMax - 1; | |
264 while (head != tail) | |
265 { | |
266 if (s_irCache[head].EventType == WINDOW_BUFFER_SIZE_EVENT | |
267 && s_irCache[head + 1].EventType | |
268 == WINDOW_BUFFER_SIZE_EVENT) | |
269 { | |
270 /* Remove duplicate event to avoid flicker. */ | |
271 for (i = head; i < tail; ++i) | |
272 s_irCache[i] = s_irCache[i + 1]; | |
273 --tail; | |
274 continue; | |
275 } | |
276 head++; | |
277 } | |
278 s_dwMax = tail + 1; | |
279 } | |
5580 | 280 } |
5635 | 281 |
5590 | 282 *lpBuffer = s_irCache[s_dwIndex]; |
6981 | 283 if (!(nLength == -1 || nLength == -2) && ++s_dwIndex >= s_dwMax) |
5580 | 284 s_dwMax = 0; |
5590 | 285 *lpEvents = 1; |
5580 | 286 return TRUE; |
287 } | |
288 | |
289 /* | |
290 * Version of PeekConsoleInput() that works with IME. | |
291 */ | |
292 static BOOL | |
293 peek_console_input( | |
5590 | 294 HANDLE hInput, |
295 INPUT_RECORD *lpBuffer, | |
296 DWORD nLength, | |
297 LPDWORD lpEvents) | |
5580 | 298 { |
5590 | 299 return read_console_input(hInput, lpBuffer, -1, lpEvents); |
5580 | 300 } |
301 | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
302 # ifdef FEAT_CLIENTSERVER |
6981 | 303 static DWORD |
304 msg_wait_for_multiple_objects( | |
305 DWORD nCount, | |
306 LPHANDLE pHandles, | |
307 BOOL fWaitAll, | |
308 DWORD dwMilliseconds, | |
309 DWORD dwWakeMask) | |
310 { | |
311 if (read_console_input(NULL, NULL, -2, NULL)) | |
312 return WAIT_OBJECT_0; | |
313 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, | |
314 dwMilliseconds, dwWakeMask); | |
315 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
316 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
317 |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
318 # ifndef FEAT_CLIENTSERVER |
6981 | 319 static DWORD |
320 wait_for_single_object( | |
321 HANDLE hHandle, | |
322 DWORD dwMilliseconds) | |
323 { | |
324 if (read_console_input(NULL, NULL, -2, NULL)) | |
325 return WAIT_OBJECT_0; | |
326 return WaitForSingleObject(hHandle, dwMilliseconds); | |
327 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
328 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
329 #endif |
6981 | 330 |
7 | 331 static void |
332 get_exe_name(void) | |
333 { | |
2630 | 334 /* Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned |
335 * as the maximum length that works (plus a NUL byte). */ | |
336 #define MAX_ENV_PATH_LEN 8192 | |
337 char temp[MAX_ENV_PATH_LEN]; | |
2612 | 338 char_u *p; |
7 | 339 |
340 if (exe_name == NULL) | |
341 { | |
342 /* store the name of the executable, may be used for $VIM */ | |
2630 | 343 GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1); |
7 | 344 if (*temp != NUL) |
345 exe_name = FullName_save((char_u *)temp, FALSE); | |
346 } | |
819 | 347 |
2612 | 348 if (exe_path == NULL && exe_name != NULL) |
819 | 349 { |
2615 | 350 exe_path = vim_strnsave(exe_name, |
351 (int)(gettail_sep(exe_name) - exe_name)); | |
2612 | 352 if (exe_path != NULL) |
819 | 353 { |
2612 | 354 /* Append our starting directory to $PATH, so that when doing |
355 * "!xxd" it's found in our starting directory. Needed because | |
356 * SearchPath() also looks there. */ | |
357 p = mch_getenv("PATH"); | |
2630 | 358 if (p == NULL |
359 || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN) | |
2612 | 360 { |
2630 | 361 if (p == NULL || *p == NUL) |
362 temp[0] = NUL; | |
363 else | |
364 { | |
365 STRCPY(temp, p); | |
366 STRCAT(temp, ";"); | |
367 } | |
2612 | 368 STRCAT(temp, exe_path); |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
369 vim_setenv((char_u *)"PATH", (char_u *)temp); |
2612 | 370 } |
819 | 371 } |
372 } | |
7 | 373 } |
374 | |
2612 | 375 /* |
3361 | 376 * Unescape characters in "p" that appear in "escaped". |
377 */ | |
378 static void | |
379 unescape_shellxquote(char_u *p, char_u *escaped) | |
380 { | |
3386 | 381 int l = (int)STRLEN(p); |
3361 | 382 int n; |
383 | |
384 while (*p != NUL) | |
385 { | |
386 if (*p == '^' && vim_strchr(escaped, p[1]) != NULL) | |
387 mch_memmove(p, p + 1, l--); | |
388 #ifdef FEAT_MBYTE | |
389 n = (*mb_ptr2len)(p); | |
390 #else | |
391 n = 1; | |
392 #endif | |
393 p += n; | |
394 l -= n; | |
395 } | |
396 } | |
397 | |
398 /* | |
2612 | 399 * Load library "name". |
400 */ | |
401 HINSTANCE | |
402 vimLoadLib(char *name) | |
403 { | |
3902 | 404 HINSTANCE dll = NULL; |
3889 | 405 |
406 /* NOTE: Do not use mch_dirname() and mch_chdir() here, they may call | |
407 * vimLoadLib() recursively, which causes a stack overflow. */ | |
2612 | 408 if (exe_path == NULL) |
409 get_exe_name(); | |
3902 | 410 if (exe_path != NULL) |
2612 | 411 { |
3902 | 412 WCHAR old_dirw[MAXPATHL]; |
413 | |
414 if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) | |
415 { | |
416 /* Change directory to where the executable is, both to make | |
417 * sure we find a .dll there and to avoid looking for a .dll | |
418 * in the current directory. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
419 SetCurrentDirectory((LPCSTR)exe_path); |
3902 | 420 dll = LoadLibrary(name); |
421 SetCurrentDirectoryW(old_dirw); | |
422 return dll; | |
423 } | |
2612 | 424 } |
425 return dll; | |
426 } | |
427 | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
428 #if defined(DYNAMIC_ICONV) || defined(DYNAMIC_GETTEXT) || defined(PROTO) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
429 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
430 * Get related information about 'funcname' which is imported by 'hInst'. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
431 * If 'info' is 0, return the function address. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
432 * If 'info' is 1, return the module name which the function is imported from. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
433 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
434 static void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
435 get_imported_func_info(HINSTANCE hInst, const char *funcname, int info) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
436 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
437 PBYTE pImage = (PBYTE)hInst; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
438 PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
439 PIMAGE_NT_HEADERS pPE; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
440 PIMAGE_IMPORT_DESCRIPTOR pImpDesc; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
441 PIMAGE_THUNK_DATA pIAT; /* Import Address Table */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
442 PIMAGE_THUNK_DATA pINT; /* Import Name Table */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
443 PIMAGE_IMPORT_BY_NAME pImpName; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
444 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
445 if (pDOS->e_magic != IMAGE_DOS_SIGNATURE) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
446 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
447 pPE = (PIMAGE_NT_HEADERS)(pImage + pDOS->e_lfanew); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
448 if (pPE->Signature != IMAGE_NT_SIGNATURE) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
449 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
450 pImpDesc = (PIMAGE_IMPORT_DESCRIPTOR)(pImage |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
451 + pPE->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
452 .VirtualAddress); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
453 for (; pImpDesc->FirstThunk; ++pImpDesc) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
454 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
455 if (!pImpDesc->OriginalFirstThunk) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
456 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
457 pIAT = (PIMAGE_THUNK_DATA)(pImage + pImpDesc->FirstThunk); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
458 pINT = (PIMAGE_THUNK_DATA)(pImage + pImpDesc->OriginalFirstThunk); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
459 for (; pIAT->u1.Function; ++pIAT, ++pINT) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
460 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
461 if (IMAGE_SNAP_BY_ORDINAL(pINT->u1.Ordinal)) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
462 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
463 pImpName = (PIMAGE_IMPORT_BY_NAME)(pImage |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
464 + (UINT_PTR)(pINT->u1.AddressOfData)); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
465 if (strcmp((char *)pImpName->Name, funcname) == 0) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
466 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
467 switch (info) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
468 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
469 case 0: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
470 return (void *)pIAT->u1.Function; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
471 case 1: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
472 return (void *)(pImage + pImpDesc->Name); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
473 default: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
474 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
475 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
476 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
477 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
478 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
479 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
480 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
481 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
482 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
483 * Get the module handle which 'funcname' in 'hInst' is imported from. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
484 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
485 HINSTANCE |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
486 find_imported_module_by_funcname(HINSTANCE hInst, const char *funcname) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
487 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
488 char *modulename; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
489 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
490 modulename = (char *)get_imported_func_info(hInst, funcname, 1); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
491 if (modulename != NULL) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
492 return GetModuleHandleA(modulename); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
493 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
494 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
495 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
496 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
497 * Get the address of 'funcname' which is imported by 'hInst' DLL. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
498 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
499 void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
500 get_dll_import_func(HINSTANCE hInst, const char *funcname) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
501 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
502 return get_imported_func_info(hInst, funcname, 0); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
503 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
504 #endif |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
505 |
7 | 506 #if defined(DYNAMIC_GETTEXT) || defined(PROTO) |
507 # ifndef GETTEXT_DLL | |
508 # define GETTEXT_DLL "libintl.dll" | |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
509 # define GETTEXT_DLL_ALT "libintl-8.dll" |
7 | 510 # endif |
3622 | 511 /* Dummy functions */ |
36 | 512 static char *null_libintl_gettext(const char *); |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
513 static char *null_libintl_ngettext(const char *, const char *, unsigned long n); |
36 | 514 static char *null_libintl_textdomain(const char *); |
515 static char *null_libintl_bindtextdomain(const char *, const char *); | |
516 static char *null_libintl_bind_textdomain_codeset(const char *, const char *); | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
517 static int null_libintl_putenv(const char *); |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
518 static int null_libintl_wputenv(const wchar_t *); |
7 | 519 |
2612 | 520 static HINSTANCE hLibintlDLL = NULL; |
36 | 521 char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext; |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
522 char *(*dyn_libintl_ngettext)(const char *, const char *, unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
523 = null_libintl_ngettext; |
36 | 524 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; |
525 char *(*dyn_libintl_bindtextdomain)(const char *, const char *) | |
7 | 526 = null_libintl_bindtextdomain; |
36 | 527 char *(*dyn_libintl_bind_textdomain_codeset)(const char *, const char *) |
528 = null_libintl_bind_textdomain_codeset; | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
529 int (*dyn_libintl_putenv)(const char *) = null_libintl_putenv; |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
530 int (*dyn_libintl_wputenv)(const wchar_t *) = null_libintl_wputenv; |
7 | 531 |
532 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
533 dyn_libintl_init(void) |
7 | 534 { |
535 int i; | |
536 static struct | |
537 { | |
538 char *name; | |
539 FARPROC *ptr; | |
540 } libintl_entry[] = | |
541 { | |
542 {"gettext", (FARPROC*)&dyn_libintl_gettext}, | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
543 {"ngettext", (FARPROC*)&dyn_libintl_ngettext}, |
7 | 544 {"textdomain", (FARPROC*)&dyn_libintl_textdomain}, |
545 {"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, | |
546 {NULL, NULL} | |
547 }; | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
548 HINSTANCE hmsvcrt; |
7 | 549 |
550 /* No need to initialize twice. */ | |
551 if (hLibintlDLL) | |
552 return 1; | |
553 /* Load gettext library (libintl.dll) */ | |
7784
29d4ee3f009a
commit https://github.com/vim/vim/commit/923e43b837ca4c8edb7998743f142823eaeaf588
Christian Brabandt <cb@256bit.org>
parents:
7734
diff
changeset
|
554 hLibintlDLL = vimLoadLib(GETTEXT_DLL); |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
555 #ifdef GETTEXT_DLL_ALT |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
556 if (!hLibintlDLL) |
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
557 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT); |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
558 #endif |
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
559 if (!hLibintlDLL) |
7 | 560 { |
2612 | 561 if (p_verbose > 0) |
7 | 562 { |
2612 | 563 verbose_enter(); |
564 EMSG2(_(e_loadlib), GETTEXT_DLL); | |
565 verbose_leave(); | |
7 | 566 } |
2612 | 567 return 0; |
7 | 568 } |
569 for (i = 0; libintl_entry[i].name != NULL | |
570 && libintl_entry[i].ptr != NULL; ++i) | |
571 { | |
572 if ((*libintl_entry[i].ptr = (FARPROC)GetProcAddress(hLibintlDLL, | |
573 libintl_entry[i].name)) == NULL) | |
574 { | |
575 dyn_libintl_end(); | |
576 if (p_verbose > 0) | |
292 | 577 { |
578 verbose_enter(); | |
7 | 579 EMSG2(_(e_loadfunc), libintl_entry[i].name); |
292 | 580 verbose_leave(); |
581 } | |
7 | 582 return 0; |
583 } | |
584 } | |
36 | 585 |
586 /* The bind_textdomain_codeset() function is optional. */ | |
323 | 587 dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL, |
36 | 588 "bind_textdomain_codeset"); |
589 if (dyn_libintl_bind_textdomain_codeset == NULL) | |
590 dyn_libintl_bind_textdomain_codeset = | |
591 null_libintl_bind_textdomain_codeset; | |
592 | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
593 /* _putenv() function for the libintl.dll is optional. */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
594 hmsvcrt = find_imported_module_by_funcname(hLibintlDLL, "getenv"); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
595 if (hmsvcrt != NULL) |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
596 { |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
597 dyn_libintl_putenv = (void *)GetProcAddress(hmsvcrt, "_putenv"); |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
598 dyn_libintl_wputenv = (void *)GetProcAddress(hmsvcrt, "_wputenv"); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
599 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
600 if (dyn_libintl_putenv == NULL || dyn_libintl_putenv == _putenv) |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
601 dyn_libintl_putenv = null_libintl_putenv; |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
602 if (dyn_libintl_wputenv == NULL || dyn_libintl_wputenv == _wputenv) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
603 dyn_libintl_wputenv = null_libintl_wputenv; |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
604 |
7 | 605 return 1; |
606 } | |
607 | |
608 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
609 dyn_libintl_end(void) |
7 | 610 { |
611 if (hLibintlDLL) | |
612 FreeLibrary(hLibintlDLL); | |
613 hLibintlDLL = NULL; | |
614 dyn_libintl_gettext = null_libintl_gettext; | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
615 dyn_libintl_ngettext = null_libintl_ngettext; |
7 | 616 dyn_libintl_textdomain = null_libintl_textdomain; |
617 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain; | |
36 | 618 dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset; |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
619 dyn_libintl_putenv = null_libintl_putenv; |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
620 dyn_libintl_wputenv = null_libintl_wputenv; |
7 | 621 } |
622 | |
623 static char * | |
26 | 624 null_libintl_gettext(const char *msgid) |
7 | 625 { |
626 return (char*)msgid; | |
627 } | |
628 | |
629 static char * | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
630 null_libintl_ngettext( |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
631 const char *msgid, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
632 const char *msgid_plural, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
633 unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
634 { |
9762
93dcc4329c74
commit https://github.com/vim/vim/commit/c90f2aedd0a5dc2cc75bc9b5f475f8a3e3fe36b1
Christian Brabandt <cb@256bit.org>
parents:
9754
diff
changeset
|
635 return (char *)(n == 1 ? msgid : msgid_plural); |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
636 } |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
637 |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
638 static char * |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
639 null_libintl_bindtextdomain( |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
640 const char *domainname UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
641 const char *dirname UNUSED) |
7 | 642 { |
643 return NULL; | |
644 } | |
645 | |
646 static char * | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
647 null_libintl_bind_textdomain_codeset( |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
648 const char *domainname UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
649 const char *codeset UNUSED) |
36 | 650 { |
651 return NULL; | |
652 } | |
653 | |
654 static char * | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
655 null_libintl_textdomain(const char *domainname UNUSED) |
7 | 656 { |
657 return NULL; | |
658 } | |
659 | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
660 int |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
661 null_libintl_putenv(const char *envstring UNUSED) |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
662 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
663 return 0; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
664 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
665 |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
666 int |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
667 null_libintl_wputenv(const wchar_t *envstring UNUSED) |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
668 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
669 return 0; |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
670 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
671 |
7 | 672 #endif /* DYNAMIC_GETTEXT */ |
673 | |
674 /* This symbol is not defined in older versions of the SDK or Visual C++ */ | |
675 | |
676 #ifndef VER_PLATFORM_WIN32_WINDOWS | |
677 # define VER_PLATFORM_WIN32_WINDOWS 1 | |
678 #endif | |
679 | |
680 DWORD g_PlatformId; | |
681 | |
682 #ifdef HAVE_ACL | |
3927 | 683 # ifndef PROTO |
684 # include <aclapi.h> | |
685 # endif | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
686 # ifndef PROTECTED_DACL_SECURITY_INFORMATION |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
687 # define PROTECTED_DACL_SECURITY_INFORMATION 0x80000000L |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
688 # endif |
7 | 689 #endif |
690 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
691 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
692 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
693 * Enables or disables the specified privilege. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
694 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
695 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
696 win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
697 { |
5590 | 698 BOOL bResult; |
699 LUID luid; | |
700 HANDLE hToken; | |
701 TOKEN_PRIVILEGES tokenPrivileges; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
702 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
703 if (!OpenProcessToken(GetCurrentProcess(), |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
704 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
705 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
706 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
707 if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
708 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
709 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
710 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
711 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
712 |
6047 | 713 tokenPrivileges.PrivilegeCount = 1; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
714 tokenPrivileges.Privileges[0].Luid = luid; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
715 tokenPrivileges.Privileges[0].Attributes = bEnable ? |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
716 SE_PRIVILEGE_ENABLED : 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
717 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
718 bResult = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
719 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
720 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
721 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
722 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
723 return bResult && GetLastError() == ERROR_SUCCESS; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
724 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
725 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
726 |
7 | 727 /* |
728 * Set g_PlatformId to VER_PLATFORM_WIN32_NT (NT) or | |
729 * VER_PLATFORM_WIN32_WINDOWS (Win95). | |
730 */ | |
731 void | |
732 PlatformId(void) | |
733 { | |
734 static int done = FALSE; | |
735 | |
736 if (!done) | |
737 { | |
738 OSVERSIONINFO ovi; | |
739 | |
740 ovi.dwOSVersionInfoSize = sizeof(ovi); | |
741 GetVersionEx(&ovi); | |
742 | |
743 g_PlatformId = ovi.dwPlatformId; | |
744 | |
5633 | 745 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2) |
746 || ovi.dwMajorVersion > 6) | |
747 win8_or_later = TRUE; | |
748 | |
7 | 749 #ifdef HAVE_ACL |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
750 /* Enable privilege for getting or setting SACLs. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
751 win32_enable_privilege(SE_SECURITY_NAME, TRUE); |
7 | 752 #endif |
753 done = TRUE; | |
754 } | |
755 } | |
756 | |
757 #ifndef FEAT_GUI_W32 | |
758 | |
759 #define SHIFT (SHIFT_PRESSED) | |
760 #define CTRL (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED) | |
761 #define ALT (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED) | |
762 #define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) | |
763 | |
764 | |
765 /* When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode. | |
766 * We map function keys to their ANSI terminal equivalents, as produced | |
767 * by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any | |
768 * ANSI key with a value >= '\300' is nonstandard, but provided anyway | |
769 * so that the user can have access to all SHIFT-, CTRL-, and ALT- | |
770 * combinations of function/arrow/etc keys. | |
771 */ | |
772 | |
297 | 773 static const struct |
7 | 774 { |
775 WORD wVirtKey; | |
776 BOOL fAnsiKey; | |
777 int chAlone; | |
778 int chShift; | |
779 int chCtrl; | |
780 int chAlt; | |
781 } VirtKeyMap[] = | |
782 { | |
783 | |
784 /* Key ANSI alone shift ctrl alt */ | |
785 { VK_ESCAPE,FALSE, ESC, ESC, ESC, ESC, }, | |
786 | |
787 { VK_F1, TRUE, ';', 'T', '^', 'h', }, | |
788 { VK_F2, TRUE, '<', 'U', '_', 'i', }, | |
789 { VK_F3, TRUE, '=', 'V', '`', 'j', }, | |
790 { VK_F4, TRUE, '>', 'W', 'a', 'k', }, | |
791 { VK_F5, TRUE, '?', 'X', 'b', 'l', }, | |
792 { VK_F6, TRUE, '@', 'Y', 'c', 'm', }, | |
793 { VK_F7, TRUE, 'A', 'Z', 'd', 'n', }, | |
794 { VK_F8, TRUE, 'B', '[', 'e', 'o', }, | |
795 { VK_F9, TRUE, 'C', '\\', 'f', 'p', }, | |
796 { VK_F10, TRUE, 'D', ']', 'g', 'q', }, | |
797 { VK_F11, TRUE, '\205', '\207', '\211', '\213', }, | |
798 { VK_F12, TRUE, '\206', '\210', '\212', '\214', }, | |
799 | |
800 { VK_HOME, TRUE, 'G', '\302', 'w', '\303', }, | |
801 { VK_UP, TRUE, 'H', '\304', '\305', '\306', }, | |
802 { VK_PRIOR, TRUE, 'I', '\307', '\204', '\310', }, /*PgUp*/ | |
803 { VK_LEFT, TRUE, 'K', '\311', 's', '\312', }, | |
804 { VK_RIGHT, TRUE, 'M', '\313', 't', '\314', }, | |
805 { VK_END, TRUE, 'O', '\315', 'u', '\316', }, | |
806 { VK_DOWN, TRUE, 'P', '\317', '\320', '\321', }, | |
807 { VK_NEXT, TRUE, 'Q', '\322', 'v', '\323', }, /*PgDn*/ | |
808 { VK_INSERT,TRUE, 'R', '\324', '\325', '\326', }, | |
809 { VK_DELETE,TRUE, 'S', '\327', '\330', '\331', }, | |
810 | |
811 { VK_SNAPSHOT,TRUE, 0, 0, 0, 'r', }, /*PrtScrn*/ | |
812 | |
813 #if 0 | |
814 /* Most people don't have F13-F20, but what the hell... */ | |
815 { VK_F13, TRUE, '\332', '\333', '\334', '\335', }, | |
816 { VK_F14, TRUE, '\336', '\337', '\340', '\341', }, | |
817 { VK_F15, TRUE, '\342', '\343', '\344', '\345', }, | |
818 { VK_F16, TRUE, '\346', '\347', '\350', '\351', }, | |
819 { VK_F17, TRUE, '\352', '\353', '\354', '\355', }, | |
820 { VK_F18, TRUE, '\356', '\357', '\360', '\361', }, | |
821 { VK_F19, TRUE, '\362', '\363', '\364', '\365', }, | |
822 { VK_F20, TRUE, '\366', '\367', '\370', '\371', }, | |
823 #endif | |
824 { VK_ADD, TRUE, 'N', 'N', 'N', 'N', }, /* keyp '+' */ | |
825 { VK_SUBTRACT, TRUE,'J', 'J', 'J', 'J', }, /* keyp '-' */ | |
826 /* { VK_DIVIDE, TRUE,'N', 'N', 'N', 'N', }, keyp '/' */ | |
827 { VK_MULTIPLY, TRUE,'7', '7', '7', '7', }, /* keyp '*' */ | |
828 | |
829 { VK_NUMPAD0,TRUE, '\332', '\333', '\334', '\335', }, | |
830 { VK_NUMPAD1,TRUE, '\336', '\337', '\340', '\341', }, | |
831 { VK_NUMPAD2,TRUE, '\342', '\343', '\344', '\345', }, | |
832 { VK_NUMPAD3,TRUE, '\346', '\347', '\350', '\351', }, | |
833 { VK_NUMPAD4,TRUE, '\352', '\353', '\354', '\355', }, | |
834 { VK_NUMPAD5,TRUE, '\356', '\357', '\360', '\361', }, | |
835 { VK_NUMPAD6,TRUE, '\362', '\363', '\364', '\365', }, | |
836 { VK_NUMPAD7,TRUE, '\366', '\367', '\370', '\371', }, | |
837 { VK_NUMPAD8,TRUE, '\372', '\373', '\374', '\375', }, | |
838 /* Sorry, out of number space! <negri>*/ | |
839 { VK_NUMPAD9,TRUE, '\376', '\377', '\377', '\367', }, | |
840 | |
841 }; | |
842 | |
843 | |
844 #ifdef _MSC_VER | |
845 // The ToAscii bug destroys several registers. Need to turn off optimization | |
846 // or the GetConsoleKeyboardLayoutName hack will fail in non-debug versions | |
797 | 847 # pragma warning(push) |
848 # pragma warning(disable: 4748) | |
7 | 849 # pragma optimize("", off) |
850 #endif | |
851 | |
852 #if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
853 # define UChar UnicodeChar |
7 | 854 #else |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
855 # define UChar uChar.UnicodeChar |
7 | 856 #endif |
857 | |
858 /* The return code indicates key code size. */ | |
859 static int | |
860 #ifdef __BORLANDC__ | |
861 __stdcall | |
862 #endif | |
863 win32_kbd_patch_key( | |
26 | 864 KEY_EVENT_RECORD *pker) |
7 | 865 { |
866 UINT uMods = pker->dwControlKeyState; | |
867 static int s_iIsDead = 0; | |
868 static WORD awAnsiCode[2]; | |
869 static BYTE abKeystate[256]; | |
870 | |
871 | |
872 if (s_iIsDead == 2) | |
873 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
874 pker->UChar = (WCHAR) awAnsiCode[1]; |
7 | 875 s_iIsDead = 0; |
876 return 1; | |
877 } | |
878 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
879 if (pker->UChar != 0) |
7 | 880 return 1; |
881 | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1752
diff
changeset
|
882 vim_memset(abKeystate, 0, sizeof (abKeystate)); |
7 | 883 |
884 /* Clear any pending dead keys */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
885 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); |
7 | 886 |
887 if (uMods & SHIFT_PRESSED) | |
888 abKeystate[VK_SHIFT] = 0x80; | |
889 if (uMods & CAPSLOCK_ON) | |
890 abKeystate[VK_CAPITAL] = 1; | |
891 | |
892 if ((uMods & ALT_GR) == ALT_GR) | |
893 { | |
894 abKeystate[VK_CONTROL] = abKeystate[VK_LCONTROL] = | |
895 abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80; | |
896 } | |
897 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
898 s_iIsDead = ToUnicode(pker->wVirtualKeyCode, pker->wVirtualScanCode, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
899 abKeystate, awAnsiCode, 2, 0); |
7 | 900 |
901 if (s_iIsDead > 0) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
902 pker->UChar = (WCHAR) awAnsiCode[0]; |
7 | 903 |
904 return s_iIsDead; | |
905 } | |
906 | |
907 #ifdef _MSC_VER | |
908 /* MUST switch optimization on again here, otherwise a call to | |
909 * decode_key_event() may crash (e.g. when hitting caps-lock) */ | |
910 # pragma optimize("", on) | |
797 | 911 # pragma warning(pop) |
7 | 912 |
913 # if (_MSC_VER < 1100) | |
914 /* MUST turn off global optimisation for this next function, or | |
915 * pressing ctrl-minus in insert mode crashes Vim when built with | |
916 * VC4.1. -- negri. */ | |
917 # pragma optimize("g", off) | |
918 # endif | |
919 #endif | |
920 | |
921 static BOOL g_fJustGotFocus = FALSE; | |
922 | |
923 /* | |
924 * Decode a KEY_EVENT into one or two keystrokes | |
925 */ | |
926 static BOOL | |
927 decode_key_event( | |
928 KEY_EVENT_RECORD *pker, | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
929 WCHAR *pch, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
930 WCHAR *pch2, |
7 | 931 int *pmodifiers, |
932 BOOL fDoPost) | |
933 { | |
934 int i; | |
935 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL); | |
936 | |
937 *pch = *pch2 = NUL; | |
938 g_fJustGotFocus = FALSE; | |
939 | |
940 /* ignore key up events */ | |
941 if (!pker->bKeyDown) | |
942 return FALSE; | |
943 | |
944 /* ignore some keystrokes */ | |
945 switch (pker->wVirtualKeyCode) | |
946 { | |
947 /* modifiers */ | |
948 case VK_SHIFT: | |
949 case VK_CONTROL: | |
950 case VK_MENU: /* Alt key */ | |
951 return FALSE; | |
952 | |
953 default: | |
954 break; | |
955 } | |
956 | |
957 /* special cases */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
958 if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL) |
7 | 959 { |
960 /* Ctrl-6 is Ctrl-^ */ | |
961 if (pker->wVirtualKeyCode == '6') | |
962 { | |
963 *pch = Ctrl_HAT; | |
964 return TRUE; | |
965 } | |
966 /* Ctrl-2 is Ctrl-@ */ | |
967 else if (pker->wVirtualKeyCode == '2') | |
968 { | |
969 *pch = NUL; | |
970 return TRUE; | |
971 } | |
972 /* Ctrl-- is Ctrl-_ */ | |
973 else if (pker->wVirtualKeyCode == 0xBD) | |
974 { | |
975 *pch = Ctrl__; | |
976 return TRUE; | |
977 } | |
978 } | |
979 | |
980 /* Shift-TAB */ | |
981 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) | |
982 { | |
983 *pch = K_NUL; | |
984 *pch2 = '\017'; | |
985 return TRUE; | |
986 } | |
987 | |
988 for (i = sizeof(VirtKeyMap) / sizeof(VirtKeyMap[0]); --i >= 0; ) | |
989 { | |
990 if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode) | |
991 { | |
992 if (nModifs == 0) | |
993 *pch = VirtKeyMap[i].chAlone; | |
994 else if ((nModifs & SHIFT) != 0 && (nModifs & ~SHIFT) == 0) | |
995 *pch = VirtKeyMap[i].chShift; | |
996 else if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0) | |
997 *pch = VirtKeyMap[i].chCtrl; | |
998 else if ((nModifs & ALT) != 0 && (nModifs & ~ALT) == 0) | |
999 *pch = VirtKeyMap[i].chAlt; | |
1000 | |
1001 if (*pch != 0) | |
1002 { | |
1003 if (VirtKeyMap[i].fAnsiKey) | |
1004 { | |
1005 *pch2 = *pch; | |
1006 *pch = K_NUL; | |
1007 } | |
1008 | |
1009 return TRUE; | |
1010 } | |
1011 } | |
1012 } | |
1013 | |
1014 i = win32_kbd_patch_key(pker); | |
1015 | |
1016 if (i < 0) | |
1017 *pch = NUL; | |
1018 else | |
1019 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1020 *pch = (i > 0) ? pker->UChar : NUL; |
7 | 1021 |
1022 if (pmodifiers != NULL) | |
1023 { | |
1024 /* Pass on the ALT key as a modifier, but only when not combined | |
1025 * with CTRL (which is ALTGR). */ | |
1026 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) | |
1027 *pmodifiers |= MOD_MASK_ALT; | |
1028 | |
1029 /* Pass on SHIFT only for special keys, because we don't know when | |
1030 * it's already included with the character. */ | |
1031 if ((nModifs & SHIFT) != 0 && *pch <= 0x20) | |
1032 *pmodifiers |= MOD_MASK_SHIFT; | |
1033 | |
1034 /* Pass on CTRL only for non-special keys, because we don't know | |
1035 * when it's already included with the character. And not when | |
1036 * combined with ALT (which is ALTGR). */ | |
1037 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 | |
1038 && *pch >= 0x20 && *pch < 0x80) | |
1039 *pmodifiers |= MOD_MASK_CTRL; | |
1040 } | |
1041 } | |
1042 | |
1043 return (*pch != NUL); | |
1044 } | |
1045 | |
1046 #ifdef _MSC_VER | |
1047 # pragma optimize("", on) | |
1048 #endif | |
1049 | |
1050 #endif /* FEAT_GUI_W32 */ | |
1051 | |
1052 | |
1053 #ifdef FEAT_MOUSE | |
1054 | |
1055 /* | |
1056 * For the GUI the mouse handling is in gui_w32.c. | |
1057 */ | |
1058 # ifdef FEAT_GUI_W32 | |
1059 void | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
1060 mch_setmouse(int on UNUSED) |
7 | 1061 { |
1062 } | |
1063 # else | |
1064 static int g_fMouseAvail = FALSE; /* mouse present */ | |
1065 static int g_fMouseActive = FALSE; /* mouse enabled */ | |
1066 static int g_nMouseClick = -1; /* mouse status */ | |
1067 static int g_xMouse; /* mouse x coordinate */ | |
1068 static int g_yMouse; /* mouse y coordinate */ | |
1069 | |
1070 /* | |
1071 * Enable or disable mouse input | |
1072 */ | |
1073 void | |
26 | 1074 mch_setmouse(int on) |
7 | 1075 { |
1076 DWORD cmodein; | |
1077 | |
1078 if (!g_fMouseAvail) | |
1079 return; | |
1080 | |
1081 g_fMouseActive = on; | |
1082 GetConsoleMode(g_hConIn, &cmodein); | |
1083 | |
1084 if (g_fMouseActive) | |
1085 cmodein |= ENABLE_MOUSE_INPUT; | |
1086 else | |
1087 cmodein &= ~ENABLE_MOUSE_INPUT; | |
1088 | |
1089 SetConsoleMode(g_hConIn, cmodein); | |
1090 } | |
1091 | |
1092 /* | |
1093 * Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT, | |
1094 * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse | |
1095 * move with a button held down; and MOUSE_RELEASE after a MOUSE_DRAG | |
1096 * or a MOUSE_LEFT, _MIDDLE, or _RIGHT. We encode the button type, | |
1097 * the number of clicks, and the Shift/Ctrl/Alt modifiers in g_nMouseClick, | |
1098 * and we return the mouse position in g_xMouse and g_yMouse. | |
1099 * | |
1100 * Every MOUSE_LEFT, _MIDDLE, or _RIGHT will be followed by zero or more | |
1101 * MOUSE_DRAGs and one MOUSE_RELEASE. MOUSE_RELEASE will be followed only | |
1102 * by MOUSE_LEFT, _MIDDLE, or _RIGHT. | |
1103 * | |
1104 * For multiple clicks, we send, say, MOUSE_LEFT/1 click, MOUSE_RELEASE, | |
1105 * MOUSE_LEFT/2 clicks, MOUSE_RELEASE, MOUSE_LEFT/3 clicks, MOUSE_RELEASE, .... | |
1106 * | |
1107 * Windows will send us MOUSE_MOVED notifications whenever the mouse | |
1108 * moves, even if it stays within the same character cell. We ignore | |
1109 * all MOUSE_MOVED messages if the position hasn't really changed, and | |
1110 * we ignore all MOUSE_MOVED messages where no button is held down (i.e., | |
1111 * we're only interested in MOUSE_DRAG). | |
1112 * | |
1113 * All of this is complicated by the code that fakes MOUSE_MIDDLE on | |
1114 * 2-button mouses by pressing the left & right buttons simultaneously. | |
1115 * In practice, it's almost impossible to click both at the same time, | |
1116 * so we need to delay a little. Also, we tend not to get MOUSE_RELEASE | |
1117 * in such cases, if the user is clicking quickly. | |
1118 */ | |
1119 static BOOL | |
1120 decode_mouse_event( | |
26 | 1121 MOUSE_EVENT_RECORD *pmer) |
7 | 1122 { |
1123 static int s_nOldButton = -1; | |
1124 static int s_nOldMouseClick = -1; | |
1125 static int s_xOldMouse = -1; | |
1126 static int s_yOldMouse = -1; | |
1127 static linenr_T s_old_topline = 0; | |
1128 #ifdef FEAT_DIFF | |
1129 static int s_old_topfill = 0; | |
1130 #endif | |
1131 static int s_cClicks = 1; | |
1132 static BOOL s_fReleased = TRUE; | |
1133 static DWORD s_dwLastClickTime = 0; | |
1134 static BOOL s_fNextIsMiddle = FALSE; | |
1135 | |
1136 static DWORD cButtons = 0; /* number of buttons supported */ | |
1137 | |
1138 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; | |
1139 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; | |
1140 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED; | |
1141 const DWORD LEFT_RIGHT = LEFT | RIGHT; | |
1142 | |
1143 int nButton; | |
1144 | |
1145 if (cButtons == 0 && !GetNumberOfConsoleMouseButtons(&cButtons)) | |
1146 cButtons = 2; | |
1147 | |
1148 if (!g_fMouseAvail || !g_fMouseActive) | |
1149 { | |
1150 g_nMouseClick = -1; | |
1151 return FALSE; | |
1152 } | |
1153 | |
1154 /* get a spurious MOUSE_EVENT immediately after receiving focus; ignore */ | |
1155 if (g_fJustGotFocus) | |
1156 { | |
1157 g_fJustGotFocus = FALSE; | |
1158 return FALSE; | |
1159 } | |
1160 | |
1161 /* unprocessed mouse click? */ | |
1162 if (g_nMouseClick != -1) | |
1163 return TRUE; | |
1164 | |
1165 nButton = -1; | |
1166 g_xMouse = pmer->dwMousePosition.X; | |
1167 g_yMouse = pmer->dwMousePosition.Y; | |
1168 | |
1169 if (pmer->dwEventFlags == MOUSE_MOVED) | |
1170 { | |
1171 /* ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these | |
1172 * events even when the mouse moves only within a char cell.) */ | |
1173 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) | |
1174 return FALSE; | |
1175 } | |
1176 | |
1177 /* If no buttons are pressed... */ | |
1178 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) | |
1179 { | |
1180 /* If the last thing returned was MOUSE_RELEASE, ignore this */ | |
1181 if (s_fReleased) | |
1182 return FALSE; | |
1183 | |
1184 nButton = MOUSE_RELEASE; | |
1185 s_fReleased = TRUE; | |
1186 } | |
1187 else /* one or more buttons pressed */ | |
1188 { | |
1189 /* on a 2-button mouse, hold down left and right buttons | |
1190 * simultaneously to get MIDDLE. */ | |
1191 | |
1192 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) | |
1193 { | |
1194 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); | |
1195 | |
1196 /* if either left or right button only is pressed, see if the | |
4352 | 1197 * next mouse event has both of them pressed */ |
7 | 1198 if (dwLR == LEFT || dwLR == RIGHT) |
1199 { | |
1200 for (;;) | |
1201 { | |
1202 /* wait a short time for next input event */ | |
1203 if (WaitForSingleObject(g_hConIn, p_mouset / 3) | |
1204 != WAIT_OBJECT_0) | |
1205 break; | |
1206 else | |
1207 { | |
1208 DWORD cRecords = 0; | |
1209 INPUT_RECORD ir; | |
1210 MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent; | |
1211 | |
5580 | 1212 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1213 |
1214 if (cRecords == 0 || ir.EventType != MOUSE_EVENT | |
1215 || !(pmer2->dwButtonState & LEFT_RIGHT)) | |
1216 break; | |
1217 else | |
1218 { | |
1219 if (pmer2->dwEventFlags != MOUSE_MOVED) | |
1220 { | |
5580 | 1221 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1222 |
1223 return decode_mouse_event(pmer2); | |
1224 } | |
1225 else if (s_xOldMouse == pmer2->dwMousePosition.X && | |
1226 s_yOldMouse == pmer2->dwMousePosition.Y) | |
1227 { | |
1228 /* throw away spurious mouse move */ | |
5580 | 1229 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1230 |
1231 /* are there any more mouse events in queue? */ | |
5580 | 1232 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1233 |
1234 if (cRecords==0 || ir.EventType != MOUSE_EVENT) | |
1235 break; | |
1236 } | |
1237 else | |
1238 break; | |
1239 } | |
1240 } | |
1241 } | |
1242 } | |
1243 } | |
1244 | |
1245 if (s_fNextIsMiddle) | |
1246 { | |
1247 nButton = (pmer->dwEventFlags == MOUSE_MOVED) | |
1248 ? MOUSE_DRAG : MOUSE_MIDDLE; | |
1249 s_fNextIsMiddle = FALSE; | |
1250 } | |
1251 else if (cButtons == 2 && | |
1252 ((pmer->dwButtonState & LEFT_RIGHT) == LEFT_RIGHT)) | |
1253 { | |
1254 nButton = MOUSE_MIDDLE; | |
1255 | |
1256 if (! s_fReleased && pmer->dwEventFlags != MOUSE_MOVED) | |
1257 { | |
1258 s_fNextIsMiddle = TRUE; | |
1259 nButton = MOUSE_RELEASE; | |
1260 } | |
1261 } | |
1262 else if ((pmer->dwButtonState & LEFT) == LEFT) | |
1263 nButton = MOUSE_LEFT; | |
1264 else if ((pmer->dwButtonState & MIDDLE) == MIDDLE) | |
1265 nButton = MOUSE_MIDDLE; | |
1266 else if ((pmer->dwButtonState & RIGHT) == RIGHT) | |
1267 nButton = MOUSE_RIGHT; | |
1268 | |
1269 if (! s_fReleased && ! s_fNextIsMiddle | |
1270 && nButton != s_nOldButton && s_nOldButton != MOUSE_DRAG) | |
1271 return FALSE; | |
1272 | |
1273 s_fReleased = s_fNextIsMiddle; | |
1274 } | |
1275 | |
1276 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) | |
1277 { | |
1278 /* button pressed or released, without mouse moving */ | |
1279 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1280 { | |
1281 DWORD dwCurrentTime = GetTickCount(); | |
1282 | |
1283 if (s_xOldMouse != g_xMouse | |
1284 || s_yOldMouse != g_yMouse | |
1285 || s_nOldButton != nButton | |
1286 || s_old_topline != curwin->w_topline | |
1287 #ifdef FEAT_DIFF | |
1288 || s_old_topfill != curwin->w_topfill | |
1289 #endif | |
1290 || (int)(dwCurrentTime - s_dwLastClickTime) > p_mouset) | |
1291 { | |
1292 s_cClicks = 1; | |
1293 } | |
1294 else if (++s_cClicks > 4) | |
1295 { | |
1296 s_cClicks = 1; | |
1297 } | |
1298 | |
1299 s_dwLastClickTime = dwCurrentTime; | |
1300 } | |
1301 } | |
1302 else if (pmer->dwEventFlags == MOUSE_MOVED) | |
1303 { | |
1304 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1305 nButton = MOUSE_DRAG; | |
1306 | |
1307 s_cClicks = 1; | |
1308 } | |
1309 | |
1310 if (nButton == -1) | |
1311 return FALSE; | |
1312 | |
1313 if (nButton != MOUSE_RELEASE) | |
1314 s_nOldButton = nButton; | |
1315 | |
1316 g_nMouseClick = nButton; | |
1317 | |
1318 if (pmer->dwControlKeyState & SHIFT_PRESSED) | |
1319 g_nMouseClick |= MOUSE_SHIFT; | |
1320 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) | |
1321 g_nMouseClick |= MOUSE_CTRL; | |
1322 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) | |
1323 g_nMouseClick |= MOUSE_ALT; | |
1324 | |
1325 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) | |
1326 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); | |
1327 | |
1328 /* only pass on interesting (i.e., different) mouse events */ | |
1329 if (s_xOldMouse == g_xMouse | |
1330 && s_yOldMouse == g_yMouse | |
1331 && s_nOldMouseClick == g_nMouseClick) | |
1332 { | |
1333 g_nMouseClick = -1; | |
1334 return FALSE; | |
1335 } | |
1336 | |
1337 s_xOldMouse = g_xMouse; | |
1338 s_yOldMouse = g_yMouse; | |
1339 s_old_topline = curwin->w_topline; | |
1340 #ifdef FEAT_DIFF | |
1341 s_old_topfill = curwin->w_topfill; | |
1342 #endif | |
1343 s_nOldMouseClick = g_nMouseClick; | |
1344 | |
1345 return TRUE; | |
1346 } | |
1347 | |
1348 # endif /* FEAT_GUI_W32 */ | |
1349 #endif /* FEAT_MOUSE */ | |
1350 | |
1351 | |
1352 #ifdef MCH_CURSOR_SHAPE | |
1353 /* | |
1354 * Set the shape of the cursor. | |
1355 * 'thickness' can be from 1 (thin) to 99 (block) | |
1356 */ | |
1357 static void | |
1358 mch_set_cursor_shape(int thickness) | |
1359 { | |
1360 CONSOLE_CURSOR_INFO ConsoleCursorInfo; | |
1361 ConsoleCursorInfo.dwSize = thickness; | |
1362 ConsoleCursorInfo.bVisible = s_cursor_visible; | |
1363 | |
1364 SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo); | |
1365 if (s_cursor_visible) | |
1366 SetConsoleCursorPosition(g_hConOut, g_coord); | |
1367 } | |
1368 | |
1369 void | |
1370 mch_update_cursor(void) | |
1371 { | |
1372 int idx; | |
1373 int thickness; | |
1374 | |
1375 /* | |
1376 * How the cursor is drawn depends on the current mode. | |
1377 */ | |
1378 idx = get_shape_idx(FALSE); | |
1379 | |
1380 if (shape_table[idx].shape == SHAPE_BLOCK) | |
1381 thickness = 99; /* 100 doesn't work on W95 */ | |
1382 else | |
1383 thickness = shape_table[idx].percentage; | |
1384 mch_set_cursor_shape(thickness); | |
1385 } | |
1386 #endif | |
1387 | |
1388 #ifndef FEAT_GUI_W32 /* this isn't used for the GUI */ | |
1389 /* | |
1390 * Handle FOCUS_EVENT. | |
1391 */ | |
1392 static void | |
1393 handle_focus_event(INPUT_RECORD ir) | |
1394 { | |
1395 g_fJustGotFocus = ir.Event.FocusEvent.bSetFocus; | |
1396 ui_focus_change((int)g_fJustGotFocus); | |
1397 } | |
1398 | |
1399 /* | |
1400 * Wait until console input from keyboard or mouse is available, | |
1401 * or the time is up. | |
1402 * Return TRUE if something is available FALSE if not. | |
1403 */ | |
1404 static int | |
1405 WaitForChar(long msec) | |
1406 { | |
1407 DWORD dwNow = 0, dwEndTime = 0; | |
1408 INPUT_RECORD ir; | |
1409 DWORD cRecords; | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1410 WCHAR ch, ch2; |
8949
c44ab784f5e5
commit https://github.com/vim/vim/commit/4445f7ee708f1a1304526a5979c9dd9883a92a0a
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
1411 #ifdef FEAT_TIMERS |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1412 int tb_change_cnt = typebuf.tb_change_cnt; |
8949
c44ab784f5e5
commit https://github.com/vim/vim/commit/4445f7ee708f1a1304526a5979c9dd9883a92a0a
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
1413 #endif |
7 | 1414 |
1415 if (msec > 0) | |
1416 /* Wait until the specified time has elapsed. */ | |
1417 dwEndTime = GetTickCount() + msec; | |
1418 else if (msec < 0) | |
1419 /* Wait forever. */ | |
1420 dwEndTime = INFINITE; | |
1421 | |
1422 /* We need to loop until the end of the time period, because | |
1423 * we might get multiple unusable mouse events in that time. | |
1424 */ | |
1425 for (;;) | |
1426 { | |
7866
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1427 #ifdef MESSAGE_QUEUE |
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1428 parse_queued_messages(); |
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1429 #endif |
14 | 1430 #ifdef FEAT_MZSCHEME |
1431 mzvim_check_threads(); | |
1432 #endif | |
7 | 1433 #ifdef FEAT_CLIENTSERVER |
1434 serverProcessPendingMessages(); | |
1435 #endif | |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1436 |
7 | 1437 if (0 |
1438 #ifdef FEAT_MOUSE | |
1439 || g_nMouseClick != -1 | |
1440 #endif | |
1441 #ifdef FEAT_CLIENTSERVER | |
1442 || input_available() | |
1443 #endif | |
1444 ) | |
1445 return TRUE; | |
1446 | |
1447 if (msec > 0) | |
1448 { | |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1449 /* If the specified wait time has passed, return. Beware that |
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1450 * GetTickCount() may wrap around (overflow). */ |
7 | 1451 dwNow = GetTickCount(); |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1452 if ((int)(dwNow - dwEndTime) >= 0) |
7 | 1453 break; |
1454 } | |
1455 if (msec != 0) | |
1456 { | |
14 | 1457 DWORD dwWaitTime = dwEndTime - dwNow; |
1458 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
1459 #ifdef FEAT_JOB_CHANNEL |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1460 /* Check channel while waiting for input. */ |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1461 if (dwWaitTime > 100) |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1462 { |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1463 dwWaitTime = 100; |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1464 /* If there is readahead then parse_queued_messages() timed out |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1465 * and we should call it again soon. */ |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1466 if (channel_any_readahead()) |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1467 dwWaitTime = 10; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1468 } |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1469 #endif |
11014
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1470 #ifdef FEAT_BEVAL |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1471 if (p_beval && dwWaitTime > 100) |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1472 /* The 'balloonexpr' may indirectly invoke a callback while |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1473 * waiting for a character, need to check often. */ |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1474 dwWaitTime = 100; |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1475 #endif |
14 | 1476 #ifdef FEAT_MZSCHEME |
1477 if (mzthreads_allowed() && p_mzq > 0 | |
1478 && (msec < 0 || (long)dwWaitTime > p_mzq)) | |
1479 dwWaitTime = p_mzq; /* don't wait longer than 'mzquantum' */ | |
1480 #endif | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1481 #ifdef FEAT_TIMERS |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1482 { |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1483 long due_time; |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1484 |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1485 /* When waiting very briefly don't trigger timers. */ |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1486 if (dwWaitTime > 10) |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1487 { |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1488 /* Trigger timers and then get the time in msec until the |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1489 * next one is due. Wait up to that time. */ |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1490 due_time = check_due_timer(); |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1491 if (typebuf.tb_change_cnt != tb_change_cnt) |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1492 { |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1493 /* timer may have used feedkeys() */ |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1494 return FALSE; |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1495 } |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1496 if (due_time > 0 && dwWaitTime > (DWORD)due_time) |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1497 dwWaitTime = due_time; |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1498 } |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1499 } |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1500 #endif |
7 | 1501 #ifdef FEAT_CLIENTSERVER |
1502 /* Wait for either an event on the console input or a message in | |
1503 * the client-server window. */ | |
6981 | 1504 if (msg_wait_for_multiple_objects(1, &g_hConIn, FALSE, |
14 | 1505 dwWaitTime, QS_SENDMESSAGE) != WAIT_OBJECT_0) |
7 | 1506 #else |
6981 | 1507 if (wait_for_single_object(g_hConIn, dwWaitTime) != WAIT_OBJECT_0) |
7 | 1508 #endif |
1509 continue; | |
1510 } | |
1511 | |
1512 cRecords = 0; | |
5580 | 1513 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1514 |
1515 #ifdef FEAT_MBYTE_IME | |
1516 if (State & CMDLINE && msg_row == Rows - 1) | |
1517 { | |
1518 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
1519 | |
1520 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
1521 { | |
1522 if (csbi.dwCursorPosition.Y != msg_row) | |
1523 { | |
1524 /* The screen is now messed up, must redraw the | |
1525 * command line and later all the windows. */ | |
1526 redraw_all_later(CLEAR); | |
1527 cmdline_row -= (msg_row - csbi.dwCursorPosition.Y); | |
1528 redrawcmd(); | |
1529 } | |
1530 } | |
1531 } | |
1532 #endif | |
1533 | |
1534 if (cRecords > 0) | |
1535 { | |
1536 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) | |
1537 { | |
1538 #ifdef FEAT_MBYTE_IME | |
1539 /* Windows IME sends two '\n's with only one 'ENTER'. First: | |
1540 * wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1541 if (ir.Event.KeyEvent.UChar == 0 |
7 | 1542 && ir.Event.KeyEvent.wVirtualKeyCode == 13) |
1543 { | |
5580 | 1544 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1545 continue; |
1546 } | |
1547 #endif | |
1548 if (decode_key_event(&ir.Event.KeyEvent, &ch, &ch2, | |
1549 NULL, FALSE)) | |
1550 return TRUE; | |
1551 } | |
1552 | |
5580 | 1553 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1554 |
1555 if (ir.EventType == FOCUS_EVENT) | |
1556 handle_focus_event(ir); | |
1557 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) | |
1558 shell_resized(); | |
1559 #ifdef FEAT_MOUSE | |
1560 else if (ir.EventType == MOUSE_EVENT | |
1561 && decode_mouse_event(&ir.Event.MouseEvent)) | |
1562 return TRUE; | |
1563 #endif | |
1564 } | |
1565 else if (msec == 0) | |
1566 break; | |
1567 } | |
1568 | |
1569 #ifdef FEAT_CLIENTSERVER | |
1570 /* Something might have been received while we were waiting. */ | |
1571 if (input_available()) | |
1572 return TRUE; | |
1573 #endif | |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1574 |
7 | 1575 return FALSE; |
1576 } | |
1577 | |
1578 #ifndef FEAT_GUI_MSWIN | |
1579 /* | |
1580 * return non-zero if a character is available | |
1581 */ | |
1582 int | |
26 | 1583 mch_char_avail(void) |
7 | 1584 { |
1585 return WaitForChar(0L); | |
1586 } | |
1587 #endif | |
1588 | |
1589 /* | |
1590 * Create the console input. Used when reading stdin doesn't work. | |
1591 */ | |
1592 static void | |
1593 create_conin(void) | |
1594 { | |
1595 g_hConIn = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE, | |
1596 FILE_SHARE_READ|FILE_SHARE_WRITE, | |
1597 (LPSECURITY_ATTRIBUTES) NULL, | |
840 | 1598 OPEN_EXISTING, 0, (HANDLE)NULL); |
7 | 1599 did_create_conin = TRUE; |
1600 } | |
1601 | |
1602 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1603 * Get a keystroke or a mouse event, use a blocking wait. |
7 | 1604 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1605 static WCHAR |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1606 tgetch(int *pmodifiers, WCHAR *pch2) |
7 | 1607 { |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1608 WCHAR ch; |
7 | 1609 |
1610 for (;;) | |
1611 { | |
1612 INPUT_RECORD ir; | |
1613 DWORD cRecords = 0; | |
1614 | |
1615 #ifdef FEAT_CLIENTSERVER | |
1616 (void)WaitForChar(-1L); | |
1617 if (input_available()) | |
1618 return 0; | |
1619 # ifdef FEAT_MOUSE | |
1620 if (g_nMouseClick != -1) | |
1621 return 0; | |
1622 # endif | |
1623 #endif | |
5580 | 1624 if (read_console_input(g_hConIn, &ir, 1, &cRecords) == 0) |
7 | 1625 { |
1626 if (did_create_conin) | |
1627 read_error_exit(); | |
1628 create_conin(); | |
1629 continue; | |
1630 } | |
1631 | |
1632 if (ir.EventType == KEY_EVENT) | |
1633 { | |
1634 if (decode_key_event(&ir.Event.KeyEvent, &ch, pch2, | |
1635 pmodifiers, TRUE)) | |
1636 return ch; | |
1637 } | |
1638 else if (ir.EventType == FOCUS_EVENT) | |
1639 handle_focus_event(ir); | |
1640 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) | |
1641 shell_resized(); | |
1642 #ifdef FEAT_MOUSE | |
1643 else if (ir.EventType == MOUSE_EVENT) | |
1644 { | |
1645 if (decode_mouse_event(&ir.Event.MouseEvent)) | |
1646 return 0; | |
1647 } | |
1648 #endif | |
1649 } | |
1650 } | |
1651 #endif /* !FEAT_GUI_W32 */ | |
1652 | |
1653 | |
1654 /* | |
3622 | 1655 * mch_inchar(): low-level input function. |
7 | 1656 * Get one or more characters from the keyboard or the mouse. |
1657 * If time == 0, do not wait for characters. | |
1658 * If time == n, wait a short time for characters. | |
1659 * If time == -1, wait forever for characters. | |
1660 * Returns the number of characters read into buf. | |
1661 */ | |
1662 int | |
1663 mch_inchar( | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
1664 char_u *buf UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
1665 int maxlen UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
1666 long time UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
1667 int tb_change_cnt UNUSED) |
7 | 1668 { |
1669 #ifndef FEAT_GUI_W32 /* this isn't used for the GUI */ | |
1670 | |
1671 int len; | |
1672 int c; | |
1673 #define TYPEAHEADLEN 20 | |
1674 static char_u typeahead[TYPEAHEADLEN]; /* previously typed bytes. */ | |
1675 static int typeaheadlen = 0; | |
1676 | |
1677 /* First use any typeahead that was kept because "buf" was too small. */ | |
1678 if (typeaheadlen > 0) | |
1679 goto theend; | |
1680 | |
1681 if (time >= 0) | |
1682 { | |
1683 if (!WaitForChar(time)) /* no character available */ | |
1684 return 0; | |
1685 } | |
1686 else /* time == -1, wait forever */ | |
1687 { | |
1688 mch_set_winsize_now(); /* Allow winsize changes from now on */ | |
1689 | |
203 | 1690 /* |
1691 * If there is no character available within 2 seconds (default) | |
1692 * write the autoscript file to disk. Or cause the CursorHold event | |
1693 * to be triggered. | |
1694 */ | |
1695 if (!WaitForChar(p_ut)) | |
7 | 1696 { |
1697 #ifdef FEAT_AUTOCMD | |
609 | 1698 if (trigger_cursorhold() && maxlen >= 3) |
7 | 1699 { |
203 | 1700 buf[0] = K_SPECIAL; |
1701 buf[1] = KS_EXTRA; | |
1702 buf[2] = (int)KE_CURSORHOLD; | |
1703 return 3; | |
7 | 1704 } |
1705 #endif | |
368 | 1706 before_blocking(); |
7 | 1707 } |
1708 } | |
1709 | |
1710 /* | |
1711 * Try to read as many characters as there are, until the buffer is full. | |
1712 */ | |
1713 | |
1714 /* we will get at least one key. Get more if they are available. */ | |
1715 g_fCBrkPressed = FALSE; | |
1716 | |
1717 #ifdef MCH_WRITE_DUMP | |
1718 if (fdDump) | |
1719 fputc('[', fdDump); | |
1720 #endif | |
1721 | |
1722 /* Keep looping until there is something in the typeahead buffer and more | |
1723 * to get and still room in the buffer (up to two bytes for a char and | |
1724 * three bytes for a modifier). */ | |
1725 while ((typeaheadlen == 0 || WaitForChar(0L)) | |
1726 && typeaheadlen + 5 <= TYPEAHEADLEN) | |
1727 { | |
1728 if (typebuf_changed(tb_change_cnt)) | |
1729 { | |
1730 /* "buf" may be invalid now if a client put something in the | |
1731 * typeahead buffer and "buf" is in the typeahead buffer. */ | |
1732 typeaheadlen = 0; | |
1733 break; | |
1734 } | |
1735 #ifdef FEAT_MOUSE | |
1736 if (g_nMouseClick != -1) | |
1737 { | |
1738 # ifdef MCH_WRITE_DUMP | |
1739 if (fdDump) | |
1740 fprintf(fdDump, "{%02x @ %d, %d}", | |
1741 g_nMouseClick, g_xMouse, g_yMouse); | |
1742 # endif | |
1743 typeahead[typeaheadlen++] = ESC + 128; | |
1744 typeahead[typeaheadlen++] = 'M'; | |
1745 typeahead[typeaheadlen++] = g_nMouseClick; | |
1746 typeahead[typeaheadlen++] = g_xMouse + '!'; | |
1747 typeahead[typeaheadlen++] = g_yMouse + '!'; | |
1748 g_nMouseClick = -1; | |
1749 } | |
1750 else | |
1751 #endif | |
1752 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1753 WCHAR ch2 = NUL; |
7 | 1754 int modifiers = 0; |
1755 | |
1756 c = tgetch(&modifiers, &ch2); | |
1757 | |
1758 if (typebuf_changed(tb_change_cnt)) | |
1759 { | |
1760 /* "buf" may be invalid now if a client put something in the | |
1761 * typeahead buffer and "buf" is in the typeahead buffer. */ | |
1762 typeaheadlen = 0; | |
1763 break; | |
1764 } | |
1765 | |
1766 if (c == Ctrl_C && ctrl_c_interrupts) | |
1767 { | |
1768 #if defined(FEAT_CLIENTSERVER) | |
1769 trash_input_buf(); | |
1770 #endif | |
1771 got_int = TRUE; | |
1772 } | |
1773 | |
1774 #ifdef FEAT_MOUSE | |
1775 if (g_nMouseClick == -1) | |
1776 #endif | |
1777 { | |
1778 int n = 1; | |
6047 | 1779 int conv = FALSE; |
1780 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1781 #ifdef FEAT_MBYTE |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1782 if (ch2 == NUL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1783 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1784 int i; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1785 char_u *p; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1786 WCHAR ch[2]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1787 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1788 ch[0] = c; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1789 if (c >= 0xD800 && c <= 0xDBFF) /* High surrogate */ |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1790 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1791 ch[1] = tgetch(&modifiers, &ch2); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1792 n++; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1793 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1794 p = utf16_to_enc(ch, &n); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1795 if (p != NULL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1796 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1797 for (i = 0; i < n; i++) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1798 typeahead[typeaheadlen + i] = p[i]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1799 vim_free(p); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1800 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1801 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1802 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1803 #endif |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1804 typeahead[typeaheadlen] = c; |
7 | 1805 if (ch2 != NUL) |
1806 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1807 typeahead[typeaheadlen + n] = 3; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1808 typeahead[typeaheadlen + n + 1] = (char_u)ch2; |
6047 | 1809 n += 2; |
7 | 1810 } |
1811 | |
6047 | 1812 if (conv) |
1813 { | |
1814 char_u *p = typeahead + typeaheadlen; | |
6524 | 1815 |
1816 if (*p != K_NUL) | |
6047 | 1817 { |
6524 | 1818 char_u *e = typeahead + TYPEAHEADLEN; |
1819 | |
1820 while (*p && p < e) | |
6047 | 1821 { |
6524 | 1822 if (*p == K_NUL) |
1823 { | |
1824 ++p; | |
1825 mch_memmove(p + 1, p, ((size_t)(e - p)) - 1); | |
1826 *p = 3; | |
1827 ++n; | |
1828 } | |
6047 | 1829 ++p; |
1830 } | |
1831 } | |
1832 } | |
1833 | |
7 | 1834 /* Use the ALT key to set the 8th bit of the character |
1835 * when it's one byte, the 8th bit isn't set yet and not | |
1836 * using a double-byte encoding (would become a lead | |
1837 * byte). */ | |
1838 if ((modifiers & MOD_MASK_ALT) | |
1839 && n == 1 | |
1840 && (typeahead[typeaheadlen] & 0x80) == 0 | |
1841 #ifdef FEAT_MBYTE | |
1842 && !enc_dbcs | |
1843 #endif | |
1844 ) | |
1845 { | |
1443 | 1846 #ifdef FEAT_MBYTE |
1847 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80, | |
1848 typeahead + typeaheadlen); | |
1849 #else | |
7 | 1850 typeahead[typeaheadlen] |= 0x80; |
1443 | 1851 #endif |
7 | 1852 modifiers &= ~MOD_MASK_ALT; |
1853 } | |
1854 | |
1855 if (modifiers != 0) | |
1856 { | |
1857 /* Prepend modifiers to the character. */ | |
1858 mch_memmove(typeahead + typeaheadlen + 3, | |
1859 typeahead + typeaheadlen, n); | |
1860 typeahead[typeaheadlen++] = K_SPECIAL; | |
1861 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER; | |
1862 typeahead[typeaheadlen++] = modifiers; | |
1863 } | |
1864 | |
1865 typeaheadlen += n; | |
1866 | |
1867 #ifdef MCH_WRITE_DUMP | |
1868 if (fdDump) | |
1869 fputc(c, fdDump); | |
1870 #endif | |
1871 } | |
1872 } | |
1873 } | |
1874 | |
1875 #ifdef MCH_WRITE_DUMP | |
1876 if (fdDump) | |
1877 { | |
1878 fputs("]\n", fdDump); | |
1879 fflush(fdDump); | |
1880 } | |
1881 #endif | |
1882 | |
1883 theend: | |
1884 /* Move typeahead to "buf", as much as fits. */ | |
1885 len = 0; | |
1886 while (len < maxlen && typeaheadlen > 0) | |
1887 { | |
1888 buf[len++] = typeahead[0]; | |
1889 mch_memmove(typeahead, typeahead + 1, --typeaheadlen); | |
1890 } | |
1891 return len; | |
1892 | |
1893 #else /* FEAT_GUI_W32 */ | |
1894 return 0; | |
1895 #endif /* FEAT_GUI_W32 */ | |
1896 } | |
1897 | |
3927 | 1898 #ifndef PROTO |
1899 # ifndef __MINGW32__ | |
1900 # include <shellapi.h> /* required for FindExecutable() */ | |
1901 # endif | |
7 | 1902 #endif |
1903 | |
9 | 1904 /* |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1905 * If "use_path" is TRUE: Return TRUE if "name" is in $PATH. |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1906 * If "use_path" is FALSE: Return TRUE if "name" exists. |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1907 * When returning TRUE and "path" is not NULL save the path and set "*path" to |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1908 * the allocated memory. |
10 | 1909 * TODO: Should somehow check if it's really executable. |
9 | 1910 */ |
7 | 1911 static int |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1912 executable_exists(char *name, char_u **path, int use_path) |
7 | 1913 { |
9 | 1914 char *dum; |
1915 char fname[_MAX_PATH]; | |
6185 | 1916 char *curpath, *newpath; |
1917 long n; | |
9 | 1918 |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1919 if (!use_path) |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1920 { |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1921 if (mch_getperm(name) != -1 && !mch_isdir(name)) |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1922 { |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1923 if (path != NULL) |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1924 *path = vim_strsave((char_u *)name); |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1925 return TRUE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1926 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1927 return FALSE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1928 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
1929 |
9 | 1930 #ifdef FEAT_MBYTE |
1931 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
7 | 1932 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
1933 WCHAR *p = enc_to_utf16((char_u *)name, NULL); |
9 | 1934 WCHAR fnamew[_MAX_PATH]; |
1935 WCHAR *dumw; | |
6185 | 1936 WCHAR *wcurpath, *wnewpath; |
9 | 1937 |
1938 if (p != NULL) | |
1939 { | |
6185 | 1940 wcurpath = _wgetenv(L"PATH"); |
1941 wnewpath = (WCHAR*)alloc((unsigned)(wcslen(wcurpath) + 3) | |
1942 * sizeof(WCHAR)); | |
1943 if (wnewpath == NULL) | |
1944 return FALSE; | |
1945 wcscpy(wnewpath, L".;"); | |
1946 wcscat(wnewpath, wcurpath); | |
1947 n = (long)SearchPathW(wnewpath, p, NULL, _MAX_PATH, fnamew, &dumw); | |
1948 vim_free(wnewpath); | |
9 | 1949 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1950 if (n == 0) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1951 return FALSE; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1952 if (GetFileAttributesW(fnamew) & FILE_ATTRIBUTE_DIRECTORY) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1953 return FALSE; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1954 if (path != NULL) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1955 *path = utf16_to_enc(fnamew, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1956 return TRUE; |
9 | 1957 } |
7 | 1958 } |
9 | 1959 #endif |
6185 | 1960 |
1961 curpath = getenv("PATH"); | |
1962 newpath = (char*)alloc((unsigned)(STRLEN(curpath) + 3)); | |
1963 if (newpath == NULL) | |
1964 return FALSE; | |
1965 STRCPY(newpath, ".;"); | |
1966 STRCAT(newpath, curpath); | |
1967 n = (long)SearchPath(newpath, name, NULL, _MAX_PATH, fname, &dum); | |
1968 vim_free(newpath); | |
1969 if (n == 0) | |
9 | 1970 return FALSE; |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
1971 if (mch_isdir((char_u *)fname)) |
9 | 1972 return FALSE; |
5782 | 1973 if (path != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
1974 *path = vim_strsave((char_u *)fname); |
9 | 1975 return TRUE; |
7 | 1976 } |
1977 | |
2584 | 1978 #if ((defined(__MINGW32__) || defined (__CYGWIN32__)) && \ |
2935 | 1979 __MSVCRT_VERSION__ >= 0x800) || (defined(_MSC_VER) && _MSC_VER >= 1400) |
2584 | 1980 /* |
1981 * Bad parameter handler. | |
1982 * | |
1983 * Certain MS CRT functions will intentionally crash when passed invalid | |
1984 * parameters to highlight possible security holes. Setting this function as | |
1985 * the bad parameter handler will prevent the crash. | |
1986 * | |
1987 * In debug builds the parameters contain CRT information that might help track | |
1988 * down the source of a problem, but in non-debug builds the arguments are all | |
1989 * NULL/0. Debug builds will also produce assert dialogs from the CRT, it is | |
1990 * worth allowing these to make debugging of issues easier. | |
1991 */ | |
1992 static void | |
1993 bad_param_handler(const wchar_t *expression, | |
1994 const wchar_t *function, | |
1995 const wchar_t *file, | |
1996 unsigned int line, | |
1997 uintptr_t pReserved) | |
1998 { | |
1999 } | |
2000 | |
2001 # define SET_INVALID_PARAM_HANDLER \ | |
2002 ((void)_set_invalid_parameter_handler(bad_param_handler)) | |
2003 #else | |
2004 # define SET_INVALID_PARAM_HANDLER | |
2005 #endif | |
2006 | |
7 | 2007 #ifdef FEAT_GUI_W32 |
2008 | |
2009 /* | |
2010 * GUI version of mch_init(). | |
2011 */ | |
2012 void | |
26 | 2013 mch_init(void) |
7 | 2014 { |
2015 #ifndef __MINGW32__ | |
2016 extern int _fmode; | |
2017 #endif | |
2018 | |
2584 | 2019 /* Silently handle invalid parameters to CRT functions */ |
2020 SET_INVALID_PARAM_HANDLER; | |
2021 | |
7 | 2022 /* Let critical errors result in a failure, not in a dialog box. Required |
2023 * for the timestamp test to work on removed floppies. */ | |
2024 SetErrorMode(SEM_FAILCRITICALERRORS); | |
2025 | |
2026 _fmode = O_BINARY; /* we do our own CR-LF translation */ | |
2027 | |
2028 /* Specify window size. Is there a place to get the default from? */ | |
2029 Rows = 25; | |
2030 Columns = 80; | |
2031 | |
2032 /* Look for 'vimrun' */ | |
2033 { | |
2034 char_u vimrun_location[_MAX_PATH + 4]; | |
2035 | |
2036 /* First try in same directory as gvim.exe */ | |
2037 STRCPY(vimrun_location, exe_name); | |
2038 STRCPY(gettail(vimrun_location), "vimrun.exe"); | |
2039 if (mch_getperm(vimrun_location) >= 0) | |
2040 { | |
2041 if (*skiptowhite(vimrun_location) != NUL) | |
2042 { | |
2043 /* Enclose path with white space in double quotes. */ | |
2044 mch_memmove(vimrun_location + 1, vimrun_location, | |
2045 STRLEN(vimrun_location) + 1); | |
2046 *vimrun_location = '"'; | |
2047 STRCPY(gettail(vimrun_location), "vimrun\" "); | |
2048 } | |
2049 else | |
2050 STRCPY(gettail(vimrun_location), "vimrun "); | |
2051 | |
2052 vimrun_path = (char *)vim_strsave(vimrun_location); | |
2053 s_dont_use_vimrun = FALSE; | |
2054 } | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2055 else if (executable_exists("vimrun.exe", NULL, TRUE)) |
7 | 2056 s_dont_use_vimrun = FALSE; |
2057 | |
2058 /* Don't give the warning for a missing vimrun.exe right now, but only | |
2059 * when vimrun was supposed to be used. Don't bother people that do | |
2060 * not need vimrun.exe. */ | |
2061 if (s_dont_use_vimrun) | |
2062 need_vimrun_warning = TRUE; | |
2063 } | |
2064 | |
2065 /* | |
2066 * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'. | |
2067 * Otherwise the default "findstr /n" is used. | |
2068 */ | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2069 if (!executable_exists("findstr.exe", NULL, TRUE)) |
7 | 2070 set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0); |
2071 | |
2072 #ifdef FEAT_CLIPBOARD | |
4168 | 2073 win_clip_init(); |
7 | 2074 #endif |
2075 } | |
2076 | |
2077 | |
2078 #else /* FEAT_GUI_W32 */ | |
2079 | |
2080 #define SRWIDTH(sr) ((sr).Right - (sr).Left + 1) | |
2081 #define SRHEIGHT(sr) ((sr).Bottom - (sr).Top + 1) | |
2082 | |
2083 /* | |
2084 * ClearConsoleBuffer() | |
2085 * Description: | |
2086 * Clears the entire contents of the console screen buffer, using the | |
2087 * specified attribute. | |
2088 * Returns: | |
2089 * TRUE on success | |
2090 */ | |
2091 static BOOL | |
2092 ClearConsoleBuffer(WORD wAttribute) | |
2093 { | |
2094 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2095 COORD coord; | |
2096 DWORD NumCells, dummy; | |
2097 | |
2098 if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2099 return FALSE; | |
2100 | |
2101 NumCells = csbi.dwSize.X * csbi.dwSize.Y; | |
2102 coord.X = 0; | |
2103 coord.Y = 0; | |
2104 if (!FillConsoleOutputCharacter(g_hConOut, ' ', NumCells, | |
2105 coord, &dummy)) | |
2106 { | |
2107 return FALSE; | |
2108 } | |
2109 if (!FillConsoleOutputAttribute(g_hConOut, wAttribute, NumCells, | |
2110 coord, &dummy)) | |
2111 { | |
2112 return FALSE; | |
2113 } | |
2114 | |
2115 return TRUE; | |
2116 } | |
2117 | |
2118 /* | |
2119 * FitConsoleWindow() | |
2120 * Description: | |
2121 * Checks if the console window will fit within given buffer dimensions. | |
2122 * Also, if requested, will shrink the window to fit. | |
2123 * Returns: | |
2124 * TRUE on success | |
2125 */ | |
2126 static BOOL | |
2127 FitConsoleWindow( | |
2128 COORD dwBufferSize, | |
2129 BOOL WantAdjust) | |
2130 { | |
2131 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2132 COORD dwWindowSize; | |
2133 BOOL NeedAdjust = FALSE; | |
2134 | |
2135 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2136 { | |
2137 /* | |
2138 * A buffer resize will fail if the current console window does | |
2139 * not lie completely within that buffer. To avoid this, we might | |
2140 * have to move and possibly shrink the window. | |
2141 */ | |
2142 if (csbi.srWindow.Right >= dwBufferSize.X) | |
2143 { | |
2144 dwWindowSize.X = SRWIDTH(csbi.srWindow); | |
2145 if (dwWindowSize.X > dwBufferSize.X) | |
2146 dwWindowSize.X = dwBufferSize.X; | |
2147 csbi.srWindow.Right = dwBufferSize.X - 1; | |
2148 csbi.srWindow.Left = dwBufferSize.X - dwWindowSize.X; | |
2149 NeedAdjust = TRUE; | |
2150 } | |
2151 if (csbi.srWindow.Bottom >= dwBufferSize.Y) | |
2152 { | |
2153 dwWindowSize.Y = SRHEIGHT(csbi.srWindow); | |
2154 if (dwWindowSize.Y > dwBufferSize.Y) | |
2155 dwWindowSize.Y = dwBufferSize.Y; | |
2156 csbi.srWindow.Bottom = dwBufferSize.Y - 1; | |
2157 csbi.srWindow.Top = dwBufferSize.Y - dwWindowSize.Y; | |
2158 NeedAdjust = TRUE; | |
2159 } | |
2160 if (NeedAdjust && WantAdjust) | |
2161 { | |
2162 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &csbi.srWindow)) | |
2163 return FALSE; | |
2164 } | |
2165 return TRUE; | |
2166 } | |
2167 | |
2168 return FALSE; | |
2169 } | |
2170 | |
2171 typedef struct ConsoleBufferStruct | |
2172 { | |
26 | 2173 BOOL IsValid; |
2174 CONSOLE_SCREEN_BUFFER_INFO Info; | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2175 PCHAR_INFO Buffer; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2176 COORD BufferSize; |
7 | 2177 } ConsoleBuffer; |
2178 | |
2179 /* | |
2180 * SaveConsoleBuffer() | |
2181 * Description: | |
2182 * Saves important information about the console buffer, including the | |
2183 * actual buffer contents. The saved information is suitable for later | |
2184 * restoration by RestoreConsoleBuffer(). | |
2185 * Returns: | |
2186 * TRUE if all information was saved; FALSE otherwise | |
2187 * If FALSE, still sets cb->IsValid if buffer characteristics were saved. | |
2188 */ | |
2189 static BOOL | |
2190 SaveConsoleBuffer( | |
2191 ConsoleBuffer *cb) | |
2192 { | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2193 DWORD NumCells; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2194 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2195 SMALL_RECT ReadRegion; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2196 WORD Y, Y_incr; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2197 |
7 | 2198 if (cb == NULL) |
2199 return FALSE; | |
2200 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2201 if (!GetConsoleScreenBufferInfo(g_hConOut, &cb->Info)) |
7 | 2202 { |
2203 cb->IsValid = FALSE; | |
2204 return FALSE; | |
2205 } | |
2206 cb->IsValid = TRUE; | |
2207 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2208 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2209 * Allocate a buffer large enough to hold the entire console screen |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2210 * buffer. If this ConsoleBuffer structure has already been initialized |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2211 * with a buffer of the correct size, then just use that one. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2212 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2213 if (!cb->IsValid || cb->Buffer == NULL || |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2214 cb->BufferSize.X != cb->Info.dwSize.X || |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2215 cb->BufferSize.Y != cb->Info.dwSize.Y) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2216 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2217 cb->BufferSize.X = cb->Info.dwSize.X; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2218 cb->BufferSize.Y = cb->Info.dwSize.Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2219 NumCells = cb->BufferSize.X * cb->BufferSize.Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2220 vim_free(cb->Buffer); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2221 cb->Buffer = (PCHAR_INFO)alloc(NumCells * sizeof(CHAR_INFO)); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2222 if (cb->Buffer == NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2223 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2224 } |
7 | 2225 |
2226 /* | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2227 * We will now copy the console screen buffer into our buffer. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2228 * ReadConsoleOutput() seems to be limited as far as how much you |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2229 * can read at a time. Empirically, this number seems to be about |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2230 * 12000 cells (rows * columns). Start at position (0, 0) and copy |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2231 * in chunks until it is all copied. The chunks will all have the |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2232 * same horizontal characteristics, so initialize them now. The |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2233 * height of each chunk will be (12000 / width). |
7 | 2234 */ |
7078
383d6f39669b
commit https://github.com/vim/vim/commit/615942452eb74eee7d8386fd3d76a1534181fa06
Christian Brabandt <cb@256bit.org>
parents:
6981
diff
changeset
|
2235 BufferCoord.X = 0; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2236 ReadRegion.Left = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2237 ReadRegion.Right = cb->Info.dwSize.X - 1; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2238 Y_incr = 12000 / cb->Info.dwSize.X; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2239 for (Y = 0; Y < cb->BufferSize.Y; Y += Y_incr) |
7 | 2240 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2241 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2242 * Read into position (0, Y) in our buffer. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2243 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2244 BufferCoord.Y = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2245 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2246 * Read the region whose top left corner is (0, Y) and whose bottom |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2247 * right corner is (width - 1, Y + Y_incr - 1). This should define |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2248 * a region of size width by Y_incr. Don't worry if this region is |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2249 * too large for the remaining buffer; it will be cropped. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2250 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2251 ReadRegion.Top = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2252 ReadRegion.Bottom = Y + Y_incr - 1; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2253 if (!ReadConsoleOutput(g_hConOut, /* output handle */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2254 cb->Buffer, /* our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2255 cb->BufferSize, /* dimensions of our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2256 BufferCoord, /* offset in our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2257 &ReadRegion)) /* region to save */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2258 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2259 vim_free(cb->Buffer); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2260 cb->Buffer = NULL; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2261 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2262 } |
7 | 2263 } |
2264 | |
2265 return TRUE; | |
2266 } | |
2267 | |
2268 /* | |
2269 * RestoreConsoleBuffer() | |
2270 * Description: | |
2271 * Restores important information about the console buffer, including the | |
2272 * actual buffer contents, if desired. The information to restore is in | |
2273 * the same format used by SaveConsoleBuffer(). | |
2274 * Returns: | |
2275 * TRUE on success | |
2276 */ | |
2277 static BOOL | |
2278 RestoreConsoleBuffer( | |
26 | 2279 ConsoleBuffer *cb, |
2280 BOOL RestoreScreen) | |
7 | 2281 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2282 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2283 SMALL_RECT WriteRegion; |
7 | 2284 |
2285 if (cb == NULL || !cb->IsValid) | |
2286 return FALSE; | |
2287 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2288 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2289 * Before restoring the buffer contents, clear the current buffer, and |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2290 * restore the cursor position and window information. Doing this now |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2291 * prevents old buffer contents from "flashing" onto the screen. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2292 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2293 if (RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2294 ClearConsoleBuffer(cb->Info.wAttributes); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2295 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2296 FitConsoleWindow(cb->Info.dwSize, TRUE); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2297 if (!SetConsoleScreenBufferSize(g_hConOut, cb->Info.dwSize)) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2298 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2299 if (!SetConsoleTextAttribute(g_hConOut, cb->Info.wAttributes)) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2300 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2301 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2302 if (!RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2303 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2304 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2305 * No need to restore the screen buffer contents, so we're done. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2306 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2307 return TRUE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2308 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2309 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2310 if (!SetConsoleCursorPosition(g_hConOut, cb->Info.dwCursorPosition)) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2311 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2312 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &cb->Info.srWindow)) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2313 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2314 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2315 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2316 * Restore the screen buffer contents. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2317 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2318 if (cb->Buffer != NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2319 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2320 BufferCoord.X = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2321 BufferCoord.Y = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2322 WriteRegion.Left = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2323 WriteRegion.Top = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2324 WriteRegion.Right = cb->Info.dwSize.X - 1; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2325 WriteRegion.Bottom = cb->Info.dwSize.Y - 1; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2326 if (!WriteConsoleOutput(g_hConOut, /* output handle */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2327 cb->Buffer, /* our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2328 cb->BufferSize, /* dimensions of our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2329 BufferCoord, /* offset in our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2330 &WriteRegion)) /* region to restore */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2331 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2332 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2333 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2334 } |
7 | 2335 |
2336 return TRUE; | |
2337 } | |
2338 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2339 #define FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2340 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2341 static ConsoleBuffer g_cbOrig = { 0 }; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2342 #endif |
7 | 2343 static ConsoleBuffer g_cbNonTermcap = { 0 }; |
2344 static ConsoleBuffer g_cbTermcap = { 0 }; | |
2345 | |
2346 #ifdef FEAT_TITLE | |
2347 #ifdef __BORLANDC__ | |
2348 typedef HWND (__stdcall *GETCONSOLEWINDOWPROC)(VOID); | |
2349 #else | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2350 typedef HWND (WINAPI *GETCONSOLEWINDOWPROC)(VOID); |
7 | 2351 #endif |
2352 char g_szOrigTitle[256] = { 0 }; | |
2353 HWND g_hWnd = NULL; /* also used in os_mswin.c */ | |
2354 static HICON g_hOrigIconSmall = NULL; | |
2355 static HICON g_hOrigIcon = NULL; | |
2356 static HICON g_hVimIcon = NULL; | |
2357 static BOOL g_fCanChangeIcon = FALSE; | |
2358 | |
2359 /* ICON* are not defined in VC++ 4.0 */ | |
2360 #ifndef ICON_SMALL | |
2361 #define ICON_SMALL 0 | |
2362 #endif | |
2363 #ifndef ICON_BIG | |
2364 #define ICON_BIG 1 | |
2365 #endif | |
2366 /* | |
2367 * GetConsoleIcon() | |
2368 * Description: | |
2369 * Attempts to retrieve the small icon and/or the big icon currently in | |
2370 * use by a given window. | |
2371 * Returns: | |
2372 * TRUE on success | |
2373 */ | |
2374 static BOOL | |
2375 GetConsoleIcon( | |
26 | 2376 HWND hWnd, |
2377 HICON *phIconSmall, | |
2378 HICON *phIcon) | |
7 | 2379 { |
2380 if (hWnd == NULL) | |
2381 return FALSE; | |
2382 | |
2383 if (phIconSmall != NULL) | |
26 | 2384 *phIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, |
2385 (WPARAM)ICON_SMALL, (LPARAM)0); | |
7 | 2386 if (phIcon != NULL) |
26 | 2387 *phIcon = (HICON)SendMessage(hWnd, WM_GETICON, |
2388 (WPARAM)ICON_BIG, (LPARAM)0); | |
7 | 2389 return TRUE; |
2390 } | |
2391 | |
2392 /* | |
2393 * SetConsoleIcon() | |
2394 * Description: | |
2395 * Attempts to change the small icon and/or the big icon currently in | |
2396 * use by a given window. | |
2397 * Returns: | |
2398 * TRUE on success | |
2399 */ | |
2400 static BOOL | |
2401 SetConsoleIcon( | |
26 | 2402 HWND hWnd, |
2403 HICON hIconSmall, | |
2404 HICON hIcon) | |
7 | 2405 { |
2406 if (hWnd == NULL) | |
2407 return FALSE; | |
2408 | |
2409 if (hIconSmall != NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2410 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2411 (WPARAM)ICON_SMALL, (LPARAM)hIconSmall); |
7 | 2412 if (hIcon != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2413 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2414 (WPARAM)ICON_BIG, (LPARAM) hIcon); |
7 | 2415 return TRUE; |
2416 } | |
2417 | |
2418 /* | |
2419 * SaveConsoleTitleAndIcon() | |
2420 * Description: | |
2421 * Saves the current console window title in g_szOrigTitle, for later | |
2422 * restoration. Also, attempts to obtain a handle to the console window, | |
2423 * and use it to save the small and big icons currently in use by the | |
2424 * console window. This is not always possible on some versions of Windows; | |
2425 * nor is it possible when running Vim remotely using Telnet (since the | |
2426 * console window the user sees is owned by a remote process). | |
2427 */ | |
2428 static void | |
2429 SaveConsoleTitleAndIcon(void) | |
2430 { | |
2431 /* Save the original title. */ | |
2432 if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle))) | |
2433 return; | |
2434 | |
2435 /* | |
2436 * Obtain a handle to the console window using GetConsoleWindow() from | |
2437 * KERNEL32.DLL; we need to handle in order to change the window icon. | |
2438 * This function only exists on NT-based Windows, starting with Windows | |
2439 * 2000. On older operating systems, we can't change the window icon | |
2440 * anyway. | |
2441 */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2442 g_hWnd = GetConsoleWindow(); |
7 | 2443 if (g_hWnd == NULL) |
2444 return; | |
2445 | |
2446 /* Save the original console window icon. */ | |
2447 GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon); | |
2448 if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL) | |
2449 return; | |
2450 | |
2451 /* Extract the first icon contained in the Vim executable. */ | |
6249 | 2452 if (mch_icon_load((HANDLE *)&g_hVimIcon) == FAIL || g_hVimIcon == NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2453 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); |
7 | 2454 if (g_hVimIcon != NULL) |
2455 g_fCanChangeIcon = TRUE; | |
2456 } | |
2457 #endif | |
2458 | |
2459 static int g_fWindInitCalled = FALSE; | |
2460 static int g_fTermcapMode = FALSE; | |
2461 static CONSOLE_CURSOR_INFO g_cci; | |
2462 static DWORD g_cmodein = 0; | |
2463 static DWORD g_cmodeout = 0; | |
2464 | |
2465 /* | |
2466 * non-GUI version of mch_init(). | |
2467 */ | |
2468 void | |
26 | 2469 mch_init(void) |
7 | 2470 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2471 #ifndef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2472 CONSOLE_SCREEN_BUFFER_INFO csbi; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2473 #endif |
7 | 2474 #ifndef __MINGW32__ |
2475 extern int _fmode; | |
2476 #endif | |
2477 | |
2584 | 2478 /* Silently handle invalid parameters to CRT functions */ |
2479 SET_INVALID_PARAM_HANDLER; | |
2480 | |
7 | 2481 /* Let critical errors result in a failure, not in a dialog box. Required |
2482 * for the timestamp test to work on removed floppies. */ | |
2483 SetErrorMode(SEM_FAILCRITICALERRORS); | |
2484 | |
2485 _fmode = O_BINARY; /* we do our own CR-LF translation */ | |
2486 out_flush(); | |
2487 | |
2488 /* Obtain handles for the standard Console I/O devices */ | |
2489 if (read_cmd_fd == 0) | |
2490 g_hConIn = GetStdHandle(STD_INPUT_HANDLE); | |
2491 else | |
2492 create_conin(); | |
2493 g_hConOut = GetStdHandle(STD_OUTPUT_HANDLE); | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2494 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2495 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2496 /* Save the initial console buffer for later restoration */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2497 SaveConsoleBuffer(&g_cbOrig); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2498 g_attrCurrent = g_attrDefault = g_cbOrig.Info.wAttributes; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2499 #else |
7 | 2500 /* Get current text attributes */ |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2501 GetConsoleScreenBufferInfo(g_hConOut, &csbi); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2502 g_attrCurrent = g_attrDefault = csbi.wAttributes; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2503 #endif |
7 | 2504 if (cterm_normal_fg_color == 0) |
2505 cterm_normal_fg_color = (g_attrCurrent & 0xf) + 1; | |
2506 if (cterm_normal_bg_color == 0) | |
2507 cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1; | |
2508 | |
2509 /* set termcap codes to current text attributes */ | |
2510 update_tcap(g_attrCurrent); | |
2511 | |
2512 GetConsoleCursorInfo(g_hConOut, &g_cci); | |
2513 GetConsoleMode(g_hConIn, &g_cmodein); | |
2514 GetConsoleMode(g_hConOut, &g_cmodeout); | |
2515 | |
2516 #ifdef FEAT_TITLE | |
2517 SaveConsoleTitleAndIcon(); | |
2518 /* | |
2519 * Set both the small and big icons of the console window to Vim's icon. | |
2520 * Note that Vim presently only has one size of icon (32x32), but it | |
2521 * automatically gets scaled down to 16x16 when setting the small icon. | |
2522 */ | |
2523 if (g_fCanChangeIcon) | |
2524 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); | |
2525 #endif | |
2526 | |
2527 ui_get_shellsize(); | |
2528 | |
2529 #ifdef MCH_WRITE_DUMP | |
2530 fdDump = fopen("dump", "wt"); | |
2531 | |
2532 if (fdDump) | |
2533 { | |
2534 time_t t; | |
2535 | |
2536 time(&t); | |
2537 fputs(ctime(&t), fdDump); | |
2538 fflush(fdDump); | |
2539 } | |
2540 #endif | |
2541 | |
2542 g_fWindInitCalled = TRUE; | |
2543 | |
2544 #ifdef FEAT_MOUSE | |
2545 g_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); | |
2546 #endif | |
2547 | |
2548 #ifdef FEAT_CLIPBOARD | |
4168 | 2549 win_clip_init(); |
7 | 2550 #endif |
2551 } | |
2552 | |
2553 /* | |
2554 * non-GUI version of mch_exit(). | |
2555 * Shut down and exit with status `r' | |
2556 * Careful: mch_exit() may be called before mch_init()! | |
2557 */ | |
2558 void | |
2559 mch_exit(int r) | |
2560 { | |
10835
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
2561 exiting = TRUE; |
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
2562 |
7 | 2563 stoptermcap(); |
2564 if (g_fWindInitCalled) | |
2565 settmode(TMODE_COOK); | |
2566 | |
2567 ml_close_all(TRUE); /* remove all memfiles */ | |
2568 | |
2569 if (g_fWindInitCalled) | |
2570 { | |
2571 #ifdef FEAT_TITLE | |
2572 mch_restore_title(3); | |
2573 /* | |
2574 * Restore both the small and big icons of the console window to | |
2575 * what they were at startup. Don't do this when the window is | |
2576 * closed, Vim would hang here. | |
2577 */ | |
2578 if (g_fCanChangeIcon && !g_fForceExit) | |
2579 SetConsoleIcon(g_hWnd, g_hOrigIconSmall, g_hOrigIcon); | |
2580 #endif | |
2581 | |
2582 #ifdef MCH_WRITE_DUMP | |
2583 if (fdDump) | |
2584 { | |
2585 time_t t; | |
2586 | |
2587 time(&t); | |
2588 fputs(ctime(&t), fdDump); | |
2589 fclose(fdDump); | |
2590 } | |
2591 fdDump = NULL; | |
2592 #endif | |
2593 } | |
2594 | |
2595 SetConsoleCursorInfo(g_hConOut, &g_cci); | |
2596 SetConsoleMode(g_hConIn, g_cmodein); | |
2597 SetConsoleMode(g_hConOut, g_cmodeout); | |
2598 | |
2599 #ifdef DYNAMIC_GETTEXT | |
2600 dyn_libintl_end(); | |
2601 #endif | |
2602 | |
2603 exit(r); | |
2604 } | |
2605 #endif /* !FEAT_GUI_W32 */ | |
2606 | |
2607 /* | |
2608 * Do we have an interactive window? | |
2609 */ | |
2610 int | |
2611 mch_check_win( | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
2612 int argc UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
2613 char **argv UNUSED) |
7 | 2614 { |
2615 get_exe_name(); | |
2616 | |
2617 #ifdef FEAT_GUI_W32 | |
2618 return OK; /* GUI always has a tty */ | |
2619 #else | |
2620 if (isatty(1)) | |
2621 return OK; | |
2622 return FAIL; | |
2623 #endif | |
2624 } | |
2625 | |
2626 | |
5326 | 2627 #ifdef FEAT_MBYTE |
2628 /* | |
2629 * fname_casew(): Wide version of fname_case(). Set the case of the file name, | |
2630 * if it already exists. When "len" is > 0, also expand short to long | |
2631 * filenames. | |
2632 * Return FAIL if wide functions are not available, OK otherwise. | |
2633 * NOTE: much of this is identical to fname_case(), keep in sync! | |
2634 */ | |
2635 static int | |
2636 fname_casew( | |
2637 WCHAR *name, | |
2638 int len) | |
2639 { | |
2640 WCHAR szTrueName[_MAX_PATH + 2]; | |
2641 WCHAR szTrueNameTemp[_MAX_PATH + 2]; | |
2642 WCHAR *ptrue, *ptruePrev; | |
2643 WCHAR *porig, *porigPrev; | |
2644 int flen; | |
2645 WIN32_FIND_DATAW fb; | |
5529 | 2646 HANDLE hFind = INVALID_HANDLE_VALUE; |
5326 | 2647 int c; |
2648 int slen; | |
2649 | |
2650 flen = (int)wcslen(name); | |
2651 if (flen > _MAX_PATH) | |
2652 return OK; | |
2653 | |
2654 /* slash_adjust(name) not needed, already adjusted by fname_case(). */ | |
2655 | |
2656 /* Build the new name in szTrueName[] one component at a time. */ | |
2657 porig = name; | |
2658 ptrue = szTrueName; | |
2659 | |
2660 if (iswalpha(porig[0]) && porig[1] == L':') | |
2661 { | |
2662 /* copy leading drive letter */ | |
2663 *ptrue++ = *porig++; | |
2664 *ptrue++ = *porig++; | |
2665 } | |
5529 | 2666 *ptrue = NUL; /* in case nothing follows */ |
5326 | 2667 |
2668 while (*porig != NUL) | |
2669 { | |
2670 /* copy \ characters */ | |
2671 while (*porig == psepc) | |
2672 *ptrue++ = *porig++; | |
2673 | |
2674 ptruePrev = ptrue; | |
2675 porigPrev = porig; | |
2676 while (*porig != NUL && *porig != psepc) | |
2677 { | |
2678 *ptrue++ = *porig++; | |
2679 } | |
2680 *ptrue = NUL; | |
2681 | |
2682 /* To avoid a slow failure append "\*" when searching a directory, | |
2683 * server or network share. */ | |
2684 wcscpy(szTrueNameTemp, szTrueName); | |
2685 slen = (int)wcslen(szTrueNameTemp); | |
2686 if (*porig == psepc && slen + 2 < _MAX_PATH) | |
2687 wcscpy(szTrueNameTemp + slen, L"\\*"); | |
2688 | |
2689 /* Skip "", "." and "..". */ | |
2690 if (ptrue > ptruePrev | |
2691 && (ptruePrev[0] != L'.' | |
2692 || (ptruePrev[1] != NUL | |
2693 && (ptruePrev[1] != L'.' || ptruePrev[2] != NUL))) | |
2694 && (hFind = FindFirstFileW(szTrueNameTemp, &fb)) | |
2695 != INVALID_HANDLE_VALUE) | |
2696 { | |
2697 c = *porig; | |
2698 *porig = NUL; | |
2699 | |
2700 /* Only use the match when it's the same name (ignoring case) or | |
2701 * expansion is allowed and there is a match with the short name | |
2702 * and there is enough room. */ | |
2703 if (_wcsicoll(porigPrev, fb.cFileName) == 0 | |
2704 || (len > 0 | |
2705 && (_wcsicoll(porigPrev, fb.cAlternateFileName) == 0 | |
2706 && (int)(ptruePrev - szTrueName) | |
2707 + (int)wcslen(fb.cFileName) < len))) | |
2708 { | |
2709 wcscpy(ptruePrev, fb.cFileName); | |
2710 | |
2711 /* Look for exact match and prefer it if found. Must be a | |
2712 * long name, otherwise there would be only one match. */ | |
2713 while (FindNextFileW(hFind, &fb)) | |
2714 { | |
2715 if (*fb.cAlternateFileName != NUL | |
2716 && (wcscoll(porigPrev, fb.cFileName) == 0 | |
2717 || (len > 0 | |
2718 && (_wcsicoll(porigPrev, | |
2719 fb.cAlternateFileName) == 0 | |
2720 && (int)(ptruePrev - szTrueName) | |
2721 + (int)wcslen(fb.cFileName) < len)))) | |
2722 { | |
2723 wcscpy(ptruePrev, fb.cFileName); | |
2724 break; | |
2725 } | |
2726 } | |
2727 } | |
2728 FindClose(hFind); | |
2729 *porig = c; | |
2730 ptrue = ptruePrev + wcslen(ptruePrev); | |
2731 } | |
2732 } | |
2733 | |
2734 wcscpy(name, szTrueName); | |
2735 return OK; | |
2736 } | |
2737 #endif | |
2738 | |
7 | 2739 /* |
2740 * fname_case(): Set the case of the file name, if it already exists. | |
2741 * When "len" is > 0, also expand short to long filenames. | |
5326 | 2742 * NOTE: much of this is identical to fname_casew(), keep in sync! |
7 | 2743 */ |
2744 void | |
2745 fname_case( | |
2746 char_u *name, | |
2747 int len) | |
2748 { | |
2749 char szTrueName[_MAX_PATH + 2]; | |
2604 | 2750 char szTrueNameTemp[_MAX_PATH + 2]; |
7 | 2751 char *ptrue, *ptruePrev; |
2752 char *porig, *porigPrev; | |
2753 int flen; | |
2754 WIN32_FIND_DATA fb; | |
2755 HANDLE hFind; | |
2756 int c; | |
2604 | 2757 int slen; |
7 | 2758 |
434 | 2759 flen = (int)STRLEN(name); |
5326 | 2760 if (flen == 0) |
7 | 2761 return; |
2762 | |
2763 slash_adjust(name); | |
2764 | |
5326 | 2765 #ifdef FEAT_MBYTE |
2766 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2767 { | |
2768 WCHAR *p = enc_to_utf16(name, NULL); | |
2769 | |
2770 if (p != NULL) | |
2771 { | |
2772 char_u *q; | |
6262 | 2773 WCHAR buf[_MAX_PATH + 1]; |
2774 | |
2775 wcsncpy(buf, p, _MAX_PATH); | |
2776 buf[_MAX_PATH] = L'\0'; | |
5326 | 2777 vim_free(p); |
2778 | |
2779 if (fname_casew(buf, (len > 0) ? _MAX_PATH : 0) == OK) | |
2780 { | |
2781 q = utf16_to_enc(buf, NULL); | |
2782 if (q != NULL) | |
2783 { | |
2784 vim_strncpy(name, q, (len > 0) ? len - 1 : flen); | |
2785 vim_free(q); | |
2786 return; | |
2787 } | |
2788 } | |
2789 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2790 return; |
5326 | 2791 } |
2792 #endif | |
2793 | |
2794 /* If 'enc' is utf-8, flen can be larger than _MAX_PATH. | |
2795 * So we should check this after calling wide function. */ | |
2796 if (flen > _MAX_PATH) | |
2797 return; | |
2798 | |
7 | 2799 /* Build the new name in szTrueName[] one component at a time. */ |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2800 porig = (char *)name; |
7 | 2801 ptrue = szTrueName; |
2802 | |
2803 if (isalpha(porig[0]) && porig[1] == ':') | |
2804 { | |
2805 /* copy leading drive letter */ | |
2806 *ptrue++ = *porig++; | |
2807 *ptrue++ = *porig++; | |
2808 } | |
5529 | 2809 *ptrue = NUL; /* in case nothing follows */ |
7 | 2810 |
2811 while (*porig != NUL) | |
2812 { | |
2813 /* copy \ characters */ | |
2814 while (*porig == psepc) | |
2815 *ptrue++ = *porig++; | |
2816 | |
2817 ptruePrev = ptrue; | |
2818 porigPrev = porig; | |
2819 while (*porig != NUL && *porig != psepc) | |
2820 { | |
2821 #ifdef FEAT_MBYTE | |
2822 int l; | |
2823 | |
2824 if (enc_dbcs) | |
2825 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2826 l = (*mb_ptr2len)((char_u *)porig); |
7 | 2827 while (--l >= 0) |
2828 *ptrue++ = *porig++; | |
2829 } | |
2830 else | |
2831 #endif | |
2832 *ptrue++ = *porig++; | |
2833 } | |
2834 *ptrue = NUL; | |
2835 | |
2604 | 2836 /* To avoid a slow failure append "\*" when searching a directory, |
2837 * server or network share. */ | |
2838 STRCPY(szTrueNameTemp, szTrueName); | |
2615 | 2839 slen = (int)strlen(szTrueNameTemp); |
2604 | 2840 if (*porig == psepc && slen + 2 < _MAX_PATH) |
2841 STRCPY(szTrueNameTemp + slen, "\\*"); | |
2842 | |
7 | 2843 /* Skip "", "." and "..". */ |
2844 if (ptrue > ptruePrev | |
2845 && (ptruePrev[0] != '.' | |
2846 || (ptruePrev[1] != NUL | |
2847 && (ptruePrev[1] != '.' || ptruePrev[2] != NUL))) | |
2604 | 2848 && (hFind = FindFirstFile(szTrueNameTemp, &fb)) |
7 | 2849 != INVALID_HANDLE_VALUE) |
2850 { | |
2851 c = *porig; | |
2852 *porig = NUL; | |
2853 | |
2854 /* Only use the match when it's the same name (ignoring case) or | |
2855 * expansion is allowed and there is a match with the short name | |
2856 * and there is enough room. */ | |
2857 if (_stricoll(porigPrev, fb.cFileName) == 0 | |
2858 || (len > 0 | |
2859 && (_stricoll(porigPrev, fb.cAlternateFileName) == 0 | |
2860 && (int)(ptruePrev - szTrueName) | |
2861 + (int)strlen(fb.cFileName) < len))) | |
2862 { | |
2863 STRCPY(ptruePrev, fb.cFileName); | |
2864 | |
2865 /* Look for exact match and prefer it if found. Must be a | |
2866 * long name, otherwise there would be only one match. */ | |
2867 while (FindNextFile(hFind, &fb)) | |
2868 { | |
2869 if (*fb.cAlternateFileName != NUL | |
2870 && (strcoll(porigPrev, fb.cFileName) == 0 | |
2871 || (len > 0 | |
2872 && (_stricoll(porigPrev, | |
2873 fb.cAlternateFileName) == 0 | |
2874 && (int)(ptruePrev - szTrueName) | |
2875 + (int)strlen(fb.cFileName) < len)))) | |
2876 { | |
2877 STRCPY(ptruePrev, fb.cFileName); | |
2878 break; | |
2879 } | |
2880 } | |
2881 } | |
2882 FindClose(hFind); | |
2883 *porig = c; | |
2884 ptrue = ptruePrev + strlen(ptruePrev); | |
2885 } | |
2886 } | |
2887 | |
2888 STRCPY(name, szTrueName); | |
2889 } | |
2890 | |
2891 | |
2892 /* | |
2893 * Insert user name in s[len]. | |
2894 */ | |
2895 int | |
2896 mch_get_user_name( | |
26 | 2897 char_u *s, |
2898 int len) | |
7 | 2899 { |
1414 | 2900 char szUserName[256 + 1]; /* UNLEN is 256 */ |
7 | 2901 DWORD cch = sizeof szUserName; |
2902 | |
5549 | 2903 #ifdef FEAT_MBYTE |
2904 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2905 { | |
2906 WCHAR wszUserName[256 + 1]; /* UNLEN is 256 */ | |
2907 DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR); | |
2908 | |
2909 if (GetUserNameW(wszUserName, &wcch)) | |
2910 { | |
2911 char_u *p = utf16_to_enc(wszUserName, NULL); | |
2912 | |
2913 if (p != NULL) | |
2914 { | |
2915 vim_strncpy(s, p, len - 1); | |
2916 vim_free(p); | |
2917 return OK; | |
2918 } | |
2919 } | |
2920 } | |
2921 #endif | |
7 | 2922 if (GetUserName(szUserName, &cch)) |
2923 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2924 vim_strncpy(s, (char_u *)szUserName, len - 1); |
7 | 2925 return OK; |
2926 } | |
2927 s[0] = NUL; | |
2928 return FAIL; | |
2929 } | |
2930 | |
2931 | |
2932 /* | |
2933 * Insert host name in s[len]. | |
2934 */ | |
2935 void | |
2936 mch_get_host_name( | |
2937 char_u *s, | |
2938 int len) | |
2939 { | |
2940 DWORD cch = len; | |
2941 | |
5551 | 2942 #ifdef FEAT_MBYTE |
2943 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2944 { | |
2945 WCHAR wszHostName[256 + 1]; | |
2946 DWORD wcch = sizeof(wszHostName) / sizeof(WCHAR); | |
2947 | |
2948 if (GetComputerNameW(wszHostName, &wcch)) | |
2949 { | |
2950 char_u *p = utf16_to_enc(wszHostName, NULL); | |
2951 | |
2952 if (p != NULL) | |
2953 { | |
2954 vim_strncpy(s, p, len - 1); | |
2955 vim_free(p); | |
2956 return; | |
2957 } | |
2958 } | |
2959 } | |
2960 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2961 if (!GetComputerName((LPSTR)s, &cch)) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2962 vim_strncpy(s, (char_u *)"PC (Win32 Vim)", len - 1); |
7 | 2963 } |
2964 | |
2965 | |
2966 /* | |
2967 * return process ID | |
2968 */ | |
2969 long | |
26 | 2970 mch_get_pid(void) |
7 | 2971 { |
2972 return (long)GetCurrentProcessId(); | |
2973 } | |
2974 | |
2975 | |
2976 /* | |
2977 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
2978 * Return OK for success, FAIL for failure. | |
2979 */ | |
2980 int | |
2981 mch_dirname( | |
2982 char_u *buf, | |
2983 int len) | |
2984 { | |
2985 /* | |
2986 * Originally this was: | |
2987 * return (getcwd(buf, len) != NULL ? OK : FAIL); | |
2988 * But the Win32s known bug list says that getcwd() doesn't work | |
2989 * so use the Win32 system call instead. <Negri> | |
2990 */ | |
2991 #ifdef FEAT_MBYTE | |
2992 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2993 { | |
2994 WCHAR wbuf[_MAX_PATH + 1]; | |
2995 | |
2996 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0) | |
2997 { | |
1752 | 2998 char_u *p = utf16_to_enc(wbuf, NULL); |
7 | 2999 |
3000 if (p != NULL) | |
3001 { | |
417 | 3002 vim_strncpy(buf, p, len - 1); |
7 | 3003 vim_free(p); |
3004 return OK; | |
3005 } | |
3006 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3007 return FAIL; |
7 | 3008 } |
3009 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3010 return (GetCurrentDirectory(len, (LPSTR)buf) != 0 ? OK : FAIL); |
7 | 3011 } |
3012 | |
3013 /* | |
5494 | 3014 * Get file permissions for "name". |
3015 * Return mode_t or -1 for error. | |
7 | 3016 */ |
3017 long | |
26 | 3018 mch_getperm(char_u *name) |
7 | 3019 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8949
diff
changeset
|
3020 stat_T st; |
5494 | 3021 int n; |
3022 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3023 n = mch_stat((char *)name, &st); |
5588 | 3024 return n == 0 ? (long)(unsigned short)st.st_mode : -1L; |
7 | 3025 } |
3026 | |
3027 | |
3028 /* | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3029 * Set file permission for "name" to "perm". |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3030 * |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3031 * Return FAIL for failure, OK otherwise. |
7 | 3032 */ |
3033 int | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3034 mch_setperm(char_u *name, long perm) |
7 | 3035 { |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3036 long n = -1; |
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3037 |
7 | 3038 #ifdef FEAT_MBYTE |
3039 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3040 { | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3041 WCHAR *p = enc_to_utf16(name, NULL); |
7 | 3042 |
3043 if (p != NULL) | |
3044 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3045 n = _wchmod(p, perm); |
7 | 3046 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3047 if (n == -1) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3048 return FAIL; |
7 | 3049 } |
3050 } | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3051 if (n == -1) |
7 | 3052 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3053 n = _chmod((const char *)name, perm); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3054 if (n == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3055 return FAIL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3056 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3057 win32_set_archive(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3058 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3059 return OK; |
7 | 3060 } |
3061 | |
3062 /* | |
3063 * Set hidden flag for "name". | |
3064 */ | |
3065 void | |
3066 mch_hide(char_u *name) | |
3067 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3068 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3069 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3070 return; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3071 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3072 attrs |= FILE_ATTRIBUTE_HIDDEN; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3073 win32_setattrs(name, attrs); |
7 | 3074 } |
3075 | |
3076 /* | |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3077 * Return TRUE if file "name" exists and is hidden. |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3078 */ |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3079 int |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3080 mch_ishidden(char_u *name) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3081 { |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3082 int f = win32_getattrs(name); |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3083 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3084 if (f == -1) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3085 return FALSE; /* file does not exist at all */ |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3086 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3087 return (f & FILE_ATTRIBUTE_HIDDEN) != 0; |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3088 } |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3089 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3090 /* |
7 | 3091 * return TRUE if "name" is a directory |
3092 * return FALSE if "name" is not a directory or upon error | |
3093 */ | |
3094 int | |
3095 mch_isdir(char_u *name) | |
3096 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3097 int f = win32_getattrs(name); |
7 | 3098 |
3099 if (f == -1) | |
3100 return FALSE; /* file does not exist at all */ | |
3101 | |
3102 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; | |
3103 } | |
3104 | |
3105 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3106 * return TRUE if "name" is a directory, NOT a symlink to a directory |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3107 * return FALSE if "name" is not a directory |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3108 * return FALSE for error |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3109 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3110 int |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3111 mch_isrealdir(char_u *name) |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3112 { |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3113 return mch_isdir(name) && !mch_is_symbolic_link(name); |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3114 } |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3115 |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3116 /* |
2803 | 3117 * Create directory "name". |
3118 * Return 0 on success, -1 on error. | |
3119 */ | |
3120 int | |
3121 mch_mkdir(char_u *name) | |
3122 { | |
3123 #ifdef FEAT_MBYTE | |
3124 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
3125 { | |
3126 WCHAR *p; | |
3127 int retval; | |
3128 | |
3129 p = enc_to_utf16(name, NULL); | |
3130 if (p == NULL) | |
3131 return -1; | |
3132 retval = _wmkdir(p); | |
3133 vim_free(p); | |
3134 return retval; | |
3135 } | |
3136 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3137 return _mkdir((const char *)name); |
2803 | 3138 } |
3139 | |
3140 /* | |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3141 * Delete directory "name". |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3142 * Return 0 on success, -1 on error. |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3143 */ |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3144 int |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3145 mch_rmdir(char_u *name) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3146 { |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3147 #ifdef FEAT_MBYTE |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3148 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3149 { |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3150 WCHAR *p; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3151 int retval; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3152 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3153 p = enc_to_utf16(name, NULL); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3154 if (p == NULL) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3155 return -1; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3156 retval = _wrmdir(p); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3157 vim_free(p); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3158 return retval; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3159 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3160 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3161 return _rmdir((const char *)name); |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3162 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3163 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3164 /* |
696 | 3165 * Return TRUE if file "fname" has more than one link. |
3166 */ | |
3167 int | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3168 mch_is_hard_link(char_u *fname) |
696 | 3169 { |
2793 | 3170 BY_HANDLE_FILE_INFORMATION info; |
3171 | |
3172 return win32_fileinfo(fname, &info) == FILEINFO_OK | |
3173 && info.nNumberOfLinks > 1; | |
3174 } | |
3175 | |
3176 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3177 * Return TRUE if "name" is a symbolic link (or a junction). |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3178 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3179 int |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3180 mch_is_symbolic_link(char_u *name) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3181 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3182 HANDLE hFind; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3183 int res = FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3184 WIN32_FIND_DATAA findDataA; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3185 DWORD fileFlags = 0, reparseTag = 0; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3186 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3187 WCHAR *wn = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3188 WIN32_FIND_DATAW findDataW; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3189 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3190 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3191 wn = enc_to_utf16(name, NULL); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3192 if (wn != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3193 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3194 hFind = FindFirstFileW(wn, &findDataW); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3195 vim_free(wn); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3196 if (hFind != INVALID_HANDLE_VALUE) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3197 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3198 fileFlags = findDataW.dwFileAttributes; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3199 reparseTag = findDataW.dwReserved0; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3200 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3201 } |
4930
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3202 else |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3203 #endif |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3204 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3205 hFind = FindFirstFile((LPCSTR)name, &findDataA); |
4930
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3206 if (hFind != INVALID_HANDLE_VALUE) |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3207 { |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3208 fileFlags = findDataA.dwFileAttributes; |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3209 reparseTag = findDataA.dwReserved0; |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3210 } |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3211 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3212 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3213 if (hFind != INVALID_HANDLE_VALUE) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3214 FindClose(hFind); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3215 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3216 if ((fileFlags & FILE_ATTRIBUTE_REPARSE_POINT) |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3217 && (reparseTag == IO_REPARSE_TAG_SYMLINK |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3218 || reparseTag == IO_REPARSE_TAG_MOUNT_POINT)) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3219 res = TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3220 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3221 return res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3222 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3223 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3224 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3225 * Return TRUE if file "fname" has more than one link or if it is a symbolic |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3226 * link. |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3227 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3228 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3229 mch_is_linked(char_u *fname) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3230 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3231 if (mch_is_hard_link(fname) || mch_is_symbolic_link(fname)) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3232 return TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3233 return FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3234 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3235 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3236 /* |
2793 | 3237 * Get the by-handle-file-information for "fname". |
3238 * Returns FILEINFO_OK when OK. | |
3239 * returns FILEINFO_ENC_FAIL when enc_to_utf16() failed. | |
3240 * Returns FILEINFO_READ_FAIL when CreateFile() failed. | |
3241 * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed. | |
3242 */ | |
3243 int | |
3244 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info) | |
3245 { | |
696 | 3246 HANDLE hFile; |
2793 | 3247 int res = FILEINFO_READ_FAIL; |
696 | 3248 #ifdef FEAT_MBYTE |
3249 WCHAR *wn = NULL; | |
3250 | |
3251 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2793 | 3252 { |
1752 | 3253 wn = enc_to_utf16(fname, NULL); |
2793 | 3254 if (wn == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3255 return FILEINFO_ENC_FAIL; |
2793 | 3256 } |
696 | 3257 if (wn != NULL) |
3258 { | |
3259 hFile = CreateFileW(wn, /* file name */ | |
3260 GENERIC_READ, /* access mode */ | |
2793 | 3261 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ |
696 | 3262 NULL, /* security descriptor */ |
3263 OPEN_EXISTING, /* creation disposition */ | |
2793 | 3264 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ |
696 | 3265 NULL); /* handle to template file */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3266 vim_free(wn); |
696 | 3267 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3268 else |
696 | 3269 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3270 hFile = CreateFile((LPCSTR)fname, /* file name */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3271 GENERIC_READ, /* access mode */ |
2793 | 3272 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ |
696 | 3273 NULL, /* security descriptor */ |
3274 OPEN_EXISTING, /* creation disposition */ | |
2793 | 3275 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ |
696 | 3276 NULL); /* handle to template file */ |
3277 | |
3278 if (hFile != INVALID_HANDLE_VALUE) | |
3279 { | |
2793 | 3280 if (GetFileInformationByHandle(hFile, info) != 0) |
3281 res = FILEINFO_OK; | |
3282 else | |
3283 res = FILEINFO_INFO_FAIL; | |
696 | 3284 CloseHandle(hFile); |
3285 } | |
3286 | |
3287 return res; | |
3288 } | |
3289 | |
3290 /* | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3291 * get file attributes for `name' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3292 * -1 : error |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3293 * else FILE_ATTRIBUTE_* defined in winnt.h |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3294 */ |
5494 | 3295 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3296 win32_getattrs(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3297 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3298 int attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3299 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3300 WCHAR *p = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3301 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3302 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3303 p = enc_to_utf16(name, NULL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3304 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3305 if (p != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3306 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3307 attr = GetFileAttributesW(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3308 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3309 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3310 else |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3311 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3312 attr = GetFileAttributes((char *)name); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3313 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3314 return attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3315 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3316 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3317 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3318 * set file attributes for `name' to `attrs' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3319 * |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3320 * return -1 for failure, 0 otherwise |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3321 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3322 static |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3323 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3324 win32_setattrs(char_u *name, int attrs) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3325 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3326 int res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3327 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3328 WCHAR *p = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3329 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3330 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3331 p = enc_to_utf16(name, NULL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3332 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3333 if (p != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3334 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3335 res = SetFileAttributesW(p, attrs); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3336 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3337 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3338 else |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3339 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3340 res = SetFileAttributes((char *)name, attrs); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3341 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3342 return res ? 0 : -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3343 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3344 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3345 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3346 * Set archive flag for "name". |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3347 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3348 static |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3349 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3350 win32_set_archive(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3351 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3352 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3353 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3354 return -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3355 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3356 attrs |= FILE_ATTRIBUTE_ARCHIVE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3357 return win32_setattrs(name, attrs); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3358 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3359 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3360 /* |
7 | 3361 * Return TRUE if file or directory "name" is writable (not readonly). |
3362 * Strange semantics of Win32: a readonly directory is writable, but you can't | |
3363 * delete a file. Let's say this means it is writable. | |
3364 */ | |
3365 int | |
3366 mch_writable(char_u *name) | |
3367 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3368 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3369 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3370 return (attrs != -1 && (!(attrs & FILE_ATTRIBUTE_READONLY) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3371 || (attrs & FILE_ATTRIBUTE_DIRECTORY))); |
7 | 3372 } |
3373 | |
3374 /* | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3375 * Return TRUE if "name" can be executed, FALSE if not. |
6700 | 3376 * If "use_path" is FALSE only check if "name" is executable. |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3377 * When returning TRUE and "path" is not NULL save the path and set "*path" to |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3378 * the allocated memory. |
7 | 3379 */ |
3380 int | |
6700 | 3381 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3382 { |
10 | 3383 char_u buf[_MAX_PATH]; |
835 | 3384 int len = (int)STRLEN(name); |
10 | 3385 char_u *p; |
3386 | |
3387 if (len >= _MAX_PATH) /* safety check */ | |
3388 return FALSE; | |
3389 | |
3390 /* If there already is an extension try using the name directly. Also do | |
3391 * this with a Unix-shell like 'shell'. */ | |
3392 if (vim_strchr(gettail(name), '.') != NULL | |
3393 || strstr((char *)gettail(p_sh), "sh") != NULL) | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3394 if (executable_exists((char *)name, path, use_path)) |
10 | 3395 return TRUE; |
3396 | |
3397 /* | |
3398 * Loop over all extensions in $PATHEXT. | |
3399 */ | |
417 | 3400 vim_strncpy(buf, name, _MAX_PATH - 1); |
10 | 3401 p = mch_getenv("PATHEXT"); |
3402 if (p == NULL) | |
3403 p = (char_u *)".com;.exe;.bat;.cmd"; | |
3404 while (*p) | |
3405 { | |
3406 if (p[0] == '.' && (p[1] == NUL || p[1] == ';')) | |
3407 { | |
3408 /* A single "." means no extension is added. */ | |
3409 buf[len] = NUL; | |
3410 ++p; | |
3411 if (*p) | |
3412 ++p; | |
3413 } | |
3414 else | |
3415 copy_option_part(&p, buf + len, _MAX_PATH - len, ";"); | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3416 if (executable_exists((char *)buf, path, use_path)) |
10 | 3417 return TRUE; |
3418 } | |
3419 return FALSE; | |
7 | 3420 } |
3421 | |
3422 /* | |
3423 * Check what "name" is: | |
3424 * NODE_NORMAL: file or directory (or doesn't exist) | |
3425 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3426 * NODE_OTHER: non-writable things | |
3427 */ | |
3428 int | |
3429 mch_nodetype(char_u *name) | |
3430 { | |
3431 HANDLE hFile; | |
3432 int type; | |
5324 | 3433 #ifdef FEAT_MBYTE |
3434 WCHAR *wn = NULL; | |
3435 #endif | |
7 | 3436 |
1004 | 3437 /* We can't open a file with a name "\\.\con" or "\\.\prn" and trying to |
3438 * read from it later will cause Vim to hang. Thus return NODE_WRITABLE | |
3439 * here. */ | |
3440 if (STRNCMP(name, "\\\\.\\", 4) == 0) | |
3441 return NODE_WRITABLE; | |
3442 | |
5324 | 3443 #ifdef FEAT_MBYTE |
3444 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3445 wn = enc_to_utf16(name, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3446 |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3447 if (wn != NULL) |
5324 | 3448 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3449 hFile = CreateFileW(wn, /* file name */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3450 GENERIC_WRITE, /* access mode */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3451 0, /* share mode */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3452 NULL, /* security descriptor */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3453 OPEN_EXISTING, /* creation disposition */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3454 0, /* file attributes */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3455 NULL); /* handle to template file */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3456 vim_free(wn); |
5324 | 3457 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3458 else |
5324 | 3459 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3460 hFile = CreateFile((LPCSTR)name, /* file name */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3461 GENERIC_WRITE, /* access mode */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3462 0, /* share mode */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3463 NULL, /* security descriptor */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3464 OPEN_EXISTING, /* creation disposition */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3465 0, /* file attributes */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3466 NULL); /* handle to template file */ |
5324 | 3467 |
7 | 3468 if (hFile == INVALID_HANDLE_VALUE) |
3469 return NODE_NORMAL; | |
3470 | |
3471 type = GetFileType(hFile); | |
3472 CloseHandle(hFile); | |
3473 if (type == FILE_TYPE_CHAR) | |
3474 return NODE_WRITABLE; | |
3475 if (type == FILE_TYPE_DISK) | |
3476 return NODE_NORMAL; | |
3477 return NODE_OTHER; | |
3478 } | |
3479 | |
3480 #ifdef HAVE_ACL | |
3481 struct my_acl | |
3482 { | |
3483 PSECURITY_DESCRIPTOR pSecurityDescriptor; | |
3484 PSID pSidOwner; | |
3485 PSID pSidGroup; | |
3486 PACL pDacl; | |
3487 PACL pSacl; | |
3488 }; | |
3489 #endif | |
3490 | |
3491 /* | |
3492 * Return a pointer to the ACL of file "fname" in allocated memory. | |
3493 * Return NULL if the ACL is not available for whatever reason. | |
3494 */ | |
3495 vim_acl_T | |
26 | 3496 mch_get_acl(char_u *fname) |
7 | 3497 { |
3498 #ifndef HAVE_ACL | |
3499 return (vim_acl_T)NULL; | |
3500 #else | |
3501 struct my_acl *p = NULL; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3502 DWORD err; |
7 | 3503 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3504 p = (struct my_acl *)alloc_clear((unsigned)sizeof(struct my_acl)); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3505 if (p != NULL) |
7 | 3506 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3507 # ifdef FEAT_MBYTE |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3508 WCHAR *wn = NULL; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3509 |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3510 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3511 wn = enc_to_utf16(fname, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3512 if (wn != NULL) |
7 | 3513 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3514 /* Try to retrieve the entire security descriptor. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3515 err = GetNamedSecurityInfoW( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3516 wn, // Abstract filename |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3517 SE_FILE_OBJECT, // File Object |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3518 OWNER_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3519 GROUP_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3520 DACL_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3521 SACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3522 &p->pSidOwner, // Ownership information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3523 &p->pSidGroup, // Group membership. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3524 &p->pDacl, // Discretionary information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3525 &p->pSacl, // For auditing purposes. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3526 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3527 if (err == ERROR_ACCESS_DENIED || |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3528 err == ERROR_PRIVILEGE_NOT_HELD) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3529 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3530 /* Retrieve only DACL. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3531 (void)GetNamedSecurityInfoW( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3532 wn, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3533 SE_FILE_OBJECT, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3534 DACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3535 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3536 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3537 &p->pDacl, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3538 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3539 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3540 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3541 if (p->pSecurityDescriptor == NULL) |
7 | 3542 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3543 mch_free_acl((vim_acl_T)p); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3544 p = NULL; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3545 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3546 vim_free(wn); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3547 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3548 else |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3549 # endif |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3550 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3551 /* Try to retrieve the entire security descriptor. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3552 err = GetNamedSecurityInfo( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3553 (LPSTR)fname, // Abstract filename |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3554 SE_FILE_OBJECT, // File Object |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3555 OWNER_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3556 GROUP_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3557 DACL_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3558 SACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3559 &p->pSidOwner, // Ownership information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3560 &p->pSidGroup, // Group membership. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3561 &p->pDacl, // Discretionary information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3562 &p->pSacl, // For auditing purposes. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3563 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3564 if (err == ERROR_ACCESS_DENIED || |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3565 err == ERROR_PRIVILEGE_NOT_HELD) |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3566 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3567 /* Retrieve only DACL. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3568 (void)GetNamedSecurityInfo( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3569 (LPSTR)fname, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3570 SE_FILE_OBJECT, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3571 DACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3572 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3573 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3574 &p->pDacl, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3575 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3576 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3577 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3578 if (p->pSecurityDescriptor == NULL) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3579 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3580 mch_free_acl((vim_acl_T)p); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3581 p = NULL; |
7 | 3582 } |
3583 } | |
3584 } | |
3585 | |
3586 return (vim_acl_T)p; | |
3587 #endif | |
3588 } | |
3589 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3590 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3591 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3592 * Check if "acl" contains inherited ACE. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3593 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3594 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3595 is_acl_inherited(PACL acl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3596 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3597 DWORD i; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3598 ACL_SIZE_INFORMATION acl_info; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3599 PACCESS_ALLOWED_ACE ace; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3600 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3601 acl_info.AceCount = 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3602 GetAclInformation(acl, &acl_info, sizeof(acl_info), AclSizeInformation); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3603 for (i = 0; i < acl_info.AceCount; i++) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3604 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3605 GetAce(acl, i, (LPVOID *)&ace); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3606 if (ace->Header.AceFlags & INHERITED_ACE) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3607 return TRUE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3608 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3609 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3610 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3611 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3612 |
7 | 3613 /* |
3614 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3615 * Errors are ignored. | |
3616 * This must only be called with "acl" equal to what mch_get_acl() returned. | |
3617 */ | |
3618 void | |
26 | 3619 mch_set_acl(char_u *fname, vim_acl_T acl) |
7 | 3620 { |
3621 #ifdef HAVE_ACL | |
3622 struct my_acl *p = (struct my_acl *)acl; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3623 SECURITY_INFORMATION sec_info = 0; |
7 | 3624 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3625 if (p != NULL) |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3626 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3627 # ifdef FEAT_MBYTE |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3628 WCHAR *wn = NULL; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3629 # endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3630 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3631 /* Set security flags */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3632 if (p->pSidOwner) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3633 sec_info |= OWNER_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3634 if (p->pSidGroup) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3635 sec_info |= GROUP_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3636 if (p->pDacl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3637 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3638 sec_info |= DACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3639 /* Do not inherit its parent's DACL. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3640 * If the DACL is inherited, Cygwin permissions would be changed. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3641 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3642 if (!is_acl_inherited(p->pDacl)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3643 sec_info |= PROTECTED_DACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3644 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3645 if (p->pSacl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3646 sec_info |= SACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3647 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3648 # ifdef FEAT_MBYTE |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3649 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3650 wn = enc_to_utf16(fname, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3651 if (wn != NULL) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3652 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3653 (void)SetNamedSecurityInfoW( |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3654 wn, // Abstract filename |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3655 SE_FILE_OBJECT, // File Object |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3656 sec_info, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3657 p->pSidOwner, // Ownership information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3658 p->pSidGroup, // Group membership. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3659 p->pDacl, // Discretionary information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3660 p->pSacl // For auditing purposes. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3661 ); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3662 vim_free(wn); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3663 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3664 else |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3665 # endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3666 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3667 (void)SetNamedSecurityInfo( |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3668 (LPSTR)fname, // Abstract filename |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3669 SE_FILE_OBJECT, // File Object |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3670 sec_info, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3671 p->pSidOwner, // Ownership information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3672 p->pSidGroup, // Group membership. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3673 p->pDacl, // Discretionary information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3674 p->pSacl // For auditing purposes. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3675 ); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3676 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3677 } |
7 | 3678 #endif |
3679 } | |
3680 | |
3681 void | |
26 | 3682 mch_free_acl(vim_acl_T acl) |
7 | 3683 { |
3684 #ifdef HAVE_ACL | |
3685 struct my_acl *p = (struct my_acl *)acl; | |
3686 | |
3687 if (p != NULL) | |
3688 { | |
3689 LocalFree(p->pSecurityDescriptor); // Free the memory just in case | |
3690 vim_free(p); | |
3691 } | |
3692 #endif | |
3693 } | |
3694 | |
3695 #ifndef FEAT_GUI_W32 | |
3696 | |
3697 /* | |
3698 * handler for ctrl-break, ctrl-c interrupts, and fatal events. | |
3699 */ | |
3700 static BOOL WINAPI | |
3701 handler_routine( | |
3702 DWORD dwCtrlType) | |
3703 { | |
3704 switch (dwCtrlType) | |
3705 { | |
3706 case CTRL_C_EVENT: | |
3707 if (ctrl_c_interrupts) | |
3708 g_fCtrlCPressed = TRUE; | |
3709 return TRUE; | |
3710 | |
3711 case CTRL_BREAK_EVENT: | |
3712 g_fCBrkPressed = TRUE; | |
3713 return TRUE; | |
3714 | |
3715 /* fatal events: shut down gracefully */ | |
3716 case CTRL_CLOSE_EVENT: | |
3717 case CTRL_LOGOFF_EVENT: | |
3718 case CTRL_SHUTDOWN_EVENT: | |
3719 windgoto((int)Rows - 1, 0); | |
3720 g_fForceExit = TRUE; | |
3721 | |
1569 | 3722 vim_snprintf((char *)IObuff, IOSIZE, _("Vim: Caught %s event\n"), |
7 | 3723 (dwCtrlType == CTRL_CLOSE_EVENT |
3724 ? _("close") | |
3725 : dwCtrlType == CTRL_LOGOFF_EVENT | |
3726 ? _("logoff") | |
3727 : _("shutdown"))); | |
3728 #ifdef DEBUG | |
3729 OutputDebugString(IObuff); | |
3730 #endif | |
3731 | |
3732 preserve_exit(); /* output IObuff, preserve files and exit */ | |
3733 | |
3734 return TRUE; /* not reached */ | |
3735 | |
3736 default: | |
3737 return FALSE; | |
3738 } | |
3739 } | |
3740 | |
3741 | |
3742 /* | |
3743 * set the tty in (raw) ? "raw" : "cooked" mode | |
3744 */ | |
3745 void | |
26 | 3746 mch_settmode(int tmode) |
7 | 3747 { |
3748 DWORD cmodein; | |
3749 DWORD cmodeout; | |
3750 BOOL bEnableHandler; | |
3751 | |
3752 GetConsoleMode(g_hConIn, &cmodein); | |
3753 GetConsoleMode(g_hConOut, &cmodeout); | |
3754 if (tmode == TMODE_RAW) | |
3755 { | |
3756 cmodein &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3757 ENABLE_ECHO_INPUT); | |
3758 #ifdef FEAT_MOUSE | |
3759 if (g_fMouseActive) | |
3760 cmodein |= ENABLE_MOUSE_INPUT; | |
3761 #endif | |
3762 cmodeout &= ~(ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); | |
3763 bEnableHandler = TRUE; | |
3764 } | |
3765 else /* cooked */ | |
3766 { | |
3767 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3768 ENABLE_ECHO_INPUT); | |
3769 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); | |
3770 bEnableHandler = FALSE; | |
3771 } | |
3772 SetConsoleMode(g_hConIn, cmodein); | |
3773 SetConsoleMode(g_hConOut, cmodeout); | |
3774 SetConsoleCtrlHandler(handler_routine, bEnableHandler); | |
3775 | |
3776 #ifdef MCH_WRITE_DUMP | |
3777 if (fdDump) | |
3778 { | |
3779 fprintf(fdDump, "mch_settmode(%s, in = %x, out = %x)\n", | |
3780 tmode == TMODE_RAW ? "raw" : | |
3781 tmode == TMODE_COOK ? "cooked" : "normal", | |
3782 cmodein, cmodeout); | |
3783 fflush(fdDump); | |
3784 } | |
3785 #endif | |
3786 } | |
3787 | |
3788 | |
3789 /* | |
3790 * Get the size of the current window in `Rows' and `Columns' | |
3791 * Return OK when size could be determined, FAIL otherwise. | |
3792 */ | |
3793 int | |
26 | 3794 mch_get_shellsize(void) |
7 | 3795 { |
3796 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
3797 | |
3798 if (!g_fTermcapMode && g_cbTermcap.IsValid) | |
3799 { | |
3800 /* | |
3801 * For some reason, we are trying to get the screen dimensions | |
3802 * even though we are not in termcap mode. The 'Rows' and 'Columns' | |
3803 * variables are really intended to mean the size of Vim screen | |
3804 * while in termcap mode. | |
3805 */ | |
3806 Rows = g_cbTermcap.Info.dwSize.Y; | |
3807 Columns = g_cbTermcap.Info.dwSize.X; | |
3808 } | |
3809 else if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3810 { | |
3811 Rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3812 Columns = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3813 } | |
3814 else | |
3815 { | |
3816 Rows = 25; | |
3817 Columns = 80; | |
3818 } | |
3819 return OK; | |
3820 } | |
3821 | |
3822 /* | |
3823 * Set a console window to `xSize' * `ySize' | |
3824 */ | |
3825 static void | |
3826 ResizeConBufAndWindow( | |
26 | 3827 HANDLE hConsole, |
3828 int xSize, | |
3829 int ySize) | |
7 | 3830 { |
3831 CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ | |
3832 SMALL_RECT srWindowRect; /* hold the new console size */ | |
3833 COORD coordScreen; | |
3834 | |
3835 #ifdef MCH_WRITE_DUMP | |
3836 if (fdDump) | |
3837 { | |
3838 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize); | |
3839 fflush(fdDump); | |
3840 } | |
3841 #endif | |
3842 | |
3843 /* get the largest size we can size the console window to */ | |
3844 coordScreen = GetLargestConsoleWindowSize(hConsole); | |
3845 | |
3846 /* define the new console window size and scroll position */ | |
3847 srWindowRect.Left = srWindowRect.Top = (SHORT) 0; | |
3848 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); | |
3849 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); | |
3850 | |
3851 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3852 { | |
3853 int sx, sy; | |
3854 | |
3855 sx = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3856 sy = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3857 if (sy < ySize || sx < xSize) | |
3858 { | |
3859 /* | |
3860 * Increasing number of lines/columns, do buffer first. | |
3861 * Use the maximal size in x and y direction. | |
3862 */ | |
3863 if (sy < ySize) | |
3864 coordScreen.Y = ySize; | |
3865 else | |
3866 coordScreen.Y = sy; | |
3867 if (sx < xSize) | |
3868 coordScreen.X = xSize; | |
3869 else | |
3870 coordScreen.X = sx; | |
3871 SetConsoleScreenBufferSize(hConsole, coordScreen); | |
3872 } | |
3873 } | |
3874 | |
3875 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &srWindowRect)) | |
3876 { | |
3877 #ifdef MCH_WRITE_DUMP | |
3878 if (fdDump) | |
3879 { | |
3880 fprintf(fdDump, "SetConsoleWindowInfo failed: %lx\n", | |
3881 GetLastError()); | |
3882 fflush(fdDump); | |
3883 } | |
3884 #endif | |
3885 } | |
3886 | |
3887 /* define the new console buffer size */ | |
3888 coordScreen.X = xSize; | |
3889 coordScreen.Y = ySize; | |
3890 | |
3891 if (!SetConsoleScreenBufferSize(hConsole, coordScreen)) | |
3892 { | |
3893 #ifdef MCH_WRITE_DUMP | |
3894 if (fdDump) | |
3895 { | |
3896 fprintf(fdDump, "SetConsoleScreenBufferSize failed: %lx\n", | |
3897 GetLastError()); | |
3898 fflush(fdDump); | |
3899 } | |
3900 #endif | |
3901 } | |
3902 } | |
3903 | |
3904 | |
3905 /* | |
3906 * Set the console window to `Rows' * `Columns' | |
3907 */ | |
3908 void | |
26 | 3909 mch_set_shellsize(void) |
7 | 3910 { |
3911 COORD coordScreen; | |
3912 | |
3913 /* Don't change window size while still starting up */ | |
3914 if (suppress_winsize != 0) | |
3915 { | |
3916 suppress_winsize = 2; | |
3917 return; | |
3918 } | |
3919 | |
3920 if (term_console) | |
3921 { | |
3922 coordScreen = GetLargestConsoleWindowSize(g_hConOut); | |
3923 | |
3924 /* Clamp Rows and Columns to reasonable values */ | |
3925 if (Rows > coordScreen.Y) | |
3926 Rows = coordScreen.Y; | |
3927 if (Columns > coordScreen.X) | |
3928 Columns = coordScreen.X; | |
3929 | |
3930 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
3931 } | |
3932 } | |
3933 | |
3934 /* | |
3935 * Rows and/or Columns has changed. | |
3936 */ | |
3937 void | |
26 | 3938 mch_new_shellsize(void) |
7 | 3939 { |
3940 set_scroll_region(0, 0, Columns - 1, Rows - 1); | |
3941 } | |
3942 | |
3943 | |
3944 /* | |
3945 * Called when started up, to set the winsize that was delayed. | |
3946 */ | |
3947 void | |
26 | 3948 mch_set_winsize_now(void) |
7 | 3949 { |
3950 if (suppress_winsize == 2) | |
3951 { | |
3952 suppress_winsize = 0; | |
3953 mch_set_shellsize(); | |
3954 shell_resized(); | |
3955 } | |
3956 suppress_winsize = 0; | |
3957 } | |
3958 #endif /* FEAT_GUI_W32 */ | |
3959 | |
5547 | 3960 static BOOL |
3961 vim_create_process( | |
5556 | 3962 char *cmd, |
5569 | 3963 BOOL inherit_handles, |
5547 | 3964 DWORD flags, |
3965 STARTUPINFO *si, | |
3966 PROCESS_INFORMATION *pi) | |
3967 { | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3968 #ifdef FEAT_MBYTE |
5547 | 3969 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
3970 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3971 WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL); |
5547 | 3972 |
3973 if (wcmd != NULL) | |
3974 { | |
3975 BOOL ret; | |
3976 ret = CreateProcessW( | |
3977 NULL, /* Executable name */ | |
3978 wcmd, /* Command to execute */ | |
3979 NULL, /* Process security attributes */ | |
3980 NULL, /* Thread security attributes */ | |
3981 inherit_handles, /* Inherit handles */ | |
3982 flags, /* Creation flags */ | |
3983 NULL, /* Environment */ | |
3984 NULL, /* Current directory */ | |
5556 | 3985 (LPSTARTUPINFOW)si, /* Startup information */ |
5547 | 3986 pi); /* Process information */ |
3987 vim_free(wcmd); | |
3988 return ret; | |
3989 } | |
3990 } | |
3991 #endif | |
3992 return CreateProcess( | |
3993 NULL, /* Executable name */ | |
3994 cmd, /* Command to execute */ | |
3995 NULL, /* Process security attributes */ | |
3996 NULL, /* Thread security attributes */ | |
3997 inherit_handles, /* Inherit handles */ | |
3998 flags, /* Creation flags */ | |
3999 NULL, /* Environment */ | |
4000 NULL, /* Current directory */ | |
4001 si, /* Startup information */ | |
4002 pi); /* Process information */ | |
4003 } | |
7 | 4004 |
4005 | |
4006 #if defined(FEAT_GUI_W32) || defined(PROTO) | |
4007 | |
4008 /* | |
4009 * Specialised version of system() for Win32 GUI mode. | |
4010 * This version proceeds as follows: | |
4011 * 1. Create a console window for use by the subprocess | |
4012 * 2. Run the subprocess (it gets the allocated console by default) | |
4013 * 3. Wait for the subprocess to terminate and get its exit code | |
4014 * 4. Prompt the user to press a key to close the console window | |
4015 */ | |
4016 static int | |
2935 | 4017 mch_system_classic(char *cmd, int options) |
7 | 4018 { |
4019 STARTUPINFO si; | |
4020 PROCESS_INFORMATION pi; | |
4021 DWORD ret = 0; | |
4022 HWND hwnd = GetFocus(); | |
4023 | |
4024 si.cb = sizeof(si); | |
4025 si.lpReserved = NULL; | |
4026 si.lpDesktop = NULL; | |
4027 si.lpTitle = NULL; | |
4028 si.dwFlags = STARTF_USESHOWWINDOW; | |
4029 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4030 * It's nicer to run a filter command in a minimized window. |
2643 | 4031 * Don't activate the window to keep focus on Vim. |
7 | 4032 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4033 if (options & SHELL_DOOUT) |
2643 | 4034 si.wShowWindow = SW_SHOWMINNOACTIVE; |
7 | 4035 else |
4036 si.wShowWindow = SW_SHOWNORMAL; | |
4037 si.cbReserved2 = 0; | |
4038 si.lpReserved2 = NULL; | |
4039 | |
4040 /* Now, run the command */ | |
5547 | 4041 vim_create_process(cmd, FALSE, |
4042 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE, &si, &pi); | |
7 | 4043 |
4044 /* Wait for the command to terminate before continuing */ | |
4045 { | |
4046 #ifdef FEAT_GUI | |
4047 int delay = 1; | |
4048 | |
4049 /* Keep updating the window while waiting for the shell to finish. */ | |
4050 for (;;) | |
4051 { | |
4052 MSG msg; | |
4053 | |
3010 | 4054 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
7 | 4055 { |
4056 TranslateMessage(&msg); | |
3010 | 4057 pDispatchMessage(&msg); |
3720 | 4058 delay = 1; |
4059 continue; | |
7 | 4060 } |
4061 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4062 break; | |
4063 | |
4064 /* We start waiting for a very short time and then increase it, so | |
4065 * that we respond quickly when the process is quick, and don't | |
4066 * consume too much overhead when it's slow. */ | |
4067 if (delay < 50) | |
4068 delay += 10; | |
4069 } | |
4070 #else | |
4071 WaitForSingleObject(pi.hProcess, INFINITE); | |
4072 #endif | |
4073 | |
4074 /* Get the command exit code */ | |
4075 GetExitCodeProcess(pi.hProcess, &ret); | |
4076 } | |
4077 | |
4078 /* Close the handles to the subprocess, so that it goes away */ | |
4079 CloseHandle(pi.hThread); | |
4080 CloseHandle(pi.hProcess); | |
4081 | |
4082 /* Try to get input focus back. Doesn't always work though. */ | |
4083 PostMessage(hwnd, WM_SETFOCUS, 0, 0); | |
4084 | |
4085 return ret; | |
4086 } | |
2935 | 4087 |
4088 /* | |
4089 * Thread launched by the gui to send the current buffer data to the | |
4090 * process. This way avoid to hang up vim totally if the children | |
4091 * process take a long time to process the lines. | |
4092 */ | |
9750
0f4b76b2757a
commit https://github.com/vim/vim/commit/4c38d66d25e4ba433fe87283a4664425a3dbd529
Christian Brabandt <cb@256bit.org>
parents:
9740
diff
changeset
|
4093 static unsigned int __stdcall |
2935 | 4094 sub_process_writer(LPVOID param) |
4095 { | |
4096 HANDLE g_hChildStd_IN_Wr = param; | |
4097 linenr_T lnum = curbuf->b_op_start.lnum; | |
4098 DWORD len = 0; | |
4099 DWORD l; | |
4100 char_u *lp = ml_get(lnum); | |
4101 char_u *s; | |
4102 int written = 0; | |
4103 | |
4104 for (;;) | |
4105 { | |
4106 l = (DWORD)STRLEN(lp + written); | |
4107 if (l == 0) | |
4108 len = 0; | |
4109 else if (lp[written] == NL) | |
4110 { | |
4111 /* NL -> NUL translation */ | |
4112 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); | |
4113 } | |
4114 else | |
4115 { | |
4116 s = vim_strchr(lp + written, NL); | |
4117 WriteFile(g_hChildStd_IN_Wr, (char *)lp + written, | |
4118 s == NULL ? l : (DWORD)(s - (lp + written)), | |
4119 &len, NULL); | |
4120 } | |
4121 if (len == (int)l) | |
4122 { | |
4123 /* Finished a line, add a NL, unless this line should not have | |
4124 * one. */ | |
4125 if (lnum != curbuf->b_op_end.lnum | |
6933 | 4126 || (!curbuf->b_p_bin |
4127 && curbuf->b_p_fixeol) | |
2935 | 4128 || (lnum != curbuf->b_no_eol_lnum |
4129 && (lnum != curbuf->b_ml.ml_line_count | |
4130 || curbuf->b_p_eol))) | |
4131 { | |
4238 | 4132 WriteFile(g_hChildStd_IN_Wr, "\n", 1, (LPDWORD)&ignored, NULL); |
2935 | 4133 } |
4134 | |
4135 ++lnum; | |
4136 if (lnum > curbuf->b_op_end.lnum) | |
4137 break; | |
4138 | |
4139 lp = ml_get(lnum); | |
4140 written = 0; | |
4141 } | |
4142 else if (len > 0) | |
4143 written += len; | |
4144 } | |
4145 | |
4146 /* finished all the lines, close pipe */ | |
4147 CloseHandle(g_hChildStd_IN_Wr); | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4148 return 0; |
2935 | 4149 } |
4150 | |
4151 | |
4152 # define BUFLEN 100 /* length for buffer, stolen from unix version */ | |
4153 | |
4154 /* | |
4155 * This function read from the children's stdout and write the | |
4156 * data on screen or in the buffer accordingly. | |
4157 */ | |
4158 static void | |
4159 dump_pipe(int options, | |
4160 HANDLE g_hChildStd_OUT_Rd, | |
4161 garray_T *ga, | |
4162 char_u buffer[], | |
4163 DWORD *buffer_off) | |
4164 { | |
4165 DWORD availableBytes = 0; | |
4166 DWORD i; | |
4167 int ret; | |
4168 DWORD len; | |
4169 DWORD toRead; | |
4170 int repeatCount; | |
4171 | |
4172 /* we query the pipe to see if there is any data to read | |
4173 * to avoid to perform a blocking read */ | |
4174 ret = PeekNamedPipe(g_hChildStd_OUT_Rd, /* pipe to query */ | |
4175 NULL, /* optional buffer */ | |
3622 | 4176 0, /* buffer size */ |
2935 | 4177 NULL, /* number of read bytes */ |
4178 &availableBytes, /* available bytes total */ | |
4179 NULL); /* byteLeft */ | |
4180 | |
4181 repeatCount = 0; | |
4182 /* We got real data in the pipe, read it */ | |
3622 | 4183 while (ret != 0 && availableBytes > 0) |
2935 | 4184 { |
4185 repeatCount++; | |
4186 toRead = | |
4187 # ifdef FEAT_MBYTE | |
4188 (DWORD)(BUFLEN - *buffer_off); | |
4189 # else | |
4190 (DWORD)BUFLEN; | |
4191 # endif | |
4192 toRead = availableBytes < toRead ? availableBytes : toRead; | |
4193 ReadFile(g_hChildStd_OUT_Rd, buffer | |
4194 # ifdef FEAT_MBYTE | |
4195 + *buffer_off, toRead | |
4196 # else | |
4197 , toRead | |
4198 # endif | |
4199 , &len, NULL); | |
4200 | |
4201 /* If we haven't read anything, there is a problem */ | |
4202 if (len == 0) | |
4203 break; | |
4204 | |
4205 availableBytes -= len; | |
4206 | |
4207 if (options & SHELL_READ) | |
4208 { | |
4209 /* Do NUL -> NL translation, append NL separated | |
4210 * lines to the current buffer. */ | |
4211 for (i = 0; i < len; ++i) | |
4212 { | |
4213 if (buffer[i] == NL) | |
4214 append_ga_line(ga); | |
4215 else if (buffer[i] == NUL) | |
4216 ga_append(ga, NL); | |
4217 else | |
4218 ga_append(ga, buffer[i]); | |
4219 } | |
4220 } | |
4221 # ifdef FEAT_MBYTE | |
4222 else if (has_mbyte) | |
4223 { | |
4224 int l; | |
3030 | 4225 int c; |
4226 char_u *p; | |
2935 | 4227 |
4228 len += *buffer_off; | |
4229 buffer[len] = NUL; | |
4230 | |
4231 /* Check if the last character in buffer[] is | |
4232 * incomplete, keep these bytes for the next | |
4233 * round. */ | |
4234 for (p = buffer; p < buffer + len; p += l) | |
4235 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9762
diff
changeset
|
4236 l = MB_CPTR2LEN(p); |
2935 | 4237 if (l == 0) |
4238 l = 1; /* NUL byte? */ | |
4239 else if (MB_BYTE2LEN(*p) != l) | |
4240 break; | |
4241 } | |
4242 if (p == buffer) /* no complete character */ | |
4243 { | |
4244 /* avoid getting stuck at an illegal byte */ | |
4245 if (len >= 12) | |
4246 ++p; | |
4247 else | |
4248 { | |
4249 *buffer_off = len; | |
4250 return; | |
4251 } | |
4252 } | |
4253 c = *p; | |
4254 *p = NUL; | |
4255 msg_puts(buffer); | |
4256 if (p < buffer + len) | |
4257 { | |
4258 *p = c; | |
4259 *buffer_off = (DWORD)((buffer + len) - p); | |
4260 mch_memmove(buffer, p, *buffer_off); | |
4261 return; | |
4262 } | |
4263 *buffer_off = 0; | |
4264 } | |
4265 # endif /* FEAT_MBYTE */ | |
4266 else | |
4267 { | |
4268 buffer[len] = NUL; | |
4269 msg_puts(buffer); | |
4270 } | |
4271 | |
4272 windgoto(msg_row, msg_col); | |
4273 cursor_on(); | |
4274 out_flush(); | |
4275 } | |
4276 } | |
4277 | |
4278 /* | |
4279 * Version of system to use for windows NT > 5.0 (Win2K), use pipe | |
4280 * for communication and doesn't open any new window. | |
4281 */ | |
4282 static int | |
4283 mch_system_piped(char *cmd, int options) | |
4284 { | |
4285 STARTUPINFO si; | |
4286 PROCESS_INFORMATION pi; | |
4287 DWORD ret = 0; | |
4288 | |
4289 HANDLE g_hChildStd_IN_Rd = NULL; | |
4290 HANDLE g_hChildStd_IN_Wr = NULL; | |
4291 HANDLE g_hChildStd_OUT_Rd = NULL; | |
4292 HANDLE g_hChildStd_OUT_Wr = NULL; | |
4293 | |
4294 char_u buffer[BUFLEN + 1]; /* reading buffer + size */ | |
4295 DWORD len; | |
4296 | |
4297 /* buffer used to receive keys */ | |
4298 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ | |
4299 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4300 | |
4301 DWORD i; | |
4302 int c; | |
4303 int noread_cnt = 0; | |
4304 garray_T ga; | |
4305 int delay = 1; | |
4306 DWORD buffer_off = 0; /* valid bytes in buffer[] */ | |
3361 | 4307 char *p = NULL; |
2935 | 4308 |
4309 SECURITY_ATTRIBUTES saAttr; | |
4310 | |
4311 /* Set the bInheritHandle flag so pipe handles are inherited. */ | |
4312 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); | |
4313 saAttr.bInheritHandle = TRUE; | |
4314 saAttr.lpSecurityDescriptor = NULL; | |
4315 | |
4316 if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) | |
4317 /* Ensure the read handle to the pipe for STDOUT is not inherited. */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4318 || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) |
2935 | 4319 /* Create a pipe for the child process's STDIN. */ |
4320 || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0) | |
4321 /* Ensure the write handle to the pipe for STDIN is not inherited. */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4322 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) |
2935 | 4323 { |
4324 CloseHandle(g_hChildStd_IN_Rd); | |
4325 CloseHandle(g_hChildStd_IN_Wr); | |
4326 CloseHandle(g_hChildStd_OUT_Rd); | |
4327 CloseHandle(g_hChildStd_OUT_Wr); | |
4328 MSG_PUTS(_("\nCannot create pipes\n")); | |
4329 } | |
4330 | |
4331 si.cb = sizeof(si); | |
4332 si.lpReserved = NULL; | |
4333 si.lpDesktop = NULL; | |
4334 si.lpTitle = NULL; | |
4335 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; | |
4336 | |
4337 /* set-up our file redirection */ | |
4338 si.hStdError = g_hChildStd_OUT_Wr; | |
4339 si.hStdOutput = g_hChildStd_OUT_Wr; | |
4340 si.hStdInput = g_hChildStd_IN_Rd; | |
4341 si.wShowWindow = SW_HIDE; | |
4342 si.cbReserved2 = 0; | |
4343 si.lpReserved2 = NULL; | |
4344 | |
4345 if (options & SHELL_READ) | |
4346 ga_init2(&ga, 1, BUFLEN); | |
4347 | |
3361 | 4348 if (cmd != NULL) |
4349 { | |
4350 p = (char *)vim_strsave((char_u *)cmd); | |
4351 if (p != NULL) | |
4352 unescape_shellxquote((char_u *)p, p_sxe); | |
4353 else | |
4354 p = cmd; | |
4355 } | |
4356 | |
5547 | 4357 /* Now, run the command. |
4358 * About "Inherit handles" being TRUE: this command can be litigious, | |
4359 * handle inheritance was deactivated for pending temp file, but, if we | |
4360 * deactivate it, the pipes don't work for some reason. */ | |
4361 vim_create_process(p, TRUE, CREATE_DEFAULT_ERROR_MODE, &si, &pi); | |
2935 | 4362 |
3361 | 4363 if (p != cmd) |
4364 vim_free(p); | |
2935 | 4365 |
4366 /* Close our unused side of the pipes */ | |
4367 CloseHandle(g_hChildStd_IN_Rd); | |
4368 CloseHandle(g_hChildStd_OUT_Wr); | |
4369 | |
4370 if (options & SHELL_WRITE) | |
4371 { | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4372 HANDLE thread = (HANDLE) |
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4373 _beginthreadex(NULL, /* security attributes */ |
2935 | 4374 0, /* default stack size */ |
4375 sub_process_writer, /* function to be executed */ | |
4376 g_hChildStd_IN_Wr, /* parameter */ | |
4377 0, /* creation flag, start immediately */ | |
4378 NULL); /* we don't care about thread id */ | |
4379 CloseHandle(thread); | |
4380 g_hChildStd_IN_Wr = NULL; | |
4381 } | |
4382 | |
4383 /* Keep updating the window while waiting for the shell to finish. */ | |
4384 for (;;) | |
4385 { | |
4386 MSG msg; | |
4387 | |
5553 | 4388 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
2935 | 4389 { |
4390 TranslateMessage(&msg); | |
5553 | 4391 pDispatchMessage(&msg); |
2935 | 4392 } |
4393 | |
4394 /* write pipe information in the window */ | |
4395 if ((options & (SHELL_READ|SHELL_WRITE)) | |
4396 # ifdef FEAT_GUI | |
4397 || gui.in_use | |
4398 # endif | |
4399 ) | |
4400 { | |
4401 len = 0; | |
4402 if (!(options & SHELL_EXPAND) | |
4403 && ((options & | |
4404 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4405 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
4406 # ifdef FEAT_GUI | |
4407 || gui.in_use | |
4408 # endif | |
4409 ) | |
4410 && (ta_len > 0 || noread_cnt > 4)) | |
4411 { | |
4412 if (ta_len == 0) | |
4413 { | |
4414 /* Get extra characters when we don't have any. Reset the | |
4415 * counter and timer. */ | |
4416 noread_cnt = 0; | |
4417 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4418 } | |
4419 if (ta_len > 0 || len > 0) | |
4420 { | |
4421 /* | |
4422 * For pipes: Check for CTRL-C: send interrupt signal to | |
4423 * child. Check for CTRL-D: EOF, close pipe to child. | |
4424 */ | |
4425 if (len == 1 && cmd != NULL) | |
4426 { | |
4427 if (ta_buf[ta_len] == Ctrl_C) | |
4428 { | |
4429 /* Learn what exit code is expected, for | |
4430 * now put 9 as SIGKILL */ | |
4431 TerminateProcess(pi.hProcess, 9); | |
4432 } | |
4433 if (ta_buf[ta_len] == Ctrl_D) | |
4434 { | |
4435 CloseHandle(g_hChildStd_IN_Wr); | |
4436 g_hChildStd_IN_Wr = NULL; | |
4437 } | |
4438 } | |
4439 | |
4440 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
4441 for (i = ta_len; i < ta_len + len; ++i) | |
4442 { | |
4443 if (ta_buf[i] == CSI && len - i > 2) | |
4444 { | |
4445 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
4446 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
4447 { | |
4448 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
4449 (size_t)(len - i - 2)); | |
4450 if (c == K_DEL || c == K_KDEL) | |
4451 ta_buf[i] = DEL; | |
4452 else | |
4453 ta_buf[i] = Ctrl_H; | |
4454 len -= 2; | |
4455 } | |
4456 } | |
4457 else if (ta_buf[i] == '\r') | |
4458 ta_buf[i] = '\n'; | |
4459 # ifdef FEAT_MBYTE | |
4460 if (has_mbyte) | |
4461 i += (*mb_ptr2len_len)(ta_buf + i, | |
4462 ta_len + len - i) - 1; | |
4463 # endif | |
4464 } | |
4465 | |
4466 /* | |
4467 * For pipes: echo the typed characters. For a pty this | |
4468 * does not seem to work. | |
4469 */ | |
4470 for (i = ta_len; i < ta_len + len; ++i) | |
4471 { | |
4472 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4473 msg_putchar(ta_buf[i]); | |
4474 # ifdef FEAT_MBYTE | |
4475 else if (has_mbyte) | |
4476 { | |
4477 int l = (*mb_ptr2len)(ta_buf + i); | |
4478 | |
4479 msg_outtrans_len(ta_buf + i, l); | |
4480 i += l - 1; | |
4481 } | |
4482 # endif | |
4483 else | |
4484 msg_outtrans_len(ta_buf + i, 1); | |
4485 } | |
4486 windgoto(msg_row, msg_col); | |
4487 out_flush(); | |
4488 | |
4489 ta_len += len; | |
4490 | |
4491 /* | |
4492 * Write the characters to the child, unless EOF has been | |
4493 * typed for pipes. Write one character at a time, to | |
4494 * avoid losing too much typeahead. When writing buffer | |
4495 * lines, drop the typed characters (only check for | |
4496 * CTRL-C). | |
4497 */ | |
4498 if (options & SHELL_WRITE) | |
4499 ta_len = 0; | |
4500 else if (g_hChildStd_IN_Wr != NULL) | |
4501 { | |
4502 WriteFile(g_hChildStd_IN_Wr, (char*)ta_buf, | |
4503 1, &len, NULL); | |
4504 // if we are typing in, we want to keep things reactive | |
4505 delay = 1; | |
4506 if (len > 0) | |
4507 { | |
4508 ta_len -= len; | |
4509 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4510 } | |
4511 } | |
4512 } | |
4513 } | |
4514 } | |
4515 | |
4516 if (ta_len) | |
4517 ui_inchar_undo(ta_buf, ta_len); | |
4518 | |
4519 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4520 { | |
3030 | 4521 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4522 break; |
4523 } | |
4524 | |
4525 ++noread_cnt; | |
3030 | 4526 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4527 |
4528 /* We start waiting for a very short time and then increase it, so | |
4529 * that we respond quickly when the process is quick, and don't | |
4530 * consume too much overhead when it's slow. */ | |
4531 if (delay < 50) | |
4532 delay += 10; | |
4533 } | |
4534 | |
4535 /* Close the pipe */ | |
4536 CloseHandle(g_hChildStd_OUT_Rd); | |
4537 if (g_hChildStd_IN_Wr != NULL) | |
4538 CloseHandle(g_hChildStd_IN_Wr); | |
4539 | |
4540 WaitForSingleObject(pi.hProcess, INFINITE); | |
4541 | |
4542 /* Get the command exit code */ | |
4543 GetExitCodeProcess(pi.hProcess, &ret); | |
4544 | |
4545 if (options & SHELL_READ) | |
4546 { | |
4547 if (ga.ga_len > 0) | |
4548 { | |
4549 append_ga_line(&ga); | |
4550 /* remember that the NL was missing */ | |
4551 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; | |
4552 } | |
4553 else | |
4554 curbuf->b_no_eol_lnum = 0; | |
4555 ga_clear(&ga); | |
4556 } | |
4557 | |
4558 /* Close the handles to the subprocess, so that it goes away */ | |
4559 CloseHandle(pi.hThread); | |
4560 CloseHandle(pi.hProcess); | |
4561 | |
4562 return ret; | |
4563 } | |
4564 | |
4565 static int | |
4566 mch_system(char *cmd, int options) | |
4567 { | |
4568 /* if we can pipe and the shelltemp option is off */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4569 if (!p_stmp) |
2935 | 4570 return mch_system_piped(cmd, options); |
4571 else | |
4572 return mch_system_classic(cmd, options); | |
4573 } | |
7 | 4574 #else |
4575 | |
5547 | 4576 # ifdef FEAT_MBYTE |
4577 static int | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
4578 mch_system(char *cmd, int options) |
5547 | 4579 { |
4580 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
4581 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4582 WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL); |
5547 | 4583 if (wcmd != NULL) |
4584 { | |
4585 int ret = _wsystem(wcmd); | |
4586 vim_free(wcmd); | |
4587 return ret; | |
4588 } | |
4589 } | |
4590 return system(cmd); | |
4591 } | |
4592 # else | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
4593 # define mch_system(c, o) system(c) |
5547 | 4594 # endif |
7 | 4595 |
4596 #endif | |
4597 | |
4598 /* | |
4599 * Either execute a command by calling the shell or start a new shell | |
4600 */ | |
4601 int | |
4602 mch_call_shell( | |
26 | 4603 char_u *cmd, |
4604 int options) /* SHELL_*, see vim.h */ | |
7 | 4605 { |
4606 int x = 0; | |
4607 int tmode = cur_tmode; | |
4608 #ifdef FEAT_TITLE | |
6293 | 4609 char szShellTitle[512]; |
6290 | 4610 # ifdef FEAT_MBYTE |
6293 | 4611 int did_set_title = FALSE; |
4612 | |
6290 | 4613 /* Change the title to reflect that we are in a subshell. */ |
4614 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
4615 { | |
4616 WCHAR szShellTitle[512]; | |
4617 | |
4618 if (GetConsoleTitleW(szShellTitle, | |
4619 sizeof(szShellTitle)/sizeof(WCHAR) - 4) > 0) | |
4620 { | |
4621 if (cmd == NULL) | |
4622 wcscat(szShellTitle, L" :sh"); | |
4623 else | |
4624 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4625 WCHAR *wn = enc_to_utf16((char_u *)cmd, NULL); |
6290 | 4626 |
4627 if (wn != NULL) | |
4628 { | |
4629 wcscat(szShellTitle, L" - !"); | |
4630 if ((wcslen(szShellTitle) + wcslen(wn) < | |
4631 sizeof(szShellTitle)/sizeof(WCHAR))) | |
4632 wcscat(szShellTitle, wn); | |
4633 SetConsoleTitleW(szShellTitle); | |
4634 vim_free(wn); | |
6293 | 4635 did_set_title = TRUE; |
6290 | 4636 } |
4637 } | |
4638 } | |
4639 } | |
6293 | 4640 if (!did_set_title) |
4641 # endif | |
4642 /* Change the title to reflect that we are in a subshell. */ | |
4643 if (GetConsoleTitle(szShellTitle, sizeof(szShellTitle) - 4) > 0) | |
7 | 4644 { |
6293 | 4645 if (cmd == NULL) |
4646 strcat(szShellTitle, " :sh"); | |
4647 else | |
4648 { | |
4649 strcat(szShellTitle, " - !"); | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4650 if ((strlen(szShellTitle) + strlen((char *)cmd) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4651 < sizeof(szShellTitle))) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4652 strcat(szShellTitle, (char *)cmd); |
6293 | 4653 } |
4654 SetConsoleTitle(szShellTitle); | |
7 | 4655 } |
4656 #endif | |
4657 | |
4658 out_flush(); | |
4659 | |
4660 #ifdef MCH_WRITE_DUMP | |
4661 if (fdDump) | |
4662 { | |
4663 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options); | |
4664 fflush(fdDump); | |
4665 } | |
4666 #endif | |
4667 | |
4668 /* | |
4669 * Catch all deadly signals while running the external command, because a | |
4670 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us. | |
4671 */ | |
4672 signal(SIGINT, SIG_IGN); | |
4673 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4674 signal(SIGKILL, SIG_IGN); | |
4675 #else | |
4676 signal(SIGBREAK, SIG_IGN); | |
4677 #endif | |
4678 signal(SIGILL, SIG_IGN); | |
4679 signal(SIGFPE, SIG_IGN); | |
4680 signal(SIGSEGV, SIG_IGN); | |
4681 signal(SIGTERM, SIG_IGN); | |
4682 signal(SIGABRT, SIG_IGN); | |
4683 | |
4684 if (options & SHELL_COOKED) | |
4685 settmode(TMODE_COOK); /* set to normal mode */ | |
4686 | |
4687 if (cmd == NULL) | |
4688 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4689 x = mch_system((char *)p_sh, options); |
7 | 4690 } |
4691 else | |
4692 { | |
4693 /* we use "command" or "cmd" to start the shell; slow but easy */ | |
3363 | 4694 char_u *newcmd = NULL; |
4695 char_u *cmdbase = cmd; | |
4696 long_u cmdlen; | |
3361 | 4697 |
4698 /* Skip a leading ", ( and "(. */ | |
4699 if (*cmdbase == '"' ) | |
4700 ++cmdbase; | |
4701 if (*cmdbase == '(') | |
4702 ++cmdbase; | |
4703 | |
4704 if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5])) | |
4705 { | |
4706 STARTUPINFO si; | |
4707 PROCESS_INFORMATION pi; | |
4708 DWORD flags = CREATE_NEW_CONSOLE; | |
4709 char_u *p; | |
4710 | |
5627 | 4711 ZeroMemory(&si, sizeof(si)); |
3361 | 4712 si.cb = sizeof(si); |
4713 si.lpReserved = NULL; | |
4714 si.lpDesktop = NULL; | |
4715 si.lpTitle = NULL; | |
4716 si.dwFlags = 0; | |
4717 si.cbReserved2 = 0; | |
4718 si.lpReserved2 = NULL; | |
4719 | |
4720 cmdbase = skipwhite(cmdbase + 5); | |
4721 if ((STRNICMP(cmdbase, "/min", 4) == 0) | |
4722 && vim_iswhite(cmdbase[4])) | |
4723 { | |
4724 cmdbase = skipwhite(cmdbase + 4); | |
4725 si.dwFlags = STARTF_USESHOWWINDOW; | |
4726 si.wShowWindow = SW_SHOWMINNOACTIVE; | |
4727 } | |
4728 else if ((STRNICMP(cmdbase, "/b", 2) == 0) | |
4729 && vim_iswhite(cmdbase[2])) | |
4730 { | |
4731 cmdbase = skipwhite(cmdbase + 2); | |
4732 flags = CREATE_NO_WINDOW; | |
4733 si.dwFlags = STARTF_USESTDHANDLES; | |
4734 si.hStdInput = CreateFile("\\\\.\\NUL", // File name | |
3363 | 4735 GENERIC_READ, // Access flags |
3361 | 4736 0, // Share flags |
3363 | 4737 NULL, // Security att. |
4738 OPEN_EXISTING, // Open flags | |
4739 FILE_ATTRIBUTE_NORMAL, // File att. | |
4740 NULL); // Temp file | |
3361 | 4741 si.hStdOutput = si.hStdInput; |
4742 si.hStdError = si.hStdInput; | |
4743 } | |
4744 | |
4745 /* Remove a trailing ", ) and )" if they have a match | |
4746 * at the start of the command. */ | |
4747 if (cmdbase > cmd) | |
4748 { | |
4749 p = cmdbase + STRLEN(cmdbase); | |
4750 if (p > cmdbase && p[-1] == '"' && *cmd == '"') | |
4751 *--p = NUL; | |
4752 if (p > cmdbase && p[-1] == ')' | |
4753 && (*cmd =='(' || cmd[1] == '(')) | |
4754 *--p = NUL; | |
4755 } | |
4756 | |
3363 | 4757 newcmd = cmdbase; |
4758 unescape_shellxquote(cmdbase, p_sxe); | |
4759 | |
3361 | 4760 /* |
3363 | 4761 * If creating new console, arguments are passed to the |
4762 * 'cmd.exe' as-is. If it's not, arguments are not treated | |
4763 * correctly for current 'cmd.exe'. So unescape characters in | |
4764 * shellxescape except '|' for avoiding to be treated as | |
4765 * argument to them. Pass the arguments to sub-shell. | |
3361 | 4766 */ |
3363 | 4767 if (flags != CREATE_NEW_CONSOLE) |
4768 { | |
4769 char_u *subcmd; | |
3367 | 4770 char_u *cmd_shell = mch_getenv("COMSPEC"); |
4771 | |
4772 if (cmd_shell == NULL || *cmd_shell == NUL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4773 cmd_shell = (char_u *)default_shell(); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4774 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4775 subcmd = vim_strsave_escaped_ext(cmdbase, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4776 (char_u *)"|", '^', FALSE); |
3363 | 4777 if (subcmd != NULL) |
4778 { | |
4779 /* make "cmd.exe /c arguments" */ | |
4780 cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5; | |
4781 newcmd = lalloc(cmdlen, TRUE); | |
4782 if (newcmd != NULL) | |
4783 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s", | |
3367 | 4784 cmd_shell, subcmd); |
3363 | 4785 else |
4786 newcmd = cmdbase; | |
3367 | 4787 vim_free(subcmd); |
3363 | 4788 } |
4789 } | |
3361 | 4790 |
4791 /* | |
4792 * Now, start the command as a process, so that it doesn't | |
4793 * inherit our handles which causes unpleasant dangling swap | |
4794 * files if we exit before the spawned process | |
4795 */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4796 if (vim_create_process((char *)newcmd, FALSE, flags, &si, &pi)) |
3361 | 4797 x = 0; |
4798 else | |
4799 { | |
4800 x = -1; | |
4801 #ifdef FEAT_GUI_W32 | |
4802 EMSG(_("E371: Command not found")); | |
4803 #endif | |
4804 } | |
3363 | 4805 |
4806 if (newcmd != cmdbase) | |
4807 vim_free(newcmd); | |
4808 | |
5627 | 4809 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) |
3361 | 4810 { |
5627 | 4811 /* Close the handle to \\.\NUL created above. */ |
3361 | 4812 CloseHandle(si.hStdInput); |
4813 } | |
4814 /* Close the handles to the subprocess, so that it goes away */ | |
4815 CloseHandle(pi.hThread); | |
4816 CloseHandle(pi.hProcess); | |
4817 } | |
4818 else | |
4819 { | |
3363 | 4820 cmdlen = ( |
7 | 4821 #ifdef FEAT_GUI_W32 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4822 (!p_stmp ? 0 : STRLEN(vimrun_path)) + |
7 | 4823 #endif |
1569 | 4824 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10); |
4825 | |
3361 | 4826 newcmd = lalloc(cmdlen, TRUE); |
4827 if (newcmd != NULL) | |
7 | 4828 { |
4829 #if defined(FEAT_GUI_W32) | |
4830 if (need_vimrun_warning) | |
4831 { | |
10400
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4832 char *msg = _("VIMRUN.EXE not found in your $PATH.\n" |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4833 "External commands will not pause after completion.\n" |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4834 "See :help win32-vimrun for more information."); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4835 char *title = _("Vim Warning"); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4836 # ifdef FEAT_MBYTE |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4837 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4838 { |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4839 WCHAR *wmsg = enc_to_utf16((char_u *)msg, NULL); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4840 WCHAR *wtitle = enc_to_utf16((char_u *)title, NULL); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4841 |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4842 if (wmsg != NULL && wtitle != NULL) |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4843 MessageBoxW(NULL, wmsg, wtitle, MB_ICONWARNING); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4844 vim_free(wmsg); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4845 vim_free(wtitle); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4846 } |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4847 else |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4848 # endif |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4849 MessageBox(NULL, msg, title, MB_ICONWARNING); |
7 | 4850 need_vimrun_warning = FALSE; |
4851 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4852 if (!s_dont_use_vimrun && p_stmp) |
7 | 4853 /* Use vimrun to execute the command. It opens a console |
4854 * window, which can be closed without killing Vim. */ | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4855 vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s", |
7 | 4856 vimrun_path, |
4857 (msg_silent != 0 || (options & SHELL_DOOUT)) | |
4858 ? "-s " : "", | |
4859 p_sh, p_shcf, cmd); | |
4860 else | |
4861 #endif | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4862 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", |
1569 | 4863 p_sh, p_shcf, cmd); |
7 | 4864 x = mch_system((char *)newcmd, options); |
3361 | 4865 vim_free(newcmd); |
7 | 4866 } |
4867 } | |
4868 } | |
4869 | |
4870 if (tmode == TMODE_RAW) | |
4871 settmode(TMODE_RAW); /* set to raw mode */ | |
4872 | |
4873 /* Print the return value, unless "vimrun" was used. */ | |
4874 if (x != 0 && !(options & SHELL_SILENT) && !emsg_silent | |
4875 #if defined(FEAT_GUI_W32) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4876 && ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) |
7 | 4877 #endif |
4878 ) | |
4879 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4880 smsg((char_u *)_("shell returned %d"), x); |
7 | 4881 msg_putchar('\n'); |
4882 } | |
4883 #ifdef FEAT_TITLE | |
4884 resettitle(); | |
4885 #endif | |
4886 | |
4887 signal(SIGINT, SIG_DFL); | |
4888 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4889 signal(SIGKILL, SIG_DFL); | |
4890 #else | |
4891 signal(SIGBREAK, SIG_DFL); | |
4892 #endif | |
4893 signal(SIGILL, SIG_DFL); | |
4894 signal(SIGFPE, SIG_DFL); | |
4895 signal(SIGSEGV, SIG_DFL); | |
4896 signal(SIGTERM, SIG_DFL); | |
4897 signal(SIGABRT, SIG_DFL); | |
4898 | |
4899 return x; | |
4900 } | |
4901 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4902 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4903 static HANDLE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4904 job_io_file_open( |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4905 char_u *fname, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4906 DWORD dwDesiredAccess, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4907 DWORD dwShareMode, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4908 LPSECURITY_ATTRIBUTES lpSecurityAttributes, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4909 DWORD dwCreationDisposition, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4910 DWORD dwFlagsAndAttributes) |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4911 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4912 HANDLE h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4913 # ifdef FEAT_MBYTE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4914 WCHAR *wn = NULL; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4915 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4916 { |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4917 wn = enc_to_utf16(fname, NULL); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4918 if (wn != NULL) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4919 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4920 h = CreateFileW(wn, dwDesiredAccess, dwShareMode, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4921 lpSecurityAttributes, dwCreationDisposition, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4922 dwFlagsAndAttributes, NULL); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4923 vim_free(wn); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4924 } |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4925 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4926 if (wn == NULL) |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4927 # endif |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4928 h = CreateFile((LPCSTR)fname, dwDesiredAccess, dwShareMode, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4929 lpSecurityAttributes, dwCreationDisposition, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4930 dwFlagsAndAttributes, NULL); |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4931 return h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4932 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4933 |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4934 void |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8082
diff
changeset
|
4935 mch_start_job(char *cmd, job_T *job, jobopt_T *options) |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4936 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4937 STARTUPINFO si; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4938 PROCESS_INFORMATION pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4939 HANDLE jo; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4940 SECURITY_ATTRIBUTES saAttr; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4941 channel_T *channel = NULL; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4942 HANDLE ifd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4943 HANDLE ofd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4944 HANDLE efd[2]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4945 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4946 int use_null_for_in = options->jo_io[PART_IN] == JIO_NULL; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4947 int use_null_for_out = options->jo_io[PART_OUT] == JIO_NULL; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4948 int use_null_for_err = options->jo_io[PART_ERR] == JIO_NULL; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4949 int use_file_for_in = options->jo_io[PART_IN] == JIO_FILE; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4950 int use_file_for_out = options->jo_io[PART_OUT] == JIO_FILE; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4951 int use_file_for_err = options->jo_io[PART_ERR] == JIO_FILE; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4952 int use_out_for_err = options->jo_io[PART_ERR] == JIO_OUT; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4953 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4954 if (use_out_for_err && use_null_for_out) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4955 use_null_for_err = TRUE; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4956 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4957 ifd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4958 ifd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4959 ofd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4960 ofd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4961 efd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4962 efd[1] = INVALID_HANDLE_VALUE; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
4963 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4964 jo = CreateJobObject(NULL, NULL); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4965 if (jo == NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4966 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4967 job->jv_status = JOB_FAILED; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4968 goto failed; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4969 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4970 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
4971 ZeroMemory(&pi, sizeof(pi)); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4972 ZeroMemory(&si, sizeof(si)); |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4973 si.cb = sizeof(si); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4974 si.dwFlags |= STARTF_USESHOWWINDOW; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
4975 si.wShowWindow = SW_HIDE; |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4976 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4977 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4978 saAttr.bInheritHandle = TRUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4979 saAttr.lpSecurityDescriptor = NULL; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4980 |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
4981 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
4982 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
4983 char_u *fname = options->jo_io_name[PART_IN]; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4984 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4985 ifd[0] = job_io_file_open(fname, GENERIC_READ, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4986 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4987 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4988 if (ifd[0] == INVALID_HANDLE_VALUE) |
8443
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
4989 { |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
4990 EMSG2(_(e_notopen), fname); |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
4991 goto failed; |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
4992 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4993 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4994 else if (!use_null_for_in && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4995 (!CreatePipe(&ifd[0], &ifd[1], &saAttr, 0) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4996 || !SetHandleInformation(ifd[1], HANDLE_FLAG_INHERIT, 0))) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
4997 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
4998 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4999 if (use_file_for_out) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5000 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5001 char_u *fname = options->jo_io_name[PART_OUT]; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5002 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5003 ofd[1] = job_io_file_open(fname, GENERIC_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5004 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5005 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5006 if (ofd[1] == INVALID_HANDLE_VALUE) |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5007 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5008 EMSG2(_(e_notopen), fname); |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5009 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5010 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5011 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5012 else if (!use_null_for_out && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5013 (!CreatePipe(&ofd[0], &ofd[1], &saAttr, 0) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5014 || !SetHandleInformation(ofd[0], HANDLE_FLAG_INHERIT, 0))) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5015 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5016 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5017 if (use_file_for_err) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5018 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5019 char_u *fname = options->jo_io_name[PART_ERR]; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5020 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5021 efd[1] = job_io_file_open(fname, GENERIC_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5022 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5023 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5024 if (efd[1] == INVALID_HANDLE_VALUE) |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5025 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5026 EMSG2(_(e_notopen), fname); |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5027 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5028 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5029 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5030 else if (!use_out_for_err && !use_null_for_err && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5031 (!CreatePipe(&efd[0], &efd[1], &saAttr, 0) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5032 || !SetHandleInformation(efd[0], HANDLE_FLAG_INHERIT, 0))) |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5033 goto failed; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5034 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5035 si.dwFlags |= STARTF_USESTDHANDLES; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5036 si.hStdInput = ifd[0]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5037 si.hStdOutput = ofd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5038 si.hStdError = use_out_for_err ? ofd[1] : efd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5039 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5040 if (!use_null_for_in || !use_null_for_out || !use_null_for_err) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5041 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5042 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5043 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5044 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5045 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5046 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5047 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5048 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5049 channel = add_channel(); |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5050 if (channel == NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5051 goto failed; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5052 } |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5053 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5054 if (!vim_create_process(cmd, TRUE, |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5055 CREATE_SUSPENDED | |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5056 CREATE_DEFAULT_ERROR_MODE | |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5057 CREATE_NEW_PROCESS_GROUP | |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5058 CREATE_NEW_CONSOLE, |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5059 &si, &pi)) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5060 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5061 CloseHandle(jo); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5062 job->jv_status = JOB_FAILED; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5063 goto failed; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5064 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5065 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5066 if (!AssignProcessToJobObject(jo, pi.hProcess)) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5067 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5068 /* if failing, switch the way to terminate |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5069 * process with TerminateProcess. */ |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5070 CloseHandle(jo); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5071 jo = NULL; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5072 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5073 ResumeThread(pi.hThread); |
8479
9f63e4506c40
commit https://github.com/vim/vim/commit/75578a388d2aff59dc330ceccd8894c79b4bc735
Christian Brabandt <cb@256bit.org>
parents:
8471
diff
changeset
|
5074 CloseHandle(pi.hThread); |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5075 job->jv_proc_info = pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5076 job->jv_job_object = jo; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5077 job->jv_status = JOB_STARTED; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5078 |
10060
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5079 CloseHandle(ifd[0]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5080 CloseHandle(ofd[1]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5081 if (!use_out_for_err && !use_null_for_err) |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5082 CloseHandle(efd[1]); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5083 |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5084 job->jv_channel = channel; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5085 if (channel != NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5086 { |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5087 channel_set_pipes(channel, |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5088 use_file_for_in || use_null_for_in |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5089 ? INVALID_FD : (sock_T)ifd[1], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5090 use_file_for_out || use_null_for_out |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5091 ? INVALID_FD : (sock_T)ofd[0], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5092 use_out_for_err || use_file_for_err || use_null_for_err |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5093 ? INVALID_FD : (sock_T)efd[0]); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5094 channel_set_job(channel, job, options); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5095 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5096 return; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5097 |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5098 failed: |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5099 CloseHandle(ifd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5100 CloseHandle(ofd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5101 CloseHandle(efd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5102 CloseHandle(ifd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5103 CloseHandle(ofd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5104 CloseHandle(efd[1]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5105 channel_unref(channel); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5106 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5107 |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5108 char * |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5109 mch_job_status(job_T *job) |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5110 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5111 DWORD dwExitCode = 0; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5112 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5113 if (!GetExitCodeProcess(job->jv_proc_info.hProcess, &dwExitCode) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5114 || dwExitCode != STILL_ACTIVE) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5115 { |
8176
477c1d855698
commit https://github.com/vim/vim/commit/eab089d22f172ddd2d33367a998e68c2f1c6c989
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
5116 job->jv_exitval = (int)dwExitCode; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10317
diff
changeset
|
5117 if (job->jv_status < JOB_ENDED) |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5118 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5119 ch_log(job->jv_channel, "Job ended"); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5120 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5121 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5122 return "dead"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5123 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5124 return "run"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5125 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5126 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5127 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5128 mch_detect_ended_job(job_T *job_list) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5129 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5130 HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5131 job_T *jobArray[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5132 job_T *job = job_list; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5133 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5134 while (job != NULL) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5135 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5136 DWORD n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5137 DWORD result; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5138 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5139 for (n = 0; n < MAXIMUM_WAIT_OBJECTS |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5140 && job != NULL; job = job->jv_next) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5141 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5142 if (job->jv_status == JOB_STARTED) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5143 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5144 jobHandles[n] = job->jv_proc_info.hProcess; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5145 jobArray[n] = job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5146 ++n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5147 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5148 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5149 if (n == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5150 continue; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5151 result = WaitForMultipleObjects(n, jobHandles, FALSE, 0); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5152 if (result >= WAIT_OBJECT_0 && result < WAIT_OBJECT_0 + n) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5153 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5154 job_T *wait_job = jobArray[result - WAIT_OBJECT_0]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5155 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5156 if (STRCMP(mch_job_status(wait_job), "dead") == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5157 return wait_job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5158 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5159 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5160 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5161 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5162 |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5163 static BOOL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5164 terminate_all(HANDLE process, int code) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5165 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5166 PROCESSENTRY32 pe; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5167 HANDLE h = INVALID_HANDLE_VALUE; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5168 DWORD pid = GetProcessId(process); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5169 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5170 if (pid != 0) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5171 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5172 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5173 if (h != INVALID_HANDLE_VALUE) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5174 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5175 pe.dwSize = sizeof(PROCESSENTRY32); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5176 if (!Process32First(h, &pe)) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5177 goto theend; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5178 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5179 do |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5180 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5181 if (pe.th32ParentProcessID == pid) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5182 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5183 HANDLE ph = OpenProcess( |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5184 PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5185 if (ph != NULL) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5186 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5187 terminate_all(ph, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5188 CloseHandle(ph); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5189 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5190 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5191 } while (Process32Next(h, &pe)); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5192 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5193 CloseHandle(h); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5194 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5195 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5196 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5197 theend: |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5198 return TerminateProcess(process, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5199 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5200 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5201 /* |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5202 * Send a (deadly) signal to "job". |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5203 * Return FAIL if it didn't work. |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5204 */ |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5205 int |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5206 mch_stop_job(job_T *job, char_u *how) |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5207 { |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5208 int ret; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5209 |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5210 if (STRCMP(how, "term") == 0 || STRCMP(how, "kill") == 0 || *how == NUL) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5211 { |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5212 /* deadly signal */ |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5213 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5214 return TerminateJobObject(job->jv_job_object, 0) ? OK : FAIL; |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5215 return terminate_all(job->jv_proc_info.hProcess, 0) ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5216 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5217 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5218 if (!AttachConsole(job->jv_proc_info.dwProcessId)) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5219 return FAIL; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5220 ret = GenerateConsoleCtrlEvent( |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5221 STRCMP(how, "int") == 0 ? CTRL_C_EVENT : CTRL_BREAK_EVENT, |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5222 job->jv_proc_info.dwProcessId) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5223 ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5224 FreeConsole(); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5225 return ret; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5226 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5227 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5228 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5229 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5230 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5231 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5232 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5233 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5234 if (job->jv_status != JOB_FAILED) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5235 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5236 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5237 CloseHandle(job->jv_job_object); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5238 CloseHandle(job->jv_proc_info.hProcess); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5239 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5240 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5241 #endif |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5242 |
7 | 5243 |
5244 #ifndef FEAT_GUI_W32 | |
5245 | |
5246 /* | |
5247 * Start termcap mode | |
5248 */ | |
5249 static void | |
5250 termcap_mode_start(void) | |
5251 { | |
5252 DWORD cmodein; | |
5253 | |
5254 if (g_fTermcapMode) | |
5255 return; | |
5256 | |
5257 SaveConsoleBuffer(&g_cbNonTermcap); | |
5258 | |
5259 if (g_cbTermcap.IsValid) | |
5260 { | |
5261 /* | |
5262 * We've been in termcap mode before. Restore certain screen | |
5263 * characteristics, including the buffer size and the window | |
5264 * size. Since we will be redrawing the screen, we don't need | |
5265 * to restore the actual contents of the buffer. | |
5266 */ | |
5267 RestoreConsoleBuffer(&g_cbTermcap, FALSE); | |
5268 SetConsoleWindowInfo(g_hConOut, TRUE, &g_cbTermcap.Info.srWindow); | |
5269 Rows = g_cbTermcap.Info.dwSize.Y; | |
5270 Columns = g_cbTermcap.Info.dwSize.X; | |
5271 } | |
5272 else | |
5273 { | |
5274 /* | |
5275 * This is our first time entering termcap mode. Clear the console | |
5276 * screen buffer, and resize the buffer to match the current window | |
5277 * size. We will use this as the size of our editing environment. | |
5278 */ | |
5279 ClearConsoleBuffer(g_attrCurrent); | |
5280 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
5281 } | |
5282 | |
5283 #ifdef FEAT_TITLE | |
5284 resettitle(); | |
5285 #endif | |
5286 | |
5287 GetConsoleMode(g_hConIn, &cmodein); | |
5288 #ifdef FEAT_MOUSE | |
5289 if (g_fMouseActive) | |
5290 cmodein |= ENABLE_MOUSE_INPUT; | |
5291 else | |
5292 cmodein &= ~ENABLE_MOUSE_INPUT; | |
5293 #endif | |
5294 cmodein |= ENABLE_WINDOW_INPUT; | |
5295 SetConsoleMode(g_hConIn, cmodein); | |
5296 | |
5297 redraw_later_clear(); | |
5298 g_fTermcapMode = TRUE; | |
5299 } | |
5300 | |
5301 | |
5302 /* | |
5303 * End termcap mode | |
5304 */ | |
5305 static void | |
5306 termcap_mode_end(void) | |
5307 { | |
5308 DWORD cmodein; | |
5309 ConsoleBuffer *cb; | |
5310 COORD coord; | |
5311 DWORD dwDummy; | |
5312 | |
5313 if (!g_fTermcapMode) | |
5314 return; | |
5315 | |
5316 SaveConsoleBuffer(&g_cbTermcap); | |
5317 | |
5318 GetConsoleMode(g_hConIn, &cmodein); | |
5319 cmodein &= ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT); | |
5320 SetConsoleMode(g_hConIn, cmodein); | |
5321 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5322 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5323 cb = exiting ? &g_cbOrig : &g_cbNonTermcap; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5324 #else |
7 | 5325 cb = &g_cbNonTermcap; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5326 #endif |
7 | 5327 RestoreConsoleBuffer(cb, p_rs); |
5328 SetConsoleCursorInfo(g_hConOut, &g_cci); | |
5329 | |
5330 if (p_rs || exiting) | |
5331 { | |
5332 /* | |
5333 * Clear anything that happens to be on the current line. | |
5334 */ | |
5335 coord.X = 0; | |
5336 coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); | |
5337 FillConsoleOutputCharacter(g_hConOut, ' ', | |
5338 cb->Info.dwSize.X, coord, &dwDummy); | |
5339 /* | |
5340 * The following is just for aesthetics. If we are exiting without | |
5341 * restoring the screen, then we want to have a prompt string | |
5342 * appear at the bottom line. However, the command interpreter | |
5343 * seems to always advance the cursor one line before displaying | |
5344 * the prompt string, which causes the screen to scroll. To | |
5345 * counter this, move the cursor up one line before exiting. | |
5346 */ | |
5347 if (exiting && !p_rs) | |
5348 coord.Y--; | |
5349 /* | |
5350 * Position the cursor at the leftmost column of the desired row. | |
5351 */ | |
5352 SetConsoleCursorPosition(g_hConOut, coord); | |
5353 } | |
5354 | |
5355 g_fTermcapMode = FALSE; | |
5356 } | |
5357 #endif /* FEAT_GUI_W32 */ | |
5358 | |
5359 | |
5360 #ifdef FEAT_GUI_W32 | |
5361 void | |
5362 mch_write( | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
5363 char_u *s UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
5364 int len UNUSED) |
7 | 5365 { |
5366 /* never used */ | |
5367 } | |
5368 | |
5369 #else | |
5370 | |
5371 /* | |
5372 * clear `n' chars, starting from `coord' | |
5373 */ | |
5374 static void | |
5375 clear_chars( | |
5376 COORD coord, | |
5377 DWORD n) | |
5378 { | |
5379 DWORD dwDummy; | |
5380 | |
5381 FillConsoleOutputCharacter(g_hConOut, ' ', n, coord, &dwDummy); | |
5382 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, n, coord, &dwDummy); | |
5383 } | |
5384 | |
5385 | |
5386 /* | |
5387 * Clear the screen | |
5388 */ | |
5389 static void | |
5390 clear_screen(void) | |
5391 { | |
5392 g_coord.X = g_coord.Y = 0; | |
5393 clear_chars(g_coord, Rows * Columns); | |
5394 } | |
5395 | |
5396 | |
5397 /* | |
5398 * Clear to end of display | |
5399 */ | |
5400 static void | |
5401 clear_to_end_of_display(void) | |
5402 { | |
5403 clear_chars(g_coord, (Rows - g_coord.Y - 1) | |
5404 * Columns + (Columns - g_coord.X)); | |
5405 } | |
5406 | |
5407 | |
5408 /* | |
5409 * Clear to end of line | |
5410 */ | |
5411 static void | |
5412 clear_to_end_of_line(void) | |
5413 { | |
5414 clear_chars(g_coord, Columns - g_coord.X); | |
5415 } | |
5416 | |
5417 | |
5418 /* | |
5419 * Scroll the scroll region up by `cLines' lines | |
5420 */ | |
5421 static void | |
26 | 5422 scroll(unsigned cLines) |
7 | 5423 { |
5424 COORD oldcoord = g_coord; | |
5425 | |
5426 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); | |
5427 delete_lines(cLines); | |
5428 | |
5429 g_coord = oldcoord; | |
5430 } | |
5431 | |
5432 | |
5433 /* | |
5434 * Set the scroll region | |
5435 */ | |
5436 static void | |
5437 set_scroll_region( | |
5438 unsigned left, | |
5439 unsigned top, | |
5440 unsigned right, | |
5441 unsigned bottom) | |
5442 { | |
5443 if (left >= right | |
5444 || top >= bottom | |
5445 || right > (unsigned) Columns - 1 | |
5446 || bottom > (unsigned) Rows - 1) | |
5447 return; | |
5448 | |
5449 g_srScrollRegion.Left = left; | |
5450 g_srScrollRegion.Top = top; | |
5451 g_srScrollRegion.Right = right; | |
5452 g_srScrollRegion.Bottom = bottom; | |
5453 } | |
5454 | |
5455 | |
5456 /* | |
5457 * Insert `cLines' lines at the current cursor position | |
5458 */ | |
5459 static void | |
26 | 5460 insert_lines(unsigned cLines) |
7 | 5461 { |
5462 SMALL_RECT source; | |
5463 COORD dest; | |
5464 CHAR_INFO fill; | |
5465 | |
5466 dest.X = 0; | |
5467 dest.Y = g_coord.Y + cLines; | |
5468 | |
5469 source.Left = 0; | |
5470 source.Top = g_coord.Y; | |
5471 source.Right = g_srScrollRegion.Right; | |
5472 source.Bottom = g_srScrollRegion.Bottom - cLines; | |
5473 | |
5474 fill.Char.AsciiChar = ' '; | |
5475 fill.Attributes = g_attrCurrent; | |
5476 | |
5477 ScrollConsoleScreenBuffer(g_hConOut, &source, NULL, dest, &fill); | |
5478 | |
5479 /* Here we have to deal with a win32 console flake: If the scroll | |
5480 * region looks like abc and we scroll c to a and fill with d we get | |
5481 * cbd... if we scroll block c one line at a time to a, we get cdd... | |
5482 * vim expects cdd consistently... So we have to deal with that | |
5483 * here... (this also occurs scrolling the same way in the other | |
5484 * direction). */ | |
5485 | |
5486 if (source.Bottom < dest.Y) | |
5487 { | |
5488 COORD coord; | |
5489 | |
5490 coord.X = 0; | |
5491 coord.Y = source.Bottom; | |
5492 clear_chars(coord, Columns * (dest.Y - source.Bottom)); | |
5493 } | |
5494 } | |
5495 | |
5496 | |
5497 /* | |
5498 * Delete `cLines' lines at the current cursor position | |
5499 */ | |
5500 static void | |
26 | 5501 delete_lines(unsigned cLines) |
7 | 5502 { |
5503 SMALL_RECT source; | |
5504 COORD dest; | |
5505 CHAR_INFO fill; | |
5506 int nb; | |
5507 | |
5508 dest.X = 0; | |
5509 dest.Y = g_coord.Y; | |
5510 | |
5511 source.Left = 0; | |
5512 source.Top = g_coord.Y + cLines; | |
5513 source.Right = g_srScrollRegion.Right; | |
5514 source.Bottom = g_srScrollRegion.Bottom; | |
5515 | |
5516 fill.Char.AsciiChar = ' '; | |
5517 fill.Attributes = g_attrCurrent; | |
5518 | |
5519 ScrollConsoleScreenBuffer(g_hConOut, &source, NULL, dest, &fill); | |
5520 | |
5521 /* Here we have to deal with a win32 console flake: If the scroll | |
5522 * region looks like abc and we scroll c to a and fill with d we get | |
5523 * cbd... if we scroll block c one line at a time to a, we get cdd... | |
5524 * vim expects cdd consistently... So we have to deal with that | |
5525 * here... (this also occurs scrolling the same way in the other | |
5526 * direction). */ | |
5527 | |
5528 nb = dest.Y + (source.Bottom - source.Top) + 1; | |
5529 | |
5530 if (nb < source.Top) | |
5531 { | |
5532 COORD coord; | |
5533 | |
5534 coord.X = 0; | |
5535 coord.Y = nb; | |
5536 clear_chars(coord, Columns * (source.Top - nb)); | |
5537 } | |
5538 } | |
5539 | |
5540 | |
5541 /* | |
5542 * Set the cursor position | |
5543 */ | |
5544 static void | |
5545 gotoxy( | |
5546 unsigned x, | |
5547 unsigned y) | |
5548 { | |
5549 if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) | |
5550 return; | |
5551 | |
5552 /* external cursor coords are 1-based; internal are 0-based */ | |
5553 g_coord.X = x - 1; | |
5554 g_coord.Y = y - 1; | |
5555 SetConsoleCursorPosition(g_hConOut, g_coord); | |
5556 } | |
5557 | |
5558 | |
5559 /* | |
5560 * Set the current text attribute = (foreground | background) | |
5561 * See ../doc/os_win32.txt for the numbers. | |
5562 */ | |
5563 static void | |
26 | 5564 textattr(WORD wAttr) |
7 | 5565 { |
6710 | 5566 g_attrCurrent = wAttr & 0xff; |
7 | 5567 |
5568 SetConsoleTextAttribute(g_hConOut, wAttr); | |
5569 } | |
5570 | |
5571 | |
5572 static void | |
26 | 5573 textcolor(WORD wAttr) |
7 | 5574 { |
6710 | 5575 g_attrCurrent = (g_attrCurrent & 0xf0) + (wAttr & 0x0f); |
7 | 5576 |
5577 SetConsoleTextAttribute(g_hConOut, g_attrCurrent); | |
5578 } | |
5579 | |
5580 | |
5581 static void | |
26 | 5582 textbackground(WORD wAttr) |
7 | 5583 { |
6710 | 5584 g_attrCurrent = (g_attrCurrent & 0x0f) + ((wAttr & 0x0f) << 4); |
7 | 5585 |
5586 SetConsoleTextAttribute(g_hConOut, g_attrCurrent); | |
5587 } | |
5588 | |
5589 | |
5590 /* | |
5591 * restore the default text attribute (whatever we started with) | |
5592 */ | |
5593 static void | |
26 | 5594 normvideo(void) |
7 | 5595 { |
5596 textattr(g_attrDefault); | |
5597 } | |
5598 | |
5599 | |
5600 static WORD g_attrPreStandout = 0; | |
5601 | |
5602 /* | |
5603 * Make the text standout, by brightening it | |
5604 */ | |
5605 static void | |
5606 standout(void) | |
5607 { | |
5608 g_attrPreStandout = g_attrCurrent; | |
5609 textattr((WORD) (g_attrCurrent|FOREGROUND_INTENSITY|BACKGROUND_INTENSITY)); | |
5610 } | |
5611 | |
5612 | |
5613 /* | |
5614 * Turn off standout mode | |
5615 */ | |
5616 static void | |
26 | 5617 standend(void) |
7 | 5618 { |
5619 if (g_attrPreStandout) | |
5620 { | |
5621 textattr(g_attrPreStandout); | |
5622 g_attrPreStandout = 0; | |
5623 } | |
5624 } | |
5625 | |
5626 | |
5627 /* | |
1199 | 5628 * Set normal fg/bg color, based on T_ME. Called when t_me has been set. |
7 | 5629 */ |
5630 void | |
26 | 5631 mch_set_normal_colors(void) |
7 | 5632 { |
5633 char_u *p; | |
5634 int n; | |
5635 | |
5636 cterm_normal_fg_color = (g_attrDefault & 0xf) + 1; | |
5637 cterm_normal_bg_color = ((g_attrDefault >> 4) & 0xf) + 1; | |
5638 if (T_ME[0] == ESC && T_ME[1] == '|') | |
5639 { | |
5640 p = T_ME + 2; | |
5641 n = getdigits(&p); | |
5642 if (*p == 'm' && n > 0) | |
5643 { | |
5644 cterm_normal_fg_color = (n & 0xf) + 1; | |
5645 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1; | |
5646 } | |
5647 } | |
5648 } | |
5649 | |
5650 | |
5651 /* | |
5652 * visual bell: flash the screen | |
5653 */ | |
5654 static void | |
26 | 5655 visual_bell(void) |
7 | 5656 { |
5657 COORD coordOrigin = {0, 0}; | |
5658 WORD attrFlash = ~g_attrCurrent & 0xff; | |
5659 | |
5660 DWORD dwDummy; | |
5661 LPWORD oldattrs = (LPWORD)alloc(Rows * Columns * sizeof(WORD)); | |
5662 | |
5663 if (oldattrs == NULL) | |
5664 return; | |
5665 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
5666 coordOrigin, &dwDummy); | |
5667 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, | |
5668 coordOrigin, &dwDummy); | |
5669 | |
5670 Sleep(15); /* wait for 15 msec */ | |
5671 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
5672 coordOrigin, &dwDummy); | |
5673 vim_free(oldattrs); | |
5674 } | |
5675 | |
5676 | |
5677 /* | |
5678 * Make the cursor visible or invisible | |
5679 */ | |
5680 static void | |
26 | 5681 cursor_visible(BOOL fVisible) |
7 | 5682 { |
5683 s_cursor_visible = fVisible; | |
5684 #ifdef MCH_CURSOR_SHAPE | |
5685 mch_update_cursor(); | |
5686 #endif | |
5687 } | |
5688 | |
5689 | |
5690 /* | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5691 * write `cbToWrite' bytes in `pchBuf' to the screen |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5692 * Returns the number of bytes actually written (at least one). |
7 | 5693 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5694 static DWORD |
7 | 5695 write_chars( |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5696 char_u *pchBuf, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5697 DWORD cbToWrite) |
7 | 5698 { |
5699 COORD coord = g_coord; | |
5700 DWORD written; | |
5701 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5702 #ifdef FEAT_MBYTE |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5703 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5704 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5705 static WCHAR *unicodebuf = NULL; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5706 static int unibuflen = 0; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5707 int length; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5708 DWORD n, cchwritten, cells; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5709 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5710 length = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pchBuf, cbToWrite, 0, 0); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5711 if (unicodebuf == NULL || length > unibuflen) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5712 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5713 vim_free(unicodebuf); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5714 unicodebuf = (WCHAR *)lalloc(length * sizeof(WCHAR), FALSE); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5715 unibuflen = length; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5716 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5717 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pchBuf, cbToWrite, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5718 unicodebuf, unibuflen); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5719 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5720 cells = mb_string2cells(pchBuf, cbToWrite); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5721 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cells, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5722 coord, &written); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5723 /* When writing fails or didn't write a single character, pretend one |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5724 * character was written, otherwise we get stuck. */ |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5725 if (WriteConsoleOutputCharacterW(g_hConOut, unicodebuf, length, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5726 coord, &cchwritten) == 0 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5727 || cchwritten == 0) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5728 cchwritten = 1; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5729 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5730 if (cchwritten == length) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5731 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5732 written = cbToWrite; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5733 g_coord.X += (SHORT)cells; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5734 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5735 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5736 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5737 char_u *p = pchBuf; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5738 for (n = 0; n < cchwritten; n++) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5739 mb_cptr_adv(p); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5740 written = p - pchBuf; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5741 g_coord.X += (SHORT)mb_string2cells(pchBuf, written); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5742 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5743 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5744 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5745 #endif |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5746 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5747 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cbToWrite, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5748 coord, &written); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5749 /* When writing fails or didn't write a single character, pretend one |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5750 * character was written, otherwise we get stuck. */ |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5751 if (WriteConsoleOutputCharacter(g_hConOut, (LPCSTR)pchBuf, cbToWrite, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5752 coord, &written) == 0 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5753 || written == 0) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5754 written = 1; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5755 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5756 g_coord.X += (SHORT) written; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5757 } |
7 | 5758 |
5759 while (g_coord.X > g_srScrollRegion.Right) | |
5760 { | |
5761 g_coord.X -= (SHORT) Columns; | |
5762 if (g_coord.Y < g_srScrollRegion.Bottom) | |
5763 g_coord.Y++; | |
5764 } | |
5765 | |
5766 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
5767 | |
5768 return written; | |
5769 } | |
5770 | |
5771 | |
5772 /* | |
5773 * mch_write(): write the output buffer to the screen, translating ESC | |
5774 * sequences into calls to console output routines. | |
5775 */ | |
5776 void | |
5777 mch_write( | |
5778 char_u *s, | |
5779 int len) | |
5780 { | |
5781 s[len] = NUL; | |
5782 | |
5783 if (!term_console) | |
5784 { | |
5785 write(1, s, (unsigned)len); | |
5786 return; | |
5787 } | |
5788 | |
5789 /* translate ESC | sequences into faked bios calls */ | |
5790 while (len--) | |
5791 { | |
5792 /* optimization: use one single write_chars for runs of text, | |
5793 * rather than once per character It ain't curses, but it helps. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
5794 DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033"); |
7 | 5795 |
5796 if (p_wd) | |
5797 { | |
5798 WaitForChar(p_wd); | |
5799 if (prefix != 0) | |
5800 prefix = 1; | |
5801 } | |
5802 | |
5803 if (prefix != 0) | |
5804 { | |
5805 DWORD nWritten; | |
5806 | |
5807 nWritten = write_chars(s, prefix); | |
5808 #ifdef MCH_WRITE_DUMP | |
5809 if (fdDump) | |
5810 { | |
5811 fputc('>', fdDump); | |
5812 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
5813 fputs("<\n", fdDump); | |
5814 } | |
5815 #endif | |
5816 len -= (nWritten - 1); | |
5817 s += nWritten; | |
5818 } | |
5819 else if (s[0] == '\n') | |
5820 { | |
5821 /* \n, newline: go to the beginning of the next line or scroll */ | |
5822 if (g_coord.Y == g_srScrollRegion.Bottom) | |
5823 { | |
5824 scroll(1); | |
5825 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1); | |
5826 } | |
5827 else | |
5828 { | |
5829 gotoxy(g_srScrollRegion.Left + 1, g_coord.Y + 2); | |
5830 } | |
5831 #ifdef MCH_WRITE_DUMP | |
5832 if (fdDump) | |
5833 fputs("\\n\n", fdDump); | |
5834 #endif | |
5835 s++; | |
5836 } | |
5837 else if (s[0] == '\r') | |
5838 { | |
5839 /* \r, carriage return: go to beginning of line */ | |
5840 gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1); | |
5841 #ifdef MCH_WRITE_DUMP | |
5842 if (fdDump) | |
5843 fputs("\\r\n", fdDump); | |
5844 #endif | |
5845 s++; | |
5846 } | |
5847 else if (s[0] == '\b') | |
5848 { | |
5849 /* \b, backspace: move cursor one position left */ | |
5850 if (g_coord.X > g_srScrollRegion.Left) | |
5851 g_coord.X--; | |
5852 else if (g_coord.Y > g_srScrollRegion.Top) | |
5853 { | |
5854 g_coord.X = g_srScrollRegion.Right; | |
5855 g_coord.Y--; | |
5856 } | |
5857 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
5858 #ifdef MCH_WRITE_DUMP | |
5859 if (fdDump) | |
5860 fputs("\\b\n", fdDump); | |
5861 #endif | |
5862 s++; | |
5863 } | |
5864 else if (s[0] == '\a') | |
5865 { | |
5866 /* \a, bell */ | |
5867 MessageBeep(0xFFFFFFFF); | |
5868 #ifdef MCH_WRITE_DUMP | |
5869 if (fdDump) | |
5870 fputs("\\a\n", fdDump); | |
5871 #endif | |
5872 s++; | |
5873 } | |
5874 else if (s[0] == ESC && len >= 3-1 && s[1] == '|') | |
5875 { | |
5876 #ifdef MCH_WRITE_DUMP | |
24 | 5877 char_u *old_s = s; |
7 | 5878 #endif |
24 | 5879 char_u *p; |
5880 int arg1 = 0, arg2 = 0; | |
7 | 5881 |
5882 switch (s[2]) | |
5883 { | |
5884 /* one or two numeric arguments, separated by ';' */ | |
5885 | |
5886 case '0': case '1': case '2': case '3': case '4': | |
5887 case '5': case '6': case '7': case '8': case '9': | |
5888 p = s + 2; | |
5889 arg1 = getdigits(&p); /* no check for length! */ | |
5890 if (p > s + len) | |
5891 break; | |
5892 | |
5893 if (*p == ';') | |
5894 { | |
5895 ++p; | |
5896 arg2 = getdigits(&p); /* no check for length! */ | |
5897 if (p > s + len) | |
5898 break; | |
5899 | |
5900 if (*p == 'H') | |
5901 gotoxy(arg2, arg1); | |
5902 else if (*p == 'r') | |
5903 set_scroll_region(0, arg1 - 1, Columns - 1, arg2 - 1); | |
5904 } | |
5905 else if (*p == 'A') | |
5906 { | |
5907 /* move cursor up arg1 lines in same column */ | |
5908 gotoxy(g_coord.X + 1, | |
5909 max(g_srScrollRegion.Top, g_coord.Y - arg1) + 1); | |
5910 } | |
5911 else if (*p == 'C') | |
5912 { | |
5913 /* move cursor right arg1 columns in same line */ | |
5914 gotoxy(min(g_srScrollRegion.Right, g_coord.X + arg1) + 1, | |
5915 g_coord.Y + 1); | |
5916 } | |
5917 else if (*p == 'H') | |
5918 { | |
5919 gotoxy(1, arg1); | |
5920 } | |
5921 else if (*p == 'L') | |
5922 { | |
5923 insert_lines(arg1); | |
5924 } | |
5925 else if (*p == 'm') | |
5926 { | |
5927 if (arg1 == 0) | |
5928 normvideo(); | |
5929 else | |
5930 textattr((WORD) arg1); | |
5931 } | |
5932 else if (*p == 'f') | |
5933 { | |
5934 textcolor((WORD) arg1); | |
5935 } | |
5936 else if (*p == 'b') | |
5937 { | |
5938 textbackground((WORD) arg1); | |
5939 } | |
5940 else if (*p == 'M') | |
5941 { | |
5942 delete_lines(arg1); | |
5943 } | |
5944 | |
835 | 5945 len -= (int)(p - s); |
7 | 5946 s = p + 1; |
5947 break; | |
5948 | |
5949 | |
5950 /* Three-character escape sequences */ | |
5951 | |
5952 case 'A': | |
5953 /* move cursor up one line in same column */ | |
5954 gotoxy(g_coord.X + 1, | |
5955 max(g_srScrollRegion.Top, g_coord.Y - 1) + 1); | |
5956 goto got3; | |
5957 | |
5958 case 'B': | |
5959 visual_bell(); | |
5960 goto got3; | |
5961 | |
5962 case 'C': | |
5963 /* move cursor right one column in same line */ | |
5964 gotoxy(min(g_srScrollRegion.Right, g_coord.X + 1) + 1, | |
5965 g_coord.Y + 1); | |
5966 goto got3; | |
5967 | |
5968 case 'E': | |
5969 termcap_mode_end(); | |
5970 goto got3; | |
5971 | |
5972 case 'F': | |
5973 standout(); | |
5974 goto got3; | |
5975 | |
5976 case 'f': | |
5977 standend(); | |
5978 goto got3; | |
5979 | |
5980 case 'H': | |
5981 gotoxy(1, 1); | |
5982 goto got3; | |
5983 | |
5984 case 'j': | |
5985 clear_to_end_of_display(); | |
5986 goto got3; | |
5987 | |
5988 case 'J': | |
5989 clear_screen(); | |
5990 goto got3; | |
5991 | |
5992 case 'K': | |
5993 clear_to_end_of_line(); | |
5994 goto got3; | |
5995 | |
5996 case 'L': | |
5997 insert_lines(1); | |
5998 goto got3; | |
5999 | |
6000 case 'M': | |
6001 delete_lines(1); | |
6002 goto got3; | |
6003 | |
6004 case 'S': | |
6005 termcap_mode_start(); | |
6006 goto got3; | |
6007 | |
6008 case 'V': | |
6009 cursor_visible(TRUE); | |
6010 goto got3; | |
6011 | |
6012 case 'v': | |
6013 cursor_visible(FALSE); | |
6014 goto got3; | |
6015 | |
6016 got3: | |
6017 s += 3; | |
6018 len -= 2; | |
6019 } | |
6020 | |
6021 #ifdef MCH_WRITE_DUMP | |
6022 if (fdDump) | |
6023 { | |
6024 fputs("ESC | ", fdDump); | |
6025 fwrite(old_s + 2, sizeof(char_u), s - old_s - 2, fdDump); | |
6026 fputc('\n', fdDump); | |
6027 } | |
6028 #endif | |
6029 } | |
6030 else | |
6031 { | |
6032 /* Write a single character */ | |
6033 DWORD nWritten; | |
6034 | |
6035 nWritten = write_chars(s, 1); | |
6036 #ifdef MCH_WRITE_DUMP | |
6037 if (fdDump) | |
6038 { | |
6039 fputc('>', fdDump); | |
6040 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6041 fputs("<\n", fdDump); | |
6042 } | |
6043 #endif | |
6044 | |
6045 len -= (nWritten - 1); | |
6046 s += nWritten; | |
6047 } | |
6048 } | |
6049 | |
6050 #ifdef MCH_WRITE_DUMP | |
6051 if (fdDump) | |
6052 fflush(fdDump); | |
6053 #endif | |
6054 } | |
6055 | |
6056 #endif /* FEAT_GUI_W32 */ | |
6057 | |
6058 | |
6059 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
6060 * Delay for "msec" milliseconds. |
7 | 6061 */ |
6062 void | |
6063 mch_delay( | |
6064 long msec, | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
6065 int ignoreinput UNUSED) |
7 | 6066 { |
6067 #ifdef FEAT_GUI_W32 | |
6068 Sleep((int)msec); /* never wait for input */ | |
14 | 6069 #else /* Console */ |
7 | 6070 if (ignoreinput) |
14 | 6071 # ifdef FEAT_MZSCHEME |
6072 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq) | |
6073 { | |
6074 int towait = p_mzq; | |
6075 | |
6076 /* if msec is large enough, wait by portions in p_mzq */ | |
6077 while (msec > 0) | |
6078 { | |
6079 mzvim_check_threads(); | |
6080 if (msec < towait) | |
6081 towait = msec; | |
6082 Sleep(towait); | |
6083 msec -= towait; | |
6084 } | |
6085 } | |
6086 else | |
6087 # endif | |
6088 Sleep((int)msec); | |
7 | 6089 else |
6090 WaitForChar(msec); | |
6091 #endif | |
6092 } | |
6093 | |
6094 | |
6095 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6096 * This version of remove is not scared by a readonly (backup) file. |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6097 * This can also remove a symbolic link like Unix. |
7 | 6098 * Return 0 for success, -1 for failure. |
6099 */ | |
6100 int | |
6101 mch_remove(char_u *name) | |
6102 { | |
6103 #ifdef FEAT_MBYTE | |
6104 WCHAR *wn = NULL; | |
6105 int n; | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6106 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6107 |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6108 /* |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6109 * On Windows, deleting a directory's symbolic link is done by |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6110 * RemoveDirectory(): mch_rmdir. It seems unnatural, but it is fact. |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6111 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6112 if (mch_isdir(name) && mch_is_symbolic_link(name)) |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6113 return mch_rmdir(name); |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6114 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6115 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6116 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6117 #ifdef FEAT_MBYTE |
7 | 6118 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
6119 { | |
1752 | 6120 wn = enc_to_utf16(name, NULL); |
7 | 6121 if (wn != NULL) |
6122 { | |
6123 n = DeleteFileW(wn) ? 0 : -1; | |
6124 vim_free(wn); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6125 return n; |
7 | 6126 } |
6127 } | |
6128 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6129 return DeleteFile((LPCSTR)name) ? 0 : -1; |
7 | 6130 } |
6131 | |
6132 | |
6133 /* | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6134 * Check for an "interrupt signal": CTRL-break or CTRL-C. |
7 | 6135 */ |
6136 void | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6137 mch_breakcheck(int force) |
7 | 6138 { |
6139 #ifndef FEAT_GUI_W32 /* never used */ | |
6140 if (g_fCtrlCPressed || g_fCBrkPressed) | |
6141 { | |
6142 g_fCtrlCPressed = g_fCBrkPressed = FALSE; | |
6143 got_int = TRUE; | |
6144 } | |
6145 #endif | |
6146 } | |
6147 | |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6148 /* physical RAM to leave for the OS */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6149 #define WINNT_RESERVE_BYTES (256*1024*1024) |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6150 |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6151 /* |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6152 * How much main memory in KiB that can be used by VIM. |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6153 */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6154 long_u |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
6155 mch_total_mem(int special UNUSED) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6156 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6157 MEMORYSTATUSEX ms; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6158 |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6159 PlatformId(); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6160 /* Need to use GlobalMemoryStatusEx() when there is more memory than |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6161 * what fits in 32 bits. But it's not always available. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6162 ms.dwLength = sizeof(MEMORYSTATUSEX); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6163 GlobalMemoryStatusEx(&ms); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6164 if (ms.ullAvailVirtual < ms.ullTotalPhys) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6165 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6166 /* Process address space fits in physical RAM, use all of it. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6167 return (long_u)(ms.ullAvailVirtual / 1024); |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6168 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6169 if (ms.ullTotalPhys <= WINNT_RESERVE_BYTES) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6170 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6171 /* Catch old NT box or perverse hardware setup. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6172 return (long_u)((ms.ullTotalPhys / 2) / 1024); |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6173 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6174 /* Use physical RAM less reserve for OS + data. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6175 return (long_u)((ms.ullTotalPhys - WINNT_RESERVE_BYTES) / 1024); |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6176 } |
7 | 6177 |
6178 #ifdef FEAT_MBYTE | |
6179 /* | |
6180 * Same code as below, but with wide functions and no comments. | |
6181 * Return 0 for success, non-zero for failure. | |
6182 */ | |
6183 int | |
6184 mch_wrename(WCHAR *wold, WCHAR *wnew) | |
6185 { | |
6186 WCHAR *p; | |
6187 int i; | |
6188 WCHAR szTempFile[_MAX_PATH + 1]; | |
6189 WCHAR szNewPath[_MAX_PATH + 1]; | |
6190 HANDLE hf; | |
6191 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6192 p = wold; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6193 for (i = 0; wold[i] != NUL; ++i) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6194 if ((wold[i] == '/' || wold[i] == '\\' || wold[i] == ':') |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6195 && wold[i + 1] != 0) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6196 p = wold + i + 1; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6197 if ((int)(wold + i - p) < 8 || p[6] != '~') |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6198 return (MoveFileW(wold, wnew) == 0); |
7 | 6199 |
6200 if (GetFullPathNameW(wnew, _MAX_PATH, szNewPath, &p) == 0 || p == NULL) | |
6201 return -1; | |
6202 *p = NUL; | |
6203 | |
6204 if (GetTempFileNameW(szNewPath, L"VIM", 0, szTempFile) == 0) | |
6205 return -2; | |
6206 | |
6207 if (!DeleteFileW(szTempFile)) | |
6208 return -3; | |
6209 | |
6210 if (!MoveFileW(wold, szTempFile)) | |
6211 return -4; | |
6212 | |
6213 if ((hf = CreateFileW(wold, GENERIC_WRITE, 0, NULL, CREATE_NEW, | |
6214 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) | |
6215 return -5; | |
6216 if (!CloseHandle(hf)) | |
6217 return -6; | |
6218 | |
6219 if (!MoveFileW(szTempFile, wnew)) | |
6220 { | |
6221 (void)MoveFileW(szTempFile, wold); | |
6222 return -7; | |
6223 } | |
6224 | |
6225 DeleteFileW(szTempFile); | |
6226 | |
6227 if (!DeleteFileW(wold)) | |
6228 return -8; | |
6229 | |
6230 return 0; | |
6231 } | |
6232 #endif | |
6233 | |
6234 | |
6235 /* | |
6236 * mch_rename() works around a bug in rename (aka MoveFile) in | |
6237 * Windows 95: rename("foo.bar", "foo.bar~") will generate a | |
6238 * file whose short file name is "FOO.BAR" (its long file name will | |
6239 * be correct: "foo.bar~"). Because a file can be accessed by | |
6240 * either its SFN or its LFN, "foo.bar" has effectively been | |
6241 * renamed to "foo.bar", which is not at all what was wanted. This | |
6242 * seems to happen only when renaming files with three-character | |
6243 * extensions by appending a suffix that does not include ".". | |
6244 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR". | |
6245 * | |
6246 * There is another problem, which isn't really a bug but isn't right either: | |
6247 * When renaming "abcdef~1.txt" to "abcdef~1.txt~", the short name can be | |
6248 * "abcdef~1.txt" again. This has been reported on Windows NT 4.0 with | |
6249 * service pack 6. Doesn't seem to happen on Windows 98. | |
6250 * | |
6251 * Like rename(), returns 0 upon success, non-zero upon failure. | |
6252 * Should probably set errno appropriately when errors occur. | |
6253 */ | |
6254 int | |
6255 mch_rename( | |
6256 const char *pszOldFile, | |
6257 const char *pszNewFile) | |
6258 { | |
6259 char szTempFile[_MAX_PATH+1]; | |
6260 char szNewPath[_MAX_PATH+1]; | |
6261 char *pszFilePart; | |
6262 HANDLE hf; | |
6263 #ifdef FEAT_MBYTE | |
6264 WCHAR *wold = NULL; | |
6265 WCHAR *wnew = NULL; | |
6266 int retval = -1; | |
6267 | |
6268 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
6269 { | |
1752 | 6270 wold = enc_to_utf16((char_u *)pszOldFile, NULL); |
6271 wnew = enc_to_utf16((char_u *)pszNewFile, NULL); | |
7 | 6272 if (wold != NULL && wnew != NULL) |
6273 retval = mch_wrename(wold, wnew); | |
6274 vim_free(wold); | |
6275 vim_free(wnew); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6276 return retval; |
7 | 6277 } |
6278 #endif | |
6279 | |
6280 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6281 * No need to play tricks unless the file name contains a "~" as the |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6282 * seventh character. |
7 | 6283 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6284 pszFilePart = (char *)gettail((char_u *)pszOldFile); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6285 if (STRLEN(pszFilePart) < 8 || pszFilePart[6] != '~') |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6286 return rename(pszOldFile, pszNewFile); |
7 | 6287 |
6288 /* Get base path of new file name. Undocumented feature: If pszNewFile is | |
6289 * a directory, no error is returned and pszFilePart will be NULL. */ | |
6290 if (GetFullPathName(pszNewFile, _MAX_PATH, szNewPath, &pszFilePart) == 0 | |
6291 || pszFilePart == NULL) | |
6292 return -1; | |
6293 *pszFilePart = NUL; | |
6294 | |
6295 /* Get (and create) a unique temporary file name in directory of new file */ | |
6296 if (GetTempFileName(szNewPath, "VIM", 0, szTempFile) == 0) | |
6297 return -2; | |
6298 | |
6299 /* blow the temp file away */ | |
6300 if (!DeleteFile(szTempFile)) | |
6301 return -3; | |
6302 | |
6303 /* rename old file to the temp file */ | |
6304 if (!MoveFile(pszOldFile, szTempFile)) | |
6305 return -4; | |
6306 | |
6307 /* now create an empty file called pszOldFile; this prevents the operating | |
6308 * system using pszOldFile as an alias (SFN) if we're renaming within the | |
6309 * same directory. For example, we're editing a file called | |
6310 * filename.asc.txt by its SFN, filena~1.txt. If we rename filena~1.txt | |
6311 * to filena~1.txt~ (i.e., we're making a backup while writing it), the | |
6312 * SFN for filena~1.txt~ will be filena~1.txt, by default, which will | |
39 | 6313 * cause all sorts of problems later in buf_write(). So, we create an |
6314 * empty file called filena~1.txt and the system will have to find some | |
6315 * other SFN for filena~1.txt~, such as filena~2.txt | |
7 | 6316 */ |
6317 if ((hf = CreateFile(pszOldFile, GENERIC_WRITE, 0, NULL, CREATE_NEW, | |
6318 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) | |
6319 return -5; | |
6320 if (!CloseHandle(hf)) | |
6321 return -6; | |
6322 | |
6323 /* rename the temp file to the new file */ | |
6324 if (!MoveFile(szTempFile, pszNewFile)) | |
6325 { | |
6326 /* Renaming failed. Rename the file back to its old name, so that it | |
6327 * looks like nothing happened. */ | |
6328 (void)MoveFile(szTempFile, pszOldFile); | |
6329 | |
6330 return -7; | |
6331 } | |
6332 | |
6333 /* Seems to be left around on Novell filesystems */ | |
6334 DeleteFile(szTempFile); | |
6335 | |
6336 /* finally, remove the empty old file */ | |
6337 if (!DeleteFile(pszOldFile)) | |
6338 return -8; | |
6339 | |
6340 return 0; /* success */ | |
6341 } | |
6342 | |
6343 /* | |
6344 * Get the default shell for the current hardware platform | |
6345 */ | |
6346 char * | |
26 | 6347 default_shell(void) |
7 | 6348 { |
6349 PlatformId(); | |
6350 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6351 return "cmd.exe"; |
7 | 6352 } |
6353 | |
6354 /* | |
6355 * mch_access() extends access() to do more detailed check on network drives. | |
6356 * Returns 0 if file "n" has access rights according to "p", -1 otherwise. | |
6357 */ | |
6358 int | |
6359 mch_access(char *n, int p) | |
6360 { | |
6361 HANDLE hFile; | |
6362 DWORD am; | |
6363 int retval = -1; /* default: fail */ | |
6364 #ifdef FEAT_MBYTE | |
6365 WCHAR *wn = NULL; | |
6366 | |
6367 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6368 wn = enc_to_utf16((char_u *)n, NULL); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6369 #endif |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6370 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6371 if (mch_isdir((char_u *)n)) |
7 | 6372 { |
6373 char TempName[_MAX_PATH + 16] = ""; | |
6374 #ifdef FEAT_MBYTE | |
6375 WCHAR TempNameW[_MAX_PATH + 16] = L""; | |
6376 #endif | |
6377 | |
6378 if (p & R_OK) | |
6379 { | |
6380 /* Read check is performed by seeing if we can do a find file on | |
6381 * the directory for any file. */ | |
6382 #ifdef FEAT_MBYTE | |
6383 if (wn != NULL) | |
6384 { | |
6385 int i; | |
6386 WIN32_FIND_DATAW d; | |
6387 | |
6388 for (i = 0; i < _MAX_PATH && wn[i] != 0; ++i) | |
6389 TempNameW[i] = wn[i]; | |
6390 if (TempNameW[i - 1] != '\\' && TempNameW[i - 1] != '/') | |
6391 TempNameW[i++] = '\\'; | |
6392 TempNameW[i++] = '*'; | |
6393 TempNameW[i++] = 0; | |
6394 | |
6395 hFile = FindFirstFileW(TempNameW, &d); | |
6396 if (hFile == INVALID_HANDLE_VALUE) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6397 goto getout; |
7 | 6398 else |
6399 (void)FindClose(hFile); | |
6400 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6401 else |
7 | 6402 #endif |
6403 { | |
6404 char *pch; | |
6405 WIN32_FIND_DATA d; | |
6406 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6407 vim_strncpy((char_u *)TempName, (char_u *)n, _MAX_PATH); |
7 | 6408 pch = TempName + STRLEN(TempName) - 1; |
6409 if (*pch != '\\' && *pch != '/') | |
6410 *++pch = '\\'; | |
6411 *++pch = '*'; | |
6412 *++pch = NUL; | |
6413 | |
6414 hFile = FindFirstFile(TempName, &d); | |
6415 if (hFile == INVALID_HANDLE_VALUE) | |
6416 goto getout; | |
6417 (void)FindClose(hFile); | |
6418 } | |
6419 } | |
6420 | |
6421 if (p & W_OK) | |
6422 { | |
6423 /* Trying to create a temporary file in the directory should catch | |
6424 * directories on read-only network shares. However, in | |
6425 * directories whose ACL allows writes but denies deletes will end | |
6426 * up keeping the temporary file :-(. */ | |
6427 #ifdef FEAT_MBYTE | |
6428 if (wn != NULL) | |
6429 { | |
6430 if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW)) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6431 goto getout; |
7 | 6432 else |
6433 DeleteFileW(TempNameW); | |
6434 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6435 else |
7 | 6436 #endif |
6437 { | |
6438 if (!GetTempFileName(n, "VIM", 0, TempName)) | |
6439 goto getout; | |
6440 mch_remove((char_u *)TempName); | |
6441 } | |
6442 } | |
6443 } | |
6444 else | |
6445 { | |
6446 /* Trying to open the file for the required access does ACL, read-only | |
6447 * network share, and file attribute checks. */ | |
6448 am = ((p & W_OK) ? GENERIC_WRITE : 0) | |
6449 | ((p & R_OK) ? GENERIC_READ : 0); | |
6450 #ifdef FEAT_MBYTE | |
6451 if (wn != NULL) | |
6452 hFile = CreateFileW(wn, am, 0, NULL, OPEN_EXISTING, 0, NULL); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6453 else |
7 | 6454 #endif |
6455 hFile = CreateFile(n, am, 0, NULL, OPEN_EXISTING, 0, NULL); | |
6456 if (hFile == INVALID_HANDLE_VALUE) | |
6457 goto getout; | |
6458 CloseHandle(hFile); | |
6459 } | |
6460 | |
6461 retval = 0; /* success */ | |
6462 getout: | |
6463 #ifdef FEAT_MBYTE | |
6464 vim_free(wn); | |
6465 #endif | |
6466 return retval; | |
6467 } | |
6468 | |
6469 #if defined(FEAT_MBYTE) || defined(PROTO) | |
6470 /* | |
1752 | 6471 * Version of open() that may use UTF-16 file name. |
7 | 6472 */ |
6473 int | |
6474 mch_open(char *name, int flags, int mode) | |
6475 { | |
39 | 6476 /* _wopen() does not work with Borland C 5.5: creates a read-only file. */ |
6477 # ifndef __BORLANDC__ | |
7 | 6478 WCHAR *wn; |
6479 int f; | |
6480 | |
39 | 6481 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7 | 6482 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6483 wn = enc_to_utf16((char_u *)name, NULL); |
7 | 6484 if (wn != NULL) |
6485 { | |
6486 f = _wopen(wn, flags, mode); | |
6487 vim_free(wn); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6488 return f; |
7 | 6489 } |
6490 } | |
39 | 6491 # endif |
7 | 6492 |
6345 | 6493 /* open() can open a file which name is longer than _MAX_PATH bytes |
6494 * and shorter than _MAX_PATH characters successfully, but sometimes it | |
6495 * causes unexpected error in another part. We make it an error explicitly | |
6496 * here. */ | |
6497 if (strlen(name) >= _MAX_PATH) | |
6498 return -1; | |
6499 | |
7 | 6500 return open(name, flags, mode); |
6501 } | |
6502 | |
6503 /* | |
1752 | 6504 * Version of fopen() that may use UTF-16 file name. |
7 | 6505 */ |
6506 FILE * | |
6507 mch_fopen(char *name, char *mode) | |
6508 { | |
6509 WCHAR *wn, *wm; | |
6510 FILE *f = NULL; | |
6511 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6512 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7 | 6513 { |
1686 | 6514 # if defined(DEBUG) && _MSC_VER >= 1400 |
1569 | 6515 /* Work around an annoying assertion in the Microsoft debug CRT |
6516 * when mode's text/binary setting doesn't match _get_fmode(). */ | |
6517 char newMode = mode[strlen(mode) - 1]; | |
6518 int oldMode = 0; | |
6519 | |
6520 _get_fmode(&oldMode); | |
6521 if (newMode == 't') | |
6522 _set_fmode(_O_TEXT); | |
6523 else if (newMode == 'b') | |
6524 _set_fmode(_O_BINARY); | |
6525 # endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6526 wn = enc_to_utf16((char_u *)name, NULL); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6527 wm = enc_to_utf16((char_u *)mode, NULL); |
7 | 6528 if (wn != NULL && wm != NULL) |
6529 f = _wfopen(wn, wm); | |
6530 vim_free(wn); | |
6531 vim_free(wm); | |
1569 | 6532 |
1686 | 6533 # if defined(DEBUG) && _MSC_VER >= 1400 |
1569 | 6534 _set_fmode(oldMode); |
6535 # endif | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6536 return f; |
7 | 6537 } |
6538 | |
6345 | 6539 /* fopen() can open a file which name is longer than _MAX_PATH bytes |
6540 * and shorter than _MAX_PATH characters successfully, but sometimes it | |
6541 * causes unexpected error in another part. We make it an error explicitly | |
6542 * here. */ | |
6543 if (strlen(name) >= _MAX_PATH) | |
6544 return NULL; | |
6545 | |
7 | 6546 return fopen(name, mode); |
6547 } | |
6548 #endif | |
6549 | |
6550 #ifdef FEAT_MBYTE | |
6551 /* | |
6552 * SUB STREAM (aka info stream) handling: | |
6553 * | |
6554 * NTFS can have sub streams for each file. Normal contents of file is | |
6555 * stored in the main stream, and extra contents (author information and | |
6556 * title and so on) can be stored in sub stream. After Windows 2000, user | |
6557 * can access and store those informations in sub streams via explorer's | |
6558 * property menuitem in right click menu. Those informations in sub streams | |
6559 * were lost when copying only the main stream. So we have to copy sub | |
6560 * streams. | |
6561 * | |
6562 * Incomplete explanation: | |
6563 * http://msdn.microsoft.com/library/en-us/dnw2k/html/ntfs5.asp | |
6564 * More useful info and an example: | |
6565 * http://www.sysinternals.com/ntw2k/source/misc.shtml#streams | |
6566 */ | |
6567 | |
6568 /* | |
6569 * Copy info stream data "substream". Read from the file with BackupRead(sh) | |
6570 * and write to stream "substream" of file "to". | |
6571 * Errors are ignored. | |
6572 */ | |
6573 static void | |
6574 copy_substream(HANDLE sh, void *context, WCHAR *to, WCHAR *substream, long len) | |
6575 { | |
6576 HANDLE hTo; | |
6577 WCHAR *to_name; | |
6578 | |
6579 to_name = malloc((wcslen(to) + wcslen(substream) + 1) * sizeof(WCHAR)); | |
6580 wcscpy(to_name, to); | |
6581 wcscat(to_name, substream); | |
6582 | |
6583 hTo = CreateFileW(to_name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, | |
6584 FILE_ATTRIBUTE_NORMAL, NULL); | |
6585 if (hTo != INVALID_HANDLE_VALUE) | |
6586 { | |
6587 long done; | |
6588 DWORD todo; | |
6589 DWORD readcnt, written; | |
6590 char buf[4096]; | |
6591 | |
6592 /* Copy block of bytes at a time. Abort when something goes wrong. */ | |
6593 for (done = 0; done < len; done += written) | |
6594 { | |
6595 /* (size_t) cast for Borland C 5.5 */ | |
835 | 6596 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) |
6597 : (size_t)(len - done)); | |
7 | 6598 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, |
6599 FALSE, FALSE, context) | |
6600 || readcnt != todo | |
6601 || !WriteFile(hTo, buf, todo, &written, NULL) | |
6602 || written != todo) | |
6603 break; | |
6604 } | |
6605 CloseHandle(hTo); | |
6606 } | |
6607 | |
6608 free(to_name); | |
6609 } | |
6610 | |
6611 /* | |
6612 * Copy info streams from file "from" to file "to". | |
6613 */ | |
6614 static void | |
6615 copy_infostreams(char_u *from, char_u *to) | |
6616 { | |
6617 WCHAR *fromw; | |
6618 WCHAR *tow; | |
6619 HANDLE sh; | |
6620 WIN32_STREAM_ID sid; | |
6621 int headersize; | |
6622 WCHAR streamname[_MAX_PATH]; | |
6623 DWORD readcount; | |
6624 void *context = NULL; | |
6625 DWORD lo, hi; | |
6626 int len; | |
6627 | |
6628 /* Convert the file names to wide characters. */ | |
1752 | 6629 fromw = enc_to_utf16(from, NULL); |
6630 tow = enc_to_utf16(to, NULL); | |
7 | 6631 if (fromw != NULL && tow != NULL) |
6632 { | |
6633 /* Open the file for reading. */ | |
6634 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, | |
6635 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | |
6636 if (sh != INVALID_HANDLE_VALUE) | |
6637 { | |
6638 /* Use BackupRead() to find the info streams. Repeat until we | |
6639 * have done them all.*/ | |
6640 for (;;) | |
6641 { | |
6642 /* Get the header to find the length of the stream name. If | |
6643 * the "readcount" is zero we have done all info streams. */ | |
6644 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); | |
835 | 6645 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); |
7 | 6646 if (!BackupRead(sh, (LPBYTE)&sid, headersize, |
6647 &readcount, FALSE, FALSE, &context) | |
6648 || readcount == 0) | |
6649 break; | |
6650 | |
6651 /* We only deal with streams that have a name. The normal | |
6652 * file data appears to be without a name, even though docs | |
6653 * suggest it is called "::$DATA". */ | |
6654 if (sid.dwStreamNameSize > 0) | |
6655 { | |
6656 /* Read the stream name. */ | |
6657 if (!BackupRead(sh, (LPBYTE)streamname, | |
6658 sid.dwStreamNameSize, | |
6659 &readcount, FALSE, FALSE, &context)) | |
6660 break; | |
6661 | |
6662 /* Copy an info stream with a name ":anything:$DATA". | |
6663 * Skip "::$DATA", it has no stream name (examples suggest | |
6664 * it might be used for the normal file contents). | |
6665 * Note that BackupRead() counts bytes, but the name is in | |
6666 * wide characters. */ | |
6667 len = readcount / sizeof(WCHAR); | |
6668 streamname[len] = 0; | |
6669 if (len > 7 && wcsicmp(streamname + len - 6, | |
6670 L":$DATA") == 0) | |
6671 { | |
6672 streamname[len - 6] = 0; | |
6673 copy_substream(sh, &context, tow, streamname, | |
10 | 6674 (long)sid.Size.u.LowPart); |
7 | 6675 } |
6676 } | |
6677 | |
6678 /* Advance to the next stream. We might try seeking too far, | |
6679 * but BackupSeek() doesn't skip over stream borders, thus | |
6680 * that's OK. */ | |
323 | 6681 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, |
7 | 6682 &lo, &hi, &context); |
6683 } | |
6684 | |
6685 /* Clear the context. */ | |
6686 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); | |
6687 | |
6688 CloseHandle(sh); | |
6689 } | |
6690 } | |
6691 vim_free(fromw); | |
6692 vim_free(tow); | |
6693 } | |
6694 #endif | |
6695 | |
6696 /* | |
6697 * Copy file attributes from file "from" to file "to". | |
6698 * For Windows NT and later we copy info streams. | |
6699 * Always returns zero, errors are ignored. | |
6700 */ | |
6701 int | |
6702 mch_copy_file_attribute(char_u *from, char_u *to) | |
6703 { | |
6704 #ifdef FEAT_MBYTE | |
6705 /* File streams only work on Windows NT and later. */ | |
6706 PlatformId(); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6707 copy_infostreams(from, to); |
7 | 6708 #endif |
6709 return 0; | |
6710 } | |
6711 | |
6712 #if defined(MYRESETSTKOFLW) || defined(PROTO) | |
6713 /* | |
6714 * Recreate a destroyed stack guard page in win32. | |
6715 * Written by Benjamin Peterson. | |
6716 */ | |
6717 | |
6718 /* These magic numbers are from the MS header files */ | |
6719 #define MIN_STACK_WINNT 2 | |
6720 | |
6721 /* | |
6722 * This function does the same thing as _resetstkoflw(), which is only | |
6723 * available in DevStudio .net and later. | |
6724 * Returns 0 for failure, 1 for success. | |
6725 */ | |
6726 int | |
6727 myresetstkoflw(void) | |
6728 { | |
6729 BYTE *pStackPtr; | |
6730 BYTE *pGuardPage; | |
6731 BYTE *pStackBase; | |
6732 BYTE *pLowestPossiblePage; | |
6733 MEMORY_BASIC_INFORMATION mbi; | |
6734 SYSTEM_INFO si; | |
6735 DWORD nPageSize; | |
6736 DWORD dummy; | |
6737 | |
6738 PlatformId(); | |
6739 | |
6740 /* We need to know the system page size. */ | |
6741 GetSystemInfo(&si); | |
6742 nPageSize = si.dwPageSize; | |
6743 | |
6744 /* ...and the current stack pointer */ | |
6745 pStackPtr = (BYTE*)_alloca(1); | |
6746 | |
6747 /* ...and the base of the stack. */ | |
6748 if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0) | |
6749 return 0; | |
6750 pStackBase = (BYTE*)mbi.AllocationBase; | |
6751 | |
6752 /* ...and the page thats min_stack_req pages away from stack base; this is | |
6753 * the lowest page we could use. */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6754 pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6755 |
7 | 6756 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6757 /* We want the first committed page in the stack Start at the stack |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6758 * base and move forward through memory until we find a committed block. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6759 */ |
7 | 6760 BYTE *pBlock = pStackBase; |
6761 | |
406 | 6762 for (;;) |
7 | 6763 { |
6764 if (VirtualQuery(pBlock, &mbi, sizeof mbi) == 0) | |
6765 return 0; | |
6766 | |
6767 pBlock += mbi.RegionSize; | |
6768 | |
6769 if (mbi.State & MEM_COMMIT) | |
6770 break; | |
6771 } | |
6772 | |
6773 /* mbi now describes the first committed block in the stack. */ | |
6774 if (mbi.Protect & PAGE_GUARD) | |
6775 return 1; | |
6776 | |
6777 /* decide where the guard page should start */ | |
6778 if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage) | |
6779 pGuardPage = pLowestPossiblePage; | |
6780 else | |
6781 pGuardPage = (BYTE*)mbi.BaseAddress; | |
6782 | |
6783 /* allocate the guard page */ | |
6784 if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE)) | |
6785 return 0; | |
6786 | |
6787 /* apply the guard attribute to the page */ | |
6788 if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD, | |
6789 &dummy)) | |
6790 return 0; | |
6791 } | |
6792 | |
6793 return 1; | |
6794 } | |
6795 #endif | |
26 | 6796 |
6797 | |
6798 #if defined(FEAT_MBYTE) || defined(PROTO) | |
6799 /* | |
6800 * The command line arguments in UCS2 | |
6801 */ | |
344 | 6802 static int nArgsW = 0; |
26 | 6803 static LPWSTR *ArglistW = NULL; |
6804 static int global_argc = 0; | |
6805 static char **global_argv; | |
6806 | |
6807 static int used_file_argc = 0; /* last argument in global_argv[] used | |
6808 for the argument list. */ | |
6809 static int *used_file_indexes = NULL; /* indexes in global_argv[] for | |
6810 command line arguments added to | |
6811 the argument list */ | |
6812 static int used_file_count = 0; /* nr of entries in used_file_indexes */ | |
6813 static int used_file_literal = FALSE; /* take file names literally */ | |
6814 static int used_file_full_path = FALSE; /* file name was full path */ | |
819 | 6815 static int used_file_diff_mode = FALSE; /* file name was with diff mode */ |
26 | 6816 static int used_alist_count = 0; |
6817 | |
6818 | |
6819 /* | |
6820 * Get the command line arguments. Unicode version. | |
6821 * Returns argc. Zero when something fails. | |
6822 */ | |
6823 int | |
6824 get_cmd_argsW(char ***argvp) | |
6825 { | |
6826 char **argv = NULL; | |
6827 int argc = 0; | |
6828 int i; | |
6829 | |
6193 | 6830 free_cmd_argsW(); |
26 | 6831 ArglistW = CommandLineToArgvW(GetCommandLineW(), &nArgsW); |
6832 if (ArglistW != NULL) | |
6833 { | |
6834 argv = malloc((nArgsW + 1) * sizeof(char *)); | |
6835 if (argv != NULL) | |
6836 { | |
6837 argc = nArgsW; | |
6838 argv[argc] = NULL; | |
6839 for (i = 0; i < argc; ++i) | |
6840 { | |
6841 int len; | |
6842 | |
6843 /* Convert each Unicode argument to the current codepage. */ | |
6844 WideCharToMultiByte_alloc(GetACP(), 0, | |
835 | 6845 ArglistW[i], (int)wcslen(ArglistW[i]) + 1, |
26 | 6846 (LPSTR *)&argv[i], &len, 0, 0); |
6847 if (argv[i] == NULL) | |
6848 { | |
6849 /* Out of memory, clear everything. */ | |
6850 while (i > 0) | |
6851 free(argv[--i]); | |
6852 free(argv); | |
5529 | 6853 argv = NULL; |
26 | 6854 argc = 0; |
6855 } | |
6856 } | |
6857 } | |
6858 } | |
6859 | |
6860 global_argc = argc; | |
6861 global_argv = argv; | |
6862 if (argc > 0) | |
6193 | 6863 { |
6864 if (used_file_indexes != NULL) | |
6865 free(used_file_indexes); | |
26 | 6866 used_file_indexes = malloc(argc * sizeof(int)); |
6193 | 6867 } |
26 | 6868 |
6869 if (argvp != NULL) | |
6870 *argvp = argv; | |
6871 return argc; | |
6872 } | |
6873 | |
6874 void | |
6875 free_cmd_argsW(void) | |
6876 { | |
6877 if (ArglistW != NULL) | |
6878 { | |
6879 GlobalFree(ArglistW); | |
6880 ArglistW = NULL; | |
6881 } | |
6882 } | |
6883 | |
6884 /* | |
6885 * Remember "name" is an argument that was added to the argument list. | |
6886 * This avoids that we have to re-parse the argument list when fix_arg_enc() | |
6887 * is called. | |
6888 */ | |
6889 void | |
819 | 6890 used_file_arg(char *name, int literal, int full_path, int diff_mode) |
26 | 6891 { |
6892 int i; | |
6893 | |
6894 if (used_file_indexes == NULL) | |
6895 return; | |
6896 for (i = used_file_argc + 1; i < global_argc; ++i) | |
6897 if (STRCMP(global_argv[i], name) == 0) | |
6898 { | |
6899 used_file_argc = i; | |
6900 used_file_indexes[used_file_count++] = i; | |
6901 break; | |
6902 } | |
6903 used_file_literal = literal; | |
6904 used_file_full_path = full_path; | |
819 | 6905 used_file_diff_mode = diff_mode; |
26 | 6906 } |
6907 | |
6908 /* | |
6909 * Remember the length of the argument list as it was. If it changes then we | |
6910 * leave it alone when 'encoding' is set. | |
6911 */ | |
6912 void | |
6913 set_alist_count(void) | |
6914 { | |
6915 used_alist_count = GARGCOUNT; | |
6916 } | |
6917 | |
6918 /* | |
6919 * Fix the encoding of the command line arguments. Invoked when 'encoding' | |
6920 * has been changed while starting up. Use the UCS-2 command line arguments | |
6921 * and convert them to 'encoding'. | |
6922 */ | |
6923 void | |
6924 fix_arg_enc(void) | |
6925 { | |
6926 int i; | |
6927 int idx; | |
6928 char_u *str; | |
41 | 6929 int *fnum_list; |
26 | 6930 |
6931 /* Safety checks: | |
6932 * - if argument count differs between the wide and non-wide argument | |
6933 * list, something must be wrong. | |
6934 * - the file name arguments must have been located. | |
6935 * - the length of the argument list wasn't changed by the user. | |
6936 */ | |
344 | 6937 if (global_argc != nArgsW |
26 | 6938 || ArglistW == NULL |
6939 || used_file_indexes == NULL | |
6940 || used_file_count == 0 | |
6941 || used_alist_count != GARGCOUNT) | |
6942 return; | |
6943 | |
41 | 6944 /* Remember the buffer numbers for the arguments. */ |
6945 fnum_list = (int *)alloc((int)sizeof(int) * GARGCOUNT); | |
6946 if (fnum_list == NULL) | |
6947 return; /* out of memory */ | |
6948 for (i = 0; i < GARGCOUNT; ++i) | |
6949 fnum_list[i] = GARGLIST[i].ae_fnum; | |
6950 | |
26 | 6951 /* Clear the argument list. Make room for the new arguments. */ |
6952 alist_clear(&global_alist); | |
6953 if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL) | |
41 | 6954 return; /* out of memory */ |
26 | 6955 |
6956 for (i = 0; i < used_file_count; ++i) | |
6957 { | |
6958 idx = used_file_indexes[i]; | |
1752 | 6959 str = utf16_to_enc(ArglistW[idx], NULL); |
26 | 6960 if (str != NULL) |
41 | 6961 { |
819 | 6962 #ifdef FEAT_DIFF |
6963 /* When using diff mode may need to concatenate file name to | |
6964 * directory name. Just like it's done in main(). */ | |
6965 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 | |
6966 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
6967 { | |
6968 char_u *r; | |
6969 | |
6970 r = concat_fnames(str, gettail(alist_name(&GARGLIST[0])), TRUE); | |
6971 if (r != NULL) | |
6972 { | |
6973 vim_free(str); | |
6974 str = r; | |
6975 } | |
6976 } | |
6977 #endif | |
41 | 6978 /* Re-use the old buffer by renaming it. When not using literal |
6979 * names it's done by alist_expand() below. */ | |
6980 if (used_file_literal) | |
6981 buf_set_name(fnum_list[i], str); | |
6982 | |
26 | 6983 alist_add(&global_alist, str, used_file_literal ? 2 : 0); |
41 | 6984 } |
26 | 6985 } |
6986 | |
6987 if (!used_file_literal) | |
6988 { | |
6989 /* Now expand wildcards in the arguments. */ | |
6990 /* Temporarily add '(' and ')' to 'isfname'. These are valid | |
6991 * filename characters but are excluded from 'isfname' to make | |
6992 * "gf" work on a file name in parenthesis (e.g.: see vim.h). */ | |
6993 do_cmdline_cmd((char_u *)":let SaVe_ISF = &isf|set isf+=(,)"); | |
41 | 6994 alist_expand(fnum_list, used_alist_count); |
26 | 6995 do_cmdline_cmd((char_u *)":let &isf = SaVe_ISF|unlet SaVe_ISF"); |
6996 } | |
6997 | |
6998 /* If wildcard expansion failed, we are editing the first file of the | |
6999 * arglist and there is no file name: Edit the first argument now. */ | |
7000 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) | |
7001 { | |
7002 do_cmdline_cmd((char_u *)":rewind"); | |
7003 if (GARGCOUNT == 1 && used_file_full_path) | |
7004 (void)vim_chdirfile(alist_name(&GARGLIST[0])); | |
7005 } | |
41 | 7006 |
7007 set_alist_count(); | |
26 | 7008 } |
7009 #endif | |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7010 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7011 int |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7012 mch_setenv(char *var, char *value, int x) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7013 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7014 char_u *envbuf; |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7015 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7016 envbuf = alloc((unsigned)(STRLEN(var) + STRLEN(value) + 2)); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7017 if (envbuf == NULL) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7018 return -1; |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7019 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7020 sprintf((char *)envbuf, "%s=%s", var, value); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7021 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7022 #ifdef FEAT_MBYTE |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7023 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7024 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7025 WCHAR *p = enc_to_utf16(envbuf, NULL); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7026 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7027 vim_free(envbuf); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7028 if (p == NULL) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7029 return -1; |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7030 _wputenv(p); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7031 # ifdef libintl_wputenv |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7032 libintl_wputenv(p); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7033 # endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7034 /* Unlike Un*x systems, we can free the string for _wputenv(). */ |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7035 vim_free(p); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7036 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7037 else |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7038 #endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7039 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7040 _putenv((char *)envbuf); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7041 # ifdef libintl_putenv |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7042 libintl_putenv((char *)envbuf); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7043 # endif |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7044 /* Unlike Un*x systems, we can free the string for _putenv(). */ |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7045 vim_free(envbuf); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7046 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7047 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7048 return 0; |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7049 } |