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