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