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