Mercurial > vim
annotate src/os_win32.c @ 18343:375a7ecdb351
Update runtime files.
Commit: https://github.com/vim/vim/commit/2e693a88b24dc6b12883fad78ff2cb9cd4469c98
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Oct 16 22:35:02 2019 +0200
Update runtime files.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 16 Oct 2019 22:45:04 +0200 |
parents | 5218e26c658f |
children | 9f51d0cef8da |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10025
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * os_win32.c | |
11 * | |
12 * Used for both the console version and the Win32 GUI. A lot of code is for | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
13 * the console version only, so there is a lot of "#ifndef FEAT_GUI_MSWIN". |
7 | 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 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
48 # if defined(FEAT_TITLE) && !defined(FEAT_GUI_MSWIN) |
3927 | 49 # include <shellapi.h> |
50 # endif | |
7 | 51 #endif |
52 | |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
53 #ifdef FEAT_JOB_CHANNEL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
54 # include <tlhelp32.h> |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
55 #endif |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
56 |
7 | 57 #ifdef __MINGW32__ |
58 # ifndef FROM_LEFT_1ST_BUTTON_PRESSED | |
59 # define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001 | |
60 # endif | |
61 # ifndef RIGHTMOST_BUTTON_PRESSED | |
62 # define RIGHTMOST_BUTTON_PRESSED 0x0002 | |
63 # endif | |
64 # ifndef FROM_LEFT_2ND_BUTTON_PRESSED | |
65 # define FROM_LEFT_2ND_BUTTON_PRESSED 0x0004 | |
66 # endif | |
67 # ifndef FROM_LEFT_3RD_BUTTON_PRESSED | |
68 # define FROM_LEFT_3RD_BUTTON_PRESSED 0x0008 | |
69 # endif | |
70 # ifndef FROM_LEFT_4TH_BUTTON_PRESSED | |
71 # define FROM_LEFT_4TH_BUTTON_PRESSED 0x0010 | |
72 # endif | |
73 | |
74 /* | |
75 * EventFlags | |
76 */ | |
77 # ifndef MOUSE_MOVED | |
78 # define MOUSE_MOVED 0x0001 | |
79 # endif | |
80 # ifndef DOUBLE_CLICK | |
81 # define DOUBLE_CLICK 0x0002 | |
82 # endif | |
83 #endif | |
84 | |
85 /* Record all output and all keyboard & mouse input */ | |
86 /* #define MCH_WRITE_DUMP */ | |
87 | |
88 #ifdef MCH_WRITE_DUMP | |
89 FILE* fdDump = NULL; | |
90 #endif | |
91 | |
92 /* | |
93 * When generating prototypes for Win32 on Unix, these lines make the syntax | |
94 * errors disappear. They do not need to be correct. | |
95 */ | |
96 #ifdef PROTO | |
97 #define WINAPI | |
98 typedef char * LPCSTR; | |
26 | 99 typedef char * LPWSTR; |
7 | 100 typedef int ACCESS_MASK; |
101 typedef int BOOL; | |
102 typedef int COLORREF; | |
103 typedef int CONSOLE_CURSOR_INFO; | |
104 typedef int COORD; | |
105 typedef int DWORD; | |
106 typedef int HANDLE; | |
7668
21b0a39d13ed
commit https://github.com/vim/vim/commit/ef26954a35207c3f17d6ed35d9a40c918d974892
Christian Brabandt <cb@256bit.org>
parents:
7657
diff
changeset
|
107 typedef int LPHANDLE; |
7 | 108 typedef int HDC; |
109 typedef int HFONT; | |
110 typedef int HICON; | |
111 typedef int HINSTANCE; | |
112 typedef int HWND; | |
113 typedef int INPUT_RECORD; | |
11929
3457728d1a58
patch 8.0.0844: wrong function prototype because of missing static
Christian Brabandt <cb@256bit.org>
parents:
11921
diff
changeset
|
114 typedef int INT; |
7 | 115 typedef int KEY_EVENT_RECORD; |
116 typedef int LOGFONT; | |
117 typedef int LPBOOL; | |
118 typedef int LPCTSTR; | |
119 typedef int LPDWORD; | |
120 typedef int LPSTR; | |
121 typedef int LPTSTR; | |
122 typedef int LPVOID; | |
123 typedef int MOUSE_EVENT_RECORD; | |
124 typedef int PACL; | |
125 typedef int PDWORD; | |
126 typedef int PHANDLE; | |
127 typedef int PRINTDLG; | |
128 typedef int PSECURITY_DESCRIPTOR; | |
129 typedef int PSID; | |
130 typedef int SECURITY_INFORMATION; | |
131 typedef int SHORT; | |
132 typedef int SMALL_RECT; | |
133 typedef int TEXTMETRIC; | |
134 typedef int TOKEN_INFORMATION_CLASS; | |
135 typedef int TRUSTEE; | |
136 typedef int WORD; | |
137 typedef int WCHAR; | |
138 typedef void VOID; | |
3927 | 139 typedef int BY_HANDLE_FILE_INFORMATION; |
5112
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
140 typedef int SE_OBJECT_TYPE; |
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
141 typedef int PSNSECINFO; |
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
142 typedef int PSNSECINFOW; |
6359 | 143 typedef int STARTUPINFO; |
144 typedef int PROCESS_INFORMATION; | |
10025
068f397d0da4
commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
145 typedef int LPSECURITY_ATTRIBUTES; |
068f397d0da4
commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
146 # define __stdcall /* empty */ |
7 | 147 #endif |
148 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
149 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 150 /* Win32 Console handles for input and output */ |
151 static HANDLE g_hConIn = INVALID_HANDLE_VALUE; | |
152 static HANDLE g_hConOut = INVALID_HANDLE_VALUE; | |
153 | |
154 /* Win32 Screen buffer,coordinate,console I/O information */ | |
155 static SMALL_RECT g_srScrollRegion; | |
156 static COORD g_coord; /* 0-based, but external coords are 1-based */ | |
157 | |
158 /* The attribute of the screen when the editor was started */ | |
159 static WORD g_attrDefault = 7; /* lightgray text on black background */ | |
160 static WORD g_attrCurrent; | |
161 | |
162 static int g_fCBrkPressed = FALSE; /* set by ctrl-break interrupt */ | |
163 static int g_fCtrlCPressed = FALSE; /* set when ctrl-C or ctrl-break detected */ | |
164 static int g_fForceExit = FALSE; /* set when forcefully exiting */ | |
165 | |
166 static void scroll(unsigned cLines); | |
167 static void set_scroll_region(unsigned left, unsigned top, | |
168 unsigned right, unsigned bottom); | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
169 static void set_scroll_region_tb(unsigned top, unsigned bottom); |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
170 static void set_scroll_region_lr(unsigned left, unsigned right); |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
171 static void insert_lines(unsigned cLines); |
7 | 172 static void delete_lines(unsigned cLines); |
173 static void gotoxy(unsigned x, unsigned y); | |
174 static void standout(void); | |
175 static int s_cursor_visible = TRUE; | |
176 static int did_create_conin = FALSE; | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
177 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
178 #ifdef FEAT_GUI_MSWIN |
7 | 179 static int s_dont_use_vimrun = TRUE; |
180 static int need_vimrun_warning = FALSE; | |
181 static char *vimrun_path = "vimrun "; | |
182 #endif | |
183 | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
184 static int win32_getattrs(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
185 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
|
186 static int win32_set_archive(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
187 |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
188 static int conpty_working = 0; |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
189 static int conpty_type = 0; |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
190 static int conpty_stable = 0; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
191 static void vtp_flag_init(); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
192 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
193 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
15848
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
194 static int vtp_working = 0; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
195 static void vtp_init(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
196 static void vtp_exit(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
197 static int vtp_printf(char *format, ...); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
198 static void vtp_sgr_bulk(int arg); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
199 static void vtp_sgr_bulks(int argc, int *argv); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
200 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
201 static guicolor_T save_console_bg_rgb; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
202 static guicolor_T save_console_fg_rgb; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
203 |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
204 static int g_color_index_bg = 0; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
205 static int g_color_index_fg = 7; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
206 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
207 # ifdef FEAT_TERMGUICOLORS |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
208 static int default_console_color_bg = 0x000000; // black |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
209 static int default_console_color_fg = 0xc0c0c0; // white |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
210 # endif |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
211 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
212 # ifdef FEAT_TERMGUICOLORS |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
213 # define USE_VTP (vtp_working && is_term_win32() && (p_tgc || (!p_tgc && t_colors >= 256))) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
214 # else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
215 # define USE_VTP 0 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
216 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
217 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
218 static void set_console_color_rgb(void); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
219 static void reset_console_color_rgb(void); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
220 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
221 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
222 /* This flag is newly created from Windows 10 */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
223 #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
224 # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
225 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
226 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
227 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 228 static int suppress_winsize = 1; /* don't fiddle with console */ |
229 #endif | |
230 | |
2612 | 231 static char_u *exe_path = NULL; |
232 | |
5633 | 233 static BOOL win8_or_later = FALSE; |
234 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
235 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
236 /* Dynamic loading for portability */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
237 typedef struct _DYN_CONSOLE_SCREEN_BUFFER_INFOEX |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
238 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
239 ULONG cbSize; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
240 COORD dwSize; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
241 COORD dwCursorPosition; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
242 WORD wAttributes; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
243 SMALL_RECT srWindow; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
244 COORD dwMaximumWindowSize; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
245 WORD wPopupAttributes; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
246 BOOL bFullscreenSupported; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
247 COLORREF ColorTable[16]; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
248 } DYN_CONSOLE_SCREEN_BUFFER_INFOEX, *PDYN_CONSOLE_SCREEN_BUFFER_INFOEX; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
249 typedef BOOL (WINAPI *PfnGetConsoleScreenBufferInfoEx)(HANDLE, PDYN_CONSOLE_SCREEN_BUFFER_INFOEX); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
250 static PfnGetConsoleScreenBufferInfoEx pGetConsoleScreenBufferInfoEx; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
251 typedef BOOL (WINAPI *PfnSetConsoleScreenBufferInfoEx)(HANDLE, PDYN_CONSOLE_SCREEN_BUFFER_INFOEX); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
252 static PfnSetConsoleScreenBufferInfoEx pSetConsoleScreenBufferInfoEx; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
253 static BOOL has_csbiex = FALSE; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
254 #endif |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
255 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
256 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
257 * Get version number including build number |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
258 */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
259 typedef BOOL (WINAPI *PfnRtlGetVersion)(LPOSVERSIONINFOW); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
260 # define MAKE_VER(major, minor, build) \ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
261 (((major) << 24) | ((minor) << 16) | (build)) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
262 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
263 static DWORD |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
264 get_build_number(void) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
265 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
266 OSVERSIONINFOW osver = {sizeof(OSVERSIONINFOW)}; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
267 HMODULE hNtdll; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
268 PfnRtlGetVersion pRtlGetVersion; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
269 DWORD ver = MAKE_VER(0, 0, 0); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
270 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
271 hNtdll = GetModuleHandle("ntdll.dll"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
272 if (hNtdll != NULL) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
273 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
274 pRtlGetVersion = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
275 (PfnRtlGetVersion)GetProcAddress(hNtdll, "RtlGetVersion"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
276 pRtlGetVersion(&osver); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
277 ver = MAKE_VER(min(osver.dwMajorVersion, 255), |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
278 min(osver.dwMinorVersion, 255), |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
279 min(osver.dwBuildNumber, 32767)); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
280 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
281 return ver; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
282 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
283 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
284 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
5580 | 285 /* |
286 * Version of ReadConsoleInput() that works with IME. | |
5590 | 287 * Works around problems on Windows 8. |
5580 | 288 */ |
289 static BOOL | |
290 read_console_input( | |
5590 | 291 HANDLE hInput, |
292 INPUT_RECORD *lpBuffer, | |
293 DWORD nLength, | |
294 LPDWORD lpEvents) | |
5580 | 295 { |
296 enum | |
297 { | |
5590 | 298 IRSIZE = 10 |
5580 | 299 }; |
5590 | 300 static INPUT_RECORD s_irCache[IRSIZE]; |
5580 | 301 static DWORD s_dwIndex = 0; |
302 static DWORD s_dwMax = 0; | |
5590 | 303 DWORD dwEvents; |
5635 | 304 int head; |
305 int tail; | |
306 int i; | |
5580 | 307 |
6981 | 308 if (nLength == -2) |
309 return (s_dwMax > 0) ? TRUE : FALSE; | |
310 | |
5633 | 311 if (!win8_or_later) |
312 { | |
313 if (nLength == -1) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
314 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
315 return ReadConsoleInputW(hInput, lpBuffer, 1, &dwEvents); |
5633 | 316 } |
317 | |
5580 | 318 if (s_dwMax == 0) |
319 { | |
5590 | 320 if (nLength == -1) |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
321 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
322 if (!ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents)) |
5590 | 323 return FALSE; |
5580 | 324 s_dwIndex = 0; |
5590 | 325 s_dwMax = dwEvents; |
326 if (dwEvents == 0) | |
5580 | 327 { |
5590 | 328 *lpEvents = 0; |
329 return TRUE; | |
5580 | 330 } |
5635 | 331 |
332 if (s_dwMax > 1) | |
333 { | |
334 head = 0; | |
335 tail = s_dwMax - 1; | |
336 while (head != tail) | |
337 { | |
338 if (s_irCache[head].EventType == WINDOW_BUFFER_SIZE_EVENT | |
339 && s_irCache[head + 1].EventType | |
340 == WINDOW_BUFFER_SIZE_EVENT) | |
341 { | |
342 /* Remove duplicate event to avoid flicker. */ | |
343 for (i = head; i < tail; ++i) | |
344 s_irCache[i] = s_irCache[i + 1]; | |
345 --tail; | |
346 continue; | |
347 } | |
348 head++; | |
349 } | |
350 s_dwMax = tail + 1; | |
351 } | |
5580 | 352 } |
5635 | 353 |
5590 | 354 *lpBuffer = s_irCache[s_dwIndex]; |
6981 | 355 if (!(nLength == -1 || nLength == -2) && ++s_dwIndex >= s_dwMax) |
5580 | 356 s_dwMax = 0; |
5590 | 357 *lpEvents = 1; |
5580 | 358 return TRUE; |
359 } | |
360 | |
361 /* | |
362 * Version of PeekConsoleInput() that works with IME. | |
363 */ | |
364 static BOOL | |
365 peek_console_input( | |
5590 | 366 HANDLE hInput, |
367 INPUT_RECORD *lpBuffer, | |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
368 DWORD nLength UNUSED, |
5590 | 369 LPDWORD lpEvents) |
5580 | 370 { |
5590 | 371 return read_console_input(hInput, lpBuffer, -1, lpEvents); |
5580 | 372 } |
373 | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
374 # ifdef FEAT_CLIENTSERVER |
6981 | 375 static DWORD |
376 msg_wait_for_multiple_objects( | |
377 DWORD nCount, | |
378 LPHANDLE pHandles, | |
379 BOOL fWaitAll, | |
380 DWORD dwMilliseconds, | |
381 DWORD dwWakeMask) | |
382 { | |
383 if (read_console_input(NULL, NULL, -2, NULL)) | |
384 return WAIT_OBJECT_0; | |
385 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, | |
386 dwMilliseconds, dwWakeMask); | |
387 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
388 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
389 |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
390 # ifndef FEAT_CLIENTSERVER |
6981 | 391 static DWORD |
392 wait_for_single_object( | |
393 HANDLE hHandle, | |
394 DWORD dwMilliseconds) | |
395 { | |
396 if (read_console_input(NULL, NULL, -2, NULL)) | |
397 return WAIT_OBJECT_0; | |
398 return WaitForSingleObject(hHandle, dwMilliseconds); | |
399 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
400 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
401 #endif |
6981 | 402 |
7 | 403 static void |
404 get_exe_name(void) | |
405 { | |
2630 | 406 /* Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned |
407 * as the maximum length that works (plus a NUL byte). */ | |
408 #define MAX_ENV_PATH_LEN 8192 | |
409 char temp[MAX_ENV_PATH_LEN]; | |
2612 | 410 char_u *p; |
7 | 411 |
412 if (exe_name == NULL) | |
413 { | |
414 /* store the name of the executable, may be used for $VIM */ | |
2630 | 415 GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1); |
7 | 416 if (*temp != NUL) |
417 exe_name = FullName_save((char_u *)temp, FALSE); | |
418 } | |
819 | 419 |
2612 | 420 if (exe_path == NULL && exe_name != NULL) |
819 | 421 { |
2615 | 422 exe_path = vim_strnsave(exe_name, |
423 (int)(gettail_sep(exe_name) - exe_name)); | |
2612 | 424 if (exe_path != NULL) |
819 | 425 { |
2612 | 426 /* Append our starting directory to $PATH, so that when doing |
427 * "!xxd" it's found in our starting directory. Needed because | |
428 * SearchPath() also looks there. */ | |
429 p = mch_getenv("PATH"); | |
2630 | 430 if (p == NULL |
431 || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN) | |
2612 | 432 { |
2630 | 433 if (p == NULL || *p == NUL) |
434 temp[0] = NUL; | |
435 else | |
436 { | |
437 STRCPY(temp, p); | |
438 STRCAT(temp, ";"); | |
439 } | |
2612 | 440 STRCAT(temp, exe_path); |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
441 vim_setenv((char_u *)"PATH", (char_u *)temp); |
2612 | 442 } |
819 | 443 } |
444 } | |
7 | 445 } |
446 | |
2612 | 447 /* |
3361 | 448 * Unescape characters in "p" that appear in "escaped". |
449 */ | |
450 static void | |
451 unescape_shellxquote(char_u *p, char_u *escaped) | |
452 { | |
3386 | 453 int l = (int)STRLEN(p); |
3361 | 454 int n; |
455 | |
456 while (*p != NUL) | |
457 { | |
458 if (*p == '^' && vim_strchr(escaped, p[1]) != NULL) | |
459 mch_memmove(p, p + 1, l--); | |
460 n = (*mb_ptr2len)(p); | |
461 p += n; | |
462 l -= n; | |
463 } | |
464 } | |
465 | |
466 /* | |
2612 | 467 * Load library "name". |
468 */ | |
469 HINSTANCE | |
470 vimLoadLib(char *name) | |
471 { | |
3902 | 472 HINSTANCE dll = NULL; |
3889 | 473 |
474 /* NOTE: Do not use mch_dirname() and mch_chdir() here, they may call | |
475 * vimLoadLib() recursively, which causes a stack overflow. */ | |
2612 | 476 if (exe_path == NULL) |
477 get_exe_name(); | |
3902 | 478 if (exe_path != NULL) |
2612 | 479 { |
3902 | 480 WCHAR old_dirw[MAXPATHL]; |
481 | |
482 if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) | |
483 { | |
484 /* Change directory to where the executable is, both to make | |
485 * sure we find a .dll there and to avoid looking for a .dll | |
486 * in the current directory. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
487 SetCurrentDirectory((LPCSTR)exe_path); |
3902 | 488 dll = LoadLibrary(name); |
489 SetCurrentDirectoryW(old_dirw); | |
490 return dll; | |
491 } | |
2612 | 492 } |
493 return dll; | |
494 } | |
495 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
496 #if defined(VIMDLL) || defined(PROTO) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
497 /* |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
498 * Check if the current executable file is for the GUI subsystem. |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
499 */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
500 int |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
501 mch_is_gui_executable(void) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
502 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
503 PBYTE pImage = (PBYTE)GetModuleHandle(NULL); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
504 PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)pImage; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
505 PIMAGE_NT_HEADERS pPE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
506 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
507 if (pDOS->e_magic != IMAGE_DOS_SIGNATURE) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
508 return FALSE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
509 pPE = (PIMAGE_NT_HEADERS)(pImage + pDOS->e_lfanew); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
510 if (pPE->Signature != IMAGE_NT_SIGNATURE) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
511 return FALSE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
512 if (pPE->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
513 return TRUE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
514 return FALSE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
515 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
516 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
517 |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
518 #if defined(DYNAMIC_ICONV) || defined(DYNAMIC_GETTEXT) || defined(PROTO) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
519 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
520 * Get related information about 'funcname' which is imported by 'hInst'. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
521 * If 'info' is 0, return the function address. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
522 * If 'info' is 1, return the module name which the function is imported from. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
523 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
524 static void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
525 get_imported_func_info(HINSTANCE hInst, const char *funcname, int info) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
526 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
527 PBYTE pImage = (PBYTE)hInst; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
528 PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
529 PIMAGE_NT_HEADERS pPE; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
530 PIMAGE_IMPORT_DESCRIPTOR pImpDesc; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
531 PIMAGE_THUNK_DATA pIAT; /* Import Address Table */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
532 PIMAGE_THUNK_DATA pINT; /* Import Name Table */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
533 PIMAGE_IMPORT_BY_NAME pImpName; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
534 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
535 if (pDOS->e_magic != IMAGE_DOS_SIGNATURE) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
536 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
537 pPE = (PIMAGE_NT_HEADERS)(pImage + pDOS->e_lfanew); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
538 if (pPE->Signature != IMAGE_NT_SIGNATURE) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
539 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
540 pImpDesc = (PIMAGE_IMPORT_DESCRIPTOR)(pImage |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
541 + pPE->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
542 .VirtualAddress); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
543 for (; pImpDesc->FirstThunk; ++pImpDesc) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
544 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
545 if (!pImpDesc->OriginalFirstThunk) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
546 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
547 pIAT = (PIMAGE_THUNK_DATA)(pImage + pImpDesc->FirstThunk); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
548 pINT = (PIMAGE_THUNK_DATA)(pImage + pImpDesc->OriginalFirstThunk); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
549 for (; pIAT->u1.Function; ++pIAT, ++pINT) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
550 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
551 if (IMAGE_SNAP_BY_ORDINAL(pINT->u1.Ordinal)) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
552 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
553 pImpName = (PIMAGE_IMPORT_BY_NAME)(pImage |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
554 + (UINT_PTR)(pINT->u1.AddressOfData)); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
555 if (strcmp((char *)pImpName->Name, funcname) == 0) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
556 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
557 switch (info) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
558 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
559 case 0: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
560 return (void *)pIAT->u1.Function; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
561 case 1: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
562 return (void *)(pImage + pImpDesc->Name); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
563 default: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
564 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
565 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
566 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
567 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
568 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
569 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
570 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
571 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
572 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
573 * Get the module handle which 'funcname' in 'hInst' is imported from. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
574 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
575 HINSTANCE |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
576 find_imported_module_by_funcname(HINSTANCE hInst, const char *funcname) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
577 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
578 char *modulename; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
579 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
580 modulename = (char *)get_imported_func_info(hInst, funcname, 1); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
581 if (modulename != NULL) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
582 return GetModuleHandleA(modulename); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
583 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
584 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
585 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
586 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
587 * Get the address of 'funcname' which is imported by 'hInst' DLL. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
588 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
589 void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
590 get_dll_import_func(HINSTANCE hInst, const char *funcname) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
591 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
592 return get_imported_func_info(hInst, funcname, 0); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
593 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
594 #endif |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
595 |
7 | 596 #if defined(DYNAMIC_GETTEXT) || defined(PROTO) |
597 # ifndef GETTEXT_DLL | |
598 # define GETTEXT_DLL "libintl.dll" | |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
599 # define GETTEXT_DLL_ALT1 "libintl-8.dll" |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
600 # define GETTEXT_DLL_ALT2 "intl.dll" |
7 | 601 # endif |
3622 | 602 /* Dummy functions */ |
36 | 603 static char *null_libintl_gettext(const char *); |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
604 static char *null_libintl_ngettext(const char *, const char *, unsigned long n); |
36 | 605 static char *null_libintl_textdomain(const char *); |
606 static char *null_libintl_bindtextdomain(const char *, const char *); | |
607 static char *null_libintl_bind_textdomain_codeset(const char *, const char *); | |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
608 static int null_libintl_wputenv(const wchar_t *); |
7 | 609 |
2612 | 610 static HINSTANCE hLibintlDLL = NULL; |
36 | 611 char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext; |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
612 char *(*dyn_libintl_ngettext)(const char *, const char *, unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
613 = null_libintl_ngettext; |
36 | 614 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; |
615 char *(*dyn_libintl_bindtextdomain)(const char *, const char *) | |
7 | 616 = null_libintl_bindtextdomain; |
36 | 617 char *(*dyn_libintl_bind_textdomain_codeset)(const char *, const char *) |
618 = null_libintl_bind_textdomain_codeset; | |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
619 int (*dyn_libintl_wputenv)(const wchar_t *) = null_libintl_wputenv; |
7 | 620 |
621 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
622 dyn_libintl_init(void) |
7 | 623 { |
624 int i; | |
625 static struct | |
626 { | |
627 char *name; | |
628 FARPROC *ptr; | |
629 } libintl_entry[] = | |
630 { | |
631 {"gettext", (FARPROC*)&dyn_libintl_gettext}, | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
632 {"ngettext", (FARPROC*)&dyn_libintl_ngettext}, |
7 | 633 {"textdomain", (FARPROC*)&dyn_libintl_textdomain}, |
634 {"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, | |
635 {NULL, NULL} | |
636 }; | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
637 HINSTANCE hmsvcrt; |
7 | 638 |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
639 // No need to initialize twice. |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
640 if (hLibintlDLL != NULL) |
7 | 641 return 1; |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
642 // Load gettext library (libintl.dll and other names). |
7784
29d4ee3f009a
commit https://github.com/vim/vim/commit/923e43b837ca4c8edb7998743f142823eaeaf588
Christian Brabandt <cb@256bit.org>
parents:
7734
diff
changeset
|
643 hLibintlDLL = vimLoadLib(GETTEXT_DLL); |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
644 #ifdef GETTEXT_DLL_ALT1 |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
645 if (!hLibintlDLL) |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
646 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT1); |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
647 #endif |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
648 #ifdef GETTEXT_DLL_ALT2 |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
649 if (!hLibintlDLL) |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
650 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT2); |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
651 #endif |
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
652 if (!hLibintlDLL) |
7 | 653 { |
2612 | 654 if (p_verbose > 0) |
7 | 655 { |
2612 | 656 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
657 semsg(_(e_loadlib), GETTEXT_DLL); |
2612 | 658 verbose_leave(); |
7 | 659 } |
2612 | 660 return 0; |
7 | 661 } |
662 for (i = 0; libintl_entry[i].name != NULL | |
663 && libintl_entry[i].ptr != NULL; ++i) | |
664 { | |
665 if ((*libintl_entry[i].ptr = (FARPROC)GetProcAddress(hLibintlDLL, | |
666 libintl_entry[i].name)) == NULL) | |
667 { | |
668 dyn_libintl_end(); | |
669 if (p_verbose > 0) | |
292 | 670 { |
671 verbose_enter(); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
672 semsg(_(e_loadfunc), libintl_entry[i].name); |
292 | 673 verbose_leave(); |
674 } | |
7 | 675 return 0; |
676 } | |
677 } | |
36 | 678 |
679 /* The bind_textdomain_codeset() function is optional. */ | |
323 | 680 dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL, |
36 | 681 "bind_textdomain_codeset"); |
682 if (dyn_libintl_bind_textdomain_codeset == NULL) | |
683 dyn_libintl_bind_textdomain_codeset = | |
684 null_libintl_bind_textdomain_codeset; | |
685 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
686 /* _wputenv() function for the libintl.dll is optional. */ |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
687 hmsvcrt = find_imported_module_by_funcname(hLibintlDLL, "getenv"); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
688 if (hmsvcrt != NULL) |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
689 dyn_libintl_wputenv = (void *)GetProcAddress(hmsvcrt, "_wputenv"); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
690 if (dyn_libintl_wputenv == NULL || dyn_libintl_wputenv == _wputenv) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
691 dyn_libintl_wputenv = null_libintl_wputenv; |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
692 |
7 | 693 return 1; |
694 } | |
695 | |
696 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
697 dyn_libintl_end(void) |
7 | 698 { |
699 if (hLibintlDLL) | |
700 FreeLibrary(hLibintlDLL); | |
701 hLibintlDLL = NULL; | |
702 dyn_libintl_gettext = null_libintl_gettext; | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
703 dyn_libintl_ngettext = null_libintl_ngettext; |
7 | 704 dyn_libintl_textdomain = null_libintl_textdomain; |
705 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain; | |
36 | 706 dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset; |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
707 dyn_libintl_wputenv = null_libintl_wputenv; |
7 | 708 } |
709 | |
710 static char * | |
26 | 711 null_libintl_gettext(const char *msgid) |
7 | 712 { |
713 return (char*)msgid; | |
714 } | |
715 | |
716 static char * | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
717 null_libintl_ngettext( |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
718 const char *msgid, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
719 const char *msgid_plural, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
720 unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
721 { |
9762
93dcc4329c74
commit https://github.com/vim/vim/commit/c90f2aedd0a5dc2cc75bc9b5f475f8a3e3fe36b1
Christian Brabandt <cb@256bit.org>
parents:
9754
diff
changeset
|
722 return (char *)(n == 1 ? msgid : msgid_plural); |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
723 } |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
724 |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
725 static char * |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
726 null_libintl_bindtextdomain( |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
727 const char *domainname UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
728 const char *dirname UNUSED) |
7 | 729 { |
730 return NULL; | |
731 } | |
732 | |
733 static char * | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
734 null_libintl_bind_textdomain_codeset( |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
735 const char *domainname UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
736 const char *codeset UNUSED) |
36 | 737 { |
738 return NULL; | |
739 } | |
740 | |
741 static char * | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
742 null_libintl_textdomain(const char *domainname UNUSED) |
7 | 743 { |
744 return NULL; | |
745 } | |
746 | |
11929
3457728d1a58
patch 8.0.0844: wrong function prototype because of missing static
Christian Brabandt <cb@256bit.org>
parents:
11921
diff
changeset
|
747 static int |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
748 null_libintl_wputenv(const wchar_t *envstring UNUSED) |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
749 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
750 return 0; |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
751 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
752 |
7 | 753 #endif /* DYNAMIC_GETTEXT */ |
754 | |
755 /* This symbol is not defined in older versions of the SDK or Visual C++ */ | |
756 | |
757 #ifndef VER_PLATFORM_WIN32_WINDOWS | |
758 # define VER_PLATFORM_WIN32_WINDOWS 1 | |
759 #endif | |
760 | |
761 DWORD g_PlatformId; | |
762 | |
763 #ifdef HAVE_ACL | |
3927 | 764 # ifndef PROTO |
765 # include <aclapi.h> | |
766 # endif | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
767 # ifndef PROTECTED_DACL_SECURITY_INFORMATION |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
768 # define PROTECTED_DACL_SECURITY_INFORMATION 0x80000000L |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
769 # endif |
7 | 770 #endif |
771 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
772 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
773 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
774 * Enables or disables the specified privilege. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
775 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
776 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
777 win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
778 { |
5590 | 779 BOOL bResult; |
780 LUID luid; | |
781 HANDLE hToken; | |
782 TOKEN_PRIVILEGES tokenPrivileges; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
783 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
784 if (!OpenProcessToken(GetCurrentProcess(), |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
785 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
786 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
787 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
788 if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
789 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
790 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
791 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
792 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
793 |
6047 | 794 tokenPrivileges.PrivilegeCount = 1; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
795 tokenPrivileges.Privileges[0].Luid = luid; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
796 tokenPrivileges.Privileges[0].Attributes = bEnable ? |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
797 SE_PRIVILEGE_ENABLED : 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
798 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
799 bResult = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
800 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
801 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
802 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
803 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
804 return bResult && GetLastError() == ERROR_SUCCESS; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
805 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
806 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
807 |
7 | 808 /* |
809 * Set g_PlatformId to VER_PLATFORM_WIN32_NT (NT) or | |
810 * VER_PLATFORM_WIN32_WINDOWS (Win95). | |
811 */ | |
812 void | |
813 PlatformId(void) | |
814 { | |
815 static int done = FALSE; | |
816 | |
817 if (!done) | |
818 { | |
819 OSVERSIONINFO ovi; | |
820 | |
821 ovi.dwOSVersionInfoSize = sizeof(ovi); | |
822 GetVersionEx(&ovi); | |
823 | |
824 g_PlatformId = ovi.dwPlatformId; | |
825 | |
5633 | 826 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2) |
827 || ovi.dwMajorVersion > 6) | |
828 win8_or_later = TRUE; | |
829 | |
7 | 830 #ifdef HAVE_ACL |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
831 /* Enable privilege for getting or setting SACLs. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
832 win32_enable_privilege(SE_SECURITY_NAME, TRUE); |
7 | 833 #endif |
834 done = TRUE; | |
835 } | |
836 } | |
837 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
838 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 839 |
840 #define SHIFT (SHIFT_PRESSED) | |
841 #define CTRL (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED) | |
842 #define ALT (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED) | |
843 #define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) | |
844 | |
845 | |
846 /* When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode. | |
847 * We map function keys to their ANSI terminal equivalents, as produced | |
848 * by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any | |
849 * ANSI key with a value >= '\300' is nonstandard, but provided anyway | |
850 * so that the user can have access to all SHIFT-, CTRL-, and ALT- | |
851 * combinations of function/arrow/etc keys. | |
852 */ | |
853 | |
297 | 854 static const struct |
7 | 855 { |
856 WORD wVirtKey; | |
857 BOOL fAnsiKey; | |
858 int chAlone; | |
859 int chShift; | |
860 int chCtrl; | |
861 int chAlt; | |
862 } VirtKeyMap[] = | |
863 { | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
864 // Key ANSI alone shift ctrl alt |
7 | 865 { VK_ESCAPE,FALSE, ESC, ESC, ESC, ESC, }, |
866 | |
867 { VK_F1, TRUE, ';', 'T', '^', 'h', }, | |
868 { VK_F2, TRUE, '<', 'U', '_', 'i', }, | |
869 { VK_F3, TRUE, '=', 'V', '`', 'j', }, | |
870 { VK_F4, TRUE, '>', 'W', 'a', 'k', }, | |
871 { VK_F5, TRUE, '?', 'X', 'b', 'l', }, | |
872 { VK_F6, TRUE, '@', 'Y', 'c', 'm', }, | |
873 { VK_F7, TRUE, 'A', 'Z', 'd', 'n', }, | |
874 { VK_F8, TRUE, 'B', '[', 'e', 'o', }, | |
875 { VK_F9, TRUE, 'C', '\\', 'f', 'p', }, | |
876 { VK_F10, TRUE, 'D', ']', 'g', 'q', }, | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
877 { VK_F11, TRUE, '\205', '\207', '\211', '\213', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
878 { VK_F12, TRUE, '\206', '\210', '\212', '\214', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
879 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
880 { VK_HOME, TRUE, 'G', '\302', 'w', '\303', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
881 { VK_UP, TRUE, 'H', '\304', '\305', '\306', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
882 { VK_PRIOR, TRUE, 'I', '\307', '\204', '\310', }, // PgUp |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
883 { VK_LEFT, TRUE, 'K', '\311', 's', '\312', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
884 { VK_RIGHT, TRUE, 'M', '\313', 't', '\314', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
885 { VK_END, TRUE, 'O', '\315', 'u', '\316', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
886 { VK_DOWN, TRUE, 'P', '\317', '\320', '\321', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
887 { VK_NEXT, TRUE, 'Q', '\322', 'v', '\323', }, // PgDn |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
888 { VK_INSERT,TRUE, 'R', '\324', '\325', '\326', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
889 { VK_DELETE,TRUE, 'S', '\327', '\330', '\331', }, |
16182
bed0d7200635
patch 8.1.1096: MS-Windows: cannot distinguish BS and CTRL-H
Bram Moolenaar <Bram@vim.org>
parents:
16180
diff
changeset
|
890 { VK_BACK, TRUE, 'x', 'y', 'z', '{', }, // Backspace |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
891 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
892 { VK_SNAPSHOT,TRUE, 0, 0, 0, 'r', }, // PrtScrn |
7 | 893 |
894 #if 0 | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
895 // Most people don't have F13-F20, but what the hell... |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
896 { VK_F13, TRUE, '\332', '\333', '\334', '\335', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
897 { VK_F14, TRUE, '\336', '\337', '\340', '\341', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
898 { VK_F15, TRUE, '\342', '\343', '\344', '\345', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
899 { VK_F16, TRUE, '\346', '\347', '\350', '\351', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
900 { VK_F17, TRUE, '\352', '\353', '\354', '\355', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
901 { VK_F18, TRUE, '\356', '\357', '\360', '\361', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
902 { VK_F19, TRUE, '\362', '\363', '\364', '\365', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
903 { VK_F20, TRUE, '\366', '\367', '\370', '\371', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
904 #endif |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
905 { VK_ADD, TRUE, 'N', 'N', 'N', 'N', }, // keyp '+' |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
906 { VK_SUBTRACT, TRUE,'J', 'J', 'J', 'J', }, // keyp '-' |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
907 // { VK_DIVIDE, TRUE,'N', 'N', 'N', 'N', }, // keyp '/' |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
908 { VK_MULTIPLY, TRUE,'7', '7', '7', '7', }, // keyp '*' |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
909 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
910 { VK_NUMPAD0,TRUE, '\332', '\333', '\334', '\335', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
911 { VK_NUMPAD1,TRUE, '\336', '\337', '\340', '\341', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
912 { VK_NUMPAD2,TRUE, '\342', '\343', '\344', '\345', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
913 { VK_NUMPAD3,TRUE, '\346', '\347', '\350', '\351', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
914 { VK_NUMPAD4,TRUE, '\352', '\353', '\354', '\355', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
915 { VK_NUMPAD5,TRUE, '\356', '\357', '\360', '\361', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
916 { VK_NUMPAD6,TRUE, '\362', '\363', '\364', '\365', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
917 { VK_NUMPAD7,TRUE, '\366', '\367', '\370', '\371', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
918 { VK_NUMPAD8,TRUE, '\372', '\373', '\374', '\375', }, |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
919 // Sorry, out of number space! <negri> |
16182
bed0d7200635
patch 8.1.1096: MS-Windows: cannot distinguish BS and CTRL-H
Bram Moolenaar <Bram@vim.org>
parents:
16180
diff
changeset
|
920 { VK_NUMPAD9,TRUE, '\376', '\377', '|', '}', }, |
7 | 921 }; |
922 | |
923 | |
924 #ifdef _MSC_VER | |
925 // The ToAscii bug destroys several registers. Need to turn off optimization | |
926 // or the GetConsoleKeyboardLayoutName hack will fail in non-debug versions | |
797 | 927 # pragma warning(push) |
928 # pragma warning(disable: 4748) | |
7 | 929 # pragma optimize("", off) |
930 #endif | |
931 | |
932 #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
|
933 # define UChar UnicodeChar |
7 | 934 #else |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
935 # define UChar uChar.UnicodeChar |
7 | 936 #endif |
937 | |
938 /* The return code indicates key code size. */ | |
939 static int | |
940 win32_kbd_patch_key( | |
26 | 941 KEY_EVENT_RECORD *pker) |
7 | 942 { |
943 UINT uMods = pker->dwControlKeyState; | |
944 static int s_iIsDead = 0; | |
945 static WORD awAnsiCode[2]; | |
946 static BYTE abKeystate[256]; | |
947 | |
948 | |
949 if (s_iIsDead == 2) | |
950 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
951 pker->UChar = (WCHAR) awAnsiCode[1]; |
7 | 952 s_iIsDead = 0; |
953 return 1; | |
954 } | |
955 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
956 if (pker->UChar != 0) |
7 | 957 return 1; |
958 | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1752
diff
changeset
|
959 vim_memset(abKeystate, 0, sizeof (abKeystate)); |
7 | 960 |
961 /* Clear any pending dead keys */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
962 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); |
7 | 963 |
964 if (uMods & SHIFT_PRESSED) | |
965 abKeystate[VK_SHIFT] = 0x80; | |
966 if (uMods & CAPSLOCK_ON) | |
967 abKeystate[VK_CAPITAL] = 1; | |
968 | |
969 if ((uMods & ALT_GR) == ALT_GR) | |
970 { | |
971 abKeystate[VK_CONTROL] = abKeystate[VK_LCONTROL] = | |
972 abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80; | |
973 } | |
974 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
975 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
|
976 abKeystate, awAnsiCode, 2, 0); |
7 | 977 |
978 if (s_iIsDead > 0) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
979 pker->UChar = (WCHAR) awAnsiCode[0]; |
7 | 980 |
981 return s_iIsDead; | |
982 } | |
983 | |
984 #ifdef _MSC_VER | |
985 /* MUST switch optimization on again here, otherwise a call to | |
986 * decode_key_event() may crash (e.g. when hitting caps-lock) */ | |
987 # pragma optimize("", on) | |
797 | 988 # pragma warning(pop) |
7 | 989 |
990 # if (_MSC_VER < 1100) | |
991 /* MUST turn off global optimisation for this next function, or | |
992 * pressing ctrl-minus in insert mode crashes Vim when built with | |
993 * VC4.1. -- negri. */ | |
994 # pragma optimize("g", off) | |
995 # endif | |
996 #endif | |
997 | |
998 static BOOL g_fJustGotFocus = FALSE; | |
999 | |
1000 /* | |
1001 * Decode a KEY_EVENT into one or two keystrokes | |
1002 */ | |
1003 static BOOL | |
1004 decode_key_event( | |
1005 KEY_EVENT_RECORD *pker, | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1006 WCHAR *pch, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1007 WCHAR *pch2, |
7 | 1008 int *pmodifiers, |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
1009 BOOL fDoPost UNUSED) |
7 | 1010 { |
1011 int i; | |
1012 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL); | |
1013 | |
1014 *pch = *pch2 = NUL; | |
1015 g_fJustGotFocus = FALSE; | |
1016 | |
1017 /* ignore key up events */ | |
1018 if (!pker->bKeyDown) | |
1019 return FALSE; | |
1020 | |
1021 /* ignore some keystrokes */ | |
1022 switch (pker->wVirtualKeyCode) | |
1023 { | |
1024 /* modifiers */ | |
1025 case VK_SHIFT: | |
1026 case VK_CONTROL: | |
1027 case VK_MENU: /* Alt key */ | |
1028 return FALSE; | |
1029 | |
1030 default: | |
1031 break; | |
1032 } | |
1033 | |
1034 /* special cases */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1035 if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL) |
7 | 1036 { |
1037 /* Ctrl-6 is Ctrl-^ */ | |
1038 if (pker->wVirtualKeyCode == '6') | |
1039 { | |
1040 *pch = Ctrl_HAT; | |
1041 return TRUE; | |
1042 } | |
1043 /* Ctrl-2 is Ctrl-@ */ | |
1044 else if (pker->wVirtualKeyCode == '2') | |
1045 { | |
1046 *pch = NUL; | |
1047 return TRUE; | |
1048 } | |
1049 /* Ctrl-- is Ctrl-_ */ | |
1050 else if (pker->wVirtualKeyCode == 0xBD) | |
1051 { | |
1052 *pch = Ctrl__; | |
1053 return TRUE; | |
1054 } | |
1055 } | |
1056 | |
1057 /* Shift-TAB */ | |
1058 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) | |
1059 { | |
1060 *pch = K_NUL; | |
1061 *pch2 = '\017'; | |
1062 return TRUE; | |
1063 } | |
1064 | |
1065 for (i = sizeof(VirtKeyMap) / sizeof(VirtKeyMap[0]); --i >= 0; ) | |
1066 { | |
1067 if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode) | |
1068 { | |
1069 if (nModifs == 0) | |
1070 *pch = VirtKeyMap[i].chAlone; | |
1071 else if ((nModifs & SHIFT) != 0 && (nModifs & ~SHIFT) == 0) | |
1072 *pch = VirtKeyMap[i].chShift; | |
1073 else if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0) | |
1074 *pch = VirtKeyMap[i].chCtrl; | |
1075 else if ((nModifs & ALT) != 0 && (nModifs & ~ALT) == 0) | |
1076 *pch = VirtKeyMap[i].chAlt; | |
1077 | |
1078 if (*pch != 0) | |
1079 { | |
1080 if (VirtKeyMap[i].fAnsiKey) | |
1081 { | |
1082 *pch2 = *pch; | |
1083 *pch = K_NUL; | |
1084 } | |
1085 | |
1086 return TRUE; | |
1087 } | |
1088 } | |
1089 } | |
1090 | |
1091 i = win32_kbd_patch_key(pker); | |
1092 | |
1093 if (i < 0) | |
1094 *pch = NUL; | |
1095 else | |
1096 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1097 *pch = (i > 0) ? pker->UChar : NUL; |
7 | 1098 |
1099 if (pmodifiers != NULL) | |
1100 { | |
1101 /* Pass on the ALT key as a modifier, but only when not combined | |
1102 * with CTRL (which is ALTGR). */ | |
1103 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) | |
1104 *pmodifiers |= MOD_MASK_ALT; | |
1105 | |
1106 /* Pass on SHIFT only for special keys, because we don't know when | |
1107 * it's already included with the character. */ | |
1108 if ((nModifs & SHIFT) != 0 && *pch <= 0x20) | |
1109 *pmodifiers |= MOD_MASK_SHIFT; | |
1110 | |
1111 /* Pass on CTRL only for non-special keys, because we don't know | |
1112 * when it's already included with the character. And not when | |
1113 * combined with ALT (which is ALTGR). */ | |
1114 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 | |
1115 && *pch >= 0x20 && *pch < 0x80) | |
1116 *pmodifiers |= MOD_MASK_CTRL; | |
1117 } | |
1118 } | |
1119 | |
1120 return (*pch != NUL); | |
1121 } | |
1122 | |
1123 #ifdef _MSC_VER | |
1124 # pragma optimize("", on) | |
1125 #endif | |
1126 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
1127 #endif /* FEAT_GUI_MSWIN */ |
7 | 1128 |
1129 | |
1130 #ifdef FEAT_MOUSE | |
1131 | |
1132 /* | |
1133 * For the GUI the mouse handling is in gui_w32.c. | |
1134 */ | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1135 # if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 1136 void |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
1137 mch_setmouse(int on UNUSED) |
7 | 1138 { |
1139 } | |
1140 # else | |
1141 static int g_fMouseAvail = FALSE; /* mouse present */ | |
1142 static int g_fMouseActive = FALSE; /* mouse enabled */ | |
1143 static int g_nMouseClick = -1; /* mouse status */ | |
1144 static int g_xMouse; /* mouse x coordinate */ | |
1145 static int g_yMouse; /* mouse y coordinate */ | |
1146 | |
1147 /* | |
1148 * Enable or disable mouse input | |
1149 */ | |
1150 void | |
26 | 1151 mch_setmouse(int on) |
7 | 1152 { |
1153 DWORD cmodein; | |
1154 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1155 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1156 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1157 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1158 # endif |
7 | 1159 if (!g_fMouseAvail) |
1160 return; | |
1161 | |
1162 g_fMouseActive = on; | |
1163 GetConsoleMode(g_hConIn, &cmodein); | |
1164 | |
1165 if (g_fMouseActive) | |
1166 cmodein |= ENABLE_MOUSE_INPUT; | |
1167 else | |
1168 cmodein &= ~ENABLE_MOUSE_INPUT; | |
1169 | |
1170 SetConsoleMode(g_hConIn, cmodein); | |
1171 } | |
1172 | |
13416
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1173 |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1174 #if defined(FEAT_BEVAL_TERM) || defined(PROTO) |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1175 /* |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1176 * Called when 'balloonevalterm' changed. |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1177 */ |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1178 void |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1179 mch_bevalterm_changed(void) |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1180 { |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1181 mch_setmouse(g_fMouseActive); |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1182 } |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1183 #endif |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1184 |
7 | 1185 /* |
1186 * Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT, | |
1187 * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse | |
1188 * move with a button held down; and MOUSE_RELEASE after a MOUSE_DRAG | |
1189 * or a MOUSE_LEFT, _MIDDLE, or _RIGHT. We encode the button type, | |
1190 * the number of clicks, and the Shift/Ctrl/Alt modifiers in g_nMouseClick, | |
1191 * and we return the mouse position in g_xMouse and g_yMouse. | |
1192 * | |
1193 * Every MOUSE_LEFT, _MIDDLE, or _RIGHT will be followed by zero or more | |
1194 * MOUSE_DRAGs and one MOUSE_RELEASE. MOUSE_RELEASE will be followed only | |
1195 * by MOUSE_LEFT, _MIDDLE, or _RIGHT. | |
1196 * | |
1197 * For multiple clicks, we send, say, MOUSE_LEFT/1 click, MOUSE_RELEASE, | |
1198 * MOUSE_LEFT/2 clicks, MOUSE_RELEASE, MOUSE_LEFT/3 clicks, MOUSE_RELEASE, .... | |
1199 * | |
1200 * Windows will send us MOUSE_MOVED notifications whenever the mouse | |
1201 * moves, even if it stays within the same character cell. We ignore | |
1202 * all MOUSE_MOVED messages if the position hasn't really changed, and | |
1203 * we ignore all MOUSE_MOVED messages where no button is held down (i.e., | |
1204 * we're only interested in MOUSE_DRAG). | |
1205 * | |
1206 * All of this is complicated by the code that fakes MOUSE_MIDDLE on | |
1207 * 2-button mouses by pressing the left & right buttons simultaneously. | |
1208 * In practice, it's almost impossible to click both at the same time, | |
1209 * so we need to delay a little. Also, we tend not to get MOUSE_RELEASE | |
1210 * in such cases, if the user is clicking quickly. | |
1211 */ | |
1212 static BOOL | |
1213 decode_mouse_event( | |
26 | 1214 MOUSE_EVENT_RECORD *pmer) |
7 | 1215 { |
1216 static int s_nOldButton = -1; | |
1217 static int s_nOldMouseClick = -1; | |
1218 static int s_xOldMouse = -1; | |
1219 static int s_yOldMouse = -1; | |
1220 static linenr_T s_old_topline = 0; | |
1221 #ifdef FEAT_DIFF | |
1222 static int s_old_topfill = 0; | |
1223 #endif | |
1224 static int s_cClicks = 1; | |
1225 static BOOL s_fReleased = TRUE; | |
1226 static DWORD s_dwLastClickTime = 0; | |
1227 static BOOL s_fNextIsMiddle = FALSE; | |
1228 | |
1229 static DWORD cButtons = 0; /* number of buttons supported */ | |
1230 | |
1231 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; | |
1232 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; | |
1233 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED; | |
1234 const DWORD LEFT_RIGHT = LEFT | RIGHT; | |
1235 | |
1236 int nButton; | |
1237 | |
1238 if (cButtons == 0 && !GetNumberOfConsoleMouseButtons(&cButtons)) | |
1239 cButtons = 2; | |
1240 | |
1241 if (!g_fMouseAvail || !g_fMouseActive) | |
1242 { | |
1243 g_nMouseClick = -1; | |
1244 return FALSE; | |
1245 } | |
1246 | |
1247 /* get a spurious MOUSE_EVENT immediately after receiving focus; ignore */ | |
1248 if (g_fJustGotFocus) | |
1249 { | |
1250 g_fJustGotFocus = FALSE; | |
1251 return FALSE; | |
1252 } | |
1253 | |
1254 /* unprocessed mouse click? */ | |
1255 if (g_nMouseClick != -1) | |
1256 return TRUE; | |
1257 | |
1258 nButton = -1; | |
1259 g_xMouse = pmer->dwMousePosition.X; | |
1260 g_yMouse = pmer->dwMousePosition.Y; | |
1261 | |
1262 if (pmer->dwEventFlags == MOUSE_MOVED) | |
1263 { | |
13416
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1264 /* Ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these |
7 | 1265 * events even when the mouse moves only within a char cell.) */ |
1266 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) | |
1267 return FALSE; | |
1268 } | |
1269 | |
1270 /* If no buttons are pressed... */ | |
1271 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) | |
1272 { | |
13416
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1273 nButton = MOUSE_RELEASE; |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1274 |
7 | 1275 /* If the last thing returned was MOUSE_RELEASE, ignore this */ |
1276 if (s_fReleased) | |
13416
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1277 { |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1278 #ifdef FEAT_BEVAL_TERM |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1279 /* do return mouse move events when we want them */ |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1280 if (p_bevalterm) |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1281 nButton = MOUSE_DRAG; |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1282 else |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1283 #endif |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1284 return FALSE; |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1285 } |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1286 |
7 | 1287 s_fReleased = TRUE; |
1288 } | |
1289 else /* one or more buttons pressed */ | |
1290 { | |
1291 /* on a 2-button mouse, hold down left and right buttons | |
1292 * simultaneously to get MIDDLE. */ | |
1293 | |
1294 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) | |
1295 { | |
1296 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); | |
1297 | |
1298 /* if either left or right button only is pressed, see if the | |
4352 | 1299 * next mouse event has both of them pressed */ |
7 | 1300 if (dwLR == LEFT || dwLR == RIGHT) |
1301 { | |
1302 for (;;) | |
1303 { | |
1304 /* wait a short time for next input event */ | |
1305 if (WaitForSingleObject(g_hConIn, p_mouset / 3) | |
1306 != WAIT_OBJECT_0) | |
1307 break; | |
1308 else | |
1309 { | |
1310 DWORD cRecords = 0; | |
1311 INPUT_RECORD ir; | |
1312 MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent; | |
1313 | |
5580 | 1314 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1315 |
1316 if (cRecords == 0 || ir.EventType != MOUSE_EVENT | |
1317 || !(pmer2->dwButtonState & LEFT_RIGHT)) | |
1318 break; | |
1319 else | |
1320 { | |
1321 if (pmer2->dwEventFlags != MOUSE_MOVED) | |
1322 { | |
5580 | 1323 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1324 |
1325 return decode_mouse_event(pmer2); | |
1326 } | |
1327 else if (s_xOldMouse == pmer2->dwMousePosition.X && | |
1328 s_yOldMouse == pmer2->dwMousePosition.Y) | |
1329 { | |
1330 /* throw away spurious mouse move */ | |
5580 | 1331 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1332 |
1333 /* are there any more mouse events in queue? */ | |
5580 | 1334 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1335 |
1336 if (cRecords==0 || ir.EventType != MOUSE_EVENT) | |
1337 break; | |
1338 } | |
1339 else | |
1340 break; | |
1341 } | |
1342 } | |
1343 } | |
1344 } | |
1345 } | |
1346 | |
1347 if (s_fNextIsMiddle) | |
1348 { | |
1349 nButton = (pmer->dwEventFlags == MOUSE_MOVED) | |
1350 ? MOUSE_DRAG : MOUSE_MIDDLE; | |
1351 s_fNextIsMiddle = FALSE; | |
1352 } | |
1353 else if (cButtons == 2 && | |
1354 ((pmer->dwButtonState & LEFT_RIGHT) == LEFT_RIGHT)) | |
1355 { | |
1356 nButton = MOUSE_MIDDLE; | |
1357 | |
1358 if (! s_fReleased && pmer->dwEventFlags != MOUSE_MOVED) | |
1359 { | |
1360 s_fNextIsMiddle = TRUE; | |
1361 nButton = MOUSE_RELEASE; | |
1362 } | |
1363 } | |
1364 else if ((pmer->dwButtonState & LEFT) == LEFT) | |
1365 nButton = MOUSE_LEFT; | |
1366 else if ((pmer->dwButtonState & MIDDLE) == MIDDLE) | |
1367 nButton = MOUSE_MIDDLE; | |
1368 else if ((pmer->dwButtonState & RIGHT) == RIGHT) | |
1369 nButton = MOUSE_RIGHT; | |
1370 | |
1371 if (! s_fReleased && ! s_fNextIsMiddle | |
1372 && nButton != s_nOldButton && s_nOldButton != MOUSE_DRAG) | |
1373 return FALSE; | |
1374 | |
1375 s_fReleased = s_fNextIsMiddle; | |
1376 } | |
1377 | |
1378 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) | |
1379 { | |
1380 /* button pressed or released, without mouse moving */ | |
1381 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1382 { | |
1383 DWORD dwCurrentTime = GetTickCount(); | |
1384 | |
1385 if (s_xOldMouse != g_xMouse | |
1386 || s_yOldMouse != g_yMouse | |
1387 || s_nOldButton != nButton | |
1388 || s_old_topline != curwin->w_topline | |
1389 #ifdef FEAT_DIFF | |
1390 || s_old_topfill != curwin->w_topfill | |
1391 #endif | |
1392 || (int)(dwCurrentTime - s_dwLastClickTime) > p_mouset) | |
1393 { | |
1394 s_cClicks = 1; | |
1395 } | |
1396 else if (++s_cClicks > 4) | |
1397 { | |
1398 s_cClicks = 1; | |
1399 } | |
1400 | |
1401 s_dwLastClickTime = dwCurrentTime; | |
1402 } | |
1403 } | |
1404 else if (pmer->dwEventFlags == MOUSE_MOVED) | |
1405 { | |
1406 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1407 nButton = MOUSE_DRAG; | |
1408 | |
1409 s_cClicks = 1; | |
1410 } | |
1411 | |
1412 if (nButton == -1) | |
1413 return FALSE; | |
1414 | |
1415 if (nButton != MOUSE_RELEASE) | |
1416 s_nOldButton = nButton; | |
1417 | |
1418 g_nMouseClick = nButton; | |
1419 | |
1420 if (pmer->dwControlKeyState & SHIFT_PRESSED) | |
1421 g_nMouseClick |= MOUSE_SHIFT; | |
1422 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) | |
1423 g_nMouseClick |= MOUSE_CTRL; | |
1424 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) | |
1425 g_nMouseClick |= MOUSE_ALT; | |
1426 | |
1427 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) | |
1428 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); | |
1429 | |
1430 /* only pass on interesting (i.e., different) mouse events */ | |
1431 if (s_xOldMouse == g_xMouse | |
1432 && s_yOldMouse == g_yMouse | |
1433 && s_nOldMouseClick == g_nMouseClick) | |
1434 { | |
1435 g_nMouseClick = -1; | |
1436 return FALSE; | |
1437 } | |
1438 | |
1439 s_xOldMouse = g_xMouse; | |
1440 s_yOldMouse = g_yMouse; | |
1441 s_old_topline = curwin->w_topline; | |
1442 #ifdef FEAT_DIFF | |
1443 s_old_topfill = curwin->w_topfill; | |
1444 #endif | |
1445 s_nOldMouseClick = g_nMouseClick; | |
1446 | |
1447 return TRUE; | |
1448 } | |
1449 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
1450 # endif /* FEAT_GUI_MSWIN */ |
7 | 1451 #endif /* FEAT_MOUSE */ |
1452 | |
1453 | |
1454 #ifdef MCH_CURSOR_SHAPE | |
1455 /* | |
1456 * Set the shape of the cursor. | |
1457 * 'thickness' can be from 1 (thin) to 99 (block) | |
1458 */ | |
1459 static void | |
1460 mch_set_cursor_shape(int thickness) | |
1461 { | |
1462 CONSOLE_CURSOR_INFO ConsoleCursorInfo; | |
1463 ConsoleCursorInfo.dwSize = thickness; | |
1464 ConsoleCursorInfo.bVisible = s_cursor_visible; | |
1465 | |
1466 SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo); | |
1467 if (s_cursor_visible) | |
1468 SetConsoleCursorPosition(g_hConOut, g_coord); | |
1469 } | |
1470 | |
1471 void | |
1472 mch_update_cursor(void) | |
1473 { | |
1474 int idx; | |
1475 int thickness; | |
1476 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1477 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1478 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1479 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1480 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1481 |
7 | 1482 /* |
1483 * How the cursor is drawn depends on the current mode. | |
1484 */ | |
1485 idx = get_shape_idx(FALSE); | |
1486 | |
1487 if (shape_table[idx].shape == SHAPE_BLOCK) | |
1488 thickness = 99; /* 100 doesn't work on W95 */ | |
1489 else | |
1490 thickness = shape_table[idx].percentage; | |
1491 mch_set_cursor_shape(thickness); | |
1492 } | |
1493 #endif | |
1494 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1495 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 1496 /* |
1497 * Handle FOCUS_EVENT. | |
1498 */ | |
1499 static void | |
1500 handle_focus_event(INPUT_RECORD ir) | |
1501 { | |
1502 g_fJustGotFocus = ir.Event.FocusEvent.bSetFocus; | |
1503 ui_focus_change((int)g_fJustGotFocus); | |
1504 } | |
1505 | |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1506 static void ResizeConBuf(HANDLE hConsole, COORD coordScreen); |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1507 |
7 | 1508 /* |
1509 * Wait until console input from keyboard or mouse is available, | |
1510 * or the time is up. | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1511 * When "ignore_input" is TRUE even wait when input is available. |
7 | 1512 * Return TRUE if something is available FALSE if not. |
1513 */ | |
1514 static int | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1515 WaitForChar(long msec, int ignore_input) |
7 | 1516 { |
1517 DWORD dwNow = 0, dwEndTime = 0; | |
1518 INPUT_RECORD ir; | |
1519 DWORD cRecords; | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1520 WCHAR ch, ch2; |
8949
c44ab784f5e5
commit https://github.com/vim/vim/commit/4445f7ee708f1a1304526a5979c9dd9883a92a0a
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
1521 #ifdef FEAT_TIMERS |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1522 int tb_change_cnt = typebuf.tb_change_cnt; |
8949
c44ab784f5e5
commit https://github.com/vim/vim/commit/4445f7ee708f1a1304526a5979c9dd9883a92a0a
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
1523 #endif |
7 | 1524 |
1525 if (msec > 0) | |
1526 /* Wait until the specified time has elapsed. */ | |
1527 dwEndTime = GetTickCount() + msec; | |
1528 else if (msec < 0) | |
1529 /* Wait forever. */ | |
1530 dwEndTime = INFINITE; | |
1531 | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
1532 // We need to loop until the end of the time period, because |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
1533 // we might get multiple unusable mouse events in that time. |
7 | 1534 for (;;) |
1535 { | |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1536 // Only process messages when waiting. |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1537 if (msec != 0) |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1538 { |
7866
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1539 #ifdef MESSAGE_QUEUE |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1540 parse_queued_messages(); |
7866
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1541 #endif |
14 | 1542 #ifdef FEAT_MZSCHEME |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1543 mzvim_check_threads(); |
14 | 1544 #endif |
7 | 1545 #ifdef FEAT_CLIENTSERVER |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1546 serverProcessPendingMessages(); |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1547 #endif |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1548 } |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1549 |
7 | 1550 if (0 |
1551 #ifdef FEAT_MOUSE | |
1552 || g_nMouseClick != -1 | |
1553 #endif | |
1554 #ifdef FEAT_CLIENTSERVER | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1555 || (!ignore_input && input_available()) |
7 | 1556 #endif |
1557 ) | |
1558 return TRUE; | |
1559 | |
1560 if (msec > 0) | |
1561 { | |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1562 /* 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
|
1563 * GetTickCount() may wrap around (overflow). */ |
7 | 1564 dwNow = GetTickCount(); |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1565 if ((int)(dwNow - dwEndTime) >= 0) |
7 | 1566 break; |
1567 } | |
1568 if (msec != 0) | |
1569 { | |
14 | 1570 DWORD dwWaitTime = dwEndTime - dwNow; |
1571 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
1572 #ifdef FEAT_JOB_CHANNEL |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1573 /* Check channel while waiting for input. */ |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1574 if (dwWaitTime > 100) |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1575 { |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1576 dwWaitTime = 100; |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1577 /* If there is readahead then parse_queued_messages() timed out |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1578 * and we should call it again soon. */ |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1579 if (channel_any_readahead()) |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1580 dwWaitTime = 10; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1581 } |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1582 #endif |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12724
diff
changeset
|
1583 #ifdef FEAT_BEVAL_GUI |
11014
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1584 if (p_beval && dwWaitTime > 100) |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1585 /* The 'balloonexpr' may indirectly invoke a callback while |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1586 * waiting for a character, need to check often. */ |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1587 dwWaitTime = 100; |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1588 #endif |
14 | 1589 #ifdef FEAT_MZSCHEME |
1590 if (mzthreads_allowed() && p_mzq > 0 | |
1591 && (msec < 0 || (long)dwWaitTime > p_mzq)) | |
1592 dwWaitTime = p_mzq; /* don't wait longer than 'mzquantum' */ | |
1593 #endif | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1594 #ifdef FEAT_TIMERS |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1595 // When waiting very briefly don't trigger timers. |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1596 if (dwWaitTime > 10) |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1597 { |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1598 long due_time; |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1599 |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1600 // Trigger timers and then get the time in msec until the next |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1601 // one is due. Wait up to that time. |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1602 due_time = check_due_timer(); |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1603 if (typebuf.tb_change_cnt != tb_change_cnt) |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1604 { |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1605 // timer may have used feedkeys(). |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1606 return FALSE; |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1607 } |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1608 if (due_time > 0 && dwWaitTime > (DWORD)due_time) |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1609 dwWaitTime = due_time; |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1610 } |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1611 #endif |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1612 if ( |
7 | 1613 #ifdef FEAT_CLIENTSERVER |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1614 // Wait for either an event on the console input or a |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1615 // message in the client-server window. |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1616 msg_wait_for_multiple_objects(1, &g_hConIn, FALSE, |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1617 dwWaitTime, QS_SENDMESSAGE) != WAIT_OBJECT_0 |
7 | 1618 #else |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1619 wait_for_single_object(g_hConIn, dwWaitTime) |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1620 != WAIT_OBJECT_0 |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1621 #endif |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1622 ) |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1623 continue; |
7 | 1624 } |
1625 | |
1626 cRecords = 0; | |
5580 | 1627 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1628 |
1629 #ifdef FEAT_MBYTE_IME | |
1630 if (State & CMDLINE && msg_row == Rows - 1) | |
1631 { | |
1632 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
1633 | |
1634 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
1635 { | |
1636 if (csbi.dwCursorPosition.Y != msg_row) | |
1637 { | |
1638 /* The screen is now messed up, must redraw the | |
1639 * command line and later all the windows. */ | |
1640 redraw_all_later(CLEAR); | |
1641 cmdline_row -= (msg_row - csbi.dwCursorPosition.Y); | |
1642 redrawcmd(); | |
1643 } | |
1644 } | |
1645 } | |
1646 #endif | |
1647 | |
1648 if (cRecords > 0) | |
1649 { | |
1650 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) | |
1651 { | |
1652 #ifdef FEAT_MBYTE_IME | |
1653 /* Windows IME sends two '\n's with only one 'ENTER'. First: | |
1654 * wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1655 if (ir.Event.KeyEvent.UChar == 0 |
7 | 1656 && ir.Event.KeyEvent.wVirtualKeyCode == 13) |
1657 { | |
5580 | 1658 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1659 continue; |
1660 } | |
1661 #endif | |
1662 if (decode_key_event(&ir.Event.KeyEvent, &ch, &ch2, | |
1663 NULL, FALSE)) | |
1664 return TRUE; | |
1665 } | |
1666 | |
5580 | 1667 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1668 |
1669 if (ir.EventType == FOCUS_EVENT) | |
1670 handle_focus_event(ir); | |
1671 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) | |
13260
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1672 { |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1673 COORD dwSize = ir.Event.WindowBufferSizeEvent.dwSize; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1674 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1675 // Only call shell_resized() when the size actually change to |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1676 // avoid the screen is cleard. |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1677 if (dwSize.X != Columns || dwSize.Y != Rows) |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1678 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1679 CONSOLE_SCREEN_BUFFER_INFO csbi; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1680 GetConsoleScreenBufferInfo(g_hConOut, &csbi); |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1681 dwSize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1682 ResizeConBuf(g_hConOut, dwSize); |
13260
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1683 shell_resized(); |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1684 } |
13260
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1685 } |
7 | 1686 #ifdef FEAT_MOUSE |
1687 else if (ir.EventType == MOUSE_EVENT | |
1688 && decode_mouse_event(&ir.Event.MouseEvent)) | |
1689 return TRUE; | |
1690 #endif | |
1691 } | |
1692 else if (msec == 0) | |
1693 break; | |
1694 } | |
1695 | |
1696 #ifdef FEAT_CLIENTSERVER | |
1697 /* Something might have been received while we were waiting. */ | |
1698 if (input_available()) | |
1699 return TRUE; | |
1700 #endif | |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1701 |
7 | 1702 return FALSE; |
1703 } | |
1704 | |
1705 /* | |
1706 * return non-zero if a character is available | |
1707 */ | |
1708 int | |
26 | 1709 mch_char_avail(void) |
7 | 1710 { |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1711 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1712 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1713 return TRUE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1714 # endif |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1715 return WaitForChar(0L, FALSE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1716 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1717 |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1718 # if defined(FEAT_TERMINAL) || defined(PROTO) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1719 /* |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1720 * Check for any pending input or messages. |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1721 */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1722 int |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1723 mch_check_messages(void) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1724 { |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1725 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1726 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1727 return TRUE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1728 # endif |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1729 return WaitForChar(0L, TRUE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1730 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1731 # endif |
7 | 1732 |
1733 /* | |
1734 * Create the console input. Used when reading stdin doesn't work. | |
1735 */ | |
1736 static void | |
1737 create_conin(void) | |
1738 { | |
1739 g_hConIn = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE, | |
1740 FILE_SHARE_READ|FILE_SHARE_WRITE, | |
1741 (LPSECURITY_ATTRIBUTES) NULL, | |
840 | 1742 OPEN_EXISTING, 0, (HANDLE)NULL); |
7 | 1743 did_create_conin = TRUE; |
1744 } | |
1745 | |
1746 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1747 * Get a keystroke or a mouse event, use a blocking wait. |
7 | 1748 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1749 static WCHAR |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1750 tgetch(int *pmodifiers, WCHAR *pch2) |
7 | 1751 { |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1752 WCHAR ch; |
7 | 1753 |
1754 for (;;) | |
1755 { | |
1756 INPUT_RECORD ir; | |
1757 DWORD cRecords = 0; | |
1758 | |
1759 #ifdef FEAT_CLIENTSERVER | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1760 (void)WaitForChar(-1L, FALSE); |
7 | 1761 if (input_available()) |
1762 return 0; | |
1763 # ifdef FEAT_MOUSE | |
1764 if (g_nMouseClick != -1) | |
1765 return 0; | |
1766 # endif | |
1767 #endif | |
5580 | 1768 if (read_console_input(g_hConIn, &ir, 1, &cRecords) == 0) |
7 | 1769 { |
1770 if (did_create_conin) | |
1771 read_error_exit(); | |
1772 create_conin(); | |
1773 continue; | |
1774 } | |
1775 | |
1776 if (ir.EventType == KEY_EVENT) | |
1777 { | |
1778 if (decode_key_event(&ir.Event.KeyEvent, &ch, pch2, | |
1779 pmodifiers, TRUE)) | |
1780 return ch; | |
1781 } | |
1782 else if (ir.EventType == FOCUS_EVENT) | |
1783 handle_focus_event(ir); | |
1784 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) | |
1785 shell_resized(); | |
1786 #ifdef FEAT_MOUSE | |
1787 else if (ir.EventType == MOUSE_EVENT) | |
1788 { | |
1789 if (decode_mouse_event(&ir.Event.MouseEvent)) | |
1790 return 0; | |
1791 } | |
1792 #endif | |
1793 } | |
1794 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
1795 #endif /* !FEAT_GUI_MSWIN */ |
7 | 1796 |
1797 | |
1798 /* | |
3622 | 1799 * mch_inchar(): low-level input function. |
7 | 1800 * Get one or more characters from the keyboard or the mouse. |
1801 * If time == 0, do not wait for characters. | |
1802 * If time == n, wait a short time for characters. | |
1803 * If time == -1, wait forever for characters. | |
1804 * Returns the number of characters read into buf. | |
1805 */ | |
1806 int | |
1807 mch_inchar( | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
1808 char_u *buf UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
1809 int maxlen UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
1810 long time UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
1811 int tb_change_cnt UNUSED) |
7 | 1812 { |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1813 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 1814 |
1815 int len; | |
1816 int c; | |
1817 #define TYPEAHEADLEN 20 | |
1818 static char_u typeahead[TYPEAHEADLEN]; /* previously typed bytes. */ | |
1819 static int typeaheadlen = 0; | |
1820 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1821 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1822 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1823 return 0; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1824 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1825 |
7 | 1826 /* First use any typeahead that was kept because "buf" was too small. */ |
1827 if (typeaheadlen > 0) | |
1828 goto theend; | |
1829 | |
1830 if (time >= 0) | |
1831 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1832 if (!WaitForChar(time, FALSE)) /* no character available */ |
7 | 1833 return 0; |
1834 } | |
1835 else /* time == -1, wait forever */ | |
1836 { | |
1837 mch_set_winsize_now(); /* Allow winsize changes from now on */ | |
1838 | |
203 | 1839 /* |
1840 * If there is no character available within 2 seconds (default) | |
1841 * write the autoscript file to disk. Or cause the CursorHold event | |
1842 * to be triggered. | |
1843 */ | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1844 if (!WaitForChar(p_ut, FALSE)) |
7 | 1845 { |
609 | 1846 if (trigger_cursorhold() && maxlen >= 3) |
7 | 1847 { |
203 | 1848 buf[0] = K_SPECIAL; |
1849 buf[1] = KS_EXTRA; | |
1850 buf[2] = (int)KE_CURSORHOLD; | |
1851 return 3; | |
7 | 1852 } |
368 | 1853 before_blocking(); |
7 | 1854 } |
1855 } | |
1856 | |
1857 /* | |
1858 * Try to read as many characters as there are, until the buffer is full. | |
1859 */ | |
1860 | |
1861 /* we will get at least one key. Get more if they are available. */ | |
1862 g_fCBrkPressed = FALSE; | |
1863 | |
1864 #ifdef MCH_WRITE_DUMP | |
1865 if (fdDump) | |
1866 fputc('[', fdDump); | |
1867 #endif | |
1868 | |
1869 /* Keep looping until there is something in the typeahead buffer and more | |
1870 * to get and still room in the buffer (up to two bytes for a char and | |
1871 * three bytes for a modifier). */ | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1872 while ((typeaheadlen == 0 || WaitForChar(0L, FALSE)) |
7 | 1873 && typeaheadlen + 5 <= TYPEAHEADLEN) |
1874 { | |
1875 if (typebuf_changed(tb_change_cnt)) | |
1876 { | |
1877 /* "buf" may be invalid now if a client put something in the | |
1878 * typeahead buffer and "buf" is in the typeahead buffer. */ | |
1879 typeaheadlen = 0; | |
1880 break; | |
1881 } | |
1882 #ifdef FEAT_MOUSE | |
1883 if (g_nMouseClick != -1) | |
1884 { | |
1885 # ifdef MCH_WRITE_DUMP | |
1886 if (fdDump) | |
1887 fprintf(fdDump, "{%02x @ %d, %d}", | |
1888 g_nMouseClick, g_xMouse, g_yMouse); | |
1889 # endif | |
1890 typeahead[typeaheadlen++] = ESC + 128; | |
1891 typeahead[typeaheadlen++] = 'M'; | |
1892 typeahead[typeaheadlen++] = g_nMouseClick; | |
1893 typeahead[typeaheadlen++] = g_xMouse + '!'; | |
1894 typeahead[typeaheadlen++] = g_yMouse + '!'; | |
1895 g_nMouseClick = -1; | |
1896 } | |
1897 else | |
1898 #endif | |
1899 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1900 WCHAR ch2 = NUL; |
7 | 1901 int modifiers = 0; |
1902 | |
1903 c = tgetch(&modifiers, &ch2); | |
1904 | |
1905 if (typebuf_changed(tb_change_cnt)) | |
1906 { | |
1907 /* "buf" may be invalid now if a client put something in the | |
1908 * typeahead buffer and "buf" is in the typeahead buffer. */ | |
1909 typeaheadlen = 0; | |
1910 break; | |
1911 } | |
1912 | |
1913 if (c == Ctrl_C && ctrl_c_interrupts) | |
1914 { | |
1915 #if defined(FEAT_CLIENTSERVER) | |
1916 trash_input_buf(); | |
1917 #endif | |
1918 got_int = TRUE; | |
1919 } | |
1920 | |
1921 #ifdef FEAT_MOUSE | |
1922 if (g_nMouseClick == -1) | |
1923 #endif | |
1924 { | |
1925 int n = 1; | |
6047 | 1926 |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1927 if (ch2 == NUL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1928 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1929 int i; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1930 char_u *p; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1931 WCHAR ch[2]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1932 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1933 ch[0] = c; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1934 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
|
1935 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1936 ch[1] = tgetch(&modifiers, &ch2); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1937 n++; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1938 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1939 p = utf16_to_enc(ch, &n); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1940 if (p != NULL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1941 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1942 for (i = 0; i < n; i++) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1943 typeahead[typeaheadlen + i] = p[i]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1944 vim_free(p); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1945 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1946 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1947 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1948 typeahead[typeaheadlen] = c; |
7 | 1949 if (ch2 != NUL) |
1950 { | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1951 if (c == K_NUL) |
12990
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1952 { |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1953 switch (ch2) |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1954 { |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1955 case (WCHAR)'\324': // SHIFT+Insert |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1956 case (WCHAR)'\325': // CTRL+Insert |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1957 case (WCHAR)'\327': // SHIFT+Delete |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1958 case (WCHAR)'\330': // CTRL+Delete |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1959 typeahead[typeaheadlen + n] = (char_u)ch2; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1960 n++; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1961 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1962 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1963 default: |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1964 typeahead[typeaheadlen + n] = 3; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1965 typeahead[typeaheadlen + n + 1] = (char_u)ch2; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1966 n += 2; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1967 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1968 } |
12990
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1969 } |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1970 else |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1971 { |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1972 typeahead[typeaheadlen + n] = 3; |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1973 typeahead[typeaheadlen + n + 1] = (char_u)ch2; |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1974 n += 2; |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1975 } |
6047 | 1976 } |
1977 | |
7 | 1978 /* Use the ALT key to set the 8th bit of the character |
1979 * when it's one byte, the 8th bit isn't set yet and not | |
1980 * using a double-byte encoding (would become a lead | |
1981 * byte). */ | |
1982 if ((modifiers & MOD_MASK_ALT) | |
1983 && n == 1 | |
1984 && (typeahead[typeaheadlen] & 0x80) == 0 | |
1985 && !enc_dbcs | |
1986 ) | |
1987 { | |
1443 | 1988 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80, |
1989 typeahead + typeaheadlen); | |
7 | 1990 modifiers &= ~MOD_MASK_ALT; |
1991 } | |
1992 | |
1993 if (modifiers != 0) | |
1994 { | |
1995 /* Prepend modifiers to the character. */ | |
1996 mch_memmove(typeahead + typeaheadlen + 3, | |
1997 typeahead + typeaheadlen, n); | |
1998 typeahead[typeaheadlen++] = K_SPECIAL; | |
1999 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER; | |
2000 typeahead[typeaheadlen++] = modifiers; | |
2001 } | |
2002 | |
2003 typeaheadlen += n; | |
2004 | |
2005 #ifdef MCH_WRITE_DUMP | |
2006 if (fdDump) | |
2007 fputc(c, fdDump); | |
2008 #endif | |
2009 } | |
2010 } | |
2011 } | |
2012 | |
2013 #ifdef MCH_WRITE_DUMP | |
2014 if (fdDump) | |
2015 { | |
2016 fputs("]\n", fdDump); | |
2017 fflush(fdDump); | |
2018 } | |
2019 #endif | |
2020 | |
2021 theend: | |
2022 /* Move typeahead to "buf", as much as fits. */ | |
2023 len = 0; | |
2024 while (len < maxlen && typeaheadlen > 0) | |
2025 { | |
2026 buf[len++] = typeahead[0]; | |
2027 mch_memmove(typeahead, typeahead + 1, --typeaheadlen); | |
2028 } | |
2029 return len; | |
2030 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
2031 #else /* FEAT_GUI_MSWIN */ |
7 | 2032 return 0; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
2033 #endif /* FEAT_GUI_MSWIN */ |
7 | 2034 } |
2035 | |
3927 | 2036 #ifndef PROTO |
2037 # ifndef __MINGW32__ | |
2038 # include <shellapi.h> /* required for FindExecutable() */ | |
2039 # endif | |
7 | 2040 #endif |
2041 | |
9 | 2042 /* |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2043 * If "use_path" is TRUE: Return TRUE if "name" is in $PATH. |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2044 * If "use_path" is FALSE: Return TRUE if "name" exists. |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2045 * When returning TRUE and "path" is not NULL save the path and set "*path" to |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2046 * the allocated memory. |
10 | 2047 * TODO: Should somehow check if it's really executable. |
9 | 2048 */ |
7 | 2049 static int |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2050 executable_exists(char *name, char_u **path, int use_path) |
7 | 2051 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2052 WCHAR *p; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2053 WCHAR fnamew[_MAX_PATH]; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2054 WCHAR *dumw; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2055 WCHAR *wcurpath, *wnewpath; |
6185 | 2056 long n; |
9 | 2057 |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2058 if (!use_path) |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2059 { |
11071
cc22b177dfe8
patch 8.0.0424: compiler warnings on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11060
diff
changeset
|
2060 if (mch_getperm((char_u *)name) != -1 && !mch_isdir((char_u *)name)) |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2061 { |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2062 if (path != NULL) |
11060
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2063 { |
11071
cc22b177dfe8
patch 8.0.0424: compiler warnings on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11060
diff
changeset
|
2064 if (mch_isFullName((char_u *)name)) |
11060
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2065 *path = vim_strsave((char_u *)name); |
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2066 else |
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2067 *path = FullName_save((char_u *)name, FALSE); |
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2068 } |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2069 return TRUE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2070 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2071 return FALSE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2072 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2073 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2074 p = enc_to_utf16((char_u *)name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2075 if (p == NULL) |
6185 | 2076 return FALSE; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2077 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2078 wcurpath = _wgetenv(L"PATH"); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2079 wnewpath = ALLOC_MULT(WCHAR, wcslen(wcurpath) + 3); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2080 if (wnewpath == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2081 return FALSE; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2082 wcscpy(wnewpath, L".;"); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2083 wcscat(wnewpath, wcurpath); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2084 n = (long)SearchPathW(wnewpath, p, NULL, _MAX_PATH, fnamew, &dumw); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2085 vim_free(wnewpath); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2086 vim_free(p); |
6185 | 2087 if (n == 0) |
9 | 2088 return FALSE; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2089 if (GetFileAttributesW(fnamew) & FILE_ATTRIBUTE_DIRECTORY) |
9 | 2090 return FALSE; |
5782 | 2091 if (path != NULL) |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2092 *path = utf16_to_enc(fnamew, NULL); |
9 | 2093 return TRUE; |
7 | 2094 } |
2095 | |
15955
907481b9260f
patch 8.1.0983: checking __CYGWIN32__ unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2096 #if (defined(__MINGW32__) && __MSVCRT_VERSION__ >= 0x800) || \ |
907481b9260f
patch 8.1.0983: checking __CYGWIN32__ unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2097 (defined(_MSC_VER) && _MSC_VER >= 1400) |
2584 | 2098 /* |
2099 * Bad parameter handler. | |
2100 * | |
2101 * Certain MS CRT functions will intentionally crash when passed invalid | |
2102 * parameters to highlight possible security holes. Setting this function as | |
2103 * the bad parameter handler will prevent the crash. | |
2104 * | |
2105 * In debug builds the parameters contain CRT information that might help track | |
2106 * down the source of a problem, but in non-debug builds the arguments are all | |
2107 * NULL/0. Debug builds will also produce assert dialogs from the CRT, it is | |
2108 * worth allowing these to make debugging of issues easier. | |
2109 */ | |
2110 static void | |
2111 bad_param_handler(const wchar_t *expression, | |
2112 const wchar_t *function, | |
2113 const wchar_t *file, | |
2114 unsigned int line, | |
2115 uintptr_t pReserved) | |
2116 { | |
2117 } | |
2118 | |
2119 # define SET_INVALID_PARAM_HANDLER \ | |
2120 ((void)_set_invalid_parameter_handler(bad_param_handler)) | |
2121 #else | |
2122 # define SET_INVALID_PARAM_HANDLER | |
2123 #endif | |
2124 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
2125 #ifdef FEAT_GUI_MSWIN |
7 | 2126 |
2127 /* | |
2128 * GUI version of mch_init(). | |
2129 */ | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2130 static void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2131 mch_init_g(void) |
7 | 2132 { |
2133 #ifndef __MINGW32__ | |
2134 extern int _fmode; | |
2135 #endif | |
2136 | |
2584 | 2137 /* Silently handle invalid parameters to CRT functions */ |
2138 SET_INVALID_PARAM_HANDLER; | |
2139 | |
7 | 2140 /* Let critical errors result in a failure, not in a dialog box. Required |
2141 * for the timestamp test to work on removed floppies. */ | |
2142 SetErrorMode(SEM_FAILCRITICALERRORS); | |
2143 | |
2144 _fmode = O_BINARY; /* we do our own CR-LF translation */ | |
2145 | |
2146 /* Specify window size. Is there a place to get the default from? */ | |
2147 Rows = 25; | |
2148 Columns = 80; | |
2149 | |
2150 /* Look for 'vimrun' */ | |
2151 { | |
2152 char_u vimrun_location[_MAX_PATH + 4]; | |
2153 | |
2154 /* First try in same directory as gvim.exe */ | |
2155 STRCPY(vimrun_location, exe_name); | |
2156 STRCPY(gettail(vimrun_location), "vimrun.exe"); | |
2157 if (mch_getperm(vimrun_location) >= 0) | |
2158 { | |
2159 if (*skiptowhite(vimrun_location) != NUL) | |
2160 { | |
2161 /* Enclose path with white space in double quotes. */ | |
2162 mch_memmove(vimrun_location + 1, vimrun_location, | |
2163 STRLEN(vimrun_location) + 1); | |
2164 *vimrun_location = '"'; | |
2165 STRCPY(gettail(vimrun_location), "vimrun\" "); | |
2166 } | |
2167 else | |
2168 STRCPY(gettail(vimrun_location), "vimrun "); | |
2169 | |
2170 vimrun_path = (char *)vim_strsave(vimrun_location); | |
2171 s_dont_use_vimrun = FALSE; | |
2172 } | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2173 else if (executable_exists("vimrun.exe", NULL, TRUE)) |
7 | 2174 s_dont_use_vimrun = FALSE; |
2175 | |
2176 /* Don't give the warning for a missing vimrun.exe right now, but only | |
2177 * when vimrun was supposed to be used. Don't bother people that do | |
2178 * not need vimrun.exe. */ | |
2179 if (s_dont_use_vimrun) | |
2180 need_vimrun_warning = TRUE; | |
2181 } | |
2182 | |
2183 /* | |
2184 * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'. | |
2185 * Otherwise the default "findstr /n" is used. | |
2186 */ | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2187 if (!executable_exists("findstr.exe", NULL, TRUE)) |
7 | 2188 set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0); |
2189 | |
2190 #ifdef FEAT_CLIPBOARD | |
4168 | 2191 win_clip_init(); |
7 | 2192 #endif |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
2193 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
2194 vtp_flag_init(); |
7 | 2195 } |
2196 | |
2197 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2198 #endif /* FEAT_GUI_MSWIN */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2199 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2200 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 2201 |
2202 #define SRWIDTH(sr) ((sr).Right - (sr).Left + 1) | |
2203 #define SRHEIGHT(sr) ((sr).Bottom - (sr).Top + 1) | |
2204 | |
2205 /* | |
2206 * ClearConsoleBuffer() | |
2207 * Description: | |
2208 * Clears the entire contents of the console screen buffer, using the | |
2209 * specified attribute. | |
2210 * Returns: | |
2211 * TRUE on success | |
2212 */ | |
2213 static BOOL | |
2214 ClearConsoleBuffer(WORD wAttribute) | |
2215 { | |
2216 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2217 COORD coord; | |
2218 DWORD NumCells, dummy; | |
2219 | |
2220 if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2221 return FALSE; | |
2222 | |
2223 NumCells = csbi.dwSize.X * csbi.dwSize.Y; | |
2224 coord.X = 0; | |
2225 coord.Y = 0; | |
2226 if (!FillConsoleOutputCharacter(g_hConOut, ' ', NumCells, | |
2227 coord, &dummy)) | |
2228 return FALSE; | |
2229 if (!FillConsoleOutputAttribute(g_hConOut, wAttribute, NumCells, | |
2230 coord, &dummy)) | |
2231 return FALSE; | |
2232 | |
2233 return TRUE; | |
2234 } | |
2235 | |
2236 /* | |
2237 * FitConsoleWindow() | |
2238 * Description: | |
2239 * Checks if the console window will fit within given buffer dimensions. | |
2240 * Also, if requested, will shrink the window to fit. | |
2241 * Returns: | |
2242 * TRUE on success | |
2243 */ | |
2244 static BOOL | |
2245 FitConsoleWindow( | |
2246 COORD dwBufferSize, | |
2247 BOOL WantAdjust) | |
2248 { | |
2249 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2250 COORD dwWindowSize; | |
2251 BOOL NeedAdjust = FALSE; | |
2252 | |
2253 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2254 { | |
2255 /* | |
2256 * A buffer resize will fail if the current console window does | |
2257 * not lie completely within that buffer. To avoid this, we might | |
2258 * have to move and possibly shrink the window. | |
2259 */ | |
2260 if (csbi.srWindow.Right >= dwBufferSize.X) | |
2261 { | |
2262 dwWindowSize.X = SRWIDTH(csbi.srWindow); | |
2263 if (dwWindowSize.X > dwBufferSize.X) | |
2264 dwWindowSize.X = dwBufferSize.X; | |
2265 csbi.srWindow.Right = dwBufferSize.X - 1; | |
2266 csbi.srWindow.Left = dwBufferSize.X - dwWindowSize.X; | |
2267 NeedAdjust = TRUE; | |
2268 } | |
2269 if (csbi.srWindow.Bottom >= dwBufferSize.Y) | |
2270 { | |
2271 dwWindowSize.Y = SRHEIGHT(csbi.srWindow); | |
2272 if (dwWindowSize.Y > dwBufferSize.Y) | |
2273 dwWindowSize.Y = dwBufferSize.Y; | |
2274 csbi.srWindow.Bottom = dwBufferSize.Y - 1; | |
2275 csbi.srWindow.Top = dwBufferSize.Y - dwWindowSize.Y; | |
2276 NeedAdjust = TRUE; | |
2277 } | |
2278 if (NeedAdjust && WantAdjust) | |
2279 { | |
2280 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &csbi.srWindow)) | |
2281 return FALSE; | |
2282 } | |
2283 return TRUE; | |
2284 } | |
2285 | |
2286 return FALSE; | |
2287 } | |
2288 | |
2289 typedef struct ConsoleBufferStruct | |
2290 { | |
26 | 2291 BOOL IsValid; |
2292 CONSOLE_SCREEN_BUFFER_INFO Info; | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2293 PCHAR_INFO Buffer; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2294 COORD BufferSize; |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2295 PSMALL_RECT Regions; |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2296 int NumRegions; |
7 | 2297 } ConsoleBuffer; |
2298 | |
2299 /* | |
2300 * SaveConsoleBuffer() | |
2301 * Description: | |
2302 * Saves important information about the console buffer, including the | |
2303 * actual buffer contents. The saved information is suitable for later | |
2304 * restoration by RestoreConsoleBuffer(). | |
2305 * Returns: | |
2306 * TRUE if all information was saved; FALSE otherwise | |
2307 * If FALSE, still sets cb->IsValid if buffer characteristics were saved. | |
2308 */ | |
2309 static BOOL | |
2310 SaveConsoleBuffer( | |
2311 ConsoleBuffer *cb) | |
2312 { | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2313 DWORD NumCells; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2314 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2315 SMALL_RECT ReadRegion; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2316 WORD Y, Y_incr; |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2317 int i, numregions; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2318 |
7 | 2319 if (cb == NULL) |
2320 return FALSE; | |
2321 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2322 if (!GetConsoleScreenBufferInfo(g_hConOut, &cb->Info)) |
7 | 2323 { |
2324 cb->IsValid = FALSE; | |
2325 return FALSE; | |
2326 } | |
2327 cb->IsValid = TRUE; | |
2328 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2329 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2330 * 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
|
2331 * 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
|
2332 * 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
|
2333 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2334 if (!cb->IsValid || cb->Buffer == NULL || |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2335 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
|
2336 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
|
2337 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2338 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
|
2339 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
|
2340 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
|
2341 vim_free(cb->Buffer); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2342 cb->Buffer = ALLOC_MULT(CHAR_INFO, NumCells); |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2343 if (cb->Buffer == NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2344 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2345 } |
7 | 2346 |
2347 /* | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2348 * 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
|
2349 * 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
|
2350 * 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
|
2351 * 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
|
2352 * 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
|
2353 * 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
|
2354 * height of each chunk will be (12000 / width). |
7 | 2355 */ |
7078
383d6f39669b
commit https://github.com/vim/vim/commit/615942452eb74eee7d8386fd3d76a1534181fa06
Christian Brabandt <cb@256bit.org>
parents:
6981
diff
changeset
|
2356 BufferCoord.X = 0; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2357 ReadRegion.Left = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2358 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
|
2359 Y_incr = 12000 / cb->Info.dwSize.X; |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2360 |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2361 numregions = (cb->Info.dwSize.Y + Y_incr - 1) / Y_incr; |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2362 if (cb->Regions == NULL || numregions != cb->NumRegions) |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2363 { |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2364 cb->NumRegions = numregions; |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2365 vim_free(cb->Regions); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2366 cb->Regions = ALLOC_MULT(SMALL_RECT, cb->NumRegions); |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2367 if (cb->Regions == NULL) |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2368 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2369 VIM_CLEAR(cb->Buffer); |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2370 return FALSE; |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2371 } |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2372 } |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2373 |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2374 for (i = 0, Y = 0; i < cb->NumRegions; i++, Y += Y_incr) |
7 | 2375 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2376 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2377 * 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
|
2378 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2379 BufferCoord.Y = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2380 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2381 * 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
|
2382 * 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
|
2383 * 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
|
2384 * 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
|
2385 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2386 ReadRegion.Top = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2387 ReadRegion.Bottom = Y + Y_incr - 1; |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2388 if (!ReadConsoleOutputW(g_hConOut, /* output handle */ |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2389 cb->Buffer, /* our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2390 cb->BufferSize, /* dimensions of our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2391 BufferCoord, /* offset in our buffer */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2392 &ReadRegion)) /* region to save */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2393 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2394 VIM_CLEAR(cb->Buffer); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2395 VIM_CLEAR(cb->Regions); |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2396 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2397 } |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2398 cb->Regions[i] = ReadRegion; |
7 | 2399 } |
2400 | |
2401 return TRUE; | |
2402 } | |
2403 | |
2404 /* | |
2405 * RestoreConsoleBuffer() | |
2406 * Description: | |
2407 * Restores important information about the console buffer, including the | |
2408 * actual buffer contents, if desired. The information to restore is in | |
2409 * the same format used by SaveConsoleBuffer(). | |
2410 * Returns: | |
2411 * TRUE on success | |
2412 */ | |
2413 static BOOL | |
2414 RestoreConsoleBuffer( | |
26 | 2415 ConsoleBuffer *cb, |
2416 BOOL RestoreScreen) | |
7 | 2417 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2418 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2419 SMALL_RECT WriteRegion; |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2420 int i; |
7 | 2421 |
2422 if (cb == NULL || !cb->IsValid) | |
2423 return FALSE; | |
2424 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2425 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2426 * 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
|
2427 * 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
|
2428 * 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
|
2429 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2430 if (RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2431 ClearConsoleBuffer(cb->Info.wAttributes); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2432 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2433 FitConsoleWindow(cb->Info.dwSize, TRUE); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2434 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
|
2435 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2436 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
|
2437 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2438 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2439 if (!RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2440 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2441 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2442 * 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
|
2443 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2444 return TRUE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2445 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2446 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2447 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
|
2448 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2449 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
|
2450 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2451 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2452 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2453 * Restore the screen buffer contents. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2454 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2455 if (cb->Buffer != NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2456 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2457 for (i = 0; i < cb->NumRegions; i++) |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2458 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2459 BufferCoord.X = cb->Regions[i].Left; |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2460 BufferCoord.Y = cb->Regions[i].Top; |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2461 WriteRegion = cb->Regions[i]; |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2462 if (!WriteConsoleOutputW(g_hConOut, /* output handle */ |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2463 cb->Buffer, /* our buffer */ |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2464 cb->BufferSize, /* dimensions of our buffer */ |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2465 BufferCoord, /* offset in our buffer */ |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2466 &WriteRegion)) /* region to restore */ |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2467 return FALSE; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2468 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2469 } |
7 | 2470 |
2471 return TRUE; | |
2472 } | |
2473 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2474 #define FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2475 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2476 static ConsoleBuffer g_cbOrig = { 0 }; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2477 #endif |
7 | 2478 static ConsoleBuffer g_cbNonTermcap = { 0 }; |
2479 static ConsoleBuffer g_cbTermcap = { 0 }; | |
2480 | |
2481 #ifdef FEAT_TITLE | |
2482 char g_szOrigTitle[256] = { 0 }; | |
2483 HWND g_hWnd = NULL; /* also used in os_mswin.c */ | |
2484 static HICON g_hOrigIconSmall = NULL; | |
2485 static HICON g_hOrigIcon = NULL; | |
2486 static HICON g_hVimIcon = NULL; | |
2487 static BOOL g_fCanChangeIcon = FALSE; | |
2488 | |
2489 /* ICON* are not defined in VC++ 4.0 */ | |
2490 #ifndef ICON_SMALL | |
2491 #define ICON_SMALL 0 | |
2492 #endif | |
2493 #ifndef ICON_BIG | |
2494 #define ICON_BIG 1 | |
2495 #endif | |
2496 /* | |
2497 * GetConsoleIcon() | |
2498 * Description: | |
2499 * Attempts to retrieve the small icon and/or the big icon currently in | |
2500 * use by a given window. | |
2501 * Returns: | |
2502 * TRUE on success | |
2503 */ | |
2504 static BOOL | |
2505 GetConsoleIcon( | |
26 | 2506 HWND hWnd, |
2507 HICON *phIconSmall, | |
2508 HICON *phIcon) | |
7 | 2509 { |
2510 if (hWnd == NULL) | |
2511 return FALSE; | |
2512 | |
2513 if (phIconSmall != NULL) | |
26 | 2514 *phIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, |
2515 (WPARAM)ICON_SMALL, (LPARAM)0); | |
7 | 2516 if (phIcon != NULL) |
26 | 2517 *phIcon = (HICON)SendMessage(hWnd, WM_GETICON, |
2518 (WPARAM)ICON_BIG, (LPARAM)0); | |
7 | 2519 return TRUE; |
2520 } | |
2521 | |
2522 /* | |
2523 * SetConsoleIcon() | |
2524 * Description: | |
2525 * Attempts to change the small icon and/or the big icon currently in | |
2526 * use by a given window. | |
2527 * Returns: | |
2528 * TRUE on success | |
2529 */ | |
2530 static BOOL | |
2531 SetConsoleIcon( | |
26 | 2532 HWND hWnd, |
2533 HICON hIconSmall, | |
2534 HICON hIcon) | |
7 | 2535 { |
2536 if (hWnd == NULL) | |
2537 return FALSE; | |
2538 | |
2539 if (hIconSmall != NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2540 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2541 (WPARAM)ICON_SMALL, (LPARAM)hIconSmall); |
7 | 2542 if (hIcon != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2543 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2544 (WPARAM)ICON_BIG, (LPARAM) hIcon); |
7 | 2545 return TRUE; |
2546 } | |
2547 | |
2548 /* | |
2549 * SaveConsoleTitleAndIcon() | |
2550 * Description: | |
2551 * Saves the current console window title in g_szOrigTitle, for later | |
2552 * restoration. Also, attempts to obtain a handle to the console window, | |
2553 * and use it to save the small and big icons currently in use by the | |
2554 * console window. This is not always possible on some versions of Windows; | |
2555 * nor is it possible when running Vim remotely using Telnet (since the | |
2556 * console window the user sees is owned by a remote process). | |
2557 */ | |
2558 static void | |
2559 SaveConsoleTitleAndIcon(void) | |
2560 { | |
2561 /* Save the original title. */ | |
2562 if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle))) | |
2563 return; | |
2564 | |
2565 /* | |
2566 * Obtain a handle to the console window using GetConsoleWindow() from | |
2567 * KERNEL32.DLL; we need to handle in order to change the window icon. | |
2568 * This function only exists on NT-based Windows, starting with Windows | |
2569 * 2000. On older operating systems, we can't change the window icon | |
2570 * anyway. | |
2571 */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2572 g_hWnd = GetConsoleWindow(); |
7 | 2573 if (g_hWnd == NULL) |
2574 return; | |
2575 | |
2576 /* Save the original console window icon. */ | |
2577 GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon); | |
2578 if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL) | |
2579 return; | |
2580 | |
2581 /* Extract the first icon contained in the Vim executable. */ | |
6249 | 2582 if (mch_icon_load((HANDLE *)&g_hVimIcon) == FAIL || g_hVimIcon == NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2583 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); |
7 | 2584 if (g_hVimIcon != NULL) |
2585 g_fCanChangeIcon = TRUE; | |
2586 } | |
2587 #endif | |
2588 | |
2589 static int g_fWindInitCalled = FALSE; | |
2590 static int g_fTermcapMode = FALSE; | |
2591 static CONSOLE_CURSOR_INFO g_cci; | |
2592 static DWORD g_cmodein = 0; | |
2593 static DWORD g_cmodeout = 0; | |
2594 | |
2595 /* | |
2596 * non-GUI version of mch_init(). | |
2597 */ | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2598 static void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2599 mch_init_c(void) |
7 | 2600 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2601 #ifndef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2602 CONSOLE_SCREEN_BUFFER_INFO csbi; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2603 #endif |
7 | 2604 #ifndef __MINGW32__ |
2605 extern int _fmode; | |
2606 #endif | |
2607 | |
2584 | 2608 /* Silently handle invalid parameters to CRT functions */ |
2609 SET_INVALID_PARAM_HANDLER; | |
2610 | |
7 | 2611 /* Let critical errors result in a failure, not in a dialog box. Required |
2612 * for the timestamp test to work on removed floppies. */ | |
2613 SetErrorMode(SEM_FAILCRITICALERRORS); | |
2614 | |
2615 _fmode = O_BINARY; /* we do our own CR-LF translation */ | |
2616 out_flush(); | |
2617 | |
2618 /* Obtain handles for the standard Console I/O devices */ | |
2619 if (read_cmd_fd == 0) | |
2620 g_hConIn = GetStdHandle(STD_INPUT_HANDLE); | |
2621 else | |
2622 create_conin(); | |
2623 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
|
2624 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2625 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2626 /* 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
|
2627 SaveConsoleBuffer(&g_cbOrig); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2628 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
|
2629 #else |
7 | 2630 /* Get current text attributes */ |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2631 GetConsoleScreenBufferInfo(g_hConOut, &csbi); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2632 g_attrCurrent = g_attrDefault = csbi.wAttributes; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2633 #endif |
7 | 2634 if (cterm_normal_fg_color == 0) |
2635 cterm_normal_fg_color = (g_attrCurrent & 0xf) + 1; | |
2636 if (cterm_normal_bg_color == 0) | |
2637 cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1; | |
2638 | |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
2639 // Fg and Bg color index number at startup |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
2640 g_color_index_fg = g_attrDefault & 0xf; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
2641 g_color_index_bg = (g_attrDefault >> 4) & 0xf; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
2642 |
7 | 2643 /* set termcap codes to current text attributes */ |
2644 update_tcap(g_attrCurrent); | |
2645 | |
2646 GetConsoleCursorInfo(g_hConOut, &g_cci); | |
2647 GetConsoleMode(g_hConIn, &g_cmodein); | |
2648 GetConsoleMode(g_hConOut, &g_cmodeout); | |
2649 | |
2650 #ifdef FEAT_TITLE | |
2651 SaveConsoleTitleAndIcon(); | |
2652 /* | |
2653 * Set both the small and big icons of the console window to Vim's icon. | |
2654 * Note that Vim presently only has one size of icon (32x32), but it | |
2655 * automatically gets scaled down to 16x16 when setting the small icon. | |
2656 */ | |
2657 if (g_fCanChangeIcon) | |
2658 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); | |
2659 #endif | |
2660 | |
2661 ui_get_shellsize(); | |
2662 | |
2663 #ifdef MCH_WRITE_DUMP | |
2664 fdDump = fopen("dump", "wt"); | |
2665 | |
2666 if (fdDump) | |
2667 { | |
2668 time_t t; | |
2669 | |
2670 time(&t); | |
2671 fputs(ctime(&t), fdDump); | |
2672 fflush(fdDump); | |
2673 } | |
2674 #endif | |
2675 | |
2676 g_fWindInitCalled = TRUE; | |
2677 | |
2678 #ifdef FEAT_MOUSE | |
2679 g_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); | |
2680 #endif | |
2681 | |
2682 #ifdef FEAT_CLIPBOARD | |
4168 | 2683 win_clip_init(); |
7 | 2684 #endif |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2685 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
2686 vtp_flag_init(); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2687 vtp_init(); |
7 | 2688 } |
2689 | |
2690 /* | |
2691 * non-GUI version of mch_exit(). | |
2692 * Shut down and exit with status `r' | |
2693 * Careful: mch_exit() may be called before mch_init()! | |
2694 */ | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2695 static void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2696 mch_exit_c(int r) |
7 | 2697 { |
10835
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
2698 exiting = TRUE; |
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
2699 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2700 vtp_exit(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2701 |
7 | 2702 stoptermcap(); |
2703 if (g_fWindInitCalled) | |
2704 settmode(TMODE_COOK); | |
2705 | |
2706 ml_close_all(TRUE); /* remove all memfiles */ | |
2707 | |
2708 if (g_fWindInitCalled) | |
2709 { | |
2710 #ifdef FEAT_TITLE | |
14479
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14473
diff
changeset
|
2711 mch_restore_title(SAVE_RESTORE_BOTH); |
7 | 2712 /* |
2713 * Restore both the small and big icons of the console window to | |
2714 * what they were at startup. Don't do this when the window is | |
2715 * closed, Vim would hang here. | |
2716 */ | |
2717 if (g_fCanChangeIcon && !g_fForceExit) | |
2718 SetConsoleIcon(g_hWnd, g_hOrigIconSmall, g_hOrigIcon); | |
2719 #endif | |
2720 | |
2721 #ifdef MCH_WRITE_DUMP | |
2722 if (fdDump) | |
2723 { | |
2724 time_t t; | |
2725 | |
2726 time(&t); | |
2727 fputs(ctime(&t), fdDump); | |
2728 fclose(fdDump); | |
2729 } | |
2730 fdDump = NULL; | |
2731 #endif | |
2732 } | |
2733 | |
2734 SetConsoleCursorInfo(g_hConOut, &g_cci); | |
2735 SetConsoleMode(g_hConIn, g_cmodein); | |
2736 SetConsoleMode(g_hConOut, g_cmodeout); | |
2737 | |
2738 #ifdef DYNAMIC_GETTEXT | |
2739 dyn_libintl_end(); | |
2740 #endif | |
2741 | |
2742 exit(r); | |
2743 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
2744 #endif /* !FEAT_GUI_MSWIN */ |
7 | 2745 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2746 void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2747 mch_init(void) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2748 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2749 #ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2750 if (gui.starting) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2751 mch_init_g(); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2752 else |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2753 mch_init_c(); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2754 #elif defined(FEAT_GUI_MSWIN) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2755 mch_init_g(); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2756 #else |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2757 mch_init_c(); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2758 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2759 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2760 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2761 void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2762 mch_exit(int r) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2763 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2764 #ifdef VIMDLL |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2765 if (gui.in_use || gui.starting) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2766 mch_exit_g(r); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2767 else |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2768 mch_exit_c(r); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2769 #elif defined(FEAT_GUI_MSWIN) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2770 mch_exit_g(r); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2771 #else |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2772 mch_exit_c(r); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2773 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2774 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2775 |
7 | 2776 /* |
2777 * Do we have an interactive window? | |
2778 */ | |
2779 int | |
2780 mch_check_win( | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
2781 int argc UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
2782 char **argv UNUSED) |
7 | 2783 { |
2784 get_exe_name(); | |
2785 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2786 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 2787 return OK; /* GUI always has a tty */ |
2788 #else | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2789 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2790 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2791 return OK; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2792 # endif |
7 | 2793 if (isatty(1)) |
2794 return OK; | |
2795 return FAIL; | |
2796 #endif | |
2797 } | |
2798 | |
5326 | 2799 /* |
16156
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2800 * Set the case of the file name, if it already exists. |
7 | 2801 * When "len" is > 0, also expand short to long filenames. |
2802 */ | |
2803 void | |
2804 fname_case( | |
2805 char_u *name, | |
2806 int len) | |
2807 { | |
16156
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2808 int flen; |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2809 WCHAR *p; |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2810 WCHAR buf[_MAX_PATH + 1]; |
7 | 2811 |
434 | 2812 flen = (int)STRLEN(name); |
5326 | 2813 if (flen == 0) |
7 | 2814 return; |
2815 | |
2816 slash_adjust(name); | |
2817 | |
16156
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2818 p = enc_to_utf16(name, NULL); |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2819 if (p == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2820 return; |
16156
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2821 |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2822 if (GetLongPathNameW(p, buf, _MAX_PATH)) |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2823 { |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2824 char_u *q = utf16_to_enc(buf, NULL); |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2825 |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2826 if (q != NULL) |
7 | 2827 { |
16156
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2828 if (len > 0 || flen >= (int)STRLEN(q)) |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2829 vim_strncpy(name, q, (len > 0) ? len - 1 : flen); |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2830 vim_free(q); |
7 | 2831 } |
16156
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2832 } |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2833 vim_free(p); |
7 | 2834 } |
2835 | |
2836 | |
2837 /* | |
2838 * Insert user name in s[len]. | |
2839 */ | |
2840 int | |
2841 mch_get_user_name( | |
26 | 2842 char_u *s, |
2843 int len) | |
7 | 2844 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2845 WCHAR wszUserName[256 + 1]; /* UNLEN is 256 */ |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2846 DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2847 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2848 if (GetUserNameW(wszUserName, &wcch)) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2849 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2850 char_u *p = utf16_to_enc(wszUserName, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2851 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2852 if (p != NULL) |
5549 | 2853 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2854 vim_strncpy(s, p, len - 1); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2855 vim_free(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2856 return OK; |
5549 | 2857 } |
2858 } | |
7 | 2859 s[0] = NUL; |
2860 return FAIL; | |
2861 } | |
2862 | |
2863 | |
2864 /* | |
2865 * Insert host name in s[len]. | |
2866 */ | |
2867 void | |
2868 mch_get_host_name( | |
2869 char_u *s, | |
2870 int len) | |
2871 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2872 WCHAR wszHostName[256 + 1]; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2873 DWORD wcch = sizeof(wszHostName) / sizeof(WCHAR); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2874 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2875 if (GetComputerNameW(wszHostName, &wcch)) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2876 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2877 char_u *p = utf16_to_enc(wszHostName, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2878 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2879 if (p != NULL) |
5551 | 2880 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2881 vim_strncpy(s, p, len - 1); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2882 vim_free(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2883 return; |
5551 | 2884 } |
2885 } | |
7 | 2886 } |
2887 | |
2888 | |
2889 /* | |
2890 * return process ID | |
2891 */ | |
2892 long | |
26 | 2893 mch_get_pid(void) |
7 | 2894 { |
2895 return (long)GetCurrentProcessId(); | |
2896 } | |
2897 | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2898 /* |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2899 * return TRUE if process "pid" is still running |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2900 */ |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2901 int |
16455
1ae13586edf8
patch 8.1.1232: can't build on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
2902 mch_process_running(long pid) |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2903 { |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2904 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, (DWORD)pid); |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2905 DWORD status = 0; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2906 int ret = FALSE; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2907 |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2908 if (hProcess == NULL) |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2909 return FALSE; // might not have access |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2910 if (GetExitCodeProcess(hProcess, &status) ) |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2911 ret = status == STILL_ACTIVE; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2912 CloseHandle(hProcess); |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2913 return ret; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2914 } |
7 | 2915 |
2916 /* | |
2917 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
2918 * Return OK for success, FAIL for failure. | |
2919 */ | |
2920 int | |
2921 mch_dirname( | |
2922 char_u *buf, | |
2923 int len) | |
2924 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2925 WCHAR wbuf[_MAX_PATH + 1]; |
14561
3ea4a48213e6
patch 8.1.0294: MS-Windows: sometimes uses short directory name
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
2926 |
7 | 2927 /* |
2928 * Originally this was: | |
2929 * return (getcwd(buf, len) != NULL ? OK : FAIL); | |
2930 * But the Win32s known bug list says that getcwd() doesn't work | |
2931 * so use the Win32 system call instead. <Negri> | |
2932 */ | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2933 if (GetCurrentDirectoryW(_MAX_PATH, wbuf) != 0) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2934 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2935 WCHAR wcbuf[_MAX_PATH + 1]; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2936 char_u *p = NULL; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2937 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2938 if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0) |
7 | 2939 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2940 p = utf16_to_enc(wcbuf, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2941 if (STRLEN(p) >= (size_t)len) |
14567
7267c0d910fe
patch 8.1.0297: MS-Windows: tests fail, Vim crashes
Christian Brabandt <cb@256bit.org>
parents:
14561
diff
changeset
|
2942 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2943 // long path name is too long, fall back to short one |
7 | 2944 vim_free(p); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2945 p = NULL; |
7 | 2946 } |
2947 } | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2948 if (p == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2949 p = utf16_to_enc(wbuf, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2950 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2951 if (p != NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2952 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2953 vim_strncpy(buf, p, len - 1); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2954 vim_free(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2955 return OK; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2956 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2957 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2958 return FAIL; |
7 | 2959 } |
2960 | |
2961 /* | |
5494 | 2962 * Get file permissions for "name". |
2963 * Return mode_t or -1 for error. | |
7 | 2964 */ |
2965 long | |
26 | 2966 mch_getperm(char_u *name) |
7 | 2967 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8949
diff
changeset
|
2968 stat_T st; |
5494 | 2969 int n; |
2970 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2971 n = mch_stat((char *)name, &st); |
5588 | 2972 return n == 0 ? (long)(unsigned short)st.st_mode : -1L; |
7 | 2973 } |
2974 | |
2975 | |
2976 /* | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2977 * Set file permission for "name" to "perm". |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2978 * |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2979 * Return FAIL for failure, OK otherwise. |
7 | 2980 */ |
2981 int | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2982 mch_setperm(char_u *name, long perm) |
7 | 2983 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2984 long n; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2985 WCHAR *p; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2986 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2987 p = enc_to_utf16(name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2988 if (p == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2989 return FAIL; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2990 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2991 n = _wchmod(p, perm); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2992 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2993 if (n == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2994 return FAIL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2995 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2996 win32_set_archive(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2997 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2998 return OK; |
7 | 2999 } |
3000 | |
3001 /* | |
3002 * Set hidden flag for "name". | |
3003 */ | |
3004 void | |
3005 mch_hide(char_u *name) | |
3006 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3007 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3008 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3009 return; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3010 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3011 attrs |= FILE_ATTRIBUTE_HIDDEN; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3012 win32_setattrs(name, attrs); |
7 | 3013 } |
3014 | |
3015 /* | |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3016 * 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
|
3017 */ |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3018 int |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3019 mch_ishidden(char_u *name) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3020 { |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3021 int f = win32_getattrs(name); |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3022 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3023 if (f == -1) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3024 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
|
3025 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3026 return (f & FILE_ATTRIBUTE_HIDDEN) != 0; |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3027 } |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3028 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3029 /* |
7 | 3030 * return TRUE if "name" is a directory |
3031 * return FALSE if "name" is not a directory or upon error | |
3032 */ | |
3033 int | |
3034 mch_isdir(char_u *name) | |
3035 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3036 int f = win32_getattrs(name); |
7 | 3037 |
3038 if (f == -1) | |
3039 return FALSE; /* file does not exist at all */ | |
3040 | |
3041 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; | |
3042 } | |
3043 | |
3044 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3045 * 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
|
3046 * 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
|
3047 * return FALSE for error |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3048 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3049 int |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3050 mch_isrealdir(char_u *name) |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3051 { |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3052 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
|
3053 } |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3054 |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3055 /* |
2803 | 3056 * Create directory "name". |
3057 * Return 0 on success, -1 on error. | |
3058 */ | |
3059 int | |
3060 mch_mkdir(char_u *name) | |
3061 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3062 WCHAR *p; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3063 int retval; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3064 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3065 p = enc_to_utf16(name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3066 if (p == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3067 return -1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3068 retval = _wmkdir(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3069 vim_free(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3070 return retval; |
2803 | 3071 } |
3072 | |
3073 /* | |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3074 * Delete directory "name". |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3075 * 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
|
3076 */ |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3077 int |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3078 mch_rmdir(char_u *name) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3079 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3080 WCHAR *p; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3081 int retval; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3082 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3083 p = enc_to_utf16(name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3084 if (p == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3085 return -1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3086 retval = _wrmdir(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3087 vim_free(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3088 return retval; |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3089 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3090 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3091 /* |
696 | 3092 * Return TRUE if file "fname" has more than one link. |
3093 */ | |
3094 int | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3095 mch_is_hard_link(char_u *fname) |
696 | 3096 { |
2793 | 3097 BY_HANDLE_FILE_INFORMATION info; |
3098 | |
3099 return win32_fileinfo(fname, &info) == FILEINFO_OK | |
3100 && info.nNumberOfLinks > 1; | |
3101 } | |
3102 | |
3103 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3104 * 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
|
3105 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3106 int |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3107 mch_is_symbolic_link(char_u *name) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3108 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3109 HANDLE hFind; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3110 int res = FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3111 DWORD fileFlags = 0, reparseTag = 0; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3112 WCHAR *wn; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3113 WIN32_FIND_DATAW findDataW; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3114 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3115 wn = enc_to_utf16(name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3116 if (wn == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3117 return FALSE; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3118 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3119 hFind = FindFirstFileW(wn, &findDataW); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3120 vim_free(wn); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3121 if (hFind != INVALID_HANDLE_VALUE) |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3122 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3123 fileFlags = findDataW.dwFileAttributes; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3124 reparseTag = findDataW.dwReserved0; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3125 FindClose(hFind); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3126 } |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3127 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3128 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
|
3129 && (reparseTag == IO_REPARSE_TAG_SYMLINK |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3130 || reparseTag == IO_REPARSE_TAG_MOUNT_POINT)) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3131 res = TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3132 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3133 return res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3134 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3135 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3136 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3137 * 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
|
3138 * link. |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3139 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3140 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3141 mch_is_linked(char_u *fname) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3142 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3143 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
|
3144 return TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3145 return FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3146 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3147 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3148 /* |
2793 | 3149 * Get the by-handle-file-information for "fname". |
3150 * Returns FILEINFO_OK when OK. | |
3151 * returns FILEINFO_ENC_FAIL when enc_to_utf16() failed. | |
3152 * Returns FILEINFO_READ_FAIL when CreateFile() failed. | |
3153 * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed. | |
3154 */ | |
3155 int | |
3156 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info) | |
3157 { | |
696 | 3158 HANDLE hFile; |
2793 | 3159 int res = FILEINFO_READ_FAIL; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3160 WCHAR *wn; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3161 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3162 wn = enc_to_utf16(fname, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3163 if (wn == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3164 return FILEINFO_ENC_FAIL; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3165 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3166 hFile = CreateFileW(wn, // file name |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3167 GENERIC_READ, // access mode |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3168 FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3169 NULL, // security descriptor |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3170 OPEN_EXISTING, // creation disposition |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3171 FILE_FLAG_BACKUP_SEMANTICS, // file attributes |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3172 NULL); // handle to template file |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3173 vim_free(wn); |
696 | 3174 |
3175 if (hFile != INVALID_HANDLE_VALUE) | |
3176 { | |
2793 | 3177 if (GetFileInformationByHandle(hFile, info) != 0) |
3178 res = FILEINFO_OK; | |
3179 else | |
3180 res = FILEINFO_INFO_FAIL; | |
696 | 3181 CloseHandle(hFile); |
3182 } | |
3183 | |
3184 return res; | |
3185 } | |
3186 | |
3187 /* | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3188 * get file attributes for `name' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3189 * -1 : error |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3190 * else FILE_ATTRIBUTE_* defined in winnt.h |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3191 */ |
5494 | 3192 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3193 win32_getattrs(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3194 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3195 int attr; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3196 WCHAR *p; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3197 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3198 p = enc_to_utf16(name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3199 if (p == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3200 return INVALID_FILE_ATTRIBUTES; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3201 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3202 attr = GetFileAttributesW(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3203 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3204 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3205 return attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3206 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3207 |
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 * set file attributes for `name' to `attrs' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3210 * |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3211 * return -1 for failure, 0 otherwise |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3212 */ |
14862
27b9a84395b5
patch 8.1.0443: unnecessary static function prototypes
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
3213 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3214 win32_setattrs(char_u *name, int attrs) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3215 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3216 int res; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3217 WCHAR *p; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3218 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3219 p = enc_to_utf16(name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3220 if (p == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3221 return -1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3222 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3223 res = SetFileAttributesW(p, attrs); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3224 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3225 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3226 return res ? 0 : -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3227 } |
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 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3230 * Set archive flag for "name". |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3231 */ |
14862
27b9a84395b5
patch 8.1.0443: unnecessary static function prototypes
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
3232 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3233 win32_set_archive(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3234 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3235 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3236 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3237 return -1; |
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 attrs |= FILE_ATTRIBUTE_ARCHIVE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3240 return win32_setattrs(name, attrs); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3241 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3242 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3243 /* |
7 | 3244 * Return TRUE if file or directory "name" is writable (not readonly). |
3245 * Strange semantics of Win32: a readonly directory is writable, but you can't | |
3246 * delete a file. Let's say this means it is writable. | |
3247 */ | |
3248 int | |
3249 mch_writable(char_u *name) | |
3250 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3251 int attrs = win32_getattrs(name); |
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 return (attrs != -1 && (!(attrs & FILE_ATTRIBUTE_READONLY) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3254 || (attrs & FILE_ATTRIBUTE_DIRECTORY))); |
7 | 3255 } |
3256 | |
3257 /* | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3258 * Return TRUE if "name" can be executed, FALSE if not. |
6700 | 3259 * If "use_path" is FALSE only check if "name" is executable. |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3260 * When returning TRUE and "path" is not NULL save the path and set "*path" to |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3261 * the allocated memory. |
7 | 3262 */ |
3263 int | |
6700 | 3264 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3265 { |
16180
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3266 // WinNT and later can use _MAX_PATH wide characters for a pathname, which |
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3267 // means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is |
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3268 // UTF-8. |
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3269 char_u buf[_MAX_PATH * 3]; |
835 | 3270 int len = (int)STRLEN(name); |
14883
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3271 char_u *p, *saved; |
10 | 3272 |
16180
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3273 if (len >= sizeof(buf)) // safety check |
10 | 3274 return FALSE; |
3275 | |
16180
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3276 // Try using the name directly when a Unix-shell like 'shell'. |
14883
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3277 if (strstr((char *)gettail(p_sh), "sh") != NULL) |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3278 if (executable_exists((char *)name, path, use_path)) |
10 | 3279 return TRUE; |
3280 | |
3281 /* | |
3282 * Loop over all extensions in $PATHEXT. | |
3283 */ | |
14883
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3284 p = mch_getenv("PATHEXT"); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3285 if (p == NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3286 p = (char_u *)".com;.exe;.bat;.cmd"; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3287 saved = vim_strsave(p); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3288 if (saved == NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3289 return FALSE; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3290 p = saved; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3291 while (*p) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3292 { |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3293 char_u *tmp = vim_strchr(p, ';'); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3294 |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3295 if (tmp != NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3296 *tmp = NUL; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3297 if (_stricoll((char *)name + len - STRLEN(p), (char *)p) == 0 |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3298 && executable_exists((char *)name, path, use_path)) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3299 { |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3300 vim_free(saved); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3301 return TRUE; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3302 } |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3303 if (tmp == NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3304 break; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3305 p = tmp + 1; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3306 } |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3307 vim_free(saved); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3308 |
16180
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3309 vim_strncpy(buf, name, sizeof(buf) - 1); |
10 | 3310 p = mch_getenv("PATHEXT"); |
3311 if (p == NULL) | |
3312 p = (char_u *)".com;.exe;.bat;.cmd"; | |
3313 while (*p) | |
3314 { | |
3315 if (p[0] == '.' && (p[1] == NUL || p[1] == ';')) | |
3316 { | |
3317 /* A single "." means no extension is added. */ | |
3318 buf[len] = NUL; | |
3319 ++p; | |
3320 if (*p) | |
3321 ++p; | |
3322 } | |
3323 else | |
16180
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3324 copy_option_part(&p, buf + len, sizeof(buf) - len, ";"); |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3325 if (executable_exists((char *)buf, path, use_path)) |
10 | 3326 return TRUE; |
3327 } | |
3328 return FALSE; | |
7 | 3329 } |
3330 | |
3331 /* | |
3332 * Check what "name" is: | |
3333 * NODE_NORMAL: file or directory (or doesn't exist) | |
3334 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3335 * NODE_OTHER: non-writable things | |
3336 */ | |
3337 int | |
3338 mch_nodetype(char_u *name) | |
3339 { | |
3340 HANDLE hFile; | |
3341 int type; | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3342 WCHAR *wn; |
7 | 3343 |
1004 | 3344 /* We can't open a file with a name "\\.\con" or "\\.\prn" and trying to |
3345 * read from it later will cause Vim to hang. Thus return NODE_WRITABLE | |
3346 * here. */ | |
3347 if (STRNCMP(name, "\\\\.\\", 4) == 0) | |
3348 return NODE_WRITABLE; | |
3349 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3350 wn = enc_to_utf16(name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3351 if (wn == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3352 return NODE_NORMAL; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3353 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3354 hFile = CreateFileW(wn, // file name |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3355 GENERIC_WRITE, // access mode |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3356 0, // share mode |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3357 NULL, // security descriptor |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3358 OPEN_EXISTING, // creation disposition |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3359 0, // file attributes |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3360 NULL); // handle to template file |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3361 vim_free(wn); |
7 | 3362 if (hFile == INVALID_HANDLE_VALUE) |
3363 return NODE_NORMAL; | |
3364 | |
3365 type = GetFileType(hFile); | |
3366 CloseHandle(hFile); | |
3367 if (type == FILE_TYPE_CHAR) | |
3368 return NODE_WRITABLE; | |
3369 if (type == FILE_TYPE_DISK) | |
3370 return NODE_NORMAL; | |
3371 return NODE_OTHER; | |
3372 } | |
3373 | |
3374 #ifdef HAVE_ACL | |
3375 struct my_acl | |
3376 { | |
3377 PSECURITY_DESCRIPTOR pSecurityDescriptor; | |
3378 PSID pSidOwner; | |
3379 PSID pSidGroup; | |
3380 PACL pDacl; | |
3381 PACL pSacl; | |
3382 }; | |
3383 #endif | |
3384 | |
3385 /* | |
3386 * Return a pointer to the ACL of file "fname" in allocated memory. | |
3387 * Return NULL if the ACL is not available for whatever reason. | |
3388 */ | |
3389 vim_acl_T | |
26 | 3390 mch_get_acl(char_u *fname) |
7 | 3391 { |
3392 #ifndef HAVE_ACL | |
3393 return (vim_acl_T)NULL; | |
3394 #else | |
3395 struct my_acl *p = NULL; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3396 DWORD err; |
7 | 3397 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
3398 p = ALLOC_CLEAR_ONE(struct my_acl); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3399 if (p != NULL) |
7 | 3400 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3401 WCHAR *wn; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3402 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3403 wn = enc_to_utf16(fname, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3404 if (wn == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3405 return NULL; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3406 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3407 // Try to retrieve the entire security descriptor. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3408 err = GetNamedSecurityInfoW( |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3409 wn, // Abstract filename |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3410 SE_FILE_OBJECT, // File Object |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3411 OWNER_SECURITY_INFORMATION | |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3412 GROUP_SECURITY_INFORMATION | |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3413 DACL_SECURITY_INFORMATION | |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3414 SACL_SECURITY_INFORMATION, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3415 &p->pSidOwner, // Ownership information. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3416 &p->pSidGroup, // Group membership. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3417 &p->pDacl, // Discretionary information. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3418 &p->pSacl, // For auditing purposes. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3419 &p->pSecurityDescriptor); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3420 if (err == ERROR_ACCESS_DENIED || |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3421 err == ERROR_PRIVILEGE_NOT_HELD) |
7 | 3422 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3423 // Retrieve only DACL. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3424 (void)GetNamedSecurityInfoW( |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3425 wn, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3426 SE_FILE_OBJECT, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3427 DACL_SECURITY_INFORMATION, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3428 NULL, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3429 NULL, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3430 &p->pDacl, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3431 NULL, |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3432 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3433 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3434 if (p->pSecurityDescriptor == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3435 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3436 mch_free_acl((vim_acl_T)p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3437 p = NULL; |
7 | 3438 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3439 vim_free(wn); |
7 | 3440 } |
3441 | |
3442 return (vim_acl_T)p; | |
3443 #endif | |
3444 } | |
3445 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3446 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3447 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3448 * Check if "acl" contains inherited ACE. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3449 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3450 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3451 is_acl_inherited(PACL acl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3452 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3453 DWORD i; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3454 ACL_SIZE_INFORMATION acl_info; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3455 PACCESS_ALLOWED_ACE ace; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3456 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3457 acl_info.AceCount = 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3458 GetAclInformation(acl, &acl_info, sizeof(acl_info), AclSizeInformation); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3459 for (i = 0; i < acl_info.AceCount; i++) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3460 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3461 GetAce(acl, i, (LPVOID *)&ace); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3462 if (ace->Header.AceFlags & INHERITED_ACE) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3463 return TRUE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3464 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3465 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3466 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3467 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3468 |
7 | 3469 /* |
3470 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3471 * Errors are ignored. | |
3472 * This must only be called with "acl" equal to what mch_get_acl() returned. | |
3473 */ | |
3474 void | |
26 | 3475 mch_set_acl(char_u *fname, vim_acl_T acl) |
7 | 3476 { |
3477 #ifdef HAVE_ACL | |
3478 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
|
3479 SECURITY_INFORMATION sec_info = 0; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3480 WCHAR *wn; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3481 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3482 if (p == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3483 return; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3484 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3485 wn = enc_to_utf16(fname, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3486 if (wn == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3487 return; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3488 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3489 // Set security flags |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3490 if (p->pSidOwner) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3491 sec_info |= OWNER_SECURITY_INFORMATION; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3492 if (p->pSidGroup) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3493 sec_info |= GROUP_SECURITY_INFORMATION; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3494 if (p->pDacl) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3495 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3496 sec_info |= DACL_SECURITY_INFORMATION; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3497 // Do not inherit its parent's DACL. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3498 // If the DACL is inherited, Cygwin permissions would be changed. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3499 if (!is_acl_inherited(p->pDacl)) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3500 sec_info |= PROTECTED_DACL_SECURITY_INFORMATION; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3501 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3502 if (p->pSacl) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3503 sec_info |= SACL_SECURITY_INFORMATION; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3504 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3505 (void)SetNamedSecurityInfoW( |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3506 wn, // Abstract filename |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3507 SE_FILE_OBJECT, // File Object |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3508 sec_info, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3509 p->pSidOwner, // Ownership information. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3510 p->pSidGroup, // Group membership. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3511 p->pDacl, // Discretionary information. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3512 p->pSacl // For auditing purposes. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3513 ); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3514 vim_free(wn); |
7 | 3515 #endif |
3516 } | |
3517 | |
3518 void | |
26 | 3519 mch_free_acl(vim_acl_T acl) |
7 | 3520 { |
3521 #ifdef HAVE_ACL | |
3522 struct my_acl *p = (struct my_acl *)acl; | |
3523 | |
3524 if (p != NULL) | |
3525 { | |
3526 LocalFree(p->pSecurityDescriptor); // Free the memory just in case | |
3527 vim_free(p); | |
3528 } | |
3529 #endif | |
3530 } | |
3531 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3532 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 3533 |
3534 /* | |
3535 * handler for ctrl-break, ctrl-c interrupts, and fatal events. | |
3536 */ | |
3537 static BOOL WINAPI | |
3538 handler_routine( | |
3539 DWORD dwCtrlType) | |
3540 { | |
12074
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3541 INPUT_RECORD ir; |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3542 DWORD out; |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3543 |
7 | 3544 switch (dwCtrlType) |
3545 { | |
3546 case CTRL_C_EVENT: | |
3547 if (ctrl_c_interrupts) | |
3548 g_fCtrlCPressed = TRUE; | |
3549 return TRUE; | |
3550 | |
3551 case CTRL_BREAK_EVENT: | |
3552 g_fCBrkPressed = TRUE; | |
12074
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3553 ctrl_break_was_pressed = TRUE; |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3554 /* ReadConsoleInput is blocking, send a key event to continue. */ |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3555 ir.EventType = KEY_EVENT; |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3556 ir.Event.KeyEvent.bKeyDown = TRUE; |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3557 ir.Event.KeyEvent.wRepeatCount = 1; |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3558 ir.Event.KeyEvent.wVirtualKeyCode = VK_CANCEL; |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3559 ir.Event.KeyEvent.wVirtualScanCode = 0; |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3560 ir.Event.KeyEvent.dwControlKeyState = 0; |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3561 ir.Event.KeyEvent.uChar.UnicodeChar = 0; |
ca55e69d9d1b
patch 8.0.0917: MS-Windows:CTRL-C handling in terminal window is wrong
Christian Brabandt <cb@256bit.org>
parents:
12066
diff
changeset
|
3562 WriteConsoleInput(g_hConIn, &ir, 1, &out); |
7 | 3563 return TRUE; |
3564 | |
3565 /* fatal events: shut down gracefully */ | |
3566 case CTRL_CLOSE_EVENT: | |
3567 case CTRL_LOGOFF_EVENT: | |
3568 case CTRL_SHUTDOWN_EVENT: | |
3569 windgoto((int)Rows - 1, 0); | |
3570 g_fForceExit = TRUE; | |
3571 | |
1569 | 3572 vim_snprintf((char *)IObuff, IOSIZE, _("Vim: Caught %s event\n"), |
7 | 3573 (dwCtrlType == CTRL_CLOSE_EVENT |
3574 ? _("close") | |
3575 : dwCtrlType == CTRL_LOGOFF_EVENT | |
3576 ? _("logoff") | |
3577 : _("shutdown"))); | |
3578 #ifdef DEBUG | |
3579 OutputDebugString(IObuff); | |
3580 #endif | |
3581 | |
3582 preserve_exit(); /* output IObuff, preserve files and exit */ | |
3583 | |
3584 return TRUE; /* not reached */ | |
3585 | |
3586 default: | |
3587 return FALSE; | |
3588 } | |
3589 } | |
3590 | |
3591 | |
3592 /* | |
3593 * set the tty in (raw) ? "raw" : "cooked" mode | |
3594 */ | |
3595 void | |
26 | 3596 mch_settmode(int tmode) |
7 | 3597 { |
3598 DWORD cmodein; | |
3599 DWORD cmodeout; | |
3600 BOOL bEnableHandler; | |
3601 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3602 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3603 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3604 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3605 # endif |
7 | 3606 GetConsoleMode(g_hConIn, &cmodein); |
3607 GetConsoleMode(g_hConOut, &cmodeout); | |
3608 if (tmode == TMODE_RAW) | |
3609 { | |
3610 cmodein &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3611 ENABLE_ECHO_INPUT); | |
3612 #ifdef FEAT_MOUSE | |
3613 if (g_fMouseActive) | |
3614 cmodein |= ENABLE_MOUSE_INPUT; | |
3615 #endif | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3616 cmodeout &= ~( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3617 #ifdef FEAT_TERMGUICOLORS |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3618 /* Do not turn off the ENABLE_PROCESSED_OUTPUT flag when using |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3619 * VTP. */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3620 ((vtp_working) ? 0 : ENABLE_PROCESSED_OUTPUT) | |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3621 #else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3622 ENABLE_PROCESSED_OUTPUT | |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3623 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3624 ENABLE_WRAP_AT_EOL_OUTPUT); |
7 | 3625 bEnableHandler = TRUE; |
3626 } | |
3627 else /* cooked */ | |
3628 { | |
3629 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3630 ENABLE_ECHO_INPUT); | |
3631 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); | |
3632 bEnableHandler = FALSE; | |
3633 } | |
3634 SetConsoleMode(g_hConIn, cmodein); | |
3635 SetConsoleMode(g_hConOut, cmodeout); | |
3636 SetConsoleCtrlHandler(handler_routine, bEnableHandler); | |
3637 | |
3638 #ifdef MCH_WRITE_DUMP | |
3639 if (fdDump) | |
3640 { | |
3641 fprintf(fdDump, "mch_settmode(%s, in = %x, out = %x)\n", | |
3642 tmode == TMODE_RAW ? "raw" : | |
3643 tmode == TMODE_COOK ? "cooked" : "normal", | |
3644 cmodein, cmodeout); | |
3645 fflush(fdDump); | |
3646 } | |
3647 #endif | |
3648 } | |
3649 | |
3650 | |
3651 /* | |
3652 * Get the size of the current window in `Rows' and `Columns' | |
3653 * Return OK when size could be determined, FAIL otherwise. | |
3654 */ | |
3655 int | |
26 | 3656 mch_get_shellsize(void) |
7 | 3657 { |
3658 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
3659 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3660 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3661 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3662 return OK; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3663 # endif |
7 | 3664 if (!g_fTermcapMode && g_cbTermcap.IsValid) |
3665 { | |
3666 /* | |
3667 * For some reason, we are trying to get the screen dimensions | |
3668 * even though we are not in termcap mode. The 'Rows' and 'Columns' | |
3669 * variables are really intended to mean the size of Vim screen | |
3670 * while in termcap mode. | |
3671 */ | |
3672 Rows = g_cbTermcap.Info.dwSize.Y; | |
3673 Columns = g_cbTermcap.Info.dwSize.X; | |
3674 } | |
3675 else if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3676 { | |
3677 Rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3678 Columns = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3679 } | |
3680 else | |
3681 { | |
3682 Rows = 25; | |
3683 Columns = 80; | |
3684 } | |
3685 return OK; | |
3686 } | |
3687 | |
3688 /* | |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3689 * Resize console buffer to 'COORD' |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3690 */ |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3691 static void |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3692 ResizeConBuf( |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3693 HANDLE hConsole, |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3694 COORD coordScreen) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3695 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3696 if (!SetConsoleScreenBufferSize(hConsole, coordScreen)) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3697 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3698 #ifdef MCH_WRITE_DUMP |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3699 if (fdDump) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3700 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3701 fprintf(fdDump, "SetConsoleScreenBufferSize failed: %lx\n", |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3702 GetLastError()); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3703 fflush(fdDump); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3704 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3705 #endif |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3706 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3707 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3708 |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3709 /* |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3710 * Resize console window size to 'srWindowRect' |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3711 */ |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3712 static void |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3713 ResizeWindow( |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3714 HANDLE hConsole, |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3715 SMALL_RECT srWindowRect) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3716 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3717 if (!SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect)) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3718 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3719 #ifdef MCH_WRITE_DUMP |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3720 if (fdDump) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3721 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3722 fprintf(fdDump, "SetConsoleWindowInfo failed: %lx\n", |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3723 GetLastError()); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3724 fflush(fdDump); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3725 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3726 #endif |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3727 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3728 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3729 |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3730 /* |
7 | 3731 * Set a console window to `xSize' * `ySize' |
3732 */ | |
3733 static void | |
3734 ResizeConBufAndWindow( | |
26 | 3735 HANDLE hConsole, |
3736 int xSize, | |
3737 int ySize) | |
7 | 3738 { |
3739 CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ | |
3740 SMALL_RECT srWindowRect; /* hold the new console size */ | |
3741 COORD coordScreen; | |
17393
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3742 COORD cursor; |
14619
5e85d326d616
patch 8.1.0323: reverse order of VTP calls only needed the first time
Christian Brabandt <cb@256bit.org>
parents:
14567
diff
changeset
|
3743 static int resized = FALSE; |
7 | 3744 |
3745 #ifdef MCH_WRITE_DUMP | |
3746 if (fdDump) | |
3747 { | |
3748 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize); | |
3749 fflush(fdDump); | |
3750 } | |
3751 #endif | |
3752 | |
3753 /* get the largest size we can size the console window to */ | |
3754 coordScreen = GetLargestConsoleWindowSize(hConsole); | |
3755 | |
3756 /* define the new console window size and scroll position */ | |
3757 srWindowRect.Left = srWindowRect.Top = (SHORT) 0; | |
3758 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); | |
3759 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); | |
3760 | |
3761 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3762 { | |
3763 int sx, sy; | |
3764 | |
3765 sx = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3766 sy = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3767 if (sy < ySize || sx < xSize) | |
3768 { | |
3769 /* | |
3770 * Increasing number of lines/columns, do buffer first. | |
3771 * Use the maximal size in x and y direction. | |
3772 */ | |
3773 if (sy < ySize) | |
3774 coordScreen.Y = ySize; | |
3775 else | |
3776 coordScreen.Y = sy; | |
3777 if (sx < xSize) | |
3778 coordScreen.X = xSize; | |
3779 else | |
3780 coordScreen.X = sx; | |
3781 SetConsoleScreenBufferSize(hConsole, coordScreen); | |
3782 } | |
3783 } | |
3784 | |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3785 // define the new console buffer size |
7 | 3786 coordScreen.X = xSize; |
3787 coordScreen.Y = ySize; | |
3788 | |
14619
5e85d326d616
patch 8.1.0323: reverse order of VTP calls only needed the first time
Christian Brabandt <cb@256bit.org>
parents:
14567
diff
changeset
|
3789 // In the new console call API, only the first time in reverse order |
5e85d326d616
patch 8.1.0323: reverse order of VTP calls only needed the first time
Christian Brabandt <cb@256bit.org>
parents:
14567
diff
changeset
|
3790 if (!vtp_working || resized) |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3791 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3792 ResizeWindow(hConsole, srWindowRect); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3793 ResizeConBuf(hConsole, coordScreen); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3794 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3795 else |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3796 { |
17393
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3797 // Workaround for a Windows 10 bug |
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3798 cursor.X = srWindowRect.Left; |
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3799 cursor.Y = srWindowRect.Top; |
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3800 SetConsoleCursorPosition(hConsole, cursor); |
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3801 |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3802 ResizeConBuf(hConsole, coordScreen); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3803 ResizeWindow(hConsole, srWindowRect); |
14619
5e85d326d616
patch 8.1.0323: reverse order of VTP calls only needed the first time
Christian Brabandt <cb@256bit.org>
parents:
14567
diff
changeset
|
3804 resized = TRUE; |
7 | 3805 } |
3806 } | |
3807 | |
3808 | |
3809 /* | |
3810 * Set the console window to `Rows' * `Columns' | |
3811 */ | |
3812 void | |
26 | 3813 mch_set_shellsize(void) |
7 | 3814 { |
3815 COORD coordScreen; | |
3816 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3817 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3818 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3819 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3820 # endif |
7 | 3821 /* Don't change window size while still starting up */ |
3822 if (suppress_winsize != 0) | |
3823 { | |
3824 suppress_winsize = 2; | |
3825 return; | |
3826 } | |
3827 | |
3828 if (term_console) | |
3829 { | |
3830 coordScreen = GetLargestConsoleWindowSize(g_hConOut); | |
3831 | |
3832 /* Clamp Rows and Columns to reasonable values */ | |
3833 if (Rows > coordScreen.Y) | |
3834 Rows = coordScreen.Y; | |
3835 if (Columns > coordScreen.X) | |
3836 Columns = coordScreen.X; | |
3837 | |
3838 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
3839 } | |
3840 } | |
3841 | |
3842 /* | |
3843 * Rows and/or Columns has changed. | |
3844 */ | |
3845 void | |
26 | 3846 mch_new_shellsize(void) |
7 | 3847 { |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3848 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3849 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3850 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
3851 # endif |
7 | 3852 set_scroll_region(0, 0, Columns - 1, Rows - 1); |
3853 } | |
3854 | |
3855 | |
3856 /* | |
3857 * Called when started up, to set the winsize that was delayed. | |
3858 */ | |
3859 void | |
26 | 3860 mch_set_winsize_now(void) |
7 | 3861 { |
3862 if (suppress_winsize == 2) | |
3863 { | |
3864 suppress_winsize = 0; | |
3865 mch_set_shellsize(); | |
3866 shell_resized(); | |
3867 } | |
3868 suppress_winsize = 0; | |
3869 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
3870 #endif /* FEAT_GUI_MSWIN */ |
7 | 3871 |
5547 | 3872 static BOOL |
3873 vim_create_process( | |
5556 | 3874 char *cmd, |
5569 | 3875 BOOL inherit_handles, |
5547 | 3876 DWORD flags, |
3877 STARTUPINFO *si, | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
3878 PROCESS_INFORMATION *pi, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
3879 LPVOID *env, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
3880 char *cwd) |
5547 | 3881 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3882 BOOL ret = FALSE; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3883 WCHAR *wcmd, *wcwd = NULL; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3884 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3885 wcmd = enc_to_utf16((char_u *)cmd, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3886 if (wcmd == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3887 return FALSE; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3888 if (cwd != NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3889 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3890 wcwd = enc_to_utf16((char_u *)cwd, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3891 if (wcwd == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3892 goto theend; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3893 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3894 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3895 ret = CreateProcessW( |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3896 NULL, // Executable name |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3897 wcmd, // Command to execute |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3898 NULL, // Process security attributes |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3899 NULL, // Thread security attributes |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3900 inherit_handles, // Inherit handles |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3901 flags, // Creation flags |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3902 env, // Environment |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3903 wcwd, // Current directory |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3904 (LPSTARTUPINFOW)si, // Startup information |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3905 pi); // Process information |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3906 theend: |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3907 vim_free(wcmd); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3908 vim_free(wcwd); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3909 return ret; |
5547 | 3910 } |
7 | 3911 |
3912 | |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3913 static HINSTANCE |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3914 vim_shell_execute( |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3915 char *cmd, |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3916 INT n_show_cmd) |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3917 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3918 HINSTANCE ret; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3919 WCHAR *wcmd; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3920 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3921 wcmd = enc_to_utf16((char_u *)cmd, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3922 if (wcmd == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3923 return (HINSTANCE) 0; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3924 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3925 ret = ShellExecuteW(NULL, NULL, wcmd, NULL, NULL, n_show_cmd); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3926 vim_free(wcmd); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3927 return ret; |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3928 } |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3929 |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3930 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
3931 #if defined(FEAT_GUI_MSWIN) || defined(PROTO) |
7 | 3932 |
3933 /* | |
3934 * Specialised version of system() for Win32 GUI mode. | |
3935 * This version proceeds as follows: | |
3936 * 1. Create a console window for use by the subprocess | |
3937 * 2. Run the subprocess (it gets the allocated console by default) | |
3938 * 3. Wait for the subprocess to terminate and get its exit code | |
3939 * 4. Prompt the user to press a key to close the console window | |
3940 */ | |
3941 static int | |
2935 | 3942 mch_system_classic(char *cmd, int options) |
7 | 3943 { |
3944 STARTUPINFO si; | |
3945 PROCESS_INFORMATION pi; | |
3946 DWORD ret = 0; | |
3947 HWND hwnd = GetFocus(); | |
3948 | |
3949 si.cb = sizeof(si); | |
3950 si.lpReserved = NULL; | |
3951 si.lpDesktop = NULL; | |
3952 si.lpTitle = NULL; | |
3953 si.dwFlags = STARTF_USESHOWWINDOW; | |
3954 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3955 * It's nicer to run a filter command in a minimized window. |
2643 | 3956 * Don't activate the window to keep focus on Vim. |
7 | 3957 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3958 if (options & SHELL_DOOUT) |
2643 | 3959 si.wShowWindow = SW_SHOWMINNOACTIVE; |
7 | 3960 else |
3961 si.wShowWindow = SW_SHOWNORMAL; | |
3962 si.cbReserved2 = 0; | |
3963 si.lpReserved2 = NULL; | |
3964 | |
3965 /* Now, run the command */ | |
5547 | 3966 vim_create_process(cmd, FALSE, |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
3967 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
3968 &si, &pi, NULL, NULL); |
7 | 3969 |
3970 /* Wait for the command to terminate before continuing */ | |
3971 { | |
3972 #ifdef FEAT_GUI | |
3973 int delay = 1; | |
3974 | |
3975 /* Keep updating the window while waiting for the shell to finish. */ | |
3976 for (;;) | |
3977 { | |
3978 MSG msg; | |
3979 | |
3010 | 3980 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
7 | 3981 { |
3982 TranslateMessage(&msg); | |
3010 | 3983 pDispatchMessage(&msg); |
3720 | 3984 delay = 1; |
3985 continue; | |
7 | 3986 } |
3987 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
3988 break; | |
3989 | |
3990 /* We start waiting for a very short time and then increase it, so | |
3991 * that we respond quickly when the process is quick, and don't | |
3992 * consume too much overhead when it's slow. */ | |
3993 if (delay < 50) | |
3994 delay += 10; | |
3995 } | |
3996 #else | |
3997 WaitForSingleObject(pi.hProcess, INFINITE); | |
3998 #endif | |
3999 | |
4000 /* Get the command exit code */ | |
4001 GetExitCodeProcess(pi.hProcess, &ret); | |
4002 } | |
4003 | |
4004 /* Close the handles to the subprocess, so that it goes away */ | |
4005 CloseHandle(pi.hThread); | |
4006 CloseHandle(pi.hProcess); | |
4007 | |
4008 /* Try to get input focus back. Doesn't always work though. */ | |
4009 PostMessage(hwnd, WM_SETFOCUS, 0, 0); | |
4010 | |
4011 return ret; | |
4012 } | |
2935 | 4013 |
4014 /* | |
4015 * Thread launched by the gui to send the current buffer data to the | |
4016 * process. This way avoid to hang up vim totally if the children | |
4017 * process take a long time to process the lines. | |
4018 */ | |
9750
0f4b76b2757a
commit https://github.com/vim/vim/commit/4c38d66d25e4ba433fe87283a4664425a3dbd529
Christian Brabandt <cb@256bit.org>
parents:
9740
diff
changeset
|
4019 static unsigned int __stdcall |
2935 | 4020 sub_process_writer(LPVOID param) |
4021 { | |
4022 HANDLE g_hChildStd_IN_Wr = param; | |
4023 linenr_T lnum = curbuf->b_op_start.lnum; | |
4024 DWORD len = 0; | |
4025 DWORD l; | |
4026 char_u *lp = ml_get(lnum); | |
4027 char_u *s; | |
4028 int written = 0; | |
4029 | |
4030 for (;;) | |
4031 { | |
4032 l = (DWORD)STRLEN(lp + written); | |
4033 if (l == 0) | |
4034 len = 0; | |
4035 else if (lp[written] == NL) | |
4036 { | |
4037 /* NL -> NUL translation */ | |
4038 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); | |
4039 } | |
4040 else | |
4041 { | |
4042 s = vim_strchr(lp + written, NL); | |
4043 WriteFile(g_hChildStd_IN_Wr, (char *)lp + written, | |
4044 s == NULL ? l : (DWORD)(s - (lp + written)), | |
4045 &len, NULL); | |
4046 } | |
4047 if (len == (int)l) | |
4048 { | |
4049 /* Finished a line, add a NL, unless this line should not have | |
4050 * one. */ | |
4051 if (lnum != curbuf->b_op_end.lnum | |
6933 | 4052 || (!curbuf->b_p_bin |
4053 && curbuf->b_p_fixeol) | |
2935 | 4054 || (lnum != curbuf->b_no_eol_lnum |
4055 && (lnum != curbuf->b_ml.ml_line_count | |
4056 || curbuf->b_p_eol))) | |
4057 { | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14673
diff
changeset
|
4058 WriteFile(g_hChildStd_IN_Wr, "\n", 1, |
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14673
diff
changeset
|
4059 (LPDWORD)&vim_ignored, NULL); |
2935 | 4060 } |
4061 | |
4062 ++lnum; | |
4063 if (lnum > curbuf->b_op_end.lnum) | |
4064 break; | |
4065 | |
4066 lp = ml_get(lnum); | |
4067 written = 0; | |
4068 } | |
4069 else if (len > 0) | |
4070 written += len; | |
4071 } | |
4072 | |
4073 /* finished all the lines, close pipe */ | |
4074 CloseHandle(g_hChildStd_IN_Wr); | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4075 return 0; |
2935 | 4076 } |
4077 | |
4078 | |
4079 # define BUFLEN 100 /* length for buffer, stolen from unix version */ | |
4080 | |
4081 /* | |
4082 * This function read from the children's stdout and write the | |
4083 * data on screen or in the buffer accordingly. | |
4084 */ | |
4085 static void | |
4086 dump_pipe(int options, | |
4087 HANDLE g_hChildStd_OUT_Rd, | |
4088 garray_T *ga, | |
4089 char_u buffer[], | |
4090 DWORD *buffer_off) | |
4091 { | |
4092 DWORD availableBytes = 0; | |
4093 DWORD i; | |
4094 int ret; | |
4095 DWORD len; | |
4096 DWORD toRead; | |
4097 int repeatCount; | |
4098 | |
4099 /* we query the pipe to see if there is any data to read | |
4100 * to avoid to perform a blocking read */ | |
4101 ret = PeekNamedPipe(g_hChildStd_OUT_Rd, /* pipe to query */ | |
4102 NULL, /* optional buffer */ | |
3622 | 4103 0, /* buffer size */ |
2935 | 4104 NULL, /* number of read bytes */ |
4105 &availableBytes, /* available bytes total */ | |
4106 NULL); /* byteLeft */ | |
4107 | |
4108 repeatCount = 0; | |
4109 /* We got real data in the pipe, read it */ | |
3622 | 4110 while (ret != 0 && availableBytes > 0) |
2935 | 4111 { |
4112 repeatCount++; | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
4113 toRead = (DWORD)(BUFLEN - *buffer_off); |
2935 | 4114 toRead = availableBytes < toRead ? availableBytes : toRead; |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
4115 ReadFile(g_hChildStd_OUT_Rd, buffer + *buffer_off, toRead , &len, NULL); |
2935 | 4116 |
4117 /* If we haven't read anything, there is a problem */ | |
4118 if (len == 0) | |
4119 break; | |
4120 | |
4121 availableBytes -= len; | |
4122 | |
4123 if (options & SHELL_READ) | |
4124 { | |
4125 /* Do NUL -> NL translation, append NL separated | |
4126 * lines to the current buffer. */ | |
4127 for (i = 0; i < len; ++i) | |
4128 { | |
4129 if (buffer[i] == NL) | |
4130 append_ga_line(ga); | |
4131 else if (buffer[i] == NUL) | |
4132 ga_append(ga, NL); | |
4133 else | |
4134 ga_append(ga, buffer[i]); | |
4135 } | |
4136 } | |
4137 else if (has_mbyte) | |
4138 { | |
4139 int l; | |
3030 | 4140 int c; |
4141 char_u *p; | |
2935 | 4142 |
4143 len += *buffer_off; | |
4144 buffer[len] = NUL; | |
4145 | |
4146 /* Check if the last character in buffer[] is | |
4147 * incomplete, keep these bytes for the next | |
4148 * round. */ | |
4149 for (p = buffer; p < buffer + len; p += l) | |
4150 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9762
diff
changeset
|
4151 l = MB_CPTR2LEN(p); |
2935 | 4152 if (l == 0) |
4153 l = 1; /* NUL byte? */ | |
4154 else if (MB_BYTE2LEN(*p) != l) | |
4155 break; | |
4156 } | |
4157 if (p == buffer) /* no complete character */ | |
4158 { | |
4159 /* avoid getting stuck at an illegal byte */ | |
4160 if (len >= 12) | |
4161 ++p; | |
4162 else | |
4163 { | |
4164 *buffer_off = len; | |
4165 return; | |
4166 } | |
4167 } | |
4168 c = *p; | |
4169 *p = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4170 msg_puts((char *)buffer); |
2935 | 4171 if (p < buffer + len) |
4172 { | |
4173 *p = c; | |
4174 *buffer_off = (DWORD)((buffer + len) - p); | |
4175 mch_memmove(buffer, p, *buffer_off); | |
4176 return; | |
4177 } | |
4178 *buffer_off = 0; | |
4179 } | |
4180 else | |
4181 { | |
4182 buffer[len] = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4183 msg_puts((char *)buffer); |
2935 | 4184 } |
4185 | |
4186 windgoto(msg_row, msg_col); | |
4187 cursor_on(); | |
4188 out_flush(); | |
4189 } | |
4190 } | |
4191 | |
4192 /* | |
4193 * Version of system to use for windows NT > 5.0 (Win2K), use pipe | |
4194 * for communication and doesn't open any new window. | |
4195 */ | |
4196 static int | |
4197 mch_system_piped(char *cmd, int options) | |
4198 { | |
4199 STARTUPINFO si; | |
4200 PROCESS_INFORMATION pi; | |
4201 DWORD ret = 0; | |
4202 | |
4203 HANDLE g_hChildStd_IN_Rd = NULL; | |
4204 HANDLE g_hChildStd_IN_Wr = NULL; | |
4205 HANDLE g_hChildStd_OUT_Rd = NULL; | |
4206 HANDLE g_hChildStd_OUT_Wr = NULL; | |
4207 | |
4208 char_u buffer[BUFLEN + 1]; /* reading buffer + size */ | |
4209 DWORD len; | |
4210 | |
4211 /* buffer used to receive keys */ | |
4212 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ | |
4213 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4214 | |
4215 DWORD i; | |
4216 int c; | |
4217 int noread_cnt = 0; | |
4218 garray_T ga; | |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4219 int delay = 1; |
2935 | 4220 DWORD buffer_off = 0; /* valid bytes in buffer[] */ |
3361 | 4221 char *p = NULL; |
2935 | 4222 |
4223 SECURITY_ATTRIBUTES saAttr; | |
4224 | |
4225 /* Set the bInheritHandle flag so pipe handles are inherited. */ | |
4226 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); | |
4227 saAttr.bInheritHandle = TRUE; | |
4228 saAttr.lpSecurityDescriptor = NULL; | |
4229 | |
4230 if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) | |
4231 /* Ensure the read handle to the pipe for STDOUT is not inherited. */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4232 || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) |
2935 | 4233 /* Create a pipe for the child process's STDIN. */ |
4234 || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0) | |
4235 /* Ensure the write handle to the pipe for STDIN is not inherited. */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4236 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) |
2935 | 4237 { |
4238 CloseHandle(g_hChildStd_IN_Rd); | |
4239 CloseHandle(g_hChildStd_IN_Wr); | |
4240 CloseHandle(g_hChildStd_OUT_Rd); | |
4241 CloseHandle(g_hChildStd_OUT_Wr); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4242 msg_puts(_("\nCannot create pipes\n")); |
2935 | 4243 } |
4244 | |
4245 si.cb = sizeof(si); | |
4246 si.lpReserved = NULL; | |
4247 si.lpDesktop = NULL; | |
4248 si.lpTitle = NULL; | |
4249 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; | |
4250 | |
4251 /* set-up our file redirection */ | |
4252 si.hStdError = g_hChildStd_OUT_Wr; | |
4253 si.hStdOutput = g_hChildStd_OUT_Wr; | |
4254 si.hStdInput = g_hChildStd_IN_Rd; | |
4255 si.wShowWindow = SW_HIDE; | |
4256 si.cbReserved2 = 0; | |
4257 si.lpReserved2 = NULL; | |
4258 | |
4259 if (options & SHELL_READ) | |
4260 ga_init2(&ga, 1, BUFLEN); | |
4261 | |
3361 | 4262 if (cmd != NULL) |
4263 { | |
4264 p = (char *)vim_strsave((char_u *)cmd); | |
4265 if (p != NULL) | |
4266 unescape_shellxquote((char_u *)p, p_sxe); | |
4267 else | |
4268 p = cmd; | |
4269 } | |
4270 | |
5547 | 4271 /* Now, run the command. |
4272 * About "Inherit handles" being TRUE: this command can be litigious, | |
4273 * handle inheritance was deactivated for pending temp file, but, if we | |
4274 * deactivate it, the pipes don't work for some reason. */ | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4275 vim_create_process(p, TRUE, CREATE_DEFAULT_ERROR_MODE, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4276 &si, &pi, NULL, NULL); |
2935 | 4277 |
3361 | 4278 if (p != cmd) |
4279 vim_free(p); | |
2935 | 4280 |
4281 /* Close our unused side of the pipes */ | |
4282 CloseHandle(g_hChildStd_IN_Rd); | |
4283 CloseHandle(g_hChildStd_OUT_Wr); | |
4284 | |
4285 if (options & SHELL_WRITE) | |
4286 { | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4287 HANDLE thread = (HANDLE) |
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4288 _beginthreadex(NULL, /* security attributes */ |
2935 | 4289 0, /* default stack size */ |
4290 sub_process_writer, /* function to be executed */ | |
4291 g_hChildStd_IN_Wr, /* parameter */ | |
4292 0, /* creation flag, start immediately */ | |
4293 NULL); /* we don't care about thread id */ | |
4294 CloseHandle(thread); | |
4295 g_hChildStd_IN_Wr = NULL; | |
4296 } | |
4297 | |
4298 /* Keep updating the window while waiting for the shell to finish. */ | |
4299 for (;;) | |
4300 { | |
4301 MSG msg; | |
4302 | |
5553 | 4303 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
2935 | 4304 { |
4305 TranslateMessage(&msg); | |
5553 | 4306 pDispatchMessage(&msg); |
2935 | 4307 } |
4308 | |
4309 /* write pipe information in the window */ | |
4310 if ((options & (SHELL_READ|SHELL_WRITE)) | |
4311 # ifdef FEAT_GUI | |
4312 || gui.in_use | |
4313 # endif | |
4314 ) | |
4315 { | |
4316 len = 0; | |
4317 if (!(options & SHELL_EXPAND) | |
4318 && ((options & | |
4319 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4320 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
4321 # ifdef FEAT_GUI | |
4322 || gui.in_use | |
4323 # endif | |
4324 ) | |
4325 && (ta_len > 0 || noread_cnt > 4)) | |
4326 { | |
4327 if (ta_len == 0) | |
4328 { | |
4329 /* Get extra characters when we don't have any. Reset the | |
4330 * counter and timer. */ | |
4331 noread_cnt = 0; | |
4332 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4333 } | |
4334 if (ta_len > 0 || len > 0) | |
4335 { | |
4336 /* | |
4337 * For pipes: Check for CTRL-C: send interrupt signal to | |
4338 * child. Check for CTRL-D: EOF, close pipe to child. | |
4339 */ | |
4340 if (len == 1 && cmd != NULL) | |
4341 { | |
4342 if (ta_buf[ta_len] == Ctrl_C) | |
4343 { | |
4344 /* Learn what exit code is expected, for | |
4345 * now put 9 as SIGKILL */ | |
4346 TerminateProcess(pi.hProcess, 9); | |
4347 } | |
4348 if (ta_buf[ta_len] == Ctrl_D) | |
4349 { | |
4350 CloseHandle(g_hChildStd_IN_Wr); | |
4351 g_hChildStd_IN_Wr = NULL; | |
4352 } | |
4353 } | |
4354 | |
4355 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
4356 for (i = ta_len; i < ta_len + len; ++i) | |
4357 { | |
4358 if (ta_buf[i] == CSI && len - i > 2) | |
4359 { | |
4360 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
4361 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
4362 { | |
4363 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
4364 (size_t)(len - i - 2)); | |
4365 if (c == K_DEL || c == K_KDEL) | |
4366 ta_buf[i] = DEL; | |
4367 else | |
4368 ta_buf[i] = Ctrl_H; | |
4369 len -= 2; | |
4370 } | |
4371 } | |
4372 else if (ta_buf[i] == '\r') | |
4373 ta_buf[i] = '\n'; | |
4374 if (has_mbyte) | |
4375 i += (*mb_ptr2len_len)(ta_buf + i, | |
4376 ta_len + len - i) - 1; | |
4377 } | |
4378 | |
4379 /* | |
4380 * For pipes: echo the typed characters. For a pty this | |
4381 * does not seem to work. | |
4382 */ | |
4383 for (i = ta_len; i < ta_len + len; ++i) | |
4384 { | |
4385 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4386 msg_putchar(ta_buf[i]); | |
4387 else if (has_mbyte) | |
4388 { | |
4389 int l = (*mb_ptr2len)(ta_buf + i); | |
4390 | |
4391 msg_outtrans_len(ta_buf + i, l); | |
4392 i += l - 1; | |
4393 } | |
4394 else | |
4395 msg_outtrans_len(ta_buf + i, 1); | |
4396 } | |
4397 windgoto(msg_row, msg_col); | |
4398 out_flush(); | |
4399 | |
4400 ta_len += len; | |
4401 | |
4402 /* | |
4403 * Write the characters to the child, unless EOF has been | |
4404 * typed for pipes. Write one character at a time, to | |
4405 * avoid losing too much typeahead. When writing buffer | |
4406 * lines, drop the typed characters (only check for | |
4407 * CTRL-C). | |
4408 */ | |
4409 if (options & SHELL_WRITE) | |
4410 ta_len = 0; | |
4411 else if (g_hChildStd_IN_Wr != NULL) | |
4412 { | |
4413 WriteFile(g_hChildStd_IN_Wr, (char*)ta_buf, | |
4414 1, &len, NULL); | |
4415 // if we are typing in, we want to keep things reactive | |
4416 delay = 1; | |
4417 if (len > 0) | |
4418 { | |
4419 ta_len -= len; | |
4420 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4421 } | |
4422 } | |
4423 } | |
4424 } | |
4425 } | |
4426 | |
4427 if (ta_len) | |
4428 ui_inchar_undo(ta_buf, ta_len); | |
4429 | |
4430 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4431 { | |
3030 | 4432 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4433 break; |
4434 } | |
4435 | |
4436 ++noread_cnt; | |
3030 | 4437 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4438 |
4439 /* We start waiting for a very short time and then increase it, so | |
4440 * that we respond quickly when the process is quick, and don't | |
4441 * consume too much overhead when it's slow. */ | |
4442 if (delay < 50) | |
4443 delay += 10; | |
4444 } | |
4445 | |
4446 /* Close the pipe */ | |
4447 CloseHandle(g_hChildStd_OUT_Rd); | |
4448 if (g_hChildStd_IN_Wr != NULL) | |
4449 CloseHandle(g_hChildStd_IN_Wr); | |
4450 | |
4451 WaitForSingleObject(pi.hProcess, INFINITE); | |
4452 | |
4453 /* Get the command exit code */ | |
4454 GetExitCodeProcess(pi.hProcess, &ret); | |
4455 | |
4456 if (options & SHELL_READ) | |
4457 { | |
4458 if (ga.ga_len > 0) | |
4459 { | |
4460 append_ga_line(&ga); | |
4461 /* remember that the NL was missing */ | |
4462 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; | |
4463 } | |
4464 else | |
4465 curbuf->b_no_eol_lnum = 0; | |
4466 ga_clear(&ga); | |
4467 } | |
4468 | |
4469 /* Close the handles to the subprocess, so that it goes away */ | |
4470 CloseHandle(pi.hThread); | |
4471 CloseHandle(pi.hProcess); | |
4472 | |
4473 return ret; | |
4474 } | |
4475 | |
4476 static int | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4477 mch_system_g(char *cmd, int options) |
2935 | 4478 { |
4479 /* if we can pipe and the shelltemp option is off */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4480 if (!p_stmp) |
2935 | 4481 return mch_system_piped(cmd, options); |
4482 else | |
4483 return mch_system_classic(cmd, options); | |
4484 } | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4485 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4486 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4487 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
5547 | 4488 static int |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
4489 mch_system_c(char *cmd, int options UNUSED) |
5547 | 4490 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4491 int ret; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4492 WCHAR *wcmd; |
18241
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4493 char_u *buf; |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4494 size_t len; |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4495 |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4496 // If the command starts and ends with double quotes, enclose the command |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4497 // in parentheses. |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4498 len = STRLEN(cmd); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4499 if (len >= 2 && cmd[0] == '"' && cmd[len - 1] == '"') |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4500 { |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4501 len += 3; |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4502 buf = alloc(len); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4503 if (buf == NULL) |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4504 return -1; |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4505 vim_snprintf((char *)buf, len, "(%s)", cmd); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4506 wcmd = enc_to_utf16(buf, NULL); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4507 free(buf); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4508 } |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4509 else |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4510 wcmd = enc_to_utf16((char_u *)cmd, NULL); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4511 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4512 if (wcmd == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4513 return -1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4514 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4515 ret = _wsystem(wcmd); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4516 vim_free(wcmd); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4517 return ret; |
5547 | 4518 } |
7 | 4519 |
4520 #endif | |
4521 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4522 static int |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4523 mch_system(char *cmd, int options) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4524 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4525 #ifdef VIMDLL |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4526 if (gui.in_use || gui.starting) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4527 return mch_system_g(cmd, options); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4528 else |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4529 return mch_system_c(cmd, options); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4530 #elif defined(FEAT_GUI_MSWIN) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4531 return mch_system_g(cmd, options); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4532 #else |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4533 return mch_system_c(cmd, options); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4534 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4535 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4536 |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4537 #if defined(FEAT_GUI) && defined(FEAT_TERMINAL) |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4538 /* |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4539 * Use a terminal window to run a shell command in. |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4540 */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4541 static int |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4542 mch_call_shell_terminal( |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4543 char_u *cmd, |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4544 int options UNUSED) /* SHELL_*, see vim.h */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4545 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4546 jobopt_T opt; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4547 char_u *newcmd = NULL; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4548 typval_T argvar[2]; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4549 long_u cmdlen; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4550 int retval = -1; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4551 buf_T *buf; |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14067
diff
changeset
|
4552 job_T *job; |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4553 aco_save_T aco; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4554 oparg_T oa; /* operator arguments */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4555 |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4556 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4557 cmdlen = STRLEN(p_sh) + 1; |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4558 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4559 cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
4560 newcmd = alloc(cmdlen); |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4561 if (newcmd == NULL) |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4562 return 255; |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4563 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4564 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4565 STRCPY(newcmd, p_sh); |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4566 ch_log(NULL, "starting terminal to run a shell"); |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4567 } |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4568 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4569 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4570 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", p_sh, p_shcf, cmd); |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4571 ch_log(NULL, "starting terminal for system command '%s'", cmd); |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4572 } |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4573 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4574 init_job_options(&opt); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4575 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4576 argvar[0].v_type = VAR_STRING; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4577 argvar[0].vval.v_string = newcmd; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4578 argvar[1].v_type = VAR_UNKNOWN; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4579 buf = term_start(argvar, NULL, &opt, TERM_START_SYSTEM); |
13491
cc7dc249e371
patch 8.0.1619: Win32 GUI: crash when winpty is not installed
Christian Brabandt <cb@256bit.org>
parents:
13487
diff
changeset
|
4580 if (buf == NULL) |
16046
884b683d12e9
patch 8.1.1028: MS-Windows: memory leak when creating terminal fails
Bram Moolenaar <Bram@vim.org>
parents:
16015
diff
changeset
|
4581 { |
884b683d12e9
patch 8.1.1028: MS-Windows: memory leak when creating terminal fails
Bram Moolenaar <Bram@vim.org>
parents:
16015
diff
changeset
|
4582 vim_free(newcmd); |
13491
cc7dc249e371
patch 8.0.1619: Win32 GUI: crash when winpty is not installed
Christian Brabandt <cb@256bit.org>
parents:
13487
diff
changeset
|
4583 return 255; |
16046
884b683d12e9
patch 8.1.1028: MS-Windows: memory leak when creating terminal fails
Bram Moolenaar <Bram@vim.org>
parents:
16015
diff
changeset
|
4584 } |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4585 |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14067
diff
changeset
|
4586 job = term_getjob(buf->b_term); |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14067
diff
changeset
|
4587 ++job->jv_refcount; |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14067
diff
changeset
|
4588 |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4589 /* Find a window to make "buf" curbuf. */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4590 aucmd_prepbuf(&aco, buf); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4591 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4592 clear_oparg(&oa); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4593 while (term_use_loop()) |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4594 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4595 if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active) |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4596 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4597 /* If terminal_loop() returns OK we got a key that is handled |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4598 * in Normal model. We don't do redrawing anyway. */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4599 if (terminal_loop(TRUE) == OK) |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4600 normal_cmd(&oa, TRUE); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4601 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4602 else |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4603 normal_cmd(&oa, TRUE); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4604 } |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14067
diff
changeset
|
4605 retval = job->jv_exitval; |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4606 ch_log(NULL, "system command finished"); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4607 |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14067
diff
changeset
|
4608 job_unref(job); |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14067
diff
changeset
|
4609 |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4610 /* restore curwin/curbuf and a few other things */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4611 aucmd_restbuf(&aco); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4612 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4613 wait_return(TRUE); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4614 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4615 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4616 vim_free(newcmd); |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4617 return retval; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4618 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4619 #endif |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4620 |
7 | 4621 /* |
4622 * Either execute a command by calling the shell or start a new shell | |
4623 */ | |
4624 int | |
4625 mch_call_shell( | |
26 | 4626 char_u *cmd, |
4627 int options) /* SHELL_*, see vim.h */ | |
7 | 4628 { |
4629 int x = 0; | |
4630 int tmode = cur_tmode; | |
4631 #ifdef FEAT_TITLE | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4632 WCHAR szShellTitle[512]; |
6293 | 4633 |
6290 | 4634 /* Change the title to reflect that we are in a subshell. */ |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4635 if (GetConsoleTitleW(szShellTitle, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4636 sizeof(szShellTitle)/sizeof(WCHAR) - 4) > 0) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4637 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4638 if (cmd == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4639 wcscat(szShellTitle, L" :sh"); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4640 else |
6290 | 4641 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4642 WCHAR *wn = enc_to_utf16((char_u *)cmd, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4643 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4644 if (wn != NULL) |
6290 | 4645 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4646 wcscat(szShellTitle, L" - !"); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4647 if ((wcslen(szShellTitle) + wcslen(wn) < |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4648 sizeof(szShellTitle)/sizeof(WCHAR))) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4649 wcscat(szShellTitle, wn); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4650 SetConsoleTitleW(szShellTitle); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4651 vim_free(wn); |
6290 | 4652 } |
4653 } | |
4654 } | |
7 | 4655 #endif |
4656 | |
4657 out_flush(); | |
4658 | |
4659 #ifdef MCH_WRITE_DUMP | |
4660 if (fdDump) | |
4661 { | |
4662 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options); | |
4663 fflush(fdDump); | |
4664 } | |
4665 #endif | |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4666 #if defined(FEAT_GUI) && defined(FEAT_TERMINAL) |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4667 // TODO: make the terminal window work with input or output redirected. |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4668 if ( |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4669 # ifdef VIMDLL |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4670 gui.in_use && |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4671 # endif |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4672 vim_strchr(p_go, GO_TERMINAL) != NULL |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4673 && (options & (SHELL_FILTER|SHELL_DOOUT|SHELL_WRITE|SHELL_READ)) == 0) |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4674 { |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4675 char_u *cmdbase = cmd; |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4676 |
18133
d683b2c82c00
patch 8.1.2061: MS-Windows GUI: ":sh" crashes when trying to use a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18064
diff
changeset
|
4677 if (cmdbase != NULL) |
d683b2c82c00
patch 8.1.2061: MS-Windows GUI: ":sh" crashes when trying to use a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18064
diff
changeset
|
4678 // Skip a leading quote and (. |
d683b2c82c00
patch 8.1.2061: MS-Windows GUI: ":sh" crashes when trying to use a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18064
diff
changeset
|
4679 while (*cmdbase == '"' || *cmdbase == '(') |
d683b2c82c00
patch 8.1.2061: MS-Windows GUI: ":sh" crashes when trying to use a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18064
diff
changeset
|
4680 ++cmdbase; |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4681 |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4682 // Check the command does not begin with "start " |
18133
d683b2c82c00
patch 8.1.2061: MS-Windows GUI: ":sh" crashes when trying to use a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18064
diff
changeset
|
4683 if (cmdbase == NULL |
d683b2c82c00
patch 8.1.2061: MS-Windows GUI: ":sh" crashes when trying to use a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18064
diff
changeset
|
4684 || STRNICMP(cmdbase, "start", 5) != 0 || !VIM_ISWHITE(cmdbase[5])) |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4685 { |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4686 // Use a terminal window to run the command in. |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4687 x = mch_call_shell_terminal(cmd, options); |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
4688 # ifdef FEAT_TITLE |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4689 resettitle(); |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
4690 # endif |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4691 return x; |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4692 } |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4693 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4694 #endif |
7 | 4695 |
4696 /* | |
4697 * Catch all deadly signals while running the external command, because a | |
4698 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us. | |
4699 */ | |
4700 signal(SIGINT, SIG_IGN); | |
4701 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4702 signal(SIGKILL, SIG_IGN); | |
4703 #else | |
4704 signal(SIGBREAK, SIG_IGN); | |
4705 #endif | |
4706 signal(SIGILL, SIG_IGN); | |
4707 signal(SIGFPE, SIG_IGN); | |
4708 signal(SIGSEGV, SIG_IGN); | |
4709 signal(SIGTERM, SIG_IGN); | |
4710 signal(SIGABRT, SIG_IGN); | |
4711 | |
4712 if (options & SHELL_COOKED) | |
4713 settmode(TMODE_COOK); /* set to normal mode */ | |
4714 | |
4715 if (cmd == NULL) | |
4716 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4717 x = mch_system((char *)p_sh, options); |
7 | 4718 } |
4719 else | |
4720 { | |
4721 /* we use "command" or "cmd" to start the shell; slow but easy */ | |
3363 | 4722 char_u *newcmd = NULL; |
4723 char_u *cmdbase = cmd; | |
4724 long_u cmdlen; | |
3361 | 4725 |
4726 /* Skip a leading ", ( and "(. */ | |
4727 if (*cmdbase == '"' ) | |
4728 ++cmdbase; | |
4729 if (*cmdbase == '(') | |
4730 ++cmdbase; | |
4731 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4732 if ((STRNICMP(cmdbase, "start", 5) == 0) && VIM_ISWHITE(cmdbase[5])) |
3361 | 4733 { |
4734 STARTUPINFO si; | |
4735 PROCESS_INFORMATION pi; | |
4736 DWORD flags = CREATE_NEW_CONSOLE; | |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4737 INT n_show_cmd = SW_SHOWNORMAL; |
3361 | 4738 char_u *p; |
4739 | |
5627 | 4740 ZeroMemory(&si, sizeof(si)); |
3361 | 4741 si.cb = sizeof(si); |
4742 si.lpReserved = NULL; | |
4743 si.lpDesktop = NULL; | |
4744 si.lpTitle = NULL; | |
4745 si.dwFlags = 0; | |
4746 si.cbReserved2 = 0; | |
4747 si.lpReserved2 = NULL; | |
4748 | |
4749 cmdbase = skipwhite(cmdbase + 5); | |
4750 if ((STRNICMP(cmdbase, "/min", 4) == 0) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4751 && VIM_ISWHITE(cmdbase[4])) |
3361 | 4752 { |
4753 cmdbase = skipwhite(cmdbase + 4); | |
4754 si.dwFlags = STARTF_USESHOWWINDOW; | |
4755 si.wShowWindow = SW_SHOWMINNOACTIVE; | |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4756 n_show_cmd = SW_SHOWMINNOACTIVE; |
3361 | 4757 } |
4758 else if ((STRNICMP(cmdbase, "/b", 2) == 0) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4759 && VIM_ISWHITE(cmdbase[2])) |
3361 | 4760 { |
4761 cmdbase = skipwhite(cmdbase + 2); | |
4762 flags = CREATE_NO_WINDOW; | |
4763 si.dwFlags = STARTF_USESTDHANDLES; | |
4764 si.hStdInput = CreateFile("\\\\.\\NUL", // File name | |
3363 | 4765 GENERIC_READ, // Access flags |
3361 | 4766 0, // Share flags |
3363 | 4767 NULL, // Security att. |
4768 OPEN_EXISTING, // Open flags | |
4769 FILE_ATTRIBUTE_NORMAL, // File att. | |
4770 NULL); // Temp file | |
3361 | 4771 si.hStdOutput = si.hStdInput; |
4772 si.hStdError = si.hStdInput; | |
4773 } | |
4774 | |
4775 /* Remove a trailing ", ) and )" if they have a match | |
4776 * at the start of the command. */ | |
4777 if (cmdbase > cmd) | |
4778 { | |
4779 p = cmdbase + STRLEN(cmdbase); | |
4780 if (p > cmdbase && p[-1] == '"' && *cmd == '"') | |
4781 *--p = NUL; | |
4782 if (p > cmdbase && p[-1] == ')' | |
4783 && (*cmd =='(' || cmd[1] == '(')) | |
4784 *--p = NUL; | |
4785 } | |
4786 | |
3363 | 4787 newcmd = cmdbase; |
4788 unescape_shellxquote(cmdbase, p_sxe); | |
4789 | |
3361 | 4790 /* |
3363 | 4791 * If creating new console, arguments are passed to the |
4792 * 'cmd.exe' as-is. If it's not, arguments are not treated | |
4793 * correctly for current 'cmd.exe'. So unescape characters in | |
4794 * shellxescape except '|' for avoiding to be treated as | |
4795 * argument to them. Pass the arguments to sub-shell. | |
3361 | 4796 */ |
3363 | 4797 if (flags != CREATE_NEW_CONSOLE) |
4798 { | |
4799 char_u *subcmd; | |
3367 | 4800 char_u *cmd_shell = mch_getenv("COMSPEC"); |
4801 | |
4802 if (cmd_shell == NULL || *cmd_shell == NUL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4803 cmd_shell = (char_u *)default_shell(); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4804 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4805 subcmd = vim_strsave_escaped_ext(cmdbase, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4806 (char_u *)"|", '^', FALSE); |
3363 | 4807 if (subcmd != NULL) |
4808 { | |
4809 /* make "cmd.exe /c arguments" */ | |
4810 cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5; | |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
4811 newcmd = alloc(cmdlen); |
3363 | 4812 if (newcmd != NULL) |
4813 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s", | |
3367 | 4814 cmd_shell, subcmd); |
3363 | 4815 else |
4816 newcmd = cmdbase; | |
3367 | 4817 vim_free(subcmd); |
3363 | 4818 } |
4819 } | |
3361 | 4820 |
4821 /* | |
4822 * Now, start the command as a process, so that it doesn't | |
4823 * inherit our handles which causes unpleasant dangling swap | |
4824 * files if we exit before the spawned process | |
4825 */ | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4826 if (vim_create_process((char *)newcmd, FALSE, flags, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4827 &si, &pi, NULL, NULL)) |
3361 | 4828 x = 0; |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4829 else if (vim_shell_execute((char *)newcmd, n_show_cmd) |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4830 > (HINSTANCE)32) |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4831 x = 0; |
3361 | 4832 else |
4833 { | |
4834 x = -1; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4835 #ifdef FEAT_GUI_MSWIN |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4836 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4837 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4838 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4839 emsg(_("E371: Command not found")); |
3361 | 4840 #endif |
4841 } | |
3363 | 4842 |
4843 if (newcmd != cmdbase) | |
4844 vim_free(newcmd); | |
4845 | |
5627 | 4846 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) |
3361 | 4847 { |
5627 | 4848 /* Close the handle to \\.\NUL created above. */ |
3361 | 4849 CloseHandle(si.hStdInput); |
4850 } | |
4851 /* Close the handles to the subprocess, so that it goes away */ | |
4852 CloseHandle(pi.hThread); | |
4853 CloseHandle(pi.hProcess); | |
4854 } | |
4855 else | |
4856 { | |
16584
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4857 cmdlen = |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4858 #ifdef FEAT_GUI_MSWIN |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4859 ((gui.in_use || gui.starting) ? |
16584
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4860 (!s_dont_use_vimrun && p_stmp ? |
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4861 STRLEN(vimrun_path) : STRLEN(p_sh) + STRLEN(p_shcf)) |
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4862 : 0) + |
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4863 #endif |
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4864 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; |
1569 | 4865 |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
4866 newcmd = alloc(cmdlen); |
3361 | 4867 if (newcmd != NULL) |
7 | 4868 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4869 #if defined(FEAT_GUI_MSWIN) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4870 if ( |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4871 # ifdef VIMDLL |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4872 (gui.in_use || gui.starting) && |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4873 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4874 need_vimrun_warning) |
7 | 4875 { |
10400
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4876 char *msg = _("VIMRUN.EXE not found in your $PATH.\n" |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4877 "External commands will not pause after completion.\n" |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4878 "See :help win32-vimrun for more information."); |
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4879 char *title = _("Vim Warning"); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4880 WCHAR *wmsg = enc_to_utf16((char_u *)msg, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4881 WCHAR *wtitle = enc_to_utf16((char_u *)title, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4882 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4883 if (wmsg != NULL && wtitle != NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4884 MessageBoxW(NULL, wmsg, wtitle, MB_ICONWARNING); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4885 vim_free(wmsg); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4886 vim_free(wtitle); |
7 | 4887 need_vimrun_warning = FALSE; |
4888 } | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4889 if ( |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4890 # ifdef VIMDLL |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4891 (gui.in_use || gui.starting) && |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4892 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4893 !s_dont_use_vimrun && p_stmp) |
16750
8050cde51945
patch 8.1.1377: MS-Windows GUI uses wrong shell command for bash
Bram Moolenaar <Bram@vim.org>
parents:
16734
diff
changeset
|
4894 // Use vimrun to execute the command. It opens a console |
8050cde51945
patch 8.1.1377: MS-Windows GUI uses wrong shell command for bash
Bram Moolenaar <Bram@vim.org>
parents:
16734
diff
changeset
|
4895 // 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
|
4896 vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s", |
7 | 4897 vimrun_path, |
4898 (msg_silent != 0 || (options & SHELL_DOOUT)) | |
4899 ? "-s " : "", | |
4900 p_sh, p_shcf, cmd); | |
16750
8050cde51945
patch 8.1.1377: MS-Windows GUI uses wrong shell command for bash
Bram Moolenaar <Bram@vim.org>
parents:
16734
diff
changeset
|
4901 else if ( |
16584
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4902 # ifdef VIMDLL |
16750
8050cde51945
patch 8.1.1377: MS-Windows GUI uses wrong shell command for bash
Bram Moolenaar <Bram@vim.org>
parents:
16734
diff
changeset
|
4903 (gui.in_use || gui.starting) && |
16584
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4904 # endif |
17569
9544335db006
patch 8.1.1782: MS-Windows: system() has temp file error with 'noshelltemp'
Bram Moolenaar <Bram@vim.org>
parents:
17393
diff
changeset
|
4905 s_dont_use_vimrun && STRCMP(p_shcf, "/c") == 0) |
16750
8050cde51945
patch 8.1.1377: MS-Windows GUI uses wrong shell command for bash
Bram Moolenaar <Bram@vim.org>
parents:
16734
diff
changeset
|
4906 // workaround for the case that "vimrun" does not exist |
16584
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4907 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s %s %s", |
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4908 p_sh, p_shcf, p_sh, p_shcf, cmd); |
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4909 else |
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4910 #endif |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4911 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", |
1569 | 4912 p_sh, p_shcf, cmd); |
7 | 4913 x = mch_system((char *)newcmd, options); |
3361 | 4914 vim_free(newcmd); |
7 | 4915 } |
4916 } | |
4917 } | |
4918 | |
4919 if (tmode == TMODE_RAW) | |
4920 settmode(TMODE_RAW); /* set to raw mode */ | |
4921 | |
4922 /* Print the return value, unless "vimrun" was used. */ | |
4923 if (x != 0 && !(options & SHELL_SILENT) && !emsg_silent | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4924 #if defined(FEAT_GUI_MSWIN) |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4925 && ((gui.in_use || gui.starting) ? |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4926 ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) : 1) |
7 | 4927 #endif |
4928 ) | |
4929 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
4930 smsg(_("shell returned %d"), x); |
7 | 4931 msg_putchar('\n'); |
4932 } | |
4933 #ifdef FEAT_TITLE | |
4934 resettitle(); | |
4935 #endif | |
4936 | |
4937 signal(SIGINT, SIG_DFL); | |
4938 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4939 signal(SIGKILL, SIG_DFL); | |
4940 #else | |
4941 signal(SIGBREAK, SIG_DFL); | |
4942 #endif | |
4943 signal(SIGILL, SIG_DFL); | |
4944 signal(SIGFPE, SIG_DFL); | |
4945 signal(SIGSEGV, SIG_DFL); | |
4946 signal(SIGTERM, SIG_DFL); | |
4947 signal(SIGABRT, SIG_DFL); | |
4948 | |
4949 return x; | |
4950 } | |
4951 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4952 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4953 static HANDLE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4954 job_io_file_open( |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4955 char_u *fname, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4956 DWORD dwDesiredAccess, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4957 DWORD dwShareMode, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4958 LPSECURITY_ATTRIBUTES lpSecurityAttributes, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4959 DWORD dwCreationDisposition, |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
4960 DWORD dwFlagsAndAttributes) |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4961 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4962 HANDLE h; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4963 WCHAR *wn; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4964 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4965 wn = enc_to_utf16(fname, NULL); |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4966 if (wn == NULL) |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4967 return INVALID_HANDLE_VALUE; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4968 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4969 h = CreateFileW(wn, dwDesiredAccess, dwShareMode, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4970 lpSecurityAttributes, dwCreationDisposition, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4971 dwFlagsAndAttributes, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4972 vim_free(wn); |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4973 return h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4974 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4975 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4976 /* |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4977 * Turn the dictionary "env" into a NUL separated list that can be used as the |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4978 * environment argument of vim_create_process(). |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4979 */ |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12140
diff
changeset
|
4980 void |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
4981 win32_build_env(dict_T *env, garray_T *gap, int is_terminal) |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4982 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4983 hashitem_T *hi; |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
4984 long_u todo = env != NULL ? env->dv_hashtab.ht_used : 0; |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4985 LPVOID base = GetEnvironmentStringsW(); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4986 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4987 /* for last \0 */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4988 if (ga_grow(gap, 1) == FAIL) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4989 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4990 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4991 if (base) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4992 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4993 WCHAR *p = (WCHAR*) base; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4994 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4995 /* for last \0 */ |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4996 if (ga_grow(gap, 1) == FAIL) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4997 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4998 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4999 while (*p != 0 || *(p + 1) != 0) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5000 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5001 if (ga_grow(gap, 1) == OK) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5002 *((WCHAR*)gap->ga_data + gap->ga_len++) = *p; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5003 p++; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5004 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5005 FreeEnvironmentStrings(base); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5006 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5007 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5008 |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5009 if (env != NULL) |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5010 { |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5011 for (hi = env->dv_hashtab.ht_array; todo > 0; ++hi) |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5012 { |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5013 if (!HASHITEM_EMPTY(hi)) |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5014 { |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5015 typval_T *item = &dict_lookup(hi)->di_tv; |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5016 WCHAR *wkey = enc_to_utf16((char_u *)hi->hi_key, NULL); |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
5017 WCHAR *wval = enc_to_utf16(tv_get_string(item), NULL); |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5018 --todo; |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5019 if (wkey != NULL && wval != NULL) |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5020 { |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5021 size_t n; |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5022 size_t lkey = wcslen(wkey); |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5023 size_t lval = wcslen(wval); |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5024 |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5025 if (ga_grow(gap, (int)(lkey + lval + 2)) != OK) |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5026 continue; |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5027 for (n = 0; n < lkey; n++) |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5028 *((WCHAR*)gap->ga_data + gap->ga_len++) = wkey[n]; |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5029 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'='; |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5030 for (n = 0; n < lval; n++) |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5031 *((WCHAR*)gap->ga_data + gap->ga_len++) = wval[n]; |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5032 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5033 } |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
5034 vim_free(wkey); |
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
5035 vim_free(wval); |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5036 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5037 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5038 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5039 |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5040 # if defined(FEAT_CLIENTSERVER) || defined(FEAT_TERMINAL) |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5041 { |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5042 # ifdef FEAT_CLIENTSERVER |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5043 char_u *servername = get_vim_var_str(VV_SEND_SERVER); |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5044 size_t servername_len = STRLEN(servername); |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5045 # endif |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5046 # ifdef FEAT_TERMINAL |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5047 char_u *version = get_vim_var_str(VV_VERSION); |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5048 size_t version_len = STRLEN(version); |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5049 # endif |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5050 // size of "VIM_SERVERNAME=" and value, |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5051 // plus "VIM_TERMINAL=" and value, |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5052 // plus two terminating NULs |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5053 size_t n = 0 |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5054 # ifdef FEAT_CLIENTSERVER |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5055 + 15 + servername_len |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5056 # endif |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5057 # ifdef FEAT_TERMINAL |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5058 + 13 + version_len + 2 |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5059 # endif |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5060 ; |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5061 |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5062 if (ga_grow(gap, (int)n) == OK) |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5063 { |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5064 # ifdef FEAT_CLIENTSERVER |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5065 for (n = 0; n < 15; n++) |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5066 *((WCHAR*)gap->ga_data + gap->ga_len++) = |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5067 (WCHAR)"VIM_SERVERNAME="[n]; |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5068 for (n = 0; n < servername_len; n++) |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5069 *((WCHAR*)gap->ga_data + gap->ga_len++) = |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5070 (WCHAR)servername[n]; |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5071 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5072 # endif |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5073 # ifdef FEAT_TERMINAL |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5074 if (is_terminal) |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5075 { |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5076 for (n = 0; n < 13; n++) |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5077 *((WCHAR*)gap->ga_data + gap->ga_len++) = |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5078 (WCHAR)"VIM_TERMINAL="[n]; |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5079 for (n = 0; n < version_len; n++) |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5080 *((WCHAR*)gap->ga_data + gap->ga_len++) = |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5081 (WCHAR)version[n]; |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5082 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5083 } |
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14063
diff
changeset
|
5084 # endif |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5085 } |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5086 } |
14067
39ec4b90e4a7
patch 8.1.0051: MS-Windows: missing #endif
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
5087 # endif |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5088 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5089 |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5090 /* |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5091 * Create a pair of pipes. |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5092 * Return TRUE for success, FALSE for failure. |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5093 */ |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5094 static BOOL |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5095 create_pipe_pair(HANDLE handles[2]) |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5096 { |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5097 static LONG s; |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5098 char name[64]; |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5099 SECURITY_ATTRIBUTES sa; |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5100 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5101 sprintf(name, "\\\\?\\pipe\\vim-%08lx-%08lx", |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5102 GetCurrentProcessId(), |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5103 InterlockedIncrement(&s)); |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5104 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5105 // Create named pipe. Max size of named pipe is 65535. |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5106 handles[1] = CreateNamedPipe( |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5107 name, |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5108 PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED, |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5109 PIPE_TYPE_BYTE | PIPE_NOWAIT, |
15621
bfbdef46aa7d
patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw()
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
5110 1, MAX_NAMED_PIPE_SIZE, 0, 0, NULL); |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5111 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5112 if (handles[1] == INVALID_HANDLE_VALUE) |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5113 return FALSE; |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5114 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5115 sa.nLength = sizeof(sa); |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5116 sa.bInheritHandle = TRUE; |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5117 sa.lpSecurityDescriptor = NULL; |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5118 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5119 handles[0] = CreateFile(name, |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5120 FILE_GENERIC_READ, |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5121 FILE_SHARE_READ, &sa, |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5122 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5123 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5124 if (handles[0] == INVALID_HANDLE_VALUE) |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5125 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5126 CloseHandle(handles[1]); |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5127 return FALSE; |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5128 } |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5129 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5130 return TRUE; |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5131 } |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5132 |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5133 void |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11230
diff
changeset
|
5134 mch_job_start(char *cmd, job_T *job, jobopt_T *options) |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5135 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5136 STARTUPINFO si; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5137 PROCESS_INFORMATION pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5138 HANDLE jo; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5139 SECURITY_ATTRIBUTES saAttr; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5140 channel_T *channel = NULL; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5141 HANDLE ifd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5142 HANDLE ofd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5143 HANDLE efd[2]; |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5144 garray_T ga; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5145 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5146 int use_null_for_in = options->jo_io[PART_IN] == JIO_NULL; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5147 int use_null_for_out = options->jo_io[PART_OUT] == JIO_NULL; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5148 int use_null_for_err = options->jo_io[PART_ERR] == JIO_NULL; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5149 int use_file_for_in = options->jo_io[PART_IN] == JIO_FILE; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5150 int use_file_for_out = options->jo_io[PART_OUT] == JIO_FILE; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5151 int use_file_for_err = options->jo_io[PART_ERR] == JIO_FILE; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5152 int use_out_for_err = options->jo_io[PART_ERR] == JIO_OUT; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5153 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5154 if (use_out_for_err && use_null_for_out) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5155 use_null_for_err = TRUE; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5156 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5157 ifd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5158 ifd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5159 ofd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5160 ofd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5161 efd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5162 efd[1] = INVALID_HANDLE_VALUE; |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5163 ga_init2(&ga, (int)sizeof(wchar_t), 500); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5164 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5165 jo = CreateJobObject(NULL, NULL); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5166 if (jo == NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5167 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5168 job->jv_status = JOB_FAILED; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5169 goto failed; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5170 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5171 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5172 if (options->jo_env != NULL) |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
5173 win32_build_env(options->jo_env, &ga, FALSE); |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5174 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5175 ZeroMemory(&pi, sizeof(pi)); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5176 ZeroMemory(&si, sizeof(si)); |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5177 si.cb = sizeof(si); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5178 si.dwFlags |= STARTF_USESHOWWINDOW; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5179 si.wShowWindow = SW_HIDE; |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5180 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5181 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5182 saAttr.bInheritHandle = TRUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5183 saAttr.lpSecurityDescriptor = NULL; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5184 |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5185 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5186 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5187 char_u *fname = options->jo_io_name[PART_IN]; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5188 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5189 ifd[0] = job_io_file_open(fname, GENERIC_READ, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5190 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5191 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5192 if (ifd[0] == INVALID_HANDLE_VALUE) |
8443
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5193 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5194 semsg(_(e_notopen), fname); |
8443
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5195 goto failed; |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5196 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5197 } |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5198 else if (!use_null_for_in |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5199 && (!create_pipe_pair(ifd) |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5200 || !SetHandleInformation(ifd[1], HANDLE_FLAG_INHERIT, 0))) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5201 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5202 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5203 if (use_file_for_out) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5204 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5205 char_u *fname = options->jo_io_name[PART_OUT]; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5206 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5207 ofd[1] = job_io_file_open(fname, GENERIC_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5208 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5209 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5210 if (ofd[1] == INVALID_HANDLE_VALUE) |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5211 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5212 semsg(_(e_notopen), fname); |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5213 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5214 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5215 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5216 else if (!use_null_for_out && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5217 (!CreatePipe(&ofd[0], &ofd[1], &saAttr, 0) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5218 || !SetHandleInformation(ofd[0], HANDLE_FLAG_INHERIT, 0))) |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5219 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5220 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5221 if (use_file_for_err) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5222 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5223 char_u *fname = options->jo_io_name[PART_ERR]; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5224 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5225 efd[1] = job_io_file_open(fname, GENERIC_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5226 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5227 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5228 if (efd[1] == INVALID_HANDLE_VALUE) |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5229 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5230 semsg(_(e_notopen), fname); |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5231 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5232 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5233 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5234 else if (!use_out_for_err && !use_null_for_err && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5235 (!CreatePipe(&efd[0], &efd[1], &saAttr, 0) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
5236 || !SetHandleInformation(efd[0], HANDLE_FLAG_INHERIT, 0))) |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5237 goto failed; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5238 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5239 si.dwFlags |= STARTF_USESTDHANDLES; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5240 si.hStdInput = ifd[0]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5241 si.hStdOutput = ofd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5242 si.hStdError = use_out_for_err ? ofd[1] : efd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5243 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5244 if (!use_null_for_in || !use_null_for_out || !use_null_for_err) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5245 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5246 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5247 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5248 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5249 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5250 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5251 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5252 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5253 channel = add_channel(); |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5254 if (channel == NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5255 goto failed; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5256 } |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5257 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5258 if (!vim_create_process(cmd, TRUE, |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5259 CREATE_SUSPENDED | |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5260 CREATE_DEFAULT_ERROR_MODE | |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5261 CREATE_NEW_PROCESS_GROUP | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5262 CREATE_UNICODE_ENVIRONMENT | |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5263 CREATE_NEW_CONSOLE, |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5264 &si, &pi, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5265 ga.ga_data, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5266 (char *)options->jo_cwd)) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5267 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5268 CloseHandle(jo); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5269 job->jv_status = JOB_FAILED; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5270 goto failed; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5271 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5272 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5273 ga_clear(&ga); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5274 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5275 if (!AssignProcessToJobObject(jo, pi.hProcess)) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5276 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5277 /* if failing, switch the way to terminate |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5278 * process with TerminateProcess. */ |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5279 CloseHandle(jo); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5280 jo = NULL; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5281 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5282 ResumeThread(pi.hThread); |
8479
9f63e4506c40
commit https://github.com/vim/vim/commit/75578a388d2aff59dc330ceccd8894c79b4bc735
Christian Brabandt <cb@256bit.org>
parents:
8471
diff
changeset
|
5283 CloseHandle(pi.hThread); |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5284 job->jv_proc_info = pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5285 job->jv_job_object = jo; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5286 job->jv_status = JOB_STARTED; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5287 |
10060
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5288 CloseHandle(ifd[0]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5289 CloseHandle(ofd[1]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5290 if (!use_out_for_err && !use_null_for_err) |
8384
764dba33605c
commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
5291 CloseHandle(efd[1]); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5292 |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5293 job->jv_channel = channel; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5294 if (channel != NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5295 { |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5296 channel_set_pipes(channel, |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5297 use_file_for_in || use_null_for_in |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5298 ? INVALID_FD : (sock_T)ifd[1], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5299 use_file_for_out || use_null_for_out |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5300 ? INVALID_FD : (sock_T)ofd[0], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5301 use_out_for_err || use_file_for_err || use_null_for_err |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5302 ? INVALID_FD : (sock_T)efd[0]); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5303 channel_set_job(channel, job, options); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5304 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5305 return; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5306 |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5307 failed: |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5308 CloseHandle(ifd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5309 CloseHandle(ofd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5310 CloseHandle(efd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5311 CloseHandle(ifd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5312 CloseHandle(ofd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5313 CloseHandle(efd[1]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5314 channel_unref(channel); |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5315 ga_clear(&ga); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5316 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5317 |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5318 char * |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5319 mch_job_status(job_T *job) |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5320 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5321 DWORD dwExitCode = 0; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5322 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5323 if (!GetExitCodeProcess(job->jv_proc_info.hProcess, &dwExitCode) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5324 || dwExitCode != STILL_ACTIVE) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5325 { |
8176
477c1d855698
commit https://github.com/vim/vim/commit/eab089d22f172ddd2d33367a998e68c2f1c6c989
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
5326 job->jv_exitval = (int)dwExitCode; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10317
diff
changeset
|
5327 if (job->jv_status < JOB_ENDED) |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5328 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5329 ch_log(job->jv_channel, "Job ended"); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5330 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5331 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5332 return "dead"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5333 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5334 return "run"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5335 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5336 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5337 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5338 mch_detect_ended_job(job_T *job_list) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5339 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5340 HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5341 job_T *jobArray[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5342 job_T *job = job_list; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5343 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5344 while (job != NULL) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5345 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5346 DWORD n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5347 DWORD result; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5348 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5349 for (n = 0; n < MAXIMUM_WAIT_OBJECTS |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5350 && job != NULL; job = job->jv_next) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5351 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5352 if (job->jv_status == JOB_STARTED) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5353 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5354 jobHandles[n] = job->jv_proc_info.hProcess; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5355 jobArray[n] = job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5356 ++n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5357 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5358 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5359 if (n == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5360 continue; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5361 result = WaitForMultipleObjects(n, jobHandles, FALSE, 0); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5362 if (result >= WAIT_OBJECT_0 && result < WAIT_OBJECT_0 + n) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5363 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5364 job_T *wait_job = jobArray[result - WAIT_OBJECT_0]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5365 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5366 if (STRCMP(mch_job_status(wait_job), "dead") == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5367 return wait_job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5368 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5369 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5370 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5371 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5372 |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5373 static BOOL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5374 terminate_all(HANDLE process, int code) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5375 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5376 PROCESSENTRY32 pe; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5377 HANDLE h = INVALID_HANDLE_VALUE; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5378 DWORD pid = GetProcessId(process); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5379 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5380 if (pid != 0) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5381 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5382 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5383 if (h != INVALID_HANDLE_VALUE) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5384 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5385 pe.dwSize = sizeof(PROCESSENTRY32); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5386 if (!Process32First(h, &pe)) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5387 goto theend; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5388 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5389 do |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5390 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5391 if (pe.th32ParentProcessID == pid) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5392 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5393 HANDLE ph = OpenProcess( |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5394 PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5395 if (ph != NULL) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5396 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5397 terminate_all(ph, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5398 CloseHandle(ph); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5399 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5400 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5401 } while (Process32Next(h, &pe)); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5402 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5403 CloseHandle(h); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5404 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5405 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5406 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5407 theend: |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5408 return TerminateProcess(process, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5409 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5410 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5411 /* |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5412 * Send a (deadly) signal to "job". |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5413 * Return FAIL if it didn't work. |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5414 */ |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5415 int |
12037
85f0f557661e
patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
5416 mch_signal_job(job_T *job, char_u *how) |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5417 { |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5418 int ret; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5419 |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5420 if (STRCMP(how, "term") == 0 || STRCMP(how, "kill") == 0 || *how == NUL) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5421 { |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5422 /* deadly signal */ |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5423 if (job->jv_job_object != NULL) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
5424 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
5425 if (job->jv_channel != NULL && job->jv_channel->ch_anonymous_pipe) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
5426 job->jv_channel->ch_killing = TRUE; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5427 return TerminateJobObject(job->jv_job_object, 0) ? OK : FAIL; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
5428 } |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5429 return terminate_all(job->jv_proc_info.hProcess, 0) ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5430 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5431 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5432 if (!AttachConsole(job->jv_proc_info.dwProcessId)) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5433 return FAIL; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5434 ret = GenerateConsoleCtrlEvent( |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5435 STRCMP(how, "int") == 0 ? CTRL_C_EVENT : CTRL_BREAK_EVENT, |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5436 job->jv_proc_info.dwProcessId) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5437 ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5438 FreeConsole(); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5439 return ret; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5440 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5441 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5442 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5443 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5444 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5445 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5446 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5447 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5448 if (job->jv_status != JOB_FAILED) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5449 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5450 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5451 CloseHandle(job->jv_job_object); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5452 CloseHandle(job->jv_proc_info.hProcess); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5453 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5454 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5455 #endif |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5456 |
7 | 5457 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
5458 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 5459 |
5460 /* | |
5461 * Start termcap mode | |
5462 */ | |
5463 static void | |
5464 termcap_mode_start(void) | |
5465 { | |
5466 DWORD cmodein; | |
5467 | |
5468 if (g_fTermcapMode) | |
5469 return; | |
5470 | |
5471 SaveConsoleBuffer(&g_cbNonTermcap); | |
5472 | |
5473 if (g_cbTermcap.IsValid) | |
5474 { | |
5475 /* | |
5476 * We've been in termcap mode before. Restore certain screen | |
5477 * characteristics, including the buffer size and the window | |
5478 * size. Since we will be redrawing the screen, we don't need | |
5479 * to restore the actual contents of the buffer. | |
5480 */ | |
5481 RestoreConsoleBuffer(&g_cbTermcap, FALSE); | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5482 reset_console_color_rgb(); |
7 | 5483 SetConsoleWindowInfo(g_hConOut, TRUE, &g_cbTermcap.Info.srWindow); |
5484 Rows = g_cbTermcap.Info.dwSize.Y; | |
5485 Columns = g_cbTermcap.Info.dwSize.X; | |
5486 } | |
5487 else | |
5488 { | |
5489 /* | |
5490 * This is our first time entering termcap mode. Clear the console | |
5491 * screen buffer, and resize the buffer to match the current window | |
5492 * size. We will use this as the size of our editing environment. | |
5493 */ | |
5494 ClearConsoleBuffer(g_attrCurrent); | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5495 set_console_color_rgb(); |
7 | 5496 ResizeConBufAndWindow(g_hConOut, Columns, Rows); |
5497 } | |
5498 | |
5499 #ifdef FEAT_TITLE | |
5500 resettitle(); | |
5501 #endif | |
5502 | |
5503 GetConsoleMode(g_hConIn, &cmodein); | |
5504 #ifdef FEAT_MOUSE | |
5505 if (g_fMouseActive) | |
5506 cmodein |= ENABLE_MOUSE_INPUT; | |
5507 else | |
5508 cmodein &= ~ENABLE_MOUSE_INPUT; | |
5509 #endif | |
5510 cmodein |= ENABLE_WINDOW_INPUT; | |
5511 SetConsoleMode(g_hConIn, cmodein); | |
5512 | |
5513 redraw_later_clear(); | |
5514 g_fTermcapMode = TRUE; | |
5515 } | |
5516 | |
5517 | |
5518 /* | |
5519 * End termcap mode | |
5520 */ | |
5521 static void | |
5522 termcap_mode_end(void) | |
5523 { | |
5524 DWORD cmodein; | |
5525 ConsoleBuffer *cb; | |
5526 COORD coord; | |
5527 DWORD dwDummy; | |
5528 | |
5529 if (!g_fTermcapMode) | |
5530 return; | |
5531 | |
5532 SaveConsoleBuffer(&g_cbTermcap); | |
5533 | |
5534 GetConsoleMode(g_hConIn, &cmodein); | |
5535 cmodein &= ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT); | |
5536 SetConsoleMode(g_hConIn, cmodein); | |
5537 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5538 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5539 cb = exiting ? &g_cbOrig : &g_cbNonTermcap; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5540 #else |
7 | 5541 cb = &g_cbNonTermcap; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5542 #endif |
7 | 5543 RestoreConsoleBuffer(cb, p_rs); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5544 reset_console_color_rgb(); |
7 | 5545 SetConsoleCursorInfo(g_hConOut, &g_cci); |
5546 | |
5547 if (p_rs || exiting) | |
5548 { | |
5549 /* | |
5550 * Clear anything that happens to be on the current line. | |
5551 */ | |
5552 coord.X = 0; | |
5553 coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); | |
5554 FillConsoleOutputCharacter(g_hConOut, ' ', | |
5555 cb->Info.dwSize.X, coord, &dwDummy); | |
5556 /* | |
5557 * The following is just for aesthetics. If we are exiting without | |
5558 * restoring the screen, then we want to have a prompt string | |
5559 * appear at the bottom line. However, the command interpreter | |
5560 * seems to always advance the cursor one line before displaying | |
5561 * the prompt string, which causes the screen to scroll. To | |
5562 * counter this, move the cursor up one line before exiting. | |
5563 */ | |
5564 if (exiting && !p_rs) | |
5565 coord.Y--; | |
5566 /* | |
5567 * Position the cursor at the leftmost column of the desired row. | |
5568 */ | |
5569 SetConsoleCursorPosition(g_hConOut, coord); | |
5570 } | |
5571 | |
5572 g_fTermcapMode = FALSE; | |
5573 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5574 #endif /* FEAT_GUI_MSWIN */ |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5575 |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5576 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
5577 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 5578 void |
5579 mch_write( | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
5580 char_u *s UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
5581 int len UNUSED) |
7 | 5582 { |
5583 /* never used */ | |
5584 } | |
5585 | |
5586 #else | |
5587 | |
5588 /* | |
5589 * clear `n' chars, starting from `coord' | |
5590 */ | |
5591 static void | |
5592 clear_chars( | |
5593 COORD coord, | |
5594 DWORD n) | |
5595 { | |
5596 DWORD dwDummy; | |
5597 | |
5598 FillConsoleOutputCharacter(g_hConOut, ' ', n, coord, &dwDummy); | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5599 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5600 if (!USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5601 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, n, coord, &dwDummy); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5602 else |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5603 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5604 set_console_color_rgb(); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5605 gotoxy(coord.X + 1, coord.Y + 1); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5606 vtp_printf("\033[%dX", n); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5607 } |
7 | 5608 } |
5609 | |
5610 | |
5611 /* | |
5612 * Clear the screen | |
5613 */ | |
5614 static void | |
5615 clear_screen(void) | |
5616 { | |
5617 g_coord.X = g_coord.Y = 0; | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5618 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5619 if (!USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5620 clear_chars(g_coord, Rows * Columns); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5621 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5622 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5623 set_console_color_rgb(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5624 gotoxy(1, 1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5625 vtp_printf("\033[2J"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5626 } |
7 | 5627 } |
5628 | |
5629 | |
5630 /* | |
5631 * Clear to end of display | |
5632 */ | |
5633 static void | |
5634 clear_to_end_of_display(void) | |
5635 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5636 COORD save = g_coord; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5637 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5638 if (!USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5639 clear_chars(g_coord, (Rows - g_coord.Y - 1) |
7 | 5640 * Columns + (Columns - g_coord.X)); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5641 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5642 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5643 set_console_color_rgb(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5644 gotoxy(g_coord.X + 1, g_coord.Y + 1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5645 vtp_printf("\033[0J"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5646 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5647 gotoxy(save.X + 1, save.Y + 1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5648 g_coord = save; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5649 } |
7 | 5650 } |
5651 | |
5652 | |
5653 /* | |
5654 * Clear to end of line | |
5655 */ | |
5656 static void | |
5657 clear_to_end_of_line(void) | |
5658 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5659 COORD save = g_coord; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5660 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5661 if (!USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5662 clear_chars(g_coord, Columns - g_coord.X); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5663 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5664 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5665 set_console_color_rgb(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5666 gotoxy(g_coord.X + 1, g_coord.Y + 1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5667 vtp_printf("\033[0K"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5668 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5669 gotoxy(save.X + 1, save.Y + 1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5670 g_coord = save; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5671 } |
7 | 5672 } |
5673 | |
5674 | |
5675 /* | |
5676 * Scroll the scroll region up by `cLines' lines | |
5677 */ | |
5678 static void | |
26 | 5679 scroll(unsigned cLines) |
7 | 5680 { |
5681 COORD oldcoord = g_coord; | |
5682 | |
5683 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); | |
5684 delete_lines(cLines); | |
5685 | |
5686 g_coord = oldcoord; | |
5687 } | |
5688 | |
5689 | |
5690 /* | |
5691 * Set the scroll region | |
5692 */ | |
5693 static void | |
5694 set_scroll_region( | |
5695 unsigned left, | |
5696 unsigned top, | |
5697 unsigned right, | |
5698 unsigned bottom) | |
5699 { | |
5700 if (left >= right | |
5701 || top >= bottom | |
5702 || right > (unsigned) Columns - 1 | |
5703 || bottom > (unsigned) Rows - 1) | |
5704 return; | |
5705 | |
5706 g_srScrollRegion.Left = left; | |
5707 g_srScrollRegion.Top = top; | |
5708 g_srScrollRegion.Right = right; | |
5709 g_srScrollRegion.Bottom = bottom; | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5710 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5711 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5712 static void |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5713 set_scroll_region_tb( |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5714 unsigned top, |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5715 unsigned bottom) |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5716 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5717 if (top >= bottom || bottom > (unsigned)Rows - 1) |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5718 return; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5719 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5720 g_srScrollRegion.Top = top; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5721 g_srScrollRegion.Bottom = bottom; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5722 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5723 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5724 static void |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5725 set_scroll_region_lr( |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5726 unsigned left, |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5727 unsigned right) |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5728 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5729 if (left >= right || right > (unsigned)Columns - 1) |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5730 return; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5731 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5732 g_srScrollRegion.Left = left; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5733 g_srScrollRegion.Right = right; |
7 | 5734 } |
5735 | |
5736 | |
5737 /* | |
5738 * Insert `cLines' lines at the current cursor position | |
5739 */ | |
5740 static void | |
26 | 5741 insert_lines(unsigned cLines) |
7 | 5742 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5743 SMALL_RECT source, clip; |
7 | 5744 COORD dest; |
5745 CHAR_INFO fill; | |
5746 | |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5747 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5748 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5749 dest.X = g_srScrollRegion.Left; |
7 | 5750 dest.Y = g_coord.Y + cLines; |
5751 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5752 source.Left = g_srScrollRegion.Left; |
7 | 5753 source.Top = g_coord.Y; |
5754 source.Right = g_srScrollRegion.Right; | |
5755 source.Bottom = g_srScrollRegion.Bottom - cLines; | |
5756 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5757 clip.Left = g_srScrollRegion.Left; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5758 clip.Top = g_coord.Y; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5759 clip.Right = g_srScrollRegion.Right; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5760 clip.Bottom = g_srScrollRegion.Bottom; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5761 |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5762 fill.Char.AsciiChar = ' '; |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5763 if (!USE_VTP) |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5764 fill.Attributes = g_attrCurrent; |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5765 else |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5766 fill.Attributes = g_attrDefault; |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5767 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5768 set_console_color_rgb(); |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5769 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5770 ScrollConsoleScreenBuffer(g_hConOut, &source, &clip, dest, &fill); |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5771 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5772 // Here we have to deal with a win32 console flake: If the scroll |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5773 // region looks like abc and we scroll c to a and fill with d we get |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5774 // cbd... if we scroll block c one line at a time to a, we get cdd... |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5775 // vim expects cdd consistently... So we have to deal with that |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5776 // here... (this also occurs scrolling the same way in the other |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5777 // direction). |
7 | 5778 |
5779 if (source.Bottom < dest.Y) | |
5780 { | |
5781 COORD coord; | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5782 int i; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5783 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5784 coord.X = source.Left; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5785 for (i = clip.Top; i < dest.Y; ++i) |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5786 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5787 coord.Y = i; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5788 clear_chars(coord, source.Right - source.Left + 1); |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5789 } |
7 | 5790 } |
5791 } | |
5792 | |
5793 | |
5794 /* | |
5795 * Delete `cLines' lines at the current cursor position | |
5796 */ | |
5797 static void | |
26 | 5798 delete_lines(unsigned cLines) |
7 | 5799 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5800 SMALL_RECT source, clip; |
7 | 5801 COORD dest; |
5802 CHAR_INFO fill; | |
5803 int nb; | |
5804 | |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5805 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5806 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5807 dest.X = g_srScrollRegion.Left; |
7 | 5808 dest.Y = g_coord.Y; |
5809 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5810 source.Left = g_srScrollRegion.Left; |
7 | 5811 source.Top = g_coord.Y + cLines; |
5812 source.Right = g_srScrollRegion.Right; | |
5813 source.Bottom = g_srScrollRegion.Bottom; | |
5814 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5815 clip.Left = g_srScrollRegion.Left; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5816 clip.Top = g_coord.Y; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5817 clip.Right = g_srScrollRegion.Right; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5818 clip.Bottom = g_srScrollRegion.Bottom; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5819 |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5820 fill.Char.AsciiChar = ' '; |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5821 if (!USE_VTP) |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5822 fill.Attributes = g_attrCurrent; |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5823 else |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5824 fill.Attributes = g_attrDefault; |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5825 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5826 set_console_color_rgb(); |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5827 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5828 ScrollConsoleScreenBuffer(g_hConOut, &source, &clip, dest, &fill); |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5829 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5830 // Here we have to deal with a win32 console flake; See insert_lines() |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5831 // above. |
7 | 5832 |
5833 nb = dest.Y + (source.Bottom - source.Top) + 1; | |
5834 | |
5835 if (nb < source.Top) | |
5836 { | |
5837 COORD coord; | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5838 int i; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5839 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5840 coord.X = source.Left; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5841 for (i = nb; i < clip.Bottom; ++i) |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5842 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5843 coord.Y = i; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5844 clear_chars(coord, source.Right - source.Left + 1); |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5845 } |
7 | 5846 } |
5847 } | |
5848 | |
5849 | |
5850 /* | |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5851 * Set the cursor position to (x,y) (1-based). |
7 | 5852 */ |
5853 static void | |
5854 gotoxy( | |
5855 unsigned x, | |
5856 unsigned y) | |
5857 { | |
5858 if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) | |
5859 return; | |
5860 | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5861 if (!USE_VTP) |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5862 { |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5863 // external cursor coords are 1-based; internal are 0-based |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5864 g_coord.X = x - 1; |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5865 g_coord.Y = y - 1; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5866 SetConsoleCursorPosition(g_hConOut, g_coord); |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5867 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5868 else |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5869 { |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5870 // Move the cursor to the left edge of the screen to prevent screen |
18275
5218e26c658f
patch 8.1.2132: MS-Windows: screen mess when not recognizing insider build
Bram Moolenaar <Bram@vim.org>
parents:
18241
diff
changeset
|
5871 // destruction. Insider build bug. Always enabled because it's cheap |
5218e26c658f
patch 8.1.2132: MS-Windows: screen mess when not recognizing insider build
Bram Moolenaar <Bram@vim.org>
parents:
18241
diff
changeset
|
5872 // and avoids mistakes with recognizing the build. |
5218e26c658f
patch 8.1.2132: MS-Windows: screen mess when not recognizing insider build
Bram Moolenaar <Bram@vim.org>
parents:
18241
diff
changeset
|
5873 vtp_printf("\033[%d;%dH", g_coord.Y + 1, 1); |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5874 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5875 vtp_printf("\033[%d;%dH", y, x); |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5876 |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5877 g_coord.X = x - 1; |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5878 g_coord.Y = y - 1; |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5879 } |
7 | 5880 } |
5881 | |
5882 | |
5883 /* | |
5884 * Set the current text attribute = (foreground | background) | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
5885 * See ../runtime/doc/os_win32.txt for the numbers. |
7 | 5886 */ |
5887 static void | |
26 | 5888 textattr(WORD wAttr) |
7 | 5889 { |
6710 | 5890 g_attrCurrent = wAttr & 0xff; |
7 | 5891 |
5892 SetConsoleTextAttribute(g_hConOut, wAttr); | |
5893 } | |
5894 | |
5895 | |
5896 static void | |
26 | 5897 textcolor(WORD wAttr) |
7 | 5898 { |
6710 | 5899 g_attrCurrent = (g_attrCurrent & 0xf0) + (wAttr & 0x0f); |
7 | 5900 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5901 if (!USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5902 SetConsoleTextAttribute(g_hConOut, g_attrCurrent); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5903 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5904 vtp_sgr_bulk(wAttr); |
7 | 5905 } |
5906 | |
5907 | |
5908 static void | |
26 | 5909 textbackground(WORD wAttr) |
7 | 5910 { |
6710 | 5911 g_attrCurrent = (g_attrCurrent & 0x0f) + ((wAttr & 0x0f) << 4); |
7 | 5912 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5913 if (!USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5914 SetConsoleTextAttribute(g_hConOut, g_attrCurrent); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5915 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5916 vtp_sgr_bulk(wAttr); |
7 | 5917 } |
5918 | |
5919 | |
5920 /* | |
5921 * restore the default text attribute (whatever we started with) | |
5922 */ | |
5923 static void | |
26 | 5924 normvideo(void) |
7 | 5925 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5926 if (!USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5927 textattr(g_attrDefault); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5928 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5929 vtp_sgr_bulk(0); |
7 | 5930 } |
5931 | |
5932 | |
5933 static WORD g_attrPreStandout = 0; | |
5934 | |
5935 /* | |
5936 * Make the text standout, by brightening it | |
5937 */ | |
5938 static void | |
5939 standout(void) | |
5940 { | |
5941 g_attrPreStandout = g_attrCurrent; | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5942 |
7 | 5943 textattr((WORD) (g_attrCurrent|FOREGROUND_INTENSITY|BACKGROUND_INTENSITY)); |
5944 } | |
5945 | |
5946 | |
5947 /* | |
5948 * Turn off standout mode | |
5949 */ | |
5950 static void | |
26 | 5951 standend(void) |
7 | 5952 { |
5953 if (g_attrPreStandout) | |
5954 textattr(g_attrPreStandout); | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5955 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5956 g_attrPreStandout = 0; |
7 | 5957 } |
5958 | |
5959 | |
5960 /* | |
1199 | 5961 * Set normal fg/bg color, based on T_ME. Called when t_me has been set. |
7 | 5962 */ |
5963 void | |
26 | 5964 mch_set_normal_colors(void) |
7 | 5965 { |
5966 char_u *p; | |
5967 int n; | |
5968 | |
5969 cterm_normal_fg_color = (g_attrDefault & 0xf) + 1; | |
5970 cterm_normal_bg_color = ((g_attrDefault >> 4) & 0xf) + 1; | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5971 if ( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5972 #ifdef FEAT_TERMGUICOLORS |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5973 !p_tgc && |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5974 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5975 T_ME[0] == ESC && T_ME[1] == '|') |
7 | 5976 { |
5977 p = T_ME + 2; | |
5978 n = getdigits(&p); | |
5979 if (*p == 'm' && n > 0) | |
5980 { | |
5981 cterm_normal_fg_color = (n & 0xf) + 1; | |
5982 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1; | |
5983 } | |
5984 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5985 #ifdef FEAT_TERMGUICOLORS |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5986 cterm_normal_fg_gui_color = INVALCOLOR; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5987 cterm_normal_bg_gui_color = INVALCOLOR; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5988 #endif |
7 | 5989 } |
5990 | |
5991 | |
5992 /* | |
5993 * visual bell: flash the screen | |
5994 */ | |
5995 static void | |
26 | 5996 visual_bell(void) |
7 | 5997 { |
5998 COORD coordOrigin = {0, 0}; | |
5999 WORD attrFlash = ~g_attrCurrent & 0xff; | |
6000 | |
6001 DWORD dwDummy; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6002 LPWORD oldattrs = ALLOC_MULT(WORD, Rows * Columns); |
7 | 6003 |
6004 if (oldattrs == NULL) | |
6005 return; | |
6006 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
6007 coordOrigin, &dwDummy); | |
6008 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, | |
6009 coordOrigin, &dwDummy); | |
6010 | |
6011 Sleep(15); /* wait for 15 msec */ | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6012 if (!USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6013 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, |
7 | 6014 coordOrigin, &dwDummy); |
6015 vim_free(oldattrs); | |
6016 } | |
6017 | |
6018 | |
6019 /* | |
6020 * Make the cursor visible or invisible | |
6021 */ | |
6022 static void | |
26 | 6023 cursor_visible(BOOL fVisible) |
7 | 6024 { |
6025 s_cursor_visible = fVisible; | |
6026 #ifdef MCH_CURSOR_SHAPE | |
6027 mch_update_cursor(); | |
6028 #endif | |
6029 } | |
6030 | |
6031 | |
6032 /* | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6033 * Write "cbToWrite" bytes in `pchBuf' to the screen. |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6034 * Returns the number of bytes actually written (at least one). |
7 | 6035 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6036 static DWORD |
7 | 6037 write_chars( |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6038 char_u *pchBuf, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6039 DWORD cbToWrite) |
7 | 6040 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6041 COORD coord = g_coord; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6042 DWORD written; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6043 DWORD n, cchwritten, cells; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6044 static WCHAR *unicodebuf = NULL; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6045 static int unibuflen = 0; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6046 int length; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6047 int cp = enc_utf8 ? CP_UTF8 : enc_codepage; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6048 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6049 length = MultiByteToWideChar(cp, 0, (LPCSTR)pchBuf, cbToWrite, 0, 0); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6050 if (unicodebuf == NULL || length > unibuflen) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6051 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6052 vim_free(unicodebuf); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6053 unicodebuf = LALLOC_MULT(WCHAR, length); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6054 unibuflen = length; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6055 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6056 MultiByteToWideChar(cp, 0, (LPCSTR)pchBuf, cbToWrite, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6057 unicodebuf, unibuflen); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6058 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6059 cells = mb_string2cells(pchBuf, cbToWrite); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6060 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6061 if (!USE_VTP) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6062 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6063 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cells, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6064 coord, &written); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6065 // When writing fails or didn't write a single character, pretend one |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6066 // character was written, otherwise we get stuck. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6067 if (WriteConsoleOutputCharacterW(g_hConOut, unicodebuf, length, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6068 coord, &cchwritten) == 0 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6069 || cchwritten == 0 || cchwritten == (DWORD)-1) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6070 cchwritten = 1; |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6071 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6072 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6073 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6074 if (WriteConsoleW(g_hConOut, unicodebuf, length, &cchwritten, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6075 NULL) == 0 || cchwritten == 0) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6076 cchwritten = 1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6077 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6078 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6079 if (cchwritten == length) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6080 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6081 written = cbToWrite; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6082 g_coord.X += (SHORT)cells; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6083 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6084 else |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6085 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6086 char_u *p = pchBuf; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6087 for (n = 0; n < cchwritten; n++) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6088 MB_CPTR_ADV(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6089 written = p - pchBuf; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6090 g_coord.X += (SHORT)mb_string2cells(pchBuf, written); |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6091 } |
7 | 6092 |
6093 while (g_coord.X > g_srScrollRegion.Right) | |
6094 { | |
6095 g_coord.X -= (SHORT) Columns; | |
6096 if (g_coord.Y < g_srScrollRegion.Bottom) | |
6097 g_coord.Y++; | |
6098 } | |
6099 | |
6100 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
6101 | |
6102 return written; | |
6103 } | |
6104 | |
6105 | |
6106 /* | |
6107 * mch_write(): write the output buffer to the screen, translating ESC | |
6108 * sequences into calls to console output routines. | |
6109 */ | |
6110 void | |
6111 mch_write( | |
6112 char_u *s, | |
6113 int len) | |
6114 { | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6115 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6116 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6117 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6118 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6119 |
7 | 6120 s[len] = NUL; |
6121 | |
6122 if (!term_console) | |
6123 { | |
6124 write(1, s, (unsigned)len); | |
6125 return; | |
6126 } | |
6127 | |
6128 /* translate ESC | sequences into faked bios calls */ | |
6129 while (len--) | |
6130 { | |
6131 /* optimization: use one single write_chars for runs of text, | |
6132 * rather than once per character It ain't curses, but it helps. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6133 DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033"); |
7 | 6134 |
6135 if (p_wd) | |
6136 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6137 WaitForChar(p_wd, FALSE); |
7 | 6138 if (prefix != 0) |
6139 prefix = 1; | |
6140 } | |
6141 | |
6142 if (prefix != 0) | |
6143 { | |
6144 DWORD nWritten; | |
6145 | |
6146 nWritten = write_chars(s, prefix); | |
6147 #ifdef MCH_WRITE_DUMP | |
6148 if (fdDump) | |
6149 { | |
6150 fputc('>', fdDump); | |
6151 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6152 fputs("<\n", fdDump); | |
6153 } | |
6154 #endif | |
6155 len -= (nWritten - 1); | |
6156 s += nWritten; | |
6157 } | |
6158 else if (s[0] == '\n') | |
6159 { | |
6160 /* \n, newline: go to the beginning of the next line or scroll */ | |
6161 if (g_coord.Y == g_srScrollRegion.Bottom) | |
6162 { | |
6163 scroll(1); | |
6164 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1); | |
6165 } | |
6166 else | |
6167 { | |
6168 gotoxy(g_srScrollRegion.Left + 1, g_coord.Y + 2); | |
6169 } | |
6170 #ifdef MCH_WRITE_DUMP | |
6171 if (fdDump) | |
6172 fputs("\\n\n", fdDump); | |
6173 #endif | |
6174 s++; | |
6175 } | |
6176 else if (s[0] == '\r') | |
6177 { | |
6178 /* \r, carriage return: go to beginning of line */ | |
6179 gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1); | |
6180 #ifdef MCH_WRITE_DUMP | |
6181 if (fdDump) | |
6182 fputs("\\r\n", fdDump); | |
6183 #endif | |
6184 s++; | |
6185 } | |
6186 else if (s[0] == '\b') | |
6187 { | |
6188 /* \b, backspace: move cursor one position left */ | |
6189 if (g_coord.X > g_srScrollRegion.Left) | |
6190 g_coord.X--; | |
6191 else if (g_coord.Y > g_srScrollRegion.Top) | |
6192 { | |
6193 g_coord.X = g_srScrollRegion.Right; | |
6194 g_coord.Y--; | |
6195 } | |
6196 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
6197 #ifdef MCH_WRITE_DUMP | |
6198 if (fdDump) | |
6199 fputs("\\b\n", fdDump); | |
6200 #endif | |
6201 s++; | |
6202 } | |
6203 else if (s[0] == '\a') | |
6204 { | |
6205 /* \a, bell */ | |
6206 MessageBeep(0xFFFFFFFF); | |
6207 #ifdef MCH_WRITE_DUMP | |
6208 if (fdDump) | |
6209 fputs("\\a\n", fdDump); | |
6210 #endif | |
6211 s++; | |
6212 } | |
6213 else if (s[0] == ESC && len >= 3-1 && s[1] == '|') | |
6214 { | |
6215 #ifdef MCH_WRITE_DUMP | |
24 | 6216 char_u *old_s = s; |
7 | 6217 #endif |
24 | 6218 char_u *p; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6219 int arg1 = 0, arg2 = 0, argc = 0, args[16]; |
7 | 6220 |
6221 switch (s[2]) | |
6222 { | |
6223 case '0': case '1': case '2': case '3': case '4': | |
6224 case '5': case '6': case '7': case '8': case '9': | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6225 p = s + 1; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6226 do |
7 | 6227 { |
6228 ++p; | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6229 args[argc] = getdigits(&p); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6230 argc += (argc < 15) ? 1 : 0; |
7 | 6231 if (p > s + len) |
6232 break; | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6233 } while (*p == ';'); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6234 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6235 if (p > s + len) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6236 break; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6237 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6238 arg1 = args[0]; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6239 arg2 = args[1]; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6240 if (*p == 'm') |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6241 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6242 if (argc == 1 && args[0] == 0) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6243 normvideo(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6244 else if (argc == 1) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6245 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6246 if (USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6247 textcolor((WORD) arg1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6248 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6249 textattr((WORD) arg1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6250 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6251 else if (USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6252 vtp_sgr_bulks(argc, args); |
7 | 6253 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6254 else if (argc == 2 && *p == 'H') |
7 | 6255 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6256 gotoxy(arg2, arg1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6257 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6258 else if (argc == 2 && *p == 'r') |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6259 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6260 set_scroll_region(0, arg1 - 1, Columns - 1, arg2 - 1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6261 } |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6262 else if (argc == 2 && *p == 'R') |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6263 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6264 set_scroll_region_tb(arg1, arg2); |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6265 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6266 else if (argc == 2 && *p == 'V') |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6267 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6268 set_scroll_region_lr(arg1, arg2); |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6269 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6270 else if (argc == 1 && *p == 'A') |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6271 { |
7 | 6272 gotoxy(g_coord.X + 1, |
6273 max(g_srScrollRegion.Top, g_coord.Y - arg1) + 1); | |
6274 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6275 else if (argc == 1 && *p == 'b') |
7 | 6276 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6277 textbackground((WORD) arg1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6278 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6279 else if (argc == 1 && *p == 'C') |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6280 { |
7 | 6281 gotoxy(min(g_srScrollRegion.Right, g_coord.X + arg1) + 1, |
6282 g_coord.Y + 1); | |
6283 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6284 else if (argc == 1 && *p == 'f') |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6285 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6286 textcolor((WORD) arg1); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6287 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6288 else if (argc == 1 && *p == 'H') |
7 | 6289 { |
6290 gotoxy(1, arg1); | |
6291 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6292 else if (argc == 1 && *p == 'L') |
7 | 6293 { |
6294 insert_lines(arg1); | |
6295 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6296 else if (argc == 1 && *p == 'M') |
7 | 6297 { |
6298 delete_lines(arg1); | |
6299 } | |
6300 | |
835 | 6301 len -= (int)(p - s); |
7 | 6302 s = p + 1; |
6303 break; | |
6304 | |
6305 case 'A': | |
6306 gotoxy(g_coord.X + 1, | |
6307 max(g_srScrollRegion.Top, g_coord.Y - 1) + 1); | |
6308 goto got3; | |
6309 | |
6310 case 'B': | |
6311 visual_bell(); | |
6312 goto got3; | |
6313 | |
6314 case 'C': | |
6315 gotoxy(min(g_srScrollRegion.Right, g_coord.X + 1) + 1, | |
6316 g_coord.Y + 1); | |
6317 goto got3; | |
6318 | |
6319 case 'E': | |
6320 termcap_mode_end(); | |
6321 goto got3; | |
6322 | |
6323 case 'F': | |
6324 standout(); | |
6325 goto got3; | |
6326 | |
6327 case 'f': | |
6328 standend(); | |
6329 goto got3; | |
6330 | |
6331 case 'H': | |
6332 gotoxy(1, 1); | |
6333 goto got3; | |
6334 | |
6335 case 'j': | |
6336 clear_to_end_of_display(); | |
6337 goto got3; | |
6338 | |
6339 case 'J': | |
6340 clear_screen(); | |
6341 goto got3; | |
6342 | |
6343 case 'K': | |
6344 clear_to_end_of_line(); | |
6345 goto got3; | |
6346 | |
6347 case 'L': | |
6348 insert_lines(1); | |
6349 goto got3; | |
6350 | |
6351 case 'M': | |
6352 delete_lines(1); | |
6353 goto got3; | |
6354 | |
6355 case 'S': | |
6356 termcap_mode_start(); | |
6357 goto got3; | |
6358 | |
6359 case 'V': | |
6360 cursor_visible(TRUE); | |
6361 goto got3; | |
6362 | |
6363 case 'v': | |
6364 cursor_visible(FALSE); | |
6365 goto got3; | |
6366 | |
6367 got3: | |
6368 s += 3; | |
6369 len -= 2; | |
6370 } | |
6371 | |
6372 #ifdef MCH_WRITE_DUMP | |
6373 if (fdDump) | |
6374 { | |
6375 fputs("ESC | ", fdDump); | |
6376 fwrite(old_s + 2, sizeof(char_u), s - old_s - 2, fdDump); | |
6377 fputc('\n', fdDump); | |
6378 } | |
6379 #endif | |
6380 } | |
6381 else | |
6382 { | |
6383 /* Write a single character */ | |
6384 DWORD nWritten; | |
6385 | |
6386 nWritten = write_chars(s, 1); | |
6387 #ifdef MCH_WRITE_DUMP | |
6388 if (fdDump) | |
6389 { | |
6390 fputc('>', fdDump); | |
6391 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6392 fputs("<\n", fdDump); | |
6393 } | |
6394 #endif | |
6395 | |
6396 len -= (nWritten - 1); | |
6397 s += nWritten; | |
6398 } | |
6399 } | |
6400 | |
6401 #ifdef MCH_WRITE_DUMP | |
6402 if (fdDump) | |
6403 fflush(fdDump); | |
6404 #endif | |
6405 } | |
6406 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
6407 #endif /* FEAT_GUI_MSWIN */ |
7 | 6408 |
6409 | |
6410 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
6411 * Delay for "msec" milliseconds. |
7 | 6412 */ |
6413 void | |
6414 mch_delay( | |
6415 long msec, | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
6416 int ignoreinput UNUSED) |
7 | 6417 { |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6418 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 6419 Sleep((int)msec); /* never wait for input */ |
14 | 6420 #else /* Console */ |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6421 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6422 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6423 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6424 Sleep((int)msec); /* never wait for input */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6425 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6426 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6427 # endif |
7 | 6428 if (ignoreinput) |
14 | 6429 # ifdef FEAT_MZSCHEME |
6430 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq) | |
6431 { | |
6432 int towait = p_mzq; | |
6433 | |
6434 /* if msec is large enough, wait by portions in p_mzq */ | |
6435 while (msec > 0) | |
6436 { | |
6437 mzvim_check_threads(); | |
6438 if (msec < towait) | |
6439 towait = msec; | |
6440 Sleep(towait); | |
6441 msec -= towait; | |
6442 } | |
6443 } | |
6444 else | |
6445 # endif | |
6446 Sleep((int)msec); | |
7 | 6447 else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6448 WaitForChar(msec, FALSE); |
7 | 6449 #endif |
6450 } | |
6451 | |
6452 | |
6453 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6454 * 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
|
6455 * This can also remove a symbolic link like Unix. |
7 | 6456 * Return 0 for success, -1 for failure. |
6457 */ | |
6458 int | |
6459 mch_remove(char_u *name) | |
6460 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6461 WCHAR *wn; |
7 | 6462 int n; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6463 |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6464 /* |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6465 * 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
|
6466 * 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
|
6467 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6468 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
|
6469 return mch_rmdir(name); |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6470 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6471 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6472 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6473 wn = enc_to_utf16(name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6474 if (wn == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6475 return -1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6476 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6477 n = DeleteFileW(wn) ? 0 : -1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6478 vim_free(wn); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6479 return n; |
7 | 6480 } |
6481 | |
6482 | |
6483 /* | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6484 * Check for an "interrupt signal": CTRL-break or CTRL-C. |
7 | 6485 */ |
6486 void | |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
6487 mch_breakcheck(int force UNUSED) |
7 | 6488 { |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6489 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6490 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6491 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6492 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6493 if (g_fCtrlCPressed || g_fCBrkPressed) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6494 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6495 ctrl_break_was_pressed = g_fCBrkPressed; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6496 g_fCtrlCPressed = g_fCBrkPressed = FALSE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6497 got_int = TRUE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6498 } |
7 | 6499 #endif |
6500 } | |
6501 | |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6502 /* 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
|
6503 #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
|
6504 |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6505 /* |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6506 * 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
|
6507 */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6508 long_u |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
6509 mch_total_mem(int special UNUSED) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6510 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6511 MEMORYSTATUSEX ms; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6512 |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6513 /* Need to use GlobalMemoryStatusEx() when there is more memory than |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6514 * what fits in 32 bits. */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6515 ms.dwLength = sizeof(MEMORYSTATUSEX); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6516 GlobalMemoryStatusEx(&ms); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6517 if (ms.ullAvailVirtual < ms.ullTotalPhys) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6518 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6519 /* Process address space fits in physical RAM, use all of it. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6520 return (long_u)(ms.ullAvailVirtual / 1024); |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6521 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6522 if (ms.ullTotalPhys <= WINNT_RESERVE_BYTES) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6523 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6524 /* Catch old NT box or perverse hardware setup. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6525 return (long_u)((ms.ullTotalPhys / 2) / 1024); |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6526 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6527 /* Use physical RAM less reserve for OS + data. */ |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6528 return (long_u)((ms.ullTotalPhys - WINNT_RESERVE_BYTES) / 1024); |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6529 } |
7 | 6530 |
6531 /* | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6532 * mch_wrename() works around a bug in rename (aka MoveFile) in |
7 | 6533 * Windows 95: rename("foo.bar", "foo.bar~") will generate a |
6534 * file whose short file name is "FOO.BAR" (its long file name will | |
6535 * be correct: "foo.bar~"). Because a file can be accessed by | |
6536 * either its SFN or its LFN, "foo.bar" has effectively been | |
6537 * renamed to "foo.bar", which is not at all what was wanted. This | |
6538 * seems to happen only when renaming files with three-character | |
6539 * extensions by appending a suffix that does not include ".". | |
6540 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR". | |
6541 * | |
6542 * There is another problem, which isn't really a bug but isn't right either: | |
6543 * When renaming "abcdef~1.txt" to "abcdef~1.txt~", the short name can be | |
6544 * "abcdef~1.txt" again. This has been reported on Windows NT 4.0 with | |
6545 * service pack 6. Doesn't seem to happen on Windows 98. | |
6546 * | |
6547 * Like rename(), returns 0 upon success, non-zero upon failure. | |
6548 * Should probably set errno appropriately when errors occur. | |
6549 */ | |
6550 int | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6551 mch_wrename(WCHAR *wold, WCHAR *wnew) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6552 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6553 WCHAR *p; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6554 int i; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6555 WCHAR szTempFile[_MAX_PATH + 1]; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6556 WCHAR szNewPath[_MAX_PATH + 1]; |
7 | 6557 HANDLE hf; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6558 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6559 // No need to play tricks unless the file name contains a "~" as the |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6560 // seventh character. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6561 p = wold; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6562 for (i = 0; wold[i] != NUL; ++i) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6563 if ((wold[i] == '/' || wold[i] == '\\' || wold[i] == ':') |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6564 && wold[i + 1] != 0) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6565 p = wold + i + 1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6566 if ((int)(wold + i - p) < 8 || p[6] != '~') |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6567 return (MoveFileW(wold, wnew) == 0); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6568 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6569 // Get base path of new file name. Undocumented feature: If pszNewFile is |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6570 // a directory, no error is returned and pszFilePart will be NULL. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6571 if (GetFullPathNameW(wnew, _MAX_PATH, szNewPath, &p) == 0 || p == NULL) |
7 | 6572 return -1; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6573 *p = NUL; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6574 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6575 // Get (and create) a unique temporary file name in directory of new file |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6576 if (GetTempFileNameW(szNewPath, L"VIM", 0, szTempFile) == 0) |
7 | 6577 return -2; |
6578 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6579 // blow the temp file away |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6580 if (!DeleteFileW(szTempFile)) |
7 | 6581 return -3; |
6582 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6583 // rename old file to the temp file |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6584 if (!MoveFileW(wold, szTempFile)) |
7 | 6585 return -4; |
6586 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6587 // now create an empty file called pszOldFile; this prevents the operating |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6588 // system using pszOldFile as an alias (SFN) if we're renaming within the |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6589 // same directory. For example, we're editing a file called |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6590 // filename.asc.txt by its SFN, filena~1.txt. If we rename filena~1.txt |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6591 // to filena~1.txt~ (i.e., we're making a backup while writing it), the |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6592 // SFN for filena~1.txt~ will be filena~1.txt, by default, which will |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6593 // cause all sorts of problems later in buf_write(). So, we create an |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6594 // empty file called filena~1.txt and the system will have to find some |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6595 // other SFN for filena~1.txt~, such as filena~2.txt |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6596 if ((hf = CreateFileW(wold, GENERIC_WRITE, 0, NULL, CREATE_NEW, |
7 | 6597 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) |
6598 return -5; | |
6599 if (!CloseHandle(hf)) | |
6600 return -6; | |
6601 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6602 // rename the temp file to the new file |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6603 if (!MoveFileW(szTempFile, wnew)) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6604 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6605 // Renaming failed. Rename the file back to its old name, so that it |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6606 // looks like nothing happened. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6607 (void)MoveFileW(szTempFile, wold); |
7 | 6608 return -7; |
6609 } | |
6610 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6611 // Seems to be left around on Novell filesystems |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6612 DeleteFileW(szTempFile); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6613 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6614 // finally, remove the empty old file |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6615 if (!DeleteFileW(wold)) |
7 | 6616 return -8; |
6617 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6618 return 0; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6619 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6620 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6621 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6622 /* |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6623 * Converts the filenames to UTF-16, then call mch_wrename(). |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6624 * Like rename(), returns 0 upon success, non-zero upon failure. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6625 */ |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6626 int |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6627 mch_rename( |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6628 const char *pszOldFile, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6629 const char *pszNewFile) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6630 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6631 WCHAR *wold = NULL; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6632 WCHAR *wnew = NULL; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6633 int retval = -1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6634 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6635 wold = enc_to_utf16((char_u *)pszOldFile, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6636 wnew = enc_to_utf16((char_u *)pszNewFile, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6637 if (wold != NULL && wnew != NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6638 retval = mch_wrename(wold, wnew); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6639 vim_free(wold); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6640 vim_free(wnew); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6641 return retval; |
7 | 6642 } |
6643 | |
6644 /* | |
6645 * Get the default shell for the current hardware platform | |
6646 */ | |
6647 char * | |
26 | 6648 default_shell(void) |
7 | 6649 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6650 return "cmd.exe"; |
7 | 6651 } |
6652 | |
6653 /* | |
6654 * mch_access() extends access() to do more detailed check on network drives. | |
6655 * Returns 0 if file "n" has access rights according to "p", -1 otherwise. | |
6656 */ | |
6657 int | |
6658 mch_access(char *n, int p) | |
6659 { | |
6660 HANDLE hFile; | |
6661 int retval = -1; /* default: fail */ | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6662 WCHAR *wn; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6663 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6664 wn = enc_to_utf16((char_u *)n, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6665 if (wn == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6666 return -1; |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6667 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6668 if (mch_isdir((char_u *)n)) |
7 | 6669 { |
6670 WCHAR TempNameW[_MAX_PATH + 16] = L""; | |
6671 | |
6672 if (p & R_OK) | |
6673 { | |
6674 /* Read check is performed by seeing if we can do a find file on | |
6675 * the directory for any file. */ | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6676 int i; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6677 WIN32_FIND_DATAW d; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6678 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6679 for (i = 0; i < _MAX_PATH && wn[i] != 0; ++i) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6680 TempNameW[i] = wn[i]; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6681 if (TempNameW[i - 1] != '\\' && TempNameW[i - 1] != '/') |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6682 TempNameW[i++] = '\\'; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6683 TempNameW[i++] = '*'; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6684 TempNameW[i++] = 0; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6685 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6686 hFile = FindFirstFileW(TempNameW, &d); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6687 if (hFile == INVALID_HANDLE_VALUE) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6688 goto getout; |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6689 else |
7 | 6690 (void)FindClose(hFile); |
6691 } | |
6692 | |
6693 if (p & W_OK) | |
6694 { | |
6695 /* Trying to create a temporary file in the directory should catch | |
6696 * directories on read-only network shares. However, in | |
6697 * directories whose ACL allows writes but denies deletes will end | |
6698 * up keeping the temporary file :-(. */ | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6699 if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW)) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6700 goto getout; |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6701 else |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6702 DeleteFileW(TempNameW); |
7 | 6703 } |
6704 } | |
6705 else | |
6706 { | |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6707 // Don't consider a file read-only if another process has opened it. |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6708 DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE; |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6709 |
7 | 6710 /* Trying to open the file for the required access does ACL, read-only |
6711 * network share, and file attribute checks. */ | |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6712 DWORD access_mode = ((p & W_OK) ? GENERIC_WRITE : 0) |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6713 | ((p & R_OK) ? GENERIC_READ : 0); |
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6714 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6715 hFile = CreateFileW(wn, access_mode, share_mode, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6716 NULL, OPEN_EXISTING, 0, NULL); |
7 | 6717 if (hFile == INVALID_HANDLE_VALUE) |
6718 goto getout; | |
6719 CloseHandle(hFile); | |
6720 } | |
6721 | |
6722 retval = 0; /* success */ | |
6723 getout: | |
6724 vim_free(wn); | |
6725 return retval; | |
6726 } | |
6727 | |
6728 /* | |
1752 | 6729 * Version of open() that may use UTF-16 file name. |
7 | 6730 */ |
6731 int | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
6732 mch_open(const char *name, int flags, int mode) |
7 | 6733 { |
6734 WCHAR *wn; | |
6735 int f; | |
6736 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6737 wn = enc_to_utf16((char_u *)name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6738 if (wn == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6739 return -1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6740 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6741 f = _wopen(wn, flags, mode); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6742 vim_free(wn); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6743 return f; |
7 | 6744 } |
6745 | |
6746 /* | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6747 * Version of fopen() that uses UTF-16 file name. |
7 | 6748 */ |
6749 FILE * | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
6750 mch_fopen(const char *name, const char *mode) |
7 | 6751 { |
6752 WCHAR *wn, *wm; | |
6753 FILE *f = NULL; | |
6754 | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6755 #if defined(DEBUG) && _MSC_VER >= 1400 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6756 /* Work around an annoying assertion in the Microsoft debug CRT |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6757 * when mode's text/binary setting doesn't match _get_fmode(). */ |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6758 char newMode = mode[strlen(mode) - 1]; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6759 int oldMode = 0; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6760 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6761 _get_fmode(&oldMode); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6762 if (newMode == 't') |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6763 _set_fmode(_O_TEXT); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6764 else if (newMode == 'b') |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6765 _set_fmode(_O_BINARY); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6766 #endif |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6767 wn = enc_to_utf16((char_u *)name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6768 wm = enc_to_utf16((char_u *)mode, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6769 if (wn != NULL && wm != NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6770 f = _wfopen(wn, wm); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6771 vim_free(wn); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6772 vim_free(wm); |
1569 | 6773 |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6774 #if defined(DEBUG) && _MSC_VER >= 1400 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6775 _set_fmode(oldMode); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6776 #endif |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6777 return f; |
7 | 6778 } |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6779 |
7 | 6780 /* |
6781 * SUB STREAM (aka info stream) handling: | |
6782 * | |
6783 * NTFS can have sub streams for each file. Normal contents of file is | |
6784 * stored in the main stream, and extra contents (author information and | |
6785 * title and so on) can be stored in sub stream. After Windows 2000, user | |
6786 * can access and store those informations in sub streams via explorer's | |
6787 * property menuitem in right click menu. Those informations in sub streams | |
6788 * were lost when copying only the main stream. So we have to copy sub | |
6789 * streams. | |
6790 * | |
6791 * Incomplete explanation: | |
6792 * http://msdn.microsoft.com/library/en-us/dnw2k/html/ntfs5.asp | |
6793 * More useful info and an example: | |
6794 * http://www.sysinternals.com/ntw2k/source/misc.shtml#streams | |
6795 */ | |
6796 | |
6797 /* | |
6798 * Copy info stream data "substream". Read from the file with BackupRead(sh) | |
6799 * and write to stream "substream" of file "to". | |
6800 * Errors are ignored. | |
6801 */ | |
6802 static void | |
6803 copy_substream(HANDLE sh, void *context, WCHAR *to, WCHAR *substream, long len) | |
6804 { | |
6805 HANDLE hTo; | |
6806 WCHAR *to_name; | |
6807 | |
6808 to_name = malloc((wcslen(to) + wcslen(substream) + 1) * sizeof(WCHAR)); | |
6809 wcscpy(to_name, to); | |
6810 wcscat(to_name, substream); | |
6811 | |
6812 hTo = CreateFileW(to_name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, | |
6813 FILE_ATTRIBUTE_NORMAL, NULL); | |
6814 if (hTo != INVALID_HANDLE_VALUE) | |
6815 { | |
6816 long done; | |
6817 DWORD todo; | |
6818 DWORD readcnt, written; | |
6819 char buf[4096]; | |
6820 | |
6821 /* Copy block of bytes at a time. Abort when something goes wrong. */ | |
6822 for (done = 0; done < len; done += written) | |
6823 { | |
6824 /* (size_t) cast for Borland C 5.5 */ | |
835 | 6825 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) |
6826 : (size_t)(len - done)); | |
7 | 6827 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, |
6828 FALSE, FALSE, context) | |
6829 || readcnt != todo | |
6830 || !WriteFile(hTo, buf, todo, &written, NULL) | |
6831 || written != todo) | |
6832 break; | |
6833 } | |
6834 CloseHandle(hTo); | |
6835 } | |
6836 | |
6837 free(to_name); | |
6838 } | |
6839 | |
6840 /* | |
6841 * Copy info streams from file "from" to file "to". | |
6842 */ | |
6843 static void | |
6844 copy_infostreams(char_u *from, char_u *to) | |
6845 { | |
6846 WCHAR *fromw; | |
6847 WCHAR *tow; | |
6848 HANDLE sh; | |
6849 WIN32_STREAM_ID sid; | |
6850 int headersize; | |
6851 WCHAR streamname[_MAX_PATH]; | |
6852 DWORD readcount; | |
6853 void *context = NULL; | |
6854 DWORD lo, hi; | |
6855 int len; | |
6856 | |
6857 /* Convert the file names to wide characters. */ | |
1752 | 6858 fromw = enc_to_utf16(from, NULL); |
6859 tow = enc_to_utf16(to, NULL); | |
7 | 6860 if (fromw != NULL && tow != NULL) |
6861 { | |
6862 /* Open the file for reading. */ | |
6863 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, | |
6864 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | |
6865 if (sh != INVALID_HANDLE_VALUE) | |
6866 { | |
6867 /* Use BackupRead() to find the info streams. Repeat until we | |
6868 * have done them all.*/ | |
6869 for (;;) | |
6870 { | |
6871 /* Get the header to find the length of the stream name. If | |
6872 * the "readcount" is zero we have done all info streams. */ | |
6873 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); | |
835 | 6874 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); |
7 | 6875 if (!BackupRead(sh, (LPBYTE)&sid, headersize, |
6876 &readcount, FALSE, FALSE, &context) | |
6877 || readcount == 0) | |
6878 break; | |
6879 | |
6880 /* We only deal with streams that have a name. The normal | |
6881 * file data appears to be without a name, even though docs | |
6882 * suggest it is called "::$DATA". */ | |
6883 if (sid.dwStreamNameSize > 0) | |
6884 { | |
6885 /* Read the stream name. */ | |
6886 if (!BackupRead(sh, (LPBYTE)streamname, | |
6887 sid.dwStreamNameSize, | |
6888 &readcount, FALSE, FALSE, &context)) | |
6889 break; | |
6890 | |
6891 /* Copy an info stream with a name ":anything:$DATA". | |
6892 * Skip "::$DATA", it has no stream name (examples suggest | |
6893 * it might be used for the normal file contents). | |
6894 * Note that BackupRead() counts bytes, but the name is in | |
6895 * wide characters. */ | |
6896 len = readcount / sizeof(WCHAR); | |
6897 streamname[len] = 0; | |
6898 if (len > 7 && wcsicmp(streamname + len - 6, | |
6899 L":$DATA") == 0) | |
6900 { | |
6901 streamname[len - 6] = 0; | |
6902 copy_substream(sh, &context, tow, streamname, | |
10 | 6903 (long)sid.Size.u.LowPart); |
7 | 6904 } |
6905 } | |
6906 | |
6907 /* Advance to the next stream. We might try seeking too far, | |
6908 * but BackupSeek() doesn't skip over stream borders, thus | |
6909 * that's OK. */ | |
323 | 6910 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, |
7 | 6911 &lo, &hi, &context); |
6912 } | |
6913 | |
6914 /* Clear the context. */ | |
6915 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); | |
6916 | |
6917 CloseHandle(sh); | |
6918 } | |
6919 } | |
6920 vim_free(fromw); | |
6921 vim_free(tow); | |
6922 } | |
6923 | |
6924 /* | |
6925 * Copy file attributes from file "from" to file "to". | |
6926 * For Windows NT and later we copy info streams. | |
6927 * Always returns zero, errors are ignored. | |
6928 */ | |
6929 int | |
6930 mch_copy_file_attribute(char_u *from, char_u *to) | |
6931 { | |
6932 /* File streams only work on Windows NT and later. */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6933 copy_infostreams(from, to); |
7 | 6934 return 0; |
6935 } | |
6936 | |
6937 #if defined(MYRESETSTKOFLW) || defined(PROTO) | |
6938 /* | |
6939 * Recreate a destroyed stack guard page in win32. | |
6940 * Written by Benjamin Peterson. | |
6941 */ | |
6942 | |
6943 /* These magic numbers are from the MS header files */ | |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
6944 # define MIN_STACK_WINNT 2 |
7 | 6945 |
6946 /* | |
6947 * This function does the same thing as _resetstkoflw(), which is only | |
6948 * available in DevStudio .net and later. | |
6949 * Returns 0 for failure, 1 for success. | |
6950 */ | |
6951 int | |
6952 myresetstkoflw(void) | |
6953 { | |
6954 BYTE *pStackPtr; | |
6955 BYTE *pGuardPage; | |
6956 BYTE *pStackBase; | |
6957 BYTE *pLowestPossiblePage; | |
6958 MEMORY_BASIC_INFORMATION mbi; | |
6959 SYSTEM_INFO si; | |
6960 DWORD nPageSize; | |
6961 DWORD dummy; | |
6962 | |
6963 /* We need to know the system page size. */ | |
6964 GetSystemInfo(&si); | |
6965 nPageSize = si.dwPageSize; | |
6966 | |
6967 /* ...and the current stack pointer */ | |
6968 pStackPtr = (BYTE*)_alloca(1); | |
6969 | |
6970 /* ...and the base of the stack. */ | |
6971 if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0) | |
6972 return 0; | |
6973 pStackBase = (BYTE*)mbi.AllocationBase; | |
6974 | |
6975 /* ...and the page thats min_stack_req pages away from stack base; this is | |
6976 * the lowest page we could use. */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6977 pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6978 |
7 | 6979 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6980 /* We want the first committed page in the stack Start at the stack |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6981 * base and move forward through memory until we find a committed block. |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6982 */ |
7 | 6983 BYTE *pBlock = pStackBase; |
6984 | |
406 | 6985 for (;;) |
7 | 6986 { |
6987 if (VirtualQuery(pBlock, &mbi, sizeof mbi) == 0) | |
6988 return 0; | |
6989 | |
6990 pBlock += mbi.RegionSize; | |
6991 | |
6992 if (mbi.State & MEM_COMMIT) | |
6993 break; | |
6994 } | |
6995 | |
6996 /* mbi now describes the first committed block in the stack. */ | |
6997 if (mbi.Protect & PAGE_GUARD) | |
6998 return 1; | |
6999 | |
7000 /* decide where the guard page should start */ | |
7001 if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage) | |
7002 pGuardPage = pLowestPossiblePage; | |
7003 else | |
7004 pGuardPage = (BYTE*)mbi.BaseAddress; | |
7005 | |
7006 /* allocate the guard page */ | |
7007 if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE)) | |
7008 return 0; | |
7009 | |
7010 /* apply the guard attribute to the page */ | |
7011 if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD, | |
7012 &dummy)) | |
7013 return 0; | |
7014 } | |
7015 | |
7016 return 1; | |
7017 } | |
7018 #endif | |
26 | 7019 |
7020 | |
7021 /* | |
7022 * The command line arguments in UCS2 | |
7023 */ | |
344 | 7024 static int nArgsW = 0; |
26 | 7025 static LPWSTR *ArglistW = NULL; |
7026 static int global_argc = 0; | |
7027 static char **global_argv; | |
7028 | |
7029 static int used_file_argc = 0; /* last argument in global_argv[] used | |
7030 for the argument list. */ | |
7031 static int *used_file_indexes = NULL; /* indexes in global_argv[] for | |
7032 command line arguments added to | |
7033 the argument list */ | |
7034 static int used_file_count = 0; /* nr of entries in used_file_indexes */ | |
7035 static int used_file_literal = FALSE; /* take file names literally */ | |
7036 static int used_file_full_path = FALSE; /* file name was full path */ | |
819 | 7037 static int used_file_diff_mode = FALSE; /* file name was with diff mode */ |
26 | 7038 static int used_alist_count = 0; |
7039 | |
7040 | |
7041 /* | |
7042 * Get the command line arguments. Unicode version. | |
7043 * Returns argc. Zero when something fails. | |
7044 */ | |
7045 int | |
7046 get_cmd_argsW(char ***argvp) | |
7047 { | |
7048 char **argv = NULL; | |
7049 int argc = 0; | |
7050 int i; | |
7051 | |
6193 | 7052 free_cmd_argsW(); |
26 | 7053 ArglistW = CommandLineToArgvW(GetCommandLineW(), &nArgsW); |
7054 if (ArglistW != NULL) | |
7055 { | |
7056 argv = malloc((nArgsW + 1) * sizeof(char *)); | |
7057 if (argv != NULL) | |
7058 { | |
7059 argc = nArgsW; | |
7060 argv[argc] = NULL; | |
7061 for (i = 0; i < argc; ++i) | |
7062 { | |
7063 int len; | |
7064 | |
7065 /* Convert each Unicode argument to the current codepage. */ | |
7066 WideCharToMultiByte_alloc(GetACP(), 0, | |
835 | 7067 ArglistW[i], (int)wcslen(ArglistW[i]) + 1, |
26 | 7068 (LPSTR *)&argv[i], &len, 0, 0); |
7069 if (argv[i] == NULL) | |
7070 { | |
7071 /* Out of memory, clear everything. */ | |
7072 while (i > 0) | |
7073 free(argv[--i]); | |
7074 free(argv); | |
5529 | 7075 argv = NULL; |
26 | 7076 argc = 0; |
7077 } | |
7078 } | |
7079 } | |
7080 } | |
7081 | |
7082 global_argc = argc; | |
7083 global_argv = argv; | |
7084 if (argc > 0) | |
6193 | 7085 { |
7086 if (used_file_indexes != NULL) | |
7087 free(used_file_indexes); | |
26 | 7088 used_file_indexes = malloc(argc * sizeof(int)); |
6193 | 7089 } |
26 | 7090 |
7091 if (argvp != NULL) | |
7092 *argvp = argv; | |
7093 return argc; | |
7094 } | |
7095 | |
7096 void | |
7097 free_cmd_argsW(void) | |
7098 { | |
7099 if (ArglistW != NULL) | |
7100 { | |
7101 GlobalFree(ArglistW); | |
7102 ArglistW = NULL; | |
7103 } | |
7104 } | |
7105 | |
7106 /* | |
7107 * Remember "name" is an argument that was added to the argument list. | |
7108 * This avoids that we have to re-parse the argument list when fix_arg_enc() | |
7109 * is called. | |
7110 */ | |
7111 void | |
819 | 7112 used_file_arg(char *name, int literal, int full_path, int diff_mode) |
26 | 7113 { |
7114 int i; | |
7115 | |
7116 if (used_file_indexes == NULL) | |
7117 return; | |
7118 for (i = used_file_argc + 1; i < global_argc; ++i) | |
7119 if (STRCMP(global_argv[i], name) == 0) | |
7120 { | |
7121 used_file_argc = i; | |
7122 used_file_indexes[used_file_count++] = i; | |
7123 break; | |
7124 } | |
7125 used_file_literal = literal; | |
7126 used_file_full_path = full_path; | |
819 | 7127 used_file_diff_mode = diff_mode; |
26 | 7128 } |
7129 | |
7130 /* | |
7131 * Remember the length of the argument list as it was. If it changes then we | |
7132 * leave it alone when 'encoding' is set. | |
7133 */ | |
7134 void | |
7135 set_alist_count(void) | |
7136 { | |
7137 used_alist_count = GARGCOUNT; | |
7138 } | |
7139 | |
7140 /* | |
7141 * Fix the encoding of the command line arguments. Invoked when 'encoding' | |
7142 * has been changed while starting up. Use the UCS-2 command line arguments | |
7143 * and convert them to 'encoding'. | |
7144 */ | |
7145 void | |
7146 fix_arg_enc(void) | |
7147 { | |
7148 int i; | |
7149 int idx; | |
7150 char_u *str; | |
41 | 7151 int *fnum_list; |
26 | 7152 |
7153 /* Safety checks: | |
7154 * - if argument count differs between the wide and non-wide argument | |
7155 * list, something must be wrong. | |
7156 * - the file name arguments must have been located. | |
7157 * - the length of the argument list wasn't changed by the user. | |
7158 */ | |
344 | 7159 if (global_argc != nArgsW |
26 | 7160 || ArglistW == NULL |
7161 || used_file_indexes == NULL | |
7162 || used_file_count == 0 | |
7163 || used_alist_count != GARGCOUNT) | |
7164 return; | |
7165 | |
41 | 7166 /* Remember the buffer numbers for the arguments. */ |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
7167 fnum_list = ALLOC_MULT(int, GARGCOUNT); |
41 | 7168 if (fnum_list == NULL) |
7169 return; /* out of memory */ | |
7170 for (i = 0; i < GARGCOUNT; ++i) | |
7171 fnum_list[i] = GARGLIST[i].ae_fnum; | |
7172 | |
26 | 7173 /* Clear the argument list. Make room for the new arguments. */ |
7174 alist_clear(&global_alist); | |
7175 if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL) | |
41 | 7176 return; /* out of memory */ |
26 | 7177 |
7178 for (i = 0; i < used_file_count; ++i) | |
7179 { | |
7180 idx = used_file_indexes[i]; | |
1752 | 7181 str = utf16_to_enc(ArglistW[idx], NULL); |
26 | 7182 if (str != NULL) |
41 | 7183 { |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7184 int literal = used_file_literal; |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7185 |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
7186 # ifdef FEAT_DIFF |
819 | 7187 /* When using diff mode may need to concatenate file name to |
7188 * directory name. Just like it's done in main(). */ | |
7189 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 | |
7190 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
7191 { | |
7192 char_u *r; | |
7193 | |
7194 r = concat_fnames(str, gettail(alist_name(&GARGLIST[0])), TRUE); | |
7195 if (r != NULL) | |
7196 { | |
7197 vim_free(str); | |
7198 str = r; | |
7199 } | |
7200 } | |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
7201 # endif |
41 | 7202 /* Re-use the old buffer by renaming it. When not using literal |
7203 * names it's done by alist_expand() below. */ | |
7204 if (used_file_literal) | |
7205 buf_set_name(fnum_list[i], str); | |
7206 | |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7207 /* Check backtick literal. backtick literal is already expanded in |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7208 * main.c, so this part add str as literal. */ |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7209 if (literal == FALSE) |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7210 { |
12015
7e704d75a882
patch 8.0.0888: compiler warnings with 64 bit build
Christian Brabandt <cb@256bit.org>
parents:
11991
diff
changeset
|
7211 size_t len = STRLEN(str); |
7e704d75a882
patch 8.0.0888: compiler warnings with 64 bit build
Christian Brabandt <cb@256bit.org>
parents:
11991
diff
changeset
|
7212 |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7213 if (len > 2 && *str == '`' && *(str + len - 1) == '`') |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7214 literal = TRUE; |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7215 } |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7216 alist_add(&global_alist, str, literal ? 2 : 0); |
41 | 7217 } |
26 | 7218 } |
7219 | |
7220 if (!used_file_literal) | |
7221 { | |
7222 /* Now expand wildcards in the arguments. */ | |
7223 /* Temporarily add '(' and ')' to 'isfname'. These are valid | |
7224 * filename characters but are excluded from 'isfname' to make | |
13433
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7225 * "gf" work on a file name in parenthesis (e.g.: see vim.h). |
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7226 * Also, unset wildignore to not be influenced by this option. |
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7227 * The arguments specified in command-line should be kept even if |
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7228 * encoding options were changed. */ |
26 | 7229 do_cmdline_cmd((char_u *)":let SaVe_ISF = &isf|set isf+=(,)"); |
13433
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7230 do_cmdline_cmd((char_u *)":let SaVe_WIG = &wig|set wig="); |
41 | 7231 alist_expand(fnum_list, used_alist_count); |
26 | 7232 do_cmdline_cmd((char_u *)":let &isf = SaVe_ISF|unlet SaVe_ISF"); |
13433
a23300c1c1cf
patch 8.0.1591: MS-Windows: when reparsing the arguments 'wildignore' matters
Christian Brabandt <cb@256bit.org>
parents:
13416
diff
changeset
|
7233 do_cmdline_cmd((char_u *)":let &wig = SaVe_WIG|unlet SaVe_WIG"); |
26 | 7234 } |
7235 | |
7236 /* If wildcard expansion failed, we are editing the first file of the | |
7237 * arglist and there is no file name: Edit the first argument now. */ | |
7238 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) | |
7239 { | |
7240 do_cmdline_cmd((char_u *)":rewind"); | |
7241 if (GARGCOUNT == 1 && used_file_full_path) | |
13170
6559e98f3e74
patch 8.0.1459: cannot handle change of directory
Christian Brabandt <cb@256bit.org>
parents:
12990
diff
changeset
|
7242 (void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop"); |
26 | 7243 } |
41 | 7244 |
7245 set_alist_count(); | |
26 | 7246 } |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7247 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7248 int |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
7249 mch_setenv(char *var, char *value, int x UNUSED) |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7250 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7251 char_u *envbuf; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7252 WCHAR *p; |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7253 |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16750
diff
changeset
|
7254 envbuf = alloc(STRLEN(var) + STRLEN(value) + 2); |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7255 if (envbuf == NULL) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7256 return -1; |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7257 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7258 sprintf((char *)envbuf, "%s=%s", var, value); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7259 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7260 p = enc_to_utf16(envbuf, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7261 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7262 vim_free(envbuf); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7263 if (p == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7264 return -1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7265 _wputenv(p); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7266 #ifdef libintl_wputenv |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7267 libintl_wputenv(p); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7268 #endif |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7269 // Unlike Un*x systems, we can free the string for _wputenv(). |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7270 vim_free(p); |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7271 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7272 return 0; |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7273 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7274 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7275 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7276 * Support for 256 colors and 24-bit colors was added in Windows 10 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7277 * version 1703 (Creators update). |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7278 */ |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7279 #define VTP_FIRST_SUPPORT_BUILD MAKE_VER(10, 0, 15063) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7280 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7281 /* |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7282 * Support for pseudo-console (ConPTY) was added in windows 10 |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7283 * version 1809 (October 2018 update). |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7284 */ |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7285 #define CONPTY_FIRST_SUPPORT_BUILD MAKE_VER(10, 0, 17763) |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7286 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7287 /* |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7288 * ConPTY differences between versions, need different logic. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7289 * version 1903 (May 2019 update). |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7290 */ |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7291 #define CONPTY_1903_BUILD MAKE_VER(10, 0, 18362) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7292 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7293 /* |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7294 * Confirm until this version. Also the logic changes. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7295 * insider preview. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7296 */ |
18235
88716bc1c20b
patch 8.1.2112: build number for ConPTY is outdated
Bram Moolenaar <Bram@vim.org>
parents:
18180
diff
changeset
|
7297 #define CONPTY_INSIDER_BUILD MAKE_VER(10, 0, 18995) |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7298 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7299 /* |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7300 * Not stable now. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7301 */ |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7302 #define CONPTY_STABLE_BUILD MAKE_VER(10, 0, 32767) // T.B.D. |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7303 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7304 static void |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7305 vtp_flag_init(void) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7306 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7307 DWORD ver = get_build_number(); |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7308 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7309 DWORD mode; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7310 HANDLE out; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7311 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7312 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7313 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7314 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7315 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7316 out = GetStdHandle(STD_OUTPUT_HANDLE); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7317 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7318 vtp_working = (ver >= VTP_FIRST_SUPPORT_BUILD) ? 1 : 0; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7319 GetConsoleMode(out, &mode); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7320 mode |= (ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7321 if (SetConsoleMode(out, mode) == 0) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7322 vtp_working = 0; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7323 } |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7324 #endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7325 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7326 if (ver >= CONPTY_FIRST_SUPPORT_BUILD) |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7327 conpty_working = 1; |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7328 if (ver >= CONPTY_STABLE_BUILD) |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7329 conpty_stable = 1; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7330 |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7331 if (ver <= CONPTY_INSIDER_BUILD) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7332 conpty_type = 3; |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7333 if (ver <= CONPTY_1903_BUILD) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7334 conpty_type = 2; |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7335 if (ver < CONPTY_FIRST_SUPPORT_BUILD) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7336 conpty_type = 1; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7337 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7338 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7339 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) || defined(PROTO) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7340 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7341 static void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7342 vtp_init(void) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7343 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7344 HMODULE hKerneldll; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7345 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7346 # ifdef FEAT_TERMGUICOLORS |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7347 COLORREF fg, bg; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7348 # endif |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7349 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7350 /* Use functions supported from Vista */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7351 hKerneldll = GetModuleHandle("kernel32.dll"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7352 if (hKerneldll != NULL) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7353 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7354 pGetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7355 (PfnGetConsoleScreenBufferInfoEx)GetProcAddress( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7356 hKerneldll, "GetConsoleScreenBufferInfoEx"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7357 pSetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7358 (PfnSetConsoleScreenBufferInfoEx)GetProcAddress( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7359 hKerneldll, "SetConsoleScreenBufferInfoEx"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7360 if (pGetConsoleScreenBufferInfoEx != NULL |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7361 && pSetConsoleScreenBufferInfoEx != NULL) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7362 has_csbiex = TRUE; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7363 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7364 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7365 csbi.cbSize = sizeof(csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7366 if (has_csbiex) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7367 pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7368 save_console_bg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_bg]; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7369 save_console_fg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_fg]; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7370 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7371 # ifdef FEAT_TERMGUICOLORS |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7372 bg = (COLORREF)csbi.ColorTable[g_color_index_bg]; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7373 fg = (COLORREF)csbi.ColorTable[g_color_index_fg]; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7374 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg); |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7375 fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg); |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7376 default_console_color_bg = bg; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7377 default_console_color_fg = fg; |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
7378 # endif |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7379 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7380 set_console_color_rgb(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7381 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7382 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7383 static void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7384 vtp_exit(void) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7385 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7386 reset_console_color_rgb(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7387 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7388 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7389 static int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7390 vtp_printf( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7391 char *format, |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7392 ...) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7393 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7394 char_u buf[100]; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7395 va_list list; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7396 DWORD result; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7397 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7398 va_start(list, format); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7399 vim_vsnprintf((char *)buf, 100, (char *)format, list); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7400 va_end(list); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7401 WriteConsoleA(g_hConOut, buf, (DWORD)STRLEN(buf), &result, NULL); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7402 return (int)result; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7403 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7404 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7405 static void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7406 vtp_sgr_bulk( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7407 int arg) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7408 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7409 int args[1]; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7410 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7411 args[0] = arg; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7412 vtp_sgr_bulks(1, args); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7413 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7414 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7415 static void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7416 vtp_sgr_bulks( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7417 int argc, |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7418 int *args |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7419 ) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7420 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7421 /* 2('\033[') + 4('255.') * 16 + NUL */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7422 char_u buf[2 + (4 * 16) + 1]; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7423 char_u *p; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7424 int i; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7425 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7426 p = buf; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7427 *p++ = '\033'; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7428 *p++ = '['; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7429 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7430 for (i = 0; i < argc; ++i) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7431 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7432 p += vim_snprintf((char *)p, 4, "%d", args[i] & 0xff); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7433 *p++ = ';'; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7434 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7435 p--; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7436 *p++ = 'm'; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7437 *p = NUL; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7438 vtp_printf((char *)buf); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7439 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7440 |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
7441 # ifdef FEAT_TERMGUICOLORS |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7442 static int |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7443 ctermtoxterm( |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7444 int cterm) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7445 { |
13839
ca8953d36264
patch 8.0.1791: using uint8_t does not work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13827
diff
changeset
|
7446 char_u r, g, b, idx; |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7447 |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7448 cterm_color2rgb(cterm, &r, &g, &b, &idx); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7449 return (((int)r << 16) | ((int)g << 8) | (int)b); |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7450 } |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
7451 # endif |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7452 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7453 static void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7454 set_console_color_rgb(void) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7455 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7456 # ifdef FEAT_TERMGUICOLORS |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7457 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7458 int id; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7459 guicolor_T fg = INVALCOLOR; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7460 guicolor_T bg = INVALCOLOR; |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7461 int ctermfg; |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7462 int ctermbg; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7463 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7464 if (!USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7465 return; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7466 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7467 id = syn_name2id((char_u *)"Normal"); |
15983
e73ed0e3faac
patch 8.1.0997: using GUI colors in vim.exe when 'termguicolors' is off
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
7468 if (id > 0 && p_tgc) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7469 syn_id2colors(id, &fg, &bg); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7470 if (fg == INVALCOLOR) |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7471 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7472 ctermfg = -1; |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7473 if (id > 0) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7474 syn_id2cterm_bg(id, &ctermfg, &ctermbg); |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7475 fg = ctermfg != -1 ? ctermtoxterm(ctermfg) : default_console_color_fg; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7476 cterm_normal_fg_gui_color = fg; |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7477 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7478 if (bg == INVALCOLOR) |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7479 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7480 ctermbg = -1; |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7481 if (id > 0) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7482 syn_id2cterm_bg(id, &ctermfg, &ctermbg); |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7483 bg = ctermbg != -1 ? ctermtoxterm(ctermbg) : default_console_color_bg; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7484 cterm_normal_bg_gui_color = bg; |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7485 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7486 fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7487 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7488 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7489 csbi.cbSize = sizeof(csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7490 if (has_csbiex) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7491 pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7492 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7493 csbi.cbSize = sizeof(csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7494 csbi.srWindow.Right += 1; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7495 csbi.srWindow.Bottom += 1; |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7496 csbi.ColorTable[g_color_index_bg] = (COLORREF)bg; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7497 csbi.ColorTable[g_color_index_fg] = (COLORREF)fg; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7498 if (has_csbiex) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7499 pSetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7500 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7501 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7502 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7503 static void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7504 reset_console_color_rgb(void) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7505 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7506 # ifdef FEAT_TERMGUICOLORS |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7507 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7508 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7509 csbi.cbSize = sizeof(csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7510 if (has_csbiex) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7511 pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7512 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7513 csbi.cbSize = sizeof(csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7514 csbi.srWindow.Right += 1; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7515 csbi.srWindow.Bottom += 1; |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7516 csbi.ColorTable[g_color_index_bg] = (COLORREF)save_console_bg_rgb; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7517 csbi.ColorTable[g_color_index_fg] = (COLORREF)save_console_fg_rgb; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7518 if (has_csbiex) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7519 pSetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7520 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7521 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7522 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7523 void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7524 control_console_color_rgb(void) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7525 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7526 if (USE_VTP) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7527 set_console_color_rgb(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7528 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7529 reset_console_color_rgb(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7530 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7531 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7532 int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7533 use_vtp(void) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7534 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7535 return USE_VTP; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7536 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7537 |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7538 int |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7539 is_term_win32(void) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7540 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7541 return T_NAME != NULL && STRCMP(T_NAME, "win32") == 0; |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7542 } |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7543 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7544 int |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7545 has_vtp_working(void) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7546 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7547 return vtp_working; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7548 } |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7549 |
15848
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
7550 #endif |
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
7551 |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7552 int |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7553 has_conpty_working(void) |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7554 { |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7555 return conpty_working; |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7556 } |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7557 |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7558 int |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7559 get_conpty_type(void) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7560 { |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7561 return conpty_type; |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7562 } |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7563 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7564 int |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7565 is_conpty_stable(void) |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7566 { |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7567 return conpty_stable; |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7568 } |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7569 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7570 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) || defined(PROTO) |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7571 void |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7572 resize_console_buf(void) |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7573 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7574 CONSOLE_SCREEN_BUFFER_INFO csbi; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7575 COORD coord; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7576 SMALL_RECT newsize; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7577 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7578 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7579 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7580 coord.X = SRWIDTH(csbi.srWindow); |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7581 coord.Y = SRHEIGHT(csbi.srWindow); |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7582 SetConsoleScreenBufferSize(g_hConOut, coord); |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7583 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7584 newsize.Left = 0; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7585 newsize.Top = 0; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7586 newsize.Right = coord.X - 1; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7587 newsize.Bottom = coord.Y - 1; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7588 SetConsoleWindowInfo(g_hConOut, TRUE, &newsize); |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7589 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7590 SetConsoleScreenBufferSize(g_hConOut, coord); |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7591 } |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7592 } |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7593 #endif |