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