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