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