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