Mercurial > vim
annotate src/os_win32.c @ 16646:ea0f9a2df961 v8.1.1325
patch 8.1.1325: cannot build with +eval but without +channel and +timers
commit https://github.com/vim/vim/commit/97b0075b0d733cc58c29247b09e7887b9991d7bf
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 12 13:07:14 2019 +0200
patch 8.1.1325: cannot build with +eval but without +channel and +timers
Problem: Cannot build with +eval but without +channel and +timers. (John
Marriott)
Solution: Adjust #ifdef for get_callback().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 May 2019 13:15:06 +0200 |
parents | 7e733046db1d |
children | e3feaa3e5f10 |
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; |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
189 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
|
190 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
|
191 |
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
|
192 #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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
200 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
|
201 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
|
202 |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
203 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
|
204 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
|
205 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
206 # 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
|
207 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
|
208 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
|
209 # endif |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
210 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
211 # 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
|
212 # 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
|
213 # else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
214 # 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
|
215 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
216 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
217 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
|
218 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
|
219 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
220 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
221 /* 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
|
222 #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
|
223 # 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
|
224 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
225 |
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
|
226 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 227 static int suppress_winsize = 1; /* don't fiddle with console */ |
228 #endif | |
229 | |
2612 | 230 static char_u *exe_path = NULL; |
231 | |
5633 | 232 static BOOL win8_or_later = FALSE; |
233 | |
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
|
234 #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
|
235 /* 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
|
236 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
|
237 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 } 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 #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
|
254 |
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 * 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
|
257 */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
258 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
|
259 # 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
|
260 (((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
|
261 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
262 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
|
263 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
|
264 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
265 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
|
266 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
|
267 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
|
268 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
|
269 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
270 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
|
271 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
|
272 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
273 pRtlGetVersion = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
274 (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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
280 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
|
281 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
282 |
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
|
283 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
5580 | 284 /* |
285 * Version of ReadConsoleInput() that works with IME. | |
5590 | 286 * Works around problems on Windows 8. |
5580 | 287 */ |
288 static BOOL | |
289 read_console_input( | |
5590 | 290 HANDLE hInput, |
291 INPUT_RECORD *lpBuffer, | |
292 DWORD nLength, | |
293 LPDWORD lpEvents) | |
5580 | 294 { |
295 enum | |
296 { | |
5590 | 297 IRSIZE = 10 |
5580 | 298 }; |
5590 | 299 static INPUT_RECORD s_irCache[IRSIZE]; |
5580 | 300 static DWORD s_dwIndex = 0; |
301 static DWORD s_dwMax = 0; | |
5590 | 302 DWORD dwEvents; |
5635 | 303 int head; |
304 int tail; | |
305 int i; | |
5580 | 306 |
6981 | 307 if (nLength == -2) |
308 return (s_dwMax > 0) ? TRUE : FALSE; | |
309 | |
5633 | 310 if (!win8_or_later) |
311 { | |
312 if (nLength == -1) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
313 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
314 return ReadConsoleInputW(hInput, lpBuffer, 1, &dwEvents); |
5633 | 315 } |
316 | |
5580 | 317 if (s_dwMax == 0) |
318 { | |
5590 | 319 if (nLength == -1) |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
320 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
321 if (!ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents)) |
5590 | 322 return FALSE; |
5580 | 323 s_dwIndex = 0; |
5590 | 324 s_dwMax = dwEvents; |
325 if (dwEvents == 0) | |
5580 | 326 { |
5590 | 327 *lpEvents = 0; |
328 return TRUE; | |
5580 | 329 } |
5635 | 330 |
331 if (s_dwMax > 1) | |
332 { | |
333 head = 0; | |
334 tail = s_dwMax - 1; | |
335 while (head != tail) | |
336 { | |
337 if (s_irCache[head].EventType == WINDOW_BUFFER_SIZE_EVENT | |
338 && s_irCache[head + 1].EventType | |
339 == WINDOW_BUFFER_SIZE_EVENT) | |
340 { | |
341 /* Remove duplicate event to avoid flicker. */ | |
342 for (i = head; i < tail; ++i) | |
343 s_irCache[i] = s_irCache[i + 1]; | |
344 --tail; | |
345 continue; | |
346 } | |
347 head++; | |
348 } | |
349 s_dwMax = tail + 1; | |
350 } | |
5580 | 351 } |
5635 | 352 |
5590 | 353 *lpBuffer = s_irCache[s_dwIndex]; |
6981 | 354 if (!(nLength == -1 || nLength == -2) && ++s_dwIndex >= s_dwMax) |
5580 | 355 s_dwMax = 0; |
5590 | 356 *lpEvents = 1; |
5580 | 357 return TRUE; |
358 } | |
359 | |
360 /* | |
361 * Version of PeekConsoleInput() that works with IME. | |
362 */ | |
363 static BOOL | |
364 peek_console_input( | |
5590 | 365 HANDLE hInput, |
366 INPUT_RECORD *lpBuffer, | |
367 DWORD nLength, | |
368 LPDWORD lpEvents) | |
5580 | 369 { |
5590 | 370 return read_console_input(hInput, lpBuffer, -1, lpEvents); |
5580 | 371 } |
372 | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
373 # ifdef FEAT_CLIENTSERVER |
6981 | 374 static DWORD |
375 msg_wait_for_multiple_objects( | |
376 DWORD nCount, | |
377 LPHANDLE pHandles, | |
378 BOOL fWaitAll, | |
379 DWORD dwMilliseconds, | |
380 DWORD dwWakeMask) | |
381 { | |
382 if (read_console_input(NULL, NULL, -2, NULL)) | |
383 return WAIT_OBJECT_0; | |
384 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, | |
385 dwMilliseconds, dwWakeMask); | |
386 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
387 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
388 |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
389 # ifndef FEAT_CLIENTSERVER |
6981 | 390 static DWORD |
391 wait_for_single_object( | |
392 HANDLE hHandle, | |
393 DWORD dwMilliseconds) | |
394 { | |
395 if (read_console_input(NULL, NULL, -2, NULL)) | |
396 return WAIT_OBJECT_0; | |
397 return WaitForSingleObject(hHandle, dwMilliseconds); | |
398 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
399 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
400 #endif |
6981 | 401 |
7 | 402 static void |
403 get_exe_name(void) | |
404 { | |
2630 | 405 /* Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned |
406 * as the maximum length that works (plus a NUL byte). */ | |
407 #define MAX_ENV_PATH_LEN 8192 | |
408 char temp[MAX_ENV_PATH_LEN]; | |
2612 | 409 char_u *p; |
7 | 410 |
411 if (exe_name == NULL) | |
412 { | |
413 /* store the name of the executable, may be used for $VIM */ | |
2630 | 414 GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1); |
7 | 415 if (*temp != NUL) |
416 exe_name = FullName_save((char_u *)temp, FALSE); | |
417 } | |
819 | 418 |
2612 | 419 if (exe_path == NULL && exe_name != NULL) |
819 | 420 { |
2615 | 421 exe_path = vim_strnsave(exe_name, |
422 (int)(gettail_sep(exe_name) - exe_name)); | |
2612 | 423 if (exe_path != NULL) |
819 | 424 { |
2612 | 425 /* Append our starting directory to $PATH, so that when doing |
426 * "!xxd" it's found in our starting directory. Needed because | |
427 * SearchPath() also looks there. */ | |
428 p = mch_getenv("PATH"); | |
2630 | 429 if (p == NULL |
430 || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN) | |
2612 | 431 { |
2630 | 432 if (p == NULL || *p == NUL) |
433 temp[0] = NUL; | |
434 else | |
435 { | |
436 STRCPY(temp, p); | |
437 STRCAT(temp, ";"); | |
438 } | |
2612 | 439 STRCAT(temp, exe_path); |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
440 vim_setenv((char_u *)"PATH", (char_u *)temp); |
2612 | 441 } |
819 | 442 } |
443 } | |
7 | 444 } |
445 | |
2612 | 446 /* |
3361 | 447 * Unescape characters in "p" that appear in "escaped". |
448 */ | |
449 static void | |
450 unescape_shellxquote(char_u *p, char_u *escaped) | |
451 { | |
3386 | 452 int l = (int)STRLEN(p); |
3361 | 453 int n; |
454 | |
455 while (*p != NUL) | |
456 { | |
457 if (*p == '^' && vim_strchr(escaped, p[1]) != NULL) | |
458 mch_memmove(p, p + 1, l--); | |
459 n = (*mb_ptr2len)(p); | |
460 p += n; | |
461 l -= n; | |
462 } | |
463 } | |
464 | |
465 /* | |
2612 | 466 * Load library "name". |
467 */ | |
468 HINSTANCE | |
469 vimLoadLib(char *name) | |
470 { | |
3902 | 471 HINSTANCE dll = NULL; |
3889 | 472 |
473 /* NOTE: Do not use mch_dirname() and mch_chdir() here, they may call | |
474 * vimLoadLib() recursively, which causes a stack overflow. */ | |
2612 | 475 if (exe_path == NULL) |
476 get_exe_name(); | |
3902 | 477 if (exe_path != NULL) |
2612 | 478 { |
3902 | 479 WCHAR old_dirw[MAXPATHL]; |
480 | |
481 if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) | |
482 { | |
483 /* Change directory to where the executable is, both to make | |
484 * sure we find a .dll there and to avoid looking for a .dll | |
485 * in the current directory. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
486 SetCurrentDirectory((LPCSTR)exe_path); |
3902 | 487 dll = LoadLibrary(name); |
488 SetCurrentDirectoryW(old_dirw); | |
489 return dll; | |
490 } | |
2612 | 491 } |
492 return dll; | |
493 } | |
494 | |
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
|
495 #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
|
496 /* |
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 * 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
|
498 */ |
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 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
|
500 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
|
501 { |
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 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
|
503 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
|
504 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
|
505 |
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 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
|
507 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
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 } |
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 #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
|
516 |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
517 #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
|
518 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
519 * 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
|
520 * 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
|
521 * 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
|
522 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
523 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
|
524 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
|
525 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
526 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
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
534 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
|
535 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
|
536 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
|
537 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
|
538 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
|
539 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
|
540 + 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
|
541 .VirtualAddress); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
542 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
|
543 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
544 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
|
545 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
546 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
|
547 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
|
548 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
|
549 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
550 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
|
551 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
552 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
|
553 + (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
|
554 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
|
555 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
556 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
|
557 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
558 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
|
559 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
|
560 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
|
561 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
|
562 default: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
563 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
|
564 } |
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 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
|
569 } |
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 * 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
|
573 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
574 HINSTANCE |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
575 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
|
576 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
577 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
|
578 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
579 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
|
580 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
|
581 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
|
582 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
|
583 } |
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 * 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
|
587 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
588 void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
589 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
|
590 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
591 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
|
592 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
593 #endif |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
594 |
7 | 595 #if defined(DYNAMIC_GETTEXT) || defined(PROTO) |
596 # ifndef GETTEXT_DLL | |
597 # 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
|
598 # 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
|
599 # define GETTEXT_DLL_ALT2 "intl.dll" |
7 | 600 # endif |
3622 | 601 /* Dummy functions */ |
36 | 602 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
|
603 static char *null_libintl_ngettext(const char *, const char *, unsigned long n); |
36 | 604 static char *null_libintl_textdomain(const char *); |
605 static char *null_libintl_bindtextdomain(const char *, const char *); | |
606 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
|
607 static int null_libintl_wputenv(const wchar_t *); |
7 | 608 |
2612 | 609 static HINSTANCE hLibintlDLL = NULL; |
36 | 610 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
|
611 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
|
612 = null_libintl_ngettext; |
36 | 613 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; |
614 char *(*dyn_libintl_bindtextdomain)(const char *, const char *) | |
7 | 615 = null_libintl_bindtextdomain; |
36 | 616 char *(*dyn_libintl_bind_textdomain_codeset)(const char *, const char *) |
617 = 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
|
618 int (*dyn_libintl_wputenv)(const wchar_t *) = null_libintl_wputenv; |
7 | 619 |
620 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
621 dyn_libintl_init(void) |
7 | 622 { |
623 int i; | |
624 static struct | |
625 { | |
626 char *name; | |
627 FARPROC *ptr; | |
628 } libintl_entry[] = | |
629 { | |
630 {"gettext", (FARPROC*)&dyn_libintl_gettext}, | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
631 {"ngettext", (FARPROC*)&dyn_libintl_ngettext}, |
7 | 632 {"textdomain", (FARPROC*)&dyn_libintl_textdomain}, |
633 {"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, | |
634 {NULL, NULL} | |
635 }; | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
636 HINSTANCE hmsvcrt; |
7 | 637 |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
638 // 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
|
639 if (hLibintlDLL != NULL) |
7 | 640 return 1; |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
641 // 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
|
642 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
|
643 #ifdef GETTEXT_DLL_ALT1 |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
644 if (!hLibintlDLL) |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
645 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
|
646 #endif |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
647 #ifdef GETTEXT_DLL_ALT2 |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
648 if (!hLibintlDLL) |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
649 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT2); |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
650 #endif |
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
651 if (!hLibintlDLL) |
7 | 652 { |
2612 | 653 if (p_verbose > 0) |
7 | 654 { |
2612 | 655 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
656 semsg(_(e_loadlib), GETTEXT_DLL); |
2612 | 657 verbose_leave(); |
7 | 658 } |
2612 | 659 return 0; |
7 | 660 } |
661 for (i = 0; libintl_entry[i].name != NULL | |
662 && libintl_entry[i].ptr != NULL; ++i) | |
663 { | |
664 if ((*libintl_entry[i].ptr = (FARPROC)GetProcAddress(hLibintlDLL, | |
665 libintl_entry[i].name)) == NULL) | |
666 { | |
667 dyn_libintl_end(); | |
668 if (p_verbose > 0) | |
292 | 669 { |
670 verbose_enter(); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
671 semsg(_(e_loadfunc), libintl_entry[i].name); |
292 | 672 verbose_leave(); |
673 } | |
7 | 674 return 0; |
675 } | |
676 } | |
36 | 677 |
678 /* The bind_textdomain_codeset() function is optional. */ | |
323 | 679 dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL, |
36 | 680 "bind_textdomain_codeset"); |
681 if (dyn_libintl_bind_textdomain_codeset == NULL) | |
682 dyn_libintl_bind_textdomain_codeset = | |
683 null_libintl_bind_textdomain_codeset; | |
684 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
685 /* _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
|
686 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
|
687 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
|
688 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
|
689 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
|
690 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
|
691 |
7 | 692 return 1; |
693 } | |
694 | |
695 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
696 dyn_libintl_end(void) |
7 | 697 { |
698 if (hLibintlDLL) | |
699 FreeLibrary(hLibintlDLL); | |
700 hLibintlDLL = NULL; | |
701 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
|
702 dyn_libintl_ngettext = null_libintl_ngettext; |
7 | 703 dyn_libintl_textdomain = null_libintl_textdomain; |
704 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain; | |
36 | 705 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
|
706 dyn_libintl_wputenv = null_libintl_wputenv; |
7 | 707 } |
708 | |
709 static char * | |
26 | 710 null_libintl_gettext(const char *msgid) |
7 | 711 { |
712 return (char*)msgid; | |
713 } | |
714 | |
715 static char * | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
716 null_libintl_ngettext( |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
717 const char *msgid, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
718 const char *msgid_plural, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
719 unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
720 { |
9762
93dcc4329c74
commit https://github.com/vim/vim/commit/c90f2aedd0a5dc2cc75bc9b5f475f8a3e3fe36b1
Christian Brabandt <cb@256bit.org>
parents:
9754
diff
changeset
|
721 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
|
722 } |
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 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
|
725 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
|
726 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
|
727 const char *dirname UNUSED) |
7 | 728 { |
729 return NULL; | |
730 } | |
731 | |
732 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
|
733 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
|
734 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
|
735 const char *codeset UNUSED) |
36 | 736 { |
737 return NULL; | |
738 } | |
739 | |
740 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
|
741 null_libintl_textdomain(const char *domainname UNUSED) |
7 | 742 { |
743 return NULL; | |
744 } | |
745 | |
11929
3457728d1a58
patch 8.0.0844: wrong function prototype because of missing static
Christian Brabandt <cb@256bit.org>
parents:
11921
diff
changeset
|
746 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
|
747 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
|
748 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
749 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
|
750 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
751 |
7 | 752 #endif /* DYNAMIC_GETTEXT */ |
753 | |
754 /* This symbol is not defined in older versions of the SDK or Visual C++ */ | |
755 | |
756 #ifndef VER_PLATFORM_WIN32_WINDOWS | |
757 # define VER_PLATFORM_WIN32_WINDOWS 1 | |
758 #endif | |
759 | |
760 DWORD g_PlatformId; | |
761 | |
762 #ifdef HAVE_ACL | |
3927 | 763 # ifndef PROTO |
764 # include <aclapi.h> | |
765 # endif | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
766 # ifndef PROTECTED_DACL_SECURITY_INFORMATION |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
767 # define PROTECTED_DACL_SECURITY_INFORMATION 0x80000000L |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
768 # endif |
7 | 769 #endif |
770 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
771 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
772 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
773 * Enables or disables the specified privilege. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
774 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
775 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
776 win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
777 { |
5590 | 778 BOOL bResult; |
779 LUID luid; | |
780 HANDLE hToken; | |
781 TOKEN_PRIVILEGES tokenPrivileges; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
782 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
783 if (!OpenProcessToken(GetCurrentProcess(), |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
784 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
785 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
786 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
787 if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
788 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
789 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
790 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
791 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
792 |
6047 | 793 tokenPrivileges.PrivilegeCount = 1; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
794 tokenPrivileges.Privileges[0].Luid = luid; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
795 tokenPrivileges.Privileges[0].Attributes = bEnable ? |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
796 SE_PRIVILEGE_ENABLED : 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
797 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
798 bResult = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
799 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
800 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
801 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
802 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
803 return bResult && GetLastError() == ERROR_SUCCESS; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
804 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
805 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
806 |
7 | 807 /* |
808 * Set g_PlatformId to VER_PLATFORM_WIN32_NT (NT) or | |
809 * VER_PLATFORM_WIN32_WINDOWS (Win95). | |
810 */ | |
811 void | |
812 PlatformId(void) | |
813 { | |
814 static int done = FALSE; | |
815 | |
816 if (!done) | |
817 { | |
818 OSVERSIONINFO ovi; | |
819 | |
820 ovi.dwOSVersionInfoSize = sizeof(ovi); | |
821 GetVersionEx(&ovi); | |
822 | |
823 g_PlatformId = ovi.dwPlatformId; | |
824 | |
5633 | 825 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2) |
826 || ovi.dwMajorVersion > 6) | |
827 win8_or_later = TRUE; | |
828 | |
7 | 829 #ifdef HAVE_ACL |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
830 /* 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
|
831 win32_enable_privilege(SE_SECURITY_NAME, TRUE); |
7 | 832 #endif |
833 done = TRUE; | |
834 } | |
835 } | |
836 | |
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
|
837 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 838 |
839 #define SHIFT (SHIFT_PRESSED) | |
840 #define CTRL (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED) | |
841 #define ALT (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED) | |
842 #define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) | |
843 | |
844 | |
845 /* When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode. | |
846 * We map function keys to their ANSI terminal equivalents, as produced | |
847 * by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any | |
848 * ANSI key with a value >= '\300' is nonstandard, but provided anyway | |
849 * so that the user can have access to all SHIFT-, CTRL-, and ALT- | |
850 * combinations of function/arrow/etc keys. | |
851 */ | |
852 | |
297 | 853 static const struct |
7 | 854 { |
855 WORD wVirtKey; | |
856 BOOL fAnsiKey; | |
857 int chAlone; | |
858 int chShift; | |
859 int chCtrl; | |
860 int chAlt; | |
861 } VirtKeyMap[] = | |
862 { | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
863 // Key ANSI alone shift ctrl alt |
7 | 864 { VK_ESCAPE,FALSE, ESC, ESC, ESC, ESC, }, |
865 | |
866 { VK_F1, TRUE, ';', 'T', '^', 'h', }, | |
867 { VK_F2, TRUE, '<', 'U', '_', 'i', }, | |
868 { VK_F3, TRUE, '=', 'V', '`', 'j', }, | |
869 { VK_F4, TRUE, '>', 'W', 'a', 'k', }, | |
870 { VK_F5, TRUE, '?', 'X', 'b', 'l', }, | |
871 { VK_F6, TRUE, '@', 'Y', 'c', 'm', }, | |
872 { VK_F7, TRUE, 'A', 'Z', 'd', 'n', }, | |
873 { VK_F8, TRUE, 'B', '[', 'e', 'o', }, | |
874 { VK_F9, TRUE, 'C', '\\', 'f', 'p', }, | |
875 { 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
|
876 { 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
|
877 { 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
|
878 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
879 { 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
|
880 { 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
|
881 { 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
|
882 { 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
|
883 { 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
|
884 { 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
|
885 { 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
|
886 { 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
|
887 { 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
|
888 { 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
|
889 { 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
|
890 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
891 { VK_SNAPSHOT,TRUE, 0, 0, 0, 'r', }, // PrtScrn |
7 | 892 |
893 #if 0 | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
894 // 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
|
895 { 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
|
896 { 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
|
897 { 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
|
898 { 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
|
899 { 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
|
900 { 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
|
901 { 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
|
902 { 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
|
903 #endif |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
904 { 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
|
905 { 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
|
906 // { 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
|
907 { 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
|
908 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
909 { 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
|
910 { 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
|
911 { 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
|
912 { 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
|
913 { 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
|
914 { 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
|
915 { 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
|
916 { 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
|
917 { 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
|
918 // 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
|
919 { VK_NUMPAD9,TRUE, '\376', '\377', '|', '}', }, |
7 | 920 }; |
921 | |
922 | |
923 #ifdef _MSC_VER | |
924 // The ToAscii bug destroys several registers. Need to turn off optimization | |
925 // or the GetConsoleKeyboardLayoutName hack will fail in non-debug versions | |
797 | 926 # pragma warning(push) |
927 # pragma warning(disable: 4748) | |
7 | 928 # pragma optimize("", off) |
929 #endif | |
930 | |
931 #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
|
932 # define UChar UnicodeChar |
7 | 933 #else |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
934 # define UChar uChar.UnicodeChar |
7 | 935 #endif |
936 | |
937 /* The return code indicates key code size. */ | |
938 static int | |
939 win32_kbd_patch_key( | |
26 | 940 KEY_EVENT_RECORD *pker) |
7 | 941 { |
942 UINT uMods = pker->dwControlKeyState; | |
943 static int s_iIsDead = 0; | |
944 static WORD awAnsiCode[2]; | |
945 static BYTE abKeystate[256]; | |
946 | |
947 | |
948 if (s_iIsDead == 2) | |
949 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
950 pker->UChar = (WCHAR) awAnsiCode[1]; |
7 | 951 s_iIsDead = 0; |
952 return 1; | |
953 } | |
954 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
955 if (pker->UChar != 0) |
7 | 956 return 1; |
957 | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1752
diff
changeset
|
958 vim_memset(abKeystate, 0, sizeof (abKeystate)); |
7 | 959 |
960 /* Clear any pending dead keys */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
961 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); |
7 | 962 |
963 if (uMods & SHIFT_PRESSED) | |
964 abKeystate[VK_SHIFT] = 0x80; | |
965 if (uMods & CAPSLOCK_ON) | |
966 abKeystate[VK_CAPITAL] = 1; | |
967 | |
968 if ((uMods & ALT_GR) == ALT_GR) | |
969 { | |
970 abKeystate[VK_CONTROL] = abKeystate[VK_LCONTROL] = | |
971 abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80; | |
972 } | |
973 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
974 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
|
975 abKeystate, awAnsiCode, 2, 0); |
7 | 976 |
977 if (s_iIsDead > 0) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
978 pker->UChar = (WCHAR) awAnsiCode[0]; |
7 | 979 |
980 return s_iIsDead; | |
981 } | |
982 | |
983 #ifdef _MSC_VER | |
984 /* MUST switch optimization on again here, otherwise a call to | |
985 * decode_key_event() may crash (e.g. when hitting caps-lock) */ | |
986 # pragma optimize("", on) | |
797 | 987 # pragma warning(pop) |
7 | 988 |
989 # if (_MSC_VER < 1100) | |
990 /* MUST turn off global optimisation for this next function, or | |
991 * pressing ctrl-minus in insert mode crashes Vim when built with | |
992 * VC4.1. -- negri. */ | |
993 # pragma optimize("g", off) | |
994 # endif | |
995 #endif | |
996 | |
997 static BOOL g_fJustGotFocus = FALSE; | |
998 | |
999 /* | |
1000 * Decode a KEY_EVENT into one or two keystrokes | |
1001 */ | |
1002 static BOOL | |
1003 decode_key_event( | |
1004 KEY_EVENT_RECORD *pker, | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1005 WCHAR *pch, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1006 WCHAR *pch2, |
7 | 1007 int *pmodifiers, |
1008 BOOL fDoPost) | |
1009 { | |
1010 int i; | |
1011 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL); | |
1012 | |
1013 *pch = *pch2 = NUL; | |
1014 g_fJustGotFocus = FALSE; | |
1015 | |
1016 /* ignore key up events */ | |
1017 if (!pker->bKeyDown) | |
1018 return FALSE; | |
1019 | |
1020 /* ignore some keystrokes */ | |
1021 switch (pker->wVirtualKeyCode) | |
1022 { | |
1023 /* modifiers */ | |
1024 case VK_SHIFT: | |
1025 case VK_CONTROL: | |
1026 case VK_MENU: /* Alt key */ | |
1027 return FALSE; | |
1028 | |
1029 default: | |
1030 break; | |
1031 } | |
1032 | |
1033 /* special cases */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1034 if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL) |
7 | 1035 { |
1036 /* Ctrl-6 is Ctrl-^ */ | |
1037 if (pker->wVirtualKeyCode == '6') | |
1038 { | |
1039 *pch = Ctrl_HAT; | |
1040 return TRUE; | |
1041 } | |
1042 /* Ctrl-2 is Ctrl-@ */ | |
1043 else if (pker->wVirtualKeyCode == '2') | |
1044 { | |
1045 *pch = NUL; | |
1046 return TRUE; | |
1047 } | |
1048 /* Ctrl-- is Ctrl-_ */ | |
1049 else if (pker->wVirtualKeyCode == 0xBD) | |
1050 { | |
1051 *pch = Ctrl__; | |
1052 return TRUE; | |
1053 } | |
1054 } | |
1055 | |
1056 /* Shift-TAB */ | |
1057 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) | |
1058 { | |
1059 *pch = K_NUL; | |
1060 *pch2 = '\017'; | |
1061 return TRUE; | |
1062 } | |
1063 | |
1064 for (i = sizeof(VirtKeyMap) / sizeof(VirtKeyMap[0]); --i >= 0; ) | |
1065 { | |
1066 if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode) | |
1067 { | |
1068 if (nModifs == 0) | |
1069 *pch = VirtKeyMap[i].chAlone; | |
1070 else if ((nModifs & SHIFT) != 0 && (nModifs & ~SHIFT) == 0) | |
1071 *pch = VirtKeyMap[i].chShift; | |
1072 else if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0) | |
1073 *pch = VirtKeyMap[i].chCtrl; | |
1074 else if ((nModifs & ALT) != 0 && (nModifs & ~ALT) == 0) | |
1075 *pch = VirtKeyMap[i].chAlt; | |
1076 | |
1077 if (*pch != 0) | |
1078 { | |
1079 if (VirtKeyMap[i].fAnsiKey) | |
1080 { | |
1081 *pch2 = *pch; | |
1082 *pch = K_NUL; | |
1083 } | |
1084 | |
1085 return TRUE; | |
1086 } | |
1087 } | |
1088 } | |
1089 | |
1090 i = win32_kbd_patch_key(pker); | |
1091 | |
1092 if (i < 0) | |
1093 *pch = NUL; | |
1094 else | |
1095 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1096 *pch = (i > 0) ? pker->UChar : NUL; |
7 | 1097 |
1098 if (pmodifiers != NULL) | |
1099 { | |
1100 /* Pass on the ALT key as a modifier, but only when not combined | |
1101 * with CTRL (which is ALTGR). */ | |
1102 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) | |
1103 *pmodifiers |= MOD_MASK_ALT; | |
1104 | |
1105 /* Pass on SHIFT only for special keys, because we don't know when | |
1106 * it's already included with the character. */ | |
1107 if ((nModifs & SHIFT) != 0 && *pch <= 0x20) | |
1108 *pmodifiers |= MOD_MASK_SHIFT; | |
1109 | |
1110 /* Pass on CTRL only for non-special keys, because we don't know | |
1111 * when it's already included with the character. And not when | |
1112 * combined with ALT (which is ALTGR). */ | |
1113 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 | |
1114 && *pch >= 0x20 && *pch < 0x80) | |
1115 *pmodifiers |= MOD_MASK_CTRL; | |
1116 } | |
1117 } | |
1118 | |
1119 return (*pch != NUL); | |
1120 } | |
1121 | |
1122 #ifdef _MSC_VER | |
1123 # pragma optimize("", on) | |
1124 #endif | |
1125 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
1126 #endif /* FEAT_GUI_MSWIN */ |
7 | 1127 |
1128 | |
1129 #ifdef FEAT_MOUSE | |
1130 | |
1131 /* | |
1132 * For the GUI the mouse handling is in gui_w32.c. | |
1133 */ | |
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
|
1134 # if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 1135 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
|
1136 mch_setmouse(int on UNUSED) |
7 | 1137 { |
1138 } | |
1139 # else | |
1140 static int g_fMouseAvail = FALSE; /* mouse present */ | |
1141 static int g_fMouseActive = FALSE; /* mouse enabled */ | |
1142 static int g_nMouseClick = -1; /* mouse status */ | |
1143 static int g_xMouse; /* mouse x coordinate */ | |
1144 static int g_yMouse; /* mouse y coordinate */ | |
1145 | |
1146 /* | |
1147 * Enable or disable mouse input | |
1148 */ | |
1149 void | |
26 | 1150 mch_setmouse(int on) |
7 | 1151 { |
1152 DWORD cmodein; | |
1153 | |
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
|
1154 # 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
|
1155 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
|
1156 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
|
1157 # endif |
7 | 1158 if (!g_fMouseAvail) |
1159 return; | |
1160 | |
1161 g_fMouseActive = on; | |
1162 GetConsoleMode(g_hConIn, &cmodein); | |
1163 | |
1164 if (g_fMouseActive) | |
1165 cmodein |= ENABLE_MOUSE_INPUT; | |
1166 else | |
1167 cmodein &= ~ENABLE_MOUSE_INPUT; | |
1168 | |
1169 SetConsoleMode(g_hConIn, cmodein); | |
1170 } | |
1171 | |
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
|
1172 |
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 #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
|
1174 /* |
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 * 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
|
1176 */ |
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 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
|
1178 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
|
1179 { |
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 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
|
1181 } |
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 #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
|
1183 |
7 | 1184 /* |
1185 * Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT, | |
1186 * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse | |
1187 * move with a button held down; and MOUSE_RELEASE after a MOUSE_DRAG | |
1188 * or a MOUSE_LEFT, _MIDDLE, or _RIGHT. We encode the button type, | |
1189 * the number of clicks, and the Shift/Ctrl/Alt modifiers in g_nMouseClick, | |
1190 * and we return the mouse position in g_xMouse and g_yMouse. | |
1191 * | |
1192 * Every MOUSE_LEFT, _MIDDLE, or _RIGHT will be followed by zero or more | |
1193 * MOUSE_DRAGs and one MOUSE_RELEASE. MOUSE_RELEASE will be followed only | |
1194 * by MOUSE_LEFT, _MIDDLE, or _RIGHT. | |
1195 * | |
1196 * For multiple clicks, we send, say, MOUSE_LEFT/1 click, MOUSE_RELEASE, | |
1197 * MOUSE_LEFT/2 clicks, MOUSE_RELEASE, MOUSE_LEFT/3 clicks, MOUSE_RELEASE, .... | |
1198 * | |
1199 * Windows will send us MOUSE_MOVED notifications whenever the mouse | |
1200 * moves, even if it stays within the same character cell. We ignore | |
1201 * all MOUSE_MOVED messages if the position hasn't really changed, and | |
1202 * we ignore all MOUSE_MOVED messages where no button is held down (i.e., | |
1203 * we're only interested in MOUSE_DRAG). | |
1204 * | |
1205 * All of this is complicated by the code that fakes MOUSE_MIDDLE on | |
1206 * 2-button mouses by pressing the left & right buttons simultaneously. | |
1207 * In practice, it's almost impossible to click both at the same time, | |
1208 * so we need to delay a little. Also, we tend not to get MOUSE_RELEASE | |
1209 * in such cases, if the user is clicking quickly. | |
1210 */ | |
1211 static BOOL | |
1212 decode_mouse_event( | |
26 | 1213 MOUSE_EVENT_RECORD *pmer) |
7 | 1214 { |
1215 static int s_nOldButton = -1; | |
1216 static int s_nOldMouseClick = -1; | |
1217 static int s_xOldMouse = -1; | |
1218 static int s_yOldMouse = -1; | |
1219 static linenr_T s_old_topline = 0; | |
1220 #ifdef FEAT_DIFF | |
1221 static int s_old_topfill = 0; | |
1222 #endif | |
1223 static int s_cClicks = 1; | |
1224 static BOOL s_fReleased = TRUE; | |
1225 static DWORD s_dwLastClickTime = 0; | |
1226 static BOOL s_fNextIsMiddle = FALSE; | |
1227 | |
1228 static DWORD cButtons = 0; /* number of buttons supported */ | |
1229 | |
1230 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; | |
1231 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; | |
1232 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED; | |
1233 const DWORD LEFT_RIGHT = LEFT | RIGHT; | |
1234 | |
1235 int nButton; | |
1236 | |
1237 if (cButtons == 0 && !GetNumberOfConsoleMouseButtons(&cButtons)) | |
1238 cButtons = 2; | |
1239 | |
1240 if (!g_fMouseAvail || !g_fMouseActive) | |
1241 { | |
1242 g_nMouseClick = -1; | |
1243 return FALSE; | |
1244 } | |
1245 | |
1246 /* get a spurious MOUSE_EVENT immediately after receiving focus; ignore */ | |
1247 if (g_fJustGotFocus) | |
1248 { | |
1249 g_fJustGotFocus = FALSE; | |
1250 return FALSE; | |
1251 } | |
1252 | |
1253 /* unprocessed mouse click? */ | |
1254 if (g_nMouseClick != -1) | |
1255 return TRUE; | |
1256 | |
1257 nButton = -1; | |
1258 g_xMouse = pmer->dwMousePosition.X; | |
1259 g_yMouse = pmer->dwMousePosition.Y; | |
1260 | |
1261 if (pmer->dwEventFlags == MOUSE_MOVED) | |
1262 { | |
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
|
1263 /* Ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these |
7 | 1264 * events even when the mouse moves only within a char cell.) */ |
1265 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) | |
1266 return FALSE; | |
1267 } | |
1268 | |
1269 /* If no buttons are pressed... */ | |
1270 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) | |
1271 { | |
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
|
1272 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
|
1273 |
7 | 1274 /* If the last thing returned was MOUSE_RELEASE, ignore this */ |
1275 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
|
1276 { |
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 #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
|
1278 /* 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
|
1279 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
|
1280 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
|
1281 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
|
1282 #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
|
1283 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
|
1284 } |
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 |
7 | 1286 s_fReleased = TRUE; |
1287 } | |
1288 else /* one or more buttons pressed */ | |
1289 { | |
1290 /* on a 2-button mouse, hold down left and right buttons | |
1291 * simultaneously to get MIDDLE. */ | |
1292 | |
1293 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) | |
1294 { | |
1295 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); | |
1296 | |
1297 /* if either left or right button only is pressed, see if the | |
4352 | 1298 * next mouse event has both of them pressed */ |
7 | 1299 if (dwLR == LEFT || dwLR == RIGHT) |
1300 { | |
1301 for (;;) | |
1302 { | |
1303 /* wait a short time for next input event */ | |
1304 if (WaitForSingleObject(g_hConIn, p_mouset / 3) | |
1305 != WAIT_OBJECT_0) | |
1306 break; | |
1307 else | |
1308 { | |
1309 DWORD cRecords = 0; | |
1310 INPUT_RECORD ir; | |
1311 MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent; | |
1312 | |
5580 | 1313 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1314 |
1315 if (cRecords == 0 || ir.EventType != MOUSE_EVENT | |
1316 || !(pmer2->dwButtonState & LEFT_RIGHT)) | |
1317 break; | |
1318 else | |
1319 { | |
1320 if (pmer2->dwEventFlags != MOUSE_MOVED) | |
1321 { | |
5580 | 1322 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1323 |
1324 return decode_mouse_event(pmer2); | |
1325 } | |
1326 else if (s_xOldMouse == pmer2->dwMousePosition.X && | |
1327 s_yOldMouse == pmer2->dwMousePosition.Y) | |
1328 { | |
1329 /* throw away spurious mouse move */ | |
5580 | 1330 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1331 |
1332 /* are there any more mouse events in queue? */ | |
5580 | 1333 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1334 |
1335 if (cRecords==0 || ir.EventType != MOUSE_EVENT) | |
1336 break; | |
1337 } | |
1338 else | |
1339 break; | |
1340 } | |
1341 } | |
1342 } | |
1343 } | |
1344 } | |
1345 | |
1346 if (s_fNextIsMiddle) | |
1347 { | |
1348 nButton = (pmer->dwEventFlags == MOUSE_MOVED) | |
1349 ? MOUSE_DRAG : MOUSE_MIDDLE; | |
1350 s_fNextIsMiddle = FALSE; | |
1351 } | |
1352 else if (cButtons == 2 && | |
1353 ((pmer->dwButtonState & LEFT_RIGHT) == LEFT_RIGHT)) | |
1354 { | |
1355 nButton = MOUSE_MIDDLE; | |
1356 | |
1357 if (! s_fReleased && pmer->dwEventFlags != MOUSE_MOVED) | |
1358 { | |
1359 s_fNextIsMiddle = TRUE; | |
1360 nButton = MOUSE_RELEASE; | |
1361 } | |
1362 } | |
1363 else if ((pmer->dwButtonState & LEFT) == LEFT) | |
1364 nButton = MOUSE_LEFT; | |
1365 else if ((pmer->dwButtonState & MIDDLE) == MIDDLE) | |
1366 nButton = MOUSE_MIDDLE; | |
1367 else if ((pmer->dwButtonState & RIGHT) == RIGHT) | |
1368 nButton = MOUSE_RIGHT; | |
1369 | |
1370 if (! s_fReleased && ! s_fNextIsMiddle | |
1371 && nButton != s_nOldButton && s_nOldButton != MOUSE_DRAG) | |
1372 return FALSE; | |
1373 | |
1374 s_fReleased = s_fNextIsMiddle; | |
1375 } | |
1376 | |
1377 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) | |
1378 { | |
1379 /* button pressed or released, without mouse moving */ | |
1380 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1381 { | |
1382 DWORD dwCurrentTime = GetTickCount(); | |
1383 | |
1384 if (s_xOldMouse != g_xMouse | |
1385 || s_yOldMouse != g_yMouse | |
1386 || s_nOldButton != nButton | |
1387 || s_old_topline != curwin->w_topline | |
1388 #ifdef FEAT_DIFF | |
1389 || s_old_topfill != curwin->w_topfill | |
1390 #endif | |
1391 || (int)(dwCurrentTime - s_dwLastClickTime) > p_mouset) | |
1392 { | |
1393 s_cClicks = 1; | |
1394 } | |
1395 else if (++s_cClicks > 4) | |
1396 { | |
1397 s_cClicks = 1; | |
1398 } | |
1399 | |
1400 s_dwLastClickTime = dwCurrentTime; | |
1401 } | |
1402 } | |
1403 else if (pmer->dwEventFlags == MOUSE_MOVED) | |
1404 { | |
1405 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1406 nButton = MOUSE_DRAG; | |
1407 | |
1408 s_cClicks = 1; | |
1409 } | |
1410 | |
1411 if (nButton == -1) | |
1412 return FALSE; | |
1413 | |
1414 if (nButton != MOUSE_RELEASE) | |
1415 s_nOldButton = nButton; | |
1416 | |
1417 g_nMouseClick = nButton; | |
1418 | |
1419 if (pmer->dwControlKeyState & SHIFT_PRESSED) | |
1420 g_nMouseClick |= MOUSE_SHIFT; | |
1421 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) | |
1422 g_nMouseClick |= MOUSE_CTRL; | |
1423 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) | |
1424 g_nMouseClick |= MOUSE_ALT; | |
1425 | |
1426 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) | |
1427 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); | |
1428 | |
1429 /* only pass on interesting (i.e., different) mouse events */ | |
1430 if (s_xOldMouse == g_xMouse | |
1431 && s_yOldMouse == g_yMouse | |
1432 && s_nOldMouseClick == g_nMouseClick) | |
1433 { | |
1434 g_nMouseClick = -1; | |
1435 return FALSE; | |
1436 } | |
1437 | |
1438 s_xOldMouse = g_xMouse; | |
1439 s_yOldMouse = g_yMouse; | |
1440 s_old_topline = curwin->w_topline; | |
1441 #ifdef FEAT_DIFF | |
1442 s_old_topfill = curwin->w_topfill; | |
1443 #endif | |
1444 s_nOldMouseClick = g_nMouseClick; | |
1445 | |
1446 return TRUE; | |
1447 } | |
1448 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
1449 # endif /* FEAT_GUI_MSWIN */ |
7 | 1450 #endif /* FEAT_MOUSE */ |
1451 | |
1452 | |
1453 #ifdef MCH_CURSOR_SHAPE | |
1454 /* | |
1455 * Set the shape of the cursor. | |
1456 * 'thickness' can be from 1 (thin) to 99 (block) | |
1457 */ | |
1458 static void | |
1459 mch_set_cursor_shape(int thickness) | |
1460 { | |
1461 CONSOLE_CURSOR_INFO ConsoleCursorInfo; | |
1462 ConsoleCursorInfo.dwSize = thickness; | |
1463 ConsoleCursorInfo.bVisible = s_cursor_visible; | |
1464 | |
1465 SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo); | |
1466 if (s_cursor_visible) | |
1467 SetConsoleCursorPosition(g_hConOut, g_coord); | |
1468 } | |
1469 | |
1470 void | |
1471 mch_update_cursor(void) | |
1472 { | |
1473 int idx; | |
1474 int thickness; | |
1475 | |
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
|
1476 # 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
|
1477 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
|
1478 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
|
1479 # 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
|
1480 |
7 | 1481 /* |
1482 * How the cursor is drawn depends on the current mode. | |
1483 */ | |
1484 idx = get_shape_idx(FALSE); | |
1485 | |
1486 if (shape_table[idx].shape == SHAPE_BLOCK) | |
1487 thickness = 99; /* 100 doesn't work on W95 */ | |
1488 else | |
1489 thickness = shape_table[idx].percentage; | |
1490 mch_set_cursor_shape(thickness); | |
1491 } | |
1492 #endif | |
1493 | |
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
|
1494 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 1495 /* |
1496 * Handle FOCUS_EVENT. | |
1497 */ | |
1498 static void | |
1499 handle_focus_event(INPUT_RECORD ir) | |
1500 { | |
1501 g_fJustGotFocus = ir.Event.FocusEvent.bSetFocus; | |
1502 ui_focus_change((int)g_fJustGotFocus); | |
1503 } | |
1504 | |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1505 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
|
1506 |
7 | 1507 /* |
1508 * Wait until console input from keyboard or mouse is available, | |
1509 * 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
|
1510 * When "ignore_input" is TRUE even wait when input is available. |
7 | 1511 * Return TRUE if something is available FALSE if not. |
1512 */ | |
1513 static int | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1514 WaitForChar(long msec, int ignore_input) |
7 | 1515 { |
1516 DWORD dwNow = 0, dwEndTime = 0; | |
1517 INPUT_RECORD ir; | |
1518 DWORD cRecords; | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1519 WCHAR ch, ch2; |
8949
c44ab784f5e5
commit https://github.com/vim/vim/commit/4445f7ee708f1a1304526a5979c9dd9883a92a0a
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
1520 #ifdef FEAT_TIMERS |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1521 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
|
1522 #endif |
7 | 1523 |
1524 if (msec > 0) | |
1525 /* Wait until the specified time has elapsed. */ | |
1526 dwEndTime = GetTickCount() + msec; | |
1527 else if (msec < 0) | |
1528 /* Wait forever. */ | |
1529 dwEndTime = INFINITE; | |
1530 | |
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
|
1531 // 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
|
1532 // we might get multiple unusable mouse events in that time. |
7 | 1533 for (;;) |
1534 { | |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1535 // 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
|
1536 if (msec != 0) |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1537 { |
7866
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1538 #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
|
1539 parse_queued_messages(); |
7866
30a9f5fc3508
commit https://github.com/vim/vim/commit/ca568aeec60dd6cc13b4dcf5cec0e0a07113547f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1540 #endif |
14 | 1541 #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
|
1542 mzvim_check_threads(); |
14 | 1543 #endif |
7 | 1544 #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
|
1545 serverProcessPendingMessages(); |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1546 #endif |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1547 } |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1548 |
7 | 1549 if (0 |
1550 #ifdef FEAT_MOUSE | |
1551 || g_nMouseClick != -1 | |
1552 #endif | |
1553 #ifdef FEAT_CLIENTSERVER | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1554 || (!ignore_input && input_available()) |
7 | 1555 #endif |
1556 ) | |
1557 return TRUE; | |
1558 | |
1559 if (msec > 0) | |
1560 { | |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1561 /* 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
|
1562 * GetTickCount() may wrap around (overflow). */ |
7 | 1563 dwNow = GetTickCount(); |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1564 if ((int)(dwNow - dwEndTime) >= 0) |
7 | 1565 break; |
1566 } | |
1567 if (msec != 0) | |
1568 { | |
14 | 1569 DWORD dwWaitTime = dwEndTime - dwNow; |
1570 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
1571 #ifdef FEAT_JOB_CHANNEL |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1572 /* 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
|
1573 if (dwWaitTime > 100) |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1574 { |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1575 dwWaitTime = 100; |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1576 /* 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
|
1577 * 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
|
1578 if (channel_any_readahead()) |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1579 dwWaitTime = 10; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1580 } |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1581 #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
|
1582 #ifdef FEAT_BEVAL_GUI |
11014
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1583 if (p_beval && dwWaitTime > 100) |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1584 /* 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
|
1585 * 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
|
1586 dwWaitTime = 100; |
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1587 #endif |
14 | 1588 #ifdef FEAT_MZSCHEME |
1589 if (mzthreads_allowed() && p_mzq > 0 | |
1590 && (msec < 0 || (long)dwWaitTime > p_mzq)) | |
1591 dwWaitTime = p_mzq; /* don't wait longer than 'mzquantum' */ | |
1592 #endif | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1593 #ifdef FEAT_TIMERS |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1594 // 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
|
1595 if (dwWaitTime > 10) |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1596 { |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1597 long due_time; |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1598 |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1599 // 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
|
1600 // 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
|
1601 due_time = check_due_timer(); |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1602 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
|
1603 { |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1604 // timer may have used feedkeys(). |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1605 return FALSE; |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1606 } |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1607 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
|
1608 dwWaitTime = due_time; |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1609 } |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1610 #endif |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1611 if ( |
7 | 1612 #ifdef FEAT_CLIENTSERVER |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1613 // 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
|
1614 // 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
|
1615 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
|
1616 dwWaitTime, QS_SENDMESSAGE) != WAIT_OBJECT_0 |
7 | 1617 #else |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1618 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
|
1619 != WAIT_OBJECT_0 |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1620 #endif |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1621 ) |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1622 continue; |
7 | 1623 } |
1624 | |
1625 cRecords = 0; | |
5580 | 1626 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1627 |
1628 #ifdef FEAT_MBYTE_IME | |
1629 if (State & CMDLINE && msg_row == Rows - 1) | |
1630 { | |
1631 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
1632 | |
1633 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
1634 { | |
1635 if (csbi.dwCursorPosition.Y != msg_row) | |
1636 { | |
1637 /* The screen is now messed up, must redraw the | |
1638 * command line and later all the windows. */ | |
1639 redraw_all_later(CLEAR); | |
1640 cmdline_row -= (msg_row - csbi.dwCursorPosition.Y); | |
1641 redrawcmd(); | |
1642 } | |
1643 } | |
1644 } | |
1645 #endif | |
1646 | |
1647 if (cRecords > 0) | |
1648 { | |
1649 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) | |
1650 { | |
1651 #ifdef FEAT_MBYTE_IME | |
1652 /* Windows IME sends two '\n's with only one 'ENTER'. First: | |
1653 * wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 */ | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1654 if (ir.Event.KeyEvent.UChar == 0 |
7 | 1655 && ir.Event.KeyEvent.wVirtualKeyCode == 13) |
1656 { | |
5580 | 1657 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1658 continue; |
1659 } | |
1660 #endif | |
1661 if (decode_key_event(&ir.Event.KeyEvent, &ch, &ch2, | |
1662 NULL, FALSE)) | |
1663 return TRUE; | |
1664 } | |
1665 | |
5580 | 1666 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1667 |
1668 if (ir.EventType == FOCUS_EVENT) | |
1669 handle_focus_event(ir); | |
1670 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
|
1671 { |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1672 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
|
1673 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1674 // 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
|
1675 // 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
|
1676 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
|
1677 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1678 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
|
1679 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
|
1680 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
|
1681 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
|
1682 shell_resized(); |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1683 } |
13260
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1684 } |
7 | 1685 #ifdef FEAT_MOUSE |
1686 else if (ir.EventType == MOUSE_EVENT | |
1687 && decode_mouse_event(&ir.Event.MouseEvent)) | |
1688 return TRUE; | |
1689 #endif | |
1690 } | |
1691 else if (msec == 0) | |
1692 break; | |
1693 } | |
1694 | |
1695 #ifdef FEAT_CLIENTSERVER | |
1696 /* Something might have been received while we were waiting. */ | |
1697 if (input_available()) | |
1698 return TRUE; | |
1699 #endif | |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1700 |
7 | 1701 return FALSE; |
1702 } | |
1703 | |
1704 /* | |
1705 * return non-zero if a character is available | |
1706 */ | |
1707 int | |
26 | 1708 mch_char_avail(void) |
7 | 1709 { |
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
|
1710 # 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
|
1711 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
|
1712 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
|
1713 # endif |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1714 return WaitForChar(0L, FALSE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1715 } |
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 # 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
|
1718 /* |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1719 * 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
|
1720 */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1721 int |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1722 mch_check_messages(void) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1723 { |
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
|
1724 # 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
|
1725 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
|
1726 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
|
1727 # endif |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1728 return WaitForChar(0L, TRUE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1729 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1730 # endif |
7 | 1731 |
1732 /* | |
1733 * Create the console input. Used when reading stdin doesn't work. | |
1734 */ | |
1735 static void | |
1736 create_conin(void) | |
1737 { | |
1738 g_hConIn = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE, | |
1739 FILE_SHARE_READ|FILE_SHARE_WRITE, | |
1740 (LPSECURITY_ATTRIBUTES) NULL, | |
840 | 1741 OPEN_EXISTING, 0, (HANDLE)NULL); |
7 | 1742 did_create_conin = TRUE; |
1743 } | |
1744 | |
1745 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1746 * Get a keystroke or a mouse event, use a blocking wait. |
7 | 1747 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1748 static WCHAR |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1749 tgetch(int *pmodifiers, WCHAR *pch2) |
7 | 1750 { |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1751 WCHAR ch; |
7 | 1752 |
1753 for (;;) | |
1754 { | |
1755 INPUT_RECORD ir; | |
1756 DWORD cRecords = 0; | |
1757 | |
1758 #ifdef FEAT_CLIENTSERVER | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1759 (void)WaitForChar(-1L, FALSE); |
7 | 1760 if (input_available()) |
1761 return 0; | |
1762 # ifdef FEAT_MOUSE | |
1763 if (g_nMouseClick != -1) | |
1764 return 0; | |
1765 # endif | |
1766 #endif | |
5580 | 1767 if (read_console_input(g_hConIn, &ir, 1, &cRecords) == 0) |
7 | 1768 { |
1769 if (did_create_conin) | |
1770 read_error_exit(); | |
1771 create_conin(); | |
1772 continue; | |
1773 } | |
1774 | |
1775 if (ir.EventType == KEY_EVENT) | |
1776 { | |
1777 if (decode_key_event(&ir.Event.KeyEvent, &ch, pch2, | |
1778 pmodifiers, TRUE)) | |
1779 return ch; | |
1780 } | |
1781 else if (ir.EventType == FOCUS_EVENT) | |
1782 handle_focus_event(ir); | |
1783 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) | |
1784 shell_resized(); | |
1785 #ifdef FEAT_MOUSE | |
1786 else if (ir.EventType == MOUSE_EVENT) | |
1787 { | |
1788 if (decode_mouse_event(&ir.Event.MouseEvent)) | |
1789 return 0; | |
1790 } | |
1791 #endif | |
1792 } | |
1793 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
1794 #endif /* !FEAT_GUI_MSWIN */ |
7 | 1795 |
1796 | |
1797 /* | |
3622 | 1798 * mch_inchar(): low-level input function. |
7 | 1799 * Get one or more characters from the keyboard or the mouse. |
1800 * If time == 0, do not wait for characters. | |
1801 * If time == n, wait a short time for characters. | |
1802 * If time == -1, wait forever for characters. | |
1803 * Returns the number of characters read into buf. | |
1804 */ | |
1805 int | |
1806 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
|
1807 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
|
1808 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
|
1809 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
|
1810 int tb_change_cnt UNUSED) |
7 | 1811 { |
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
|
1812 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 1813 |
1814 int len; | |
1815 int c; | |
1816 #define TYPEAHEADLEN 20 | |
1817 static char_u typeahead[TYPEAHEADLEN]; /* previously typed bytes. */ | |
1818 static int typeaheadlen = 0; | |
1819 | |
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
|
1820 # 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
|
1821 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
|
1822 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
|
1823 # 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
|
1824 |
7 | 1825 /* First use any typeahead that was kept because "buf" was too small. */ |
1826 if (typeaheadlen > 0) | |
1827 goto theend; | |
1828 | |
1829 if (time >= 0) | |
1830 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1831 if (!WaitForChar(time, FALSE)) /* no character available */ |
7 | 1832 return 0; |
1833 } | |
1834 else /* time == -1, wait forever */ | |
1835 { | |
1836 mch_set_winsize_now(); /* Allow winsize changes from now on */ | |
1837 | |
203 | 1838 /* |
1839 * If there is no character available within 2 seconds (default) | |
1840 * write the autoscript file to disk. Or cause the CursorHold event | |
1841 * to be triggered. | |
1842 */ | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1843 if (!WaitForChar(p_ut, FALSE)) |
7 | 1844 { |
609 | 1845 if (trigger_cursorhold() && maxlen >= 3) |
7 | 1846 { |
203 | 1847 buf[0] = K_SPECIAL; |
1848 buf[1] = KS_EXTRA; | |
1849 buf[2] = (int)KE_CURSORHOLD; | |
1850 return 3; | |
7 | 1851 } |
368 | 1852 before_blocking(); |
7 | 1853 } |
1854 } | |
1855 | |
1856 /* | |
1857 * Try to read as many characters as there are, until the buffer is full. | |
1858 */ | |
1859 | |
1860 /* we will get at least one key. Get more if they are available. */ | |
1861 g_fCBrkPressed = FALSE; | |
1862 | |
1863 #ifdef MCH_WRITE_DUMP | |
1864 if (fdDump) | |
1865 fputc('[', fdDump); | |
1866 #endif | |
1867 | |
1868 /* Keep looping until there is something in the typeahead buffer and more | |
1869 * to get and still room in the buffer (up to two bytes for a char and | |
1870 * 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
|
1871 while ((typeaheadlen == 0 || WaitForChar(0L, FALSE)) |
7 | 1872 && typeaheadlen + 5 <= TYPEAHEADLEN) |
1873 { | |
1874 if (typebuf_changed(tb_change_cnt)) | |
1875 { | |
1876 /* "buf" may be invalid now if a client put something in the | |
1877 * typeahead buffer and "buf" is in the typeahead buffer. */ | |
1878 typeaheadlen = 0; | |
1879 break; | |
1880 } | |
1881 #ifdef FEAT_MOUSE | |
1882 if (g_nMouseClick != -1) | |
1883 { | |
1884 # ifdef MCH_WRITE_DUMP | |
1885 if (fdDump) | |
1886 fprintf(fdDump, "{%02x @ %d, %d}", | |
1887 g_nMouseClick, g_xMouse, g_yMouse); | |
1888 # endif | |
1889 typeahead[typeaheadlen++] = ESC + 128; | |
1890 typeahead[typeaheadlen++] = 'M'; | |
1891 typeahead[typeaheadlen++] = g_nMouseClick; | |
1892 typeahead[typeaheadlen++] = g_xMouse + '!'; | |
1893 typeahead[typeaheadlen++] = g_yMouse + '!'; | |
1894 g_nMouseClick = -1; | |
1895 } | |
1896 else | |
1897 #endif | |
1898 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1899 WCHAR ch2 = NUL; |
7 | 1900 int modifiers = 0; |
1901 | |
1902 c = tgetch(&modifiers, &ch2); | |
1903 | |
1904 if (typebuf_changed(tb_change_cnt)) | |
1905 { | |
1906 /* "buf" may be invalid now if a client put something in the | |
1907 * typeahead buffer and "buf" is in the typeahead buffer. */ | |
1908 typeaheadlen = 0; | |
1909 break; | |
1910 } | |
1911 | |
1912 if (c == Ctrl_C && ctrl_c_interrupts) | |
1913 { | |
1914 #if defined(FEAT_CLIENTSERVER) | |
1915 trash_input_buf(); | |
1916 #endif | |
1917 got_int = TRUE; | |
1918 } | |
1919 | |
1920 #ifdef FEAT_MOUSE | |
1921 if (g_nMouseClick == -1) | |
1922 #endif | |
1923 { | |
1924 int n = 1; | |
6047 | 1925 |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1926 if (ch2 == NUL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1927 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1928 int i; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1929 char_u *p; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1930 WCHAR ch[2]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1931 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1932 ch[0] = c; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1933 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
|
1934 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1935 ch[1] = tgetch(&modifiers, &ch2); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1936 n++; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1937 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1938 p = utf16_to_enc(ch, &n); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1939 if (p != NULL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1940 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1941 for (i = 0; i < n; i++) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1942 typeahead[typeaheadlen + i] = p[i]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1943 vim_free(p); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1944 } |
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 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1947 typeahead[typeaheadlen] = c; |
7 | 1948 if (ch2 != NUL) |
1949 { | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1950 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
|
1951 { |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1952 switch (ch2) |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1953 { |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1954 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
|
1955 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
|
1956 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
|
1957 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
|
1958 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
|
1959 n++; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1960 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1961 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1962 default: |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1963 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
|
1964 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
|
1965 n += 2; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1966 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1967 } |
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
|
1968 } |
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 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
|
1970 { |
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 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
|
1972 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
|
1973 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
|
1974 } |
6047 | 1975 } |
1976 | |
7 | 1977 /* Use the ALT key to set the 8th bit of the character |
1978 * when it's one byte, the 8th bit isn't set yet and not | |
1979 * using a double-byte encoding (would become a lead | |
1980 * byte). */ | |
1981 if ((modifiers & MOD_MASK_ALT) | |
1982 && n == 1 | |
1983 && (typeahead[typeaheadlen] & 0x80) == 0 | |
1984 && !enc_dbcs | |
1985 ) | |
1986 { | |
1443 | 1987 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80, |
1988 typeahead + typeaheadlen); | |
7 | 1989 modifiers &= ~MOD_MASK_ALT; |
1990 } | |
1991 | |
1992 if (modifiers != 0) | |
1993 { | |
1994 /* Prepend modifiers to the character. */ | |
1995 mch_memmove(typeahead + typeaheadlen + 3, | |
1996 typeahead + typeaheadlen, n); | |
1997 typeahead[typeaheadlen++] = K_SPECIAL; | |
1998 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER; | |
1999 typeahead[typeaheadlen++] = modifiers; | |
2000 } | |
2001 | |
2002 typeaheadlen += n; | |
2003 | |
2004 #ifdef MCH_WRITE_DUMP | |
2005 if (fdDump) | |
2006 fputc(c, fdDump); | |
2007 #endif | |
2008 } | |
2009 } | |
2010 } | |
2011 | |
2012 #ifdef MCH_WRITE_DUMP | |
2013 if (fdDump) | |
2014 { | |
2015 fputs("]\n", fdDump); | |
2016 fflush(fdDump); | |
2017 } | |
2018 #endif | |
2019 | |
2020 theend: | |
2021 /* Move typeahead to "buf", as much as fits. */ | |
2022 len = 0; | |
2023 while (len < maxlen && typeaheadlen > 0) | |
2024 { | |
2025 buf[len++] = typeahead[0]; | |
2026 mch_memmove(typeahead, typeahead + 1, --typeaheadlen); | |
2027 } | |
2028 return len; | |
2029 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
2030 #else /* FEAT_GUI_MSWIN */ |
7 | 2031 return 0; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
2032 #endif /* FEAT_GUI_MSWIN */ |
7 | 2033 } |
2034 | |
3927 | 2035 #ifndef PROTO |
2036 # ifndef __MINGW32__ | |
2037 # include <shellapi.h> /* required for FindExecutable() */ | |
2038 # endif | |
7 | 2039 #endif |
2040 | |
9 | 2041 /* |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2042 * 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
|
2043 * 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
|
2044 * 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
|
2045 * the allocated memory. |
10 | 2046 * TODO: Should somehow check if it's really executable. |
9 | 2047 */ |
7 | 2048 static int |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2049 executable_exists(char *name, char_u **path, int use_path) |
7 | 2050 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2051 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
|
2052 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
|
2053 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
|
2054 WCHAR *wcurpath, *wnewpath; |
6185 | 2055 long n; |
9 | 2056 |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2057 if (!use_path) |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2058 { |
11071
cc22b177dfe8
patch 8.0.0424: compiler warnings on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11060
diff
changeset
|
2059 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
|
2060 { |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2061 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
|
2062 { |
11071
cc22b177dfe8
patch 8.0.0424: compiler warnings on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11060
diff
changeset
|
2063 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
|
2064 *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
|
2065 else |
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2066 *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
|
2067 } |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2068 return TRUE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2069 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2070 return FALSE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2071 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2072 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2073 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
|
2074 if (p == NULL) |
6185 | 2075 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
|
2076 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2077 wcurpath = _wgetenv(L"PATH"); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2078 wnewpath = (WCHAR*)alloc((unsigned)(wcslen(wcurpath) + 3) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2079 * 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
|
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); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2342 cb->Buffer = (PCHAR_INFO)alloc(NumCells * sizeof(CHAR_INFO)); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
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); |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2366 cb->Regions = (PSMALL_RECT)alloc(cb->NumRegions * sizeof(SMALL_RECT)); |
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 |
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
|
2765 if (gui.starting || 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
|
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 |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3398 p = (struct my_acl *)alloc_clear((unsigned)sizeof(struct my_acl)); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
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; | |
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
|
3742 static int resized = FALSE; |
7 | 3743 |
3744 #ifdef MCH_WRITE_DUMP | |
3745 if (fdDump) | |
3746 { | |
3747 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize); | |
3748 fflush(fdDump); | |
3749 } | |
3750 #endif | |
3751 | |
3752 /* get the largest size we can size the console window to */ | |
3753 coordScreen = GetLargestConsoleWindowSize(hConsole); | |
3754 | |
3755 /* define the new console window size and scroll position */ | |
3756 srWindowRect.Left = srWindowRect.Top = (SHORT) 0; | |
3757 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); | |
3758 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); | |
3759 | |
3760 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3761 { | |
3762 int sx, sy; | |
3763 | |
3764 sx = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3765 sy = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3766 if (sy < ySize || sx < xSize) | |
3767 { | |
3768 /* | |
3769 * Increasing number of lines/columns, do buffer first. | |
3770 * Use the maximal size in x and y direction. | |
3771 */ | |
3772 if (sy < ySize) | |
3773 coordScreen.Y = ySize; | |
3774 else | |
3775 coordScreen.Y = sy; | |
3776 if (sx < xSize) | |
3777 coordScreen.X = xSize; | |
3778 else | |
3779 coordScreen.X = sx; | |
3780 SetConsoleScreenBufferSize(hConsole, coordScreen); | |
3781 } | |
3782 } | |
3783 | |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3784 // define the new console buffer size |
7 | 3785 coordScreen.X = xSize; |
3786 coordScreen.Y = ySize; | |
3787 | |
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
|
3788 // 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
|
3789 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
|
3790 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3791 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
|
3792 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
|
3793 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3794 else |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3795 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3796 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
|
3797 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
|
3798 resized = TRUE; |
7 | 3799 } |
3800 } | |
3801 | |
3802 | |
3803 /* | |
3804 * Set the console window to `Rows' * `Columns' | |
3805 */ | |
3806 void | |
26 | 3807 mch_set_shellsize(void) |
7 | 3808 { |
3809 COORD coordScreen; | |
3810 | |
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
|
3811 # 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
|
3812 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
|
3813 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
|
3814 # endif |
7 | 3815 /* Don't change window size while still starting up */ |
3816 if (suppress_winsize != 0) | |
3817 { | |
3818 suppress_winsize = 2; | |
3819 return; | |
3820 } | |
3821 | |
3822 if (term_console) | |
3823 { | |
3824 coordScreen = GetLargestConsoleWindowSize(g_hConOut); | |
3825 | |
3826 /* Clamp Rows and Columns to reasonable values */ | |
3827 if (Rows > coordScreen.Y) | |
3828 Rows = coordScreen.Y; | |
3829 if (Columns > coordScreen.X) | |
3830 Columns = coordScreen.X; | |
3831 | |
3832 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
3833 } | |
3834 } | |
3835 | |
3836 /* | |
3837 * Rows and/or Columns has changed. | |
3838 */ | |
3839 void | |
26 | 3840 mch_new_shellsize(void) |
7 | 3841 { |
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
|
3842 # 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
|
3843 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
|
3844 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
|
3845 # endif |
7 | 3846 set_scroll_region(0, 0, Columns - 1, Rows - 1); |
3847 } | |
3848 | |
3849 | |
3850 /* | |
3851 * Called when started up, to set the winsize that was delayed. | |
3852 */ | |
3853 void | |
26 | 3854 mch_set_winsize_now(void) |
7 | 3855 { |
3856 if (suppress_winsize == 2) | |
3857 { | |
3858 suppress_winsize = 0; | |
3859 mch_set_shellsize(); | |
3860 shell_resized(); | |
3861 } | |
3862 suppress_winsize = 0; | |
3863 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
3864 #endif /* FEAT_GUI_MSWIN */ |
7 | 3865 |
5547 | 3866 static BOOL |
3867 vim_create_process( | |
5556 | 3868 char *cmd, |
5569 | 3869 BOOL inherit_handles, |
5547 | 3870 DWORD flags, |
3871 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
|
3872 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
|
3873 LPVOID *env, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
3874 char *cwd) |
5547 | 3875 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3876 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
|
3877 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
|
3878 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3879 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
|
3880 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
|
3881 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
|
3882 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
|
3883 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3884 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
|
3885 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
|
3886 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
|
3887 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3888 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3889 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
|
3890 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
|
3891 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
|
3892 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
|
3893 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
|
3894 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
|
3895 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
|
3896 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
|
3897 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
|
3898 (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
|
3899 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
|
3900 theend: |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3901 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
|
3902 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
|
3903 return ret; |
5547 | 3904 } |
7 | 3905 |
3906 | |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3907 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
|
3908 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
|
3909 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
|
3910 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
|
3911 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3912 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
|
3913 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
|
3914 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3915 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
|
3916 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
|
3917 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
|
3918 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3919 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
|
3920 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
|
3921 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
|
3922 } |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3923 |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3924 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
3925 #if defined(FEAT_GUI_MSWIN) || defined(PROTO) |
7 | 3926 |
3927 /* | |
3928 * Specialised version of system() for Win32 GUI mode. | |
3929 * This version proceeds as follows: | |
3930 * 1. Create a console window for use by the subprocess | |
3931 * 2. Run the subprocess (it gets the allocated console by default) | |
3932 * 3. Wait for the subprocess to terminate and get its exit code | |
3933 * 4. Prompt the user to press a key to close the console window | |
3934 */ | |
3935 static int | |
2935 | 3936 mch_system_classic(char *cmd, int options) |
7 | 3937 { |
3938 STARTUPINFO si; | |
3939 PROCESS_INFORMATION pi; | |
3940 DWORD ret = 0; | |
3941 HWND hwnd = GetFocus(); | |
3942 | |
3943 si.cb = sizeof(si); | |
3944 si.lpReserved = NULL; | |
3945 si.lpDesktop = NULL; | |
3946 si.lpTitle = NULL; | |
3947 si.dwFlags = STARTF_USESHOWWINDOW; | |
3948 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3949 * It's nicer to run a filter command in a minimized window. |
2643 | 3950 * Don't activate the window to keep focus on Vim. |
7 | 3951 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3952 if (options & SHELL_DOOUT) |
2643 | 3953 si.wShowWindow = SW_SHOWMINNOACTIVE; |
7 | 3954 else |
3955 si.wShowWindow = SW_SHOWNORMAL; | |
3956 si.cbReserved2 = 0; | |
3957 si.lpReserved2 = NULL; | |
3958 | |
3959 /* Now, run the command */ | |
5547 | 3960 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
|
3961 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
|
3962 &si, &pi, NULL, NULL); |
7 | 3963 |
3964 /* Wait for the command to terminate before continuing */ | |
3965 { | |
3966 #ifdef FEAT_GUI | |
3967 int delay = 1; | |
3968 | |
3969 /* Keep updating the window while waiting for the shell to finish. */ | |
3970 for (;;) | |
3971 { | |
3972 MSG msg; | |
3973 | |
3010 | 3974 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
7 | 3975 { |
3976 TranslateMessage(&msg); | |
3010 | 3977 pDispatchMessage(&msg); |
3720 | 3978 delay = 1; |
3979 continue; | |
7 | 3980 } |
3981 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
3982 break; | |
3983 | |
3984 /* We start waiting for a very short time and then increase it, so | |
3985 * that we respond quickly when the process is quick, and don't | |
3986 * consume too much overhead when it's slow. */ | |
3987 if (delay < 50) | |
3988 delay += 10; | |
3989 } | |
3990 #else | |
3991 WaitForSingleObject(pi.hProcess, INFINITE); | |
3992 #endif | |
3993 | |
3994 /* Get the command exit code */ | |
3995 GetExitCodeProcess(pi.hProcess, &ret); | |
3996 } | |
3997 | |
3998 /* Close the handles to the subprocess, so that it goes away */ | |
3999 CloseHandle(pi.hThread); | |
4000 CloseHandle(pi.hProcess); | |
4001 | |
4002 /* Try to get input focus back. Doesn't always work though. */ | |
4003 PostMessage(hwnd, WM_SETFOCUS, 0, 0); | |
4004 | |
4005 return ret; | |
4006 } | |
2935 | 4007 |
4008 /* | |
4009 * Thread launched by the gui to send the current buffer data to the | |
4010 * process. This way avoid to hang up vim totally if the children | |
4011 * process take a long time to process the lines. | |
4012 */ | |
9750
0f4b76b2757a
commit https://github.com/vim/vim/commit/4c38d66d25e4ba433fe87283a4664425a3dbd529
Christian Brabandt <cb@256bit.org>
parents:
9740
diff
changeset
|
4013 static unsigned int __stdcall |
2935 | 4014 sub_process_writer(LPVOID param) |
4015 { | |
4016 HANDLE g_hChildStd_IN_Wr = param; | |
4017 linenr_T lnum = curbuf->b_op_start.lnum; | |
4018 DWORD len = 0; | |
4019 DWORD l; | |
4020 char_u *lp = ml_get(lnum); | |
4021 char_u *s; | |
4022 int written = 0; | |
4023 | |
4024 for (;;) | |
4025 { | |
4026 l = (DWORD)STRLEN(lp + written); | |
4027 if (l == 0) | |
4028 len = 0; | |
4029 else if (lp[written] == NL) | |
4030 { | |
4031 /* NL -> NUL translation */ | |
4032 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); | |
4033 } | |
4034 else | |
4035 { | |
4036 s = vim_strchr(lp + written, NL); | |
4037 WriteFile(g_hChildStd_IN_Wr, (char *)lp + written, | |
4038 s == NULL ? l : (DWORD)(s - (lp + written)), | |
4039 &len, NULL); | |
4040 } | |
4041 if (len == (int)l) | |
4042 { | |
4043 /* Finished a line, add a NL, unless this line should not have | |
4044 * one. */ | |
4045 if (lnum != curbuf->b_op_end.lnum | |
6933 | 4046 || (!curbuf->b_p_bin |
4047 && curbuf->b_p_fixeol) | |
2935 | 4048 || (lnum != curbuf->b_no_eol_lnum |
4049 && (lnum != curbuf->b_ml.ml_line_count | |
4050 || curbuf->b_p_eol))) | |
4051 { | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14673
diff
changeset
|
4052 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
|
4053 (LPDWORD)&vim_ignored, NULL); |
2935 | 4054 } |
4055 | |
4056 ++lnum; | |
4057 if (lnum > curbuf->b_op_end.lnum) | |
4058 break; | |
4059 | |
4060 lp = ml_get(lnum); | |
4061 written = 0; | |
4062 } | |
4063 else if (len > 0) | |
4064 written += len; | |
4065 } | |
4066 | |
4067 /* finished all the lines, close pipe */ | |
4068 CloseHandle(g_hChildStd_IN_Wr); | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4069 return 0; |
2935 | 4070 } |
4071 | |
4072 | |
4073 # define BUFLEN 100 /* length for buffer, stolen from unix version */ | |
4074 | |
4075 /* | |
4076 * This function read from the children's stdout and write the | |
4077 * data on screen or in the buffer accordingly. | |
4078 */ | |
4079 static void | |
4080 dump_pipe(int options, | |
4081 HANDLE g_hChildStd_OUT_Rd, | |
4082 garray_T *ga, | |
4083 char_u buffer[], | |
4084 DWORD *buffer_off) | |
4085 { | |
4086 DWORD availableBytes = 0; | |
4087 DWORD i; | |
4088 int ret; | |
4089 DWORD len; | |
4090 DWORD toRead; | |
4091 int repeatCount; | |
4092 | |
4093 /* we query the pipe to see if there is any data to read | |
4094 * to avoid to perform a blocking read */ | |
4095 ret = PeekNamedPipe(g_hChildStd_OUT_Rd, /* pipe to query */ | |
4096 NULL, /* optional buffer */ | |
3622 | 4097 0, /* buffer size */ |
2935 | 4098 NULL, /* number of read bytes */ |
4099 &availableBytes, /* available bytes total */ | |
4100 NULL); /* byteLeft */ | |
4101 | |
4102 repeatCount = 0; | |
4103 /* We got real data in the pipe, read it */ | |
3622 | 4104 while (ret != 0 && availableBytes > 0) |
2935 | 4105 { |
4106 repeatCount++; | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
4107 toRead = (DWORD)(BUFLEN - *buffer_off); |
2935 | 4108 toRead = availableBytes < toRead ? availableBytes : toRead; |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
4109 ReadFile(g_hChildStd_OUT_Rd, buffer + *buffer_off, toRead , &len, NULL); |
2935 | 4110 |
4111 /* If we haven't read anything, there is a problem */ | |
4112 if (len == 0) | |
4113 break; | |
4114 | |
4115 availableBytes -= len; | |
4116 | |
4117 if (options & SHELL_READ) | |
4118 { | |
4119 /* Do NUL -> NL translation, append NL separated | |
4120 * lines to the current buffer. */ | |
4121 for (i = 0; i < len; ++i) | |
4122 { | |
4123 if (buffer[i] == NL) | |
4124 append_ga_line(ga); | |
4125 else if (buffer[i] == NUL) | |
4126 ga_append(ga, NL); | |
4127 else | |
4128 ga_append(ga, buffer[i]); | |
4129 } | |
4130 } | |
4131 else if (has_mbyte) | |
4132 { | |
4133 int l; | |
3030 | 4134 int c; |
4135 char_u *p; | |
2935 | 4136 |
4137 len += *buffer_off; | |
4138 buffer[len] = NUL; | |
4139 | |
4140 /* Check if the last character in buffer[] is | |
4141 * incomplete, keep these bytes for the next | |
4142 * round. */ | |
4143 for (p = buffer; p < buffer + len; p += l) | |
4144 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9762
diff
changeset
|
4145 l = MB_CPTR2LEN(p); |
2935 | 4146 if (l == 0) |
4147 l = 1; /* NUL byte? */ | |
4148 else if (MB_BYTE2LEN(*p) != l) | |
4149 break; | |
4150 } | |
4151 if (p == buffer) /* no complete character */ | |
4152 { | |
4153 /* avoid getting stuck at an illegal byte */ | |
4154 if (len >= 12) | |
4155 ++p; | |
4156 else | |
4157 { | |
4158 *buffer_off = len; | |
4159 return; | |
4160 } | |
4161 } | |
4162 c = *p; | |
4163 *p = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4164 msg_puts((char *)buffer); |
2935 | 4165 if (p < buffer + len) |
4166 { | |
4167 *p = c; | |
4168 *buffer_off = (DWORD)((buffer + len) - p); | |
4169 mch_memmove(buffer, p, *buffer_off); | |
4170 return; | |
4171 } | |
4172 *buffer_off = 0; | |
4173 } | |
4174 else | |
4175 { | |
4176 buffer[len] = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4177 msg_puts((char *)buffer); |
2935 | 4178 } |
4179 | |
4180 windgoto(msg_row, msg_col); | |
4181 cursor_on(); | |
4182 out_flush(); | |
4183 } | |
4184 } | |
4185 | |
4186 /* | |
4187 * Version of system to use for windows NT > 5.0 (Win2K), use pipe | |
4188 * for communication and doesn't open any new window. | |
4189 */ | |
4190 static int | |
4191 mch_system_piped(char *cmd, int options) | |
4192 { | |
4193 STARTUPINFO si; | |
4194 PROCESS_INFORMATION pi; | |
4195 DWORD ret = 0; | |
4196 | |
4197 HANDLE g_hChildStd_IN_Rd = NULL; | |
4198 HANDLE g_hChildStd_IN_Wr = NULL; | |
4199 HANDLE g_hChildStd_OUT_Rd = NULL; | |
4200 HANDLE g_hChildStd_OUT_Wr = NULL; | |
4201 | |
4202 char_u buffer[BUFLEN + 1]; /* reading buffer + size */ | |
4203 DWORD len; | |
4204 | |
4205 /* buffer used to receive keys */ | |
4206 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ | |
4207 int ta_len = 0; /* valid bytes in ta_buf[] */ | |
4208 | |
4209 DWORD i; | |
4210 int c; | |
4211 int noread_cnt = 0; | |
4212 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
|
4213 int delay = 1; |
2935 | 4214 DWORD buffer_off = 0; /* valid bytes in buffer[] */ |
3361 | 4215 char *p = NULL; |
2935 | 4216 |
4217 SECURITY_ATTRIBUTES saAttr; | |
4218 | |
4219 /* Set the bInheritHandle flag so pipe handles are inherited. */ | |
4220 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); | |
4221 saAttr.bInheritHandle = TRUE; | |
4222 saAttr.lpSecurityDescriptor = NULL; | |
4223 | |
4224 if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) | |
4225 /* 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
|
4226 || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) |
2935 | 4227 /* Create a pipe for the child process's STDIN. */ |
4228 || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0) | |
4229 /* 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
|
4230 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) |
2935 | 4231 { |
4232 CloseHandle(g_hChildStd_IN_Rd); | |
4233 CloseHandle(g_hChildStd_IN_Wr); | |
4234 CloseHandle(g_hChildStd_OUT_Rd); | |
4235 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
|
4236 msg_puts(_("\nCannot create pipes\n")); |
2935 | 4237 } |
4238 | |
4239 si.cb = sizeof(si); | |
4240 si.lpReserved = NULL; | |
4241 si.lpDesktop = NULL; | |
4242 si.lpTitle = NULL; | |
4243 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; | |
4244 | |
4245 /* set-up our file redirection */ | |
4246 si.hStdError = g_hChildStd_OUT_Wr; | |
4247 si.hStdOutput = g_hChildStd_OUT_Wr; | |
4248 si.hStdInput = g_hChildStd_IN_Rd; | |
4249 si.wShowWindow = SW_HIDE; | |
4250 si.cbReserved2 = 0; | |
4251 si.lpReserved2 = NULL; | |
4252 | |
4253 if (options & SHELL_READ) | |
4254 ga_init2(&ga, 1, BUFLEN); | |
4255 | |
3361 | 4256 if (cmd != NULL) |
4257 { | |
4258 p = (char *)vim_strsave((char_u *)cmd); | |
4259 if (p != NULL) | |
4260 unescape_shellxquote((char_u *)p, p_sxe); | |
4261 else | |
4262 p = cmd; | |
4263 } | |
4264 | |
5547 | 4265 /* Now, run the command. |
4266 * About "Inherit handles" being TRUE: this command can be litigious, | |
4267 * handle inheritance was deactivated for pending temp file, but, if we | |
4268 * 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
|
4269 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
|
4270 &si, &pi, NULL, NULL); |
2935 | 4271 |
3361 | 4272 if (p != cmd) |
4273 vim_free(p); | |
2935 | 4274 |
4275 /* Close our unused side of the pipes */ | |
4276 CloseHandle(g_hChildStd_IN_Rd); | |
4277 CloseHandle(g_hChildStd_OUT_Wr); | |
4278 | |
4279 if (options & SHELL_WRITE) | |
4280 { | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4281 HANDLE thread = (HANDLE) |
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4282 _beginthreadex(NULL, /* security attributes */ |
2935 | 4283 0, /* default stack size */ |
4284 sub_process_writer, /* function to be executed */ | |
4285 g_hChildStd_IN_Wr, /* parameter */ | |
4286 0, /* creation flag, start immediately */ | |
4287 NULL); /* we don't care about thread id */ | |
4288 CloseHandle(thread); | |
4289 g_hChildStd_IN_Wr = NULL; | |
4290 } | |
4291 | |
4292 /* Keep updating the window while waiting for the shell to finish. */ | |
4293 for (;;) | |
4294 { | |
4295 MSG msg; | |
4296 | |
5553 | 4297 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
2935 | 4298 { |
4299 TranslateMessage(&msg); | |
5553 | 4300 pDispatchMessage(&msg); |
2935 | 4301 } |
4302 | |
4303 /* write pipe information in the window */ | |
4304 if ((options & (SHELL_READ|SHELL_WRITE)) | |
4305 # ifdef FEAT_GUI | |
4306 || gui.in_use | |
4307 # endif | |
4308 ) | |
4309 { | |
4310 len = 0; | |
4311 if (!(options & SHELL_EXPAND) | |
4312 && ((options & | |
4313 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4314 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
4315 # ifdef FEAT_GUI | |
4316 || gui.in_use | |
4317 # endif | |
4318 ) | |
4319 && (ta_len > 0 || noread_cnt > 4)) | |
4320 { | |
4321 if (ta_len == 0) | |
4322 { | |
4323 /* Get extra characters when we don't have any. Reset the | |
4324 * counter and timer. */ | |
4325 noread_cnt = 0; | |
4326 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4327 } | |
4328 if (ta_len > 0 || len > 0) | |
4329 { | |
4330 /* | |
4331 * For pipes: Check for CTRL-C: send interrupt signal to | |
4332 * child. Check for CTRL-D: EOF, close pipe to child. | |
4333 */ | |
4334 if (len == 1 && cmd != NULL) | |
4335 { | |
4336 if (ta_buf[ta_len] == Ctrl_C) | |
4337 { | |
4338 /* Learn what exit code is expected, for | |
4339 * now put 9 as SIGKILL */ | |
4340 TerminateProcess(pi.hProcess, 9); | |
4341 } | |
4342 if (ta_buf[ta_len] == Ctrl_D) | |
4343 { | |
4344 CloseHandle(g_hChildStd_IN_Wr); | |
4345 g_hChildStd_IN_Wr = NULL; | |
4346 } | |
4347 } | |
4348 | |
4349 /* replace K_BS by <BS> and K_DEL by <DEL> */ | |
4350 for (i = ta_len; i < ta_len + len; ++i) | |
4351 { | |
4352 if (ta_buf[i] == CSI && len - i > 2) | |
4353 { | |
4354 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
4355 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
4356 { | |
4357 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
4358 (size_t)(len - i - 2)); | |
4359 if (c == K_DEL || c == K_KDEL) | |
4360 ta_buf[i] = DEL; | |
4361 else | |
4362 ta_buf[i] = Ctrl_H; | |
4363 len -= 2; | |
4364 } | |
4365 } | |
4366 else if (ta_buf[i] == '\r') | |
4367 ta_buf[i] = '\n'; | |
4368 if (has_mbyte) | |
4369 i += (*mb_ptr2len_len)(ta_buf + i, | |
4370 ta_len + len - i) - 1; | |
4371 } | |
4372 | |
4373 /* | |
4374 * For pipes: echo the typed characters. For a pty this | |
4375 * does not seem to work. | |
4376 */ | |
4377 for (i = ta_len; i < ta_len + len; ++i) | |
4378 { | |
4379 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4380 msg_putchar(ta_buf[i]); | |
4381 else if (has_mbyte) | |
4382 { | |
4383 int l = (*mb_ptr2len)(ta_buf + i); | |
4384 | |
4385 msg_outtrans_len(ta_buf + i, l); | |
4386 i += l - 1; | |
4387 } | |
4388 else | |
4389 msg_outtrans_len(ta_buf + i, 1); | |
4390 } | |
4391 windgoto(msg_row, msg_col); | |
4392 out_flush(); | |
4393 | |
4394 ta_len += len; | |
4395 | |
4396 /* | |
4397 * Write the characters to the child, unless EOF has been | |
4398 * typed for pipes. Write one character at a time, to | |
4399 * avoid losing too much typeahead. When writing buffer | |
4400 * lines, drop the typed characters (only check for | |
4401 * CTRL-C). | |
4402 */ | |
4403 if (options & SHELL_WRITE) | |
4404 ta_len = 0; | |
4405 else if (g_hChildStd_IN_Wr != NULL) | |
4406 { | |
4407 WriteFile(g_hChildStd_IN_Wr, (char*)ta_buf, | |
4408 1, &len, NULL); | |
4409 // if we are typing in, we want to keep things reactive | |
4410 delay = 1; | |
4411 if (len > 0) | |
4412 { | |
4413 ta_len -= len; | |
4414 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4415 } | |
4416 } | |
4417 } | |
4418 } | |
4419 } | |
4420 | |
4421 if (ta_len) | |
4422 ui_inchar_undo(ta_buf, ta_len); | |
4423 | |
4424 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4425 { | |
3030 | 4426 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4427 break; |
4428 } | |
4429 | |
4430 ++noread_cnt; | |
3030 | 4431 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4432 |
4433 /* We start waiting for a very short time and then increase it, so | |
4434 * that we respond quickly when the process is quick, and don't | |
4435 * consume too much overhead when it's slow. */ | |
4436 if (delay < 50) | |
4437 delay += 10; | |
4438 } | |
4439 | |
4440 /* Close the pipe */ | |
4441 CloseHandle(g_hChildStd_OUT_Rd); | |
4442 if (g_hChildStd_IN_Wr != NULL) | |
4443 CloseHandle(g_hChildStd_IN_Wr); | |
4444 | |
4445 WaitForSingleObject(pi.hProcess, INFINITE); | |
4446 | |
4447 /* Get the command exit code */ | |
4448 GetExitCodeProcess(pi.hProcess, &ret); | |
4449 | |
4450 if (options & SHELL_READ) | |
4451 { | |
4452 if (ga.ga_len > 0) | |
4453 { | |
4454 append_ga_line(&ga); | |
4455 /* remember that the NL was missing */ | |
4456 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; | |
4457 } | |
4458 else | |
4459 curbuf->b_no_eol_lnum = 0; | |
4460 ga_clear(&ga); | |
4461 } | |
4462 | |
4463 /* Close the handles to the subprocess, so that it goes away */ | |
4464 CloseHandle(pi.hThread); | |
4465 CloseHandle(pi.hProcess); | |
4466 | |
4467 return ret; | |
4468 } | |
4469 | |
4470 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
|
4471 mch_system_g(char *cmd, int options) |
2935 | 4472 { |
4473 /* 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
|
4474 if (!p_stmp) |
2935 | 4475 return mch_system_piped(cmd, options); |
4476 else | |
4477 return mch_system_classic(cmd, options); | |
4478 } | |
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
|
4479 #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
|
4480 |
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
|
4481 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
5547 | 4482 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
|
4483 mch_system_c(char *cmd, int options) |
5547 | 4484 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4485 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
|
4486 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
|
4487 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4488 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
|
4489 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
|
4490 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
|
4491 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4492 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
|
4493 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
|
4494 return ret; |
5547 | 4495 } |
7 | 4496 |
4497 #endif | |
4498 | |
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
|
4499 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
|
4500 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
|
4501 { |
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
|
4502 #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
|
4503 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
|
4504 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
|
4505 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
|
4506 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
|
4507 #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
|
4508 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
|
4509 #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
|
4510 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
|
4511 #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
|
4512 } |
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
|
4513 |
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
|
4514 #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
|
4515 /* |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4516 * 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
|
4517 */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4518 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
|
4519 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
|
4520 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
|
4521 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
|
4522 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4523 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
|
4524 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
|
4525 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
|
4526 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
|
4527 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
|
4528 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
|
4529 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
|
4530 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
|
4531 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
|
4532 |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4533 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4534 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
|
4535 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4536 cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; |
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 newcmd = lalloc(cmdlen, 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
|
4538 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
|
4539 return 255; |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4540 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4541 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4542 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
|
4543 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
|
4544 } |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4545 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4546 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4547 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
|
4548 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
|
4549 } |
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
|
4550 |
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 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
|
4552 |
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 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
|
4554 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
|
4555 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
|
4556 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
|
4557 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
|
4558 { |
884b683d12e9
patch 8.1.1028: MS-Windows: memory leak when creating terminal fails
Bram Moolenaar <Bram@vim.org>
parents:
16015
diff
changeset
|
4559 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
|
4560 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
|
4561 } |
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
|
4562 |
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
|
4563 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
|
4564 ++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
|
4565 |
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
|
4566 /* 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
|
4567 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
|
4568 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4569 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
|
4570 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
|
4571 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4572 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
|
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 /* 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
|
4575 * 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
|
4576 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
|
4577 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
|
4578 } |
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 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
|
4580 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
|
4581 } |
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
|
4582 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
|
4583 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
|
4584 |
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
|
4585 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
|
4586 |
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
|
4587 /* 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
|
4588 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
|
4589 |
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 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
|
4591 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
|
4592 |
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 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
|
4594 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
|
4595 } |
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 #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
|
4597 |
7 | 4598 /* |
4599 * Either execute a command by calling the shell or start a new shell | |
4600 */ | |
4601 int | |
4602 mch_call_shell( | |
26 | 4603 char_u *cmd, |
4604 int options) /* SHELL_*, see vim.h */ | |
7 | 4605 { |
4606 int x = 0; | |
4607 int tmode = cur_tmode; | |
4608 #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
|
4609 WCHAR szShellTitle[512]; |
6293 | 4610 |
6290 | 4611 /* 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
|
4612 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
|
4613 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
|
4614 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4615 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
|
4616 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
|
4617 else |
6290 | 4618 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4619 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
|
4620 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4621 if (wn != NULL) |
6290 | 4622 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4623 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
|
4624 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
|
4625 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
|
4626 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
|
4627 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
|
4628 vim_free(wn); |
6290 | 4629 } |
4630 } | |
4631 } | |
7 | 4632 #endif |
4633 | |
4634 out_flush(); | |
4635 | |
4636 #ifdef MCH_WRITE_DUMP | |
4637 if (fdDump) | |
4638 { | |
4639 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options); | |
4640 fflush(fdDump); | |
4641 } | |
4642 #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
|
4643 #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
|
4644 /* 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
|
4645 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
|
4646 # 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
|
4647 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
|
4648 # 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
|
4649 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
|
4650 && (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
|
4651 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4652 /* Use a terminal window to run the 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
|
4653 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
|
4654 # ifdef FEAT_TITLE |
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
|
4655 resettitle(); |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
4656 # 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
|
4657 return x; |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4658 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4659 #endif |
7 | 4660 |
4661 /* | |
4662 * Catch all deadly signals while running the external command, because a | |
4663 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us. | |
4664 */ | |
4665 signal(SIGINT, SIG_IGN); | |
4666 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4667 signal(SIGKILL, SIG_IGN); | |
4668 #else | |
4669 signal(SIGBREAK, SIG_IGN); | |
4670 #endif | |
4671 signal(SIGILL, SIG_IGN); | |
4672 signal(SIGFPE, SIG_IGN); | |
4673 signal(SIGSEGV, SIG_IGN); | |
4674 signal(SIGTERM, SIG_IGN); | |
4675 signal(SIGABRT, SIG_IGN); | |
4676 | |
4677 if (options & SHELL_COOKED) | |
4678 settmode(TMODE_COOK); /* set to normal mode */ | |
4679 | |
4680 if (cmd == NULL) | |
4681 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4682 x = mch_system((char *)p_sh, options); |
7 | 4683 } |
4684 else | |
4685 { | |
4686 /* we use "command" or "cmd" to start the shell; slow but easy */ | |
3363 | 4687 char_u *newcmd = NULL; |
4688 char_u *cmdbase = cmd; | |
4689 long_u cmdlen; | |
3361 | 4690 |
4691 /* Skip a leading ", ( and "(. */ | |
4692 if (*cmdbase == '"' ) | |
4693 ++cmdbase; | |
4694 if (*cmdbase == '(') | |
4695 ++cmdbase; | |
4696 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4697 if ((STRNICMP(cmdbase, "start", 5) == 0) && VIM_ISWHITE(cmdbase[5])) |
3361 | 4698 { |
4699 STARTUPINFO si; | |
4700 PROCESS_INFORMATION pi; | |
4701 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
|
4702 INT n_show_cmd = SW_SHOWNORMAL; |
3361 | 4703 char_u *p; |
4704 | |
5627 | 4705 ZeroMemory(&si, sizeof(si)); |
3361 | 4706 si.cb = sizeof(si); |
4707 si.lpReserved = NULL; | |
4708 si.lpDesktop = NULL; | |
4709 si.lpTitle = NULL; | |
4710 si.dwFlags = 0; | |
4711 si.cbReserved2 = 0; | |
4712 si.lpReserved2 = NULL; | |
4713 | |
4714 cmdbase = skipwhite(cmdbase + 5); | |
4715 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
|
4716 && VIM_ISWHITE(cmdbase[4])) |
3361 | 4717 { |
4718 cmdbase = skipwhite(cmdbase + 4); | |
4719 si.dwFlags = STARTF_USESHOWWINDOW; | |
4720 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
|
4721 n_show_cmd = SW_SHOWMINNOACTIVE; |
3361 | 4722 } |
4723 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
|
4724 && VIM_ISWHITE(cmdbase[2])) |
3361 | 4725 { |
4726 cmdbase = skipwhite(cmdbase + 2); | |
4727 flags = CREATE_NO_WINDOW; | |
4728 si.dwFlags = STARTF_USESTDHANDLES; | |
4729 si.hStdInput = CreateFile("\\\\.\\NUL", // File name | |
3363 | 4730 GENERIC_READ, // Access flags |
3361 | 4731 0, // Share flags |
3363 | 4732 NULL, // Security att. |
4733 OPEN_EXISTING, // Open flags | |
4734 FILE_ATTRIBUTE_NORMAL, // File att. | |
4735 NULL); // Temp file | |
3361 | 4736 si.hStdOutput = si.hStdInput; |
4737 si.hStdError = si.hStdInput; | |
4738 } | |
4739 | |
4740 /* Remove a trailing ", ) and )" if they have a match | |
4741 * at the start of the command. */ | |
4742 if (cmdbase > cmd) | |
4743 { | |
4744 p = cmdbase + STRLEN(cmdbase); | |
4745 if (p > cmdbase && p[-1] == '"' && *cmd == '"') | |
4746 *--p = NUL; | |
4747 if (p > cmdbase && p[-1] == ')' | |
4748 && (*cmd =='(' || cmd[1] == '(')) | |
4749 *--p = NUL; | |
4750 } | |
4751 | |
3363 | 4752 newcmd = cmdbase; |
4753 unescape_shellxquote(cmdbase, p_sxe); | |
4754 | |
3361 | 4755 /* |
3363 | 4756 * If creating new console, arguments are passed to the |
4757 * 'cmd.exe' as-is. If it's not, arguments are not treated | |
4758 * correctly for current 'cmd.exe'. So unescape characters in | |
4759 * shellxescape except '|' for avoiding to be treated as | |
4760 * argument to them. Pass the arguments to sub-shell. | |
3361 | 4761 */ |
3363 | 4762 if (flags != CREATE_NEW_CONSOLE) |
4763 { | |
4764 char_u *subcmd; | |
3367 | 4765 char_u *cmd_shell = mch_getenv("COMSPEC"); |
4766 | |
4767 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
|
4768 cmd_shell = (char_u *)default_shell(); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4769 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4770 subcmd = vim_strsave_escaped_ext(cmdbase, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4771 (char_u *)"|", '^', FALSE); |
3363 | 4772 if (subcmd != NULL) |
4773 { | |
4774 /* make "cmd.exe /c arguments" */ | |
4775 cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5; | |
4776 newcmd = lalloc(cmdlen, TRUE); | |
4777 if (newcmd != NULL) | |
4778 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s", | |
3367 | 4779 cmd_shell, subcmd); |
3363 | 4780 else |
4781 newcmd = cmdbase; | |
3367 | 4782 vim_free(subcmd); |
3363 | 4783 } |
4784 } | |
3361 | 4785 |
4786 /* | |
4787 * Now, start the command as a process, so that it doesn't | |
4788 * inherit our handles which causes unpleasant dangling swap | |
4789 * files if we exit before the spawned process | |
4790 */ | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4791 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
|
4792 &si, &pi, NULL, NULL)) |
3361 | 4793 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
|
4794 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
|
4795 > (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
|
4796 x = 0; |
3361 | 4797 else |
4798 { | |
4799 x = -1; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4800 #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
|
4801 # 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
|
4802 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
|
4803 # 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
|
4804 emsg(_("E371: Command not found")); |
3361 | 4805 #endif |
4806 } | |
3363 | 4807 |
4808 if (newcmd != cmdbase) | |
4809 vim_free(newcmd); | |
4810 | |
5627 | 4811 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) |
3361 | 4812 { |
5627 | 4813 /* Close the handle to \\.\NUL created above. */ |
3361 | 4814 CloseHandle(si.hStdInput); |
4815 } | |
4816 /* Close the handles to the subprocess, so that it goes away */ | |
4817 CloseHandle(pi.hThread); | |
4818 CloseHandle(pi.hProcess); | |
4819 } | |
4820 else | |
4821 { | |
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
|
4822 cmdlen = |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4823 #ifdef FEAT_GUI_MSWIN |
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
|
4824 (gui.in_use ? |
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4825 (!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
|
4826 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
|
4827 : 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
|
4828 #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
|
4829 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; |
1569 | 4830 |
3361 | 4831 newcmd = lalloc(cmdlen, TRUE); |
4832 if (newcmd != NULL) | |
7 | 4833 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4834 #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
|
4835 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
|
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 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 need_vimrun_warning) |
7 | 4840 { |
10400
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4841 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
|
4842 "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
|
4843 "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
|
4844 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
|
4845 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
|
4846 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
|
4847 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4848 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
|
4849 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
|
4850 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
|
4851 vim_free(wtitle); |
7 | 4852 need_vimrun_warning = FALSE; |
4853 } | |
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
|
4854 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
|
4855 # 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
|
4856 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
|
4857 # 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
|
4858 !s_dont_use_vimrun && p_stmp) |
7 | 4859 /* Use vimrun to execute the command. It opens a console |
4860 * 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
|
4861 vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s", |
7 | 4862 vimrun_path, |
4863 (msg_silent != 0 || (options & SHELL_DOOUT)) | |
4864 ? "-s " : "", | |
4865 p_sh, p_shcf, cmd); | |
4866 else | |
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
|
4867 # ifdef VIMDLL |
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4868 if (gui.in_use) |
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4869 # 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
|
4870 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
|
4871 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
|
4872 # ifdef VIMDLL |
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4873 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
|
4874 # 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
|
4875 #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
|
4876 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4877 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", |
1569 | 4878 p_sh, p_shcf, cmd); |
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
|
4879 #endif |
7 | 4880 x = mch_system((char *)newcmd, options); |
3361 | 4881 vim_free(newcmd); |
7 | 4882 } |
4883 } | |
4884 } | |
4885 | |
4886 if (tmode == TMODE_RAW) | |
4887 settmode(TMODE_RAW); /* set to raw mode */ | |
4888 | |
4889 /* Print the return value, unless "vimrun" was used. */ | |
4890 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
|
4891 #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
|
4892 && (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
|
4893 ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) : 1) |
7 | 4894 #endif |
4895 ) | |
4896 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
4897 smsg(_("shell returned %d"), x); |
7 | 4898 msg_putchar('\n'); |
4899 } | |
4900 #ifdef FEAT_TITLE | |
4901 resettitle(); | |
4902 #endif | |
4903 | |
4904 signal(SIGINT, SIG_DFL); | |
4905 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4906 signal(SIGKILL, SIG_DFL); | |
4907 #else | |
4908 signal(SIGBREAK, SIG_DFL); | |
4909 #endif | |
4910 signal(SIGILL, SIG_DFL); | |
4911 signal(SIGFPE, SIG_DFL); | |
4912 signal(SIGSEGV, SIG_DFL); | |
4913 signal(SIGTERM, SIG_DFL); | |
4914 signal(SIGABRT, SIG_DFL); | |
4915 | |
4916 return x; | |
4917 } | |
4918 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4919 #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
|
4920 static HANDLE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4921 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
|
4922 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
|
4923 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
|
4924 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
|
4925 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
|
4926 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
|
4927 DWORD dwFlagsAndAttributes) |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4928 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4929 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
|
4930 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
|
4931 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4932 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
|
4933 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
|
4934 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
|
4935 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4936 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
|
4937 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
|
4938 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
|
4939 vim_free(wn); |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4940 return h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4941 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4942 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4943 /* |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4944 * 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
|
4945 * 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
|
4946 */ |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12140
diff
changeset
|
4947 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
|
4948 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
|
4949 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4950 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
|
4951 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
|
4952 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
|
4953 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4954 /* 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
|
4955 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
|
4956 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4957 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4958 if (base) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4959 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4960 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
|
4961 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4962 /* 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
|
4963 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
|
4964 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4965 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4966 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
|
4967 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4968 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
|
4969 *((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
|
4970 p++; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4971 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4972 FreeEnvironmentStrings(base); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4973 *((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
|
4974 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4975 |
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
|
4976 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
|
4977 { |
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
|
4978 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
|
4979 { |
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
|
4980 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
|
4981 { |
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
|
4982 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
|
4983 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
|
4984 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
|
4985 --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
|
4986 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
|
4987 { |
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
|
4988 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
|
4989 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
|
4990 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
|
4991 |
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
|
4992 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
|
4993 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
|
4994 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
|
4995 *((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
|
4996 *((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
|
4997 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
|
4998 *((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
|
4999 *((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
|
5000 } |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
5001 vim_free(wkey); |
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
5002 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
|
5003 } |
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 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5006 |
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
|
5007 # 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
|
5008 { |
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
|
5009 # 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
|
5010 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
|
5011 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
|
5012 # 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
|
5013 # 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
|
5014 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
|
5015 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
|
5016 # endif |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5017 // 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
|
5018 // 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
|
5019 // 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
|
5020 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
|
5021 # 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
|
5022 + 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
|
5023 # 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
|
5024 # 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
|
5025 + 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
|
5026 # 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
|
5027 ; |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5028 |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5029 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
|
5030 { |
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
|
5031 # 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
|
5032 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
|
5033 *((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
|
5034 (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
|
5035 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
|
5036 *((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
|
5037 (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
|
5038 *((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
|
5039 # 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
|
5040 # 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
|
5041 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
|
5042 { |
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
|
5043 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
|
5044 *((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
|
5045 (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
|
5046 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
|
5047 *((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
|
5048 (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
|
5049 *((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
|
5050 } |
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
|
5051 # 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
|
5052 } |
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
|
5053 } |
14067
39ec4b90e4a7
patch 8.1.0051: MS-Windows: missing #endif
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
5054 # endif |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5055 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5056 |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5057 /* |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5058 * 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
|
5059 * 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
|
5060 */ |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5061 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
|
5062 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
|
5063 { |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5064 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
|
5065 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
|
5066 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
|
5067 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5068 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
|
5069 GetCurrentProcessId(), |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5070 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
|
5071 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5072 // 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
|
5073 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
|
5074 name, |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5075 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
|
5076 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
|
5077 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
|
5078 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5079 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
|
5080 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
|
5081 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5082 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
|
5083 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
|
5084 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
|
5085 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5086 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
|
5087 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
|
5088 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
|
5089 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
|
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 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
|
5092 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5093 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
|
5094 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
|
5095 } |
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 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
|
5098 } |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5099 |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5100 void |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11230
diff
changeset
|
5101 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
|
5102 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5103 STARTUPINFO si; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5104 PROCESS_INFORMATION pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5105 HANDLE jo; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5106 SECURITY_ATTRIBUTES saAttr; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5107 channel_T *channel = NULL; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5108 HANDLE ifd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5109 HANDLE ofd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5110 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
|
5111 garray_T ga; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5112 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5113 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
|
5114 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
|
5115 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
|
5116 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
|
5117 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
|
5118 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
|
5119 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
|
5120 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5121 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
|
5122 use_null_for_err = TRUE; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5123 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5124 ifd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5125 ifd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5126 ofd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5127 ofd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5128 efd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5129 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
|
5130 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
|
5131 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5132 jo = CreateJobObject(NULL, NULL); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5133 if (jo == NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5134 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5135 job->jv_status = JOB_FAILED; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5136 goto failed; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5137 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5138 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5139 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
|
5140 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
|
5141 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5142 ZeroMemory(&pi, sizeof(pi)); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5143 ZeroMemory(&si, sizeof(si)); |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5144 si.cb = sizeof(si); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5145 si.dwFlags |= STARTF_USESHOWWINDOW; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5146 si.wShowWindow = SW_HIDE; |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5147 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5148 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5149 saAttr.bInheritHandle = TRUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5150 saAttr.lpSecurityDescriptor = NULL; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5151 |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5152 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5153 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5154 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
|
5155 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5156 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
|
5157 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5158 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5159 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
|
5160 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5161 semsg(_(e_notopen), fname); |
8443
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5162 goto failed; |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5163 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5164 } |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5165 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
|
5166 && (!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
|
5167 || !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
|
5168 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5169 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5170 if (use_file_for_out) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5171 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5172 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
|
5173 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5174 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
|
5175 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5176 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5177 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
|
5178 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5179 semsg(_(e_notopen), fname); |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5180 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5181 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5182 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5183 else if (!use_null_for_out && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5184 (!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
|
5185 || !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
|
5186 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5187 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5188 if (use_file_for_err) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5189 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5190 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
|
5191 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5192 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
|
5193 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5194 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5195 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
|
5196 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5197 semsg(_(e_notopen), fname); |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5198 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5199 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5200 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5201 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
|
5202 (!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
|
5203 || !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
|
5204 goto failed; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5205 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5206 si.dwFlags |= STARTF_USESTDHANDLES; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5207 si.hStdInput = ifd[0]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5208 si.hStdOutput = ofd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5209 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
|
5210 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5211 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
|
5212 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5213 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5214 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5215 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5216 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5217 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5218 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5219 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5220 channel = add_channel(); |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5221 if (channel == NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5222 goto failed; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5223 } |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5224 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5225 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
|
5226 CREATE_SUSPENDED | |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5227 CREATE_DEFAULT_ERROR_MODE | |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5228 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
|
5229 CREATE_UNICODE_ENVIRONMENT | |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5230 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
|
5231 &si, &pi, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5232 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
|
5233 (char *)options->jo_cwd)) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5234 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5235 CloseHandle(jo); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5236 job->jv_status = JOB_FAILED; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5237 goto failed; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5238 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5239 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5240 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
|
5241 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5242 if (!AssignProcessToJobObject(jo, pi.hProcess)) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5243 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5244 /* 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
|
5245 * process with TerminateProcess. */ |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5246 CloseHandle(jo); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5247 jo = NULL; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5248 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5249 ResumeThread(pi.hThread); |
8479
9f63e4506c40
commit https://github.com/vim/vim/commit/75578a388d2aff59dc330ceccd8894c79b4bc735
Christian Brabandt <cb@256bit.org>
parents:
8471
diff
changeset
|
5250 CloseHandle(pi.hThread); |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5251 job->jv_proc_info = pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5252 job->jv_job_object = jo; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5253 job->jv_status = JOB_STARTED; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5254 |
10060
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5255 CloseHandle(ifd[0]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5256 CloseHandle(ofd[1]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5257 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
|
5258 CloseHandle(efd[1]); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5259 |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5260 job->jv_channel = channel; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5261 if (channel != NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5262 { |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5263 channel_set_pipes(channel, |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5264 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
|
5265 ? INVALID_FD : (sock_T)ifd[1], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5266 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
|
5267 ? INVALID_FD : (sock_T)ofd[0], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5268 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
|
5269 ? INVALID_FD : (sock_T)efd[0]); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5270 channel_set_job(channel, job, options); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5271 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5272 return; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5273 |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5274 failed: |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5275 CloseHandle(ifd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5276 CloseHandle(ofd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5277 CloseHandle(efd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5278 CloseHandle(ifd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5279 CloseHandle(ofd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5280 CloseHandle(efd[1]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5281 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
|
5282 ga_clear(&ga); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5283 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5284 |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5285 char * |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5286 mch_job_status(job_T *job) |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5287 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5288 DWORD dwExitCode = 0; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5289 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5290 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
|
5291 || dwExitCode != STILL_ACTIVE) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5292 { |
8176
477c1d855698
commit https://github.com/vim/vim/commit/eab089d22f172ddd2d33367a998e68c2f1c6c989
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
5293 job->jv_exitval = (int)dwExitCode; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10317
diff
changeset
|
5294 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
|
5295 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5296 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
|
5297 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5298 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5299 return "dead"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5300 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5301 return "run"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5302 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5303 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5304 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5305 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
|
5306 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5307 HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5308 job_T *jobArray[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5309 job_T *job = job_list; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5310 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5311 while (job != NULL) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5312 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5313 DWORD n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5314 DWORD result; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5315 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5316 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
|
5317 && job != NULL; job = job->jv_next) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5318 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5319 if (job->jv_status == JOB_STARTED) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5320 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5321 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
|
5322 jobArray[n] = job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5323 ++n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5324 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5325 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5326 if (n == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5327 continue; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5328 result = WaitForMultipleObjects(n, jobHandles, FALSE, 0); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5329 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
|
5330 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5331 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
|
5332 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5333 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
|
5334 return wait_job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5335 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5336 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5337 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5338 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5339 |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5340 static BOOL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5341 terminate_all(HANDLE process, int code) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5342 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5343 PROCESSENTRY32 pe; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5344 HANDLE h = INVALID_HANDLE_VALUE; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5345 DWORD pid = GetProcessId(process); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5346 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5347 if (pid != 0) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5348 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5349 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5350 if (h != INVALID_HANDLE_VALUE) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5351 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5352 pe.dwSize = sizeof(PROCESSENTRY32); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5353 if (!Process32First(h, &pe)) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5354 goto theend; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5355 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5356 do |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5357 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5358 if (pe.th32ParentProcessID == pid) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5359 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5360 HANDLE ph = OpenProcess( |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5361 PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5362 if (ph != NULL) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5363 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5364 terminate_all(ph, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5365 CloseHandle(ph); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5366 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5367 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5368 } while (Process32Next(h, &pe)); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5369 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5370 CloseHandle(h); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5371 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5372 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5373 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5374 theend: |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5375 return TerminateProcess(process, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5376 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5377 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5378 /* |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5379 * Send a (deadly) signal to "job". |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5380 * 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
|
5381 */ |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5382 int |
12037
85f0f557661e
patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
5383 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
|
5384 { |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5385 int ret; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5386 |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5387 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
|
5388 { |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5389 /* deadly signal */ |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5390 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
|
5391 { |
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
|
5392 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
|
5393 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
|
5394 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
|
5395 } |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5396 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
|
5397 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5398 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5399 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
|
5400 return FAIL; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5401 ret = GenerateConsoleCtrlEvent( |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5402 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
|
5403 job->jv_proc_info.dwProcessId) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5404 ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5405 FreeConsole(); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5406 return ret; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5407 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5408 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5409 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5410 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5411 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5412 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5413 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5414 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5415 if (job->jv_status != JOB_FAILED) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5416 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5417 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5418 CloseHandle(job->jv_job_object); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5419 CloseHandle(job->jv_proc_info.hProcess); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5420 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5421 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5422 #endif |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5423 |
7 | 5424 |
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
|
5425 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 5426 |
5427 /* | |
5428 * Start termcap mode | |
5429 */ | |
5430 static void | |
5431 termcap_mode_start(void) | |
5432 { | |
5433 DWORD cmodein; | |
5434 | |
5435 if (g_fTermcapMode) | |
5436 return; | |
5437 | |
5438 SaveConsoleBuffer(&g_cbNonTermcap); | |
5439 | |
5440 if (g_cbTermcap.IsValid) | |
5441 { | |
5442 /* | |
5443 * We've been in termcap mode before. Restore certain screen | |
5444 * characteristics, including the buffer size and the window | |
5445 * size. Since we will be redrawing the screen, we don't need | |
5446 * to restore the actual contents of the buffer. | |
5447 */ | |
5448 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
|
5449 reset_console_color_rgb(); |
7 | 5450 SetConsoleWindowInfo(g_hConOut, TRUE, &g_cbTermcap.Info.srWindow); |
5451 Rows = g_cbTermcap.Info.dwSize.Y; | |
5452 Columns = g_cbTermcap.Info.dwSize.X; | |
5453 } | |
5454 else | |
5455 { | |
5456 /* | |
5457 * This is our first time entering termcap mode. Clear the console | |
5458 * screen buffer, and resize the buffer to match the current window | |
5459 * size. We will use this as the size of our editing environment. | |
5460 */ | |
5461 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
|
5462 set_console_color_rgb(); |
7 | 5463 ResizeConBufAndWindow(g_hConOut, Columns, Rows); |
5464 } | |
5465 | |
5466 #ifdef FEAT_TITLE | |
5467 resettitle(); | |
5468 #endif | |
5469 | |
5470 GetConsoleMode(g_hConIn, &cmodein); | |
5471 #ifdef FEAT_MOUSE | |
5472 if (g_fMouseActive) | |
5473 cmodein |= ENABLE_MOUSE_INPUT; | |
5474 else | |
5475 cmodein &= ~ENABLE_MOUSE_INPUT; | |
5476 #endif | |
5477 cmodein |= ENABLE_WINDOW_INPUT; | |
5478 SetConsoleMode(g_hConIn, cmodein); | |
5479 | |
5480 redraw_later_clear(); | |
5481 g_fTermcapMode = TRUE; | |
5482 } | |
5483 | |
5484 | |
5485 /* | |
5486 * End termcap mode | |
5487 */ | |
5488 static void | |
5489 termcap_mode_end(void) | |
5490 { | |
5491 DWORD cmodein; | |
5492 ConsoleBuffer *cb; | |
5493 COORD coord; | |
5494 DWORD dwDummy; | |
5495 | |
5496 if (!g_fTermcapMode) | |
5497 return; | |
5498 | |
5499 SaveConsoleBuffer(&g_cbTermcap); | |
5500 | |
5501 GetConsoleMode(g_hConIn, &cmodein); | |
5502 cmodein &= ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT); | |
5503 SetConsoleMode(g_hConIn, cmodein); | |
5504 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5505 #ifdef FEAT_RESTORE_ORIG_SCREEN |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5506 cb = exiting ? &g_cbOrig : &g_cbNonTermcap; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5507 #else |
7 | 5508 cb = &g_cbNonTermcap; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5509 #endif |
7 | 5510 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
|
5511 reset_console_color_rgb(); |
7 | 5512 SetConsoleCursorInfo(g_hConOut, &g_cci); |
5513 | |
5514 if (p_rs || exiting) | |
5515 { | |
5516 /* | |
5517 * Clear anything that happens to be on the current line. | |
5518 */ | |
5519 coord.X = 0; | |
5520 coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); | |
5521 FillConsoleOutputCharacter(g_hConOut, ' ', | |
5522 cb->Info.dwSize.X, coord, &dwDummy); | |
5523 /* | |
5524 * The following is just for aesthetics. If we are exiting without | |
5525 * restoring the screen, then we want to have a prompt string | |
5526 * appear at the bottom line. However, the command interpreter | |
5527 * seems to always advance the cursor one line before displaying | |
5528 * the prompt string, which causes the screen to scroll. To | |
5529 * counter this, move the cursor up one line before exiting. | |
5530 */ | |
5531 if (exiting && !p_rs) | |
5532 coord.Y--; | |
5533 /* | |
5534 * Position the cursor at the leftmost column of the desired row. | |
5535 */ | |
5536 SetConsoleCursorPosition(g_hConOut, coord); | |
5537 } | |
5538 | |
5539 g_fTermcapMode = FALSE; | |
5540 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5541 #endif /* FEAT_GUI_MSWIN */ |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5542 |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5543 |
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
|
5544 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 5545 void |
5546 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
|
5547 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
|
5548 int len UNUSED) |
7 | 5549 { |
5550 /* never used */ | |
5551 } | |
5552 | |
5553 #else | |
5554 | |
5555 /* | |
5556 * clear `n' chars, starting from `coord' | |
5557 */ | |
5558 static void | |
5559 clear_chars( | |
5560 COORD coord, | |
5561 DWORD n) | |
5562 { | |
5563 DWORD dwDummy; | |
5564 | |
5565 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
|
5566 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5567 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
|
5568 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
|
5569 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
|
5570 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5571 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
|
5572 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
|
5573 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
|
5574 } |
7 | 5575 } |
5576 | |
5577 | |
5578 /* | |
5579 * Clear the screen | |
5580 */ | |
5581 static void | |
5582 clear_screen(void) | |
5583 { | |
5584 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
|
5585 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5586 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
|
5587 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
|
5588 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5589 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5590 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
|
5591 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
|
5592 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
|
5593 } |
7 | 5594 } |
5595 | |
5596 | |
5597 /* | |
5598 * Clear to end of display | |
5599 */ | |
5600 static void | |
5601 clear_to_end_of_display(void) | |
5602 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5603 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
|
5604 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5605 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
|
5606 clear_chars(g_coord, (Rows - g_coord.Y - 1) |
7 | 5607 * 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
|
5608 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5609 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5610 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
|
5611 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
|
5612 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
|
5613 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5614 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
|
5615 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
|
5616 } |
7 | 5617 } |
5618 | |
5619 | |
5620 /* | |
5621 * Clear to end of line | |
5622 */ | |
5623 static void | |
5624 clear_to_end_of_line(void) | |
5625 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5626 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
|
5627 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5628 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
|
5629 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
|
5630 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5631 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5632 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
|
5633 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
|
5634 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
|
5635 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5636 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
|
5637 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
|
5638 } |
7 | 5639 } |
5640 | |
5641 | |
5642 /* | |
5643 * Scroll the scroll region up by `cLines' lines | |
5644 */ | |
5645 static void | |
26 | 5646 scroll(unsigned cLines) |
7 | 5647 { |
5648 COORD oldcoord = g_coord; | |
5649 | |
5650 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); | |
5651 delete_lines(cLines); | |
5652 | |
5653 g_coord = oldcoord; | |
5654 } | |
5655 | |
5656 | |
5657 /* | |
5658 * Set the scroll region | |
5659 */ | |
5660 static void | |
5661 set_scroll_region( | |
5662 unsigned left, | |
5663 unsigned top, | |
5664 unsigned right, | |
5665 unsigned bottom) | |
5666 { | |
5667 if (left >= right | |
5668 || top >= bottom | |
5669 || right > (unsigned) Columns - 1 | |
5670 || bottom > (unsigned) Rows - 1) | |
5671 return; | |
5672 | |
5673 g_srScrollRegion.Left = left; | |
5674 g_srScrollRegion.Top = top; | |
5675 g_srScrollRegion.Right = right; | |
5676 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
|
5677 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5678 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5679 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
|
5680 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
|
5681 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
|
5682 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
|
5683 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5684 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
|
5685 return; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5686 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5687 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
|
5688 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
|
5689 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5690 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5691 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
|
5692 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
|
5693 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
|
5694 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
|
5695 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5696 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
|
5697 return; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5698 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5699 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
|
5700 g_srScrollRegion.Right = right; |
7 | 5701 } |
5702 | |
5703 | |
5704 /* | |
5705 * Insert `cLines' lines at the current cursor position | |
5706 */ | |
5707 static void | |
26 | 5708 insert_lines(unsigned cLines) |
7 | 5709 { |
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 SMALL_RECT source, clip; |
7 | 5711 COORD dest; |
5712 CHAR_INFO fill; | |
5713 | |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5714 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
|
5715 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5716 dest.X = g_srScrollRegion.Left; |
7 | 5717 dest.Y = g_coord.Y + cLines; |
5718 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5719 source.Left = g_srScrollRegion.Left; |
7 | 5720 source.Top = g_coord.Y; |
5721 source.Right = g_srScrollRegion.Right; | |
5722 source.Bottom = g_srScrollRegion.Bottom - cLines; | |
5723 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5724 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
|
5725 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
|
5726 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
|
5727 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
|
5728 |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5729 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
|
5730 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
|
5731 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
|
5732 else |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5733 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
|
5734 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5735 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
|
5736 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5737 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
|
5738 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5739 // 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
|
5740 // 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
|
5741 // 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
|
5742 // 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
|
5743 // 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
|
5744 // direction). |
7 | 5745 |
5746 if (source.Bottom < dest.Y) | |
5747 { | |
5748 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
|
5749 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
|
5750 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5751 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
|
5752 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
|
5753 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5754 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
|
5755 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
|
5756 } |
7 | 5757 } |
5758 } | |
5759 | |
5760 | |
5761 /* | |
5762 * Delete `cLines' lines at the current cursor position | |
5763 */ | |
5764 static void | |
26 | 5765 delete_lines(unsigned cLines) |
7 | 5766 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5767 SMALL_RECT source, clip; |
7 | 5768 COORD dest; |
5769 CHAR_INFO fill; | |
5770 int nb; | |
5771 | |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5772 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
|
5773 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5774 dest.X = g_srScrollRegion.Left; |
7 | 5775 dest.Y = g_coord.Y; |
5776 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5777 source.Left = g_srScrollRegion.Left; |
7 | 5778 source.Top = g_coord.Y + cLines; |
5779 source.Right = g_srScrollRegion.Right; | |
5780 source.Bottom = g_srScrollRegion.Bottom; | |
5781 | |
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 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
|
5783 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
|
5784 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
|
5785 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
|
5786 |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5787 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
|
5788 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
|
5789 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
|
5790 else |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5791 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
|
5792 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5793 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
|
5794 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5795 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
|
5796 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5797 // 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
|
5798 // above. |
7 | 5799 |
5800 nb = dest.Y + (source.Bottom - source.Top) + 1; | |
5801 | |
5802 if (nb < source.Top) | |
5803 { | |
5804 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
|
5805 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
|
5806 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5807 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
|
5808 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
|
5809 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5810 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
|
5811 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
|
5812 } |
7 | 5813 } |
5814 } | |
5815 | |
5816 | |
5817 /* | |
5818 * Set the cursor position | |
5819 */ | |
5820 static void | |
5821 gotoxy( | |
5822 unsigned x, | |
5823 unsigned y) | |
5824 { | |
5825 if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) | |
5826 return; | |
5827 | |
5828 /* external cursor coords are 1-based; internal are 0-based */ | |
5829 g_coord.X = x - 1; | |
5830 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
|
5831 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5832 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
|
5833 SetConsoleCursorPosition(g_hConOut, 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
|
5834 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5835 vtp_printf("\033[%d;%dH", y, x); |
7 | 5836 } |
5837 | |
5838 | |
5839 /* | |
5840 * 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
|
5841 * See ../runtime/doc/os_win32.txt for the numbers. |
7 | 5842 */ |
5843 static void | |
26 | 5844 textattr(WORD wAttr) |
7 | 5845 { |
6710 | 5846 g_attrCurrent = wAttr & 0xff; |
7 | 5847 |
5848 SetConsoleTextAttribute(g_hConOut, wAttr); | |
5849 } | |
5850 | |
5851 | |
5852 static void | |
26 | 5853 textcolor(WORD wAttr) |
7 | 5854 { |
6710 | 5855 g_attrCurrent = (g_attrCurrent & 0xf0) + (wAttr & 0x0f); |
7 | 5856 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5857 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
|
5858 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
|
5859 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5860 vtp_sgr_bulk(wAttr); |
7 | 5861 } |
5862 | |
5863 | |
5864 static void | |
26 | 5865 textbackground(WORD wAttr) |
7 | 5866 { |
6710 | 5867 g_attrCurrent = (g_attrCurrent & 0x0f) + ((wAttr & 0x0f) << 4); |
7 | 5868 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5869 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
|
5870 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
|
5871 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5872 vtp_sgr_bulk(wAttr); |
7 | 5873 } |
5874 | |
5875 | |
5876 /* | |
5877 * restore the default text attribute (whatever we started with) | |
5878 */ | |
5879 static void | |
26 | 5880 normvideo(void) |
7 | 5881 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5882 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
|
5883 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
|
5884 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5885 vtp_sgr_bulk(0); |
7 | 5886 } |
5887 | |
5888 | |
5889 static WORD g_attrPreStandout = 0; | |
5890 | |
5891 /* | |
5892 * Make the text standout, by brightening it | |
5893 */ | |
5894 static void | |
5895 standout(void) | |
5896 { | |
5897 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
|
5898 |
7 | 5899 textattr((WORD) (g_attrCurrent|FOREGROUND_INTENSITY|BACKGROUND_INTENSITY)); |
5900 } | |
5901 | |
5902 | |
5903 /* | |
5904 * Turn off standout mode | |
5905 */ | |
5906 static void | |
26 | 5907 standend(void) |
7 | 5908 { |
5909 if (g_attrPreStandout) | |
5910 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
|
5911 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5912 g_attrPreStandout = 0; |
7 | 5913 } |
5914 | |
5915 | |
5916 /* | |
1199 | 5917 * Set normal fg/bg color, based on T_ME. Called when t_me has been set. |
7 | 5918 */ |
5919 void | |
26 | 5920 mch_set_normal_colors(void) |
7 | 5921 { |
5922 char_u *p; | |
5923 int n; | |
5924 | |
5925 cterm_normal_fg_color = (g_attrDefault & 0xf) + 1; | |
5926 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
|
5927 if ( |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5928 #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
|
5929 !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
|
5930 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5931 T_ME[0] == ESC && T_ME[1] == '|') |
7 | 5932 { |
5933 p = T_ME + 2; | |
5934 n = getdigits(&p); | |
5935 if (*p == 'm' && n > 0) | |
5936 { | |
5937 cterm_normal_fg_color = (n & 0xf) + 1; | |
5938 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1; | |
5939 } | |
5940 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5941 #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
|
5942 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
|
5943 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
|
5944 #endif |
7 | 5945 } |
5946 | |
5947 | |
5948 /* | |
5949 * visual bell: flash the screen | |
5950 */ | |
5951 static void | |
26 | 5952 visual_bell(void) |
7 | 5953 { |
5954 COORD coordOrigin = {0, 0}; | |
5955 WORD attrFlash = ~g_attrCurrent & 0xff; | |
5956 | |
5957 DWORD dwDummy; | |
5958 LPWORD oldattrs = (LPWORD)alloc(Rows * Columns * sizeof(WORD)); | |
5959 | |
5960 if (oldattrs == NULL) | |
5961 return; | |
5962 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
5963 coordOrigin, &dwDummy); | |
5964 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, | |
5965 coordOrigin, &dwDummy); | |
5966 | |
5967 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
|
5968 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
|
5969 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, |
7 | 5970 coordOrigin, &dwDummy); |
5971 vim_free(oldattrs); | |
5972 } | |
5973 | |
5974 | |
5975 /* | |
5976 * Make the cursor visible or invisible | |
5977 */ | |
5978 static void | |
26 | 5979 cursor_visible(BOOL fVisible) |
7 | 5980 { |
5981 s_cursor_visible = fVisible; | |
5982 #ifdef MCH_CURSOR_SHAPE | |
5983 mch_update_cursor(); | |
5984 #endif | |
5985 } | |
5986 | |
5987 | |
5988 /* | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
5989 * 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
|
5990 * Returns the number of bytes actually written (at least one). |
7 | 5991 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5992 static DWORD |
7 | 5993 write_chars( |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5994 char_u *pchBuf, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5995 DWORD cbToWrite) |
7 | 5996 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
5997 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
|
5998 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
|
5999 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
|
6000 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
|
6001 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
|
6002 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
|
6003 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
|
6004 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6005 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
|
6006 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
|
6007 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6008 vim_free(unicodebuf); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6009 unicodebuf = (WCHAR *)lalloc(length * sizeof(WCHAR), FALSE); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6010 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
|
6011 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6012 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
|
6013 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
|
6014 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6015 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
|
6016 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6017 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
|
6018 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6019 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
|
6020 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
|
6021 // 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
|
6022 // 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
|
6023 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
|
6024 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
|
6025 || 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
|
6026 cchwritten = 1; |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6027 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6028 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6029 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6030 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
|
6031 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
|
6032 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
|
6033 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6034 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6035 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
|
6036 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6037 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
|
6038 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
|
6039 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6040 else |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6041 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6042 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
|
6043 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
|
6044 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
|
6045 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
|
6046 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
|
6047 } |
7 | 6048 |
6049 while (g_coord.X > g_srScrollRegion.Right) | |
6050 { | |
6051 g_coord.X -= (SHORT) Columns; | |
6052 if (g_coord.Y < g_srScrollRegion.Bottom) | |
6053 g_coord.Y++; | |
6054 } | |
6055 | |
6056 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
6057 | |
6058 return written; | |
6059 } | |
6060 | |
6061 | |
6062 /* | |
6063 * mch_write(): write the output buffer to the screen, translating ESC | |
6064 * sequences into calls to console output routines. | |
6065 */ | |
6066 void | |
6067 mch_write( | |
6068 char_u *s, | |
6069 int len) | |
6070 { | |
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
|
6071 # 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
|
6072 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
|
6073 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
|
6074 # 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
|
6075 |
7 | 6076 s[len] = NUL; |
6077 | |
6078 if (!term_console) | |
6079 { | |
6080 write(1, s, (unsigned)len); | |
6081 return; | |
6082 } | |
6083 | |
6084 /* translate ESC | sequences into faked bios calls */ | |
6085 while (len--) | |
6086 { | |
6087 /* optimization: use one single write_chars for runs of text, | |
6088 * 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
|
6089 DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033"); |
7 | 6090 |
6091 if (p_wd) | |
6092 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6093 WaitForChar(p_wd, FALSE); |
7 | 6094 if (prefix != 0) |
6095 prefix = 1; | |
6096 } | |
6097 | |
6098 if (prefix != 0) | |
6099 { | |
6100 DWORD nWritten; | |
6101 | |
6102 nWritten = write_chars(s, prefix); | |
6103 #ifdef MCH_WRITE_DUMP | |
6104 if (fdDump) | |
6105 { | |
6106 fputc('>', fdDump); | |
6107 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6108 fputs("<\n", fdDump); | |
6109 } | |
6110 #endif | |
6111 len -= (nWritten - 1); | |
6112 s += nWritten; | |
6113 } | |
6114 else if (s[0] == '\n') | |
6115 { | |
6116 /* \n, newline: go to the beginning of the next line or scroll */ | |
6117 if (g_coord.Y == g_srScrollRegion.Bottom) | |
6118 { | |
6119 scroll(1); | |
6120 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1); | |
6121 } | |
6122 else | |
6123 { | |
6124 gotoxy(g_srScrollRegion.Left + 1, g_coord.Y + 2); | |
6125 } | |
6126 #ifdef MCH_WRITE_DUMP | |
6127 if (fdDump) | |
6128 fputs("\\n\n", fdDump); | |
6129 #endif | |
6130 s++; | |
6131 } | |
6132 else if (s[0] == '\r') | |
6133 { | |
6134 /* \r, carriage return: go to beginning of line */ | |
6135 gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1); | |
6136 #ifdef MCH_WRITE_DUMP | |
6137 if (fdDump) | |
6138 fputs("\\r\n", fdDump); | |
6139 #endif | |
6140 s++; | |
6141 } | |
6142 else if (s[0] == '\b') | |
6143 { | |
6144 /* \b, backspace: move cursor one position left */ | |
6145 if (g_coord.X > g_srScrollRegion.Left) | |
6146 g_coord.X--; | |
6147 else if (g_coord.Y > g_srScrollRegion.Top) | |
6148 { | |
6149 g_coord.X = g_srScrollRegion.Right; | |
6150 g_coord.Y--; | |
6151 } | |
6152 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
6153 #ifdef MCH_WRITE_DUMP | |
6154 if (fdDump) | |
6155 fputs("\\b\n", fdDump); | |
6156 #endif | |
6157 s++; | |
6158 } | |
6159 else if (s[0] == '\a') | |
6160 { | |
6161 /* \a, bell */ | |
6162 MessageBeep(0xFFFFFFFF); | |
6163 #ifdef MCH_WRITE_DUMP | |
6164 if (fdDump) | |
6165 fputs("\\a\n", fdDump); | |
6166 #endif | |
6167 s++; | |
6168 } | |
6169 else if (s[0] == ESC && len >= 3-1 && s[1] == '|') | |
6170 { | |
6171 #ifdef MCH_WRITE_DUMP | |
24 | 6172 char_u *old_s = s; |
7 | 6173 #endif |
24 | 6174 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
|
6175 int arg1 = 0, arg2 = 0, argc = 0, args[16]; |
7 | 6176 |
6177 switch (s[2]) | |
6178 { | |
6179 case '0': case '1': case '2': case '3': case '4': | |
6180 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
|
6181 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
|
6182 do |
7 | 6183 { |
6184 ++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
|
6185 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
|
6186 argc += (argc < 15) ? 1 : 0; |
7 | 6187 if (p > s + len) |
6188 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
|
6189 } 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
|
6190 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6191 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
|
6192 break; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6193 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6194 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
|
6195 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
|
6196 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
|
6197 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6198 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
|
6199 normvideo(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6200 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
|
6201 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6202 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
|
6203 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
|
6204 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6205 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
|
6206 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6207 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
|
6208 vtp_sgr_bulks(argc, args); |
7 | 6209 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6210 else if (argc == 2 && *p == 'H') |
7 | 6211 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6212 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
|
6213 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6214 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
|
6215 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6216 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
|
6217 } |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6218 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
|
6219 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6220 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
|
6221 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6222 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
|
6223 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6224 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
|
6225 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6226 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
|
6227 { |
7 | 6228 gotoxy(g_coord.X + 1, |
6229 max(g_srScrollRegion.Top, g_coord.Y - arg1) + 1); | |
6230 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6231 else if (argc == 1 && *p == 'b') |
7 | 6232 { |
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 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
|
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 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
|
6236 { |
7 | 6237 gotoxy(min(g_srScrollRegion.Right, g_coord.X + arg1) + 1, |
6238 g_coord.Y + 1); | |
6239 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6240 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
|
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 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
|
6243 } |
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 && *p == 'H') |
7 | 6245 { |
6246 gotoxy(1, arg1); | |
6247 } | |
13314
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 if (argc == 1 && *p == 'L') |
7 | 6249 { |
6250 insert_lines(arg1); | |
6251 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6252 else if (argc == 1 && *p == 'M') |
7 | 6253 { |
6254 delete_lines(arg1); | |
6255 } | |
6256 | |
835 | 6257 len -= (int)(p - s); |
7 | 6258 s = p + 1; |
6259 break; | |
6260 | |
6261 case 'A': | |
6262 gotoxy(g_coord.X + 1, | |
6263 max(g_srScrollRegion.Top, g_coord.Y - 1) + 1); | |
6264 goto got3; | |
6265 | |
6266 case 'B': | |
6267 visual_bell(); | |
6268 goto got3; | |
6269 | |
6270 case 'C': | |
6271 gotoxy(min(g_srScrollRegion.Right, g_coord.X + 1) + 1, | |
6272 g_coord.Y + 1); | |
6273 goto got3; | |
6274 | |
6275 case 'E': | |
6276 termcap_mode_end(); | |
6277 goto got3; | |
6278 | |
6279 case 'F': | |
6280 standout(); | |
6281 goto got3; | |
6282 | |
6283 case 'f': | |
6284 standend(); | |
6285 goto got3; | |
6286 | |
6287 case 'H': | |
6288 gotoxy(1, 1); | |
6289 goto got3; | |
6290 | |
6291 case 'j': | |
6292 clear_to_end_of_display(); | |
6293 goto got3; | |
6294 | |
6295 case 'J': | |
6296 clear_screen(); | |
6297 goto got3; | |
6298 | |
6299 case 'K': | |
6300 clear_to_end_of_line(); | |
6301 goto got3; | |
6302 | |
6303 case 'L': | |
6304 insert_lines(1); | |
6305 goto got3; | |
6306 | |
6307 case 'M': | |
6308 delete_lines(1); | |
6309 goto got3; | |
6310 | |
6311 case 'S': | |
6312 termcap_mode_start(); | |
6313 goto got3; | |
6314 | |
6315 case 'V': | |
6316 cursor_visible(TRUE); | |
6317 goto got3; | |
6318 | |
6319 case 'v': | |
6320 cursor_visible(FALSE); | |
6321 goto got3; | |
6322 | |
6323 got3: | |
6324 s += 3; | |
6325 len -= 2; | |
6326 } | |
6327 | |
6328 #ifdef MCH_WRITE_DUMP | |
6329 if (fdDump) | |
6330 { | |
6331 fputs("ESC | ", fdDump); | |
6332 fwrite(old_s + 2, sizeof(char_u), s - old_s - 2, fdDump); | |
6333 fputc('\n', fdDump); | |
6334 } | |
6335 #endif | |
6336 } | |
6337 else | |
6338 { | |
6339 /* Write a single character */ | |
6340 DWORD nWritten; | |
6341 | |
6342 nWritten = write_chars(s, 1); | |
6343 #ifdef MCH_WRITE_DUMP | |
6344 if (fdDump) | |
6345 { | |
6346 fputc('>', fdDump); | |
6347 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6348 fputs("<\n", fdDump); | |
6349 } | |
6350 #endif | |
6351 | |
6352 len -= (nWritten - 1); | |
6353 s += nWritten; | |
6354 } | |
6355 } | |
6356 | |
6357 #ifdef MCH_WRITE_DUMP | |
6358 if (fdDump) | |
6359 fflush(fdDump); | |
6360 #endif | |
6361 } | |
6362 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
6363 #endif /* FEAT_GUI_MSWIN */ |
7 | 6364 |
6365 | |
6366 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
6367 * Delay for "msec" milliseconds. |
7 | 6368 */ |
6369 void | |
6370 mch_delay( | |
6371 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
|
6372 int ignoreinput UNUSED) |
7 | 6373 { |
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
|
6374 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 6375 Sleep((int)msec); /* never wait for input */ |
14 | 6376 #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
|
6377 # 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
|
6378 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
|
6379 { |
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
|
6380 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
|
6381 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
|
6382 } |
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
|
6383 # endif |
7 | 6384 if (ignoreinput) |
14 | 6385 # ifdef FEAT_MZSCHEME |
6386 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq) | |
6387 { | |
6388 int towait = p_mzq; | |
6389 | |
6390 /* if msec is large enough, wait by portions in p_mzq */ | |
6391 while (msec > 0) | |
6392 { | |
6393 mzvim_check_threads(); | |
6394 if (msec < towait) | |
6395 towait = msec; | |
6396 Sleep(towait); | |
6397 msec -= towait; | |
6398 } | |
6399 } | |
6400 else | |
6401 # endif | |
6402 Sleep((int)msec); | |
7 | 6403 else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6404 WaitForChar(msec, FALSE); |
7 | 6405 #endif |
6406 } | |
6407 | |
6408 | |
6409 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6410 * 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
|
6411 * This can also remove a symbolic link like Unix. |
7 | 6412 * Return 0 for success, -1 for failure. |
6413 */ | |
6414 int | |
6415 mch_remove(char_u *name) | |
6416 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6417 WCHAR *wn; |
7 | 6418 int n; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6419 |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6420 /* |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6421 * 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
|
6422 * 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
|
6423 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6424 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
|
6425 return mch_rmdir(name); |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6426 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6427 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6428 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6429 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
|
6430 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
|
6431 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
|
6432 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6433 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
|
6434 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
|
6435 return n; |
7 | 6436 } |
6437 | |
6438 | |
6439 /* | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6440 * Check for an "interrupt signal": CTRL-break or CTRL-C. |
7 | 6441 */ |
6442 void | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6443 mch_breakcheck(int force) |
7 | 6444 { |
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
|
6445 #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
|
6446 # 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
|
6447 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
|
6448 # 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
|
6449 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
|
6450 { |
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
|
6451 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
|
6452 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
|
6453 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
|
6454 } |
7 | 6455 #endif |
6456 } | |
6457 | |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6458 /* 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
|
6459 #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
|
6460 |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6461 /* |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6462 * 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
|
6463 */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6464 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
|
6465 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
|
6466 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6467 MEMORYSTATUSEX ms; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6468 |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6469 /* 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
|
6470 * what fits in 32 bits. */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6471 ms.dwLength = sizeof(MEMORYSTATUSEX); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6472 GlobalMemoryStatusEx(&ms); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6473 if (ms.ullAvailVirtual < ms.ullTotalPhys) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6474 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6475 /* 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
|
6476 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
|
6477 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6478 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
|
6479 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6480 /* 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
|
6481 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
|
6482 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6483 /* 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
|
6484 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
|
6485 } |
7 | 6486 |
6487 /* | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6488 * mch_wrename() works around a bug in rename (aka MoveFile) in |
7 | 6489 * Windows 95: rename("foo.bar", "foo.bar~") will generate a |
6490 * file whose short file name is "FOO.BAR" (its long file name will | |
6491 * be correct: "foo.bar~"). Because a file can be accessed by | |
6492 * either its SFN or its LFN, "foo.bar" has effectively been | |
6493 * renamed to "foo.bar", which is not at all what was wanted. This | |
6494 * seems to happen only when renaming files with three-character | |
6495 * extensions by appending a suffix that does not include ".". | |
6496 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR". | |
6497 * | |
6498 * There is another problem, which isn't really a bug but isn't right either: | |
6499 * When renaming "abcdef~1.txt" to "abcdef~1.txt~", the short name can be | |
6500 * "abcdef~1.txt" again. This has been reported on Windows NT 4.0 with | |
6501 * service pack 6. Doesn't seem to happen on Windows 98. | |
6502 * | |
6503 * Like rename(), returns 0 upon success, non-zero upon failure. | |
6504 * Should probably set errno appropriately when errors occur. | |
6505 */ | |
6506 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
|
6507 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
|
6508 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6509 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
|
6510 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
|
6511 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
|
6512 WCHAR szNewPath[_MAX_PATH + 1]; |
7 | 6513 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
|
6514 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6515 // 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
|
6516 // 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
|
6517 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
|
6518 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
|
6519 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
|
6520 && 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
|
6521 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
|
6522 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
|
6523 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
|
6524 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6525 // 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
|
6526 // 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
|
6527 if (GetFullPathNameW(wnew, _MAX_PATH, szNewPath, &p) == 0 || p == NULL) |
7 | 6528 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
|
6529 *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
|
6530 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6531 // 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
|
6532 if (GetTempFileNameW(szNewPath, L"VIM", 0, szTempFile) == 0) |
7 | 6533 return -2; |
6534 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6535 // 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
|
6536 if (!DeleteFileW(szTempFile)) |
7 | 6537 return -3; |
6538 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6539 // 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
|
6540 if (!MoveFileW(wold, szTempFile)) |
7 | 6541 return -4; |
6542 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6543 // 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
|
6544 // 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
|
6545 // 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
|
6546 // 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
|
6547 // 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
|
6548 // 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
|
6549 // 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
|
6550 // 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
|
6551 // 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
|
6552 if ((hf = CreateFileW(wold, GENERIC_WRITE, 0, NULL, CREATE_NEW, |
7 | 6553 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) |
6554 return -5; | |
6555 if (!CloseHandle(hf)) | |
6556 return -6; | |
6557 | |
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 // 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
|
6559 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
|
6560 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6561 // 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
|
6562 // 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
|
6563 (void)MoveFileW(szTempFile, wold); |
7 | 6564 return -7; |
6565 } | |
6566 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6567 // 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
|
6568 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
|
6569 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6570 // 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
|
6571 if (!DeleteFileW(wold)) |
7 | 6572 return -8; |
6573 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6574 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
|
6575 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6576 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6577 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6578 /* |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6579 * 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
|
6580 * 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
|
6581 */ |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6582 int |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6583 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
|
6584 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
|
6585 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
|
6586 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6587 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
|
6588 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
|
6589 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
|
6590 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6591 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
|
6592 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
|
6593 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
|
6594 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
|
6595 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
|
6596 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
|
6597 return retval; |
7 | 6598 } |
6599 | |
6600 /* | |
6601 * Get the default shell for the current hardware platform | |
6602 */ | |
6603 char * | |
26 | 6604 default_shell(void) |
7 | 6605 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6606 return "cmd.exe"; |
7 | 6607 } |
6608 | |
6609 /* | |
6610 * mch_access() extends access() to do more detailed check on network drives. | |
6611 * Returns 0 if file "n" has access rights according to "p", -1 otherwise. | |
6612 */ | |
6613 int | |
6614 mch_access(char *n, int p) | |
6615 { | |
6616 HANDLE hFile; | |
6617 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
|
6618 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
|
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 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
|
6621 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
|
6622 return -1; |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6623 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6624 if (mch_isdir((char_u *)n)) |
7 | 6625 { |
6626 WCHAR TempNameW[_MAX_PATH + 16] = L""; | |
6627 | |
6628 if (p & R_OK) | |
6629 { | |
6630 /* Read check is performed by seeing if we can do a find file on | |
6631 * 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
|
6632 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
|
6633 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
|
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 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
|
6636 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
|
6637 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
|
6638 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
|
6639 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
|
6640 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
|
6641 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6642 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
|
6643 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
|
6644 goto getout; |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6645 else |
7 | 6646 (void)FindClose(hFile); |
6647 } | |
6648 | |
6649 if (p & W_OK) | |
6650 { | |
6651 /* Trying to create a temporary file in the directory should catch | |
6652 * directories on read-only network shares. However, in | |
6653 * directories whose ACL allows writes but denies deletes will end | |
6654 * 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
|
6655 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
|
6656 goto getout; |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6657 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
|
6658 DeleteFileW(TempNameW); |
7 | 6659 } |
6660 } | |
6661 else | |
6662 { | |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6663 // 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
|
6664 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
|
6665 |
7 | 6666 /* Trying to open the file for the required access does ACL, read-only |
6667 * 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
|
6668 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
|
6669 | ((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
|
6670 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6671 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
|
6672 NULL, OPEN_EXISTING, 0, NULL); |
7 | 6673 if (hFile == INVALID_HANDLE_VALUE) |
6674 goto getout; | |
6675 CloseHandle(hFile); | |
6676 } | |
6677 | |
6678 retval = 0; /* success */ | |
6679 getout: | |
6680 vim_free(wn); | |
6681 return retval; | |
6682 } | |
6683 | |
6684 /* | |
1752 | 6685 * Version of open() that may use UTF-16 file name. |
7 | 6686 */ |
6687 int | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
6688 mch_open(const char *name, int flags, int mode) |
7 | 6689 { |
6690 WCHAR *wn; | |
6691 int f; | |
6692 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6693 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
|
6694 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
|
6695 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
|
6696 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6697 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
|
6698 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
|
6699 return f; |
7 | 6700 } |
6701 | |
6702 /* | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6703 * Version of fopen() that uses UTF-16 file name. |
7 | 6704 */ |
6705 FILE * | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
6706 mch_fopen(const char *name, const char *mode) |
7 | 6707 { |
6708 WCHAR *wn, *wm; | |
6709 FILE *f = NULL; | |
6710 | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6711 #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
|
6712 /* 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
|
6713 * 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
|
6714 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
|
6715 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
|
6716 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6717 _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
|
6718 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
|
6719 _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
|
6720 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
|
6721 _set_fmode(_O_BINARY); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6722 #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
|
6723 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
|
6724 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
|
6725 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
|
6726 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
|
6727 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
|
6728 vim_free(wm); |
1569 | 6729 |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6730 #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
|
6731 _set_fmode(oldMode); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6732 #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
|
6733 return f; |
7 | 6734 } |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6735 |
7 | 6736 /* |
6737 * SUB STREAM (aka info stream) handling: | |
6738 * | |
6739 * NTFS can have sub streams for each file. Normal contents of file is | |
6740 * stored in the main stream, and extra contents (author information and | |
6741 * title and so on) can be stored in sub stream. After Windows 2000, user | |
6742 * can access and store those informations in sub streams via explorer's | |
6743 * property menuitem in right click menu. Those informations in sub streams | |
6744 * were lost when copying only the main stream. So we have to copy sub | |
6745 * streams. | |
6746 * | |
6747 * Incomplete explanation: | |
6748 * http://msdn.microsoft.com/library/en-us/dnw2k/html/ntfs5.asp | |
6749 * More useful info and an example: | |
6750 * http://www.sysinternals.com/ntw2k/source/misc.shtml#streams | |
6751 */ | |
6752 | |
6753 /* | |
6754 * Copy info stream data "substream". Read from the file with BackupRead(sh) | |
6755 * and write to stream "substream" of file "to". | |
6756 * Errors are ignored. | |
6757 */ | |
6758 static void | |
6759 copy_substream(HANDLE sh, void *context, WCHAR *to, WCHAR *substream, long len) | |
6760 { | |
6761 HANDLE hTo; | |
6762 WCHAR *to_name; | |
6763 | |
6764 to_name = malloc((wcslen(to) + wcslen(substream) + 1) * sizeof(WCHAR)); | |
6765 wcscpy(to_name, to); | |
6766 wcscat(to_name, substream); | |
6767 | |
6768 hTo = CreateFileW(to_name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, | |
6769 FILE_ATTRIBUTE_NORMAL, NULL); | |
6770 if (hTo != INVALID_HANDLE_VALUE) | |
6771 { | |
6772 long done; | |
6773 DWORD todo; | |
6774 DWORD readcnt, written; | |
6775 char buf[4096]; | |
6776 | |
6777 /* Copy block of bytes at a time. Abort when something goes wrong. */ | |
6778 for (done = 0; done < len; done += written) | |
6779 { | |
6780 /* (size_t) cast for Borland C 5.5 */ | |
835 | 6781 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) |
6782 : (size_t)(len - done)); | |
7 | 6783 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, |
6784 FALSE, FALSE, context) | |
6785 || readcnt != todo | |
6786 || !WriteFile(hTo, buf, todo, &written, NULL) | |
6787 || written != todo) | |
6788 break; | |
6789 } | |
6790 CloseHandle(hTo); | |
6791 } | |
6792 | |
6793 free(to_name); | |
6794 } | |
6795 | |
6796 /* | |
6797 * Copy info streams from file "from" to file "to". | |
6798 */ | |
6799 static void | |
6800 copy_infostreams(char_u *from, char_u *to) | |
6801 { | |
6802 WCHAR *fromw; | |
6803 WCHAR *tow; | |
6804 HANDLE sh; | |
6805 WIN32_STREAM_ID sid; | |
6806 int headersize; | |
6807 WCHAR streamname[_MAX_PATH]; | |
6808 DWORD readcount; | |
6809 void *context = NULL; | |
6810 DWORD lo, hi; | |
6811 int len; | |
6812 | |
6813 /* Convert the file names to wide characters. */ | |
1752 | 6814 fromw = enc_to_utf16(from, NULL); |
6815 tow = enc_to_utf16(to, NULL); | |
7 | 6816 if (fromw != NULL && tow != NULL) |
6817 { | |
6818 /* Open the file for reading. */ | |
6819 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, | |
6820 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | |
6821 if (sh != INVALID_HANDLE_VALUE) | |
6822 { | |
6823 /* Use BackupRead() to find the info streams. Repeat until we | |
6824 * have done them all.*/ | |
6825 for (;;) | |
6826 { | |
6827 /* Get the header to find the length of the stream name. If | |
6828 * the "readcount" is zero we have done all info streams. */ | |
6829 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); | |
835 | 6830 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); |
7 | 6831 if (!BackupRead(sh, (LPBYTE)&sid, headersize, |
6832 &readcount, FALSE, FALSE, &context) | |
6833 || readcount == 0) | |
6834 break; | |
6835 | |
6836 /* We only deal with streams that have a name. The normal | |
6837 * file data appears to be without a name, even though docs | |
6838 * suggest it is called "::$DATA". */ | |
6839 if (sid.dwStreamNameSize > 0) | |
6840 { | |
6841 /* Read the stream name. */ | |
6842 if (!BackupRead(sh, (LPBYTE)streamname, | |
6843 sid.dwStreamNameSize, | |
6844 &readcount, FALSE, FALSE, &context)) | |
6845 break; | |
6846 | |
6847 /* Copy an info stream with a name ":anything:$DATA". | |
6848 * Skip "::$DATA", it has no stream name (examples suggest | |
6849 * it might be used for the normal file contents). | |
6850 * Note that BackupRead() counts bytes, but the name is in | |
6851 * wide characters. */ | |
6852 len = readcount / sizeof(WCHAR); | |
6853 streamname[len] = 0; | |
6854 if (len > 7 && wcsicmp(streamname + len - 6, | |
6855 L":$DATA") == 0) | |
6856 { | |
6857 streamname[len - 6] = 0; | |
6858 copy_substream(sh, &context, tow, streamname, | |
10 | 6859 (long)sid.Size.u.LowPart); |
7 | 6860 } |
6861 } | |
6862 | |
6863 /* Advance to the next stream. We might try seeking too far, | |
6864 * but BackupSeek() doesn't skip over stream borders, thus | |
6865 * that's OK. */ | |
323 | 6866 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, |
7 | 6867 &lo, &hi, &context); |
6868 } | |
6869 | |
6870 /* Clear the context. */ | |
6871 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); | |
6872 | |
6873 CloseHandle(sh); | |
6874 } | |
6875 } | |
6876 vim_free(fromw); | |
6877 vim_free(tow); | |
6878 } | |
6879 | |
6880 /* | |
6881 * Copy file attributes from file "from" to file "to". | |
6882 * For Windows NT and later we copy info streams. | |
6883 * Always returns zero, errors are ignored. | |
6884 */ | |
6885 int | |
6886 mch_copy_file_attribute(char_u *from, char_u *to) | |
6887 { | |
6888 /* 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
|
6889 copy_infostreams(from, to); |
7 | 6890 return 0; |
6891 } | |
6892 | |
6893 #if defined(MYRESETSTKOFLW) || defined(PROTO) | |
6894 /* | |
6895 * Recreate a destroyed stack guard page in win32. | |
6896 * Written by Benjamin Peterson. | |
6897 */ | |
6898 | |
6899 /* 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
|
6900 # define MIN_STACK_WINNT 2 |
7 | 6901 |
6902 /* | |
6903 * This function does the same thing as _resetstkoflw(), which is only | |
6904 * available in DevStudio .net and later. | |
6905 * Returns 0 for failure, 1 for success. | |
6906 */ | |
6907 int | |
6908 myresetstkoflw(void) | |
6909 { | |
6910 BYTE *pStackPtr; | |
6911 BYTE *pGuardPage; | |
6912 BYTE *pStackBase; | |
6913 BYTE *pLowestPossiblePage; | |
6914 MEMORY_BASIC_INFORMATION mbi; | |
6915 SYSTEM_INFO si; | |
6916 DWORD nPageSize; | |
6917 DWORD dummy; | |
6918 | |
6919 /* We need to know the system page size. */ | |
6920 GetSystemInfo(&si); | |
6921 nPageSize = si.dwPageSize; | |
6922 | |
6923 /* ...and the current stack pointer */ | |
6924 pStackPtr = (BYTE*)_alloca(1); | |
6925 | |
6926 /* ...and the base of the stack. */ | |
6927 if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0) | |
6928 return 0; | |
6929 pStackBase = (BYTE*)mbi.AllocationBase; | |
6930 | |
6931 /* ...and the page thats min_stack_req pages away from stack base; this is | |
6932 * 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
|
6933 pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6934 |
7 | 6935 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6936 /* 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
|
6937 * 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
|
6938 */ |
7 | 6939 BYTE *pBlock = pStackBase; |
6940 | |
406 | 6941 for (;;) |
7 | 6942 { |
6943 if (VirtualQuery(pBlock, &mbi, sizeof mbi) == 0) | |
6944 return 0; | |
6945 | |
6946 pBlock += mbi.RegionSize; | |
6947 | |
6948 if (mbi.State & MEM_COMMIT) | |
6949 break; | |
6950 } | |
6951 | |
6952 /* mbi now describes the first committed block in the stack. */ | |
6953 if (mbi.Protect & PAGE_GUARD) | |
6954 return 1; | |
6955 | |
6956 /* decide where the guard page should start */ | |
6957 if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage) | |
6958 pGuardPage = pLowestPossiblePage; | |
6959 else | |
6960 pGuardPage = (BYTE*)mbi.BaseAddress; | |
6961 | |
6962 /* allocate the guard page */ | |
6963 if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE)) | |
6964 return 0; | |
6965 | |
6966 /* apply the guard attribute to the page */ | |
6967 if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD, | |
6968 &dummy)) | |
6969 return 0; | |
6970 } | |
6971 | |
6972 return 1; | |
6973 } | |
6974 #endif | |
26 | 6975 |
6976 | |
6977 /* | |
6978 * The command line arguments in UCS2 | |
6979 */ | |
344 | 6980 static int nArgsW = 0; |
26 | 6981 static LPWSTR *ArglistW = NULL; |
6982 static int global_argc = 0; | |
6983 static char **global_argv; | |
6984 | |
6985 static int used_file_argc = 0; /* last argument in global_argv[] used | |
6986 for the argument list. */ | |
6987 static int *used_file_indexes = NULL; /* indexes in global_argv[] for | |
6988 command line arguments added to | |
6989 the argument list */ | |
6990 static int used_file_count = 0; /* nr of entries in used_file_indexes */ | |
6991 static int used_file_literal = FALSE; /* take file names literally */ | |
6992 static int used_file_full_path = FALSE; /* file name was full path */ | |
819 | 6993 static int used_file_diff_mode = FALSE; /* file name was with diff mode */ |
26 | 6994 static int used_alist_count = 0; |
6995 | |
6996 | |
6997 /* | |
6998 * Get the command line arguments. Unicode version. | |
6999 * Returns argc. Zero when something fails. | |
7000 */ | |
7001 int | |
7002 get_cmd_argsW(char ***argvp) | |
7003 { | |
7004 char **argv = NULL; | |
7005 int argc = 0; | |
7006 int i; | |
7007 | |
6193 | 7008 free_cmd_argsW(); |
26 | 7009 ArglistW = CommandLineToArgvW(GetCommandLineW(), &nArgsW); |
7010 if (ArglistW != NULL) | |
7011 { | |
7012 argv = malloc((nArgsW + 1) * sizeof(char *)); | |
7013 if (argv != NULL) | |
7014 { | |
7015 argc = nArgsW; | |
7016 argv[argc] = NULL; | |
7017 for (i = 0; i < argc; ++i) | |
7018 { | |
7019 int len; | |
7020 | |
7021 /* Convert each Unicode argument to the current codepage. */ | |
7022 WideCharToMultiByte_alloc(GetACP(), 0, | |
835 | 7023 ArglistW[i], (int)wcslen(ArglistW[i]) + 1, |
26 | 7024 (LPSTR *)&argv[i], &len, 0, 0); |
7025 if (argv[i] == NULL) | |
7026 { | |
7027 /* Out of memory, clear everything. */ | |
7028 while (i > 0) | |
7029 free(argv[--i]); | |
7030 free(argv); | |
5529 | 7031 argv = NULL; |
26 | 7032 argc = 0; |
7033 } | |
7034 } | |
7035 } | |
7036 } | |
7037 | |
7038 global_argc = argc; | |
7039 global_argv = argv; | |
7040 if (argc > 0) | |
6193 | 7041 { |
7042 if (used_file_indexes != NULL) | |
7043 free(used_file_indexes); | |
26 | 7044 used_file_indexes = malloc(argc * sizeof(int)); |
6193 | 7045 } |
26 | 7046 |
7047 if (argvp != NULL) | |
7048 *argvp = argv; | |
7049 return argc; | |
7050 } | |
7051 | |
7052 void | |
7053 free_cmd_argsW(void) | |
7054 { | |
7055 if (ArglistW != NULL) | |
7056 { | |
7057 GlobalFree(ArglistW); | |
7058 ArglistW = NULL; | |
7059 } | |
7060 } | |
7061 | |
7062 /* | |
7063 * Remember "name" is an argument that was added to the argument list. | |
7064 * This avoids that we have to re-parse the argument list when fix_arg_enc() | |
7065 * is called. | |
7066 */ | |
7067 void | |
819 | 7068 used_file_arg(char *name, int literal, int full_path, int diff_mode) |
26 | 7069 { |
7070 int i; | |
7071 | |
7072 if (used_file_indexes == NULL) | |
7073 return; | |
7074 for (i = used_file_argc + 1; i < global_argc; ++i) | |
7075 if (STRCMP(global_argv[i], name) == 0) | |
7076 { | |
7077 used_file_argc = i; | |
7078 used_file_indexes[used_file_count++] = i; | |
7079 break; | |
7080 } | |
7081 used_file_literal = literal; | |
7082 used_file_full_path = full_path; | |
819 | 7083 used_file_diff_mode = diff_mode; |
26 | 7084 } |
7085 | |
7086 /* | |
7087 * Remember the length of the argument list as it was. If it changes then we | |
7088 * leave it alone when 'encoding' is set. | |
7089 */ | |
7090 void | |
7091 set_alist_count(void) | |
7092 { | |
7093 used_alist_count = GARGCOUNT; | |
7094 } | |
7095 | |
7096 /* | |
7097 * Fix the encoding of the command line arguments. Invoked when 'encoding' | |
7098 * has been changed while starting up. Use the UCS-2 command line arguments | |
7099 * and convert them to 'encoding'. | |
7100 */ | |
7101 void | |
7102 fix_arg_enc(void) | |
7103 { | |
7104 int i; | |
7105 int idx; | |
7106 char_u *str; | |
41 | 7107 int *fnum_list; |
26 | 7108 |
7109 /* Safety checks: | |
7110 * - if argument count differs between the wide and non-wide argument | |
7111 * list, something must be wrong. | |
7112 * - the file name arguments must have been located. | |
7113 * - the length of the argument list wasn't changed by the user. | |
7114 */ | |
344 | 7115 if (global_argc != nArgsW |
26 | 7116 || ArglistW == NULL |
7117 || used_file_indexes == NULL | |
7118 || used_file_count == 0 | |
7119 || used_alist_count != GARGCOUNT) | |
7120 return; | |
7121 | |
41 | 7122 /* Remember the buffer numbers for the arguments. */ |
7123 fnum_list = (int *)alloc((int)sizeof(int) * GARGCOUNT); | |
7124 if (fnum_list == NULL) | |
7125 return; /* out of memory */ | |
7126 for (i = 0; i < GARGCOUNT; ++i) | |
7127 fnum_list[i] = GARGLIST[i].ae_fnum; | |
7128 | |
26 | 7129 /* Clear the argument list. Make room for the new arguments. */ |
7130 alist_clear(&global_alist); | |
7131 if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL) | |
41 | 7132 return; /* out of memory */ |
26 | 7133 |
7134 for (i = 0; i < used_file_count; ++i) | |
7135 { | |
7136 idx = used_file_indexes[i]; | |
1752 | 7137 str = utf16_to_enc(ArglistW[idx], NULL); |
26 | 7138 if (str != NULL) |
41 | 7139 { |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7140 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
|
7141 |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
7142 # ifdef FEAT_DIFF |
819 | 7143 /* When using diff mode may need to concatenate file name to |
7144 * directory name. Just like it's done in main(). */ | |
7145 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 | |
7146 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
7147 { | |
7148 char_u *r; | |
7149 | |
7150 r = concat_fnames(str, gettail(alist_name(&GARGLIST[0])), TRUE); | |
7151 if (r != NULL) | |
7152 { | |
7153 vim_free(str); | |
7154 str = r; | |
7155 } | |
7156 } | |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
7157 # endif |
41 | 7158 /* Re-use the old buffer by renaming it. When not using literal |
7159 * names it's done by alist_expand() below. */ | |
7160 if (used_file_literal) | |
7161 buf_set_name(fnum_list[i], str); | |
7162 | |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7163 /* 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
|
7164 * 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
|
7165 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
|
7166 { |
12015
7e704d75a882
patch 8.0.0888: compiler warnings with 64 bit build
Christian Brabandt <cb@256bit.org>
parents:
11991
diff
changeset
|
7167 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
|
7168 |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7169 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
|
7170 literal = TRUE; |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7171 } |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7172 alist_add(&global_alist, str, literal ? 2 : 0); |
41 | 7173 } |
26 | 7174 } |
7175 | |
7176 if (!used_file_literal) | |
7177 { | |
7178 /* Now expand wildcards in the arguments. */ | |
7179 /* Temporarily add '(' and ')' to 'isfname'. These are valid | |
7180 * 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
|
7181 * "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
|
7182 * 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
|
7183 * 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
|
7184 * encoding options were changed. */ |
26 | 7185 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
|
7186 do_cmdline_cmd((char_u *)":let SaVe_WIG = &wig|set wig="); |
41 | 7187 alist_expand(fnum_list, used_alist_count); |
26 | 7188 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
|
7189 do_cmdline_cmd((char_u *)":let &wig = SaVe_WIG|unlet SaVe_WIG"); |
26 | 7190 } |
7191 | |
7192 /* If wildcard expansion failed, we are editing the first file of the | |
7193 * arglist and there is no file name: Edit the first argument now. */ | |
7194 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) | |
7195 { | |
7196 do_cmdline_cmd((char_u *)":rewind"); | |
7197 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
|
7198 (void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop"); |
26 | 7199 } |
41 | 7200 |
7201 set_alist_count(); | |
26 | 7202 } |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7203 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7204 int |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7205 mch_setenv(char *var, char *value, int x) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7206 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7207 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
|
7208 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
|
7209 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7210 envbuf = alloc((unsigned)(STRLEN(var) + STRLEN(value) + 2)); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7211 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
|
7212 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
|
7213 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7214 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
|
7215 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7216 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
|
7217 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7218 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
|
7219 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
|
7220 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
|
7221 _wputenv(p); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7222 #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
|
7223 libintl_wputenv(p); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7224 #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
|
7225 // 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
|
7226 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
|
7227 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7228 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
|
7229 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7230 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7231 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7232 * 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
|
7233 * 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
|
7234 */ |
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
|
7235 #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
|
7236 |
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
|
7237 /* |
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
|
7238 * Support for pseudo-console (ConPTY) was added in windows 10 |
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
|
7239 * version 1809 (October 2018 update). However, that version is unstable. |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7240 */ |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7241 #define CONPTY_FIRST_SUPPORT_BUILD MAKE_VER(10, 0, 17763) |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7242 #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
|
7243 |
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
|
7244 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
|
7245 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
|
7246 { |
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
|
7247 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
|
7248 #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
|
7249 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
|
7250 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
|
7251 |
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
|
7252 # 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
|
7253 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
|
7254 # 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
|
7255 { |
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
|
7256 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
|
7257 |
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
|
7258 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
|
7259 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
|
7260 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
|
7261 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
|
7262 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
|
7263 } |
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
|
7264 #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
|
7265 |
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
|
7266 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
|
7267 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
|
7268 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
|
7269 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
|
7270 |
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
|
7271 } |
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
|
7272 |
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
|
7273 #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
|
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 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
|
7276 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
|
7277 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7278 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
|
7279 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
|
7280 # 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
|
7281 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
|
7282 # 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
|
7283 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7284 /* 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
|
7285 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
|
7286 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
|
7287 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7288 pGetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7289 (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
|
7290 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
|
7291 pSetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7292 (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
|
7293 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
|
7294 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
|
7295 && 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
|
7296 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
|
7297 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7298 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7299 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
|
7300 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
|
7301 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
|
7302 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
|
7303 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
|
7304 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7305 # 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
|
7306 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
|
7307 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
|
7308 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
|
7309 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
|
7310 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
|
7311 default_console_color_fg = fg; |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
7312 # 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
|
7313 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7314 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
|
7315 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7316 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7317 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
|
7318 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
|
7319 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7320 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
|
7321 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7322 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7323 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
|
7324 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
|
7325 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
|
7326 ...) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7327 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7328 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
|
7329 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
|
7330 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
|
7331 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7332 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
|
7333 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
|
7334 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
|
7335 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
|
7336 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
|
7337 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7338 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7339 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
|
7340 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
|
7341 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
|
7342 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7343 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
|
7344 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7345 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
|
7346 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
|
7347 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7348 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7349 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
|
7350 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
|
7351 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
|
7352 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
|
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 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7355 /* 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
|
7356 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
|
7357 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
|
7358 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
|
7359 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7360 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
|
7361 *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
|
7362 *p++ = '['; |
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 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
|
7365 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7366 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
|
7367 *p++ = ';'; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7368 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7369 p--; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7370 *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
|
7371 *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
|
7372 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
|
7373 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7374 |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
7375 # 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
|
7376 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
|
7377 ctermtoxterm( |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7378 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
|
7379 { |
13839
ca8953d36264
patch 8.0.1791: using uint8_t does not work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13827
diff
changeset
|
7380 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
|
7381 |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7382 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
|
7383 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
|
7384 } |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
7385 # 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
|
7386 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7387 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
|
7388 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
|
7389 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7390 # 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
|
7391 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
|
7392 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
|
7393 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
|
7394 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
|
7395 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
|
7396 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
|
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 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
|
7399 return; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7400 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7401 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
|
7402 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
|
7403 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
|
7404 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
|
7405 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7406 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
|
7407 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
|
7408 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
|
7409 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
|
7410 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
|
7411 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7412 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
|
7413 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7414 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
|
7415 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
|
7416 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
|
7417 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
|
7418 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
|
7419 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7420 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
|
7421 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
|
7422 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7423 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
|
7424 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
|
7425 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
|
7426 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7427 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
|
7428 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
|
7429 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
|
7430 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
|
7431 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
|
7432 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
|
7433 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
|
7434 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7435 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7436 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7437 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
|
7438 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
|
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 # 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
|
7441 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
|
7442 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7443 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
|
7444 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
|
7445 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
|
7446 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7447 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
|
7448 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
|
7449 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
|
7450 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
|
7451 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
|
7452 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
|
7453 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
|
7454 # endif |
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 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7457 void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7458 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
|
7459 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7460 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
|
7461 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
|
7462 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7463 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
|
7464 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7465 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7466 int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7467 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
|
7468 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7469 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
|
7470 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7471 |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7472 int |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7473 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
|
7474 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7475 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
|
7476 } |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7477 |
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
|
7478 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
|
7479 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
|
7480 { |
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
|
7481 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
|
7482 } |
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
|
7483 |
15848
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
7484 #endif |
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
7485 |
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
|
7486 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
|
7487 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
|
7488 { |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7489 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
|
7490 } |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7491 |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7492 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
|
7493 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
|
7494 { |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7495 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
|
7496 } |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7497 |
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
|
7498 #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
|
7499 void |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7500 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
|
7501 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7502 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
|
7503 COORD coord; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7504 SMALL_RECT newsize; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7505 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7506 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
|
7507 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7508 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
|
7509 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
|
7510 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
|
7511 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7512 newsize.Left = 0; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7513 newsize.Top = 0; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7514 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
|
7515 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
|
7516 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
|
7517 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7518 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
|
7519 } |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7520 } |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7521 #endif |