Mercurial > vim
annotate src/os_win32.c @ 10406:42911b233245 v8.0.0097
commit https://github.com/vim/vim/commit/833eb1d752426689051bf2001083359899536939
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 24 17:22:50 2016 +0100
patch 8.0.0097
Problem: When a channel callback consumes a lot of time Vim becomes
unresponsive. (skywind)
Solution: Bail out of checking channel readahead after 100 msec.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 24 Nov 2016 17:30:04 +0100 |
parents | 17165aabc731 |
children | 56cb9538386c |
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 | |
7 | 428 #if defined(DYNAMIC_GETTEXT) || defined(PROTO) |
429 # ifndef GETTEXT_DLL | |
430 # define GETTEXT_DLL "libintl.dll" | |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
431 # define GETTEXT_DLL_ALT "libintl-8.dll" |
7 | 432 # endif |
3622 | 433 /* Dummy functions */ |
36 | 434 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
|
435 static char *null_libintl_ngettext(const char *, const char *, unsigned long n); |
36 | 436 static char *null_libintl_textdomain(const char *); |
437 static char *null_libintl_bindtextdomain(const char *, const char *); | |
438 static char *null_libintl_bind_textdomain_codeset(const char *, const char *); | |
7 | 439 |
2612 | 440 static HINSTANCE hLibintlDLL = NULL; |
36 | 441 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
|
442 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
|
443 = null_libintl_ngettext; |
36 | 444 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; |
445 char *(*dyn_libintl_bindtextdomain)(const char *, const char *) | |
7 | 446 = null_libintl_bindtextdomain; |
36 | 447 char *(*dyn_libintl_bind_textdomain_codeset)(const char *, const char *) |
448 = null_libintl_bind_textdomain_codeset; | |
7 | 449 |
450 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
451 dyn_libintl_init(void) |
7 | 452 { |
453 int i; | |
454 static struct | |
455 { | |
456 char *name; | |
457 FARPROC *ptr; | |
458 } libintl_entry[] = | |
459 { | |
460 {"gettext", (FARPROC*)&dyn_libintl_gettext}, | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
461 {"ngettext", (FARPROC*)&dyn_libintl_ngettext}, |
7 | 462 {"textdomain", (FARPROC*)&dyn_libintl_textdomain}, |
463 {"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, | |
464 {NULL, NULL} | |
465 }; | |
466 | |
467 /* No need to initialize twice. */ | |
468 if (hLibintlDLL) | |
469 return 1; | |
470 /* Load gettext library (libintl.dll) */ | |
7784
29d4ee3f009a
commit https://github.com/vim/vim/commit/923e43b837ca4c8edb7998743f142823eaeaf588
Christian Brabandt <cb@256bit.org>
parents:
7734
diff
changeset
|
471 hLibintlDLL = vimLoadLib(GETTEXT_DLL); |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
472 #ifdef GETTEXT_DLL_ALT |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
473 if (!hLibintlDLL) |
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
474 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT); |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
475 #endif |
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
476 if (!hLibintlDLL) |
7 | 477 { |
2612 | 478 if (p_verbose > 0) |
7 | 479 { |
2612 | 480 verbose_enter(); |
481 EMSG2(_(e_loadlib), GETTEXT_DLL); | |
482 verbose_leave(); | |
7 | 483 } |
2612 | 484 return 0; |
7 | 485 } |
486 for (i = 0; libintl_entry[i].name != NULL | |
487 && libintl_entry[i].ptr != NULL; ++i) | |
488 { | |
489 if ((*libintl_entry[i].ptr = (FARPROC)GetProcAddress(hLibintlDLL, | |
490 libintl_entry[i].name)) == NULL) | |
491 { | |
492 dyn_libintl_end(); | |
493 if (p_verbose > 0) | |
292 | 494 { |
495 verbose_enter(); | |
7 | 496 EMSG2(_(e_loadfunc), libintl_entry[i].name); |
292 | 497 verbose_leave(); |
498 } | |
7 | 499 return 0; |
500 } | |
501 } | |
36 | 502 |
503 /* The bind_textdomain_codeset() function is optional. */ | |
323 | 504 dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL, |
36 | 505 "bind_textdomain_codeset"); |
506 if (dyn_libintl_bind_textdomain_codeset == NULL) | |
507 dyn_libintl_bind_textdomain_codeset = | |
508 null_libintl_bind_textdomain_codeset; | |
509 | |
7 | 510 return 1; |
511 } | |
512 | |
513 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
514 dyn_libintl_end(void) |
7 | 515 { |
516 if (hLibintlDLL) | |
517 FreeLibrary(hLibintlDLL); | |
518 hLibintlDLL = NULL; | |
519 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
|
520 dyn_libintl_ngettext = null_libintl_ngettext; |
7 | 521 dyn_libintl_textdomain = null_libintl_textdomain; |
522 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain; | |
36 | 523 dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset; |
7 | 524 } |
525 | |
323 | 526 /*ARGSUSED*/ |
7 | 527 static char * |
26 | 528 null_libintl_gettext(const char *msgid) |
7 | 529 { |
530 return (char*)msgid; | |
531 } | |
532 | |
323 | 533 /*ARGSUSED*/ |
7 | 534 static char * |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
535 null_libintl_ngettext( |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
536 const char *msgid, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
537 const char *msgid_plural, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
538 unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
539 { |
9762
93dcc4329c74
commit https://github.com/vim/vim/commit/c90f2aedd0a5dc2cc75bc9b5f475f8a3e3fe36b1
Christian Brabandt <cb@256bit.org>
parents:
9754
diff
changeset
|
540 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
|
541 } |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
542 |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
543 /*ARGSUSED*/ |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
544 static char * |
26 | 545 null_libintl_bindtextdomain(const char *domainname, const char *dirname) |
7 | 546 { |
547 return NULL; | |
548 } | |
549 | |
323 | 550 /*ARGSUSED*/ |
7 | 551 static char * |
36 | 552 null_libintl_bind_textdomain_codeset(const char *domainname, |
553 const char *codeset) | |
554 { | |
555 return NULL; | |
556 } | |
557 | |
323 | 558 /*ARGSUSED*/ |
36 | 559 static char * |
26 | 560 null_libintl_textdomain(const char *domainname) |
7 | 561 { |
562 return NULL; | |
563 } | |
564 | |
565 #endif /* DYNAMIC_GETTEXT */ | |
566 | |
567 /* This symbol is not defined in older versions of the SDK or Visual C++ */ | |
568 | |
569 #ifndef VER_PLATFORM_WIN32_WINDOWS | |
570 # define VER_PLATFORM_WIN32_WINDOWS 1 | |
571 #endif | |
572 | |
573 DWORD g_PlatformId; | |
574 | |
575 #ifdef HAVE_ACL | |
3927 | 576 # ifndef PROTO |
577 # include <aclapi.h> | |
578 # endif | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
579 # ifndef PROTECTED_DACL_SECURITY_INFORMATION |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
580 # define PROTECTED_DACL_SECURITY_INFORMATION 0x80000000L |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
581 # endif |
7 | 582 #endif |
583 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
584 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
585 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
586 * Enables or disables the specified privilege. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
587 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
588 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
589 win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
590 { |
5590 | 591 BOOL bResult; |
592 LUID luid; | |
593 HANDLE hToken; | |
594 TOKEN_PRIVILEGES tokenPrivileges; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
595 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
596 if (!OpenProcessToken(GetCurrentProcess(), |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
597 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
598 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
599 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
600 if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
601 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
602 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
603 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
604 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
605 |
6047 | 606 tokenPrivileges.PrivilegeCount = 1; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
607 tokenPrivileges.Privileges[0].Luid = luid; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
608 tokenPrivileges.Privileges[0].Attributes = bEnable ? |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
609 SE_PRIVILEGE_ENABLED : 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
610 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
611 bResult = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
612 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
613 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
614 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
615 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
616 return bResult && GetLastError() == ERROR_SUCCESS; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
617 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
618 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
619 |
7 | 620 /* |
621 * Set g_PlatformId to VER_PLATFORM_WIN32_NT (NT) or | |
622 * VER_PLATFORM_WIN32_WINDOWS (Win95). | |
623 */ | |
624 void | |
625 PlatformId(void) | |
626 { | |
627 static int done = FALSE; | |
628 | |
629 if (!done) | |
630 { | |
631 OSVERSIONINFO ovi; | |
632 | |
633 ovi.dwOSVersionInfoSize = sizeof(ovi); | |
634 GetVersionEx(&ovi); | |
635 | |
636 g_PlatformId = ovi.dwPlatformId; | |
637 | |
5633 | 638 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2) |
639 || ovi.dwMajorVersion > 6) | |
640 win8_or_later = TRUE; | |
641 | |
7 | 642 #ifdef HAVE_ACL |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
643 /* 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
|
644 win32_enable_privilege(SE_SECURITY_NAME, TRUE); |
7 | 645 #endif |
646 done = TRUE; | |
647 } | |
648 } | |
649 | |
650 #ifndef FEAT_GUI_W32 | |
651 | |
652 #define SHIFT (SHIFT_PRESSED) | |
653 #define CTRL (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED) | |
654 #define ALT (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED) | |
655 #define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) | |
656 | |
657 | |
658 /* When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode. | |
659 * We map function keys to their ANSI terminal equivalents, as produced | |
660 * by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any | |
661 * ANSI key with a value >= '\300' is nonstandard, but provided anyway | |
662 * so that the user can have access to all SHIFT-, CTRL-, and ALT- | |
663 * combinations of function/arrow/etc keys. | |
664 */ | |
665 | |
297 | 666 static const struct |
7 | 667 { |
668 WORD wVirtKey; | |
669 BOOL fAnsiKey; | |
670 int chAlone; | |
671 int chShift; | |
672 int chCtrl; | |
673 int chAlt; | |
674 } VirtKeyMap[] = | |
675 { | |
676 | |
677 /* Key ANSI alone shift ctrl alt */ | |
678 { VK_ESCAPE,FALSE, ESC, ESC, ESC, ESC, }, | |
679 | |
680 { VK_F1, TRUE, ';', 'T', '^', 'h', }, | |
681 { VK_F2, TRUE, '<', 'U', '_', 'i', }, | |
682 { VK_F3, TRUE, '=', 'V', '`', 'j', }, | |
683 { VK_F4, TRUE, '>', 'W', 'a', 'k', }, | |
684 { VK_F5, TRUE, '?', 'X', 'b', 'l', }, | |
685 { VK_F6, TRUE, '@', 'Y', 'c', 'm', }, | |
686 { VK_F7, TRUE, 'A', 'Z', 'd', 'n', }, | |
687 { VK_F8, TRUE, 'B', '[', 'e', 'o', }, | |
688 { VK_F9, TRUE, 'C', '\\', 'f', 'p', }, | |
689 { VK_F10, TRUE, 'D', ']', 'g', 'q', }, | |
690 { VK_F11, TRUE, '\205', '\207', '\211', '\213', }, | |
691 { VK_F12, TRUE, '\206', '\210', '\212', '\214', }, | |
692 | |
693 { VK_HOME, TRUE, 'G', '\302', 'w', '\303', }, | |
694 { VK_UP, TRUE, 'H', '\304', '\305', '\306', }, | |
695 { VK_PRIOR, TRUE, 'I', '\307', '\204', '\310', }, /*PgUp*/ | |
696 { VK_LEFT, TRUE, 'K', '\311', 's', '\312', }, | |
697 { VK_RIGHT, TRUE, 'M', '\313', 't', '\314', }, | |
698 { VK_END, TRUE, 'O', '\315', 'u', '\316', }, | |
699 { VK_DOWN, TRUE, 'P', '\317', '\320', '\321', }, | |
700 { VK_NEXT, TRUE, 'Q', '\322', 'v', '\323', }, /*PgDn*/ | |
701 { VK_INSERT,TRUE, 'R', '\324', '\325', '\326', }, | |
702 { VK_DELETE,TRUE, 'S', '\327', '\330', '\331', }, | |
703 | |
704 { VK_SNAPSHOT,TRUE, 0, 0, 0, 'r', }, /*PrtScrn*/ | |
705 | |
706 #if 0 | |
707 /* Most people don't have F13-F20, but what the hell... */ | |
708 { VK_F13, TRUE, '\332', '\333', '\334', '\335', }, | |
709 { VK_F14, TRUE, '\336', '\337', '\340', '\341', }, | |
710 { VK_F15, TRUE, '\342', '\343', '\344', '\345', }, | |
711 { VK_F16, TRUE, '\346', '\347', '\350', '\351', }, | |
712 { VK_F17, TRUE, '\352', '\353', '\354', '\355', }, | |
713 { VK_F18, TRUE, '\356', '\357', '\360', '\361', }, | |
714 { VK_F19, TRUE, '\362', '\363', '\364', '\365', }, | |
715 { VK_F20, TRUE, '\366', '\367', '\370', '\371', }, | |
716 #endif | |
717 { VK_ADD, TRUE, 'N', 'N', 'N', 'N', }, /* keyp '+' */ | |
718 { VK_SUBTRACT, TRUE,'J', 'J', 'J', 'J', }, /* keyp '-' */ | |
719 /* { VK_DIVIDE, TRUE,'N', 'N', 'N', 'N', }, keyp '/' */ | |
720 { VK_MULTIPLY, TRUE,'7', '7', '7', '7', }, /* keyp '*' */ | |
721 | |
722 { VK_NUMPAD0,TRUE, '\332', '\333', '\334', '\335', }, | |
723 { VK_NUMPAD1,TRUE, '\336', '\337', '\340', '\341', }, | |
724 { VK_NUMPAD2,TRUE, '\342', '\343', '\344', '\345', }, | |
725 { VK_NUMPAD3,TRUE, '\346', '\347', '\350', '\351', }, | |
726 { VK_NUMPAD4,TRUE, '\352', '\353', '\354', '\355', }, | |
727 { VK_NUMPAD5,TRUE, '\356', '\357', '\360', '\361', }, | |
728 { VK_NUMPAD6,TRUE, '\362', '\363', '\364', '\365', }, | |
729 { VK_NUMPAD7,TRUE, '\366', '\367', '\370', '\371', }, | |
730 { VK_NUMPAD8,TRUE, '\372', '\373', '\374', '\375', }, | |
731 /* Sorry, out of number space! <negri>*/ | |
732 { VK_NUMPAD9,TRUE, '\376', '\377', '\377', '\367', }, | |
733 | |
734 }; | |
735 | |
736 | |
737 #ifdef _MSC_VER | |
738 // The ToAscii bug destroys several registers. Need to turn off optimization | |
739 // or the GetConsoleKeyboardLayoutName hack will fail in non-debug versions | |
797 | 740 # pragma warning(push) |
741 # pragma warning(disable: 4748) | |
7 | 742 # pragma optimize("", off) |
743 #endif | |
744 | |
745 #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
|
746 # define UChar UnicodeChar |
7 | 747 #else |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
748 # define UChar uChar.UnicodeChar |
7 | 749 #endif |
750 | |
751 /* The return code indicates key code size. */ | |
752 static int | |
753 #ifdef __BORLANDC__ | |
754 __stdcall | |
755 #endif | |
756 win32_kbd_patch_key( | |
26 | 757 KEY_EVENT_RECORD *pker) |
7 | 758 { |
759 UINT uMods = pker->dwControlKeyState; | |
760 static int s_iIsDead = 0; | |
761 static WORD awAnsiCode[2]; | |
762 static BYTE abKeystate[256]; | |
763 | |
764 | |
765 if (s_iIsDead == 2) | |
766 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
767 pker->UChar = (WCHAR) awAnsiCode[1]; |
7 | 768 s_iIsDead = 0; |
769 return 1; | |
770 } | |
771 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
772 if (pker->UChar != 0) |
7 | 773 return 1; |
774 | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1752
diff
changeset
|
775 vim_memset(abKeystate, 0, sizeof (abKeystate)); |
7 | 776 |
777 /* Clear any pending dead keys */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
778 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); |
7 | 779 |
780 if (uMods & SHIFT_PRESSED) | |
781 abKeystate[VK_SHIFT] = 0x80; | |
782 if (uMods & CAPSLOCK_ON) | |
783 abKeystate[VK_CAPITAL] = 1; | |
784 | |
785 if ((uMods & ALT_GR) == ALT_GR) | |
786 { | |
787 abKeystate[VK_CONTROL] = abKeystate[VK_LCONTROL] = | |
788 abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80; | |
789 } | |
790 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
791 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
|
792 abKeystate, awAnsiCode, 2, 0); |
7 | 793 |
794 if (s_iIsDead > 0) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
795 pker->UChar = (WCHAR) awAnsiCode[0]; |
7 | 796 |
797 return s_iIsDead; | |
798 } | |
799 | |
800 #ifdef _MSC_VER | |
801 /* MUST switch optimization on again here, otherwise a call to | |
802 * decode_key_event() may crash (e.g. when hitting caps-lock) */ | |
803 # pragma optimize("", on) | |
797 | 804 # pragma warning(pop) |
7 | 805 |
806 # if (_MSC_VER < 1100) | |
807 /* MUST turn off global optimisation for this next function, or | |
808 * pressing ctrl-minus in insert mode crashes Vim when built with | |
809 * VC4.1. -- negri. */ | |
810 # pragma optimize("g", off) | |
811 # endif | |
812 #endif | |
813 | |
814 static BOOL g_fJustGotFocus = FALSE; | |
815 | |
816 /* | |
817 * Decode a KEY_EVENT into one or two keystrokes | |
818 */ | |
819 static BOOL | |
820 decode_key_event( | |
821 KEY_EVENT_RECORD *pker, | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
822 WCHAR *pch, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
823 WCHAR *pch2, |
7 | 824 int *pmodifiers, |
825 BOOL fDoPost) | |
826 { | |
827 int i; | |
828 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL); | |
829 | |
830 *pch = *pch2 = NUL; | |
831 g_fJustGotFocus = FALSE; | |
832 | |
833 /* ignore key up events */ | |
834 if (!pker->bKeyDown) | |
835 return FALSE; | |
836 | |
837 /* ignore some keystrokes */ | |
838 switch (pker->wVirtualKeyCode) | |
839 { | |
840 /* modifiers */ | |
841 case VK_SHIFT: | |
842 case VK_CONTROL: | |
843 case VK_MENU: /* Alt key */ | |
844 return FALSE; | |
845 | |
846 default: | |
847 break; | |
848 } | |
849 | |
850 /* special cases */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
851 if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL) |
7 | 852 { |
853 /* Ctrl-6 is Ctrl-^ */ | |
854 if (pker->wVirtualKeyCode == '6') | |
855 { | |
856 *pch = Ctrl_HAT; | |
857 return TRUE; | |
858 } | |
859 /* Ctrl-2 is Ctrl-@ */ | |
860 else if (pker->wVirtualKeyCode == '2') | |
861 { | |
862 *pch = NUL; | |
863 return TRUE; | |
864 } | |
865 /* Ctrl-- is Ctrl-_ */ | |
866 else if (pker->wVirtualKeyCode == 0xBD) | |
867 { | |
868 *pch = Ctrl__; | |
869 return TRUE; | |
870 } | |
871 } | |
872 | |
873 /* Shift-TAB */ | |
874 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) | |
875 { | |
876 *pch = K_NUL; | |
877 *pch2 = '\017'; | |
878 return TRUE; | |
879 } | |
880 | |
881 for (i = sizeof(VirtKeyMap) / sizeof(VirtKeyMap[0]); --i >= 0; ) | |
882 { | |
883 if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode) | |
884 { | |
885 if (nModifs == 0) | |
886 *pch = VirtKeyMap[i].chAlone; | |
887 else if ((nModifs & SHIFT) != 0 && (nModifs & ~SHIFT) == 0) | |
888 *pch = VirtKeyMap[i].chShift; | |
889 else if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0) | |
890 *pch = VirtKeyMap[i].chCtrl; | |
891 else if ((nModifs & ALT) != 0 && (nModifs & ~ALT) == 0) | |
892 *pch = VirtKeyMap[i].chAlt; | |
893 | |
894 if (*pch != 0) | |
895 { | |
896 if (VirtKeyMap[i].fAnsiKey) | |
897 { | |
898 *pch2 = *pch; | |
899 *pch = K_NUL; | |
900 } | |
901 | |
902 return TRUE; | |
903 } | |
904 } | |
905 } | |
906 | |
907 i = win32_kbd_patch_key(pker); | |
908 | |
909 if (i < 0) | |
910 *pch = NUL; | |
911 else | |
912 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
913 *pch = (i > 0) ? pker->UChar : NUL; |
7 | 914 |
915 if (pmodifiers != NULL) | |
916 { | |
917 /* Pass on the ALT key as a modifier, but only when not combined | |
918 * with CTRL (which is ALTGR). */ | |
919 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) | |
920 *pmodifiers |= MOD_MASK_ALT; | |
921 | |
922 /* Pass on SHIFT only for special keys, because we don't know when | |
923 * it's already included with the character. */ | |
924 if ((nModifs & SHIFT) != 0 && *pch <= 0x20) | |
925 *pmodifiers |= MOD_MASK_SHIFT; | |
926 | |
927 /* Pass on CTRL only for non-special keys, because we don't know | |
928 * when it's already included with the character. And not when | |
929 * combined with ALT (which is ALTGR). */ | |
930 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 | |
931 && *pch >= 0x20 && *pch < 0x80) | |
932 *pmodifiers |= MOD_MASK_CTRL; | |
933 } | |
934 } | |
935 | |
936 return (*pch != NUL); | |
937 } | |
938 | |
939 #ifdef _MSC_VER | |
940 # pragma optimize("", on) | |
941 #endif | |
942 | |
943 #endif /* FEAT_GUI_W32 */ | |
944 | |
945 | |
946 #ifdef FEAT_MOUSE | |
947 | |
948 /* | |
949 * For the GUI the mouse handling is in gui_w32.c. | |
950 */ | |
951 # ifdef FEAT_GUI_W32 | |
323 | 952 /*ARGSUSED*/ |
7 | 953 void |
26 | 954 mch_setmouse(int on) |
7 | 955 { |
956 } | |
957 # else | |
958 static int g_fMouseAvail = FALSE; /* mouse present */ | |
959 static int g_fMouseActive = FALSE; /* mouse enabled */ | |
960 static int g_nMouseClick = -1; /* mouse status */ | |
961 static int g_xMouse; /* mouse x coordinate */ | |
962 static int g_yMouse; /* mouse y coordinate */ | |
963 | |
964 /* | |
965 * Enable or disable mouse input | |
966 */ | |
967 void | |
26 | 968 mch_setmouse(int on) |
7 | 969 { |
970 DWORD cmodein; | |
971 | |
972 if (!g_fMouseAvail) | |
973 return; | |
974 | |
975 g_fMouseActive = on; | |
976 GetConsoleMode(g_hConIn, &cmodein); | |
977 | |
978 if (g_fMouseActive) | |
979 cmodein |= ENABLE_MOUSE_INPUT; | |
980 else | |
981 cmodein &= ~ENABLE_MOUSE_INPUT; | |
982 | |
983 SetConsoleMode(g_hConIn, cmodein); | |
984 } | |
985 | |
986 /* | |
987 * Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT, | |
988 * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse | |
989 * move with a button held down; and MOUSE_RELEASE after a MOUSE_DRAG | |
990 * or a MOUSE_LEFT, _MIDDLE, or _RIGHT. We encode the button type, | |
991 * the number of clicks, and the Shift/Ctrl/Alt modifiers in g_nMouseClick, | |
992 * and we return the mouse position in g_xMouse and g_yMouse. | |
993 * | |
994 * Every MOUSE_LEFT, _MIDDLE, or _RIGHT will be followed by zero or more | |
995 * MOUSE_DRAGs and one MOUSE_RELEASE. MOUSE_RELEASE will be followed only | |
996 * by MOUSE_LEFT, _MIDDLE, or _RIGHT. | |
997 * | |
998 * For multiple clicks, we send, say, MOUSE_LEFT/1 click, MOUSE_RELEASE, | |
999 * MOUSE_LEFT/2 clicks, MOUSE_RELEASE, MOUSE_LEFT/3 clicks, MOUSE_RELEASE, .... | |
1000 * | |
1001 * Windows will send us MOUSE_MOVED notifications whenever the mouse | |
1002 * moves, even if it stays within the same character cell. We ignore | |
1003 * all MOUSE_MOVED messages if the position hasn't really changed, and | |
1004 * we ignore all MOUSE_MOVED messages where no button is held down (i.e., | |
1005 * we're only interested in MOUSE_DRAG). | |
1006 * | |
1007 * All of this is complicated by the code that fakes MOUSE_MIDDLE on | |
1008 * 2-button mouses by pressing the left & right buttons simultaneously. | |
1009 * In practice, it's almost impossible to click both at the same time, | |
1010 * so we need to delay a little. Also, we tend not to get MOUSE_RELEASE | |
1011 * in such cases, if the user is clicking quickly. | |
1012 */ | |
1013 static BOOL | |
1014 decode_mouse_event( | |
26 | 1015 MOUSE_EVENT_RECORD *pmer) |
7 | 1016 { |
1017 static int s_nOldButton = -1; | |
1018 static int s_nOldMouseClick = -1; | |
1019 static int s_xOldMouse = -1; | |
1020 static int s_yOldMouse = -1; | |
1021 static linenr_T s_old_topline = 0; | |
1022 #ifdef FEAT_DIFF | |
1023 static int s_old_topfill = 0; | |
1024 #endif | |
1025 static int s_cClicks = 1; | |
1026 static BOOL s_fReleased = TRUE; | |
1027 static DWORD s_dwLastClickTime = 0; | |
1028 static BOOL s_fNextIsMiddle = FALSE; | |
1029 | |
1030 static DWORD cButtons = 0; /* number of buttons supported */ | |
1031 | |
1032 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; | |
1033 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; | |
1034 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED; | |
1035 const DWORD LEFT_RIGHT = LEFT | RIGHT; | |
1036 | |
1037 int nButton; | |
1038 | |
1039 if (cButtons == 0 && !GetNumberOfConsoleMouseButtons(&cButtons)) | |
1040 cButtons = 2; | |
1041 | |
1042 if (!g_fMouseAvail || !g_fMouseActive) | |
1043 { | |
1044 g_nMouseClick = -1; | |
1045 return FALSE; | |
1046 } | |
1047 | |
1048 /* get a spurious MOUSE_EVENT immediately after receiving focus; ignore */ | |
1049 if (g_fJustGotFocus) | |
1050 { | |
1051 g_fJustGotFocus = FALSE; | |
1052 return FALSE; | |
1053 } | |
1054 | |
1055 /* unprocessed mouse click? */ | |
1056 if (g_nMouseClick != -1) | |
1057 return TRUE; | |
1058 | |
1059 nButton = -1; | |
1060 g_xMouse = pmer->dwMousePosition.X; | |
1061 g_yMouse = pmer->dwMousePosition.Y; | |
1062 | |
1063 if (pmer->dwEventFlags == MOUSE_MOVED) | |
1064 { | |
1065 /* ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these | |
1066 * events even when the mouse moves only within a char cell.) */ | |
1067 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) | |
1068 return FALSE; | |
1069 } | |
1070 | |
1071 /* If no buttons are pressed... */ | |
1072 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) | |
1073 { | |
1074 /* If the last thing returned was MOUSE_RELEASE, ignore this */ | |
1075 if (s_fReleased) | |
1076 return FALSE; | |
1077 | |
1078 nButton = MOUSE_RELEASE; | |
1079 s_fReleased = TRUE; | |
1080 } | |
1081 else /* one or more buttons pressed */ | |
1082 { | |
1083 /* on a 2-button mouse, hold down left and right buttons | |
1084 * simultaneously to get MIDDLE. */ | |
1085 | |
1086 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) | |
1087 { | |
1088 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); | |
1089 | |
1090 /* if either left or right button only is pressed, see if the | |
4352 | 1091 * next mouse event has both of them pressed */ |
7 | 1092 if (dwLR == LEFT || dwLR == RIGHT) |
1093 { | |
1094 for (;;) | |
1095 { | |
1096 /* wait a short time for next input event */ | |
1097 if (WaitForSingleObject(g_hConIn, p_mouset / 3) | |
1098 != WAIT_OBJECT_0) | |
1099 break; | |
1100 else | |
1101 { | |
1102 DWORD cRecords = 0; | |
1103 INPUT_RECORD ir; | |
1104 MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent; | |
1105 | |
5580 | 1106 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1107 |
1108 if (cRecords == 0 || ir.EventType != MOUSE_EVENT | |
1109 || !(pmer2->dwButtonState & LEFT_RIGHT)) | |
1110 break; | |
1111 else | |
1112 { | |
1113 if (pmer2->dwEventFlags != MOUSE_MOVED) | |
1114 { | |
5580 | 1115 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1116 |
1117 return decode_mouse_event(pmer2); | |
1118 } | |
1119 else if (s_xOldMouse == pmer2->dwMousePosition.X && | |
1120 s_yOldMouse == pmer2->dwMousePosition.Y) | |
1121 { | |
1122 /* throw away spurious mouse move */ | |
5580 | 1123 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1124 |
1125 /* are there any more mouse events in queue? */ | |
5580 | 1126 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1127 |
1128 if (cRecords==0 || ir.EventType != MOUSE_EVENT) | |
1129 break; | |
1130 } | |
1131 else | |
1132 break; | |
1133 } | |
1134 } | |
1135 } | |
1136 } | |
1137 } | |
1138 | |
1139 if (s_fNextIsMiddle) | |
1140 { | |
1141 nButton = (pmer->dwEventFlags == MOUSE_MOVED) | |
1142 ? MOUSE_DRAG : MOUSE_MIDDLE; | |
1143 s_fNextIsMiddle = FALSE; | |
1144 } | |
1145 else if (cButtons == 2 && | |
1146 ((pmer->dwButtonState & LEFT_RIGHT) == LEFT_RIGHT)) | |
1147 { | |
1148 nButton = MOUSE_MIDDLE; | |
1149 | |
1150 if (! s_fReleased && pmer->dwEventFlags != MOUSE_MOVED) | |
1151 { | |
1152 s_fNextIsMiddle = TRUE; | |
1153 nButton = MOUSE_RELEASE; | |
1154 } | |
1155 } | |
1156 else if ((pmer->dwButtonState & LEFT) == LEFT) | |
1157 nButton = MOUSE_LEFT; | |
1158 else if ((pmer->dwButtonState & MIDDLE) == MIDDLE) | |
1159 nButton = MOUSE_MIDDLE; | |
1160 else if ((pmer->dwButtonState & RIGHT) == RIGHT) | |
1161 nButton = MOUSE_RIGHT; | |
1162 | |
1163 if (! s_fReleased && ! s_fNextIsMiddle | |
1164 && nButton != s_nOldButton && s_nOldButton != MOUSE_DRAG) | |
1165 return FALSE; | |
1166 | |
1167 s_fReleased = s_fNextIsMiddle; | |
1168 } | |
1169 | |
1170 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) | |
1171 { | |
1172 /* button pressed or released, without mouse moving */ | |
1173 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1174 { | |
1175 DWORD dwCurrentTime = GetTickCount(); | |
1176 | |
1177 if (s_xOldMouse != g_xMouse | |
1178 || s_yOldMouse != g_yMouse | |
1179 || s_nOldButton != nButton | |
1180 || s_old_topline != curwin->w_topline | |
1181 #ifdef FEAT_DIFF | |
1182 || s_old_topfill != curwin->w_topfill | |
1183 #endif | |
1184 || (int)(dwCurrentTime - s_dwLastClickTime) > p_mouset) | |
1185 { | |
1186 s_cClicks = 1; | |
1187 } | |
1188 else if (++s_cClicks > 4) | |
1189 { | |
1190 s_cClicks = 1; | |
1191 } | |
1192 | |
1193 s_dwLastClickTime = dwCurrentTime; | |
1194 } | |
1195 } | |
1196 else if (pmer->dwEventFlags == MOUSE_MOVED) | |
1197 { | |
1198 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1199 nButton = MOUSE_DRAG; | |
1200 | |
1201 s_cClicks = 1; | |
1202 } | |
1203 | |
1204 if (nButton == -1) | |
1205 return FALSE; | |
1206 | |
1207 if (nButton != MOUSE_RELEASE) | |
1208 s_nOldButton = nButton; | |
1209 | |
1210 g_nMouseClick = nButton; | |
1211 | |
1212 if (pmer->dwControlKeyState & SHIFT_PRESSED) | |
1213 g_nMouseClick |= MOUSE_SHIFT; | |
1214 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) | |
1215 g_nMouseClick |= MOUSE_CTRL; | |
1216 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) | |
1217 g_nMouseClick |= MOUSE_ALT; | |
1218 | |
1219 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) | |
1220 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); | |
1221 | |
1222 /* only pass on interesting (i.e., different) mouse events */ | |
1223 if (s_xOldMouse == g_xMouse | |
1224 && s_yOldMouse == g_yMouse | |
1225 && s_nOldMouseClick == g_nMouseClick) | |
1226 { | |
1227 g_nMouseClick = -1; | |
1228 return FALSE; | |
1229 } | |
1230 | |
1231 s_xOldMouse = g_xMouse; | |
1232 s_yOldMouse = g_yMouse; | |
1233 s_old_topline = curwin->w_topline; | |
1234 #ifdef FEAT_DIFF | |
1235 s_old_topfill = curwin->w_topfill; | |
1236 #endif | |
1237 s_nOldMouseClick = g_nMouseClick; | |
1238 | |
1239 return TRUE; | |
1240 } | |
1241 | |
1242 # endif /* FEAT_GUI_W32 */ | |
1243 #endif /* FEAT_MOUSE */ | |
1244 | |
1245 | |
1246 #ifdef MCH_CURSOR_SHAPE | |
1247 /* | |
1248 * Set the shape of the cursor. | |
1249 * 'thickness' can be from 1 (thin) to 99 (block) | |
1250 */ | |
1251 static void | |
1252 mch_set_cursor_shape(int thickness) | |
1253 { | |
1254 CONSOLE_CURSOR_INFO ConsoleCursorInfo; | |
1255 ConsoleCursorInfo.dwSize = thickness; | |
1256 ConsoleCursorInfo.bVisible = s_cursor_visible; | |
1257 | |
1258 SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo); | |
1259 if (s_cursor_visible) | |
1260 SetConsoleCursorPosition(g_hConOut, g_coord); | |
1261 } | |
1262 | |
1263 void | |
1264 mch_update_cursor(void) | |
1265 { | |
1266 int idx; | |
1267 int thickness; | |
1268 | |
1269 /* | |
1270 * How the cursor is drawn depends on the current mode. | |
1271 */ | |
1272 idx = get_shape_idx(FALSE); | |
1273 | |
1274 if (shape_table[idx].shape == SHAPE_BLOCK) | |
1275 thickness = 99; /* 100 doesn't work on W95 */ | |
1276 else | |
1277 thickness = shape_table[idx].percentage; | |
1278 mch_set_cursor_shape(thickness); | |
1279 } | |
1280 #endif | |
1281 | |
1282 #ifndef FEAT_GUI_W32 /* this isn't used for the GUI */ | |
1283 /* | |
1284 * Handle FOCUS_EVENT. | |
1285 */ | |
1286 static void | |
1287 handle_focus_event(INPUT_RECORD ir) | |
1288 { | |
1289 g_fJustGotFocus = ir.Event.FocusEvent.bSetFocus; | |
1290 ui_focus_change((int)g_fJustGotFocus); | |
1291 } | |
1292 | |
1293 /* | |
1294 * Wait until console input from keyboard or mouse is available, | |
1295 * or the time is up. | |
1296 * Return TRUE if something is available FALSE if not. | |
1297 */ | |
1298 static int | |
1299 WaitForChar(long msec) | |
1300 { | |
1301 DWORD dwNow = 0, dwEndTime = 0; | |
1302 INPUT_RECORD ir; | |
1303 DWORD cRecords; | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1304 WCHAR ch, ch2; |
8949
c44ab784f5e5
commit https://github.com/vim/vim/commit/4445f7ee708f1a1304526a5979c9dd9883a92a0a
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
1305 #ifdef FEAT_TIMERS |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1306 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
|
1307 #endif |
7 | 1308 |
1309 if (msec > 0) | |
1310 /* Wait until the specified time has elapsed. */ | |
1311 dwEndTime = GetTickCount() + msec; | |
1312 else if (msec < 0) | |
1313 /* Wait forever. */ | |
1314 dwEndTime = INFINITE; | |
1315 | |
1316 /* We need to loop until the end of the time period, because | |
1317 * we might get multiple unusable mouse events in that time. | |
1318 */ | |
1319 for (;;) | |
1320 { | |
7866
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1321 #ifdef MESSAGE_QUEUE |
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1322 parse_queued_messages(); |
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1323 #endif |
14 | 1324 #ifdef FEAT_MZSCHEME |
1325 mzvim_check_threads(); | |
1326 #endif | |
7 | 1327 #ifdef FEAT_CLIENTSERVER |
1328 serverProcessPendingMessages(); | |
1329 #endif | |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1330 |
7 | 1331 if (0 |
1332 #ifdef FEAT_MOUSE | |
1333 || g_nMouseClick != -1 | |
1334 #endif | |
1335 #ifdef FEAT_CLIENTSERVER | |
1336 || input_available() | |
1337 #endif | |
1338 ) | |
1339 return TRUE; | |
1340 | |
1341 if (msec > 0) | |
1342 { | |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1343 /* 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
|
1344 * GetTickCount() may wrap around (overflow). */ |
7 | 1345 dwNow = GetTickCount(); |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1346 if ((int)(dwNow - dwEndTime) >= 0) |
7 | 1347 break; |
1348 } | |
1349 if (msec != 0) | |
1350 { | |
14 | 1351 DWORD dwWaitTime = dwEndTime - dwNow; |
1352 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
1353 #ifdef FEAT_JOB_CHANNEL |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1354 /* Check channel while waiting input. */ |
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1355 if (dwWaitTime > 100) |
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1356 dwWaitTime = 100; |
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1357 #endif |
14 | 1358 #ifdef FEAT_MZSCHEME |
1359 if (mzthreads_allowed() && p_mzq > 0 | |
1360 && (msec < 0 || (long)dwWaitTime > p_mzq)) | |
1361 dwWaitTime = p_mzq; /* don't wait longer than 'mzquantum' */ | |
1362 #endif | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1363 #ifdef FEAT_TIMERS |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1364 { |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1365 long due_time; |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1366 |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1367 /* 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
|
1368 if (dwWaitTime > 10) |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1369 { |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1370 /* 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
|
1371 * 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
|
1372 due_time = check_due_timer(); |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1373 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
|
1374 { |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1375 /* timer may have used feedkeys() */ |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1376 return FALSE; |
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1377 } |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1378 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
|
1379 dwWaitTime = due_time; |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1380 } |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1381 } |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1382 #endif |
7 | 1383 #ifdef FEAT_CLIENTSERVER |
1384 /* Wait for either an event on the console input or a message in | |
1385 * the client-server window. */ | |
6981 | 1386 if (msg_wait_for_multiple_objects(1, &g_hConIn, FALSE, |
14 | 1387 dwWaitTime, QS_SENDMESSAGE) != WAIT_OBJECT_0) |
7 | 1388 #else |
6981 | 1389 if (wait_for_single_object(g_hConIn, dwWaitTime) != WAIT_OBJECT_0) |
7 | 1390 #endif |
1391 continue; | |
1392 } | |
1393 | |
1394 cRecords = 0; | |
5580 | 1395 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1396 |
1397 #ifdef FEAT_MBYTE_IME | |
1398 if (State & CMDLINE && msg_row == Rows - 1) | |
1399 { | |
1400 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
1401 | |
1402 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
1403 { | |
1404 if (csbi.dwCursorPosition.Y != msg_row) | |
1405 { | |
1406 /* The screen is now messed up, must redraw the | |
1407 * command line and later all the windows. */ | |
1408 redraw_all_later(CLEAR); | |
1409 cmdline_row -= (msg_row - csbi.dwCursorPosition.Y); | |
1410 redrawcmd(); | |
1411 } | |
1412 } | |
1413 } | |
1414 #endif | |
1415 | |
1416 if (cRecords > 0) | |
1417 { | |
1418 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) | |
1419 { | |
1420 #ifdef FEAT_MBYTE_IME | |
1421 /* Windows IME sends two '\n's with only one 'ENTER'. First: | |
1422 * wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1423 if (ir.Event.KeyEvent.UChar == 0 |
7 | 1424 && ir.Event.KeyEvent.wVirtualKeyCode == 13) |
1425 { | |
5580 | 1426 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1427 continue; |
1428 } | |
1429 #endif | |
1430 if (decode_key_event(&ir.Event.KeyEvent, &ch, &ch2, | |
1431 NULL, FALSE)) | |
1432 return TRUE; | |
1433 } | |
1434 | |
5580 | 1435 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1436 |
1437 if (ir.EventType == FOCUS_EVENT) | |
1438 handle_focus_event(ir); | |
1439 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) | |
1440 shell_resized(); | |
1441 #ifdef FEAT_MOUSE | |
1442 else if (ir.EventType == MOUSE_EVENT | |
1443 && decode_mouse_event(&ir.Event.MouseEvent)) | |
1444 return TRUE; | |
1445 #endif | |
1446 } | |
1447 else if (msec == 0) | |
1448 break; | |
1449 } | |
1450 | |
1451 #ifdef FEAT_CLIENTSERVER | |
1452 /* Something might have been received while we were waiting. */ | |
1453 if (input_available()) | |
1454 return TRUE; | |
1455 #endif | |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1456 |
7 | 1457 return FALSE; |
1458 } | |
1459 | |
1460 #ifndef FEAT_GUI_MSWIN | |
1461 /* | |
1462 * return non-zero if a character is available | |
1463 */ | |
1464 int | |
26 | 1465 mch_char_avail(void) |
7 | 1466 { |
1467 return WaitForChar(0L); | |
1468 } | |
1469 #endif | |
1470 | |
1471 /* | |
1472 * Create the console input. Used when reading stdin doesn't work. | |
1473 */ | |
1474 static void | |
1475 create_conin(void) | |
1476 { | |
1477 g_hConIn = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE, | |
1478 FILE_SHARE_READ|FILE_SHARE_WRITE, | |
1479 (LPSECURITY_ATTRIBUTES) NULL, | |
840 | 1480 OPEN_EXISTING, 0, (HANDLE)NULL); |
7 | 1481 did_create_conin = TRUE; |
1482 } | |
1483 | |
1484 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1485 * Get a keystroke or a mouse event, use a blocking wait. |
7 | 1486 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1487 static WCHAR |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1488 tgetch(int *pmodifiers, WCHAR *pch2) |
7 | 1489 { |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1490 WCHAR ch; |
7 | 1491 |
1492 for (;;) | |
1493 { | |
1494 INPUT_RECORD ir; | |
1495 DWORD cRecords = 0; | |
1496 | |
1497 #ifdef FEAT_CLIENTSERVER | |
1498 (void)WaitForChar(-1L); | |
1499 if (input_available()) | |
1500 return 0; | |
1501 # ifdef FEAT_MOUSE | |
1502 if (g_nMouseClick != -1) | |
1503 return 0; | |
1504 # endif | |
1505 #endif | |
5580 | 1506 if (read_console_input(g_hConIn, &ir, 1, &cRecords) == 0) |
7 | 1507 { |
1508 if (did_create_conin) | |
1509 read_error_exit(); | |
1510 create_conin(); | |
1511 continue; | |
1512 } | |
1513 | |
1514 if (ir.EventType == KEY_EVENT) | |
1515 { | |
1516 if (decode_key_event(&ir.Event.KeyEvent, &ch, pch2, | |
1517 pmodifiers, TRUE)) | |
1518 return ch; | |
1519 } | |
1520 else if (ir.EventType == FOCUS_EVENT) | |
1521 handle_focus_event(ir); | |
1522 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) | |
1523 shell_resized(); | |
1524 #ifdef FEAT_MOUSE | |
1525 else if (ir.EventType == MOUSE_EVENT) | |
1526 { | |
1527 if (decode_mouse_event(&ir.Event.MouseEvent)) | |
1528 return 0; | |
1529 } | |
1530 #endif | |
1531 } | |
1532 } | |
1533 #endif /* !FEAT_GUI_W32 */ | |
1534 | |
1535 | |
1536 /* | |
3622 | 1537 * mch_inchar(): low-level input function. |
7 | 1538 * Get one or more characters from the keyboard or the mouse. |
1539 * If time == 0, do not wait for characters. | |
1540 * If time == n, wait a short time for characters. | |
1541 * If time == -1, wait forever for characters. | |
1542 * Returns the number of characters read into buf. | |
1543 */ | |
344 | 1544 /*ARGSUSED*/ |
7 | 1545 int |
1546 mch_inchar( | |
1547 char_u *buf, | |
1548 int maxlen, | |
1549 long time, | |
1550 int tb_change_cnt) | |
1551 { | |
1552 #ifndef FEAT_GUI_W32 /* this isn't used for the GUI */ | |
1553 | |
1554 int len; | |
1555 int c; | |
1556 #define TYPEAHEADLEN 20 | |
1557 static char_u typeahead[TYPEAHEADLEN]; /* previously typed bytes. */ | |
1558 static int typeaheadlen = 0; | |
1559 | |
1560 /* First use any typeahead that was kept because "buf" was too small. */ | |
1561 if (typeaheadlen > 0) | |
1562 goto theend; | |
1563 | |
1564 if (time >= 0) | |
1565 { | |
1566 if (!WaitForChar(time)) /* no character available */ | |
1567 return 0; | |
1568 } | |
1569 else /* time == -1, wait forever */ | |
1570 { | |
1571 mch_set_winsize_now(); /* Allow winsize changes from now on */ | |
1572 | |
203 | 1573 /* |
1574 * If there is no character available within 2 seconds (default) | |
1575 * write the autoscript file to disk. Or cause the CursorHold event | |
1576 * to be triggered. | |
1577 */ | |
1578 if (!WaitForChar(p_ut)) | |
7 | 1579 { |
1580 #ifdef FEAT_AUTOCMD | |
609 | 1581 if (trigger_cursorhold() && maxlen >= 3) |
7 | 1582 { |
203 | 1583 buf[0] = K_SPECIAL; |
1584 buf[1] = KS_EXTRA; | |
1585 buf[2] = (int)KE_CURSORHOLD; | |
1586 return 3; | |
7 | 1587 } |
1588 #endif | |
368 | 1589 before_blocking(); |
7 | 1590 } |
1591 } | |
1592 | |
1593 /* | |
1594 * Try to read as many characters as there are, until the buffer is full. | |
1595 */ | |
1596 | |
1597 /* we will get at least one key. Get more if they are available. */ | |
1598 g_fCBrkPressed = FALSE; | |
1599 | |
1600 #ifdef MCH_WRITE_DUMP | |
1601 if (fdDump) | |
1602 fputc('[', fdDump); | |
1603 #endif | |
1604 | |
1605 /* Keep looping until there is something in the typeahead buffer and more | |
1606 * to get and still room in the buffer (up to two bytes for a char and | |
1607 * three bytes for a modifier). */ | |
1608 while ((typeaheadlen == 0 || WaitForChar(0L)) | |
1609 && typeaheadlen + 5 <= TYPEAHEADLEN) | |
1610 { | |
1611 if (typebuf_changed(tb_change_cnt)) | |
1612 { | |
1613 /* "buf" may be invalid now if a client put something in the | |
1614 * typeahead buffer and "buf" is in the typeahead buffer. */ | |
1615 typeaheadlen = 0; | |
1616 break; | |
1617 } | |
1618 #ifdef FEAT_MOUSE | |
1619 if (g_nMouseClick != -1) | |
1620 { | |
1621 # ifdef MCH_WRITE_DUMP | |
1622 if (fdDump) | |
1623 fprintf(fdDump, "{%02x @ %d, %d}", | |
1624 g_nMouseClick, g_xMouse, g_yMouse); | |
1625 # endif | |
1626 typeahead[typeaheadlen++] = ESC + 128; | |
1627 typeahead[typeaheadlen++] = 'M'; | |
1628 typeahead[typeaheadlen++] = g_nMouseClick; | |
1629 typeahead[typeaheadlen++] = g_xMouse + '!'; | |
1630 typeahead[typeaheadlen++] = g_yMouse + '!'; | |
1631 g_nMouseClick = -1; | |
1632 } | |
1633 else | |
1634 #endif | |
1635 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1636 WCHAR ch2 = NUL; |
7 | 1637 int modifiers = 0; |
1638 | |
1639 c = tgetch(&modifiers, &ch2); | |
1640 | |
1641 if (typebuf_changed(tb_change_cnt)) | |
1642 { | |
1643 /* "buf" may be invalid now if a client put something in the | |
1644 * typeahead buffer and "buf" is in the typeahead buffer. */ | |
1645 typeaheadlen = 0; | |
1646 break; | |
1647 } | |
1648 | |
1649 if (c == Ctrl_C && ctrl_c_interrupts) | |
1650 { | |
1651 #if defined(FEAT_CLIENTSERVER) | |
1652 trash_input_buf(); | |
1653 #endif | |
1654 got_int = TRUE; | |
1655 } | |
1656 | |
1657 #ifdef FEAT_MOUSE | |
1658 if (g_nMouseClick == -1) | |
1659 #endif | |
1660 { | |
1661 int n = 1; | |
6047 | 1662 int conv = FALSE; |
1663 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1664 #ifdef FEAT_MBYTE |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1665 if (ch2 == NUL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1666 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1667 int i; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1668 char_u *p; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1669 WCHAR ch[2]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1670 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1671 ch[0] = c; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1672 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
|
1673 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1674 ch[1] = tgetch(&modifiers, &ch2); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1675 n++; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1676 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1677 p = utf16_to_enc(ch, &n); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1678 if (p != NULL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1679 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1680 for (i = 0; i < n; i++) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1681 typeahead[typeaheadlen + i] = p[i]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1682 vim_free(p); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1683 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1684 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1685 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1686 #endif |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1687 typeahead[typeaheadlen] = c; |
7 | 1688 if (ch2 != NUL) |
1689 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1690 typeahead[typeaheadlen + n] = 3; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1691 typeahead[typeaheadlen + n + 1] = (char_u)ch2; |
6047 | 1692 n += 2; |
7 | 1693 } |
1694 | |
6047 | 1695 if (conv) |
1696 { | |
1697 char_u *p = typeahead + typeaheadlen; | |
6524 | 1698 |
1699 if (*p != K_NUL) | |
6047 | 1700 { |
6524 | 1701 char_u *e = typeahead + TYPEAHEADLEN; |
1702 | |
1703 while (*p && p < e) | |
6047 | 1704 { |
6524 | 1705 if (*p == K_NUL) |
1706 { | |
1707 ++p; | |
1708 mch_memmove(p + 1, p, ((size_t)(e - p)) - 1); | |
1709 *p = 3; | |
1710 ++n; | |
1711 } | |
6047 | 1712 ++p; |
1713 } | |
1714 } | |
1715 } | |
1716 | |
7 | 1717 /* Use the ALT key to set the 8th bit of the character |
1718 * when it's one byte, the 8th bit isn't set yet and not | |
1719 * using a double-byte encoding (would become a lead | |
1720 * byte). */ | |
1721 if ((modifiers & MOD_MASK_ALT) | |
1722 && n == 1 | |
1723 && (typeahead[typeaheadlen] & 0x80) == 0 | |
1724 #ifdef FEAT_MBYTE | |
1725 && !enc_dbcs | |
1726 #endif | |
1727 ) | |
1728 { | |
1443 | 1729 #ifdef FEAT_MBYTE |
1730 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80, | |
1731 typeahead + typeaheadlen); | |
1732 #else | |
7 | 1733 typeahead[typeaheadlen] |= 0x80; |
1443 | 1734 #endif |
7 | 1735 modifiers &= ~MOD_MASK_ALT; |
1736 } | |
1737 | |
1738 if (modifiers != 0) | |
1739 { | |
1740 /* Prepend modifiers to the character. */ | |
1741 mch_memmove(typeahead + typeaheadlen + 3, | |
1742 typeahead + typeaheadlen, n); | |
1743 typeahead[typeaheadlen++] = K_SPECIAL; | |
1744 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER; | |
1745 typeahead[typeaheadlen++] = modifiers; | |
1746 } | |
1747 | |
1748 typeaheadlen += n; | |
1749 | |
1750 #ifdef MCH_WRITE_DUMP | |
1751 if (fdDump) | |
1752 fputc(c, fdDump); | |
1753 #endif | |
1754 } | |
1755 } | |
1756 } | |
1757 | |
1758 #ifdef MCH_WRITE_DUMP | |
1759 if (fdDump) | |
1760 { | |
1761 fputs("]\n", fdDump); | |
1762 fflush(fdDump); | |
1763 } | |
1764 #endif | |
1765 | |
1766 theend: | |
1767 /* Move typeahead to "buf", as much as fits. */ | |
1768 len = 0; | |
1769 while (len < maxlen && typeaheadlen > 0) | |
1770 { | |
1771 buf[len++] = typeahead[0]; | |
1772 mch_memmove(typeahead, typeahead + 1, --typeaheadlen); | |
1773 } | |
1774 return len; | |
1775 | |
1776 #else /* FEAT_GUI_W32 */ | |
1777 return 0; | |
1778 #endif /* FEAT_GUI_W32 */ | |
1779 } | |
1780 | |
3927 | 1781 #ifndef PROTO |
1782 # ifndef __MINGW32__ | |
1783 # include <shellapi.h> /* required for FindExecutable() */ | |
1784 # endif | |
7 | 1785 #endif |
1786 | |
9 | 1787 /* |
1788 * Return TRUE if "name" is in $PATH. | |
10 | 1789 * TODO: Should somehow check if it's really executable. |
9 | 1790 */ |
7 | 1791 static int |
5782 | 1792 executable_exists(char *name, char_u **path) |
7 | 1793 { |
9 | 1794 char *dum; |
1795 char fname[_MAX_PATH]; | |
6185 | 1796 char *curpath, *newpath; |
1797 long n; | |
9 | 1798 |
1799 #ifdef FEAT_MBYTE | |
1800 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
7 | 1801 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
1802 WCHAR *p = enc_to_utf16((char_u *)name, NULL); |
9 | 1803 WCHAR fnamew[_MAX_PATH]; |
1804 WCHAR *dumw; | |
6185 | 1805 WCHAR *wcurpath, *wnewpath; |
9 | 1806 |
1807 if (p != NULL) | |
1808 { | |
6185 | 1809 wcurpath = _wgetenv(L"PATH"); |
1810 wnewpath = (WCHAR*)alloc((unsigned)(wcslen(wcurpath) + 3) | |
1811 * sizeof(WCHAR)); | |
1812 if (wnewpath == NULL) | |
1813 return FALSE; | |
1814 wcscpy(wnewpath, L".;"); | |
1815 wcscat(wnewpath, wcurpath); | |
1816 n = (long)SearchPathW(wnewpath, p, NULL, _MAX_PATH, fnamew, &dumw); | |
1817 vim_free(wnewpath); | |
9 | 1818 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1819 if (n == 0) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1820 return FALSE; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1821 if (GetFileAttributesW(fnamew) & FILE_ATTRIBUTE_DIRECTORY) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1822 return FALSE; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1823 if (path != NULL) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1824 *path = utf16_to_enc(fnamew, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
1825 return TRUE; |
9 | 1826 } |
7 | 1827 } |
9 | 1828 #endif |
6185 | 1829 |
1830 curpath = getenv("PATH"); | |
1831 newpath = (char*)alloc((unsigned)(STRLEN(curpath) + 3)); | |
1832 if (newpath == NULL) | |
1833 return FALSE; | |
1834 STRCPY(newpath, ".;"); | |
1835 STRCAT(newpath, curpath); | |
1836 n = (long)SearchPath(newpath, name, NULL, _MAX_PATH, fname, &dum); | |
1837 vim_free(newpath); | |
1838 if (n == 0) | |
9 | 1839 return FALSE; |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
1840 if (mch_isdir((char_u *)fname)) |
9 | 1841 return FALSE; |
5782 | 1842 if (path != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
1843 *path = vim_strsave((char_u *)fname); |
9 | 1844 return TRUE; |
7 | 1845 } |
1846 | |
2584 | 1847 #if ((defined(__MINGW32__) || defined (__CYGWIN32__)) && \ |
2935 | 1848 __MSVCRT_VERSION__ >= 0x800) || (defined(_MSC_VER) && _MSC_VER >= 1400) |
2584 | 1849 /* |
1850 * Bad parameter handler. | |
1851 * | |
1852 * Certain MS CRT functions will intentionally crash when passed invalid | |
1853 * parameters to highlight possible security holes. Setting this function as | |
1854 * the bad parameter handler will prevent the crash. | |
1855 * | |
1856 * In debug builds the parameters contain CRT information that might help track | |
1857 * down the source of a problem, but in non-debug builds the arguments are all | |
1858 * NULL/0. Debug builds will also produce assert dialogs from the CRT, it is | |
1859 * worth allowing these to make debugging of issues easier. | |
1860 */ | |
1861 static void | |
1862 bad_param_handler(const wchar_t *expression, | |
1863 const wchar_t *function, | |
1864 const wchar_t *file, | |
1865 unsigned int line, | |
1866 uintptr_t pReserved) | |
1867 { | |
1868 } | |
1869 | |
1870 # define SET_INVALID_PARAM_HANDLER \ | |
1871 ((void)_set_invalid_parameter_handler(bad_param_handler)) | |
1872 #else | |
1873 # define SET_INVALID_PARAM_HANDLER | |
1874 #endif | |
1875 | |
7 | 1876 #ifdef FEAT_GUI_W32 |
1877 | |
1878 /* | |
1879 * GUI version of mch_init(). | |
1880 */ | |
1881 void | |
26 | 1882 mch_init(void) |
7 | 1883 { |
1884 #ifndef __MINGW32__ | |
1885 extern int _fmode; | |
1886 #endif | |
1887 | |
2584 | 1888 /* Silently handle invalid parameters to CRT functions */ |
1889 SET_INVALID_PARAM_HANDLER; | |
1890 | |
7 | 1891 /* Let critical errors result in a failure, not in a dialog box. Required |
1892 * for the timestamp test to work on removed floppies. */ | |
1893 SetErrorMode(SEM_FAILCRITICALERRORS); | |
1894 | |
1895 _fmode = O_BINARY; /* we do our own CR-LF translation */ | |
1896 | |
1897 /* Specify window size. Is there a place to get the default from? */ | |
1898 Rows = 25; | |
1899 Columns = 80; | |
1900 | |
1901 /* Look for 'vimrun' */ | |
1902 { | |
1903 char_u vimrun_location[_MAX_PATH + 4]; | |
1904 | |
1905 /* First try in same directory as gvim.exe */ | |
1906 STRCPY(vimrun_location, exe_name); | |
1907 STRCPY(gettail(vimrun_location), "vimrun.exe"); | |
1908 if (mch_getperm(vimrun_location) >= 0) | |
1909 { | |
1910 if (*skiptowhite(vimrun_location) != NUL) | |
1911 { | |
1912 /* Enclose path with white space in double quotes. */ | |
1913 mch_memmove(vimrun_location + 1, vimrun_location, | |
1914 STRLEN(vimrun_location) + 1); | |
1915 *vimrun_location = '"'; | |
1916 STRCPY(gettail(vimrun_location), "vimrun\" "); | |
1917 } | |
1918 else | |
1919 STRCPY(gettail(vimrun_location), "vimrun "); | |
1920 | |
1921 vimrun_path = (char *)vim_strsave(vimrun_location); | |
1922 s_dont_use_vimrun = FALSE; | |
1923 } | |
5782 | 1924 else if (executable_exists("vimrun.exe", NULL)) |
7 | 1925 s_dont_use_vimrun = FALSE; |
1926 | |
1927 /* Don't give the warning for a missing vimrun.exe right now, but only | |
1928 * when vimrun was supposed to be used. Don't bother people that do | |
1929 * not need vimrun.exe. */ | |
1930 if (s_dont_use_vimrun) | |
1931 need_vimrun_warning = TRUE; | |
1932 } | |
1933 | |
1934 /* | |
1935 * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'. | |
1936 * Otherwise the default "findstr /n" is used. | |
1937 */ | |
5782 | 1938 if (!executable_exists("findstr.exe", NULL)) |
7 | 1939 set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0); |
1940 | |
1941 #ifdef FEAT_CLIPBOARD | |
4168 | 1942 win_clip_init(); |
7 | 1943 #endif |
1944 } | |
1945 | |
1946 | |
1947 #else /* FEAT_GUI_W32 */ | |
1948 | |
1949 #define SRWIDTH(sr) ((sr).Right - (sr).Left + 1) | |
1950 #define SRHEIGHT(sr) ((sr).Bottom - (sr).Top + 1) | |
1951 | |
1952 /* | |
1953 * ClearConsoleBuffer() | |
1954 * Description: | |
1955 * Clears the entire contents of the console screen buffer, using the | |
1956 * specified attribute. | |
1957 * Returns: | |
1958 * TRUE on success | |
1959 */ | |
1960 static BOOL | |
1961 ClearConsoleBuffer(WORD wAttribute) | |
1962 { | |
1963 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
1964 COORD coord; | |
1965 DWORD NumCells, dummy; | |
1966 | |
1967 if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
1968 return FALSE; | |
1969 | |
1970 NumCells = csbi.dwSize.X * csbi.dwSize.Y; | |
1971 coord.X = 0; | |
1972 coord.Y = 0; | |
1973 if (!FillConsoleOutputCharacter(g_hConOut, ' ', NumCells, | |
1974 coord, &dummy)) | |
1975 { | |
1976 return FALSE; | |
1977 } | |
1978 if (!FillConsoleOutputAttribute(g_hConOut, wAttribute, NumCells, | |
1979 coord, &dummy)) | |
1980 { | |
1981 return FALSE; | |
1982 } | |
1983 | |
1984 return TRUE; | |
1985 } | |
1986 | |
1987 /* | |
1988 * FitConsoleWindow() | |
1989 * Description: | |
1990 * Checks if the console window will fit within given buffer dimensions. | |
1991 * Also, if requested, will shrink the window to fit. | |
1992 * Returns: | |
1993 * TRUE on success | |
1994 */ | |
1995 static BOOL | |
1996 FitConsoleWindow( | |
1997 COORD dwBufferSize, | |
1998 BOOL WantAdjust) | |
1999 { | |
2000 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2001 COORD dwWindowSize; | |
2002 BOOL NeedAdjust = FALSE; | |
2003 | |
2004 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2005 { | |
2006 /* | |
2007 * A buffer resize will fail if the current console window does | |
2008 * not lie completely within that buffer. To avoid this, we might | |
2009 * have to move and possibly shrink the window. | |
2010 */ | |
2011 if (csbi.srWindow.Right >= dwBufferSize.X) | |
2012 { | |
2013 dwWindowSize.X = SRWIDTH(csbi.srWindow); | |
2014 if (dwWindowSize.X > dwBufferSize.X) | |
2015 dwWindowSize.X = dwBufferSize.X; | |
2016 csbi.srWindow.Right = dwBufferSize.X - 1; | |
2017 csbi.srWindow.Left = dwBufferSize.X - dwWindowSize.X; | |
2018 NeedAdjust = TRUE; | |
2019 } | |
2020 if (csbi.srWindow.Bottom >= dwBufferSize.Y) | |
2021 { | |
2022 dwWindowSize.Y = SRHEIGHT(csbi.srWindow); | |
2023 if (dwWindowSize.Y > dwBufferSize.Y) | |
2024 dwWindowSize.Y = dwBufferSize.Y; | |
2025 csbi.srWindow.Bottom = dwBufferSize.Y - 1; | |
2026 csbi.srWindow.Top = dwBufferSize.Y - dwWindowSize.Y; | |
2027 NeedAdjust = TRUE; | |
2028 } | |
2029 if (NeedAdjust && WantAdjust) | |
2030 { | |
2031 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &csbi.srWindow)) | |
2032 return FALSE; | |
2033 } | |
2034 return TRUE; | |
2035 } | |
2036 | |
2037 return FALSE; | |
2038 } | |
2039 | |
2040 typedef struct ConsoleBufferStruct | |
2041 { | |
26 | 2042 BOOL IsValid; |
2043 CONSOLE_SCREEN_BUFFER_INFO Info; | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2044 PCHAR_INFO Buffer; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2045 COORD BufferSize; |
7 | 2046 } ConsoleBuffer; |
2047 | |
2048 /* | |
2049 * SaveConsoleBuffer() | |
2050 * Description: | |
2051 * Saves important information about the console buffer, including the | |
2052 * actual buffer contents. The saved information is suitable for later | |
2053 * restoration by RestoreConsoleBuffer(). | |
2054 * Returns: | |
2055 * TRUE if all information was saved; FALSE otherwise | |
2056 * If FALSE, still sets cb->IsValid if buffer characteristics were saved. | |
2057 */ | |
2058 static BOOL | |
2059 SaveConsoleBuffer( | |
2060 ConsoleBuffer *cb) | |
2061 { | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2062 DWORD NumCells; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2063 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2064 SMALL_RECT ReadRegion; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2065 WORD Y, Y_incr; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2066 |
7 | 2067 if (cb == NULL) |
2068 return FALSE; | |
2069 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2070 if (!GetConsoleScreenBufferInfo(g_hConOut, &cb->Info)) |
7 | 2071 { |
2072 cb->IsValid = FALSE; | |
2073 return FALSE; | |
2074 } | |
2075 cb->IsValid = TRUE; | |
2076 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2077 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2078 * 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
|
2079 * 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
|
2080 * 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
|
2081 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2082 if (!cb->IsValid || cb->Buffer == NULL || |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2083 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
|
2084 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
|
2085 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2086 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
|
2087 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
|
2088 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
|
2089 vim_free(cb->Buffer); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2090 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
|
2091 if (cb->Buffer == NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2092 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2093 } |
7 | 2094 |
2095 /* | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2096 * 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
|
2097 * 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
|
2098 * 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
|
2099 * 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
|
2100 * 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
|
2101 * 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
|
2102 * height of each chunk will be (12000 / width). |
7 | 2103 */ |
7078
383d6f39669b
commit https://github.com/vim/vim/commit/615942452eb74eee7d8386fd3d76a1534181fa06
Christian Brabandt <cb@256bit.org>
parents:
6981
diff
changeset
|
2104 BufferCoord.X = 0; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2105 ReadRegion.Left = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2106 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
|
2107 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
|
2108 for (Y = 0; Y < cb->BufferSize.Y; Y += Y_incr) |
7 | 2109 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2110 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2111 * 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
|
2112 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2113 BufferCoord.Y = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2114 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2115 * 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
|
2116 * 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
|
2117 * 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
|
2118 * 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
|
2119 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2120 ReadRegion.Top = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2121 ReadRegion.Bottom = Y + Y_incr - 1; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2122 if (!ReadConsoleOutput(g_hConOut, /* output handle */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2123 cb->Buffer, /* our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2124 cb->BufferSize, /* dimensions of our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2125 BufferCoord, /* offset in our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2126 &ReadRegion)) /* region to save */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2127 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2128 vim_free(cb->Buffer); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2129 cb->Buffer = NULL; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2130 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2131 } |
7 | 2132 } |
2133 | |
2134 return TRUE; | |
2135 } | |
2136 | |
2137 /* | |
2138 * RestoreConsoleBuffer() | |
2139 * Description: | |
2140 * Restores important information about the console buffer, including the | |
2141 * actual buffer contents, if desired. The information to restore is in | |
2142 * the same format used by SaveConsoleBuffer(). | |
2143 * Returns: | |
2144 * TRUE on success | |
2145 */ | |
2146 static BOOL | |
2147 RestoreConsoleBuffer( | |
26 | 2148 ConsoleBuffer *cb, |
2149 BOOL RestoreScreen) | |
7 | 2150 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2151 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2152 SMALL_RECT WriteRegion; |
7 | 2153 |
2154 if (cb == NULL || !cb->IsValid) | |
2155 return FALSE; | |
2156 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2157 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2158 * 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
|
2159 * 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
|
2160 * 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
|
2161 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2162 if (RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2163 ClearConsoleBuffer(cb->Info.wAttributes); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2164 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2165 FitConsoleWindow(cb->Info.dwSize, TRUE); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2166 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
|
2167 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2168 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
|
2169 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2170 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2171 if (!RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2172 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2173 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2174 * 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
|
2175 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2176 return TRUE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2177 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2178 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2179 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
|
2180 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2181 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
|
2182 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2183 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2184 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2185 * Restore the screen buffer contents. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2186 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2187 if (cb->Buffer != NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2188 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2189 BufferCoord.X = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2190 BufferCoord.Y = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2191 WriteRegion.Left = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2192 WriteRegion.Top = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2193 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
|
2194 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
|
2195 if (!WriteConsoleOutput(g_hConOut, /* output handle */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2196 cb->Buffer, /* our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2197 cb->BufferSize, /* dimensions of our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2198 BufferCoord, /* offset in our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2199 &WriteRegion)) /* region to restore */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2200 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2201 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2202 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2203 } |
7 | 2204 |
2205 return TRUE; | |
2206 } | |
2207 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2208 #define FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2209 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2210 static ConsoleBuffer g_cbOrig = { 0 }; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2211 #endif |
7 | 2212 static ConsoleBuffer g_cbNonTermcap = { 0 }; |
2213 static ConsoleBuffer g_cbTermcap = { 0 }; | |
2214 | |
2215 #ifdef FEAT_TITLE | |
2216 #ifdef __BORLANDC__ | |
2217 typedef HWND (__stdcall *GETCONSOLEWINDOWPROC)(VOID); | |
2218 #else | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2219 typedef HWND (WINAPI *GETCONSOLEWINDOWPROC)(VOID); |
7 | 2220 #endif |
2221 char g_szOrigTitle[256] = { 0 }; | |
2222 HWND g_hWnd = NULL; /* also used in os_mswin.c */ | |
2223 static HICON g_hOrigIconSmall = NULL; | |
2224 static HICON g_hOrigIcon = NULL; | |
2225 static HICON g_hVimIcon = NULL; | |
2226 static BOOL g_fCanChangeIcon = FALSE; | |
2227 | |
2228 /* ICON* are not defined in VC++ 4.0 */ | |
2229 #ifndef ICON_SMALL | |
2230 #define ICON_SMALL 0 | |
2231 #endif | |
2232 #ifndef ICON_BIG | |
2233 #define ICON_BIG 1 | |
2234 #endif | |
2235 /* | |
2236 * GetConsoleIcon() | |
2237 * Description: | |
2238 * Attempts to retrieve the small icon and/or the big icon currently in | |
2239 * use by a given window. | |
2240 * Returns: | |
2241 * TRUE on success | |
2242 */ | |
2243 static BOOL | |
2244 GetConsoleIcon( | |
26 | 2245 HWND hWnd, |
2246 HICON *phIconSmall, | |
2247 HICON *phIcon) | |
7 | 2248 { |
2249 if (hWnd == NULL) | |
2250 return FALSE; | |
2251 | |
2252 if (phIconSmall != NULL) | |
26 | 2253 *phIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, |
2254 (WPARAM)ICON_SMALL, (LPARAM)0); | |
7 | 2255 if (phIcon != NULL) |
26 | 2256 *phIcon = (HICON)SendMessage(hWnd, WM_GETICON, |
2257 (WPARAM)ICON_BIG, (LPARAM)0); | |
7 | 2258 return TRUE; |
2259 } | |
2260 | |
2261 /* | |
2262 * SetConsoleIcon() | |
2263 * Description: | |
2264 * Attempts to change the small icon and/or the big icon currently in | |
2265 * use by a given window. | |
2266 * Returns: | |
2267 * TRUE on success | |
2268 */ | |
2269 static BOOL | |
2270 SetConsoleIcon( | |
26 | 2271 HWND hWnd, |
2272 HICON hIconSmall, | |
2273 HICON hIcon) | |
7 | 2274 { |
2275 if (hWnd == NULL) | |
2276 return FALSE; | |
2277 | |
2278 if (hIconSmall != NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2279 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2280 (WPARAM)ICON_SMALL, (LPARAM)hIconSmall); |
7 | 2281 if (hIcon != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2282 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2283 (WPARAM)ICON_BIG, (LPARAM) hIcon); |
7 | 2284 return TRUE; |
2285 } | |
2286 | |
2287 /* | |
2288 * SaveConsoleTitleAndIcon() | |
2289 * Description: | |
2290 * Saves the current console window title in g_szOrigTitle, for later | |
2291 * restoration. Also, attempts to obtain a handle to the console window, | |
2292 * and use it to save the small and big icons currently in use by the | |
2293 * console window. This is not always possible on some versions of Windows; | |
2294 * nor is it possible when running Vim remotely using Telnet (since the | |
2295 * console window the user sees is owned by a remote process). | |
2296 */ | |
2297 static void | |
2298 SaveConsoleTitleAndIcon(void) | |
2299 { | |
2300 /* Save the original title. */ | |
2301 if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle))) | |
2302 return; | |
2303 | |
2304 /* | |
2305 * Obtain a handle to the console window using GetConsoleWindow() from | |
2306 * KERNEL32.DLL; we need to handle in order to change the window icon. | |
2307 * This function only exists on NT-based Windows, starting with Windows | |
2308 * 2000. On older operating systems, we can't change the window icon | |
2309 * anyway. | |
2310 */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2311 g_hWnd = GetConsoleWindow(); |
7 | 2312 if (g_hWnd == NULL) |
2313 return; | |
2314 | |
2315 /* Save the original console window icon. */ | |
2316 GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon); | |
2317 if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL) | |
2318 return; | |
2319 | |
2320 /* Extract the first icon contained in the Vim executable. */ | |
6249 | 2321 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
|
2322 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); |
7 | 2323 if (g_hVimIcon != NULL) |
2324 g_fCanChangeIcon = TRUE; | |
2325 } | |
2326 #endif | |
2327 | |
2328 static int g_fWindInitCalled = FALSE; | |
2329 static int g_fTermcapMode = FALSE; | |
2330 static CONSOLE_CURSOR_INFO g_cci; | |
2331 static DWORD g_cmodein = 0; | |
2332 static DWORD g_cmodeout = 0; | |
2333 | |
2334 /* | |
2335 * non-GUI version of mch_init(). | |
2336 */ | |
2337 void | |
26 | 2338 mch_init(void) |
7 | 2339 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2340 #ifndef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2341 CONSOLE_SCREEN_BUFFER_INFO csbi; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2342 #endif |
7 | 2343 #ifndef __MINGW32__ |
2344 extern int _fmode; | |
2345 #endif | |
2346 | |
2584 | 2347 /* Silently handle invalid parameters to CRT functions */ |
2348 SET_INVALID_PARAM_HANDLER; | |
2349 | |
7 | 2350 /* Let critical errors result in a failure, not in a dialog box. Required |
2351 * for the timestamp test to work on removed floppies. */ | |
2352 SetErrorMode(SEM_FAILCRITICALERRORS); | |
2353 | |
2354 _fmode = O_BINARY; /* we do our own CR-LF translation */ | |
2355 out_flush(); | |
2356 | |
2357 /* Obtain handles for the standard Console I/O devices */ | |
2358 if (read_cmd_fd == 0) | |
2359 g_hConIn = GetStdHandle(STD_INPUT_HANDLE); | |
2360 else | |
2361 create_conin(); | |
2362 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
|
2363 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2364 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2365 /* 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
|
2366 SaveConsoleBuffer(&g_cbOrig); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2367 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
|
2368 #else |
7 | 2369 /* Get current text attributes */ |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2370 GetConsoleScreenBufferInfo(g_hConOut, &csbi); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2371 g_attrCurrent = g_attrDefault = csbi.wAttributes; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2372 #endif |
7 | 2373 if (cterm_normal_fg_color == 0) |
2374 cterm_normal_fg_color = (g_attrCurrent & 0xf) + 1; | |
2375 if (cterm_normal_bg_color == 0) | |
2376 cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1; | |
2377 | |
2378 /* set termcap codes to current text attributes */ | |
2379 update_tcap(g_attrCurrent); | |
2380 | |
2381 GetConsoleCursorInfo(g_hConOut, &g_cci); | |
2382 GetConsoleMode(g_hConIn, &g_cmodein); | |
2383 GetConsoleMode(g_hConOut, &g_cmodeout); | |
2384 | |
2385 #ifdef FEAT_TITLE | |
2386 SaveConsoleTitleAndIcon(); | |
2387 /* | |
2388 * Set both the small and big icons of the console window to Vim's icon. | |
2389 * Note that Vim presently only has one size of icon (32x32), but it | |
2390 * automatically gets scaled down to 16x16 when setting the small icon. | |
2391 */ | |
2392 if (g_fCanChangeIcon) | |
2393 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); | |
2394 #endif | |
2395 | |
2396 ui_get_shellsize(); | |
2397 | |
2398 #ifdef MCH_WRITE_DUMP | |
2399 fdDump = fopen("dump", "wt"); | |
2400 | |
2401 if (fdDump) | |
2402 { | |
2403 time_t t; | |
2404 | |
2405 time(&t); | |
2406 fputs(ctime(&t), fdDump); | |
2407 fflush(fdDump); | |
2408 } | |
2409 #endif | |
2410 | |
2411 g_fWindInitCalled = TRUE; | |
2412 | |
2413 #ifdef FEAT_MOUSE | |
2414 g_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); | |
2415 #endif | |
2416 | |
2417 #ifdef FEAT_CLIPBOARD | |
4168 | 2418 win_clip_init(); |
7 | 2419 #endif |
2420 } | |
2421 | |
2422 /* | |
2423 * non-GUI version of mch_exit(). | |
2424 * Shut down and exit with status `r' | |
2425 * Careful: mch_exit() may be called before mch_init()! | |
2426 */ | |
2427 void | |
2428 mch_exit(int r) | |
2429 { | |
2430 stoptermcap(); | |
2431 | |
2432 if (g_fWindInitCalled) | |
2433 settmode(TMODE_COOK); | |
2434 | |
2435 ml_close_all(TRUE); /* remove all memfiles */ | |
2436 | |
2437 if (g_fWindInitCalled) | |
2438 { | |
2439 #ifdef FEAT_TITLE | |
2440 mch_restore_title(3); | |
2441 /* | |
2442 * Restore both the small and big icons of the console window to | |
2443 * what they were at startup. Don't do this when the window is | |
2444 * closed, Vim would hang here. | |
2445 */ | |
2446 if (g_fCanChangeIcon && !g_fForceExit) | |
2447 SetConsoleIcon(g_hWnd, g_hOrigIconSmall, g_hOrigIcon); | |
2448 #endif | |
2449 | |
2450 #ifdef MCH_WRITE_DUMP | |
2451 if (fdDump) | |
2452 { | |
2453 time_t t; | |
2454 | |
2455 time(&t); | |
2456 fputs(ctime(&t), fdDump); | |
2457 fclose(fdDump); | |
2458 } | |
2459 fdDump = NULL; | |
2460 #endif | |
2461 } | |
2462 | |
2463 SetConsoleCursorInfo(g_hConOut, &g_cci); | |
2464 SetConsoleMode(g_hConIn, g_cmodein); | |
2465 SetConsoleMode(g_hConOut, g_cmodeout); | |
2466 | |
2467 #ifdef DYNAMIC_GETTEXT | |
2468 dyn_libintl_end(); | |
2469 #endif | |
2470 | |
2471 exit(r); | |
2472 } | |
2473 #endif /* !FEAT_GUI_W32 */ | |
2474 | |
2475 /* | |
2476 * Do we have an interactive window? | |
2477 */ | |
323 | 2478 /*ARGSUSED*/ |
7 | 2479 int |
2480 mch_check_win( | |
2481 int argc, | |
2482 char **argv) | |
2483 { | |
2484 get_exe_name(); | |
2485 | |
2486 #ifdef FEAT_GUI_W32 | |
2487 return OK; /* GUI always has a tty */ | |
2488 #else | |
2489 if (isatty(1)) | |
2490 return OK; | |
2491 return FAIL; | |
2492 #endif | |
2493 } | |
2494 | |
2495 | |
5326 | 2496 #ifdef FEAT_MBYTE |
2497 /* | |
2498 * fname_casew(): Wide version of fname_case(). Set the case of the file name, | |
2499 * if it already exists. When "len" is > 0, also expand short to long | |
2500 * filenames. | |
2501 * Return FAIL if wide functions are not available, OK otherwise. | |
2502 * NOTE: much of this is identical to fname_case(), keep in sync! | |
2503 */ | |
2504 static int | |
2505 fname_casew( | |
2506 WCHAR *name, | |
2507 int len) | |
2508 { | |
2509 WCHAR szTrueName[_MAX_PATH + 2]; | |
2510 WCHAR szTrueNameTemp[_MAX_PATH + 2]; | |
2511 WCHAR *ptrue, *ptruePrev; | |
2512 WCHAR *porig, *porigPrev; | |
2513 int flen; | |
2514 WIN32_FIND_DATAW fb; | |
5529 | 2515 HANDLE hFind = INVALID_HANDLE_VALUE; |
5326 | 2516 int c; |
2517 int slen; | |
2518 | |
2519 flen = (int)wcslen(name); | |
2520 if (flen > _MAX_PATH) | |
2521 return OK; | |
2522 | |
2523 /* slash_adjust(name) not needed, already adjusted by fname_case(). */ | |
2524 | |
2525 /* Build the new name in szTrueName[] one component at a time. */ | |
2526 porig = name; | |
2527 ptrue = szTrueName; | |
2528 | |
2529 if (iswalpha(porig[0]) && porig[1] == L':') | |
2530 { | |
2531 /* copy leading drive letter */ | |
2532 *ptrue++ = *porig++; | |
2533 *ptrue++ = *porig++; | |
2534 } | |
5529 | 2535 *ptrue = NUL; /* in case nothing follows */ |
5326 | 2536 |
2537 while (*porig != NUL) | |
2538 { | |
2539 /* copy \ characters */ | |
2540 while (*porig == psepc) | |
2541 *ptrue++ = *porig++; | |
2542 | |
2543 ptruePrev = ptrue; | |
2544 porigPrev = porig; | |
2545 while (*porig != NUL && *porig != psepc) | |
2546 { | |
2547 *ptrue++ = *porig++; | |
2548 } | |
2549 *ptrue = NUL; | |
2550 | |
2551 /* To avoid a slow failure append "\*" when searching a directory, | |
2552 * server or network share. */ | |
2553 wcscpy(szTrueNameTemp, szTrueName); | |
2554 slen = (int)wcslen(szTrueNameTemp); | |
2555 if (*porig == psepc && slen + 2 < _MAX_PATH) | |
2556 wcscpy(szTrueNameTemp + slen, L"\\*"); | |
2557 | |
2558 /* Skip "", "." and "..". */ | |
2559 if (ptrue > ptruePrev | |
2560 && (ptruePrev[0] != L'.' | |
2561 || (ptruePrev[1] != NUL | |
2562 && (ptruePrev[1] != L'.' || ptruePrev[2] != NUL))) | |
2563 && (hFind = FindFirstFileW(szTrueNameTemp, &fb)) | |
2564 != INVALID_HANDLE_VALUE) | |
2565 { | |
2566 c = *porig; | |
2567 *porig = NUL; | |
2568 | |
2569 /* Only use the match when it's the same name (ignoring case) or | |
2570 * expansion is allowed and there is a match with the short name | |
2571 * and there is enough room. */ | |
2572 if (_wcsicoll(porigPrev, fb.cFileName) == 0 | |
2573 || (len > 0 | |
2574 && (_wcsicoll(porigPrev, fb.cAlternateFileName) == 0 | |
2575 && (int)(ptruePrev - szTrueName) | |
2576 + (int)wcslen(fb.cFileName) < len))) | |
2577 { | |
2578 wcscpy(ptruePrev, fb.cFileName); | |
2579 | |
2580 /* Look for exact match and prefer it if found. Must be a | |
2581 * long name, otherwise there would be only one match. */ | |
2582 while (FindNextFileW(hFind, &fb)) | |
2583 { | |
2584 if (*fb.cAlternateFileName != NUL | |
2585 && (wcscoll(porigPrev, fb.cFileName) == 0 | |
2586 || (len > 0 | |
2587 && (_wcsicoll(porigPrev, | |
2588 fb.cAlternateFileName) == 0 | |
2589 && (int)(ptruePrev - szTrueName) | |
2590 + (int)wcslen(fb.cFileName) < len)))) | |
2591 { | |
2592 wcscpy(ptruePrev, fb.cFileName); | |
2593 break; | |
2594 } | |
2595 } | |
2596 } | |
2597 FindClose(hFind); | |
2598 *porig = c; | |
2599 ptrue = ptruePrev + wcslen(ptruePrev); | |
2600 } | |
2601 } | |
2602 | |
2603 wcscpy(name, szTrueName); | |
2604 return OK; | |
2605 } | |
2606 #endif | |
2607 | |
7 | 2608 /* |
2609 * fname_case(): Set the case of the file name, if it already exists. | |
2610 * When "len" is > 0, also expand short to long filenames. | |
5326 | 2611 * NOTE: much of this is identical to fname_casew(), keep in sync! |
7 | 2612 */ |
2613 void | |
2614 fname_case( | |
2615 char_u *name, | |
2616 int len) | |
2617 { | |
2618 char szTrueName[_MAX_PATH + 2]; | |
2604 | 2619 char szTrueNameTemp[_MAX_PATH + 2]; |
7 | 2620 char *ptrue, *ptruePrev; |
2621 char *porig, *porigPrev; | |
2622 int flen; | |
2623 WIN32_FIND_DATA fb; | |
2624 HANDLE hFind; | |
2625 int c; | |
2604 | 2626 int slen; |
7 | 2627 |
434 | 2628 flen = (int)STRLEN(name); |
5326 | 2629 if (flen == 0) |
7 | 2630 return; |
2631 | |
2632 slash_adjust(name); | |
2633 | |
5326 | 2634 #ifdef FEAT_MBYTE |
2635 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2636 { | |
2637 WCHAR *p = enc_to_utf16(name, NULL); | |
2638 | |
2639 if (p != NULL) | |
2640 { | |
2641 char_u *q; | |
6262 | 2642 WCHAR buf[_MAX_PATH + 1]; |
2643 | |
2644 wcsncpy(buf, p, _MAX_PATH); | |
2645 buf[_MAX_PATH] = L'\0'; | |
5326 | 2646 vim_free(p); |
2647 | |
2648 if (fname_casew(buf, (len > 0) ? _MAX_PATH : 0) == OK) | |
2649 { | |
2650 q = utf16_to_enc(buf, NULL); | |
2651 if (q != NULL) | |
2652 { | |
2653 vim_strncpy(name, q, (len > 0) ? len - 1 : flen); | |
2654 vim_free(q); | |
2655 return; | |
2656 } | |
2657 } | |
2658 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2659 return; |
5326 | 2660 } |
2661 #endif | |
2662 | |
2663 /* If 'enc' is utf-8, flen can be larger than _MAX_PATH. | |
2664 * So we should check this after calling wide function. */ | |
2665 if (flen > _MAX_PATH) | |
2666 return; | |
2667 | |
7 | 2668 /* 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
|
2669 porig = (char *)name; |
7 | 2670 ptrue = szTrueName; |
2671 | |
2672 if (isalpha(porig[0]) && porig[1] == ':') | |
2673 { | |
2674 /* copy leading drive letter */ | |
2675 *ptrue++ = *porig++; | |
2676 *ptrue++ = *porig++; | |
2677 } | |
5529 | 2678 *ptrue = NUL; /* in case nothing follows */ |
7 | 2679 |
2680 while (*porig != NUL) | |
2681 { | |
2682 /* copy \ characters */ | |
2683 while (*porig == psepc) | |
2684 *ptrue++ = *porig++; | |
2685 | |
2686 ptruePrev = ptrue; | |
2687 porigPrev = porig; | |
2688 while (*porig != NUL && *porig != psepc) | |
2689 { | |
2690 #ifdef FEAT_MBYTE | |
2691 int l; | |
2692 | |
2693 if (enc_dbcs) | |
2694 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2695 l = (*mb_ptr2len)((char_u *)porig); |
7 | 2696 while (--l >= 0) |
2697 *ptrue++ = *porig++; | |
2698 } | |
2699 else | |
2700 #endif | |
2701 *ptrue++ = *porig++; | |
2702 } | |
2703 *ptrue = NUL; | |
2704 | |
2604 | 2705 /* To avoid a slow failure append "\*" when searching a directory, |
2706 * server or network share. */ | |
2707 STRCPY(szTrueNameTemp, szTrueName); | |
2615 | 2708 slen = (int)strlen(szTrueNameTemp); |
2604 | 2709 if (*porig == psepc && slen + 2 < _MAX_PATH) |
2710 STRCPY(szTrueNameTemp + slen, "\\*"); | |
2711 | |
7 | 2712 /* Skip "", "." and "..". */ |
2713 if (ptrue > ptruePrev | |
2714 && (ptruePrev[0] != '.' | |
2715 || (ptruePrev[1] != NUL | |
2716 && (ptruePrev[1] != '.' || ptruePrev[2] != NUL))) | |
2604 | 2717 && (hFind = FindFirstFile(szTrueNameTemp, &fb)) |
7 | 2718 != INVALID_HANDLE_VALUE) |
2719 { | |
2720 c = *porig; | |
2721 *porig = NUL; | |
2722 | |
2723 /* Only use the match when it's the same name (ignoring case) or | |
2724 * expansion is allowed and there is a match with the short name | |
2725 * and there is enough room. */ | |
2726 if (_stricoll(porigPrev, fb.cFileName) == 0 | |
2727 || (len > 0 | |
2728 && (_stricoll(porigPrev, fb.cAlternateFileName) == 0 | |
2729 && (int)(ptruePrev - szTrueName) | |
2730 + (int)strlen(fb.cFileName) < len))) | |
2731 { | |
2732 STRCPY(ptruePrev, fb.cFileName); | |
2733 | |
2734 /* Look for exact match and prefer it if found. Must be a | |
2735 * long name, otherwise there would be only one match. */ | |
2736 while (FindNextFile(hFind, &fb)) | |
2737 { | |
2738 if (*fb.cAlternateFileName != NUL | |
2739 && (strcoll(porigPrev, fb.cFileName) == 0 | |
2740 || (len > 0 | |
2741 && (_stricoll(porigPrev, | |
2742 fb.cAlternateFileName) == 0 | |
2743 && (int)(ptruePrev - szTrueName) | |
2744 + (int)strlen(fb.cFileName) < len)))) | |
2745 { | |
2746 STRCPY(ptruePrev, fb.cFileName); | |
2747 break; | |
2748 } | |
2749 } | |
2750 } | |
2751 FindClose(hFind); | |
2752 *porig = c; | |
2753 ptrue = ptruePrev + strlen(ptruePrev); | |
2754 } | |
2755 } | |
2756 | |
2757 STRCPY(name, szTrueName); | |
2758 } | |
2759 | |
2760 | |
2761 /* | |
2762 * Insert user name in s[len]. | |
2763 */ | |
2764 int | |
2765 mch_get_user_name( | |
26 | 2766 char_u *s, |
2767 int len) | |
7 | 2768 { |
1414 | 2769 char szUserName[256 + 1]; /* UNLEN is 256 */ |
7 | 2770 DWORD cch = sizeof szUserName; |
2771 | |
5549 | 2772 #ifdef FEAT_MBYTE |
2773 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2774 { | |
2775 WCHAR wszUserName[256 + 1]; /* UNLEN is 256 */ | |
2776 DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR); | |
2777 | |
2778 if (GetUserNameW(wszUserName, &wcch)) | |
2779 { | |
2780 char_u *p = utf16_to_enc(wszUserName, NULL); | |
2781 | |
2782 if (p != NULL) | |
2783 { | |
2784 vim_strncpy(s, p, len - 1); | |
2785 vim_free(p); | |
2786 return OK; | |
2787 } | |
2788 } | |
2789 } | |
2790 #endif | |
7 | 2791 if (GetUserName(szUserName, &cch)) |
2792 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2793 vim_strncpy(s, (char_u *)szUserName, len - 1); |
7 | 2794 return OK; |
2795 } | |
2796 s[0] = NUL; | |
2797 return FAIL; | |
2798 } | |
2799 | |
2800 | |
2801 /* | |
2802 * Insert host name in s[len]. | |
2803 */ | |
2804 void | |
2805 mch_get_host_name( | |
2806 char_u *s, | |
2807 int len) | |
2808 { | |
2809 DWORD cch = len; | |
2810 | |
5551 | 2811 #ifdef FEAT_MBYTE |
2812 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2813 { | |
2814 WCHAR wszHostName[256 + 1]; | |
2815 DWORD wcch = sizeof(wszHostName) / sizeof(WCHAR); | |
2816 | |
2817 if (GetComputerNameW(wszHostName, &wcch)) | |
2818 { | |
2819 char_u *p = utf16_to_enc(wszHostName, NULL); | |
2820 | |
2821 if (p != NULL) | |
2822 { | |
2823 vim_strncpy(s, p, len - 1); | |
2824 vim_free(p); | |
2825 return; | |
2826 } | |
2827 } | |
2828 } | |
2829 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2830 if (!GetComputerName((LPSTR)s, &cch)) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2831 vim_strncpy(s, (char_u *)"PC (Win32 Vim)", len - 1); |
7 | 2832 } |
2833 | |
2834 | |
2835 /* | |
2836 * return process ID | |
2837 */ | |
2838 long | |
26 | 2839 mch_get_pid(void) |
7 | 2840 { |
2841 return (long)GetCurrentProcessId(); | |
2842 } | |
2843 | |
2844 | |
2845 /* | |
2846 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
2847 * Return OK for success, FAIL for failure. | |
2848 */ | |
2849 int | |
2850 mch_dirname( | |
2851 char_u *buf, | |
2852 int len) | |
2853 { | |
2854 /* | |
2855 * Originally this was: | |
2856 * return (getcwd(buf, len) != NULL ? OK : FAIL); | |
2857 * But the Win32s known bug list says that getcwd() doesn't work | |
2858 * so use the Win32 system call instead. <Negri> | |
2859 */ | |
2860 #ifdef FEAT_MBYTE | |
2861 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2862 { | |
2863 WCHAR wbuf[_MAX_PATH + 1]; | |
2864 | |
2865 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0) | |
2866 { | |
1752 | 2867 char_u *p = utf16_to_enc(wbuf, NULL); |
7 | 2868 |
2869 if (p != NULL) | |
2870 { | |
417 | 2871 vim_strncpy(buf, p, len - 1); |
7 | 2872 vim_free(p); |
2873 return OK; | |
2874 } | |
2875 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2876 return FAIL; |
7 | 2877 } |
2878 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2879 return (GetCurrentDirectory(len, (LPSTR)buf) != 0 ? OK : FAIL); |
7 | 2880 } |
2881 | |
2882 /* | |
5494 | 2883 * Get file permissions for "name". |
2884 * Return mode_t or -1 for error. | |
7 | 2885 */ |
2886 long | |
26 | 2887 mch_getperm(char_u *name) |
7 | 2888 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8949
diff
changeset
|
2889 stat_T st; |
5494 | 2890 int n; |
2891 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2892 n = mch_stat((char *)name, &st); |
5588 | 2893 return n == 0 ? (long)(unsigned short)st.st_mode : -1L; |
7 | 2894 } |
2895 | |
2896 | |
2897 /* | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2898 * Set file permission for "name" to "perm". |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2899 * |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2900 * Return FAIL for failure, OK otherwise. |
7 | 2901 */ |
2902 int | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2903 mch_setperm(char_u *name, long perm) |
7 | 2904 { |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2905 long n = -1; |
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2906 |
7 | 2907 #ifdef FEAT_MBYTE |
2908 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2909 { | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2910 WCHAR *p = enc_to_utf16(name, NULL); |
7 | 2911 |
2912 if (p != NULL) | |
2913 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2914 n = _wchmod(p, perm); |
7 | 2915 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2916 if (n == -1) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2917 return FAIL; |
7 | 2918 } |
2919 } | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2920 if (n == -1) |
7 | 2921 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2922 n = _chmod((const char *)name, perm); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2923 if (n == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2924 return FAIL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2925 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2926 win32_set_archive(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2927 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2928 return OK; |
7 | 2929 } |
2930 | |
2931 /* | |
2932 * Set hidden flag for "name". | |
2933 */ | |
2934 void | |
2935 mch_hide(char_u *name) | |
2936 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2937 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2938 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2939 return; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2940 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2941 attrs |= FILE_ATTRIBUTE_HIDDEN; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2942 win32_setattrs(name, attrs); |
7 | 2943 } |
2944 | |
2945 /* | |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2946 * 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
|
2947 */ |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2948 int |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2949 mch_ishidden(char_u *name) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2950 { |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2951 int f = win32_getattrs(name); |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2952 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2953 if (f == -1) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2954 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
|
2955 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2956 return (f & FILE_ATTRIBUTE_HIDDEN) != 0; |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2957 } |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2958 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2959 /* |
7 | 2960 * return TRUE if "name" is a directory |
2961 * return FALSE if "name" is not a directory or upon error | |
2962 */ | |
2963 int | |
2964 mch_isdir(char_u *name) | |
2965 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2966 int f = win32_getattrs(name); |
7 | 2967 |
2968 if (f == -1) | |
2969 return FALSE; /* file does not exist at all */ | |
2970 | |
2971 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; | |
2972 } | |
2973 | |
2974 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
2975 * 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
|
2976 * 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
|
2977 * return FALSE for error |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
2978 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
2979 int |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
2980 mch_isrealdir(char_u *name) |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
2981 { |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
2982 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
|
2983 } |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
2984 |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
2985 /* |
2803 | 2986 * Create directory "name". |
2987 * Return 0 on success, -1 on error. | |
2988 */ | |
2989 int | |
2990 mch_mkdir(char_u *name) | |
2991 { | |
2992 #ifdef FEAT_MBYTE | |
2993 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2994 { | |
2995 WCHAR *p; | |
2996 int retval; | |
2997 | |
2998 p = enc_to_utf16(name, NULL); | |
2999 if (p == NULL) | |
3000 return -1; | |
3001 retval = _wmkdir(p); | |
3002 vim_free(p); | |
3003 return retval; | |
3004 } | |
3005 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3006 return _mkdir((const char *)name); |
2803 | 3007 } |
3008 | |
3009 /* | |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3010 * Delete directory "name". |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3011 * 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
|
3012 */ |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3013 int |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3014 mch_rmdir(char_u *name) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3015 { |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3016 #ifdef FEAT_MBYTE |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3017 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
|
3018 { |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3019 WCHAR *p; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3020 int retval; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3021 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3022 p = enc_to_utf16(name, NULL); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3023 if (p == NULL) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3024 return -1; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3025 retval = _wrmdir(p); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3026 vim_free(p); |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3027 return retval; |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3028 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3029 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3030 return _rmdir((const char *)name); |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3031 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3032 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3033 /* |
696 | 3034 * Return TRUE if file "fname" has more than one link. |
3035 */ | |
3036 int | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3037 mch_is_hard_link(char_u *fname) |
696 | 3038 { |
2793 | 3039 BY_HANDLE_FILE_INFORMATION info; |
3040 | |
3041 return win32_fileinfo(fname, &info) == FILEINFO_OK | |
3042 && info.nNumberOfLinks > 1; | |
3043 } | |
3044 | |
3045 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3046 * 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
|
3047 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3048 int |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3049 mch_is_symbolic_link(char_u *name) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3050 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3051 HANDLE hFind; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3052 int res = FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3053 WIN32_FIND_DATAA findDataA; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3054 DWORD fileFlags = 0, reparseTag = 0; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3055 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3056 WCHAR *wn = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3057 WIN32_FIND_DATAW findDataW; |
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 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
|
3060 wn = enc_to_utf16(name, NULL); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3061 if (wn != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3062 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3063 hFind = FindFirstFileW(wn, &findDataW); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3064 vim_free(wn); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3065 if (hFind != INVALID_HANDLE_VALUE) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3066 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3067 fileFlags = findDataW.dwFileAttributes; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3068 reparseTag = findDataW.dwReserved0; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3069 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3070 } |
4930
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3071 else |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3072 #endif |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3073 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3074 hFind = FindFirstFile((LPCSTR)name, &findDataA); |
4930
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3075 if (hFind != INVALID_HANDLE_VALUE) |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3076 { |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3077 fileFlags = findDataA.dwFileAttributes; |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3078 reparseTag = findDataA.dwReserved0; |
7155782d94fb
updated for version 7.3.1210
Bram Moolenaar <bram@vim.org>
parents:
4872
diff
changeset
|
3079 } |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3080 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3081 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3082 if (hFind != INVALID_HANDLE_VALUE) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3083 FindClose(hFind); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3084 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3085 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
|
3086 && (reparseTag == IO_REPARSE_TAG_SYMLINK |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3087 || reparseTag == IO_REPARSE_TAG_MOUNT_POINT)) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3088 res = TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3089 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3090 return res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3091 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3092 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3093 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3094 * 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
|
3095 * link. |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3096 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3097 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3098 mch_is_linked(char_u *fname) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3099 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3100 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
|
3101 return TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3102 return FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3103 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3104 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3105 /* |
2793 | 3106 * Get the by-handle-file-information for "fname". |
3107 * Returns FILEINFO_OK when OK. | |
3108 * returns FILEINFO_ENC_FAIL when enc_to_utf16() failed. | |
3109 * Returns FILEINFO_READ_FAIL when CreateFile() failed. | |
3110 * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed. | |
3111 */ | |
3112 int | |
3113 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info) | |
3114 { | |
696 | 3115 HANDLE hFile; |
2793 | 3116 int res = FILEINFO_READ_FAIL; |
696 | 3117 #ifdef FEAT_MBYTE |
3118 WCHAR *wn = NULL; | |
3119 | |
3120 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
2793 | 3121 { |
1752 | 3122 wn = enc_to_utf16(fname, NULL); |
2793 | 3123 if (wn == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3124 return FILEINFO_ENC_FAIL; |
2793 | 3125 } |
696 | 3126 if (wn != NULL) |
3127 { | |
3128 hFile = CreateFileW(wn, /* file name */ | |
3129 GENERIC_READ, /* access mode */ | |
2793 | 3130 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ |
696 | 3131 NULL, /* security descriptor */ |
3132 OPEN_EXISTING, /* creation disposition */ | |
2793 | 3133 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ |
696 | 3134 NULL); /* handle to template file */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3135 vim_free(wn); |
696 | 3136 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3137 else |
696 | 3138 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3139 hFile = CreateFile((LPCSTR)fname, /* file name */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3140 GENERIC_READ, /* access mode */ |
2793 | 3141 FILE_SHARE_READ | FILE_SHARE_WRITE, /* share mode */ |
696 | 3142 NULL, /* security descriptor */ |
3143 OPEN_EXISTING, /* creation disposition */ | |
2793 | 3144 FILE_FLAG_BACKUP_SEMANTICS, /* file attributes */ |
696 | 3145 NULL); /* handle to template file */ |
3146 | |
3147 if (hFile != INVALID_HANDLE_VALUE) | |
3148 { | |
2793 | 3149 if (GetFileInformationByHandle(hFile, info) != 0) |
3150 res = FILEINFO_OK; | |
3151 else | |
3152 res = FILEINFO_INFO_FAIL; | |
696 | 3153 CloseHandle(hFile); |
3154 } | |
3155 | |
3156 return res; | |
3157 } | |
3158 | |
3159 /* | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3160 * get file attributes for `name' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3161 * -1 : error |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3162 * else FILE_ATTRIBUTE_* defined in winnt.h |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3163 */ |
5494 | 3164 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3165 win32_getattrs(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3166 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3167 int attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3168 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3169 WCHAR *p = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3170 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3171 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3172 p = enc_to_utf16(name, NULL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3173 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3174 if (p != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3175 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3176 attr = GetFileAttributesW(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3177 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3178 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3179 else |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3180 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3181 attr = GetFileAttributes((char *)name); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3182 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3183 return attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3184 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3185 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3186 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3187 * set file attributes for `name' to `attrs' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3188 * |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3189 * return -1 for failure, 0 otherwise |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3190 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3191 static |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3192 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3193 win32_setattrs(char_u *name, int attrs) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3194 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3195 int res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3196 #ifdef FEAT_MBYTE |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3197 WCHAR *p = NULL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3198 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3199 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3200 p = enc_to_utf16(name, NULL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3201 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3202 if (p != NULL) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3203 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3204 res = SetFileAttributesW(p, attrs); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3205 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3206 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3207 else |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3208 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3209 res = SetFileAttributes((char *)name, attrs); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3210 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3211 return res ? 0 : -1; |
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 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3214 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3215 * Set archive flag for "name". |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3216 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3217 static |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3218 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3219 win32_set_archive(char_u *name) |
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 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3222 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3223 return -1; |
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 attrs |= FILE_ATTRIBUTE_ARCHIVE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3226 return win32_setattrs(name, attrs); |
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 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3229 /* |
7 | 3230 * Return TRUE if file or directory "name" is writable (not readonly). |
3231 * Strange semantics of Win32: a readonly directory is writable, but you can't | |
3232 * delete a file. Let's say this means it is writable. | |
3233 */ | |
3234 int | |
3235 mch_writable(char_u *name) | |
3236 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3237 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3238 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3239 return (attrs != -1 && (!(attrs & FILE_ATTRIBUTE_READONLY) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3240 || (attrs & FILE_ATTRIBUTE_DIRECTORY))); |
7 | 3241 } |
3242 | |
3243 /* | |
3244 * Return 1 if "name" can be executed, 0 if not. | |
6700 | 3245 * If "use_path" is FALSE only check if "name" is executable. |
7 | 3246 * Return -1 if unknown. |
3247 */ | |
3248 int | |
6700 | 3249 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3250 { |
10 | 3251 char_u buf[_MAX_PATH]; |
835 | 3252 int len = (int)STRLEN(name); |
10 | 3253 char_u *p; |
3254 | |
3255 if (len >= _MAX_PATH) /* safety check */ | |
3256 return FALSE; | |
6700 | 3257 if (!use_path) |
3258 { | |
3259 /* TODO: check if file is really executable. */ | |
3260 return mch_getperm(name) != -1 && !mch_isdir(name); | |
3261 } | |
10 | 3262 |
3263 /* If there already is an extension try using the name directly. Also do | |
3264 * this with a Unix-shell like 'shell'. */ | |
3265 if (vim_strchr(gettail(name), '.') != NULL | |
3266 || strstr((char *)gettail(p_sh), "sh") != NULL) | |
5782 | 3267 if (executable_exists((char *)name, path)) |
10 | 3268 return TRUE; |
3269 | |
3270 /* | |
3271 * Loop over all extensions in $PATHEXT. | |
3272 */ | |
417 | 3273 vim_strncpy(buf, name, _MAX_PATH - 1); |
10 | 3274 p = mch_getenv("PATHEXT"); |
3275 if (p == NULL) | |
3276 p = (char_u *)".com;.exe;.bat;.cmd"; | |
3277 while (*p) | |
3278 { | |
3279 if (p[0] == '.' && (p[1] == NUL || p[1] == ';')) | |
3280 { | |
3281 /* A single "." means no extension is added. */ | |
3282 buf[len] = NUL; | |
3283 ++p; | |
3284 if (*p) | |
3285 ++p; | |
3286 } | |
3287 else | |
3288 copy_option_part(&p, buf + len, _MAX_PATH - len, ";"); | |
5782 | 3289 if (executable_exists((char *)buf, path)) |
10 | 3290 return TRUE; |
3291 } | |
3292 return FALSE; | |
7 | 3293 } |
3294 | |
3295 /* | |
3296 * Check what "name" is: | |
3297 * NODE_NORMAL: file or directory (or doesn't exist) | |
3298 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3299 * NODE_OTHER: non-writable things | |
3300 */ | |
3301 int | |
3302 mch_nodetype(char_u *name) | |
3303 { | |
3304 HANDLE hFile; | |
3305 int type; | |
5324 | 3306 #ifdef FEAT_MBYTE |
3307 WCHAR *wn = NULL; | |
3308 #endif | |
7 | 3309 |
1004 | 3310 /* We can't open a file with a name "\\.\con" or "\\.\prn" and trying to |
3311 * read from it later will cause Vim to hang. Thus return NODE_WRITABLE | |
3312 * here. */ | |
3313 if (STRNCMP(name, "\\\\.\\", 4) == 0) | |
3314 return NODE_WRITABLE; | |
3315 | |
5324 | 3316 #ifdef FEAT_MBYTE |
3317 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
|
3318 wn = enc_to_utf16(name, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3319 |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3320 if (wn != NULL) |
5324 | 3321 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3322 hFile = CreateFileW(wn, /* file name */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3323 GENERIC_WRITE, /* access mode */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3324 0, /* share mode */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3325 NULL, /* security descriptor */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3326 OPEN_EXISTING, /* creation disposition */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3327 0, /* file attributes */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3328 NULL); /* handle to template file */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3329 vim_free(wn); |
5324 | 3330 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3331 else |
5324 | 3332 #endif |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3333 hFile = CreateFile((LPCSTR)name, /* file name */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3334 GENERIC_WRITE, /* access mode */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3335 0, /* share mode */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3336 NULL, /* security descriptor */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3337 OPEN_EXISTING, /* creation disposition */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3338 0, /* file attributes */ |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3339 NULL); /* handle to template file */ |
5324 | 3340 |
7 | 3341 if (hFile == INVALID_HANDLE_VALUE) |
3342 return NODE_NORMAL; | |
3343 | |
3344 type = GetFileType(hFile); | |
3345 CloseHandle(hFile); | |
3346 if (type == FILE_TYPE_CHAR) | |
3347 return NODE_WRITABLE; | |
3348 if (type == FILE_TYPE_DISK) | |
3349 return NODE_NORMAL; | |
3350 return NODE_OTHER; | |
3351 } | |
3352 | |
3353 #ifdef HAVE_ACL | |
3354 struct my_acl | |
3355 { | |
3356 PSECURITY_DESCRIPTOR pSecurityDescriptor; | |
3357 PSID pSidOwner; | |
3358 PSID pSidGroup; | |
3359 PACL pDacl; | |
3360 PACL pSacl; | |
3361 }; | |
3362 #endif | |
3363 | |
3364 /* | |
3365 * Return a pointer to the ACL of file "fname" in allocated memory. | |
3366 * Return NULL if the ACL is not available for whatever reason. | |
3367 */ | |
3368 vim_acl_T | |
26 | 3369 mch_get_acl(char_u *fname) |
7 | 3370 { |
3371 #ifndef HAVE_ACL | |
3372 return (vim_acl_T)NULL; | |
3373 #else | |
3374 struct my_acl *p = NULL; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3375 DWORD err; |
7 | 3376 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3377 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
|
3378 if (p != NULL) |
7 | 3379 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3380 # ifdef FEAT_MBYTE |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3381 WCHAR *wn = NULL; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3382 |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3383 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
|
3384 wn = enc_to_utf16(fname, NULL); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3385 if (wn != NULL) |
7 | 3386 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3387 /* 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
|
3388 err = GetNamedSecurityInfoW( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3389 wn, // Abstract filename |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3390 SE_FILE_OBJECT, // File Object |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3391 OWNER_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3392 GROUP_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3393 DACL_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3394 SACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3395 &p->pSidOwner, // Ownership information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3396 &p->pSidGroup, // Group membership. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3397 &p->pDacl, // Discretionary information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3398 &p->pSacl, // For auditing purposes. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3399 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3400 if (err == ERROR_ACCESS_DENIED || |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3401 err == ERROR_PRIVILEGE_NOT_HELD) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3402 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3403 /* Retrieve only DACL. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3404 (void)GetNamedSecurityInfoW( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3405 wn, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3406 SE_FILE_OBJECT, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3407 DACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3408 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3409 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3410 &p->pDacl, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3411 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3412 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3413 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3414 if (p->pSecurityDescriptor == NULL) |
7 | 3415 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3416 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
|
3417 p = NULL; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3418 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3419 vim_free(wn); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3420 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3421 else |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3422 # endif |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3423 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3424 /* 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
|
3425 err = GetNamedSecurityInfo( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3426 (LPSTR)fname, // Abstract filename |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3427 SE_FILE_OBJECT, // File Object |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3428 OWNER_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3429 GROUP_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3430 DACL_SECURITY_INFORMATION | |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3431 SACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3432 &p->pSidOwner, // Ownership information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3433 &p->pSidGroup, // Group membership. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3434 &p->pDacl, // Discretionary information. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3435 &p->pSacl, // For auditing purposes. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3436 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3437 if (err == ERROR_ACCESS_DENIED || |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3438 err == ERROR_PRIVILEGE_NOT_HELD) |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3439 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3440 /* Retrieve only DACL. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3441 (void)GetNamedSecurityInfo( |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3442 (LPSTR)fname, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3443 SE_FILE_OBJECT, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3444 DACL_SECURITY_INFORMATION, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3445 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3446 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3447 &p->pDacl, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3448 NULL, |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3449 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3450 } |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3451 if (p->pSecurityDescriptor == NULL) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3452 { |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3453 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
|
3454 p = NULL; |
7 | 3455 } |
3456 } | |
3457 } | |
3458 | |
3459 return (vim_acl_T)p; | |
3460 #endif | |
3461 } | |
3462 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3463 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3464 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3465 * Check if "acl" contains inherited ACE. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3466 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3467 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3468 is_acl_inherited(PACL acl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3469 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3470 DWORD i; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3471 ACL_SIZE_INFORMATION acl_info; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3472 PACCESS_ALLOWED_ACE ace; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3473 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3474 acl_info.AceCount = 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3475 GetAclInformation(acl, &acl_info, sizeof(acl_info), AclSizeInformation); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3476 for (i = 0; i < acl_info.AceCount; i++) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3477 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3478 GetAce(acl, i, (LPVOID *)&ace); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3479 if (ace->Header.AceFlags & INHERITED_ACE) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3480 return TRUE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3481 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3482 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3483 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3484 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3485 |
7 | 3486 /* |
3487 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3488 * Errors are ignored. | |
3489 * This must only be called with "acl" equal to what mch_get_acl() returned. | |
3490 */ | |
3491 void | |
26 | 3492 mch_set_acl(char_u *fname, vim_acl_T acl) |
7 | 3493 { |
3494 #ifdef HAVE_ACL | |
3495 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
|
3496 SECURITY_INFORMATION sec_info = 0; |
7 | 3497 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3498 if (p != NULL) |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3499 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3500 # ifdef FEAT_MBYTE |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3501 WCHAR *wn = NULL; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3502 # endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3503 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3504 /* Set security flags */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3505 if (p->pSidOwner) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3506 sec_info |= OWNER_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3507 if (p->pSidGroup) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3508 sec_info |= GROUP_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3509 if (p->pDacl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3510 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3511 sec_info |= DACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3512 /* Do not inherit its parent's DACL. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3513 * 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
|
3514 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3515 if (!is_acl_inherited(p->pDacl)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3516 sec_info |= PROTECTED_DACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3517 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3518 if (p->pSacl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3519 sec_info |= SACL_SECURITY_INFORMATION; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3520 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3521 # ifdef FEAT_MBYTE |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3522 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3523 wn = enc_to_utf16(fname, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3524 if (wn != NULL) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3525 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3526 (void)SetNamedSecurityInfoW( |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3527 wn, // Abstract filename |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3528 SE_FILE_OBJECT, // File Object |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3529 sec_info, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3530 p->pSidOwner, // Ownership information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3531 p->pSidGroup, // Group membership. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3532 p->pDacl, // Discretionary information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3533 p->pSacl // For auditing purposes. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3534 ); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3535 vim_free(wn); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3536 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3537 else |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3538 # endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3539 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3540 (void)SetNamedSecurityInfo( |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3541 (LPSTR)fname, // Abstract filename |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3542 SE_FILE_OBJECT, // File Object |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3543 sec_info, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3544 p->pSidOwner, // Ownership information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3545 p->pSidGroup, // Group membership. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3546 p->pDacl, // Discretionary information. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3547 p->pSacl // For auditing purposes. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3548 ); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3549 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3550 } |
7 | 3551 #endif |
3552 } | |
3553 | |
3554 void | |
26 | 3555 mch_free_acl(vim_acl_T acl) |
7 | 3556 { |
3557 #ifdef HAVE_ACL | |
3558 struct my_acl *p = (struct my_acl *)acl; | |
3559 | |
3560 if (p != NULL) | |
3561 { | |
3562 LocalFree(p->pSecurityDescriptor); // Free the memory just in case | |
3563 vim_free(p); | |
3564 } | |
3565 #endif | |
3566 } | |
3567 | |
3568 #ifndef FEAT_GUI_W32 | |
3569 | |
3570 /* | |
3571 * handler for ctrl-break, ctrl-c interrupts, and fatal events. | |
3572 */ | |
3573 static BOOL WINAPI | |
3574 handler_routine( | |
3575 DWORD dwCtrlType) | |
3576 { | |
3577 switch (dwCtrlType) | |
3578 { | |
3579 case CTRL_C_EVENT: | |
3580 if (ctrl_c_interrupts) | |
3581 g_fCtrlCPressed = TRUE; | |
3582 return TRUE; | |
3583 | |
3584 case CTRL_BREAK_EVENT: | |
3585 g_fCBrkPressed = TRUE; | |
3586 return TRUE; | |
3587 | |
3588 /* fatal events: shut down gracefully */ | |
3589 case CTRL_CLOSE_EVENT: | |
3590 case CTRL_LOGOFF_EVENT: | |
3591 case CTRL_SHUTDOWN_EVENT: | |
3592 windgoto((int)Rows - 1, 0); | |
3593 g_fForceExit = TRUE; | |
3594 | |
1569 | 3595 vim_snprintf((char *)IObuff, IOSIZE, _("Vim: Caught %s event\n"), |
7 | 3596 (dwCtrlType == CTRL_CLOSE_EVENT |
3597 ? _("close") | |
3598 : dwCtrlType == CTRL_LOGOFF_EVENT | |
3599 ? _("logoff") | |
3600 : _("shutdown"))); | |
3601 #ifdef DEBUG | |
3602 OutputDebugString(IObuff); | |
3603 #endif | |
3604 | |
3605 preserve_exit(); /* output IObuff, preserve files and exit */ | |
3606 | |
3607 return TRUE; /* not reached */ | |
3608 | |
3609 default: | |
3610 return FALSE; | |
3611 } | |
3612 } | |
3613 | |
3614 | |
3615 /* | |
3616 * set the tty in (raw) ? "raw" : "cooked" mode | |
3617 */ | |
3618 void | |
26 | 3619 mch_settmode(int tmode) |
7 | 3620 { |
3621 DWORD cmodein; | |
3622 DWORD cmodeout; | |
3623 BOOL bEnableHandler; | |
3624 | |
3625 GetConsoleMode(g_hConIn, &cmodein); | |
3626 GetConsoleMode(g_hConOut, &cmodeout); | |
3627 if (tmode == TMODE_RAW) | |
3628 { | |
3629 cmodein &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3630 ENABLE_ECHO_INPUT); | |
3631 #ifdef FEAT_MOUSE | |
3632 if (g_fMouseActive) | |
3633 cmodein |= ENABLE_MOUSE_INPUT; | |
3634 #endif | |
3635 cmodeout &= ~(ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); | |
3636 bEnableHandler = TRUE; | |
3637 } | |
3638 else /* cooked */ | |
3639 { | |
3640 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3641 ENABLE_ECHO_INPUT); | |
3642 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); | |
3643 bEnableHandler = FALSE; | |
3644 } | |
3645 SetConsoleMode(g_hConIn, cmodein); | |
3646 SetConsoleMode(g_hConOut, cmodeout); | |
3647 SetConsoleCtrlHandler(handler_routine, bEnableHandler); | |
3648 | |
3649 #ifdef MCH_WRITE_DUMP | |
3650 if (fdDump) | |
3651 { | |
3652 fprintf(fdDump, "mch_settmode(%s, in = %x, out = %x)\n", | |
3653 tmode == TMODE_RAW ? "raw" : | |
3654 tmode == TMODE_COOK ? "cooked" : "normal", | |
3655 cmodein, cmodeout); | |
3656 fflush(fdDump); | |
3657 } | |
3658 #endif | |
3659 } | |
3660 | |
3661 | |
3662 /* | |
3663 * Get the size of the current window in `Rows' and `Columns' | |
3664 * Return OK when size could be determined, FAIL otherwise. | |
3665 */ | |
3666 int | |
26 | 3667 mch_get_shellsize(void) |
7 | 3668 { |
3669 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
3670 | |
3671 if (!g_fTermcapMode && g_cbTermcap.IsValid) | |
3672 { | |
3673 /* | |
3674 * For some reason, we are trying to get the screen dimensions | |
3675 * even though we are not in termcap mode. The 'Rows' and 'Columns' | |
3676 * variables are really intended to mean the size of Vim screen | |
3677 * while in termcap mode. | |
3678 */ | |
3679 Rows = g_cbTermcap.Info.dwSize.Y; | |
3680 Columns = g_cbTermcap.Info.dwSize.X; | |
3681 } | |
3682 else if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3683 { | |
3684 Rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3685 Columns = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3686 } | |
3687 else | |
3688 { | |
3689 Rows = 25; | |
3690 Columns = 80; | |
3691 } | |
3692 return OK; | |
3693 } | |
3694 | |
3695 /* | |
3696 * Set a console window to `xSize' * `ySize' | |
3697 */ | |
3698 static void | |
3699 ResizeConBufAndWindow( | |
26 | 3700 HANDLE hConsole, |
3701 int xSize, | |
3702 int ySize) | |
7 | 3703 { |
3704 CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ | |
3705 SMALL_RECT srWindowRect; /* hold the new console size */ | |
3706 COORD coordScreen; | |
3707 | |
3708 #ifdef MCH_WRITE_DUMP | |
3709 if (fdDump) | |
3710 { | |
3711 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize); | |
3712 fflush(fdDump); | |
3713 } | |
3714 #endif | |
3715 | |
3716 /* get the largest size we can size the console window to */ | |
3717 coordScreen = GetLargestConsoleWindowSize(hConsole); | |
3718 | |
3719 /* define the new console window size and scroll position */ | |
3720 srWindowRect.Left = srWindowRect.Top = (SHORT) 0; | |
3721 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); | |
3722 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); | |
3723 | |
3724 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3725 { | |
3726 int sx, sy; | |
3727 | |
3728 sx = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3729 sy = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3730 if (sy < ySize || sx < xSize) | |
3731 { | |
3732 /* | |
3733 * Increasing number of lines/columns, do buffer first. | |
3734 * Use the maximal size in x and y direction. | |
3735 */ | |
3736 if (sy < ySize) | |
3737 coordScreen.Y = ySize; | |
3738 else | |
3739 coordScreen.Y = sy; | |
3740 if (sx < xSize) | |
3741 coordScreen.X = xSize; | |
3742 else | |
3743 coordScreen.X = sx; | |
3744 SetConsoleScreenBufferSize(hConsole, coordScreen); | |
3745 } | |
3746 } | |
3747 | |
3748 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &srWindowRect)) | |
3749 { | |
3750 #ifdef MCH_WRITE_DUMP | |
3751 if (fdDump) | |
3752 { | |
3753 fprintf(fdDump, "SetConsoleWindowInfo failed: %lx\n", | |
3754 GetLastError()); | |
3755 fflush(fdDump); | |
3756 } | |
3757 #endif | |
3758 } | |
3759 | |
3760 /* define the new console buffer size */ | |
3761 coordScreen.X = xSize; | |
3762 coordScreen.Y = ySize; | |
3763 | |
3764 if (!SetConsoleScreenBufferSize(hConsole, coordScreen)) | |
3765 { | |
3766 #ifdef MCH_WRITE_DUMP | |
3767 if (fdDump) | |
3768 { | |
3769 fprintf(fdDump, "SetConsoleScreenBufferSize failed: %lx\n", | |
3770 GetLastError()); | |
3771 fflush(fdDump); | |
3772 } | |
3773 #endif | |
3774 } | |
3775 } | |
3776 | |
3777 | |
3778 /* | |
3779 * Set the console window to `Rows' * `Columns' | |
3780 */ | |
3781 void | |
26 | 3782 mch_set_shellsize(void) |
7 | 3783 { |
3784 COORD coordScreen; | |
3785 | |
3786 /* Don't change window size while still starting up */ | |
3787 if (suppress_winsize != 0) | |
3788 { | |
3789 suppress_winsize = 2; | |
3790 return; | |
3791 } | |
3792 | |
3793 if (term_console) | |
3794 { | |
3795 coordScreen = GetLargestConsoleWindowSize(g_hConOut); | |
3796 | |
3797 /* Clamp Rows and Columns to reasonable values */ | |
3798 if (Rows > coordScreen.Y) | |
3799 Rows = coordScreen.Y; | |
3800 if (Columns > coordScreen.X) | |
3801 Columns = coordScreen.X; | |
3802 | |
3803 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
3804 } | |
3805 } | |
3806 | |
3807 /* | |
3808 * Rows and/or Columns has changed. | |
3809 */ | |
3810 void | |
26 | 3811 mch_new_shellsize(void) |
7 | 3812 { |
3813 set_scroll_region(0, 0, Columns - 1, Rows - 1); | |
3814 } | |
3815 | |
3816 | |
3817 /* | |
3818 * Called when started up, to set the winsize that was delayed. | |
3819 */ | |
3820 void | |
26 | 3821 mch_set_winsize_now(void) |
7 | 3822 { |
3823 if (suppress_winsize == 2) | |
3824 { | |
3825 suppress_winsize = 0; | |
3826 mch_set_shellsize(); | |
3827 shell_resized(); | |
3828 } | |
3829 suppress_winsize = 0; | |
3830 } | |
3831 #endif /* FEAT_GUI_W32 */ | |
3832 | |
5547 | 3833 static BOOL |
3834 vim_create_process( | |
5556 | 3835 char *cmd, |
5569 | 3836 BOOL inherit_handles, |
5547 | 3837 DWORD flags, |
3838 STARTUPINFO *si, | |
3839 PROCESS_INFORMATION *pi) | |
3840 { | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3841 #ifdef FEAT_MBYTE |
5547 | 3842 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
3843 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3844 WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL); |
5547 | 3845 |
3846 if (wcmd != NULL) | |
3847 { | |
3848 BOOL ret; | |
3849 ret = CreateProcessW( | |
3850 NULL, /* Executable name */ | |
3851 wcmd, /* Command to execute */ | |
3852 NULL, /* Process security attributes */ | |
3853 NULL, /* Thread security attributes */ | |
3854 inherit_handles, /* Inherit handles */ | |
3855 flags, /* Creation flags */ | |
3856 NULL, /* Environment */ | |
3857 NULL, /* Current directory */ | |
5556 | 3858 (LPSTARTUPINFOW)si, /* Startup information */ |
5547 | 3859 pi); /* Process information */ |
3860 vim_free(wcmd); | |
3861 return ret; | |
3862 } | |
3863 } | |
3864 #endif | |
3865 return CreateProcess( | |
3866 NULL, /* Executable name */ | |
3867 cmd, /* Command to execute */ | |
3868 NULL, /* Process security attributes */ | |
3869 NULL, /* Thread security attributes */ | |
3870 inherit_handles, /* Inherit handles */ | |
3871 flags, /* Creation flags */ | |
3872 NULL, /* Environment */ | |
3873 NULL, /* Current directory */ | |
3874 si, /* Startup information */ | |
3875 pi); /* Process information */ | |
3876 } | |
7 | 3877 |
3878 | |
3879 #if defined(FEAT_GUI_W32) || defined(PROTO) | |
3880 | |
3881 /* | |
3882 * Specialised version of system() for Win32 GUI mode. | |
3883 * This version proceeds as follows: | |
3884 * 1. Create a console window for use by the subprocess | |
3885 * 2. Run the subprocess (it gets the allocated console by default) | |
3886 * 3. Wait for the subprocess to terminate and get its exit code | |
3887 * 4. Prompt the user to press a key to close the console window | |
3888 */ | |
3889 static int | |
2935 | 3890 mch_system_classic(char *cmd, int options) |
7 | 3891 { |
3892 STARTUPINFO si; | |
3893 PROCESS_INFORMATION pi; | |
3894 DWORD ret = 0; | |
3895 HWND hwnd = GetFocus(); | |
3896 | |
3897 si.cb = sizeof(si); | |
3898 si.lpReserved = NULL; | |
3899 si.lpDesktop = NULL; | |
3900 si.lpTitle = NULL; | |
3901 si.dwFlags = STARTF_USESHOWWINDOW; | |
3902 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3903 * It's nicer to run a filter command in a minimized window. |
2643 | 3904 * Don't activate the window to keep focus on Vim. |
7 | 3905 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3906 if (options & SHELL_DOOUT) |
2643 | 3907 si.wShowWindow = SW_SHOWMINNOACTIVE; |
7 | 3908 else |
3909 si.wShowWindow = SW_SHOWNORMAL; | |
3910 si.cbReserved2 = 0; | |
3911 si.lpReserved2 = NULL; | |
3912 | |
3913 /* Now, run the command */ | |
5547 | 3914 vim_create_process(cmd, FALSE, |
3915 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE, &si, &pi); | |
7 | 3916 |
3917 /* Wait for the command to terminate before continuing */ | |
3918 { | |
3919 #ifdef FEAT_GUI | |
3920 int delay = 1; | |
3921 | |
3922 /* Keep updating the window while waiting for the shell to finish. */ | |
3923 for (;;) | |
3924 { | |
3925 MSG msg; | |
3926 | |
3010 | 3927 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
7 | 3928 { |
3929 TranslateMessage(&msg); | |
3010 | 3930 pDispatchMessage(&msg); |
3720 | 3931 delay = 1; |
3932 continue; | |
7 | 3933 } |
3934 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
3935 break; | |
3936 | |
3937 /* We start waiting for a very short time and then increase it, so | |
3938 * that we respond quickly when the process is quick, and don't | |
3939 * consume too much overhead when it's slow. */ | |
3940 if (delay < 50) | |
3941 delay += 10; | |
3942 } | |
3943 #else | |
3944 WaitForSingleObject(pi.hProcess, INFINITE); | |
3945 #endif | |
3946 | |
3947 /* Get the command exit code */ | |
3948 GetExitCodeProcess(pi.hProcess, &ret); | |
3949 } | |
3950 | |
3951 /* Close the handles to the subprocess, so that it goes away */ | |
3952 CloseHandle(pi.hThread); | |
3953 CloseHandle(pi.hProcess); | |
3954 | |
3955 /* Try to get input focus back. Doesn't always work though. */ | |
3956 PostMessage(hwnd, WM_SETFOCUS, 0, 0); | |
3957 | |
3958 return ret; | |
3959 } | |
2935 | 3960 |
3961 /* | |
3962 * Thread launched by the gui to send the current buffer data to the | |
3963 * process. This way avoid to hang up vim totally if the children | |
3964 * process take a long time to process the lines. | |
3965 */ | |
9750
0f4b76b2757a
commit https://github.com/vim/vim/commit/4c38d66d25e4ba433fe87283a4664425a3dbd529
Christian Brabandt <cb@256bit.org>
parents:
9740
diff
changeset
|
3966 static unsigned int __stdcall |
2935 | 3967 sub_process_writer(LPVOID param) |
3968 { | |
3969 HANDLE g_hChildStd_IN_Wr = param; | |
3970 linenr_T lnum = curbuf->b_op_start.lnum; | |
3971 DWORD len = 0; | |
3972 DWORD l; | |
3973 char_u *lp = ml_get(lnum); | |
3974 char_u *s; | |
3975 int written = 0; | |
3976 | |
3977 for (;;) | |
3978 { | |
3979 l = (DWORD)STRLEN(lp + written); | |
3980 if (l == 0) | |
3981 len = 0; | |
3982 else if (lp[written] == NL) | |
3983 { | |
3984 /* NL -> NUL translation */ | |
3985 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); | |
3986 } | |
3987 else | |
3988 { | |
3989 s = vim_strchr(lp + written, NL); | |
3990 WriteFile(g_hChildStd_IN_Wr, (char *)lp + written, | |
3991 s == NULL ? l : (DWORD)(s - (lp + written)), | |
3992 &len, NULL); | |
3993 } | |
3994 if (len == (int)l) | |
3995 { | |
3996 /* Finished a line, add a NL, unless this line should not have | |
3997 * one. */ | |
3998 if (lnum != curbuf->b_op_end.lnum | |
6933 | 3999 || (!curbuf->b_p_bin |
4000 && curbuf->b_p_fixeol) | |
2935 | 4001 || (lnum != curbuf->b_no_eol_lnum |
4002 && (lnum != curbuf->b_ml.ml_line_count | |
4003 || curbuf->b_p_eol))) | |
4004 { | |
4238 | 4005 WriteFile(g_hChildStd_IN_Wr, "\n", 1, (LPDWORD)&ignored, NULL); |
2935 | 4006 } |
4007 | |
4008 ++lnum; | |
4009 if (lnum > curbuf->b_op_end.lnum) | |
4010 break; | |
4011 | |
4012 lp = ml_get(lnum); | |
4013 written = 0; | |
4014 } | |
4015 else if (len > 0) | |
4016 written += len; | |
4017 } | |
4018 | |
4019 /* finished all the lines, close pipe */ | |
4020 CloseHandle(g_hChildStd_IN_Wr); | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4021 return 0; |
2935 | 4022 } |
4023 | |
4024 | |
4025 # define BUFLEN 100 /* length for buffer, stolen from unix version */ | |
4026 | |
4027 /* | |
4028 * This function read from the children's stdout and write the | |
4029 * data on screen or in the buffer accordingly. | |
4030 */ | |
4031 static void | |
4032 dump_pipe(int options, | |
4033 HANDLE g_hChildStd_OUT_Rd, | |
4034 garray_T *ga, | |
4035 char_u buffer[], | |
4036 DWORD *buffer_off) | |
4037 { | |
4038 DWORD availableBytes = 0; | |
4039 DWORD i; | |
4040 int ret; | |
4041 DWORD len; | |
4042 DWORD toRead; | |
4043 int repeatCount; | |
4044 | |
4045 /* we query the pipe to see if there is any data to read | |
4046 * to avoid to perform a blocking read */ | |
4047 ret = PeekNamedPipe(g_hChildStd_OUT_Rd, /* pipe to query */ | |
4048 NULL, /* optional buffer */ | |
3622 | 4049 0, /* buffer size */ |
2935 | 4050 NULL, /* number of read bytes */ |
4051 &availableBytes, /* available bytes total */ | |
4052 NULL); /* byteLeft */ | |
4053 | |
4054 repeatCount = 0; | |
4055 /* We got real data in the pipe, read it */ | |
3622 | 4056 while (ret != 0 && availableBytes > 0) |
2935 | 4057 { |
4058 repeatCount++; | |
4059 toRead = | |
4060 # ifdef FEAT_MBYTE | |
4061 (DWORD)(BUFLEN - *buffer_off); | |
4062 # else | |
4063 (DWORD)BUFLEN; | |
4064 # endif | |
4065 toRead = availableBytes < toRead ? availableBytes : toRead; | |
4066 ReadFile(g_hChildStd_OUT_Rd, buffer | |
4067 # ifdef FEAT_MBYTE | |
4068 + *buffer_off, toRead | |
4069 # else | |
4070 , toRead | |
4071 # endif | |
4072 , &len, NULL); | |
4073 | |
4074 /* If we haven't read anything, there is a problem */ | |
4075 if (len == 0) | |
4076 break; | |
4077 | |
4078 availableBytes -= len; | |
4079 | |
4080 if (options & SHELL_READ) | |
4081 { | |
4082 /* Do NUL -> NL translation, append NL separated | |
4083 * lines to the current buffer. */ | |
4084 for (i = 0; i < len; ++i) | |
4085 { | |
4086 if (buffer[i] == NL) | |
4087 append_ga_line(ga); | |
4088 else if (buffer[i] == NUL) | |
4089 ga_append(ga, NL); | |
4090 else | |
4091 ga_append(ga, buffer[i]); | |
4092 } | |
4093 } | |
4094 # ifdef FEAT_MBYTE | |
4095 else if (has_mbyte) | |
4096 { | |
4097 int l; | |
3030 | 4098 int c; |
4099 char_u *p; | |
2935 | 4100 |
4101 len += *buffer_off; | |
4102 buffer[len] = NUL; | |
4103 | |
4104 /* Check if the last character in buffer[] is | |
4105 * incomplete, keep these bytes for the next | |
4106 * round. */ | |
4107 for (p = buffer; p < buffer + len; p += l) | |
4108 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9762
diff
changeset
|
4109 l = MB_CPTR2LEN(p); |
2935 | 4110 if (l == 0) |
4111 l = 1; /* NUL byte? */ | |
4112 else if (MB_BYTE2LEN(*p) != l) | |
4113 break; | |
4114 } | |
4115 if (p == buffer) /* no complete character */ | |
4116 { | |
4117 /* avoid getting stuck at an illegal byte */ | |
4118 if (len >= 12) | |
4119 ++p; | |
4120 else | |
4121 { | |
4122 *buffer_off = len; | |
4123 return; | |
4124 } | |
4125 } | |
4126 c = *p; | |
4127 *p = NUL; | |
4128 msg_puts(buffer); | |
4129 if (p < buffer + len) | |
4130 { | |
4131 *p = c; | |
4132 *buffer_off = (DWORD)((buffer + len) - p); | |
4133 mch_memmove(buffer, p, *buffer_off); | |
4134 return; | |
4135 } | |
4136 *buffer_off = 0; | |
4137 } | |
4138 # endif /* FEAT_MBYTE */ | |
4139 else | |
4140 { | |
4141 buffer[len] = NUL; | |
4142 msg_puts(buffer); | |
4143 } | |
4144 | |
4145 windgoto(msg_row, msg_col); | |
4146 cursor_on(); | |
4147 out_flush(); | |
4148 } | |
4149 } | |
4150 | |
4151 /* | |
4152 * Version of system to use for windows NT > 5.0 (Win2K), use pipe | |
4153 * for communication and doesn't open any new window. | |
4154 */ | |
4155 static int | |
4156 mch_system_piped(char *cmd, int options) | |
4157 { | |
4158 STARTUPINFO si; | |
4159 PROCESS_INFORMATION pi; | |
4160 DWORD ret = 0; | |
4161 | |
4162 HANDLE g_hChildStd_IN_Rd = NULL; | |
4163 HANDLE g_hChildStd_IN_Wr = NULL; | |
4164 HANDLE g_hChildStd_OUT_Rd = NULL; | |
4165 HANDLE g_hChildStd_OUT_Wr = NULL; | |
4166 | |
4167 char_u buffer[BUFLEN + 1]; /* reading buffer + size */ | |
4168 DWORD len; | |
4169 | |
4170 /* buffer used to receive keys */ | |
4171 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ | |
4172 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4173 | |
4174 DWORD i; | |
4175 int c; | |
4176 int noread_cnt = 0; | |
4177 garray_T ga; | |
4178 int delay = 1; | |
4179 DWORD buffer_off = 0; /* valid bytes in buffer[] */ | |
3361 | 4180 char *p = NULL; |
2935 | 4181 |
4182 SECURITY_ATTRIBUTES saAttr; | |
4183 | |
4184 /* Set the bInheritHandle flag so pipe handles are inherited. */ | |
4185 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); | |
4186 saAttr.bInheritHandle = TRUE; | |
4187 saAttr.lpSecurityDescriptor = NULL; | |
4188 | |
4189 if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) | |
4190 /* 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
|
4191 || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) |
2935 | 4192 /* Create a pipe for the child process's STDIN. */ |
4193 || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0) | |
4194 /* 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
|
4195 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) |
2935 | 4196 { |
4197 CloseHandle(g_hChildStd_IN_Rd); | |
4198 CloseHandle(g_hChildStd_IN_Wr); | |
4199 CloseHandle(g_hChildStd_OUT_Rd); | |
4200 CloseHandle(g_hChildStd_OUT_Wr); | |
4201 MSG_PUTS(_("\nCannot create pipes\n")); | |
4202 } | |
4203 | |
4204 si.cb = sizeof(si); | |
4205 si.lpReserved = NULL; | |
4206 si.lpDesktop = NULL; | |
4207 si.lpTitle = NULL; | |
4208 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; | |
4209 | |
4210 /* set-up our file redirection */ | |
4211 si.hStdError = g_hChildStd_OUT_Wr; | |
4212 si.hStdOutput = g_hChildStd_OUT_Wr; | |
4213 si.hStdInput = g_hChildStd_IN_Rd; | |
4214 si.wShowWindow = SW_HIDE; | |
4215 si.cbReserved2 = 0; | |
4216 si.lpReserved2 = NULL; | |
4217 | |
4218 if (options & SHELL_READ) | |
4219 ga_init2(&ga, 1, BUFLEN); | |
4220 | |
3361 | 4221 if (cmd != NULL) |
4222 { | |
4223 p = (char *)vim_strsave((char_u *)cmd); | |
4224 if (p != NULL) | |
4225 unescape_shellxquote((char_u *)p, p_sxe); | |
4226 else | |
4227 p = cmd; | |
4228 } | |
4229 | |
5547 | 4230 /* Now, run the command. |
4231 * About "Inherit handles" being TRUE: this command can be litigious, | |
4232 * handle inheritance was deactivated for pending temp file, but, if we | |
4233 * deactivate it, the pipes don't work for some reason. */ | |
4234 vim_create_process(p, TRUE, CREATE_DEFAULT_ERROR_MODE, &si, &pi); | |
2935 | 4235 |
3361 | 4236 if (p != cmd) |
4237 vim_free(p); | |
2935 | 4238 |
4239 /* Close our unused side of the pipes */ | |
4240 CloseHandle(g_hChildStd_IN_Rd); | |
4241 CloseHandle(g_hChildStd_OUT_Wr); | |
4242 | |
4243 if (options & SHELL_WRITE) | |
4244 { | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4245 HANDLE thread = (HANDLE) |
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4246 _beginthreadex(NULL, /* security attributes */ |
2935 | 4247 0, /* default stack size */ |
4248 sub_process_writer, /* function to be executed */ | |
4249 g_hChildStd_IN_Wr, /* parameter */ | |
4250 0, /* creation flag, start immediately */ | |
4251 NULL); /* we don't care about thread id */ | |
4252 CloseHandle(thread); | |
4253 g_hChildStd_IN_Wr = NULL; | |
4254 } | |
4255 | |
4256 /* Keep updating the window while waiting for the shell to finish. */ | |
4257 for (;;) | |
4258 { | |
4259 MSG msg; | |
4260 | |
5553 | 4261 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
2935 | 4262 { |
4263 TranslateMessage(&msg); | |
5553 | 4264 pDispatchMessage(&msg); |
2935 | 4265 } |
4266 | |
4267 /* write pipe information in the window */ | |
4268 if ((options & (SHELL_READ|SHELL_WRITE)) | |
4269 # ifdef FEAT_GUI | |
4270 || gui.in_use | |
4271 # endif | |
4272 ) | |
4273 { | |
4274 len = 0; | |
4275 if (!(options & SHELL_EXPAND) | |
4276 && ((options & | |
4277 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4278 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
4279 # ifdef FEAT_GUI | |
4280 || gui.in_use | |
4281 # endif | |
4282 ) | |
4283 && (ta_len > 0 || noread_cnt > 4)) | |
4284 { | |
4285 if (ta_len == 0) | |
4286 { | |
4287 /* Get extra characters when we don't have any. Reset the | |
4288 * counter and timer. */ | |
4289 noread_cnt = 0; | |
4290 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4291 } | |
4292 if (ta_len > 0 || len > 0) | |
4293 { | |
4294 /* | |
4295 * For pipes: Check for CTRL-C: send interrupt signal to | |
4296 * child. Check for CTRL-D: EOF, close pipe to child. | |
4297 */ | |
4298 if (len == 1 && cmd != NULL) | |
4299 { | |
4300 if (ta_buf[ta_len] == Ctrl_C) | |
4301 { | |
4302 /* Learn what exit code is expected, for | |
4303 * now put 9 as SIGKILL */ | |
4304 TerminateProcess(pi.hProcess, 9); | |
4305 } | |
4306 if (ta_buf[ta_len] == Ctrl_D) | |
4307 { | |
4308 CloseHandle(g_hChildStd_IN_Wr); | |
4309 g_hChildStd_IN_Wr = NULL; | |
4310 } | |
4311 } | |
4312 | |
4313 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
4314 for (i = ta_len; i < ta_len + len; ++i) | |
4315 { | |
4316 if (ta_buf[i] == CSI && len - i > 2) | |
4317 { | |
4318 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
4319 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
4320 { | |
4321 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
4322 (size_t)(len - i - 2)); | |
4323 if (c == K_DEL || c == K_KDEL) | |
4324 ta_buf[i] = DEL; | |
4325 else | |
4326 ta_buf[i] = Ctrl_H; | |
4327 len -= 2; | |
4328 } | |
4329 } | |
4330 else if (ta_buf[i] == '\r') | |
4331 ta_buf[i] = '\n'; | |
4332 # ifdef FEAT_MBYTE | |
4333 if (has_mbyte) | |
4334 i += (*mb_ptr2len_len)(ta_buf + i, | |
4335 ta_len + len - i) - 1; | |
4336 # endif | |
4337 } | |
4338 | |
4339 /* | |
4340 * For pipes: echo the typed characters. For a pty this | |
4341 * does not seem to work. | |
4342 */ | |
4343 for (i = ta_len; i < ta_len + len; ++i) | |
4344 { | |
4345 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4346 msg_putchar(ta_buf[i]); | |
4347 # ifdef FEAT_MBYTE | |
4348 else if (has_mbyte) | |
4349 { | |
4350 int l = (*mb_ptr2len)(ta_buf + i); | |
4351 | |
4352 msg_outtrans_len(ta_buf + i, l); | |
4353 i += l - 1; | |
4354 } | |
4355 # endif | |
4356 else | |
4357 msg_outtrans_len(ta_buf + i, 1); | |
4358 } | |
4359 windgoto(msg_row, msg_col); | |
4360 out_flush(); | |
4361 | |
4362 ta_len += len; | |
4363 | |
4364 /* | |
4365 * Write the characters to the child, unless EOF has been | |
4366 * typed for pipes. Write one character at a time, to | |
4367 * avoid losing too much typeahead. When writing buffer | |
4368 * lines, drop the typed characters (only check for | |
4369 * CTRL-C). | |
4370 */ | |
4371 if (options & SHELL_WRITE) | |
4372 ta_len = 0; | |
4373 else if (g_hChildStd_IN_Wr != NULL) | |
4374 { | |
4375 WriteFile(g_hChildStd_IN_Wr, (char*)ta_buf, | |
4376 1, &len, NULL); | |
4377 // if we are typing in, we want to keep things reactive | |
4378 delay = 1; | |
4379 if (len > 0) | |
4380 { | |
4381 ta_len -= len; | |
4382 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4383 } | |
4384 } | |
4385 } | |
4386 } | |
4387 } | |
4388 | |
4389 if (ta_len) | |
4390 ui_inchar_undo(ta_buf, ta_len); | |
4391 | |
4392 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4393 { | |
3030 | 4394 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4395 break; |
4396 } | |
4397 | |
4398 ++noread_cnt; | |
3030 | 4399 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4400 |
4401 /* We start waiting for a very short time and then increase it, so | |
4402 * that we respond quickly when the process is quick, and don't | |
4403 * consume too much overhead when it's slow. */ | |
4404 if (delay < 50) | |
4405 delay += 10; | |
4406 } | |
4407 | |
4408 /* Close the pipe */ | |
4409 CloseHandle(g_hChildStd_OUT_Rd); | |
4410 if (g_hChildStd_IN_Wr != NULL) | |
4411 CloseHandle(g_hChildStd_IN_Wr); | |
4412 | |
4413 WaitForSingleObject(pi.hProcess, INFINITE); | |
4414 | |
4415 /* Get the command exit code */ | |
4416 GetExitCodeProcess(pi.hProcess, &ret); | |
4417 | |
4418 if (options & SHELL_READ) | |
4419 { | |
4420 if (ga.ga_len > 0) | |
4421 { | |
4422 append_ga_line(&ga); | |
4423 /* remember that the NL was missing */ | |
4424 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; | |
4425 } | |
4426 else | |
4427 curbuf->b_no_eol_lnum = 0; | |
4428 ga_clear(&ga); | |
4429 } | |
4430 | |
4431 /* Close the handles to the subprocess, so that it goes away */ | |
4432 CloseHandle(pi.hThread); | |
4433 CloseHandle(pi.hProcess); | |
4434 | |
4435 return ret; | |
4436 } | |
4437 | |
4438 static int | |
4439 mch_system(char *cmd, int options) | |
4440 { | |
4441 /* 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
|
4442 if (!p_stmp) |
2935 | 4443 return mch_system_piped(cmd, options); |
4444 else | |
4445 return mch_system_classic(cmd, options); | |
4446 } | |
7 | 4447 #else |
4448 | |
5547 | 4449 # ifdef FEAT_MBYTE |
4450 static int | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
4451 mch_system(char *cmd, int options) |
5547 | 4452 { |
4453 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
4454 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4455 WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL); |
5547 | 4456 if (wcmd != NULL) |
4457 { | |
4458 int ret = _wsystem(wcmd); | |
4459 vim_free(wcmd); | |
4460 return ret; | |
4461 } | |
4462 } | |
4463 return system(cmd); | |
4464 } | |
4465 # else | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
4466 # define mch_system(c, o) system(c) |
5547 | 4467 # endif |
7 | 4468 |
4469 #endif | |
4470 | |
4471 /* | |
4472 * Either execute a command by calling the shell or start a new shell | |
4473 */ | |
4474 int | |
4475 mch_call_shell( | |
26 | 4476 char_u *cmd, |
4477 int options) /* SHELL_*, see vim.h */ | |
7 | 4478 { |
4479 int x = 0; | |
4480 int tmode = cur_tmode; | |
4481 #ifdef FEAT_TITLE | |
6293 | 4482 char szShellTitle[512]; |
6290 | 4483 # ifdef FEAT_MBYTE |
6293 | 4484 int did_set_title = FALSE; |
4485 | |
6290 | 4486 /* Change the title to reflect that we are in a subshell. */ |
4487 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
4488 { | |
4489 WCHAR szShellTitle[512]; | |
4490 | |
4491 if (GetConsoleTitleW(szShellTitle, | |
4492 sizeof(szShellTitle)/sizeof(WCHAR) - 4) > 0) | |
4493 { | |
4494 if (cmd == NULL) | |
4495 wcscat(szShellTitle, L" :sh"); | |
4496 else | |
4497 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4498 WCHAR *wn = enc_to_utf16((char_u *)cmd, NULL); |
6290 | 4499 |
4500 if (wn != NULL) | |
4501 { | |
4502 wcscat(szShellTitle, L" - !"); | |
4503 if ((wcslen(szShellTitle) + wcslen(wn) < | |
4504 sizeof(szShellTitle)/sizeof(WCHAR))) | |
4505 wcscat(szShellTitle, wn); | |
4506 SetConsoleTitleW(szShellTitle); | |
4507 vim_free(wn); | |
6293 | 4508 did_set_title = TRUE; |
6290 | 4509 } |
4510 } | |
4511 } | |
4512 } | |
6293 | 4513 if (!did_set_title) |
4514 # endif | |
4515 /* Change the title to reflect that we are in a subshell. */ | |
4516 if (GetConsoleTitle(szShellTitle, sizeof(szShellTitle) - 4) > 0) | |
7 | 4517 { |
6293 | 4518 if (cmd == NULL) |
4519 strcat(szShellTitle, " :sh"); | |
4520 else | |
4521 { | |
4522 strcat(szShellTitle, " - !"); | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4523 if ((strlen(szShellTitle) + strlen((char *)cmd) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4524 < sizeof(szShellTitle))) |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4525 strcat(szShellTitle, (char *)cmd); |
6293 | 4526 } |
4527 SetConsoleTitle(szShellTitle); | |
7 | 4528 } |
4529 #endif | |
4530 | |
4531 out_flush(); | |
4532 | |
4533 #ifdef MCH_WRITE_DUMP | |
4534 if (fdDump) | |
4535 { | |
4536 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options); | |
4537 fflush(fdDump); | |
4538 } | |
4539 #endif | |
4540 | |
4541 /* | |
4542 * Catch all deadly signals while running the external command, because a | |
4543 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us. | |
4544 */ | |
4545 signal(SIGINT, SIG_IGN); | |
4546 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4547 signal(SIGKILL, SIG_IGN); | |
4548 #else | |
4549 signal(SIGBREAK, SIG_IGN); | |
4550 #endif | |
4551 signal(SIGILL, SIG_IGN); | |
4552 signal(SIGFPE, SIG_IGN); | |
4553 signal(SIGSEGV, SIG_IGN); | |
4554 signal(SIGTERM, SIG_IGN); | |
4555 signal(SIGABRT, SIG_IGN); | |
4556 | |
4557 if (options & SHELL_COOKED) | |
4558 settmode(TMODE_COOK); /* set to normal mode */ | |
4559 | |
4560 if (cmd == NULL) | |
4561 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4562 x = mch_system((char *)p_sh, options); |
7 | 4563 } |
4564 else | |
4565 { | |
4566 /* we use "command" or "cmd" to start the shell; slow but easy */ | |
3363 | 4567 char_u *newcmd = NULL; |
4568 char_u *cmdbase = cmd; | |
4569 long_u cmdlen; | |
3361 | 4570 |
4571 /* Skip a leading ", ( and "(. */ | |
4572 if (*cmdbase == '"' ) | |
4573 ++cmdbase; | |
4574 if (*cmdbase == '(') | |
4575 ++cmdbase; | |
4576 | |
4577 if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5])) | |
4578 { | |
4579 STARTUPINFO si; | |
4580 PROCESS_INFORMATION pi; | |
4581 DWORD flags = CREATE_NEW_CONSOLE; | |
4582 char_u *p; | |
4583 | |
5627 | 4584 ZeroMemory(&si, sizeof(si)); |
3361 | 4585 si.cb = sizeof(si); |
4586 si.lpReserved = NULL; | |
4587 si.lpDesktop = NULL; | |
4588 si.lpTitle = NULL; | |
4589 si.dwFlags = 0; | |
4590 si.cbReserved2 = 0; | |
4591 si.lpReserved2 = NULL; | |
4592 | |
4593 cmdbase = skipwhite(cmdbase + 5); | |
4594 if ((STRNICMP(cmdbase, "/min", 4) == 0) | |
4595 && vim_iswhite(cmdbase[4])) | |
4596 { | |
4597 cmdbase = skipwhite(cmdbase + 4); | |
4598 si.dwFlags = STARTF_USESHOWWINDOW; | |
4599 si.wShowWindow = SW_SHOWMINNOACTIVE; | |
4600 } | |
4601 else if ((STRNICMP(cmdbase, "/b", 2) == 0) | |
4602 && vim_iswhite(cmdbase[2])) | |
4603 { | |
4604 cmdbase = skipwhite(cmdbase + 2); | |
4605 flags = CREATE_NO_WINDOW; | |
4606 si.dwFlags = STARTF_USESTDHANDLES; | |
4607 si.hStdInput = CreateFile("\\\\.\\NUL", // File name | |
3363 | 4608 GENERIC_READ, // Access flags |
3361 | 4609 0, // Share flags |
3363 | 4610 NULL, // Security att. |
4611 OPEN_EXISTING, // Open flags | |
4612 FILE_ATTRIBUTE_NORMAL, // File att. | |
4613 NULL); // Temp file | |
3361 | 4614 si.hStdOutput = si.hStdInput; |
4615 si.hStdError = si.hStdInput; | |
4616 } | |
4617 | |
4618 /* Remove a trailing ", ) and )" if they have a match | |
4619 * at the start of the command. */ | |
4620 if (cmdbase > cmd) | |
4621 { | |
4622 p = cmdbase + STRLEN(cmdbase); | |
4623 if (p > cmdbase && p[-1] == '"' && *cmd == '"') | |
4624 *--p = NUL; | |
4625 if (p > cmdbase && p[-1] == ')' | |
4626 && (*cmd =='(' || cmd[1] == '(')) | |
4627 *--p = NUL; | |
4628 } | |
4629 | |
3363 | 4630 newcmd = cmdbase; |
4631 unescape_shellxquote(cmdbase, p_sxe); | |
4632 | |
3361 | 4633 /* |
3363 | 4634 * If creating new console, arguments are passed to the |
4635 * 'cmd.exe' as-is. If it's not, arguments are not treated | |
4636 * correctly for current 'cmd.exe'. So unescape characters in | |
4637 * shellxescape except '|' for avoiding to be treated as | |
4638 * argument to them. Pass the arguments to sub-shell. | |
3361 | 4639 */ |
3363 | 4640 if (flags != CREATE_NEW_CONSOLE) |
4641 { | |
4642 char_u *subcmd; | |
3367 | 4643 char_u *cmd_shell = mch_getenv("COMSPEC"); |
4644 | |
4645 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
|
4646 cmd_shell = (char_u *)default_shell(); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4647 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4648 subcmd = vim_strsave_escaped_ext(cmdbase, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4649 (char_u *)"|", '^', FALSE); |
3363 | 4650 if (subcmd != NULL) |
4651 { | |
4652 /* make "cmd.exe /c arguments" */ | |
4653 cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5; | |
4654 newcmd = lalloc(cmdlen, TRUE); | |
4655 if (newcmd != NULL) | |
4656 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s", | |
3367 | 4657 cmd_shell, subcmd); |
3363 | 4658 else |
4659 newcmd = cmdbase; | |
3367 | 4660 vim_free(subcmd); |
3363 | 4661 } |
4662 } | |
3361 | 4663 |
4664 /* | |
4665 * Now, start the command as a process, so that it doesn't | |
4666 * inherit our handles which causes unpleasant dangling swap | |
4667 * files if we exit before the spawned process | |
4668 */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4669 if (vim_create_process((char *)newcmd, FALSE, flags, &si, &pi)) |
3361 | 4670 x = 0; |
4671 else | |
4672 { | |
4673 x = -1; | |
4674 #ifdef FEAT_GUI_W32 | |
4675 EMSG(_("E371: Command not found")); | |
4676 #endif | |
4677 } | |
3363 | 4678 |
4679 if (newcmd != cmdbase) | |
4680 vim_free(newcmd); | |
4681 | |
5627 | 4682 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) |
3361 | 4683 { |
5627 | 4684 /* Close the handle to \\.\NUL created above. */ |
3361 | 4685 CloseHandle(si.hStdInput); |
4686 } | |
4687 /* Close the handles to the subprocess, so that it goes away */ | |
4688 CloseHandle(pi.hThread); | |
4689 CloseHandle(pi.hProcess); | |
4690 } | |
4691 else | |
4692 { | |
3363 | 4693 cmdlen = ( |
7 | 4694 #ifdef FEAT_GUI_W32 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4695 (!p_stmp ? 0 : STRLEN(vimrun_path)) + |
7 | 4696 #endif |
1569 | 4697 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10); |
4698 | |
3361 | 4699 newcmd = lalloc(cmdlen, TRUE); |
4700 if (newcmd != NULL) | |
7 | 4701 { |
4702 #if defined(FEAT_GUI_W32) | |
4703 if (need_vimrun_warning) | |
4704 { | |
10400
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4705 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
|
4706 "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
|
4707 "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
|
4708 char *title = _("Vim Warning"); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4709 # ifdef FEAT_MBYTE |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4710 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
|
4711 { |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4712 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
|
4713 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
|
4714 |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4715 if (wmsg != NULL && wtitle != NULL) |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4716 MessageBoxW(NULL, wmsg, wtitle, MB_ICONWARNING); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4717 vim_free(wmsg); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4718 vim_free(wtitle); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4719 } |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4720 else |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4721 # endif |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4722 MessageBox(NULL, msg, title, MB_ICONWARNING); |
7 | 4723 need_vimrun_warning = FALSE; |
4724 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4725 if (!s_dont_use_vimrun && p_stmp) |
7 | 4726 /* Use vimrun to execute the command. It opens a console |
4727 * 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
|
4728 vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s", |
7 | 4729 vimrun_path, |
4730 (msg_silent != 0 || (options & SHELL_DOOUT)) | |
4731 ? "-s " : "", | |
4732 p_sh, p_shcf, cmd); | |
4733 else | |
4734 #endif | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4735 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", |
1569 | 4736 p_sh, p_shcf, cmd); |
7 | 4737 x = mch_system((char *)newcmd, options); |
3361 | 4738 vim_free(newcmd); |
7 | 4739 } |
4740 } | |
4741 } | |
4742 | |
4743 if (tmode == TMODE_RAW) | |
4744 settmode(TMODE_RAW); /* set to raw mode */ | |
4745 | |
4746 /* Print the return value, unless "vimrun" was used. */ | |
4747 if (x != 0 && !(options & SHELL_SILENT) && !emsg_silent | |
4748 #if defined(FEAT_GUI_W32) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4749 && ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) |
7 | 4750 #endif |
4751 ) | |
4752 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4753 smsg((char_u *)_("shell returned %d"), x); |
7 | 4754 msg_putchar('\n'); |
4755 } | |
4756 #ifdef FEAT_TITLE | |
4757 resettitle(); | |
4758 #endif | |
4759 | |
4760 signal(SIGINT, SIG_DFL); | |
4761 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4762 signal(SIGKILL, SIG_DFL); | |
4763 #else | |
4764 signal(SIGBREAK, SIG_DFL); | |
4765 #endif | |
4766 signal(SIGILL, SIG_DFL); | |
4767 signal(SIGFPE, SIG_DFL); | |
4768 signal(SIGSEGV, SIG_DFL); | |
4769 signal(SIGTERM, SIG_DFL); | |
4770 signal(SIGABRT, SIG_DFL); | |
4771 | |
4772 return x; | |
4773 } | |
4774 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4775 #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
|
4776 static HANDLE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4777 job_io_file_open( |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4778 char_u *fname, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4779 DWORD dwDesiredAccess, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4780 DWORD dwShareMode, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4781 LPSECURITY_ATTRIBUTES lpSecurityAttributes, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4782 DWORD dwCreationDisposition, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4783 DWORD dwFlagsAndAttributes) |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4784 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4785 HANDLE h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4786 # ifdef FEAT_MBYTE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4787 WCHAR *wn = NULL; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4788 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
|
4789 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4790 wn = enc_to_utf16(fname, NULL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4791 if (wn != NULL) |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4792 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4793 h = CreateFileW(wn, dwDesiredAccess, dwShareMode, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4794 lpSecurityAttributes, dwCreationDisposition, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4795 dwFlagsAndAttributes, NULL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4796 vim_free(wn); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4797 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4798 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4799 if (wn == NULL) |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4800 # endif |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4801 h = CreateFile((LPCSTR)fname, dwDesiredAccess, dwShareMode, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4802 lpSecurityAttributes, dwCreationDisposition, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4803 dwFlagsAndAttributes, NULL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4804 return h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4805 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4806 |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4807 void |
8084
3ea56a74077f
commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents:
8082
diff
changeset
|
4808 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
|
4809 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4810 STARTUPINFO si; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4811 PROCESS_INFORMATION pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4812 HANDLE jo; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4813 SECURITY_ATTRIBUTES saAttr; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4814 channel_T *channel = NULL; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4815 HANDLE ifd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4816 HANDLE ofd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4817 HANDLE efd[2]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4818 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4819 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
|
4820 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
|
4821 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
|
4822 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
|
4823 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
|
4824 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
|
4825 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
|
4826 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4827 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
|
4828 use_null_for_err = TRUE; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4829 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4830 ifd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4831 ifd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4832 ofd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4833 ofd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4834 efd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4835 efd[1] = INVALID_HANDLE_VALUE; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
4836 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4837 jo = CreateJobObject(NULL, NULL); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4838 if (jo == NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4839 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4840 job->jv_status = JOB_FAILED; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4841 goto failed; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4842 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4843 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
4844 ZeroMemory(&pi, sizeof(pi)); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4845 ZeroMemory(&si, sizeof(si)); |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4846 si.cb = sizeof(si); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4847 si.dwFlags |= STARTF_USESHOWWINDOW; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
4848 si.wShowWindow = SW_HIDE; |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4849 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4850 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4851 saAttr.bInheritHandle = TRUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4852 saAttr.lpSecurityDescriptor = NULL; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4853 |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
4854 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
4855 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
4856 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
|
4857 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4858 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
|
4859 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4860 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4861 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
|
4862 { |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
4863 EMSG2(_(e_notopen), fname); |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
4864 goto failed; |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
4865 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4866 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4867 else if (!use_null_for_in && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4868 (!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
|
4869 || !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
|
4870 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
4871 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4872 if (use_file_for_out) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4873 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4874 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
|
4875 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4876 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
|
4877 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4878 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4879 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
|
4880 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4881 EMSG2(_(e_notopen), fname); |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4882 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4883 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4884 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4885 else if (!use_null_for_out && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4886 (!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
|
4887 || !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
|
4888 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
4889 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4890 if (use_file_for_err) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4891 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4892 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
|
4893 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4894 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
|
4895 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4896 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4897 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
|
4898 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4899 EMSG2(_(e_notopen), fname); |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4900 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4901 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4902 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4903 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
|
4904 (!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
|
4905 || !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
|
4906 goto failed; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
4907 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4908 si.dwFlags |= STARTF_USESTDHANDLES; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4909 si.hStdInput = ifd[0]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4910 si.hStdOutput = ofd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4911 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
|
4912 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4913 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
|
4914 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
4915 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
4916 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
4917 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
4918 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
4919 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
4920 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
4921 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
4922 channel = add_channel(); |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4923 if (channel == NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4924 goto failed; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4925 } |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4926 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4927 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
|
4928 CREATE_SUSPENDED | |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4929 CREATE_DEFAULT_ERROR_MODE | |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4930 CREATE_NEW_PROCESS_GROUP | |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
4931 CREATE_NEW_CONSOLE, |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4932 &si, &pi)) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
4933 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4934 CloseHandle(jo); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4935 job->jv_status = JOB_FAILED; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4936 goto failed; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4937 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4938 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4939 if (!AssignProcessToJobObject(jo, pi.hProcess)) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4940 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4941 /* 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
|
4942 * process with TerminateProcess. */ |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4943 CloseHandle(jo); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4944 jo = NULL; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4945 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4946 ResumeThread(pi.hThread); |
8479
9f63e4506c40
commit https://github.com/vim/vim/commit/75578a388d2aff59dc330ceccd8894c79b4bc735
Christian Brabandt <cb@256bit.org>
parents:
8471
diff
changeset
|
4947 CloseHandle(pi.hThread); |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4948 job->jv_proc_info = pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
4949 job->jv_job_object = jo; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4950 job->jv_status = JOB_STARTED; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4951 |
10060
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4952 CloseHandle(ifd[0]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4953 CloseHandle(ofd[1]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4954 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
|
4955 CloseHandle(efd[1]); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4956 |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4957 job->jv_channel = channel; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4958 if (channel != NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4959 { |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4960 channel_set_pipes(channel, |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4961 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
|
4962 ? INVALID_FD : (sock_T)ifd[1], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4963 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
|
4964 ? INVALID_FD : (sock_T)ofd[0], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4965 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
|
4966 ? INVALID_FD : (sock_T)efd[0]); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4967 channel_set_job(channel, job, options); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
4968 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4969 return; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4970 |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
4971 failed: |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4972 CloseHandle(ifd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4973 CloseHandle(ofd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4974 CloseHandle(efd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4975 CloseHandle(ifd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4976 CloseHandle(ofd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
4977 CloseHandle(efd[1]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
4978 channel_unref(channel); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4979 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4980 |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4981 char * |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4982 mch_job_status(job_T *job) |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4983 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4984 DWORD dwExitCode = 0; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4985 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
4986 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
|
4987 || dwExitCode != STILL_ACTIVE) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
4988 { |
8176
477c1d855698
commit https://github.com/vim/vim/commit/eab089d22f172ddd2d33367a998e68c2f1c6c989
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
4989 job->jv_exitval = (int)dwExitCode; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10317
diff
changeset
|
4990 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
|
4991 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
4992 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
|
4993 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
4994 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4995 return "dead"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4996 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4997 return "run"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4998 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
4999 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5000 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5001 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
|
5002 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5003 HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5004 job_T *jobArray[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5005 job_T *job = job_list; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5006 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5007 while (job != NULL) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5008 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5009 DWORD n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5010 DWORD result; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5011 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5012 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
|
5013 && job != NULL; job = job->jv_next) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5014 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5015 if (job->jv_status == JOB_STARTED) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5016 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5017 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
|
5018 jobArray[n] = job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5019 ++n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5020 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5021 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5022 if (n == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5023 continue; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5024 result = WaitForMultipleObjects(n, jobHandles, FALSE, 0); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5025 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
|
5026 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5027 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
|
5028 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5029 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
|
5030 return wait_job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5031 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5032 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5033 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5034 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5035 |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5036 static BOOL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5037 terminate_all(HANDLE process, int code) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5038 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5039 PROCESSENTRY32 pe; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5040 HANDLE h = INVALID_HANDLE_VALUE; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5041 DWORD pid = GetProcessId(process); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5042 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5043 if (pid != 0) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5044 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5045 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5046 if (h != INVALID_HANDLE_VALUE) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5047 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5048 pe.dwSize = sizeof(PROCESSENTRY32); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5049 if (!Process32First(h, &pe)) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5050 goto theend; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5051 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5052 do |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5053 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5054 if (pe.th32ParentProcessID == pid) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5055 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5056 HANDLE ph = OpenProcess( |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5057 PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5058 if (ph != NULL) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5059 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5060 terminate_all(ph, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5061 CloseHandle(ph); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5062 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5063 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5064 } while (Process32Next(h, &pe)); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5065 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5066 CloseHandle(h); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5067 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5068 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5069 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5070 theend: |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5071 return TerminateProcess(process, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5072 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5073 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5074 /* |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5075 * Send a (deadly) signal to "job". |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5076 * 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
|
5077 */ |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5078 int |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5079 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
|
5080 { |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5081 int ret; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5082 |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5083 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
|
5084 { |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5085 /* deadly signal */ |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5086 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5087 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
|
5088 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
|
5089 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5090 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5091 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
|
5092 return FAIL; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5093 ret = GenerateConsoleCtrlEvent( |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5094 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
|
5095 job->jv_proc_info.dwProcessId) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5096 ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5097 FreeConsole(); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5098 return ret; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5099 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5100 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5101 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5102 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5103 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5104 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5105 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5106 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5107 if (job->jv_status != JOB_FAILED) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5108 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5109 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5110 CloseHandle(job->jv_job_object); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5111 CloseHandle(job->jv_proc_info.hProcess); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5112 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5113 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5114 #endif |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5115 |
7 | 5116 |
5117 #ifndef FEAT_GUI_W32 | |
5118 | |
5119 /* | |
5120 * Start termcap mode | |
5121 */ | |
5122 static void | |
5123 termcap_mode_start(void) | |
5124 { | |
5125 DWORD cmodein; | |
5126 | |
5127 if (g_fTermcapMode) | |
5128 return; | |
5129 | |
5130 SaveConsoleBuffer(&g_cbNonTermcap); | |
5131 | |
5132 if (g_cbTermcap.IsValid) | |
5133 { | |
5134 /* | |
5135 * We've been in termcap mode before. Restore certain screen | |
5136 * characteristics, including the buffer size and the window | |
5137 * size. Since we will be redrawing the screen, we don't need | |
5138 * to restore the actual contents of the buffer. | |
5139 */ | |
5140 RestoreConsoleBuffer(&g_cbTermcap, FALSE); | |
5141 SetConsoleWindowInfo(g_hConOut, TRUE, &g_cbTermcap.Info.srWindow); | |
5142 Rows = g_cbTermcap.Info.dwSize.Y; | |
5143 Columns = g_cbTermcap.Info.dwSize.X; | |
5144 } | |
5145 else | |
5146 { | |
5147 /* | |
5148 * This is our first time entering termcap mode. Clear the console | |
5149 * screen buffer, and resize the buffer to match the current window | |
5150 * size. We will use this as the size of our editing environment. | |
5151 */ | |
5152 ClearConsoleBuffer(g_attrCurrent); | |
5153 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
5154 } | |
5155 | |
5156 #ifdef FEAT_TITLE | |
5157 resettitle(); | |
5158 #endif | |
5159 | |
5160 GetConsoleMode(g_hConIn, &cmodein); | |
5161 #ifdef FEAT_MOUSE | |
5162 if (g_fMouseActive) | |
5163 cmodein |= ENABLE_MOUSE_INPUT; | |
5164 else | |
5165 cmodein &= ~ENABLE_MOUSE_INPUT; | |
5166 #endif | |
5167 cmodein |= ENABLE_WINDOW_INPUT; | |
5168 SetConsoleMode(g_hConIn, cmodein); | |
5169 | |
5170 redraw_later_clear(); | |
5171 g_fTermcapMode = TRUE; | |
5172 } | |
5173 | |
5174 | |
5175 /* | |
5176 * End termcap mode | |
5177 */ | |
5178 static void | |
5179 termcap_mode_end(void) | |
5180 { | |
5181 DWORD cmodein; | |
5182 ConsoleBuffer *cb; | |
5183 COORD coord; | |
5184 DWORD dwDummy; | |
5185 | |
5186 if (!g_fTermcapMode) | |
5187 return; | |
5188 | |
5189 SaveConsoleBuffer(&g_cbTermcap); | |
5190 | |
5191 GetConsoleMode(g_hConIn, &cmodein); | |
5192 cmodein &= ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT); | |
5193 SetConsoleMode(g_hConIn, cmodein); | |
5194 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5195 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5196 cb = exiting ? &g_cbOrig : &g_cbNonTermcap; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5197 #else |
7 | 5198 cb = &g_cbNonTermcap; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5199 #endif |
7 | 5200 RestoreConsoleBuffer(cb, p_rs); |
5201 SetConsoleCursorInfo(g_hConOut, &g_cci); | |
5202 | |
5203 if (p_rs || exiting) | |
5204 { | |
5205 /* | |
5206 * Clear anything that happens to be on the current line. | |
5207 */ | |
5208 coord.X = 0; | |
5209 coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); | |
5210 FillConsoleOutputCharacter(g_hConOut, ' ', | |
5211 cb->Info.dwSize.X, coord, &dwDummy); | |
5212 /* | |
5213 * The following is just for aesthetics. If we are exiting without | |
5214 * restoring the screen, then we want to have a prompt string | |
5215 * appear at the bottom line. However, the command interpreter | |
5216 * seems to always advance the cursor one line before displaying | |
5217 * the prompt string, which causes the screen to scroll. To | |
5218 * counter this, move the cursor up one line before exiting. | |
5219 */ | |
5220 if (exiting && !p_rs) | |
5221 coord.Y--; | |
5222 /* | |
5223 * Position the cursor at the leftmost column of the desired row. | |
5224 */ | |
5225 SetConsoleCursorPosition(g_hConOut, coord); | |
5226 } | |
5227 | |
5228 g_fTermcapMode = FALSE; | |
5229 } | |
5230 #endif /* FEAT_GUI_W32 */ | |
5231 | |
5232 | |
5233 #ifdef FEAT_GUI_W32 | |
323 | 5234 /*ARGSUSED*/ |
7 | 5235 void |
5236 mch_write( | |
5237 char_u *s, | |
5238 int len) | |
5239 { | |
5240 /* never used */ | |
5241 } | |
5242 | |
5243 #else | |
5244 | |
5245 /* | |
5246 * clear `n' chars, starting from `coord' | |
5247 */ | |
5248 static void | |
5249 clear_chars( | |
5250 COORD coord, | |
5251 DWORD n) | |
5252 { | |
5253 DWORD dwDummy; | |
5254 | |
5255 FillConsoleOutputCharacter(g_hConOut, ' ', n, coord, &dwDummy); | |
5256 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, n, coord, &dwDummy); | |
5257 } | |
5258 | |
5259 | |
5260 /* | |
5261 * Clear the screen | |
5262 */ | |
5263 static void | |
5264 clear_screen(void) | |
5265 { | |
5266 g_coord.X = g_coord.Y = 0; | |
5267 clear_chars(g_coord, Rows * Columns); | |
5268 } | |
5269 | |
5270 | |
5271 /* | |
5272 * Clear to end of display | |
5273 */ | |
5274 static void | |
5275 clear_to_end_of_display(void) | |
5276 { | |
5277 clear_chars(g_coord, (Rows - g_coord.Y - 1) | |
5278 * Columns + (Columns - g_coord.X)); | |
5279 } | |
5280 | |
5281 | |
5282 /* | |
5283 * Clear to end of line | |
5284 */ | |
5285 static void | |
5286 clear_to_end_of_line(void) | |
5287 { | |
5288 clear_chars(g_coord, Columns - g_coord.X); | |
5289 } | |
5290 | |
5291 | |
5292 /* | |
5293 * Scroll the scroll region up by `cLines' lines | |
5294 */ | |
5295 static void | |
26 | 5296 scroll(unsigned cLines) |
7 | 5297 { |
5298 COORD oldcoord = g_coord; | |
5299 | |
5300 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); | |
5301 delete_lines(cLines); | |
5302 | |
5303 g_coord = oldcoord; | |
5304 } | |
5305 | |
5306 | |
5307 /* | |
5308 * Set the scroll region | |
5309 */ | |
5310 static void | |
5311 set_scroll_region( | |
5312 unsigned left, | |
5313 unsigned top, | |
5314 unsigned right, | |
5315 unsigned bottom) | |
5316 { | |
5317 if (left >= right | |
5318 || top >= bottom | |
5319 || right > (unsigned) Columns - 1 | |
5320 || bottom > (unsigned) Rows - 1) | |
5321 return; | |
5322 | |
5323 g_srScrollRegion.Left = left; | |
5324 g_srScrollRegion.Top = top; | |
5325 g_srScrollRegion.Right = right; | |
5326 g_srScrollRegion.Bottom = bottom; | |
5327 } | |
5328 | |
5329 | |
5330 /* | |
5331 * Insert `cLines' lines at the current cursor position | |
5332 */ | |
5333 static void | |
26 | 5334 insert_lines(unsigned cLines) |
7 | 5335 { |
5336 SMALL_RECT source; | |
5337 COORD dest; | |
5338 CHAR_INFO fill; | |
5339 | |
5340 dest.X = 0; | |
5341 dest.Y = g_coord.Y + cLines; | |
5342 | |
5343 source.Left = 0; | |
5344 source.Top = g_coord.Y; | |
5345 source.Right = g_srScrollRegion.Right; | |
5346 source.Bottom = g_srScrollRegion.Bottom - cLines; | |
5347 | |
5348 fill.Char.AsciiChar = ' '; | |
5349 fill.Attributes = g_attrCurrent; | |
5350 | |
5351 ScrollConsoleScreenBuffer(g_hConOut, &source, NULL, dest, &fill); | |
5352 | |
5353 /* Here we have to deal with a win32 console flake: If the scroll | |
5354 * region looks like abc and we scroll c to a and fill with d we get | |
5355 * cbd... if we scroll block c one line at a time to a, we get cdd... | |
5356 * vim expects cdd consistently... So we have to deal with that | |
5357 * here... (this also occurs scrolling the same way in the other | |
5358 * direction). */ | |
5359 | |
5360 if (source.Bottom < dest.Y) | |
5361 { | |
5362 COORD coord; | |
5363 | |
5364 coord.X = 0; | |
5365 coord.Y = source.Bottom; | |
5366 clear_chars(coord, Columns * (dest.Y - source.Bottom)); | |
5367 } | |
5368 } | |
5369 | |
5370 | |
5371 /* | |
5372 * Delete `cLines' lines at the current cursor position | |
5373 */ | |
5374 static void | |
26 | 5375 delete_lines(unsigned cLines) |
7 | 5376 { |
5377 SMALL_RECT source; | |
5378 COORD dest; | |
5379 CHAR_INFO fill; | |
5380 int nb; | |
5381 | |
5382 dest.X = 0; | |
5383 dest.Y = g_coord.Y; | |
5384 | |
5385 source.Left = 0; | |
5386 source.Top = g_coord.Y + cLines; | |
5387 source.Right = g_srScrollRegion.Right; | |
5388 source.Bottom = g_srScrollRegion.Bottom; | |
5389 | |
5390 fill.Char.AsciiChar = ' '; | |
5391 fill.Attributes = g_attrCurrent; | |
5392 | |
5393 ScrollConsoleScreenBuffer(g_hConOut, &source, NULL, dest, &fill); | |
5394 | |
5395 /* Here we have to deal with a win32 console flake: If the scroll | |
5396 * region looks like abc and we scroll c to a and fill with d we get | |
5397 * cbd... if we scroll block c one line at a time to a, we get cdd... | |
5398 * vim expects cdd consistently... So we have to deal with that | |
5399 * here... (this also occurs scrolling the same way in the other | |
5400 * direction). */ | |
5401 | |
5402 nb = dest.Y + (source.Bottom - source.Top) + 1; | |
5403 | |
5404 if (nb < source.Top) | |
5405 { | |
5406 COORD coord; | |
5407 | |
5408 coord.X = 0; | |
5409 coord.Y = nb; | |
5410 clear_chars(coord, Columns * (source.Top - nb)); | |
5411 } | |
5412 } | |
5413 | |
5414 | |
5415 /* | |
5416 * Set the cursor position | |
5417 */ | |
5418 static void | |
5419 gotoxy( | |
5420 unsigned x, | |
5421 unsigned y) | |
5422 { | |
5423 if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) | |
5424 return; | |
5425 | |
5426 /* external cursor coords are 1-based; internal are 0-based */ | |
5427 g_coord.X = x - 1; | |
5428 g_coord.Y = y - 1; | |
5429 SetConsoleCursorPosition(g_hConOut, g_coord); | |
5430 } | |
5431 | |
5432 | |
5433 /* | |
5434 * Set the current text attribute = (foreground | background) | |
5435 * See ../doc/os_win32.txt for the numbers. | |
5436 */ | |
5437 static void | |
26 | 5438 textattr(WORD wAttr) |
7 | 5439 { |
6710 | 5440 g_attrCurrent = wAttr & 0xff; |
7 | 5441 |
5442 SetConsoleTextAttribute(g_hConOut, wAttr); | |
5443 } | |
5444 | |
5445 | |
5446 static void | |
26 | 5447 textcolor(WORD wAttr) |
7 | 5448 { |
6710 | 5449 g_attrCurrent = (g_attrCurrent & 0xf0) + (wAttr & 0x0f); |
7 | 5450 |
5451 SetConsoleTextAttribute(g_hConOut, g_attrCurrent); | |
5452 } | |
5453 | |
5454 | |
5455 static void | |
26 | 5456 textbackground(WORD wAttr) |
7 | 5457 { |
6710 | 5458 g_attrCurrent = (g_attrCurrent & 0x0f) + ((wAttr & 0x0f) << 4); |
7 | 5459 |
5460 SetConsoleTextAttribute(g_hConOut, g_attrCurrent); | |
5461 } | |
5462 | |
5463 | |
5464 /* | |
5465 * restore the default text attribute (whatever we started with) | |
5466 */ | |
5467 static void | |
26 | 5468 normvideo(void) |
7 | 5469 { |
5470 textattr(g_attrDefault); | |
5471 } | |
5472 | |
5473 | |
5474 static WORD g_attrPreStandout = 0; | |
5475 | |
5476 /* | |
5477 * Make the text standout, by brightening it | |
5478 */ | |
5479 static void | |
5480 standout(void) | |
5481 { | |
5482 g_attrPreStandout = g_attrCurrent; | |
5483 textattr((WORD) (g_attrCurrent|FOREGROUND_INTENSITY|BACKGROUND_INTENSITY)); | |
5484 } | |
5485 | |
5486 | |
5487 /* | |
5488 * Turn off standout mode | |
5489 */ | |
5490 static void | |
26 | 5491 standend(void) |
7 | 5492 { |
5493 if (g_attrPreStandout) | |
5494 { | |
5495 textattr(g_attrPreStandout); | |
5496 g_attrPreStandout = 0; | |
5497 } | |
5498 } | |
5499 | |
5500 | |
5501 /* | |
1199 | 5502 * Set normal fg/bg color, based on T_ME. Called when t_me has been set. |
7 | 5503 */ |
5504 void | |
26 | 5505 mch_set_normal_colors(void) |
7 | 5506 { |
5507 char_u *p; | |
5508 int n; | |
5509 | |
5510 cterm_normal_fg_color = (g_attrDefault & 0xf) + 1; | |
5511 cterm_normal_bg_color = ((g_attrDefault >> 4) & 0xf) + 1; | |
5512 if (T_ME[0] == ESC && T_ME[1] == '|') | |
5513 { | |
5514 p = T_ME + 2; | |
5515 n = getdigits(&p); | |
5516 if (*p == 'm' && n > 0) | |
5517 { | |
5518 cterm_normal_fg_color = (n & 0xf) + 1; | |
5519 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1; | |
5520 } | |
5521 } | |
5522 } | |
5523 | |
5524 | |
5525 /* | |
5526 * visual bell: flash the screen | |
5527 */ | |
5528 static void | |
26 | 5529 visual_bell(void) |
7 | 5530 { |
5531 COORD coordOrigin = {0, 0}; | |
5532 WORD attrFlash = ~g_attrCurrent & 0xff; | |
5533 | |
5534 DWORD dwDummy; | |
5535 LPWORD oldattrs = (LPWORD)alloc(Rows * Columns * sizeof(WORD)); | |
5536 | |
5537 if (oldattrs == NULL) | |
5538 return; | |
5539 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
5540 coordOrigin, &dwDummy); | |
5541 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, | |
5542 coordOrigin, &dwDummy); | |
5543 | |
5544 Sleep(15); /* wait for 15 msec */ | |
5545 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
5546 coordOrigin, &dwDummy); | |
5547 vim_free(oldattrs); | |
5548 } | |
5549 | |
5550 | |
5551 /* | |
5552 * Make the cursor visible or invisible | |
5553 */ | |
5554 static void | |
26 | 5555 cursor_visible(BOOL fVisible) |
7 | 5556 { |
5557 s_cursor_visible = fVisible; | |
5558 #ifdef MCH_CURSOR_SHAPE | |
5559 mch_update_cursor(); | |
5560 #endif | |
5561 } | |
5562 | |
5563 | |
5564 /* | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5565 * 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
|
5566 * Returns the number of bytes actually written (at least one). |
7 | 5567 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5568 static DWORD |
7 | 5569 write_chars( |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5570 char_u *pchBuf, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5571 DWORD cbToWrite) |
7 | 5572 { |
5573 COORD coord = g_coord; | |
5574 DWORD written; | |
5575 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5576 #ifdef FEAT_MBYTE |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5577 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
|
5578 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5579 static WCHAR *unicodebuf = NULL; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5580 static int unibuflen = 0; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5581 int length; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5582 DWORD n, cchwritten, cells; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5583 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5584 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
|
5585 if (unicodebuf == NULL || length > unibuflen) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5586 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5587 vim_free(unicodebuf); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5588 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
|
5589 unibuflen = length; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5590 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5591 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
|
5592 unicodebuf, unibuflen); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5593 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5594 cells = mb_string2cells(pchBuf, cbToWrite); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5595 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cells, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5596 coord, &written); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5597 /* 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
|
5598 * 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
|
5599 if (WriteConsoleOutputCharacterW(g_hConOut, unicodebuf, length, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5600 coord, &cchwritten) == 0 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5601 || cchwritten == 0) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5602 cchwritten = 1; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5603 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5604 if (cchwritten == length) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5605 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5606 written = cbToWrite; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5607 g_coord.X += (SHORT)cells; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5608 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5609 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5610 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5611 char_u *p = pchBuf; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5612 for (n = 0; n < cchwritten; n++) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5613 mb_cptr_adv(p); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5614 written = p - pchBuf; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5615 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
|
5616 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5617 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5618 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5619 #endif |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5620 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5621 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cbToWrite, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5622 coord, &written); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5623 /* 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
|
5624 * 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
|
5625 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
|
5626 coord, &written) == 0 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5627 || written == 0) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5628 written = 1; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5629 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5630 g_coord.X += (SHORT) written; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5631 } |
7 | 5632 |
5633 while (g_coord.X > g_srScrollRegion.Right) | |
5634 { | |
5635 g_coord.X -= (SHORT) Columns; | |
5636 if (g_coord.Y < g_srScrollRegion.Bottom) | |
5637 g_coord.Y++; | |
5638 } | |
5639 | |
5640 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
5641 | |
5642 return written; | |
5643 } | |
5644 | |
5645 | |
5646 /* | |
5647 * mch_write(): write the output buffer to the screen, translating ESC | |
5648 * sequences into calls to console output routines. | |
5649 */ | |
5650 void | |
5651 mch_write( | |
5652 char_u *s, | |
5653 int len) | |
5654 { | |
5655 s[len] = NUL; | |
5656 | |
5657 if (!term_console) | |
5658 { | |
5659 write(1, s, (unsigned)len); | |
5660 return; | |
5661 } | |
5662 | |
5663 /* translate ESC | sequences into faked bios calls */ | |
5664 while (len--) | |
5665 { | |
5666 /* optimization: use one single write_chars for runs of text, | |
5667 * 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
|
5668 DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033"); |
7 | 5669 |
5670 if (p_wd) | |
5671 { | |
5672 WaitForChar(p_wd); | |
5673 if (prefix != 0) | |
5674 prefix = 1; | |
5675 } | |
5676 | |
5677 if (prefix != 0) | |
5678 { | |
5679 DWORD nWritten; | |
5680 | |
5681 nWritten = write_chars(s, prefix); | |
5682 #ifdef MCH_WRITE_DUMP | |
5683 if (fdDump) | |
5684 { | |
5685 fputc('>', fdDump); | |
5686 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
5687 fputs("<\n", fdDump); | |
5688 } | |
5689 #endif | |
5690 len -= (nWritten - 1); | |
5691 s += nWritten; | |
5692 } | |
5693 else if (s[0] == '\n') | |
5694 { | |
5695 /* \n, newline: go to the beginning of the next line or scroll */ | |
5696 if (g_coord.Y == g_srScrollRegion.Bottom) | |
5697 { | |
5698 scroll(1); | |
5699 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1); | |
5700 } | |
5701 else | |
5702 { | |
5703 gotoxy(g_srScrollRegion.Left + 1, g_coord.Y + 2); | |
5704 } | |
5705 #ifdef MCH_WRITE_DUMP | |
5706 if (fdDump) | |
5707 fputs("\\n\n", fdDump); | |
5708 #endif | |
5709 s++; | |
5710 } | |
5711 else if (s[0] == '\r') | |
5712 { | |
5713 /* \r, carriage return: go to beginning of line */ | |
5714 gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1); | |
5715 #ifdef MCH_WRITE_DUMP | |
5716 if (fdDump) | |
5717 fputs("\\r\n", fdDump); | |
5718 #endif | |
5719 s++; | |
5720 } | |
5721 else if (s[0] == '\b') | |
5722 { | |
5723 /* \b, backspace: move cursor one position left */ | |
5724 if (g_coord.X > g_srScrollRegion.Left) | |
5725 g_coord.X--; | |
5726 else if (g_coord.Y > g_srScrollRegion.Top) | |
5727 { | |
5728 g_coord.X = g_srScrollRegion.Right; | |
5729 g_coord.Y--; | |
5730 } | |
5731 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
5732 #ifdef MCH_WRITE_DUMP | |
5733 if (fdDump) | |
5734 fputs("\\b\n", fdDump); | |
5735 #endif | |
5736 s++; | |
5737 } | |
5738 else if (s[0] == '\a') | |
5739 { | |
5740 /* \a, bell */ | |
5741 MessageBeep(0xFFFFFFFF); | |
5742 #ifdef MCH_WRITE_DUMP | |
5743 if (fdDump) | |
5744 fputs("\\a\n", fdDump); | |
5745 #endif | |
5746 s++; | |
5747 } | |
5748 else if (s[0] == ESC && len >= 3-1 && s[1] == '|') | |
5749 { | |
5750 #ifdef MCH_WRITE_DUMP | |
24 | 5751 char_u *old_s = s; |
7 | 5752 #endif |
24 | 5753 char_u *p; |
5754 int arg1 = 0, arg2 = 0; | |
7 | 5755 |
5756 switch (s[2]) | |
5757 { | |
5758 /* one or two numeric arguments, separated by ';' */ | |
5759 | |
5760 case '0': case '1': case '2': case '3': case '4': | |
5761 case '5': case '6': case '7': case '8': case '9': | |
5762 p = s + 2; | |
5763 arg1 = getdigits(&p); /* no check for length! */ | |
5764 if (p > s + len) | |
5765 break; | |
5766 | |
5767 if (*p == ';') | |
5768 { | |
5769 ++p; | |
5770 arg2 = getdigits(&p); /* no check for length! */ | |
5771 if (p > s + len) | |
5772 break; | |
5773 | |
5774 if (*p == 'H') | |
5775 gotoxy(arg2, arg1); | |
5776 else if (*p == 'r') | |
5777 set_scroll_region(0, arg1 - 1, Columns - 1, arg2 - 1); | |
5778 } | |
5779 else if (*p == 'A') | |
5780 { | |
5781 /* move cursor up arg1 lines in same column */ | |
5782 gotoxy(g_coord.X + 1, | |
5783 max(g_srScrollRegion.Top, g_coord.Y - arg1) + 1); | |
5784 } | |
5785 else if (*p == 'C') | |
5786 { | |
5787 /* move cursor right arg1 columns in same line */ | |
5788 gotoxy(min(g_srScrollRegion.Right, g_coord.X + arg1) + 1, | |
5789 g_coord.Y + 1); | |
5790 } | |
5791 else if (*p == 'H') | |
5792 { | |
5793 gotoxy(1, arg1); | |
5794 } | |
5795 else if (*p == 'L') | |
5796 { | |
5797 insert_lines(arg1); | |
5798 } | |
5799 else if (*p == 'm') | |
5800 { | |
5801 if (arg1 == 0) | |
5802 normvideo(); | |
5803 else | |
5804 textattr((WORD) arg1); | |
5805 } | |
5806 else if (*p == 'f') | |
5807 { | |
5808 textcolor((WORD) arg1); | |
5809 } | |
5810 else if (*p == 'b') | |
5811 { | |
5812 textbackground((WORD) arg1); | |
5813 } | |
5814 else if (*p == 'M') | |
5815 { | |
5816 delete_lines(arg1); | |
5817 } | |
5818 | |
835 | 5819 len -= (int)(p - s); |
7 | 5820 s = p + 1; |
5821 break; | |
5822 | |
5823 | |
5824 /* Three-character escape sequences */ | |
5825 | |
5826 case 'A': | |
5827 /* move cursor up one line in same column */ | |
5828 gotoxy(g_coord.X + 1, | |
5829 max(g_srScrollRegion.Top, g_coord.Y - 1) + 1); | |
5830 goto got3; | |
5831 | |
5832 case 'B': | |
5833 visual_bell(); | |
5834 goto got3; | |
5835 | |
5836 case 'C': | |
5837 /* move cursor right one column in same line */ | |
5838 gotoxy(min(g_srScrollRegion.Right, g_coord.X + 1) + 1, | |
5839 g_coord.Y + 1); | |
5840 goto got3; | |
5841 | |
5842 case 'E': | |
5843 termcap_mode_end(); | |
5844 goto got3; | |
5845 | |
5846 case 'F': | |
5847 standout(); | |
5848 goto got3; | |
5849 | |
5850 case 'f': | |
5851 standend(); | |
5852 goto got3; | |
5853 | |
5854 case 'H': | |
5855 gotoxy(1, 1); | |
5856 goto got3; | |
5857 | |
5858 case 'j': | |
5859 clear_to_end_of_display(); | |
5860 goto got3; | |
5861 | |
5862 case 'J': | |
5863 clear_screen(); | |
5864 goto got3; | |
5865 | |
5866 case 'K': | |
5867 clear_to_end_of_line(); | |
5868 goto got3; | |
5869 | |
5870 case 'L': | |
5871 insert_lines(1); | |
5872 goto got3; | |
5873 | |
5874 case 'M': | |
5875 delete_lines(1); | |
5876 goto got3; | |
5877 | |
5878 case 'S': | |
5879 termcap_mode_start(); | |
5880 goto got3; | |
5881 | |
5882 case 'V': | |
5883 cursor_visible(TRUE); | |
5884 goto got3; | |
5885 | |
5886 case 'v': | |
5887 cursor_visible(FALSE); | |
5888 goto got3; | |
5889 | |
5890 got3: | |
5891 s += 3; | |
5892 len -= 2; | |
5893 } | |
5894 | |
5895 #ifdef MCH_WRITE_DUMP | |
5896 if (fdDump) | |
5897 { | |
5898 fputs("ESC | ", fdDump); | |
5899 fwrite(old_s + 2, sizeof(char_u), s - old_s - 2, fdDump); | |
5900 fputc('\n', fdDump); | |
5901 } | |
5902 #endif | |
5903 } | |
5904 else | |
5905 { | |
5906 /* Write a single character */ | |
5907 DWORD nWritten; | |
5908 | |
5909 nWritten = write_chars(s, 1); | |
5910 #ifdef MCH_WRITE_DUMP | |
5911 if (fdDump) | |
5912 { | |
5913 fputc('>', fdDump); | |
5914 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
5915 fputs("<\n", fdDump); | |
5916 } | |
5917 #endif | |
5918 | |
5919 len -= (nWritten - 1); | |
5920 s += nWritten; | |
5921 } | |
5922 } | |
5923 | |
5924 #ifdef MCH_WRITE_DUMP | |
5925 if (fdDump) | |
5926 fflush(fdDump); | |
5927 #endif | |
5928 } | |
5929 | |
5930 #endif /* FEAT_GUI_W32 */ | |
5931 | |
5932 | |
5933 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5934 * Delay for "msec" milliseconds. |
7 | 5935 */ |
323 | 5936 /*ARGSUSED*/ |
7 | 5937 void |
5938 mch_delay( | |
5939 long msec, | |
5940 int ignoreinput) | |
5941 { | |
5942 #ifdef FEAT_GUI_W32 | |
5943 Sleep((int)msec); /* never wait for input */ | |
14 | 5944 #else /* Console */ |
7 | 5945 if (ignoreinput) |
14 | 5946 # ifdef FEAT_MZSCHEME |
5947 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq) | |
5948 { | |
5949 int towait = p_mzq; | |
5950 | |
5951 /* if msec is large enough, wait by portions in p_mzq */ | |
5952 while (msec > 0) | |
5953 { | |
5954 mzvim_check_threads(); | |
5955 if (msec < towait) | |
5956 towait = msec; | |
5957 Sleep(towait); | |
5958 msec -= towait; | |
5959 } | |
5960 } | |
5961 else | |
5962 # endif | |
5963 Sleep((int)msec); | |
7 | 5964 else |
5965 WaitForChar(msec); | |
5966 #endif | |
5967 } | |
5968 | |
5969 | |
5970 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
5971 * 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
|
5972 * This can also remove a symbolic link like Unix. |
7 | 5973 * Return 0 for success, -1 for failure. |
5974 */ | |
5975 int | |
5976 mch_remove(char_u *name) | |
5977 { | |
5978 #ifdef FEAT_MBYTE | |
5979 WCHAR *wn = NULL; | |
5980 int n; | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
5981 #endif |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
5982 |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
5983 /* |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
5984 * 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
|
5985 * 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
|
5986 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
5987 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
|
5988 return mch_rmdir(name); |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
5989 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
5990 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
5991 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
5992 #ifdef FEAT_MBYTE |
7 | 5993 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
5994 { | |
1752 | 5995 wn = enc_to_utf16(name, NULL); |
7 | 5996 if (wn != NULL) |
5997 { | |
5998 n = DeleteFileW(wn) ? 0 : -1; | |
5999 vim_free(wn); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6000 return n; |
7 | 6001 } |
6002 } | |
6003 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6004 return DeleteFile((LPCSTR)name) ? 0 : -1; |
7 | 6005 } |
6006 | |
6007 | |
6008 /* | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6009 * Check for an "interrupt signal": CTRL-break or CTRL-C. |
7 | 6010 */ |
6011 void | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6012 mch_breakcheck(int force) |
7 | 6013 { |
6014 #ifndef FEAT_GUI_W32 /* never used */ | |
6015 if (g_fCtrlCPressed || g_fCBrkPressed) | |
6016 { | |
6017 g_fCtrlCPressed = g_fCBrkPressed = FALSE; | |
6018 got_int = TRUE; | |
6019 } | |
6020 #endif | |
6021 } | |
6022 | |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6023 /* 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
|
6024 #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
|
6025 |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6026 /* |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6027 * 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
|
6028 */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6029 /*ARGSUSED*/ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6030 long_u |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6031 mch_total_mem(int special) |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6032 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6033 MEMORYSTATUSEX ms; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6034 |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6035 PlatformId(); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6036 /* 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
|
6037 * 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
|
6038 ms.dwLength = sizeof(MEMORYSTATUSEX); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6039 GlobalMemoryStatusEx(&ms); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6040 if (ms.ullAvailVirtual < ms.ullTotalPhys) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6041 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6042 /* 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
|
6043 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
|
6044 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6045 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
|
6046 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6047 /* 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
|
6048 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
|
6049 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6050 /* 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
|
6051 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
|
6052 } |
7 | 6053 |
6054 #ifdef FEAT_MBYTE | |
6055 /* | |
6056 * Same code as below, but with wide functions and no comments. | |
6057 * Return 0 for success, non-zero for failure. | |
6058 */ | |
6059 int | |
6060 mch_wrename(WCHAR *wold, WCHAR *wnew) | |
6061 { | |
6062 WCHAR *p; | |
6063 int i; | |
6064 WCHAR szTempFile[_MAX_PATH + 1]; | |
6065 WCHAR szNewPath[_MAX_PATH + 1]; | |
6066 HANDLE hf; | |
6067 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6068 p = wold; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6069 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
|
6070 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
|
6071 && wold[i + 1] != 0) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6072 p = wold + i + 1; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6073 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
|
6074 return (MoveFileW(wold, wnew) == 0); |
7 | 6075 |
6076 if (GetFullPathNameW(wnew, _MAX_PATH, szNewPath, &p) == 0 || p == NULL) | |
6077 return -1; | |
6078 *p = NUL; | |
6079 | |
6080 if (GetTempFileNameW(szNewPath, L"VIM", 0, szTempFile) == 0) | |
6081 return -2; | |
6082 | |
6083 if (!DeleteFileW(szTempFile)) | |
6084 return -3; | |
6085 | |
6086 if (!MoveFileW(wold, szTempFile)) | |
6087 return -4; | |
6088 | |
6089 if ((hf = CreateFileW(wold, GENERIC_WRITE, 0, NULL, CREATE_NEW, | |
6090 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) | |
6091 return -5; | |
6092 if (!CloseHandle(hf)) | |
6093 return -6; | |
6094 | |
6095 if (!MoveFileW(szTempFile, wnew)) | |
6096 { | |
6097 (void)MoveFileW(szTempFile, wold); | |
6098 return -7; | |
6099 } | |
6100 | |
6101 DeleteFileW(szTempFile); | |
6102 | |
6103 if (!DeleteFileW(wold)) | |
6104 return -8; | |
6105 | |
6106 return 0; | |
6107 } | |
6108 #endif | |
6109 | |
6110 | |
6111 /* | |
6112 * mch_rename() works around a bug in rename (aka MoveFile) in | |
6113 * Windows 95: rename("foo.bar", "foo.bar~") will generate a | |
6114 * file whose short file name is "FOO.BAR" (its long file name will | |
6115 * be correct: "foo.bar~"). Because a file can be accessed by | |
6116 * either its SFN or its LFN, "foo.bar" has effectively been | |
6117 * renamed to "foo.bar", which is not at all what was wanted. This | |
6118 * seems to happen only when renaming files with three-character | |
6119 * extensions by appending a suffix that does not include ".". | |
6120 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR". | |
6121 * | |
6122 * There is another problem, which isn't really a bug but isn't right either: | |
6123 * When renaming "abcdef~1.txt" to "abcdef~1.txt~", the short name can be | |
6124 * "abcdef~1.txt" again. This has been reported on Windows NT 4.0 with | |
6125 * service pack 6. Doesn't seem to happen on Windows 98. | |
6126 * | |
6127 * Like rename(), returns 0 upon success, non-zero upon failure. | |
6128 * Should probably set errno appropriately when errors occur. | |
6129 */ | |
6130 int | |
6131 mch_rename( | |
6132 const char *pszOldFile, | |
6133 const char *pszNewFile) | |
6134 { | |
6135 char szTempFile[_MAX_PATH+1]; | |
6136 char szNewPath[_MAX_PATH+1]; | |
6137 char *pszFilePart; | |
6138 HANDLE hf; | |
6139 #ifdef FEAT_MBYTE | |
6140 WCHAR *wold = NULL; | |
6141 WCHAR *wnew = NULL; | |
6142 int retval = -1; | |
6143 | |
6144 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | |
6145 { | |
1752 | 6146 wold = enc_to_utf16((char_u *)pszOldFile, NULL); |
6147 wnew = enc_to_utf16((char_u *)pszNewFile, NULL); | |
7 | 6148 if (wold != NULL && wnew != NULL) |
6149 retval = mch_wrename(wold, wnew); | |
6150 vim_free(wold); | |
6151 vim_free(wnew); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6152 return retval; |
7 | 6153 } |
6154 #endif | |
6155 | |
6156 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6157 * 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
|
6158 * seventh character. |
7 | 6159 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6160 pszFilePart = (char *)gettail((char_u *)pszOldFile); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6161 if (STRLEN(pszFilePart) < 8 || pszFilePart[6] != '~') |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6162 return rename(pszOldFile, pszNewFile); |
7 | 6163 |
6164 /* Get base path of new file name. Undocumented feature: If pszNewFile is | |
6165 * a directory, no error is returned and pszFilePart will be NULL. */ | |
6166 if (GetFullPathName(pszNewFile, _MAX_PATH, szNewPath, &pszFilePart) == 0 | |
6167 || pszFilePart == NULL) | |
6168 return -1; | |
6169 *pszFilePart = NUL; | |
6170 | |
6171 /* Get (and create) a unique temporary file name in directory of new file */ | |
6172 if (GetTempFileName(szNewPath, "VIM", 0, szTempFile) == 0) | |
6173 return -2; | |
6174 | |
6175 /* blow the temp file away */ | |
6176 if (!DeleteFile(szTempFile)) | |
6177 return -3; | |
6178 | |
6179 /* rename old file to the temp file */ | |
6180 if (!MoveFile(pszOldFile, szTempFile)) | |
6181 return -4; | |
6182 | |
6183 /* now create an empty file called pszOldFile; this prevents the operating | |
6184 * system using pszOldFile as an alias (SFN) if we're renaming within the | |
6185 * same directory. For example, we're editing a file called | |
6186 * filename.asc.txt by its SFN, filena~1.txt. If we rename filena~1.txt | |
6187 * to filena~1.txt~ (i.e., we're making a backup while writing it), the | |
6188 * SFN for filena~1.txt~ will be filena~1.txt, by default, which will | |
39 | 6189 * cause all sorts of problems later in buf_write(). So, we create an |
6190 * empty file called filena~1.txt and the system will have to find some | |
6191 * other SFN for filena~1.txt~, such as filena~2.txt | |
7 | 6192 */ |
6193 if ((hf = CreateFile(pszOldFile, GENERIC_WRITE, 0, NULL, CREATE_NEW, | |
6194 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) | |
6195 return -5; | |
6196 if (!CloseHandle(hf)) | |
6197 return -6; | |
6198 | |
6199 /* rename the temp file to the new file */ | |
6200 if (!MoveFile(szTempFile, pszNewFile)) | |
6201 { | |
6202 /* Renaming failed. Rename the file back to its old name, so that it | |
6203 * looks like nothing happened. */ | |
6204 (void)MoveFile(szTempFile, pszOldFile); | |
6205 | |
6206 return -7; | |
6207 } | |
6208 | |
6209 /* Seems to be left around on Novell filesystems */ | |
6210 DeleteFile(szTempFile); | |
6211 | |
6212 /* finally, remove the empty old file */ | |
6213 if (!DeleteFile(pszOldFile)) | |
6214 return -8; | |
6215 | |
6216 return 0; /* success */ | |
6217 } | |
6218 | |
6219 /* | |
6220 * Get the default shell for the current hardware platform | |
6221 */ | |
6222 char * | |
26 | 6223 default_shell(void) |
7 | 6224 { |
6225 PlatformId(); | |
6226 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6227 return "cmd.exe"; |
7 | 6228 } |
6229 | |
6230 /* | |
6231 * mch_access() extends access() to do more detailed check on network drives. | |
6232 * Returns 0 if file "n" has access rights according to "p", -1 otherwise. | |
6233 */ | |
6234 int | |
6235 mch_access(char *n, int p) | |
6236 { | |
6237 HANDLE hFile; | |
6238 DWORD am; | |
6239 int retval = -1; /* default: fail */ | |
6240 #ifdef FEAT_MBYTE | |
6241 WCHAR *wn = NULL; | |
6242 | |
6243 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
|
6244 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
|
6245 #endif |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6246 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6247 if (mch_isdir((char_u *)n)) |
7 | 6248 { |
6249 char TempName[_MAX_PATH + 16] = ""; | |
6250 #ifdef FEAT_MBYTE | |
6251 WCHAR TempNameW[_MAX_PATH + 16] = L""; | |
6252 #endif | |
6253 | |
6254 if (p & R_OK) | |
6255 { | |
6256 /* Read check is performed by seeing if we can do a find file on | |
6257 * the directory for any file. */ | |
6258 #ifdef FEAT_MBYTE | |
6259 if (wn != NULL) | |
6260 { | |
6261 int i; | |
6262 WIN32_FIND_DATAW d; | |
6263 | |
6264 for (i = 0; i < _MAX_PATH && wn[i] != 0; ++i) | |
6265 TempNameW[i] = wn[i]; | |
6266 if (TempNameW[i - 1] != '\\' && TempNameW[i - 1] != '/') | |
6267 TempNameW[i++] = '\\'; | |
6268 TempNameW[i++] = '*'; | |
6269 TempNameW[i++] = 0; | |
6270 | |
6271 hFile = FindFirstFileW(TempNameW, &d); | |
6272 if (hFile == INVALID_HANDLE_VALUE) | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6273 goto getout; |
7 | 6274 else |
6275 (void)FindClose(hFile); | |
6276 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6277 else |
7 | 6278 #endif |
6279 { | |
6280 char *pch; | |
6281 WIN32_FIND_DATA d; | |
6282 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6283 vim_strncpy((char_u *)TempName, (char_u *)n, _MAX_PATH); |
7 | 6284 pch = TempName + STRLEN(TempName) - 1; |
6285 if (*pch != '\\' && *pch != '/') | |
6286 *++pch = '\\'; | |
6287 *++pch = '*'; | |
6288 *++pch = NUL; | |
6289 | |
6290 hFile = FindFirstFile(TempName, &d); | |
6291 if (hFile == INVALID_HANDLE_VALUE) | |
6292 goto getout; | |
6293 (void)FindClose(hFile); | |
6294 } | |
6295 } | |
6296 | |
6297 if (p & W_OK) | |
6298 { | |
6299 /* Trying to create a temporary file in the directory should catch | |
6300 * directories on read-only network shares. However, in | |
6301 * directories whose ACL allows writes but denies deletes will end | |
6302 * up keeping the temporary file :-(. */ | |
6303 #ifdef FEAT_MBYTE | |
6304 if (wn != NULL) | |
6305 { | |
6306 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
|
6307 goto getout; |
7 | 6308 else |
6309 DeleteFileW(TempNameW); | |
6310 } | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6311 else |
7 | 6312 #endif |
6313 { | |
6314 if (!GetTempFileName(n, "VIM", 0, TempName)) | |
6315 goto getout; | |
6316 mch_remove((char_u *)TempName); | |
6317 } | |
6318 } | |
6319 } | |
6320 else | |
6321 { | |
6322 /* Trying to open the file for the required access does ACL, read-only | |
6323 * network share, and file attribute checks. */ | |
6324 am = ((p & W_OK) ? GENERIC_WRITE : 0) | |
6325 | ((p & R_OK) ? GENERIC_READ : 0); | |
6326 #ifdef FEAT_MBYTE | |
6327 if (wn != NULL) | |
6328 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
|
6329 else |
7 | 6330 #endif |
6331 hFile = CreateFile(n, am, 0, NULL, OPEN_EXISTING, 0, NULL); | |
6332 if (hFile == INVALID_HANDLE_VALUE) | |
6333 goto getout; | |
6334 CloseHandle(hFile); | |
6335 } | |
6336 | |
6337 retval = 0; /* success */ | |
6338 getout: | |
6339 #ifdef FEAT_MBYTE | |
6340 vim_free(wn); | |
6341 #endif | |
6342 return retval; | |
6343 } | |
6344 | |
6345 #if defined(FEAT_MBYTE) || defined(PROTO) | |
6346 /* | |
1752 | 6347 * Version of open() that may use UTF-16 file name. |
7 | 6348 */ |
6349 int | |
6350 mch_open(char *name, int flags, int mode) | |
6351 { | |
39 | 6352 /* _wopen() does not work with Borland C 5.5: creates a read-only file. */ |
6353 # ifndef __BORLANDC__ | |
7 | 6354 WCHAR *wn; |
6355 int f; | |
6356 | |
39 | 6357 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7 | 6358 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6359 wn = enc_to_utf16((char_u *)name, NULL); |
7 | 6360 if (wn != NULL) |
6361 { | |
6362 f = _wopen(wn, flags, mode); | |
6363 vim_free(wn); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6364 return f; |
7 | 6365 } |
6366 } | |
39 | 6367 # endif |
7 | 6368 |
6345 | 6369 /* open() can open a file which name is longer than _MAX_PATH bytes |
6370 * and shorter than _MAX_PATH characters successfully, but sometimes it | |
6371 * causes unexpected error in another part. We make it an error explicitly | |
6372 * here. */ | |
6373 if (strlen(name) >= _MAX_PATH) | |
6374 return -1; | |
6375 | |
7 | 6376 return open(name, flags, mode); |
6377 } | |
6378 | |
6379 /* | |
1752 | 6380 * Version of fopen() that may use UTF-16 file name. |
7 | 6381 */ |
6382 FILE * | |
6383 mch_fopen(char *name, char *mode) | |
6384 { | |
6385 WCHAR *wn, *wm; | |
6386 FILE *f = NULL; | |
6387 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6388 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
7 | 6389 { |
1686 | 6390 # if defined(DEBUG) && _MSC_VER >= 1400 |
1569 | 6391 /* Work around an annoying assertion in the Microsoft debug CRT |
6392 * when mode's text/binary setting doesn't match _get_fmode(). */ | |
6393 char newMode = mode[strlen(mode) - 1]; | |
6394 int oldMode = 0; | |
6395 | |
6396 _get_fmode(&oldMode); | |
6397 if (newMode == 't') | |
6398 _set_fmode(_O_TEXT); | |
6399 else if (newMode == 'b') | |
6400 _set_fmode(_O_BINARY); | |
6401 # endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6402 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
|
6403 wm = enc_to_utf16((char_u *)mode, NULL); |
7 | 6404 if (wn != NULL && wm != NULL) |
6405 f = _wfopen(wn, wm); | |
6406 vim_free(wn); | |
6407 vim_free(wm); | |
1569 | 6408 |
1686 | 6409 # if defined(DEBUG) && _MSC_VER >= 1400 |
1569 | 6410 _set_fmode(oldMode); |
6411 # endif | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6412 return f; |
7 | 6413 } |
6414 | |
6345 | 6415 /* fopen() can open a file which name is longer than _MAX_PATH bytes |
6416 * and shorter than _MAX_PATH characters successfully, but sometimes it | |
6417 * causes unexpected error in another part. We make it an error explicitly | |
6418 * here. */ | |
6419 if (strlen(name) >= _MAX_PATH) | |
6420 return NULL; | |
6421 | |
7 | 6422 return fopen(name, mode); |
6423 } | |
6424 #endif | |
6425 | |
6426 #ifdef FEAT_MBYTE | |
6427 /* | |
6428 * SUB STREAM (aka info stream) handling: | |
6429 * | |
6430 * NTFS can have sub streams for each file. Normal contents of file is | |
6431 * stored in the main stream, and extra contents (author information and | |
6432 * title and so on) can be stored in sub stream. After Windows 2000, user | |
6433 * can access and store those informations in sub streams via explorer's | |
6434 * property menuitem in right click menu. Those informations in sub streams | |
6435 * were lost when copying only the main stream. So we have to copy sub | |
6436 * streams. | |
6437 * | |
6438 * Incomplete explanation: | |
6439 * http://msdn.microsoft.com/library/en-us/dnw2k/html/ntfs5.asp | |
6440 * More useful info and an example: | |
6441 * http://www.sysinternals.com/ntw2k/source/misc.shtml#streams | |
6442 */ | |
6443 | |
6444 /* | |
6445 * Copy info stream data "substream". Read from the file with BackupRead(sh) | |
6446 * and write to stream "substream" of file "to". | |
6447 * Errors are ignored. | |
6448 */ | |
6449 static void | |
6450 copy_substream(HANDLE sh, void *context, WCHAR *to, WCHAR *substream, long len) | |
6451 { | |
6452 HANDLE hTo; | |
6453 WCHAR *to_name; | |
6454 | |
6455 to_name = malloc((wcslen(to) + wcslen(substream) + 1) * sizeof(WCHAR)); | |
6456 wcscpy(to_name, to); | |
6457 wcscat(to_name, substream); | |
6458 | |
6459 hTo = CreateFileW(to_name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, | |
6460 FILE_ATTRIBUTE_NORMAL, NULL); | |
6461 if (hTo != INVALID_HANDLE_VALUE) | |
6462 { | |
6463 long done; | |
6464 DWORD todo; | |
6465 DWORD readcnt, written; | |
6466 char buf[4096]; | |
6467 | |
6468 /* Copy block of bytes at a time. Abort when something goes wrong. */ | |
6469 for (done = 0; done < len; done += written) | |
6470 { | |
6471 /* (size_t) cast for Borland C 5.5 */ | |
835 | 6472 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) |
6473 : (size_t)(len - done)); | |
7 | 6474 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, |
6475 FALSE, FALSE, context) | |
6476 || readcnt != todo | |
6477 || !WriteFile(hTo, buf, todo, &written, NULL) | |
6478 || written != todo) | |
6479 break; | |
6480 } | |
6481 CloseHandle(hTo); | |
6482 } | |
6483 | |
6484 free(to_name); | |
6485 } | |
6486 | |
6487 /* | |
6488 * Copy info streams from file "from" to file "to". | |
6489 */ | |
6490 static void | |
6491 copy_infostreams(char_u *from, char_u *to) | |
6492 { | |
6493 WCHAR *fromw; | |
6494 WCHAR *tow; | |
6495 HANDLE sh; | |
6496 WIN32_STREAM_ID sid; | |
6497 int headersize; | |
6498 WCHAR streamname[_MAX_PATH]; | |
6499 DWORD readcount; | |
6500 void *context = NULL; | |
6501 DWORD lo, hi; | |
6502 int len; | |
6503 | |
6504 /* Convert the file names to wide characters. */ | |
1752 | 6505 fromw = enc_to_utf16(from, NULL); |
6506 tow = enc_to_utf16(to, NULL); | |
7 | 6507 if (fromw != NULL && tow != NULL) |
6508 { | |
6509 /* Open the file for reading. */ | |
6510 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, | |
6511 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | |
6512 if (sh != INVALID_HANDLE_VALUE) | |
6513 { | |
6514 /* Use BackupRead() to find the info streams. Repeat until we | |
6515 * have done them all.*/ | |
6516 for (;;) | |
6517 { | |
6518 /* Get the header to find the length of the stream name. If | |
6519 * the "readcount" is zero we have done all info streams. */ | |
6520 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); | |
835 | 6521 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); |
7 | 6522 if (!BackupRead(sh, (LPBYTE)&sid, headersize, |
6523 &readcount, FALSE, FALSE, &context) | |
6524 || readcount == 0) | |
6525 break; | |
6526 | |
6527 /* We only deal with streams that have a name. The normal | |
6528 * file data appears to be without a name, even though docs | |
6529 * suggest it is called "::$DATA". */ | |
6530 if (sid.dwStreamNameSize > 0) | |
6531 { | |
6532 /* Read the stream name. */ | |
6533 if (!BackupRead(sh, (LPBYTE)streamname, | |
6534 sid.dwStreamNameSize, | |
6535 &readcount, FALSE, FALSE, &context)) | |
6536 break; | |
6537 | |
6538 /* Copy an info stream with a name ":anything:$DATA". | |
6539 * Skip "::$DATA", it has no stream name (examples suggest | |
6540 * it might be used for the normal file contents). | |
6541 * Note that BackupRead() counts bytes, but the name is in | |
6542 * wide characters. */ | |
6543 len = readcount / sizeof(WCHAR); | |
6544 streamname[len] = 0; | |
6545 if (len > 7 && wcsicmp(streamname + len - 6, | |
6546 L":$DATA") == 0) | |
6547 { | |
6548 streamname[len - 6] = 0; | |
6549 copy_substream(sh, &context, tow, streamname, | |
10 | 6550 (long)sid.Size.u.LowPart); |
7 | 6551 } |
6552 } | |
6553 | |
6554 /* Advance to the next stream. We might try seeking too far, | |
6555 * but BackupSeek() doesn't skip over stream borders, thus | |
6556 * that's OK. */ | |
323 | 6557 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, |
7 | 6558 &lo, &hi, &context); |
6559 } | |
6560 | |
6561 /* Clear the context. */ | |
6562 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); | |
6563 | |
6564 CloseHandle(sh); | |
6565 } | |
6566 } | |
6567 vim_free(fromw); | |
6568 vim_free(tow); | |
6569 } | |
6570 #endif | |
6571 | |
6572 /* | |
6573 * Copy file attributes from file "from" to file "to". | |
6574 * For Windows NT and later we copy info streams. | |
6575 * Always returns zero, errors are ignored. | |
6576 */ | |
6577 int | |
6578 mch_copy_file_attribute(char_u *from, char_u *to) | |
6579 { | |
6580 #ifdef FEAT_MBYTE | |
6581 /* File streams only work on Windows NT and later. */ | |
6582 PlatformId(); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6583 copy_infostreams(from, to); |
7 | 6584 #endif |
6585 return 0; | |
6586 } | |
6587 | |
6588 #if defined(MYRESETSTKOFLW) || defined(PROTO) | |
6589 /* | |
6590 * Recreate a destroyed stack guard page in win32. | |
6591 * Written by Benjamin Peterson. | |
6592 */ | |
6593 | |
6594 /* These magic numbers are from the MS header files */ | |
6595 #define MIN_STACK_WINNT 2 | |
6596 | |
6597 /* | |
6598 * This function does the same thing as _resetstkoflw(), which is only | |
6599 * available in DevStudio .net and later. | |
6600 * Returns 0 for failure, 1 for success. | |
6601 */ | |
6602 int | |
6603 myresetstkoflw(void) | |
6604 { | |
6605 BYTE *pStackPtr; | |
6606 BYTE *pGuardPage; | |
6607 BYTE *pStackBase; | |
6608 BYTE *pLowestPossiblePage; | |
6609 MEMORY_BASIC_INFORMATION mbi; | |
6610 SYSTEM_INFO si; | |
6611 DWORD nPageSize; | |
6612 DWORD dummy; | |
6613 | |
6614 PlatformId(); | |
6615 | |
6616 /* We need to know the system page size. */ | |
6617 GetSystemInfo(&si); | |
6618 nPageSize = si.dwPageSize; | |
6619 | |
6620 /* ...and the current stack pointer */ | |
6621 pStackPtr = (BYTE*)_alloca(1); | |
6622 | |
6623 /* ...and the base of the stack. */ | |
6624 if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0) | |
6625 return 0; | |
6626 pStackBase = (BYTE*)mbi.AllocationBase; | |
6627 | |
6628 /* ...and the page thats min_stack_req pages away from stack base; this is | |
6629 * 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
|
6630 pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6631 |
7 | 6632 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6633 /* 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
|
6634 * 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
|
6635 */ |
7 | 6636 BYTE *pBlock = pStackBase; |
6637 | |
406 | 6638 for (;;) |
7 | 6639 { |
6640 if (VirtualQuery(pBlock, &mbi, sizeof mbi) == 0) | |
6641 return 0; | |
6642 | |
6643 pBlock += mbi.RegionSize; | |
6644 | |
6645 if (mbi.State & MEM_COMMIT) | |
6646 break; | |
6647 } | |
6648 | |
6649 /* mbi now describes the first committed block in the stack. */ | |
6650 if (mbi.Protect & PAGE_GUARD) | |
6651 return 1; | |
6652 | |
6653 /* decide where the guard page should start */ | |
6654 if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage) | |
6655 pGuardPage = pLowestPossiblePage; | |
6656 else | |
6657 pGuardPage = (BYTE*)mbi.BaseAddress; | |
6658 | |
6659 /* allocate the guard page */ | |
6660 if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE)) | |
6661 return 0; | |
6662 | |
6663 /* apply the guard attribute to the page */ | |
6664 if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD, | |
6665 &dummy)) | |
6666 return 0; | |
6667 } | |
6668 | |
6669 return 1; | |
6670 } | |
6671 #endif | |
26 | 6672 |
6673 | |
6674 #if defined(FEAT_MBYTE) || defined(PROTO) | |
6675 /* | |
6676 * The command line arguments in UCS2 | |
6677 */ | |
344 | 6678 static int nArgsW = 0; |
26 | 6679 static LPWSTR *ArglistW = NULL; |
6680 static int global_argc = 0; | |
6681 static char **global_argv; | |
6682 | |
6683 static int used_file_argc = 0; /* last argument in global_argv[] used | |
6684 for the argument list. */ | |
6685 static int *used_file_indexes = NULL; /* indexes in global_argv[] for | |
6686 command line arguments added to | |
6687 the argument list */ | |
6688 static int used_file_count = 0; /* nr of entries in used_file_indexes */ | |
6689 static int used_file_literal = FALSE; /* take file names literally */ | |
6690 static int used_file_full_path = FALSE; /* file name was full path */ | |
819 | 6691 static int used_file_diff_mode = FALSE; /* file name was with diff mode */ |
26 | 6692 static int used_alist_count = 0; |
6693 | |
6694 | |
6695 /* | |
6696 * Get the command line arguments. Unicode version. | |
6697 * Returns argc. Zero when something fails. | |
6698 */ | |
6699 int | |
6700 get_cmd_argsW(char ***argvp) | |
6701 { | |
6702 char **argv = NULL; | |
6703 int argc = 0; | |
6704 int i; | |
6705 | |
6193 | 6706 free_cmd_argsW(); |
26 | 6707 ArglistW = CommandLineToArgvW(GetCommandLineW(), &nArgsW); |
6708 if (ArglistW != NULL) | |
6709 { | |
6710 argv = malloc((nArgsW + 1) * sizeof(char *)); | |
6711 if (argv != NULL) | |
6712 { | |
6713 argc = nArgsW; | |
6714 argv[argc] = NULL; | |
6715 for (i = 0; i < argc; ++i) | |
6716 { | |
6717 int len; | |
6718 | |
6719 /* Convert each Unicode argument to the current codepage. */ | |
6720 WideCharToMultiByte_alloc(GetACP(), 0, | |
835 | 6721 ArglistW[i], (int)wcslen(ArglistW[i]) + 1, |
26 | 6722 (LPSTR *)&argv[i], &len, 0, 0); |
6723 if (argv[i] == NULL) | |
6724 { | |
6725 /* Out of memory, clear everything. */ | |
6726 while (i > 0) | |
6727 free(argv[--i]); | |
6728 free(argv); | |
5529 | 6729 argv = NULL; |
26 | 6730 argc = 0; |
6731 } | |
6732 } | |
6733 } | |
6734 } | |
6735 | |
6736 global_argc = argc; | |
6737 global_argv = argv; | |
6738 if (argc > 0) | |
6193 | 6739 { |
6740 if (used_file_indexes != NULL) | |
6741 free(used_file_indexes); | |
26 | 6742 used_file_indexes = malloc(argc * sizeof(int)); |
6193 | 6743 } |
26 | 6744 |
6745 if (argvp != NULL) | |
6746 *argvp = argv; | |
6747 return argc; | |
6748 } | |
6749 | |
6750 void | |
6751 free_cmd_argsW(void) | |
6752 { | |
6753 if (ArglistW != NULL) | |
6754 { | |
6755 GlobalFree(ArglistW); | |
6756 ArglistW = NULL; | |
6757 } | |
6758 } | |
6759 | |
6760 /* | |
6761 * Remember "name" is an argument that was added to the argument list. | |
6762 * This avoids that we have to re-parse the argument list when fix_arg_enc() | |
6763 * is called. | |
6764 */ | |
6765 void | |
819 | 6766 used_file_arg(char *name, int literal, int full_path, int diff_mode) |
26 | 6767 { |
6768 int i; | |
6769 | |
6770 if (used_file_indexes == NULL) | |
6771 return; | |
6772 for (i = used_file_argc + 1; i < global_argc; ++i) | |
6773 if (STRCMP(global_argv[i], name) == 0) | |
6774 { | |
6775 used_file_argc = i; | |
6776 used_file_indexes[used_file_count++] = i; | |
6777 break; | |
6778 } | |
6779 used_file_literal = literal; | |
6780 used_file_full_path = full_path; | |
819 | 6781 used_file_diff_mode = diff_mode; |
26 | 6782 } |
6783 | |
6784 /* | |
6785 * Remember the length of the argument list as it was. If it changes then we | |
6786 * leave it alone when 'encoding' is set. | |
6787 */ | |
6788 void | |
6789 set_alist_count(void) | |
6790 { | |
6791 used_alist_count = GARGCOUNT; | |
6792 } | |
6793 | |
6794 /* | |
6795 * Fix the encoding of the command line arguments. Invoked when 'encoding' | |
6796 * has been changed while starting up. Use the UCS-2 command line arguments | |
6797 * and convert them to 'encoding'. | |
6798 */ | |
6799 void | |
6800 fix_arg_enc(void) | |
6801 { | |
6802 int i; | |
6803 int idx; | |
6804 char_u *str; | |
41 | 6805 int *fnum_list; |
26 | 6806 |
6807 /* Safety checks: | |
6808 * - if argument count differs between the wide and non-wide argument | |
6809 * list, something must be wrong. | |
6810 * - the file name arguments must have been located. | |
6811 * - the length of the argument list wasn't changed by the user. | |
6812 */ | |
344 | 6813 if (global_argc != nArgsW |
26 | 6814 || ArglistW == NULL |
6815 || used_file_indexes == NULL | |
6816 || used_file_count == 0 | |
6817 || used_alist_count != GARGCOUNT) | |
6818 return; | |
6819 | |
41 | 6820 /* Remember the buffer numbers for the arguments. */ |
6821 fnum_list = (int *)alloc((int)sizeof(int) * GARGCOUNT); | |
6822 if (fnum_list == NULL) | |
6823 return; /* out of memory */ | |
6824 for (i = 0; i < GARGCOUNT; ++i) | |
6825 fnum_list[i] = GARGLIST[i].ae_fnum; | |
6826 | |
26 | 6827 /* Clear the argument list. Make room for the new arguments. */ |
6828 alist_clear(&global_alist); | |
6829 if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL) | |
41 | 6830 return; /* out of memory */ |
26 | 6831 |
6832 for (i = 0; i < used_file_count; ++i) | |
6833 { | |
6834 idx = used_file_indexes[i]; | |
1752 | 6835 str = utf16_to_enc(ArglistW[idx], NULL); |
26 | 6836 if (str != NULL) |
41 | 6837 { |
819 | 6838 #ifdef FEAT_DIFF |
6839 /* When using diff mode may need to concatenate file name to | |
6840 * directory name. Just like it's done in main(). */ | |
6841 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 | |
6842 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
6843 { | |
6844 char_u *r; | |
6845 | |
6846 r = concat_fnames(str, gettail(alist_name(&GARGLIST[0])), TRUE); | |
6847 if (r != NULL) | |
6848 { | |
6849 vim_free(str); | |
6850 str = r; | |
6851 } | |
6852 } | |
6853 #endif | |
41 | 6854 /* Re-use the old buffer by renaming it. When not using literal |
6855 * names it's done by alist_expand() below. */ | |
6856 if (used_file_literal) | |
6857 buf_set_name(fnum_list[i], str); | |
6858 | |
26 | 6859 alist_add(&global_alist, str, used_file_literal ? 2 : 0); |
41 | 6860 } |
26 | 6861 } |
6862 | |
6863 if (!used_file_literal) | |
6864 { | |
6865 /* Now expand wildcards in the arguments. */ | |
6866 /* Temporarily add '(' and ')' to 'isfname'. These are valid | |
6867 * filename characters but are excluded from 'isfname' to make | |
6868 * "gf" work on a file name in parenthesis (e.g.: see vim.h). */ | |
6869 do_cmdline_cmd((char_u *)":let SaVe_ISF = &isf|set isf+=(,)"); | |
41 | 6870 alist_expand(fnum_list, used_alist_count); |
26 | 6871 do_cmdline_cmd((char_u *)":let &isf = SaVe_ISF|unlet SaVe_ISF"); |
6872 } | |
6873 | |
6874 /* If wildcard expansion failed, we are editing the first file of the | |
6875 * arglist and there is no file name: Edit the first argument now. */ | |
6876 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) | |
6877 { | |
6878 do_cmdline_cmd((char_u *)":rewind"); | |
6879 if (GARGCOUNT == 1 && used_file_full_path) | |
6880 (void)vim_chdirfile(alist_name(&GARGLIST[0])); | |
6881 } | |
41 | 6882 |
6883 set_alist_count(); | |
26 | 6884 } |
6885 #endif |