Mercurial > vim
annotate src/os_win32.c @ 18867:c9409f359583
Added tag v8.1.2419 for changeset a686560cf6c90b9917be2eb06cb57b592bfeb541
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 11 Dec 2019 19:15:05 +0100 |
parents | 44b855153d8e |
children | 44906eff69f9 |
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 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
33 // cproto fails on missing include files |
3927 | 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 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
85 // Record all output and all keyboard & mouse input |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
86 // #define MCH_WRITE_DUMP |
7 | 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 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
97 # define WINAPI |
7 | 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; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
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) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
150 // Win32 Console handles for input and output |
7 | 151 static HANDLE g_hConIn = INVALID_HANDLE_VALUE; |
152 static HANDLE g_hConOut = INVALID_HANDLE_VALUE; | |
153 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
154 // Win32 Screen buffer,coordinate,console I/O information |
7 | 155 static SMALL_RECT g_srScrollRegion; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
156 static COORD g_coord; // 0-based, but external coords are 1-based |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
157 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
158 // The attribute of the screen when the editor was started |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
159 static WORD g_attrDefault = 7; // lightgray text on black background |
7 | 160 static WORD g_attrCurrent; |
161 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
162 static int g_fCBrkPressed = FALSE; // set by ctrl-break interrupt |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
163 static int g_fCtrlCPressed = FALSE; // set when ctrl-C or ctrl-break detected |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
164 static int g_fForceExit = FALSE; // set when forcefully exiting |
7 | 165 |
166 static void scroll(unsigned cLines); | |
167 static void set_scroll_region(unsigned left, unsigned top, | |
168 unsigned right, unsigned bottom); | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
169 static void set_scroll_region_tb(unsigned top, unsigned bottom); |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
170 static void set_scroll_region_lr(unsigned left, unsigned right); |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
171 static void insert_lines(unsigned cLines); |
7 | 172 static void delete_lines(unsigned cLines); |
173 static void gotoxy(unsigned x, unsigned y); | |
174 static void standout(void); | |
175 static int s_cursor_visible = TRUE; | |
176 static int did_create_conin = FALSE; | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
177 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
178 #ifdef FEAT_GUI_MSWIN |
7 | 179 static int s_dont_use_vimrun = TRUE; |
180 static int need_vimrun_warning = FALSE; | |
181 static char *vimrun_path = "vimrun "; | |
182 #endif | |
183 | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
184 static int win32_getattrs(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
185 static int win32_setattrs(char_u *name, int attrs); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
186 static int win32_set_archive(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
187 |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
188 static int conpty_working = 0; |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
189 static int conpty_type = 0; |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
190 static int conpty_stable = 0; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
191 static void vtp_flag_init(); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
192 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
193 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
15848
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
194 static int vtp_working = 0; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
195 static void vtp_init(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
196 static void vtp_exit(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
197 static int vtp_printf(char *format, ...); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
198 static void vtp_sgr_bulk(int arg); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
199 static void vtp_sgr_bulks(int argc, int *argv); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
200 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
201 static guicolor_T save_console_bg_rgb; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
202 static guicolor_T save_console_fg_rgb; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
203 |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
204 static int g_color_index_bg = 0; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
205 static int g_color_index_fg = 7; |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
206 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
207 # ifdef FEAT_TERMGUICOLORS |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
208 static int default_console_color_bg = 0x000000; // black |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
209 static int default_console_color_fg = 0xc0c0c0; // white |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
210 # endif |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
211 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
212 # ifdef FEAT_TERMGUICOLORS |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
213 # define USE_VTP (vtp_working && is_term_win32() && (p_tgc || (!p_tgc && t_colors >= 256))) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
214 # else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
215 # define USE_VTP 0 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
216 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
217 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
218 static void set_console_color_rgb(void); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
219 static void reset_console_color_rgb(void); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
220 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
221 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
222 // This flag is newly created from Windows 10 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
223 #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
224 # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
225 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
226 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
227 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
228 static int suppress_winsize = 1; // don't fiddle with console |
7 | 229 #endif |
230 | |
2612 | 231 static char_u *exe_path = NULL; |
232 | |
5633 | 233 static BOOL win8_or_later = FALSE; |
234 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
235 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
236 // Dynamic loading for portability |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
237 typedef struct _DYN_CONSOLE_SCREEN_BUFFER_INFOEX |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
238 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
239 ULONG cbSize; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
240 COORD dwSize; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
241 COORD dwCursorPosition; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
242 WORD wAttributes; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
243 SMALL_RECT srWindow; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
244 COORD dwMaximumWindowSize; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
245 WORD wPopupAttributes; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
246 BOOL bFullscreenSupported; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
247 COLORREF ColorTable[16]; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
248 } DYN_CONSOLE_SCREEN_BUFFER_INFOEX, *PDYN_CONSOLE_SCREEN_BUFFER_INFOEX; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
249 typedef BOOL (WINAPI *PfnGetConsoleScreenBufferInfoEx)(HANDLE, PDYN_CONSOLE_SCREEN_BUFFER_INFOEX); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
250 static PfnGetConsoleScreenBufferInfoEx pGetConsoleScreenBufferInfoEx; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
251 typedef BOOL (WINAPI *PfnSetConsoleScreenBufferInfoEx)(HANDLE, PDYN_CONSOLE_SCREEN_BUFFER_INFOEX); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
252 static PfnSetConsoleScreenBufferInfoEx pSetConsoleScreenBufferInfoEx; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
253 static BOOL has_csbiex = FALSE; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
254 #endif |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
255 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
256 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
257 * Get version number including build number |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
258 */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
259 typedef BOOL (WINAPI *PfnRtlGetVersion)(LPOSVERSIONINFOW); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
260 #define MAKE_VER(major, minor, build) \ |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
261 (((major) << 24) | ((minor) << 16) | (build)) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
262 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
263 static DWORD |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
264 get_build_number(void) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
265 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
266 OSVERSIONINFOW osver = {sizeof(OSVERSIONINFOW)}; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
267 HMODULE hNtdll; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
268 PfnRtlGetVersion pRtlGetVersion; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
269 DWORD ver = MAKE_VER(0, 0, 0); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
270 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
271 hNtdll = GetModuleHandle("ntdll.dll"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
272 if (hNtdll != NULL) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
273 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
274 pRtlGetVersion = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
275 (PfnRtlGetVersion)GetProcAddress(hNtdll, "RtlGetVersion"); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
276 pRtlGetVersion(&osver); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
277 ver = MAKE_VER(min(osver.dwMajorVersion, 255), |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
278 min(osver.dwMinorVersion, 255), |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
279 min(osver.dwBuildNumber, 32767)); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
280 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
281 return ver; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
282 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
283 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
284 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
5580 | 285 /* |
286 * Version of ReadConsoleInput() that works with IME. | |
5590 | 287 * Works around problems on Windows 8. |
5580 | 288 */ |
289 static BOOL | |
290 read_console_input( | |
5590 | 291 HANDLE hInput, |
292 INPUT_RECORD *lpBuffer, | |
293 DWORD nLength, | |
294 LPDWORD lpEvents) | |
5580 | 295 { |
296 enum | |
297 { | |
5590 | 298 IRSIZE = 10 |
5580 | 299 }; |
5590 | 300 static INPUT_RECORD s_irCache[IRSIZE]; |
5580 | 301 static DWORD s_dwIndex = 0; |
302 static DWORD s_dwMax = 0; | |
5590 | 303 DWORD dwEvents; |
5635 | 304 int head; |
305 int tail; | |
306 int i; | |
5580 | 307 |
6981 | 308 if (nLength == -2) |
309 return (s_dwMax > 0) ? TRUE : FALSE; | |
310 | |
5633 | 311 if (!win8_or_later) |
312 { | |
313 if (nLength == -1) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
314 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
315 return ReadConsoleInputW(hInput, lpBuffer, 1, &dwEvents); |
5633 | 316 } |
317 | |
5580 | 318 if (s_dwMax == 0) |
319 { | |
5590 | 320 if (nLength == -1) |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
321 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
322 if (!ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents)) |
5590 | 323 return FALSE; |
5580 | 324 s_dwIndex = 0; |
5590 | 325 s_dwMax = dwEvents; |
326 if (dwEvents == 0) | |
5580 | 327 { |
5590 | 328 *lpEvents = 0; |
329 return TRUE; | |
5580 | 330 } |
5635 | 331 |
332 if (s_dwMax > 1) | |
333 { | |
334 head = 0; | |
335 tail = s_dwMax - 1; | |
336 while (head != tail) | |
337 { | |
338 if (s_irCache[head].EventType == WINDOW_BUFFER_SIZE_EVENT | |
339 && s_irCache[head + 1].EventType | |
340 == WINDOW_BUFFER_SIZE_EVENT) | |
341 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
342 // Remove duplicate event to avoid flicker. |
5635 | 343 for (i = head; i < tail; ++i) |
344 s_irCache[i] = s_irCache[i + 1]; | |
345 --tail; | |
346 continue; | |
347 } | |
348 head++; | |
349 } | |
350 s_dwMax = tail + 1; | |
351 } | |
5580 | 352 } |
5635 | 353 |
5590 | 354 *lpBuffer = s_irCache[s_dwIndex]; |
6981 | 355 if (!(nLength == -1 || nLength == -2) && ++s_dwIndex >= s_dwMax) |
5580 | 356 s_dwMax = 0; |
5590 | 357 *lpEvents = 1; |
5580 | 358 return TRUE; |
359 } | |
360 | |
361 /* | |
362 * Version of PeekConsoleInput() that works with IME. | |
363 */ | |
364 static BOOL | |
365 peek_console_input( | |
5590 | 366 HANDLE hInput, |
367 INPUT_RECORD *lpBuffer, | |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
368 DWORD nLength UNUSED, |
5590 | 369 LPDWORD lpEvents) |
5580 | 370 { |
5590 | 371 return read_console_input(hInput, lpBuffer, -1, lpEvents); |
5580 | 372 } |
373 | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
374 # ifdef FEAT_CLIENTSERVER |
6981 | 375 static DWORD |
376 msg_wait_for_multiple_objects( | |
377 DWORD nCount, | |
378 LPHANDLE pHandles, | |
379 BOOL fWaitAll, | |
380 DWORD dwMilliseconds, | |
381 DWORD dwWakeMask) | |
382 { | |
383 if (read_console_input(NULL, NULL, -2, NULL)) | |
384 return WAIT_OBJECT_0; | |
385 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, | |
386 dwMilliseconds, dwWakeMask); | |
387 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
388 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
389 |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
390 # ifndef FEAT_CLIENTSERVER |
6981 | 391 static DWORD |
392 wait_for_single_object( | |
393 HANDLE hHandle, | |
394 DWORD dwMilliseconds) | |
395 { | |
396 if (read_console_input(NULL, NULL, -2, NULL)) | |
397 return WAIT_OBJECT_0; | |
398 return WaitForSingleObject(hHandle, dwMilliseconds); | |
399 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
400 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
401 #endif |
6981 | 402 |
7 | 403 static void |
404 get_exe_name(void) | |
405 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
406 // Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
407 // as the maximum length that works (plus a NUL byte). |
2630 | 408 #define MAX_ENV_PATH_LEN 8192 |
409 char temp[MAX_ENV_PATH_LEN]; | |
2612 | 410 char_u *p; |
7 | 411 |
412 if (exe_name == NULL) | |
413 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
414 // store the name of the executable, may be used for $VIM |
2630 | 415 GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1); |
7 | 416 if (*temp != NUL) |
417 exe_name = FullName_save((char_u *)temp, FALSE); | |
418 } | |
819 | 419 |
2612 | 420 if (exe_path == NULL && exe_name != NULL) |
819 | 421 { |
2615 | 422 exe_path = vim_strnsave(exe_name, |
423 (int)(gettail_sep(exe_name) - exe_name)); | |
2612 | 424 if (exe_path != NULL) |
819 | 425 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
426 // Append our starting directory to $PATH, so that when doing |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
427 // "!xxd" it's found in our starting directory. Needed because |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
428 // SearchPath() also looks there. |
2612 | 429 p = mch_getenv("PATH"); |
2630 | 430 if (p == NULL |
431 || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN) | |
2612 | 432 { |
2630 | 433 if (p == NULL || *p == NUL) |
434 temp[0] = NUL; | |
435 else | |
436 { | |
437 STRCPY(temp, p); | |
438 STRCAT(temp, ";"); | |
439 } | |
2612 | 440 STRCAT(temp, exe_path); |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
441 vim_setenv((char_u *)"PATH", (char_u *)temp); |
2612 | 442 } |
819 | 443 } |
444 } | |
7 | 445 } |
446 | |
2612 | 447 /* |
3361 | 448 * Unescape characters in "p" that appear in "escaped". |
449 */ | |
450 static void | |
451 unescape_shellxquote(char_u *p, char_u *escaped) | |
452 { | |
3386 | 453 int l = (int)STRLEN(p); |
3361 | 454 int n; |
455 | |
456 while (*p != NUL) | |
457 { | |
458 if (*p == '^' && vim_strchr(escaped, p[1]) != NULL) | |
459 mch_memmove(p, p + 1, l--); | |
460 n = (*mb_ptr2len)(p); | |
461 p += n; | |
462 l -= n; | |
463 } | |
464 } | |
465 | |
466 /* | |
2612 | 467 * Load library "name". |
468 */ | |
469 HINSTANCE | |
470 vimLoadLib(char *name) | |
471 { | |
3902 | 472 HINSTANCE dll = NULL; |
3889 | 473 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
474 // NOTE: Do not use mch_dirname() and mch_chdir() here, they may call |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
475 // vimLoadLib() recursively, which causes a stack overflow. |
2612 | 476 if (exe_path == NULL) |
477 get_exe_name(); | |
3902 | 478 if (exe_path != NULL) |
2612 | 479 { |
3902 | 480 WCHAR old_dirw[MAXPATHL]; |
481 | |
482 if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) | |
483 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
484 // Change directory to where the executable is, both to make |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
485 // sure we find a .dll there and to avoid looking for a .dll |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
486 // in the current directory. |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
487 SetCurrentDirectory((LPCSTR)exe_path); |
3902 | 488 dll = LoadLibrary(name); |
489 SetCurrentDirectoryW(old_dirw); | |
490 return dll; | |
491 } | |
2612 | 492 } |
493 return dll; | |
494 } | |
495 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
496 #if defined(VIMDLL) || defined(PROTO) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
497 /* |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
498 * Check if the current executable file is for the GUI subsystem. |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
499 */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
500 int |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
501 mch_is_gui_executable(void) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
502 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
503 PBYTE pImage = (PBYTE)GetModuleHandle(NULL); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
504 PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)pImage; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
505 PIMAGE_NT_HEADERS pPE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
506 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
507 if (pDOS->e_magic != IMAGE_DOS_SIGNATURE) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
508 return FALSE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
509 pPE = (PIMAGE_NT_HEADERS)(pImage + pDOS->e_lfanew); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
510 if (pPE->Signature != IMAGE_NT_SIGNATURE) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
511 return FALSE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
512 if (pPE->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
513 return TRUE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
514 return FALSE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
515 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
516 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
517 |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
518 #if defined(DYNAMIC_ICONV) || defined(DYNAMIC_GETTEXT) || defined(PROTO) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
519 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
520 * Get related information about 'funcname' which is imported by 'hInst'. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
521 * If 'info' is 0, return the function address. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
522 * If 'info' is 1, return the module name which the function is imported from. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
523 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
524 static void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
525 get_imported_func_info(HINSTANCE hInst, const char *funcname, int info) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
526 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
527 PBYTE pImage = (PBYTE)hInst; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
528 PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
529 PIMAGE_NT_HEADERS pPE; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
530 PIMAGE_IMPORT_DESCRIPTOR pImpDesc; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
531 PIMAGE_THUNK_DATA pIAT; // Import Address Table |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
532 PIMAGE_THUNK_DATA pINT; // Import Name Table |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
533 PIMAGE_IMPORT_BY_NAME pImpName; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
534 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
535 if (pDOS->e_magic != IMAGE_DOS_SIGNATURE) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
536 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
537 pPE = (PIMAGE_NT_HEADERS)(pImage + pDOS->e_lfanew); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
538 if (pPE->Signature != IMAGE_NT_SIGNATURE) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
539 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
540 pImpDesc = (PIMAGE_IMPORT_DESCRIPTOR)(pImage |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
541 + pPE->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
542 .VirtualAddress); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
543 for (; pImpDesc->FirstThunk; ++pImpDesc) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
544 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
545 if (!pImpDesc->OriginalFirstThunk) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
546 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
547 pIAT = (PIMAGE_THUNK_DATA)(pImage + pImpDesc->FirstThunk); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
548 pINT = (PIMAGE_THUNK_DATA)(pImage + pImpDesc->OriginalFirstThunk); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
549 for (; pIAT->u1.Function; ++pIAT, ++pINT) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
550 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
551 if (IMAGE_SNAP_BY_ORDINAL(pINT->u1.Ordinal)) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
552 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
553 pImpName = (PIMAGE_IMPORT_BY_NAME)(pImage |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
554 + (UINT_PTR)(pINT->u1.AddressOfData)); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
555 if (strcmp((char *)pImpName->Name, funcname) == 0) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
556 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
557 switch (info) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
558 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
559 case 0: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
560 return (void *)pIAT->u1.Function; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
561 case 1: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
562 return (void *)(pImage + pImpDesc->Name); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
563 default: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
564 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
565 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
566 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
567 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
568 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
569 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
570 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
571 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
572 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
573 * Get the module handle which 'funcname' in 'hInst' is imported from. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
574 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
575 HINSTANCE |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
576 find_imported_module_by_funcname(HINSTANCE hInst, const char *funcname) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
577 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
578 char *modulename; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
579 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
580 modulename = (char *)get_imported_func_info(hInst, funcname, 1); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
581 if (modulename != NULL) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
582 return GetModuleHandleA(modulename); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
583 return NULL; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
584 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
585 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
586 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
587 * Get the address of 'funcname' which is imported by 'hInst' DLL. |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
588 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
589 void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
590 get_dll_import_func(HINSTANCE hInst, const char *funcname) |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
591 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
592 return get_imported_func_info(hInst, funcname, 0); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
593 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
594 #endif |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
595 |
7 | 596 #if defined(DYNAMIC_GETTEXT) || defined(PROTO) |
597 # ifndef GETTEXT_DLL | |
598 # define GETTEXT_DLL "libintl.dll" | |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
599 # define GETTEXT_DLL_ALT1 "libintl-8.dll" |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
600 # define GETTEXT_DLL_ALT2 "intl.dll" |
7 | 601 # endif |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
602 // Dummy functions |
36 | 603 static char *null_libintl_gettext(const char *); |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
604 static char *null_libintl_ngettext(const char *, const char *, unsigned long n); |
36 | 605 static char *null_libintl_textdomain(const char *); |
606 static char *null_libintl_bindtextdomain(const char *, const char *); | |
607 static char *null_libintl_bind_textdomain_codeset(const char *, const char *); | |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
608 static int null_libintl_wputenv(const wchar_t *); |
7 | 609 |
2612 | 610 static HINSTANCE hLibintlDLL = NULL; |
36 | 611 char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext; |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
612 char *(*dyn_libintl_ngettext)(const char *, const char *, unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
613 = null_libintl_ngettext; |
36 | 614 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; |
615 char *(*dyn_libintl_bindtextdomain)(const char *, const char *) | |
7 | 616 = null_libintl_bindtextdomain; |
36 | 617 char *(*dyn_libintl_bind_textdomain_codeset)(const char *, const char *) |
618 = null_libintl_bind_textdomain_codeset; | |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
619 int (*dyn_libintl_wputenv)(const wchar_t *) = null_libintl_wputenv; |
7 | 620 |
621 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
622 dyn_libintl_init(void) |
7 | 623 { |
624 int i; | |
625 static struct | |
626 { | |
627 char *name; | |
628 FARPROC *ptr; | |
629 } libintl_entry[] = | |
630 { | |
631 {"gettext", (FARPROC*)&dyn_libintl_gettext}, | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
632 {"ngettext", (FARPROC*)&dyn_libintl_ngettext}, |
7 | 633 {"textdomain", (FARPROC*)&dyn_libintl_textdomain}, |
634 {"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, | |
635 {NULL, NULL} | |
636 }; | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
637 HINSTANCE hmsvcrt; |
7 | 638 |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
639 // No need to initialize twice. |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
640 if (hLibintlDLL != NULL) |
7 | 641 return 1; |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
642 // Load gettext library (libintl.dll and other names). |
7784
29d4ee3f009a
commit https://github.com/vim/vim/commit/923e43b837ca4c8edb7998743f142823eaeaf588
Christian Brabandt <cb@256bit.org>
parents:
7734
diff
changeset
|
643 hLibintlDLL = vimLoadLib(GETTEXT_DLL); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
644 # ifdef GETTEXT_DLL_ALT1 |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
645 if (!hLibintlDLL) |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
646 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT1); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
647 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
648 # ifdef GETTEXT_DLL_ALT2 |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
649 if (!hLibintlDLL) |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
650 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT2); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
651 # endif |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
652 if (!hLibintlDLL) |
7 | 653 { |
2612 | 654 if (p_verbose > 0) |
7 | 655 { |
2612 | 656 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
657 semsg(_(e_loadlib), GETTEXT_DLL); |
2612 | 658 verbose_leave(); |
7 | 659 } |
2612 | 660 return 0; |
7 | 661 } |
662 for (i = 0; libintl_entry[i].name != NULL | |
663 && libintl_entry[i].ptr != NULL; ++i) | |
664 { | |
665 if ((*libintl_entry[i].ptr = (FARPROC)GetProcAddress(hLibintlDLL, | |
666 libintl_entry[i].name)) == NULL) | |
667 { | |
668 dyn_libintl_end(); | |
669 if (p_verbose > 0) | |
292 | 670 { |
671 verbose_enter(); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
672 semsg(_(e_loadfunc), libintl_entry[i].name); |
292 | 673 verbose_leave(); |
674 } | |
7 | 675 return 0; |
676 } | |
677 } | |
36 | 678 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
679 // The bind_textdomain_codeset() function is optional. |
323 | 680 dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL, |
36 | 681 "bind_textdomain_codeset"); |
682 if (dyn_libintl_bind_textdomain_codeset == NULL) | |
683 dyn_libintl_bind_textdomain_codeset = | |
684 null_libintl_bind_textdomain_codeset; | |
685 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
686 // _wputenv() function for the libintl.dll is optional. |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
687 hmsvcrt = find_imported_module_by_funcname(hLibintlDLL, "getenv"); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
688 if (hmsvcrt != NULL) |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
689 dyn_libintl_wputenv = (void *)GetProcAddress(hmsvcrt, "_wputenv"); |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
690 if (dyn_libintl_wputenv == NULL || dyn_libintl_wputenv == _wputenv) |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
691 dyn_libintl_wputenv = null_libintl_wputenv; |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
692 |
7 | 693 return 1; |
694 } | |
695 | |
696 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
697 dyn_libintl_end(void) |
7 | 698 { |
699 if (hLibintlDLL) | |
700 FreeLibrary(hLibintlDLL); | |
701 hLibintlDLL = NULL; | |
702 dyn_libintl_gettext = null_libintl_gettext; | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
703 dyn_libintl_ngettext = null_libintl_ngettext; |
7 | 704 dyn_libintl_textdomain = null_libintl_textdomain; |
705 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain; | |
36 | 706 dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset; |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
707 dyn_libintl_wputenv = null_libintl_wputenv; |
7 | 708 } |
709 | |
710 static char * | |
26 | 711 null_libintl_gettext(const char *msgid) |
7 | 712 { |
713 return (char*)msgid; | |
714 } | |
715 | |
716 static char * | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
717 null_libintl_ngettext( |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
718 const char *msgid, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
719 const char *msgid_plural, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
720 unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
721 { |
9762
93dcc4329c74
commit https://github.com/vim/vim/commit/c90f2aedd0a5dc2cc75bc9b5f475f8a3e3fe36b1
Christian Brabandt <cb@256bit.org>
parents:
9754
diff
changeset
|
722 return (char *)(n == 1 ? msgid : msgid_plural); |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
723 } |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
724 |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
725 static char * |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
726 null_libintl_bindtextdomain( |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
727 const char *domainname UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
728 const char *dirname UNUSED) |
7 | 729 { |
730 return NULL; | |
731 } | |
732 | |
733 static char * | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
734 null_libintl_bind_textdomain_codeset( |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
735 const char *domainname UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
736 const char *codeset UNUSED) |
36 | 737 { |
738 return NULL; | |
739 } | |
740 | |
741 static char * | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
742 null_libintl_textdomain(const char *domainname UNUSED) |
7 | 743 { |
744 return NULL; | |
745 } | |
746 | |
11929
3457728d1a58
patch 8.0.0844: wrong function prototype because of missing static
Christian Brabandt <cb@256bit.org>
parents:
11921
diff
changeset
|
747 static int |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10781
diff
changeset
|
748 null_libintl_wputenv(const wchar_t *envstring UNUSED) |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
749 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
750 return 0; |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
751 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
752 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
753 #endif // DYNAMIC_GETTEXT |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
754 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
755 // This symbol is not defined in older versions of the SDK or Visual C++ |
7 | 756 |
757 #ifndef VER_PLATFORM_WIN32_WINDOWS | |
758 # define VER_PLATFORM_WIN32_WINDOWS 1 | |
759 #endif | |
760 | |
761 DWORD g_PlatformId; | |
762 | |
763 #ifdef HAVE_ACL | |
3927 | 764 # ifndef PROTO |
765 # include <aclapi.h> | |
766 # endif | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
767 # ifndef PROTECTED_DACL_SECURITY_INFORMATION |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
768 # define PROTECTED_DACL_SECURITY_INFORMATION 0x80000000L |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
769 # endif |
7 | 770 #endif |
771 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
772 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
773 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
774 * Enables or disables the specified privilege. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
775 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
776 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
777 win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
778 { |
5590 | 779 BOOL bResult; |
780 LUID luid; | |
781 HANDLE hToken; | |
782 TOKEN_PRIVILEGES tokenPrivileges; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
783 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
784 if (!OpenProcessToken(GetCurrentProcess(), |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
785 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
786 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
787 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
788 if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
789 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
790 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
791 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
792 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
793 |
6047 | 794 tokenPrivileges.PrivilegeCount = 1; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
795 tokenPrivileges.Privileges[0].Luid = luid; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
796 tokenPrivileges.Privileges[0].Attributes = bEnable ? |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
797 SE_PRIVILEGE_ENABLED : 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
798 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
799 bResult = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
800 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
801 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
802 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
803 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
804 return bResult && GetLastError() == ERROR_SUCCESS; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
805 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
806 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
807 |
7 | 808 /* |
809 * Set g_PlatformId to VER_PLATFORM_WIN32_NT (NT) or | |
810 * VER_PLATFORM_WIN32_WINDOWS (Win95). | |
811 */ | |
812 void | |
813 PlatformId(void) | |
814 { | |
815 static int done = FALSE; | |
816 | |
817 if (!done) | |
818 { | |
819 OSVERSIONINFO ovi; | |
820 | |
821 ovi.dwOSVersionInfoSize = sizeof(ovi); | |
822 GetVersionEx(&ovi); | |
823 | |
824 g_PlatformId = ovi.dwPlatformId; | |
825 | |
5633 | 826 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2) |
827 || ovi.dwMajorVersion > 6) | |
828 win8_or_later = TRUE; | |
829 | |
7 | 830 #ifdef HAVE_ACL |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
831 // Enable privilege for getting or setting SACLs. |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
832 win32_enable_privilege(SE_SECURITY_NAME, TRUE); |
7 | 833 #endif |
834 done = TRUE; | |
835 } | |
836 } | |
837 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
838 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 839 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
840 # define SHIFT (SHIFT_PRESSED) |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
841 # define CTRL (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED) |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
842 # define ALT (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED) |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
843 # define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) |
7 | 844 |
845 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
846 // When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
847 // We map function keys to their ANSI terminal equivalents, as produced |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
848 // by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
849 // ANSI key with a value >= '\300' is nonstandard, but provided anyway |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
850 // so that the user can have access to all SHIFT-, CTRL-, and ALT- |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
851 // combinations of function/arrow/etc keys. |
7 | 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 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
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', }, |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
903 # endif |
14891
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 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
923 # if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__) |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
924 # define UChar UnicodeChar |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
925 # else |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
926 # define UChar uChar.UnicodeChar |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
927 # endif |
7 | 928 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
929 /* |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
930 * The return code indicates key code size. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
931 */ |
7 | 932 static int |
933 win32_kbd_patch_key( | |
26 | 934 KEY_EVENT_RECORD *pker) |
7 | 935 { |
936 UINT uMods = pker->dwControlKeyState; | |
937 static int s_iIsDead = 0; | |
938 static WORD awAnsiCode[2]; | |
939 static BYTE abKeystate[256]; | |
940 | |
941 | |
942 if (s_iIsDead == 2) | |
943 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
944 pker->UChar = (WCHAR) awAnsiCode[1]; |
7 | 945 s_iIsDead = 0; |
946 return 1; | |
947 } | |
948 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
949 if (pker->UChar != 0) |
7 | 950 return 1; |
951 | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1752
diff
changeset
|
952 vim_memset(abKeystate, 0, sizeof (abKeystate)); |
7 | 953 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
954 // Clear any pending dead keys |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
955 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); |
7 | 956 |
957 if (uMods & SHIFT_PRESSED) | |
958 abKeystate[VK_SHIFT] = 0x80; | |
959 if (uMods & CAPSLOCK_ON) | |
960 abKeystate[VK_CAPITAL] = 1; | |
961 | |
962 if ((uMods & ALT_GR) == ALT_GR) | |
963 { | |
964 abKeystate[VK_CONTROL] = abKeystate[VK_LCONTROL] = | |
965 abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80; | |
966 } | |
967 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
968 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
|
969 abKeystate, awAnsiCode, 2, 0); |
7 | 970 |
971 if (s_iIsDead > 0) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
972 pker->UChar = (WCHAR) awAnsiCode[0]; |
7 | 973 |
974 return s_iIsDead; | |
975 } | |
976 | |
977 static BOOL g_fJustGotFocus = FALSE; | |
978 | |
979 /* | |
980 * Decode a KEY_EVENT into one or two keystrokes | |
981 */ | |
982 static BOOL | |
983 decode_key_event( | |
984 KEY_EVENT_RECORD *pker, | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
985 WCHAR *pch, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
986 WCHAR *pch2, |
7 | 987 int *pmodifiers, |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
988 BOOL fDoPost UNUSED) |
7 | 989 { |
990 int i; | |
991 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL); | |
992 | |
993 *pch = *pch2 = NUL; | |
994 g_fJustGotFocus = FALSE; | |
995 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
996 // ignore key up events |
7 | 997 if (!pker->bKeyDown) |
998 return FALSE; | |
999 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1000 // ignore some keystrokes |
7 | 1001 switch (pker->wVirtualKeyCode) |
1002 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1003 // modifiers |
7 | 1004 case VK_SHIFT: |
1005 case VK_CONTROL: | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1006 case VK_MENU: // Alt key |
7 | 1007 return FALSE; |
1008 | |
1009 default: | |
1010 break; | |
1011 } | |
1012 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1013 // special cases |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1014 if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL) |
7 | 1015 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1016 // Ctrl-6 is Ctrl-^ |
7 | 1017 if (pker->wVirtualKeyCode == '6') |
1018 { | |
1019 *pch = Ctrl_HAT; | |
1020 return TRUE; | |
1021 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1022 // Ctrl-2 is Ctrl-@ |
7 | 1023 else if (pker->wVirtualKeyCode == '2') |
1024 { | |
1025 *pch = NUL; | |
1026 return TRUE; | |
1027 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1028 // Ctrl-- is Ctrl-_ |
7 | 1029 else if (pker->wVirtualKeyCode == 0xBD) |
1030 { | |
1031 *pch = Ctrl__; | |
1032 return TRUE; | |
1033 } | |
1034 } | |
1035 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1036 // Shift-TAB |
7 | 1037 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) |
1038 { | |
1039 *pch = K_NUL; | |
1040 *pch2 = '\017'; | |
1041 return TRUE; | |
1042 } | |
1043 | |
1044 for (i = sizeof(VirtKeyMap) / sizeof(VirtKeyMap[0]); --i >= 0; ) | |
1045 { | |
1046 if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode) | |
1047 { | |
1048 if (nModifs == 0) | |
1049 *pch = VirtKeyMap[i].chAlone; | |
1050 else if ((nModifs & SHIFT) != 0 && (nModifs & ~SHIFT) == 0) | |
1051 *pch = VirtKeyMap[i].chShift; | |
1052 else if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0) | |
1053 *pch = VirtKeyMap[i].chCtrl; | |
1054 else if ((nModifs & ALT) != 0 && (nModifs & ~ALT) == 0) | |
1055 *pch = VirtKeyMap[i].chAlt; | |
1056 | |
1057 if (*pch != 0) | |
1058 { | |
1059 if (VirtKeyMap[i].fAnsiKey) | |
1060 { | |
1061 *pch2 = *pch; | |
1062 *pch = K_NUL; | |
1063 } | |
1064 | |
1065 return TRUE; | |
1066 } | |
1067 } | |
1068 } | |
1069 | |
1070 i = win32_kbd_patch_key(pker); | |
1071 | |
1072 if (i < 0) | |
1073 *pch = NUL; | |
1074 else | |
1075 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1076 *pch = (i > 0) ? pker->UChar : NUL; |
7 | 1077 |
1078 if (pmodifiers != NULL) | |
1079 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1080 // Pass on the ALT key as a modifier, but only when not combined |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1081 // with CTRL (which is ALTGR). |
7 | 1082 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) |
1083 *pmodifiers |= MOD_MASK_ALT; | |
1084 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1085 // Pass on SHIFT only for special keys, because we don't know when |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1086 // it's already included with the character. |
7 | 1087 if ((nModifs & SHIFT) != 0 && *pch <= 0x20) |
1088 *pmodifiers |= MOD_MASK_SHIFT; | |
1089 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1090 // Pass on CTRL only for non-special keys, because we don't know |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1091 // when it's already included with the character. And not when |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1092 // combined with ALT (which is ALTGR). |
7 | 1093 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 |
1094 && *pch >= 0x20 && *pch < 0x80) | |
1095 *pmodifiers |= MOD_MASK_CTRL; | |
1096 } | |
1097 } | |
1098 | |
1099 return (*pch != NUL); | |
1100 } | |
1101 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1102 #endif // FEAT_GUI_MSWIN |
7 | 1103 |
1104 | |
1105 /* | |
1106 * For the GUI the mouse handling is in gui_w32.c. | |
1107 */ | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1108 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 1109 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
|
1110 mch_setmouse(int on UNUSED) |
7 | 1111 { |
1112 } | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1113 #else |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1114 static int g_fMouseAvail = FALSE; // mouse present |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1115 static int g_fMouseActive = FALSE; // mouse enabled |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1116 static int g_nMouseClick = -1; // mouse status |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1117 static int g_xMouse; // mouse x coordinate |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1118 static int g_yMouse; // mouse y coordinate |
7 | 1119 |
1120 /* | |
1121 * Enable or disable mouse input | |
1122 */ | |
1123 void | |
26 | 1124 mch_setmouse(int on) |
7 | 1125 { |
1126 DWORD cmodein; | |
1127 | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1128 # ifdef VIMDLL |
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
|
1129 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
|
1130 return; |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1131 # endif |
7 | 1132 if (!g_fMouseAvail) |
1133 return; | |
1134 | |
1135 g_fMouseActive = on; | |
1136 GetConsoleMode(g_hConIn, &cmodein); | |
1137 | |
1138 if (g_fMouseActive) | |
1139 cmodein |= ENABLE_MOUSE_INPUT; | |
1140 else | |
1141 cmodein &= ~ENABLE_MOUSE_INPUT; | |
1142 | |
1143 SetConsoleMode(g_hConIn, cmodein); | |
1144 } | |
1145 | |
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
|
1146 |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1147 # if defined(FEAT_BEVAL_TERM) || defined(PROTO) |
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
|
1148 /* |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1149 * 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
|
1150 */ |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1151 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
|
1152 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
|
1153 { |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1154 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
|
1155 } |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1156 # endif |
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
|
1157 |
7 | 1158 /* |
1159 * Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT, | |
1160 * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse | |
1161 * move with a button held down; and MOUSE_RELEASE after a MOUSE_DRAG | |
1162 * or a MOUSE_LEFT, _MIDDLE, or _RIGHT. We encode the button type, | |
1163 * the number of clicks, and the Shift/Ctrl/Alt modifiers in g_nMouseClick, | |
1164 * and we return the mouse position in g_xMouse and g_yMouse. | |
1165 * | |
1166 * Every MOUSE_LEFT, _MIDDLE, or _RIGHT will be followed by zero or more | |
1167 * MOUSE_DRAGs and one MOUSE_RELEASE. MOUSE_RELEASE will be followed only | |
1168 * by MOUSE_LEFT, _MIDDLE, or _RIGHT. | |
1169 * | |
1170 * For multiple clicks, we send, say, MOUSE_LEFT/1 click, MOUSE_RELEASE, | |
1171 * MOUSE_LEFT/2 clicks, MOUSE_RELEASE, MOUSE_LEFT/3 clicks, MOUSE_RELEASE, .... | |
1172 * | |
1173 * Windows will send us MOUSE_MOVED notifications whenever the mouse | |
1174 * moves, even if it stays within the same character cell. We ignore | |
1175 * all MOUSE_MOVED messages if the position hasn't really changed, and | |
1176 * we ignore all MOUSE_MOVED messages where no button is held down (i.e., | |
1177 * we're only interested in MOUSE_DRAG). | |
1178 * | |
1179 * All of this is complicated by the code that fakes MOUSE_MIDDLE on | |
1180 * 2-button mouses by pressing the left & right buttons simultaneously. | |
1181 * In practice, it's almost impossible to click both at the same time, | |
1182 * so we need to delay a little. Also, we tend not to get MOUSE_RELEASE | |
1183 * in such cases, if the user is clicking quickly. | |
1184 */ | |
1185 static BOOL | |
1186 decode_mouse_event( | |
26 | 1187 MOUSE_EVENT_RECORD *pmer) |
7 | 1188 { |
1189 static int s_nOldButton = -1; | |
1190 static int s_nOldMouseClick = -1; | |
1191 static int s_xOldMouse = -1; | |
1192 static int s_yOldMouse = -1; | |
1193 static linenr_T s_old_topline = 0; | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1194 # ifdef FEAT_DIFF |
7 | 1195 static int s_old_topfill = 0; |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1196 # endif |
7 | 1197 static int s_cClicks = 1; |
1198 static BOOL s_fReleased = TRUE; | |
1199 static DWORD s_dwLastClickTime = 0; | |
1200 static BOOL s_fNextIsMiddle = FALSE; | |
1201 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1202 static DWORD cButtons = 0; // number of buttons supported |
7 | 1203 |
1204 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; | |
1205 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; | |
1206 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED; | |
1207 const DWORD LEFT_RIGHT = LEFT | RIGHT; | |
1208 | |
1209 int nButton; | |
1210 | |
1211 if (cButtons == 0 && !GetNumberOfConsoleMouseButtons(&cButtons)) | |
1212 cButtons = 2; | |
1213 | |
1214 if (!g_fMouseAvail || !g_fMouseActive) | |
1215 { | |
1216 g_nMouseClick = -1; | |
1217 return FALSE; | |
1218 } | |
1219 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1220 // get a spurious MOUSE_EVENT immediately after receiving focus; ignore |
7 | 1221 if (g_fJustGotFocus) |
1222 { | |
1223 g_fJustGotFocus = FALSE; | |
1224 return FALSE; | |
1225 } | |
1226 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1227 // unprocessed mouse click? |
7 | 1228 if (g_nMouseClick != -1) |
1229 return TRUE; | |
1230 | |
1231 nButton = -1; | |
1232 g_xMouse = pmer->dwMousePosition.X; | |
1233 g_yMouse = pmer->dwMousePosition.Y; | |
1234 | |
1235 if (pmer->dwEventFlags == MOUSE_MOVED) | |
1236 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1237 // Ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1238 // events even when the mouse moves only within a char cell.) |
7 | 1239 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) |
1240 return FALSE; | |
1241 } | |
1242 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1243 // If no buttons are pressed... |
7 | 1244 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) |
1245 { | |
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
|
1246 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
|
1247 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1248 // If the last thing returned was MOUSE_RELEASE, ignore this |
7 | 1249 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
|
1250 { |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1251 # ifdef FEAT_BEVAL_TERM |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1252 // do return mouse move events when we want them |
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
|
1253 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
|
1254 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
|
1255 else |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1256 # endif |
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
|
1257 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
|
1258 } |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1259 |
7 | 1260 s_fReleased = TRUE; |
1261 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1262 else // one or more buttons pressed |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1263 { |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1264 // on a 2-button mouse, hold down left and right buttons |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1265 // simultaneously to get MIDDLE. |
7 | 1266 |
1267 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) | |
1268 { | |
1269 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); | |
1270 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1271 // if either left or right button only is pressed, see if the |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1272 // next mouse event has both of them pressed |
7 | 1273 if (dwLR == LEFT || dwLR == RIGHT) |
1274 { | |
1275 for (;;) | |
1276 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1277 // wait a short time for next input event |
7 | 1278 if (WaitForSingleObject(g_hConIn, p_mouset / 3) |
1279 != WAIT_OBJECT_0) | |
1280 break; | |
1281 else | |
1282 { | |
1283 DWORD cRecords = 0; | |
1284 INPUT_RECORD ir; | |
1285 MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent; | |
1286 | |
5580 | 1287 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1288 |
1289 if (cRecords == 0 || ir.EventType != MOUSE_EVENT | |
1290 || !(pmer2->dwButtonState & LEFT_RIGHT)) | |
1291 break; | |
1292 else | |
1293 { | |
1294 if (pmer2->dwEventFlags != MOUSE_MOVED) | |
1295 { | |
5580 | 1296 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1297 |
1298 return decode_mouse_event(pmer2); | |
1299 } | |
1300 else if (s_xOldMouse == pmer2->dwMousePosition.X && | |
1301 s_yOldMouse == pmer2->dwMousePosition.Y) | |
1302 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1303 // throw away spurious mouse move |
5580 | 1304 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1305 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1306 // are there any more mouse events in queue? |
5580 | 1307 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1308 |
1309 if (cRecords==0 || ir.EventType != MOUSE_EVENT) | |
1310 break; | |
1311 } | |
1312 else | |
1313 break; | |
1314 } | |
1315 } | |
1316 } | |
1317 } | |
1318 } | |
1319 | |
1320 if (s_fNextIsMiddle) | |
1321 { | |
1322 nButton = (pmer->dwEventFlags == MOUSE_MOVED) | |
1323 ? MOUSE_DRAG : MOUSE_MIDDLE; | |
1324 s_fNextIsMiddle = FALSE; | |
1325 } | |
1326 else if (cButtons == 2 && | |
1327 ((pmer->dwButtonState & LEFT_RIGHT) == LEFT_RIGHT)) | |
1328 { | |
1329 nButton = MOUSE_MIDDLE; | |
1330 | |
1331 if (! s_fReleased && pmer->dwEventFlags != MOUSE_MOVED) | |
1332 { | |
1333 s_fNextIsMiddle = TRUE; | |
1334 nButton = MOUSE_RELEASE; | |
1335 } | |
1336 } | |
1337 else if ((pmer->dwButtonState & LEFT) == LEFT) | |
1338 nButton = MOUSE_LEFT; | |
1339 else if ((pmer->dwButtonState & MIDDLE) == MIDDLE) | |
1340 nButton = MOUSE_MIDDLE; | |
1341 else if ((pmer->dwButtonState & RIGHT) == RIGHT) | |
1342 nButton = MOUSE_RIGHT; | |
1343 | |
1344 if (! s_fReleased && ! s_fNextIsMiddle | |
1345 && nButton != s_nOldButton && s_nOldButton != MOUSE_DRAG) | |
1346 return FALSE; | |
1347 | |
1348 s_fReleased = s_fNextIsMiddle; | |
1349 } | |
1350 | |
1351 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) | |
1352 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1353 // button pressed or released, without mouse moving |
7 | 1354 if (nButton != -1 && nButton != MOUSE_RELEASE) |
1355 { | |
1356 DWORD dwCurrentTime = GetTickCount(); | |
1357 | |
1358 if (s_xOldMouse != g_xMouse | |
1359 || s_yOldMouse != g_yMouse | |
1360 || s_nOldButton != nButton | |
1361 || s_old_topline != curwin->w_topline | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1362 # ifdef FEAT_DIFF |
7 | 1363 || s_old_topfill != curwin->w_topfill |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1364 # endif |
7 | 1365 || (int)(dwCurrentTime - s_dwLastClickTime) > p_mouset) |
1366 { | |
1367 s_cClicks = 1; | |
1368 } | |
1369 else if (++s_cClicks > 4) | |
1370 { | |
1371 s_cClicks = 1; | |
1372 } | |
1373 | |
1374 s_dwLastClickTime = dwCurrentTime; | |
1375 } | |
1376 } | |
1377 else if (pmer->dwEventFlags == MOUSE_MOVED) | |
1378 { | |
1379 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1380 nButton = MOUSE_DRAG; | |
1381 | |
1382 s_cClicks = 1; | |
1383 } | |
1384 | |
1385 if (nButton == -1) | |
1386 return FALSE; | |
1387 | |
1388 if (nButton != MOUSE_RELEASE) | |
1389 s_nOldButton = nButton; | |
1390 | |
1391 g_nMouseClick = nButton; | |
1392 | |
1393 if (pmer->dwControlKeyState & SHIFT_PRESSED) | |
1394 g_nMouseClick |= MOUSE_SHIFT; | |
1395 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) | |
1396 g_nMouseClick |= MOUSE_CTRL; | |
1397 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) | |
1398 g_nMouseClick |= MOUSE_ALT; | |
1399 | |
1400 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) | |
1401 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); | |
1402 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1403 // only pass on interesting (i.e., different) mouse events |
7 | 1404 if (s_xOldMouse == g_xMouse |
1405 && s_yOldMouse == g_yMouse | |
1406 && s_nOldMouseClick == g_nMouseClick) | |
1407 { | |
1408 g_nMouseClick = -1; | |
1409 return FALSE; | |
1410 } | |
1411 | |
1412 s_xOldMouse = g_xMouse; | |
1413 s_yOldMouse = g_yMouse; | |
1414 s_old_topline = curwin->w_topline; | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1415 # ifdef FEAT_DIFF |
7 | 1416 s_old_topfill = curwin->w_topfill; |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1417 # endif |
7 | 1418 s_nOldMouseClick = g_nMouseClick; |
1419 | |
1420 return TRUE; | |
1421 } | |
1422 | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1423 #endif // FEAT_GUI_MSWIN |
7 | 1424 |
1425 | |
1426 #ifdef MCH_CURSOR_SHAPE | |
1427 /* | |
1428 * Set the shape of the cursor. | |
1429 * 'thickness' can be from 1 (thin) to 99 (block) | |
1430 */ | |
1431 static void | |
1432 mch_set_cursor_shape(int thickness) | |
1433 { | |
1434 CONSOLE_CURSOR_INFO ConsoleCursorInfo; | |
1435 ConsoleCursorInfo.dwSize = thickness; | |
1436 ConsoleCursorInfo.bVisible = s_cursor_visible; | |
1437 | |
1438 SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo); | |
1439 if (s_cursor_visible) | |
1440 SetConsoleCursorPosition(g_hConOut, g_coord); | |
1441 } | |
1442 | |
1443 void | |
1444 mch_update_cursor(void) | |
1445 { | |
1446 int idx; | |
1447 int thickness; | |
1448 | |
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
|
1449 # 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
|
1450 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
|
1451 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
|
1452 # 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
|
1453 |
7 | 1454 /* |
1455 * How the cursor is drawn depends on the current mode. | |
1456 */ | |
1457 idx = get_shape_idx(FALSE); | |
1458 | |
1459 if (shape_table[idx].shape == SHAPE_BLOCK) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1460 thickness = 99; // 100 doesn't work on W95 |
7 | 1461 else |
1462 thickness = shape_table[idx].percentage; | |
1463 mch_set_cursor_shape(thickness); | |
1464 } | |
1465 #endif | |
1466 | |
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
|
1467 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 1468 /* |
1469 * Handle FOCUS_EVENT. | |
1470 */ | |
1471 static void | |
1472 handle_focus_event(INPUT_RECORD ir) | |
1473 { | |
1474 g_fJustGotFocus = ir.Event.FocusEvent.bSetFocus; | |
1475 ui_focus_change((int)g_fJustGotFocus); | |
1476 } | |
1477 | |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1478 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
|
1479 |
7 | 1480 /* |
1481 * Wait until console input from keyboard or mouse is available, | |
1482 * 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
|
1483 * When "ignore_input" is TRUE even wait when input is available. |
7 | 1484 * Return TRUE if something is available FALSE if not. |
1485 */ | |
1486 static int | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1487 WaitForChar(long msec, int ignore_input) |
7 | 1488 { |
1489 DWORD dwNow = 0, dwEndTime = 0; | |
1490 INPUT_RECORD ir; | |
1491 DWORD cRecords; | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1492 WCHAR ch, ch2; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1493 # ifdef FEAT_TIMERS |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1494 int tb_change_cnt = typebuf.tb_change_cnt; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1495 # endif |
7 | 1496 |
1497 if (msec > 0) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1498 // Wait until the specified time has elapsed. |
7 | 1499 dwEndTime = GetTickCount() + msec; |
1500 else if (msec < 0) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1501 // Wait forever. |
7 | 1502 dwEndTime = INFINITE; |
1503 | |
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
|
1504 // 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
|
1505 // we might get multiple unusable mouse events in that time. |
7 | 1506 for (;;) |
1507 { | |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1508 // 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
|
1509 if (msec != 0) |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1510 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1511 # 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
|
1512 parse_queued_messages(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1513 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1514 # 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
|
1515 mzvim_check_threads(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1516 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1517 # 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
|
1518 serverProcessPendingMessages(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1519 # endif |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1520 } |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1521 |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1522 if (g_nMouseClick != -1 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1523 # ifdef FEAT_CLIENTSERVER |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1524 || (!ignore_input && input_available()) |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1525 # endif |
7 | 1526 ) |
1527 return TRUE; | |
1528 | |
1529 if (msec > 0) | |
1530 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1531 // If the specified wait time has passed, return. Beware that |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1532 // GetTickCount() may wrap around (overflow). |
7 | 1533 dwNow = GetTickCount(); |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1534 if ((int)(dwNow - dwEndTime) >= 0) |
7 | 1535 break; |
1536 } | |
1537 if (msec != 0) | |
1538 { | |
14 | 1539 DWORD dwWaitTime = dwEndTime - dwNow; |
1540 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1541 # ifdef FEAT_JOB_CHANNEL |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1542 // 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
|
1543 if (dwWaitTime > 100) |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1544 { |
8222
4f0677020a43
commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents:
8176
diff
changeset
|
1545 dwWaitTime = 100; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1546 // If there is readahead then parse_queued_messages() timed out |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1547 // and we should call it again soon. |
10418
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1548 if (channel_any_readahead()) |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1549 dwWaitTime = 10; |
56cb9538386c
commit https://github.com/vim/vim/commit/8a8199e4a1814b10630a770165502abb1121cd1b
Christian Brabandt <cb@256bit.org>
parents:
10406
diff
changeset
|
1550 } |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1551 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1552 # ifdef FEAT_BEVAL_GUI |
11014
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1553 if (p_beval && dwWaitTime > 100) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1554 // The 'balloonexpr' may indirectly invoke a callback while |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1555 // waiting for a character, need to check often. |
11014
fb2bcfa6a8de
patch 8.0.0396: 'balloonexpr' only works synchronously
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1556 dwWaitTime = 100; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1557 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1558 # ifdef FEAT_MZSCHEME |
14 | 1559 if (mzthreads_allowed() && p_mzq > 0 |
1560 && (msec < 0 || (long)dwWaitTime > p_mzq)) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1561 dwWaitTime = p_mzq; // don't wait longer than 'mzquantum' |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1562 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1563 # ifdef FEAT_TIMERS |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1564 // 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
|
1565 if (dwWaitTime > 10) |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1566 { |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1567 long due_time; |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1568 |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1569 // 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
|
1570 // 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
|
1571 due_time = check_due_timer(); |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1572 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
|
1573 { |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1574 // timer may have used feedkeys(). |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1575 return FALSE; |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1576 } |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1577 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
|
1578 dwWaitTime = due_time; |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1579 } |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1580 # endif |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1581 if ( |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1582 # ifdef FEAT_CLIENTSERVER |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1583 // 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
|
1584 // 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
|
1585 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
|
1586 dwWaitTime, QS_SENDMESSAGE) != WAIT_OBJECT_0 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1587 # else |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1588 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
|
1589 != WAIT_OBJECT_0 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1590 # endif |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1591 ) |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1592 continue; |
7 | 1593 } |
1594 | |
1595 cRecords = 0; | |
5580 | 1596 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1597 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1598 # ifdef FEAT_MBYTE_IME |
7 | 1599 if (State & CMDLINE && msg_row == Rows - 1) |
1600 { | |
1601 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
1602 | |
1603 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
1604 { | |
1605 if (csbi.dwCursorPosition.Y != msg_row) | |
1606 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1607 // The screen is now messed up, must redraw the |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1608 // command line and later all the windows. |
7 | 1609 redraw_all_later(CLEAR); |
1610 cmdline_row -= (msg_row - csbi.dwCursorPosition.Y); | |
1611 redrawcmd(); | |
1612 } | |
1613 } | |
1614 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1615 # endif |
7 | 1616 |
1617 if (cRecords > 0) | |
1618 { | |
1619 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) | |
1620 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1621 # ifdef FEAT_MBYTE_IME |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1622 // Windows IME sends two '\n's with only one 'ENTER'. First: |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1623 // wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1624 if (ir.Event.KeyEvent.UChar == 0 |
7 | 1625 && ir.Event.KeyEvent.wVirtualKeyCode == 13) |
1626 { | |
5580 | 1627 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1628 continue; |
1629 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1630 # endif |
7 | 1631 if (decode_key_event(&ir.Event.KeyEvent, &ch, &ch2, |
1632 NULL, FALSE)) | |
1633 return TRUE; | |
1634 } | |
1635 | |
5580 | 1636 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1637 |
1638 if (ir.EventType == FOCUS_EVENT) | |
1639 handle_focus_event(ir); | |
1640 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
|
1641 { |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1642 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
|
1643 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1644 // Only call shell_resized() when the size actually change to |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1645 // avoid the screen is cleared. |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1646 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
|
1647 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1648 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
|
1649 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
|
1650 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
|
1651 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
|
1652 shell_resized(); |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1653 } |
13260
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1654 } |
7 | 1655 else if (ir.EventType == MOUSE_EVENT |
1656 && decode_mouse_event(&ir.Event.MouseEvent)) | |
1657 return TRUE; | |
1658 } | |
1659 else if (msec == 0) | |
1660 break; | |
1661 } | |
1662 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1663 # ifdef FEAT_CLIENTSERVER |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1664 // Something might have been received while we were waiting. |
7 | 1665 if (input_available()) |
1666 return TRUE; | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1667 # endif |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1668 |
7 | 1669 return FALSE; |
1670 } | |
1671 | |
1672 /* | |
1673 * return non-zero if a character is available | |
1674 */ | |
1675 int | |
26 | 1676 mch_char_avail(void) |
7 | 1677 { |
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
|
1678 # 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
|
1679 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
|
1680 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
|
1681 # endif |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1682 return WaitForChar(0L, FALSE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1683 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1684 |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1685 # 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
|
1686 /* |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1687 * 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
|
1688 */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1689 int |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1690 mch_check_messages(void) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1691 { |
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
|
1692 # 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
|
1693 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
|
1694 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
|
1695 # endif |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1696 return WaitForChar(0L, TRUE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1697 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1698 # endif |
7 | 1699 |
1700 /* | |
1701 * Create the console input. Used when reading stdin doesn't work. | |
1702 */ | |
1703 static void | |
1704 create_conin(void) | |
1705 { | |
1706 g_hConIn = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE, | |
1707 FILE_SHARE_READ|FILE_SHARE_WRITE, | |
1708 (LPSECURITY_ATTRIBUTES) NULL, | |
840 | 1709 OPEN_EXISTING, 0, (HANDLE)NULL); |
7 | 1710 did_create_conin = TRUE; |
1711 } | |
1712 | |
1713 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1714 * Get a keystroke or a mouse event, use a blocking wait. |
7 | 1715 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1716 static WCHAR |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1717 tgetch(int *pmodifiers, WCHAR *pch2) |
7 | 1718 { |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1719 WCHAR ch; |
7 | 1720 |
1721 for (;;) | |
1722 { | |
1723 INPUT_RECORD ir; | |
1724 DWORD cRecords = 0; | |
1725 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1726 # ifdef FEAT_CLIENTSERVER |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1727 (void)WaitForChar(-1L, FALSE); |
7 | 1728 if (input_available()) |
1729 return 0; | |
1730 if (g_nMouseClick != -1) | |
1731 return 0; | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1732 # endif |
5580 | 1733 if (read_console_input(g_hConIn, &ir, 1, &cRecords) == 0) |
7 | 1734 { |
1735 if (did_create_conin) | |
1736 read_error_exit(); | |
1737 create_conin(); | |
1738 continue; | |
1739 } | |
1740 | |
1741 if (ir.EventType == KEY_EVENT) | |
1742 { | |
1743 if (decode_key_event(&ir.Event.KeyEvent, &ch, pch2, | |
1744 pmodifiers, TRUE)) | |
1745 return ch; | |
1746 } | |
1747 else if (ir.EventType == FOCUS_EVENT) | |
1748 handle_focus_event(ir); | |
1749 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) | |
1750 shell_resized(); | |
1751 else if (ir.EventType == MOUSE_EVENT) | |
1752 { | |
1753 if (decode_mouse_event(&ir.Event.MouseEvent)) | |
1754 return 0; | |
1755 } | |
1756 } | |
1757 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1758 #endif // !FEAT_GUI_MSWIN |
7 | 1759 |
1760 | |
1761 /* | |
3622 | 1762 * mch_inchar(): low-level input function. |
7 | 1763 * Get one or more characters from the keyboard or the mouse. |
1764 * If time == 0, do not wait for characters. | |
1765 * If time == n, wait a short time for characters. | |
1766 * If time == -1, wait forever for characters. | |
1767 * Returns the number of characters read into buf. | |
1768 */ | |
1769 int | |
1770 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
|
1771 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
|
1772 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
|
1773 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
|
1774 int tb_change_cnt UNUSED) |
7 | 1775 { |
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
|
1776 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 1777 |
1778 int len; | |
1779 int c; | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1780 # define TYPEAHEADLEN 20 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1781 static char_u typeahead[TYPEAHEADLEN]; // previously typed bytes. |
7 | 1782 static int typeaheadlen = 0; |
1783 | |
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
|
1784 # 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
|
1785 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
|
1786 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
|
1787 # 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
|
1788 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1789 // First use any typeahead that was kept because "buf" was too small. |
7 | 1790 if (typeaheadlen > 0) |
1791 goto theend; | |
1792 | |
1793 if (time >= 0) | |
1794 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1795 if (!WaitForChar(time, FALSE)) // no character available |
7 | 1796 return 0; |
1797 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1798 else // time == -1, wait forever |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1799 { |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1800 mch_set_winsize_now(); // Allow winsize changes from now on |
7 | 1801 |
203 | 1802 /* |
1803 * If there is no character available within 2 seconds (default) | |
1804 * write the autoscript file to disk. Or cause the CursorHold event | |
1805 * to be triggered. | |
1806 */ | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1807 if (!WaitForChar(p_ut, FALSE)) |
7 | 1808 { |
609 | 1809 if (trigger_cursorhold() && maxlen >= 3) |
7 | 1810 { |
203 | 1811 buf[0] = K_SPECIAL; |
1812 buf[1] = KS_EXTRA; | |
1813 buf[2] = (int)KE_CURSORHOLD; | |
1814 return 3; | |
7 | 1815 } |
368 | 1816 before_blocking(); |
7 | 1817 } |
1818 } | |
1819 | |
1820 /* | |
1821 * Try to read as many characters as there are, until the buffer is full. | |
1822 */ | |
1823 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1824 // we will get at least one key. Get more if they are available. |
7 | 1825 g_fCBrkPressed = FALSE; |
1826 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1827 # ifdef MCH_WRITE_DUMP |
7 | 1828 if (fdDump) |
1829 fputc('[', fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1830 # endif |
7 | 1831 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1832 // Keep looping until there is something in the typeahead buffer and more |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1833 // to get and still room in the buffer (up to two bytes for a char and |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1834 // 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
|
1835 while ((typeaheadlen == 0 || WaitForChar(0L, FALSE)) |
7 | 1836 && typeaheadlen + 5 <= TYPEAHEADLEN) |
1837 { | |
1838 if (typebuf_changed(tb_change_cnt)) | |
1839 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1840 // "buf" may be invalid now if a client put something in the |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1841 // typeahead buffer and "buf" is in the typeahead buffer. |
7 | 1842 typeaheadlen = 0; |
1843 break; | |
1844 } | |
1845 if (g_nMouseClick != -1) | |
1846 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1847 # ifdef MCH_WRITE_DUMP |
7 | 1848 if (fdDump) |
1849 fprintf(fdDump, "{%02x @ %d, %d}", | |
1850 g_nMouseClick, g_xMouse, g_yMouse); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1851 # endif |
7 | 1852 typeahead[typeaheadlen++] = ESC + 128; |
1853 typeahead[typeaheadlen++] = 'M'; | |
1854 typeahead[typeaheadlen++] = g_nMouseClick; | |
1855 typeahead[typeaheadlen++] = g_xMouse + '!'; | |
1856 typeahead[typeaheadlen++] = g_yMouse + '!'; | |
1857 g_nMouseClick = -1; | |
1858 } | |
1859 else | |
1860 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1861 WCHAR ch2 = NUL; |
7 | 1862 int modifiers = 0; |
1863 | |
1864 c = tgetch(&modifiers, &ch2); | |
1865 | |
1866 if (typebuf_changed(tb_change_cnt)) | |
1867 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1868 // "buf" may be invalid now if a client put something in the |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1869 // typeahead buffer and "buf" is in the typeahead buffer. |
7 | 1870 typeaheadlen = 0; |
1871 break; | |
1872 } | |
1873 | |
1874 if (c == Ctrl_C && ctrl_c_interrupts) | |
1875 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1876 # if defined(FEAT_CLIENTSERVER) |
7 | 1877 trash_input_buf(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1878 # endif |
7 | 1879 got_int = TRUE; |
1880 } | |
1881 | |
1882 if (g_nMouseClick == -1) | |
1883 { | |
1884 int n = 1; | |
6047 | 1885 |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1886 if (ch2 == NUL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1887 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1888 int i; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1889 char_u *p; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1890 WCHAR ch[2]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1891 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1892 ch[0] = c; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1893 if (c >= 0xD800 && c <= 0xDBFF) // High surrogate |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1894 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1895 ch[1] = tgetch(&modifiers, &ch2); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1896 n++; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1897 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1898 p = utf16_to_enc(ch, &n); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1899 if (p != NULL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1900 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1901 for (i = 0; i < n; i++) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1902 typeahead[typeaheadlen + i] = p[i]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1903 vim_free(p); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1904 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1905 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1906 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1907 typeahead[typeaheadlen] = c; |
7 | 1908 if (ch2 != NUL) |
1909 { | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1910 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
|
1911 { |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1912 switch (ch2) |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1913 { |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1914 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
|
1915 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
|
1916 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
|
1917 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
|
1918 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
|
1919 n++; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1920 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1921 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1922 default: |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1923 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
|
1924 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
|
1925 n += 2; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1926 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
1927 } |
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
|
1928 } |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1929 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
|
1930 { |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
1931 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
|
1932 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
|
1933 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
|
1934 } |
6047 | 1935 } |
1936 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1937 // Use the ALT key to set the 8th bit of the character |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1938 // when it's one byte, the 8th bit isn't set yet and not |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1939 // using a double-byte encoding (would become a lead |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1940 // byte). |
7 | 1941 if ((modifiers & MOD_MASK_ALT) |
1942 && n == 1 | |
1943 && (typeahead[typeaheadlen] & 0x80) == 0 | |
1944 && !enc_dbcs | |
1945 ) | |
1946 { | |
1443 | 1947 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80, |
1948 typeahead + typeaheadlen); | |
7 | 1949 modifiers &= ~MOD_MASK_ALT; |
1950 } | |
1951 | |
1952 if (modifiers != 0) | |
1953 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1954 // Prepend modifiers to the character. |
7 | 1955 mch_memmove(typeahead + typeaheadlen + 3, |
1956 typeahead + typeaheadlen, n); | |
1957 typeahead[typeaheadlen++] = K_SPECIAL; | |
1958 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER; | |
1959 typeahead[typeaheadlen++] = modifiers; | |
1960 } | |
1961 | |
1962 typeaheadlen += n; | |
1963 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1964 # ifdef MCH_WRITE_DUMP |
7 | 1965 if (fdDump) |
1966 fputc(c, fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1967 # endif |
7 | 1968 } |
1969 } | |
1970 } | |
1971 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1972 # ifdef MCH_WRITE_DUMP |
7 | 1973 if (fdDump) |
1974 { | |
1975 fputs("]\n", fdDump); | |
1976 fflush(fdDump); | |
1977 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1978 # endif |
7 | 1979 |
1980 theend: | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1981 // Move typeahead to "buf", as much as fits. |
7 | 1982 len = 0; |
1983 while (len < maxlen && typeaheadlen > 0) | |
1984 { | |
1985 buf[len++] = typeahead[0]; | |
1986 mch_memmove(typeahead, typeahead + 1, --typeaheadlen); | |
1987 } | |
1988 return len; | |
1989 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1990 #else // FEAT_GUI_MSWIN |
7 | 1991 return 0; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1992 #endif // FEAT_GUI_MSWIN |
7 | 1993 } |
1994 | |
3927 | 1995 #ifndef PROTO |
1996 # ifndef __MINGW32__ | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1997 # include <shellapi.h> // required for FindExecutable() |
3927 | 1998 # endif |
7 | 1999 #endif |
2000 | |
9 | 2001 /* |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2002 * 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
|
2003 * 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
|
2004 * 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
|
2005 * the allocated memory. |
10 | 2006 * TODO: Should somehow check if it's really executable. |
9 | 2007 */ |
7 | 2008 static int |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2009 executable_exists(char *name, char_u **path, int use_path) |
7 | 2010 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2011 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
|
2012 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
|
2013 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
|
2014 WCHAR *wcurpath, *wnewpath; |
6185 | 2015 long n; |
9 | 2016 |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2017 if (!use_path) |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2018 { |
11071
cc22b177dfe8
patch 8.0.0424: compiler warnings on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11060
diff
changeset
|
2019 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
|
2020 { |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2021 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
|
2022 { |
11071
cc22b177dfe8
patch 8.0.0424: compiler warnings on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11060
diff
changeset
|
2023 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
|
2024 *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
|
2025 else |
354593196e20
patch 8.0.0419: test for v:progpath fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11054
diff
changeset
|
2026 *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
|
2027 } |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2028 return TRUE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2029 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2030 return FALSE; |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2031 } |
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2032 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2033 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
|
2034 if (p == NULL) |
6185 | 2035 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
|
2036 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2037 wcurpath = _wgetenv(L"PATH"); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2038 wnewpath = ALLOC_MULT(WCHAR, wcslen(wcurpath) + 3); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2039 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
|
2040 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
|
2041 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
|
2042 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
|
2043 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
|
2044 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
|
2045 vim_free(p); |
6185 | 2046 if (n == 0) |
9 | 2047 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
|
2048 if (GetFileAttributesW(fnamew) & FILE_ATTRIBUTE_DIRECTORY) |
9 | 2049 return FALSE; |
5782 | 2050 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
|
2051 *path = utf16_to_enc(fnamew, NULL); |
9 | 2052 return TRUE; |
7 | 2053 } |
2054 | |
15955
907481b9260f
patch 8.1.0983: checking __CYGWIN32__ unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2055 #if (defined(__MINGW32__) && __MSVCRT_VERSION__ >= 0x800) || \ |
907481b9260f
patch 8.1.0983: checking __CYGWIN32__ unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2056 (defined(_MSC_VER) && _MSC_VER >= 1400) |
2584 | 2057 /* |
2058 * Bad parameter handler. | |
2059 * | |
2060 * Certain MS CRT functions will intentionally crash when passed invalid | |
2061 * parameters to highlight possible security holes. Setting this function as | |
2062 * the bad parameter handler will prevent the crash. | |
2063 * | |
2064 * In debug builds the parameters contain CRT information that might help track | |
2065 * down the source of a problem, but in non-debug builds the arguments are all | |
2066 * NULL/0. Debug builds will also produce assert dialogs from the CRT, it is | |
2067 * worth allowing these to make debugging of issues easier. | |
2068 */ | |
2069 static void | |
2070 bad_param_handler(const wchar_t *expression, | |
2071 const wchar_t *function, | |
2072 const wchar_t *file, | |
2073 unsigned int line, | |
2074 uintptr_t pReserved) | |
2075 { | |
2076 } | |
2077 | |
2078 # define SET_INVALID_PARAM_HANDLER \ | |
2079 ((void)_set_invalid_parameter_handler(bad_param_handler)) | |
2080 #else | |
2081 # define SET_INVALID_PARAM_HANDLER | |
2082 #endif | |
2083 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
2084 #ifdef FEAT_GUI_MSWIN |
7 | 2085 |
2086 /* | |
2087 * GUI version of mch_init(). | |
2088 */ | |
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
|
2089 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
|
2090 mch_init_g(void) |
7 | 2091 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2092 # ifndef __MINGW32__ |
7 | 2093 extern int _fmode; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2094 # endif |
7 | 2095 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2096 // Silently handle invalid parameters to CRT functions |
2584 | 2097 SET_INVALID_PARAM_HANDLER; |
2098 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2099 // Let critical errors result in a failure, not in a dialog box. Required |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2100 // for the timestamp test to work on removed floppies. |
7 | 2101 SetErrorMode(SEM_FAILCRITICALERRORS); |
2102 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2103 _fmode = O_BINARY; // we do our own CR-LF translation |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2104 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2105 // Specify window size. Is there a place to get the default from? |
7 | 2106 Rows = 25; |
2107 Columns = 80; | |
2108 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2109 // Look for 'vimrun' |
7 | 2110 { |
2111 char_u vimrun_location[_MAX_PATH + 4]; | |
2112 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2113 // First try in same directory as gvim.exe |
7 | 2114 STRCPY(vimrun_location, exe_name); |
2115 STRCPY(gettail(vimrun_location), "vimrun.exe"); | |
2116 if (mch_getperm(vimrun_location) >= 0) | |
2117 { | |
2118 if (*skiptowhite(vimrun_location) != NUL) | |
2119 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2120 // Enclose path with white space in double quotes. |
7 | 2121 mch_memmove(vimrun_location + 1, vimrun_location, |
2122 STRLEN(vimrun_location) + 1); | |
2123 *vimrun_location = '"'; | |
2124 STRCPY(gettail(vimrun_location), "vimrun\" "); | |
2125 } | |
2126 else | |
2127 STRCPY(gettail(vimrun_location), "vimrun "); | |
2128 | |
2129 vimrun_path = (char *)vim_strsave(vimrun_location); | |
2130 s_dont_use_vimrun = FALSE; | |
2131 } | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2132 else if (executable_exists("vimrun.exe", NULL, TRUE)) |
7 | 2133 s_dont_use_vimrun = FALSE; |
2134 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2135 // Don't give the warning for a missing vimrun.exe right now, but only |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2136 // when vimrun was supposed to be used. Don't bother people that do |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2137 // not need vimrun.exe. |
7 | 2138 if (s_dont_use_vimrun) |
2139 need_vimrun_warning = TRUE; | |
2140 } | |
2141 | |
2142 /* | |
2143 * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'. | |
2144 * Otherwise the default "findstr /n" is used. | |
2145 */ | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2146 if (!executable_exists("findstr.exe", NULL, TRUE)) |
7 | 2147 set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0); |
2148 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2149 # ifdef FEAT_CLIPBOARD |
4168 | 2150 win_clip_init(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2151 # 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
|
2152 |
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
|
2153 vtp_flag_init(); |
7 | 2154 } |
2155 | |
2156 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2157 #endif // 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
|
2158 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2159 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 2160 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2161 # define SRWIDTH(sr) ((sr).Right - (sr).Left + 1) |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2162 # define SRHEIGHT(sr) ((sr).Bottom - (sr).Top + 1) |
7 | 2163 |
2164 /* | |
2165 * ClearConsoleBuffer() | |
2166 * Description: | |
2167 * Clears the entire contents of the console screen buffer, using the | |
2168 * specified attribute. | |
2169 * Returns: | |
2170 * TRUE on success | |
2171 */ | |
2172 static BOOL | |
2173 ClearConsoleBuffer(WORD wAttribute) | |
2174 { | |
2175 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2176 COORD coord; | |
2177 DWORD NumCells, dummy; | |
2178 | |
2179 if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2180 return FALSE; | |
2181 | |
2182 NumCells = csbi.dwSize.X * csbi.dwSize.Y; | |
2183 coord.X = 0; | |
2184 coord.Y = 0; | |
2185 if (!FillConsoleOutputCharacter(g_hConOut, ' ', NumCells, | |
2186 coord, &dummy)) | |
2187 return FALSE; | |
2188 if (!FillConsoleOutputAttribute(g_hConOut, wAttribute, NumCells, | |
2189 coord, &dummy)) | |
2190 return FALSE; | |
2191 | |
2192 return TRUE; | |
2193 } | |
2194 | |
2195 /* | |
2196 * FitConsoleWindow() | |
2197 * Description: | |
2198 * Checks if the console window will fit within given buffer dimensions. | |
2199 * Also, if requested, will shrink the window to fit. | |
2200 * Returns: | |
2201 * TRUE on success | |
2202 */ | |
2203 static BOOL | |
2204 FitConsoleWindow( | |
2205 COORD dwBufferSize, | |
2206 BOOL WantAdjust) | |
2207 { | |
2208 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2209 COORD dwWindowSize; | |
2210 BOOL NeedAdjust = FALSE; | |
2211 | |
2212 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2213 { | |
2214 /* | |
2215 * A buffer resize will fail if the current console window does | |
2216 * not lie completely within that buffer. To avoid this, we might | |
2217 * have to move and possibly shrink the window. | |
2218 */ | |
2219 if (csbi.srWindow.Right >= dwBufferSize.X) | |
2220 { | |
2221 dwWindowSize.X = SRWIDTH(csbi.srWindow); | |
2222 if (dwWindowSize.X > dwBufferSize.X) | |
2223 dwWindowSize.X = dwBufferSize.X; | |
2224 csbi.srWindow.Right = dwBufferSize.X - 1; | |
2225 csbi.srWindow.Left = dwBufferSize.X - dwWindowSize.X; | |
2226 NeedAdjust = TRUE; | |
2227 } | |
2228 if (csbi.srWindow.Bottom >= dwBufferSize.Y) | |
2229 { | |
2230 dwWindowSize.Y = SRHEIGHT(csbi.srWindow); | |
2231 if (dwWindowSize.Y > dwBufferSize.Y) | |
2232 dwWindowSize.Y = dwBufferSize.Y; | |
2233 csbi.srWindow.Bottom = dwBufferSize.Y - 1; | |
2234 csbi.srWindow.Top = dwBufferSize.Y - dwWindowSize.Y; | |
2235 NeedAdjust = TRUE; | |
2236 } | |
2237 if (NeedAdjust && WantAdjust) | |
2238 { | |
2239 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &csbi.srWindow)) | |
2240 return FALSE; | |
2241 } | |
2242 return TRUE; | |
2243 } | |
2244 | |
2245 return FALSE; | |
2246 } | |
2247 | |
2248 typedef struct ConsoleBufferStruct | |
2249 { | |
26 | 2250 BOOL IsValid; |
2251 CONSOLE_SCREEN_BUFFER_INFO Info; | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2252 PCHAR_INFO Buffer; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2253 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
|
2254 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
|
2255 int NumRegions; |
7 | 2256 } ConsoleBuffer; |
2257 | |
2258 /* | |
2259 * SaveConsoleBuffer() | |
2260 * Description: | |
2261 * Saves important information about the console buffer, including the | |
2262 * actual buffer contents. The saved information is suitable for later | |
2263 * restoration by RestoreConsoleBuffer(). | |
2264 * Returns: | |
2265 * TRUE if all information was saved; FALSE otherwise | |
2266 * If FALSE, still sets cb->IsValid if buffer characteristics were saved. | |
2267 */ | |
2268 static BOOL | |
2269 SaveConsoleBuffer( | |
2270 ConsoleBuffer *cb) | |
2271 { | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2272 DWORD NumCells; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2273 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2274 SMALL_RECT ReadRegion; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2275 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
|
2276 int i, numregions; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2277 |
7 | 2278 if (cb == NULL) |
2279 return FALSE; | |
2280 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2281 if (!GetConsoleScreenBufferInfo(g_hConOut, &cb->Info)) |
7 | 2282 { |
2283 cb->IsValid = FALSE; | |
2284 return FALSE; | |
2285 } | |
2286 cb->IsValid = TRUE; | |
2287 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2288 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2289 * 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
|
2290 * 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
|
2291 * 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
|
2292 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2293 if (!cb->IsValid || cb->Buffer == NULL || |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2294 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
|
2295 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
|
2296 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2297 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
|
2298 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
|
2299 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
|
2300 vim_free(cb->Buffer); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2301 cb->Buffer = ALLOC_MULT(CHAR_INFO, NumCells); |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2302 if (cb->Buffer == NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2303 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2304 } |
7 | 2305 |
2306 /* | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2307 * 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
|
2308 * 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
|
2309 * 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
|
2310 * 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
|
2311 * 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
|
2312 * 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
|
2313 * height of each chunk will be (12000 / width). |
7 | 2314 */ |
7078
383d6f39669b
commit https://github.com/vim/vim/commit/615942452eb74eee7d8386fd3d76a1534181fa06
Christian Brabandt <cb@256bit.org>
parents:
6981
diff
changeset
|
2315 BufferCoord.X = 0; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2316 ReadRegion.Left = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2317 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
|
2318 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
|
2319 |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2320 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
|
2321 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
|
2322 { |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2323 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
|
2324 vim_free(cb->Regions); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2325 cb->Regions = ALLOC_MULT(SMALL_RECT, cb->NumRegions); |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2326 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
|
2327 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2328 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
|
2329 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
|
2330 } |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2331 } |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2332 |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2333 for (i = 0, Y = 0; i < cb->NumRegions; i++, Y += Y_incr) |
7 | 2334 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2335 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2336 * 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
|
2337 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2338 BufferCoord.Y = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2339 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2340 * 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
|
2341 * 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
|
2342 * 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
|
2343 * 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
|
2344 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2345 ReadRegion.Top = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2346 ReadRegion.Bottom = Y + Y_incr - 1; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2347 if (!ReadConsoleOutputW(g_hConOut, // output handle |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2348 cb->Buffer, // our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2349 cb->BufferSize, // dimensions of our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2350 BufferCoord, // offset in our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2351 &ReadRegion)) // region to save |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2352 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2353 VIM_CLEAR(cb->Buffer); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2354 VIM_CLEAR(cb->Regions); |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2355 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2356 } |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2357 cb->Regions[i] = ReadRegion; |
7 | 2358 } |
2359 | |
2360 return TRUE; | |
2361 } | |
2362 | |
2363 /* | |
2364 * RestoreConsoleBuffer() | |
2365 * Description: | |
2366 * Restores important information about the console buffer, including the | |
2367 * actual buffer contents, if desired. The information to restore is in | |
2368 * the same format used by SaveConsoleBuffer(). | |
2369 * Returns: | |
2370 * TRUE on success | |
2371 */ | |
2372 static BOOL | |
2373 RestoreConsoleBuffer( | |
26 | 2374 ConsoleBuffer *cb, |
2375 BOOL RestoreScreen) | |
7 | 2376 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2377 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2378 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
|
2379 int i; |
7 | 2380 |
2381 if (cb == NULL || !cb->IsValid) | |
2382 return FALSE; | |
2383 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2384 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2385 * 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
|
2386 * 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
|
2387 * 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
|
2388 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2389 if (RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2390 ClearConsoleBuffer(cb->Info.wAttributes); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2391 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2392 FitConsoleWindow(cb->Info.dwSize, TRUE); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2393 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
|
2394 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2395 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
|
2396 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2397 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2398 if (!RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2399 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2400 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2401 * 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
|
2402 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2403 return TRUE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2404 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2405 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2406 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
|
2407 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2408 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
|
2409 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2410 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2411 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2412 * Restore the screen buffer contents. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2413 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2414 if (cb->Buffer != NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2415 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2416 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
|
2417 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2418 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
|
2419 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
|
2420 WriteRegion = cb->Regions[i]; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2421 if (!WriteConsoleOutputW(g_hConOut, // output handle |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2422 cb->Buffer, // our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2423 cb->BufferSize, // dimensions of our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2424 BufferCoord, // offset in our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2425 &WriteRegion)) // region to restore |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2426 return FALSE; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2427 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2428 } |
7 | 2429 |
2430 return TRUE; | |
2431 } | |
2432 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2433 # define FEAT_RESTORE_ORIG_SCREEN |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2434 # ifdef FEAT_RESTORE_ORIG_SCREEN |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2435 static ConsoleBuffer g_cbOrig = { 0 }; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2436 # endif |
7 | 2437 static ConsoleBuffer g_cbNonTermcap = { 0 }; |
2438 static ConsoleBuffer g_cbTermcap = { 0 }; | |
2439 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2440 # ifdef FEAT_TITLE |
7 | 2441 char g_szOrigTitle[256] = { 0 }; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2442 HWND g_hWnd = NULL; // also used in os_mswin.c |
7 | 2443 static HICON g_hOrigIconSmall = NULL; |
2444 static HICON g_hOrigIcon = NULL; | |
2445 static HICON g_hVimIcon = NULL; | |
2446 static BOOL g_fCanChangeIcon = FALSE; | |
2447 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2448 // ICON* are not defined in VC++ 4.0 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2449 # ifndef ICON_SMALL |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2450 # define ICON_SMALL 0 |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2451 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2452 # ifndef ICON_BIG |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2453 # define ICON_BIG 1 |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2454 # endif |
7 | 2455 /* |
2456 * GetConsoleIcon() | |
2457 * Description: | |
2458 * Attempts to retrieve the small icon and/or the big icon currently in | |
2459 * use by a given window. | |
2460 * Returns: | |
2461 * TRUE on success | |
2462 */ | |
2463 static BOOL | |
2464 GetConsoleIcon( | |
26 | 2465 HWND hWnd, |
2466 HICON *phIconSmall, | |
2467 HICON *phIcon) | |
7 | 2468 { |
2469 if (hWnd == NULL) | |
2470 return FALSE; | |
2471 | |
2472 if (phIconSmall != NULL) | |
26 | 2473 *phIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, |
2474 (WPARAM)ICON_SMALL, (LPARAM)0); | |
7 | 2475 if (phIcon != NULL) |
26 | 2476 *phIcon = (HICON)SendMessage(hWnd, WM_GETICON, |
2477 (WPARAM)ICON_BIG, (LPARAM)0); | |
7 | 2478 return TRUE; |
2479 } | |
2480 | |
2481 /* | |
2482 * SetConsoleIcon() | |
2483 * Description: | |
2484 * Attempts to change the small icon and/or the big icon currently in | |
2485 * use by a given window. | |
2486 * Returns: | |
2487 * TRUE on success | |
2488 */ | |
2489 static BOOL | |
2490 SetConsoleIcon( | |
26 | 2491 HWND hWnd, |
2492 HICON hIconSmall, | |
2493 HICON hIcon) | |
7 | 2494 { |
2495 if (hWnd == NULL) | |
2496 return FALSE; | |
2497 | |
2498 if (hIconSmall != NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2499 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2500 (WPARAM)ICON_SMALL, (LPARAM)hIconSmall); |
7 | 2501 if (hIcon != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2502 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2503 (WPARAM)ICON_BIG, (LPARAM) hIcon); |
7 | 2504 return TRUE; |
2505 } | |
2506 | |
2507 /* | |
2508 * SaveConsoleTitleAndIcon() | |
2509 * Description: | |
2510 * Saves the current console window title in g_szOrigTitle, for later | |
2511 * restoration. Also, attempts to obtain a handle to the console window, | |
2512 * and use it to save the small and big icons currently in use by the | |
2513 * console window. This is not always possible on some versions of Windows; | |
2514 * nor is it possible when running Vim remotely using Telnet (since the | |
2515 * console window the user sees is owned by a remote process). | |
2516 */ | |
2517 static void | |
2518 SaveConsoleTitleAndIcon(void) | |
2519 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2520 // Save the original title. |
7 | 2521 if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle))) |
2522 return; | |
2523 | |
2524 /* | |
2525 * Obtain a handle to the console window using GetConsoleWindow() from | |
2526 * KERNEL32.DLL; we need to handle in order to change the window icon. | |
2527 * This function only exists on NT-based Windows, starting with Windows | |
2528 * 2000. On older operating systems, we can't change the window icon | |
2529 * anyway. | |
2530 */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2531 g_hWnd = GetConsoleWindow(); |
7 | 2532 if (g_hWnd == NULL) |
2533 return; | |
2534 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2535 // Save the original console window icon. |
7 | 2536 GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon); |
2537 if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL) | |
2538 return; | |
2539 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2540 // Extract the first icon contained in the Vim executable. |
6249 | 2541 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
|
2542 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); |
7 | 2543 if (g_hVimIcon != NULL) |
2544 g_fCanChangeIcon = TRUE; | |
2545 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2546 # endif |
7 | 2547 |
2548 static int g_fWindInitCalled = FALSE; | |
2549 static int g_fTermcapMode = FALSE; | |
2550 static CONSOLE_CURSOR_INFO g_cci; | |
2551 static DWORD g_cmodein = 0; | |
2552 static DWORD g_cmodeout = 0; | |
2553 | |
2554 /* | |
2555 * non-GUI version of mch_init(). | |
2556 */ | |
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
|
2557 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
|
2558 mch_init_c(void) |
7 | 2559 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2560 # ifndef FEAT_RESTORE_ORIG_SCREEN |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2561 CONSOLE_SCREEN_BUFFER_INFO csbi; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2562 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2563 # ifndef __MINGW32__ |
7 | 2564 extern int _fmode; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2565 # endif |
7 | 2566 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2567 // Silently handle invalid parameters to CRT functions |
2584 | 2568 SET_INVALID_PARAM_HANDLER; |
2569 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2570 // Let critical errors result in a failure, not in a dialog box. Required |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2571 // for the timestamp test to work on removed floppies. |
7 | 2572 SetErrorMode(SEM_FAILCRITICALERRORS); |
2573 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2574 _fmode = O_BINARY; // we do our own CR-LF translation |
7 | 2575 out_flush(); |
2576 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2577 // Obtain handles for the standard Console I/O devices |
7 | 2578 if (read_cmd_fd == 0) |
2579 g_hConIn = GetStdHandle(STD_INPUT_HANDLE); | |
2580 else | |
2581 create_conin(); | |
2582 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
|
2583 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2584 # ifdef FEAT_RESTORE_ORIG_SCREEN |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2585 // Save the initial console buffer for later restoration |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2586 SaveConsoleBuffer(&g_cbOrig); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2587 g_attrCurrent = g_attrDefault = g_cbOrig.Info.wAttributes; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2588 # else |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2589 // Get current text attributes |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2590 GetConsoleScreenBufferInfo(g_hConOut, &csbi); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2591 g_attrCurrent = g_attrDefault = csbi.wAttributes; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2592 # endif |
7 | 2593 if (cterm_normal_fg_color == 0) |
2594 cterm_normal_fg_color = (g_attrCurrent & 0xf) + 1; | |
2595 if (cterm_normal_bg_color == 0) | |
2596 cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1; | |
2597 | |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
2598 // 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
|
2599 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
|
2600 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
|
2601 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2602 // set termcap codes to current text attributes |
7 | 2603 update_tcap(g_attrCurrent); |
2604 | |
2605 GetConsoleCursorInfo(g_hConOut, &g_cci); | |
2606 GetConsoleMode(g_hConIn, &g_cmodein); | |
2607 GetConsoleMode(g_hConOut, &g_cmodeout); | |
2608 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2609 # ifdef FEAT_TITLE |
7 | 2610 SaveConsoleTitleAndIcon(); |
2611 /* | |
2612 * Set both the small and big icons of the console window to Vim's icon. | |
2613 * Note that Vim presently only has one size of icon (32x32), but it | |
2614 * automatically gets scaled down to 16x16 when setting the small icon. | |
2615 */ | |
2616 if (g_fCanChangeIcon) | |
2617 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2618 # endif |
7 | 2619 |
2620 ui_get_shellsize(); | |
2621 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2622 # ifdef MCH_WRITE_DUMP |
7 | 2623 fdDump = fopen("dump", "wt"); |
2624 | |
2625 if (fdDump) | |
2626 { | |
2627 time_t t; | |
2628 | |
2629 time(&t); | |
2630 fputs(ctime(&t), fdDump); | |
2631 fflush(fdDump); | |
2632 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2633 # endif |
7 | 2634 |
2635 g_fWindInitCalled = TRUE; | |
2636 | |
2637 g_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); | |
2638 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2639 # ifdef FEAT_CLIPBOARD |
4168 | 2640 win_clip_init(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2641 # 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
|
2642 |
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
|
2643 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
|
2644 vtp_init(); |
7 | 2645 } |
2646 | |
2647 /* | |
2648 * non-GUI version of mch_exit(). | |
2649 * Shut down and exit with status `r' | |
2650 * Careful: mch_exit() may be called before mch_init()! | |
2651 */ | |
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
|
2652 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
|
2653 mch_exit_c(int r) |
7 | 2654 { |
10835
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
2655 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
|
2656 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2657 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
|
2658 |
7 | 2659 stoptermcap(); |
2660 if (g_fWindInitCalled) | |
2661 settmode(TMODE_COOK); | |
2662 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2663 ml_close_all(TRUE); // remove all memfiles |
7 | 2664 |
2665 if (g_fWindInitCalled) | |
2666 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2667 # 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
|
2668 mch_restore_title(SAVE_RESTORE_BOTH); |
7 | 2669 /* |
2670 * Restore both the small and big icons of the console window to | |
2671 * what they were at startup. Don't do this when the window is | |
2672 * closed, Vim would hang here. | |
2673 */ | |
2674 if (g_fCanChangeIcon && !g_fForceExit) | |
2675 SetConsoleIcon(g_hWnd, g_hOrigIconSmall, g_hOrigIcon); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2676 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2677 |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2678 # ifdef MCH_WRITE_DUMP |
7 | 2679 if (fdDump) |
2680 { | |
2681 time_t t; | |
2682 | |
2683 time(&t); | |
2684 fputs(ctime(&t), fdDump); | |
2685 fclose(fdDump); | |
2686 } | |
2687 fdDump = NULL; | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2688 # endif |
7 | 2689 } |
2690 | |
2691 SetConsoleCursorInfo(g_hConOut, &g_cci); | |
2692 SetConsoleMode(g_hConIn, g_cmodein); | |
2693 SetConsoleMode(g_hConOut, g_cmodeout); | |
2694 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2695 # ifdef DYNAMIC_GETTEXT |
7 | 2696 dyn_libintl_end(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2697 # endif |
7 | 2698 |
2699 exit(r); | |
2700 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2701 #endif // !FEAT_GUI_MSWIN |
7 | 2702 |
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
|
2703 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
|
2704 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
|
2705 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2706 #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
|
2707 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
|
2708 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
|
2709 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
|
2710 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
|
2711 #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
|
2712 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
|
2713 #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
|
2714 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
|
2715 #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
|
2716 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2717 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2718 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
|
2719 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
|
2720 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2721 #ifdef VIMDLL |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2722 if (gui.in_use || gui.starting) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2723 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
|
2724 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
|
2725 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
|
2726 #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
|
2727 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
|
2728 #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
|
2729 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
|
2730 #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
|
2731 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2732 |
7 | 2733 /* |
2734 * Do we have an interactive window? | |
2735 */ | |
2736 int | |
2737 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
|
2738 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
|
2739 char **argv UNUSED) |
7 | 2740 { |
2741 get_exe_name(); | |
2742 | |
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
|
2743 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2744 return OK; // GUI always has a tty |
7 | 2745 #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
|
2746 # 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
|
2747 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
|
2748 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
|
2749 # endif |
7 | 2750 if (isatty(1)) |
2751 return OK; | |
2752 return FAIL; | |
2753 #endif | |
2754 } | |
2755 | |
5326 | 2756 /* |
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
|
2757 * Set the case of the file name, if it already exists. |
7 | 2758 * When "len" is > 0, also expand short to long filenames. |
2759 */ | |
2760 void | |
2761 fname_case( | |
2762 char_u *name, | |
2763 int len) | |
2764 { | |
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
|
2765 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
|
2766 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
|
2767 WCHAR buf[_MAX_PATH + 1]; |
7 | 2768 |
434 | 2769 flen = (int)STRLEN(name); |
5326 | 2770 if (flen == 0) |
7 | 2771 return; |
2772 | |
2773 slash_adjust(name); | |
2774 | |
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
|
2775 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
|
2776 if (p == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2777 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
|
2778 |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2779 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
|
2780 { |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2781 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
|
2782 |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2783 if (q != NULL) |
7 | 2784 { |
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
|
2785 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
|
2786 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
|
2787 vim_free(q); |
7 | 2788 } |
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
|
2789 } |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
2790 vim_free(p); |
7 | 2791 } |
2792 | |
2793 | |
2794 /* | |
2795 * Insert user name in s[len]. | |
2796 */ | |
2797 int | |
2798 mch_get_user_name( | |
26 | 2799 char_u *s, |
2800 int len) | |
7 | 2801 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2802 WCHAR wszUserName[256 + 1]; // UNLEN is 256 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2803 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
|
2804 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2805 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
|
2806 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2807 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
|
2808 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2809 if (p != NULL) |
5549 | 2810 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2811 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
|
2812 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
|
2813 return OK; |
5549 | 2814 } |
2815 } | |
7 | 2816 s[0] = NUL; |
2817 return FAIL; | |
2818 } | |
2819 | |
2820 | |
2821 /* | |
2822 * Insert host name in s[len]. | |
2823 */ | |
2824 void | |
2825 mch_get_host_name( | |
2826 char_u *s, | |
2827 int len) | |
2828 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2829 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
|
2830 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
|
2831 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2832 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
|
2833 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2834 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
|
2835 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2836 if (p != NULL) |
5551 | 2837 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2838 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
|
2839 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
|
2840 return; |
5551 | 2841 } |
2842 } | |
7 | 2843 } |
2844 | |
2845 | |
2846 /* | |
2847 * return process ID | |
2848 */ | |
2849 long | |
26 | 2850 mch_get_pid(void) |
7 | 2851 { |
2852 return (long)GetCurrentProcessId(); | |
2853 } | |
2854 | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2855 /* |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2856 * 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
|
2857 */ |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2858 int |
16455
1ae13586edf8
patch 8.1.1232: can't build on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
2859 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
|
2860 { |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2861 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
|
2862 DWORD status = 0; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2863 int ret = FALSE; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2864 |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2865 if (hProcess == NULL) |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2866 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
|
2867 if (GetExitCodeProcess(hProcess, &status) ) |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2868 ret = status == STILL_ACTIVE; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2869 CloseHandle(hProcess); |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2870 return ret; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2871 } |
7 | 2872 |
2873 /* | |
2874 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
2875 * Return OK for success, FAIL for failure. | |
2876 */ | |
2877 int | |
2878 mch_dirname( | |
2879 char_u *buf, | |
2880 int len) | |
2881 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2882 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
|
2883 |
7 | 2884 /* |
2885 * Originally this was: | |
2886 * return (getcwd(buf, len) != NULL ? OK : FAIL); | |
2887 * But the Win32s known bug list says that getcwd() doesn't work | |
2888 * so use the Win32 system call instead. <Negri> | |
2889 */ | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2890 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
|
2891 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2892 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
|
2893 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
|
2894 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2895 if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0) |
7 | 2896 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2897 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
|
2898 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
|
2899 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2900 // long path name is too long, fall back to short one |
7 | 2901 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
|
2902 p = NULL; |
7 | 2903 } |
2904 } | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2905 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
|
2906 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
|
2907 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2908 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
|
2909 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2910 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
|
2911 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
|
2912 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
|
2913 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2914 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2915 return FAIL; |
7 | 2916 } |
2917 | |
2918 /* | |
5494 | 2919 * Get file permissions for "name". |
2920 * Return mode_t or -1 for error. | |
7 | 2921 */ |
2922 long | |
26 | 2923 mch_getperm(char_u *name) |
7 | 2924 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8949
diff
changeset
|
2925 stat_T st; |
5494 | 2926 int n; |
2927 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2928 n = mch_stat((char *)name, &st); |
5588 | 2929 return n == 0 ? (long)(unsigned short)st.st_mode : -1L; |
7 | 2930 } |
2931 | |
2932 | |
2933 /* | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2934 * Set file permission for "name" to "perm". |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2935 * |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2936 * Return FAIL for failure, OK otherwise. |
7 | 2937 */ |
2938 int | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
2939 mch_setperm(char_u *name, long perm) |
7 | 2940 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2941 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
|
2942 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
|
2943 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2944 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
|
2945 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
|
2946 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
|
2947 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
2948 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
|
2949 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2950 if (n == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2951 return FAIL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2952 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2953 win32_set_archive(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2954 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2955 return OK; |
7 | 2956 } |
2957 | |
2958 /* | |
2959 * Set hidden flag for "name". | |
2960 */ | |
2961 void | |
2962 mch_hide(char_u *name) | |
2963 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2964 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2965 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2966 return; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2967 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2968 attrs |= FILE_ATTRIBUTE_HIDDEN; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2969 win32_setattrs(name, attrs); |
7 | 2970 } |
2971 | |
2972 /* | |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2973 * 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
|
2974 */ |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2975 int |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2976 mch_ishidden(char_u *name) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2977 { |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2978 int f = win32_getattrs(name); |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2979 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2980 if (f == -1) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2981 return FALSE; // file does not exist at all |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2982 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2983 return (f & FILE_ATTRIBUTE_HIDDEN) != 0; |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2984 } |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2985 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
2986 /* |
7 | 2987 * return TRUE if "name" is a directory |
2988 * return FALSE if "name" is not a directory or upon error | |
2989 */ | |
2990 int | |
2991 mch_isdir(char_u *name) | |
2992 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
2993 int f = win32_getattrs(name); |
7 | 2994 |
2995 if (f == -1) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2996 return FALSE; // file does not exist at all |
7 | 2997 |
2998 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; | |
2999 } | |
3000 | |
3001 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3002 * 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
|
3003 * 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
|
3004 * return FALSE for error |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3005 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3006 int |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3007 mch_isrealdir(char_u *name) |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3008 { |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3009 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
|
3010 } |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3011 |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3012 /* |
2803 | 3013 * Create directory "name". |
3014 * Return 0 on success, -1 on error. | |
3015 */ | |
3016 int | |
3017 mch_mkdir(char_u *name) | |
3018 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3019 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
|
3020 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
|
3021 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3022 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
|
3023 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
|
3024 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
|
3025 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
|
3026 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
|
3027 return retval; |
2803 | 3028 } |
3029 | |
3030 /* | |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3031 * Delete directory "name". |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3032 * 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
|
3033 */ |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3034 int |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3035 mch_rmdir(char_u *name) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3036 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3037 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
|
3038 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
|
3039 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3040 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
|
3041 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
|
3042 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
|
3043 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
|
3044 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
|
3045 return retval; |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3046 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3047 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3048 /* |
696 | 3049 * Return TRUE if file "fname" has more than one link. |
3050 */ | |
3051 int | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3052 mch_is_hard_link(char_u *fname) |
696 | 3053 { |
2793 | 3054 BY_HANDLE_FILE_INFORMATION info; |
3055 | |
3056 return win32_fileinfo(fname, &info) == FILEINFO_OK | |
3057 && info.nNumberOfLinks > 1; | |
3058 } | |
3059 | |
3060 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3061 * 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
|
3062 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3063 int |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3064 mch_is_symbolic_link(char_u *name) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3065 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3066 HANDLE hFind; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3067 int res = FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3068 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
|
3069 WCHAR *wn; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3070 WIN32_FIND_DATAW findDataW; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3071 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3072 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
|
3073 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
|
3074 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
|
3075 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3076 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
|
3077 vim_free(wn); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3078 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
|
3079 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3080 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
|
3081 reparseTag = findDataW.dwReserved0; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3082 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
|
3083 } |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3084 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3085 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
|
3086 && (reparseTag == IO_REPARSE_TAG_SYMLINK |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3087 || reparseTag == IO_REPARSE_TAG_MOUNT_POINT)) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3088 res = TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3089 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3090 return res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3091 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3092 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3093 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3094 * 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
|
3095 * link. |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3096 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3097 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3098 mch_is_linked(char_u *fname) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3099 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3100 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
|
3101 return TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3102 return FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3103 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3104 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3105 /* |
2793 | 3106 * Get the by-handle-file-information for "fname". |
3107 * Returns FILEINFO_OK when OK. | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3108 * Returns FILEINFO_ENC_FAIL when enc_to_utf16() failed. |
2793 | 3109 * Returns FILEINFO_READ_FAIL when CreateFile() failed. |
3110 * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed. | |
3111 */ | |
3112 int | |
3113 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info) | |
3114 { | |
696 | 3115 HANDLE hFile; |
2793 | 3116 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
|
3117 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
|
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 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
|
3120 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
|
3121 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
|
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 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
|
3124 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
|
3125 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
|
3126 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
|
3127 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
|
3128 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
|
3129 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
|
3130 vim_free(wn); |
696 | 3131 |
3132 if (hFile != INVALID_HANDLE_VALUE) | |
3133 { | |
2793 | 3134 if (GetFileInformationByHandle(hFile, info) != 0) |
3135 res = FILEINFO_OK; | |
3136 else | |
3137 res = FILEINFO_INFO_FAIL; | |
696 | 3138 CloseHandle(hFile); |
3139 } | |
3140 | |
3141 return res; | |
3142 } | |
3143 | |
3144 /* | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3145 * get file attributes for `name' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3146 * -1 : error |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3147 * else FILE_ATTRIBUTE_* defined in winnt.h |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3148 */ |
5494 | 3149 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3150 win32_getattrs(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3151 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3152 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
|
3153 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
|
3154 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3155 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
|
3156 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
|
3157 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
|
3158 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3159 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
|
3160 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3161 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3162 return attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3163 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3164 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3165 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3166 * set file attributes for `name' to `attrs' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3167 * |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3168 * return -1 for failure, 0 otherwise |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3169 */ |
14862
27b9a84395b5
patch 8.1.0443: unnecessary static function prototypes
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
3170 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3171 win32_setattrs(char_u *name, int attrs) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3172 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3173 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
|
3174 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
|
3175 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3176 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
|
3177 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
|
3178 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
|
3179 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3180 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
|
3181 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3182 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3183 return res ? 0 : -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3184 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3185 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3186 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3187 * Set archive flag for "name". |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3188 */ |
14862
27b9a84395b5
patch 8.1.0443: unnecessary static function prototypes
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
3189 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3190 win32_set_archive(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3191 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3192 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3193 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3194 return -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3195 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3196 attrs |= FILE_ATTRIBUTE_ARCHIVE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3197 return win32_setattrs(name, attrs); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3198 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3199 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3200 /* |
7 | 3201 * Return TRUE if file or directory "name" is writable (not readonly). |
3202 * Strange semantics of Win32: a readonly directory is writable, but you can't | |
3203 * delete a file. Let's say this means it is writable. | |
3204 */ | |
3205 int | |
3206 mch_writable(char_u *name) | |
3207 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3208 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3209 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3210 return (attrs != -1 && (!(attrs & FILE_ATTRIBUTE_READONLY) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3211 || (attrs & FILE_ATTRIBUTE_DIRECTORY))); |
7 | 3212 } |
3213 | |
3214 /* | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3215 * Return TRUE if "name" can be executed, FALSE if not. |
6700 | 3216 * 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
|
3217 * 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
|
3218 * the allocated memory. |
7 | 3219 */ |
3220 int | |
6700 | 3221 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3222 { |
16180
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3223 // 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
|
3224 // 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
|
3225 // UTF-8. |
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3226 char_u buf[_MAX_PATH * 3]; |
835 | 3227 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
|
3228 char_u *p, *saved; |
10 | 3229 |
16180
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3230 if (len >= sizeof(buf)) // safety check |
10 | 3231 return FALSE; |
3232 | |
16180
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3233 // 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
|
3234 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
|
3235 if (executable_exists((char *)name, path, use_path)) |
10 | 3236 return TRUE; |
3237 | |
3238 /* | |
3239 * Loop over all extensions in $PATHEXT. | |
3240 */ | |
14883
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3241 p = mch_getenv("PATHEXT"); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3242 if (p == NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3243 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
|
3244 saved = vim_strsave(p); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3245 if (saved == NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3246 return FALSE; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3247 p = saved; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3248 while (*p) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3249 { |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3250 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
|
3251 |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3252 if (tmp != NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3253 *tmp = NUL; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3254 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
|
3255 && 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
|
3256 { |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3257 vim_free(saved); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3258 return TRUE; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3259 } |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3260 if (tmp == NULL) |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3261 break; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3262 p = tmp + 1; |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3263 } |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
3264 vim_free(saved); |
1c2ba2b0227e
patch 8.1.0453: MS-Windows: executable() is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
14881
diff
changeset
|
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 vim_strncpy(buf, name, sizeof(buf) - 1); |
10 | 3267 p = mch_getenv("PATHEXT"); |
3268 if (p == NULL) | |
3269 p = (char_u *)".com;.exe;.bat;.cmd"; | |
3270 while (*p) | |
3271 { | |
3272 if (p[0] == '.' && (p[1] == NUL || p[1] == ';')) | |
3273 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3274 // A single "." means no extension is added. |
10 | 3275 buf[len] = NUL; |
3276 ++p; | |
3277 if (*p) | |
3278 ++p; | |
3279 } | |
3280 else | |
16180
1eaaa82ececf
patch 8.1.1095: MS-Windows: executable() fails on very long filename
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
3281 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
|
3282 if (executable_exists((char *)buf, path, use_path)) |
10 | 3283 return TRUE; |
3284 } | |
3285 return FALSE; | |
7 | 3286 } |
3287 | |
3288 /* | |
3289 * Check what "name" is: | |
3290 * NODE_NORMAL: file or directory (or doesn't exist) | |
3291 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3292 * NODE_OTHER: non-writable things | |
3293 */ | |
3294 int | |
3295 mch_nodetype(char_u *name) | |
3296 { | |
3297 HANDLE hFile; | |
3298 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
|
3299 WCHAR *wn; |
7 | 3300 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3301 // We can't open a file with a name "\\.\con" or "\\.\prn" and trying to |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3302 // read from it later will cause Vim to hang. Thus return NODE_WRITABLE |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3303 // here. |
1004 | 3304 if (STRNCMP(name, "\\\\.\\", 4) == 0) |
3305 return NODE_WRITABLE; | |
3306 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3307 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
|
3308 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
|
3309 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
|
3310 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3311 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
|
3312 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
|
3313 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
|
3314 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
|
3315 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
|
3316 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
|
3317 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
|
3318 vim_free(wn); |
7 | 3319 if (hFile == INVALID_HANDLE_VALUE) |
3320 return NODE_NORMAL; | |
3321 | |
3322 type = GetFileType(hFile); | |
3323 CloseHandle(hFile); | |
3324 if (type == FILE_TYPE_CHAR) | |
3325 return NODE_WRITABLE; | |
3326 if (type == FILE_TYPE_DISK) | |
3327 return NODE_NORMAL; | |
3328 return NODE_OTHER; | |
3329 } | |
3330 | |
3331 #ifdef HAVE_ACL | |
3332 struct my_acl | |
3333 { | |
3334 PSECURITY_DESCRIPTOR pSecurityDescriptor; | |
3335 PSID pSidOwner; | |
3336 PSID pSidGroup; | |
3337 PACL pDacl; | |
3338 PACL pSacl; | |
3339 }; | |
3340 #endif | |
3341 | |
3342 /* | |
3343 * Return a pointer to the ACL of file "fname" in allocated memory. | |
3344 * Return NULL if the ACL is not available for whatever reason. | |
3345 */ | |
3346 vim_acl_T | |
26 | 3347 mch_get_acl(char_u *fname) |
7 | 3348 { |
3349 #ifndef HAVE_ACL | |
3350 return (vim_acl_T)NULL; | |
3351 #else | |
3352 struct my_acl *p = NULL; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3353 DWORD err; |
7 | 3354 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
3355 p = ALLOC_CLEAR_ONE(struct my_acl); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3356 if (p != NULL) |
7 | 3357 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3358 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
|
3359 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3360 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
|
3361 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
|
3362 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
|
3363 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3364 // 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
|
3365 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
|
3366 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
|
3367 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
|
3368 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
|
3369 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
|
3370 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
|
3371 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
|
3372 &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
|
3373 &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
|
3374 &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
|
3375 &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
|
3376 &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
|
3377 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
|
3378 err == ERROR_PRIVILEGE_NOT_HELD) |
7 | 3379 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3380 // 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
|
3381 (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
|
3382 wn, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3383 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
|
3384 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
|
3385 NULL, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3386 NULL, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3387 &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
|
3388 NULL, |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3389 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3390 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3391 if (p->pSecurityDescriptor == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3392 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3393 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
|
3394 p = NULL; |
7 | 3395 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3396 vim_free(wn); |
7 | 3397 } |
3398 | |
3399 return (vim_acl_T)p; | |
3400 #endif | |
3401 } | |
3402 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3403 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3404 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3405 * Check if "acl" contains inherited ACE. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3406 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3407 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3408 is_acl_inherited(PACL acl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3409 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3410 DWORD i; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3411 ACL_SIZE_INFORMATION acl_info; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3412 PACCESS_ALLOWED_ACE ace; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3413 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3414 acl_info.AceCount = 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3415 GetAclInformation(acl, &acl_info, sizeof(acl_info), AclSizeInformation); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3416 for (i = 0; i < acl_info.AceCount; i++) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3417 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3418 GetAce(acl, i, (LPVOID *)&ace); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3419 if (ace->Header.AceFlags & INHERITED_ACE) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3420 return TRUE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3421 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3422 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3423 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3424 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3425 |
7 | 3426 /* |
3427 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3428 * Errors are ignored. | |
3429 * This must only be called with "acl" equal to what mch_get_acl() returned. | |
3430 */ | |
3431 void | |
26 | 3432 mch_set_acl(char_u *fname, vim_acl_T acl) |
7 | 3433 { |
3434 #ifdef HAVE_ACL | |
3435 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
|
3436 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
|
3437 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
|
3438 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3439 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
|
3440 return; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3441 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3442 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
|
3443 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
|
3444 return; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3445 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3446 // 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
|
3447 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
|
3448 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
|
3449 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
|
3450 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
|
3451 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
|
3452 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3453 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
|
3454 // 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
|
3455 // 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
|
3456 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
|
3457 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
|
3458 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3459 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
|
3460 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
|
3461 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3462 (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
|
3463 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
|
3464 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
|
3465 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
|
3466 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
|
3467 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
|
3468 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
|
3469 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
|
3470 ); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3471 vim_free(wn); |
7 | 3472 #endif |
3473 } | |
3474 | |
3475 void | |
26 | 3476 mch_free_acl(vim_acl_T acl) |
7 | 3477 { |
3478 #ifdef HAVE_ACL | |
3479 struct my_acl *p = (struct my_acl *)acl; | |
3480 | |
3481 if (p != NULL) | |
3482 { | |
3483 LocalFree(p->pSecurityDescriptor); // Free the memory just in case | |
3484 vim_free(p); | |
3485 } | |
3486 #endif | |
3487 } | |
3488 | |
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
|
3489 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 3490 |
3491 /* | |
3492 * handler for ctrl-break, ctrl-c interrupts, and fatal events. | |
3493 */ | |
3494 static BOOL WINAPI | |
3495 handler_routine( | |
3496 DWORD dwCtrlType) | |
3497 { | |
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
|
3498 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
|
3499 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
|
3500 |
7 | 3501 switch (dwCtrlType) |
3502 { | |
3503 case CTRL_C_EVENT: | |
3504 if (ctrl_c_interrupts) | |
3505 g_fCtrlCPressed = TRUE; | |
3506 return TRUE; | |
3507 | |
3508 case CTRL_BREAK_EVENT: | |
3509 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
|
3510 ctrl_break_was_pressed = TRUE; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3511 // ReadConsoleInput is blocking, send a key event to continue. |
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
|
3512 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
|
3513 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
|
3514 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
|
3515 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
|
3516 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
|
3517 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
|
3518 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
|
3519 WriteConsoleInput(g_hConIn, &ir, 1, &out); |
7 | 3520 return TRUE; |
3521 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3522 // fatal events: shut down gracefully |
7 | 3523 case CTRL_CLOSE_EVENT: |
3524 case CTRL_LOGOFF_EVENT: | |
3525 case CTRL_SHUTDOWN_EVENT: | |
3526 windgoto((int)Rows - 1, 0); | |
3527 g_fForceExit = TRUE; | |
3528 | |
1569 | 3529 vim_snprintf((char *)IObuff, IOSIZE, _("Vim: Caught %s event\n"), |
7 | 3530 (dwCtrlType == CTRL_CLOSE_EVENT |
3531 ? _("close") | |
3532 : dwCtrlType == CTRL_LOGOFF_EVENT | |
3533 ? _("logoff") | |
3534 : _("shutdown"))); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3535 # ifdef DEBUG |
7 | 3536 OutputDebugString(IObuff); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3537 # endif |
7 | 3538 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3539 preserve_exit(); // output IObuff, preserve files and exit |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3540 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3541 return TRUE; // not reached |
7 | 3542 |
3543 default: | |
3544 return FALSE; | |
3545 } | |
3546 } | |
3547 | |
3548 | |
3549 /* | |
3550 * set the tty in (raw) ? "raw" : "cooked" mode | |
3551 */ | |
3552 void | |
26 | 3553 mch_settmode(int tmode) |
7 | 3554 { |
3555 DWORD cmodein; | |
3556 DWORD cmodeout; | |
3557 BOOL bEnableHandler; | |
3558 | |
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
|
3559 # 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
|
3560 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
|
3561 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
|
3562 # endif |
7 | 3563 GetConsoleMode(g_hConIn, &cmodein); |
3564 GetConsoleMode(g_hConOut, &cmodeout); | |
3565 if (tmode == TMODE_RAW) | |
3566 { | |
3567 cmodein &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3568 ENABLE_ECHO_INPUT); | |
3569 if (g_fMouseActive) | |
3570 cmodein |= ENABLE_MOUSE_INPUT; | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3571 cmodeout &= ~( |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3572 # ifdef FEAT_TERMGUICOLORS |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3573 // Do not turn off the ENABLE_PROCESSED_OUTPUT flag when using |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3574 // VTP. |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3575 ((vtp_working) ? 0 : ENABLE_PROCESSED_OUTPUT) | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3576 # else |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3577 ENABLE_PROCESSED_OUTPUT | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3578 # 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
|
3579 ENABLE_WRAP_AT_EOL_OUTPUT); |
7 | 3580 bEnableHandler = TRUE; |
3581 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3582 else // cooked |
7 | 3583 { |
3584 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3585 ENABLE_ECHO_INPUT); | |
3586 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); | |
3587 bEnableHandler = FALSE; | |
3588 } | |
3589 SetConsoleMode(g_hConIn, cmodein); | |
3590 SetConsoleMode(g_hConOut, cmodeout); | |
3591 SetConsoleCtrlHandler(handler_routine, bEnableHandler); | |
3592 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3593 # ifdef MCH_WRITE_DUMP |
7 | 3594 if (fdDump) |
3595 { | |
3596 fprintf(fdDump, "mch_settmode(%s, in = %x, out = %x)\n", | |
3597 tmode == TMODE_RAW ? "raw" : | |
3598 tmode == TMODE_COOK ? "cooked" : "normal", | |
3599 cmodein, cmodeout); | |
3600 fflush(fdDump); | |
3601 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3602 # endif |
7 | 3603 } |
3604 | |
3605 | |
3606 /* | |
3607 * Get the size of the current window in `Rows' and `Columns' | |
3608 * Return OK when size could be determined, FAIL otherwise. | |
3609 */ | |
3610 int | |
26 | 3611 mch_get_shellsize(void) |
7 | 3612 { |
3613 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
3614 | |
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
|
3615 # 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
|
3616 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
|
3617 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
|
3618 # endif |
7 | 3619 if (!g_fTermcapMode && g_cbTermcap.IsValid) |
3620 { | |
3621 /* | |
3622 * For some reason, we are trying to get the screen dimensions | |
3623 * even though we are not in termcap mode. The 'Rows' and 'Columns' | |
3624 * variables are really intended to mean the size of Vim screen | |
3625 * while in termcap mode. | |
3626 */ | |
3627 Rows = g_cbTermcap.Info.dwSize.Y; | |
3628 Columns = g_cbTermcap.Info.dwSize.X; | |
3629 } | |
3630 else if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3631 { | |
3632 Rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3633 Columns = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3634 } | |
3635 else | |
3636 { | |
3637 Rows = 25; | |
3638 Columns = 80; | |
3639 } | |
3640 return OK; | |
3641 } | |
3642 | |
3643 /* | |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3644 * 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
|
3645 */ |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3646 static void |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3647 ResizeConBuf( |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3648 HANDLE hConsole, |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3649 COORD coordScreen) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3650 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3651 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
|
3652 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3653 # ifdef MCH_WRITE_DUMP |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3654 if (fdDump) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3655 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3656 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
|
3657 GetLastError()); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3658 fflush(fdDump); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3659 } |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3660 # endif |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3661 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3662 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3663 |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3664 /* |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3665 * 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
|
3666 */ |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3667 static void |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3668 ResizeWindow( |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3669 HANDLE hConsole, |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3670 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
|
3671 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3672 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
|
3673 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3674 # ifdef MCH_WRITE_DUMP |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3675 if (fdDump) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3676 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3677 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
|
3678 GetLastError()); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3679 fflush(fdDump); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3680 } |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3681 # endif |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3682 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3683 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3684 |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3685 /* |
7 | 3686 * Set a console window to `xSize' * `ySize' |
3687 */ | |
3688 static void | |
3689 ResizeConBufAndWindow( | |
26 | 3690 HANDLE hConsole, |
3691 int xSize, | |
3692 int ySize) | |
7 | 3693 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3694 CONSOLE_SCREEN_BUFFER_INFO csbi; // hold current console buffer info |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3695 SMALL_RECT srWindowRect; // hold the new console size |
7 | 3696 COORD coordScreen; |
17393
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3697 COORD cursor; |
14619
5e85d326d616
patch 8.1.0323: reverse order of VTP calls only needed the first time
Christian Brabandt <cb@256bit.org>
parents:
14567
diff
changeset
|
3698 static int resized = FALSE; |
7 | 3699 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3700 # ifdef MCH_WRITE_DUMP |
7 | 3701 if (fdDump) |
3702 { | |
3703 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize); | |
3704 fflush(fdDump); | |
3705 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3706 # endif |
7 | 3707 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3708 // get the largest size we can size the console window to |
7 | 3709 coordScreen = GetLargestConsoleWindowSize(hConsole); |
3710 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3711 // define the new console window size and scroll position |
7 | 3712 srWindowRect.Left = srWindowRect.Top = (SHORT) 0; |
3713 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); | |
3714 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); | |
3715 | |
3716 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3717 { | |
3718 int sx, sy; | |
3719 | |
3720 sx = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3721 sy = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3722 if (sy < ySize || sx < xSize) | |
3723 { | |
3724 /* | |
3725 * Increasing number of lines/columns, do buffer first. | |
3726 * Use the maximal size in x and y direction. | |
3727 */ | |
3728 if (sy < ySize) | |
3729 coordScreen.Y = ySize; | |
3730 else | |
3731 coordScreen.Y = sy; | |
3732 if (sx < xSize) | |
3733 coordScreen.X = xSize; | |
3734 else | |
3735 coordScreen.X = sx; | |
3736 SetConsoleScreenBufferSize(hConsole, coordScreen); | |
3737 } | |
3738 } | |
3739 | |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3740 // define the new console buffer size |
7 | 3741 coordScreen.X = xSize; |
3742 coordScreen.Y = ySize; | |
3743 | |
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
|
3744 // 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
|
3745 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
|
3746 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3747 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
|
3748 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
|
3749 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3750 else |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3751 { |
17393
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3752 // Workaround for a Windows 10 bug |
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3753 cursor.X = srWindowRect.Left; |
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3754 cursor.Y = srWindowRect.Top; |
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3755 SetConsoleCursorPosition(hConsole, cursor); |
372f2eaa544a
patch 8.1.1695: Windows 10: crash when cursor is at bottom of terminal
Bram Moolenaar <Bram@vim.org>
parents:
16984
diff
changeset
|
3756 |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3757 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
|
3758 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
|
3759 resized = TRUE; |
7 | 3760 } |
3761 } | |
3762 | |
3763 | |
3764 /* | |
3765 * Set the console window to `Rows' * `Columns' | |
3766 */ | |
3767 void | |
26 | 3768 mch_set_shellsize(void) |
7 | 3769 { |
3770 COORD coordScreen; | |
3771 | |
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
|
3772 # 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
|
3773 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
|
3774 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
|
3775 # endif |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3776 // Don't change window size while still starting up |
7 | 3777 if (suppress_winsize != 0) |
3778 { | |
3779 suppress_winsize = 2; | |
3780 return; | |
3781 } | |
3782 | |
3783 if (term_console) | |
3784 { | |
3785 coordScreen = GetLargestConsoleWindowSize(g_hConOut); | |
3786 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3787 // Clamp Rows and Columns to reasonable values |
7 | 3788 if (Rows > coordScreen.Y) |
3789 Rows = coordScreen.Y; | |
3790 if (Columns > coordScreen.X) | |
3791 Columns = coordScreen.X; | |
3792 | |
3793 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
3794 } | |
3795 } | |
3796 | |
3797 /* | |
3798 * Rows and/or Columns has changed. | |
3799 */ | |
3800 void | |
26 | 3801 mch_new_shellsize(void) |
7 | 3802 { |
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
|
3803 # 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
|
3804 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
|
3805 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
|
3806 # endif |
7 | 3807 set_scroll_region(0, 0, Columns - 1, Rows - 1); |
3808 } | |
3809 | |
3810 | |
3811 /* | |
3812 * Called when started up, to set the winsize that was delayed. | |
3813 */ | |
3814 void | |
26 | 3815 mch_set_winsize_now(void) |
7 | 3816 { |
3817 if (suppress_winsize == 2) | |
3818 { | |
3819 suppress_winsize = 0; | |
3820 mch_set_shellsize(); | |
3821 shell_resized(); | |
3822 } | |
3823 suppress_winsize = 0; | |
3824 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3825 #endif // FEAT_GUI_MSWIN |
7 | 3826 |
5547 | 3827 static BOOL |
3828 vim_create_process( | |
5556 | 3829 char *cmd, |
5569 | 3830 BOOL inherit_handles, |
5547 | 3831 DWORD flags, |
3832 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
|
3833 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
|
3834 LPVOID *env, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
3835 char *cwd) |
5547 | 3836 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3837 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
|
3838 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
|
3839 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3840 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
|
3841 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
|
3842 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
|
3843 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
|
3844 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3845 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
|
3846 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
|
3847 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
|
3848 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3849 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3850 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
|
3851 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
|
3852 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
|
3853 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
|
3854 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
|
3855 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
|
3856 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
|
3857 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
|
3858 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
|
3859 (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
|
3860 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
|
3861 theend: |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3862 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
|
3863 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
|
3864 return ret; |
5547 | 3865 } |
7 | 3866 |
3867 | |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3868 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
|
3869 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
|
3870 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
|
3871 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
|
3872 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3873 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
|
3874 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
|
3875 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3876 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
|
3877 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
|
3878 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
|
3879 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3880 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
|
3881 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
|
3882 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
|
3883 } |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3884 |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3885 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
3886 #if defined(FEAT_GUI_MSWIN) || defined(PROTO) |
7 | 3887 |
3888 /* | |
3889 * Specialised version of system() for Win32 GUI mode. | |
3890 * This version proceeds as follows: | |
3891 * 1. Create a console window for use by the subprocess | |
3892 * 2. Run the subprocess (it gets the allocated console by default) | |
3893 * 3. Wait for the subprocess to terminate and get its exit code | |
3894 * 4. Prompt the user to press a key to close the console window | |
3895 */ | |
3896 static int | |
2935 | 3897 mch_system_classic(char *cmd, int options) |
7 | 3898 { |
3899 STARTUPINFO si; | |
3900 PROCESS_INFORMATION pi; | |
3901 DWORD ret = 0; | |
3902 HWND hwnd = GetFocus(); | |
3903 | |
3904 si.cb = sizeof(si); | |
3905 si.lpReserved = NULL; | |
3906 si.lpDesktop = NULL; | |
3907 si.lpTitle = NULL; | |
3908 si.dwFlags = STARTF_USESHOWWINDOW; | |
3909 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3910 * It's nicer to run a filter command in a minimized window. |
2643 | 3911 * Don't activate the window to keep focus on Vim. |
7 | 3912 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3913 if (options & SHELL_DOOUT) |
2643 | 3914 si.wShowWindow = SW_SHOWMINNOACTIVE; |
7 | 3915 else |
3916 si.wShowWindow = SW_SHOWNORMAL; | |
3917 si.cbReserved2 = 0; | |
3918 si.lpReserved2 = NULL; | |
3919 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3920 // Now, run the command |
5547 | 3921 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
|
3922 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
|
3923 &si, &pi, NULL, NULL); |
7 | 3924 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3925 // Wait for the command to terminate before continuing |
7 | 3926 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3927 # ifdef FEAT_GUI |
7 | 3928 int delay = 1; |
3929 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3930 // Keep updating the window while waiting for the shell to finish. |
7 | 3931 for (;;) |
3932 { | |
3933 MSG msg; | |
3934 | |
3010 | 3935 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
7 | 3936 { |
3937 TranslateMessage(&msg); | |
3010 | 3938 pDispatchMessage(&msg); |
3720 | 3939 delay = 1; |
3940 continue; | |
7 | 3941 } |
3942 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
3943 break; | |
3944 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3945 // We start waiting for a very short time and then increase it, so |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3946 // that we respond quickly when the process is quick, and don't |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3947 // consume too much overhead when it's slow. |
7 | 3948 if (delay < 50) |
3949 delay += 10; | |
3950 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3951 # else |
7 | 3952 WaitForSingleObject(pi.hProcess, INFINITE); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3953 # endif |
7 | 3954 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3955 // Get the command exit code |
7 | 3956 GetExitCodeProcess(pi.hProcess, &ret); |
3957 } | |
3958 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3959 // Close the handles to the subprocess, so that it goes away |
7 | 3960 CloseHandle(pi.hThread); |
3961 CloseHandle(pi.hProcess); | |
3962 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3963 // Try to get input focus back. Doesn't always work though. |
7 | 3964 PostMessage(hwnd, WM_SETFOCUS, 0, 0); |
3965 | |
3966 return ret; | |
3967 } | |
2935 | 3968 |
3969 /* | |
3970 * Thread launched by the gui to send the current buffer data to the | |
3971 * process. This way avoid to hang up vim totally if the children | |
3972 * process take a long time to process the lines. | |
3973 */ | |
9750
0f4b76b2757a
commit https://github.com/vim/vim/commit/4c38d66d25e4ba433fe87283a4664425a3dbd529
Christian Brabandt <cb@256bit.org>
parents:
9740
diff
changeset
|
3974 static unsigned int __stdcall |
2935 | 3975 sub_process_writer(LPVOID param) |
3976 { | |
3977 HANDLE g_hChildStd_IN_Wr = param; | |
3978 linenr_T lnum = curbuf->b_op_start.lnum; | |
3979 DWORD len = 0; | |
3980 DWORD l; | |
3981 char_u *lp = ml_get(lnum); | |
3982 char_u *s; | |
3983 int written = 0; | |
3984 | |
3985 for (;;) | |
3986 { | |
3987 l = (DWORD)STRLEN(lp + written); | |
3988 if (l == 0) | |
3989 len = 0; | |
3990 else if (lp[written] == NL) | |
3991 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3992 // NL -> NUL translation |
2935 | 3993 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); |
3994 } | |
3995 else | |
3996 { | |
3997 s = vim_strchr(lp + written, NL); | |
3998 WriteFile(g_hChildStd_IN_Wr, (char *)lp + written, | |
3999 s == NULL ? l : (DWORD)(s - (lp + written)), | |
4000 &len, NULL); | |
4001 } | |
4002 if (len == (int)l) | |
4003 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4004 // Finished a line, add a NL, unless this line should not have |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4005 // one. |
2935 | 4006 if (lnum != curbuf->b_op_end.lnum |
6933 | 4007 || (!curbuf->b_p_bin |
4008 && curbuf->b_p_fixeol) | |
2935 | 4009 || (lnum != curbuf->b_no_eol_lnum |
4010 && (lnum != curbuf->b_ml.ml_line_count | |
4011 || curbuf->b_p_eol))) | |
4012 { | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14673
diff
changeset
|
4013 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
|
4014 (LPDWORD)&vim_ignored, NULL); |
2935 | 4015 } |
4016 | |
4017 ++lnum; | |
4018 if (lnum > curbuf->b_op_end.lnum) | |
4019 break; | |
4020 | |
4021 lp = ml_get(lnum); | |
4022 written = 0; | |
4023 } | |
4024 else if (len > 0) | |
4025 written += len; | |
4026 } | |
4027 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4028 // finished all the lines, close pipe |
2935 | 4029 CloseHandle(g_hChildStd_IN_Wr); |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4030 return 0; |
2935 | 4031 } |
4032 | |
4033 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4034 # define BUFLEN 100 // length for buffer, stolen from unix version |
2935 | 4035 |
4036 /* | |
4037 * This function read from the children's stdout and write the | |
4038 * data on screen or in the buffer accordingly. | |
4039 */ | |
4040 static void | |
4041 dump_pipe(int options, | |
4042 HANDLE g_hChildStd_OUT_Rd, | |
4043 garray_T *ga, | |
4044 char_u buffer[], | |
4045 DWORD *buffer_off) | |
4046 { | |
4047 DWORD availableBytes = 0; | |
4048 DWORD i; | |
4049 int ret; | |
4050 DWORD len; | |
4051 DWORD toRead; | |
4052 int repeatCount; | |
4053 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4054 // we query the pipe to see if there is any data to read |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4055 // to avoid to perform a blocking read |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4056 ret = PeekNamedPipe(g_hChildStd_OUT_Rd, // pipe to query |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4057 NULL, // optional buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4058 0, // buffer size |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4059 NULL, // number of read bytes |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4060 &availableBytes, // available bytes total |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4061 NULL); // byteLeft |
2935 | 4062 |
4063 repeatCount = 0; | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4064 // We got real data in the pipe, read it |
3622 | 4065 while (ret != 0 && availableBytes > 0) |
2935 | 4066 { |
4067 repeatCount++; | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
4068 toRead = (DWORD)(BUFLEN - *buffer_off); |
2935 | 4069 toRead = availableBytes < toRead ? availableBytes : toRead; |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
4070 ReadFile(g_hChildStd_OUT_Rd, buffer + *buffer_off, toRead , &len, NULL); |
2935 | 4071 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4072 // If we haven't read anything, there is a problem |
2935 | 4073 if (len == 0) |
4074 break; | |
4075 | |
4076 availableBytes -= len; | |
4077 | |
4078 if (options & SHELL_READ) | |
4079 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4080 // Do NUL -> NL translation, append NL separated |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4081 // lines to the current buffer. |
2935 | 4082 for (i = 0; i < len; ++i) |
4083 { | |
4084 if (buffer[i] == NL) | |
4085 append_ga_line(ga); | |
4086 else if (buffer[i] == NUL) | |
4087 ga_append(ga, NL); | |
4088 else | |
4089 ga_append(ga, buffer[i]); | |
4090 } | |
4091 } | |
4092 else if (has_mbyte) | |
4093 { | |
4094 int l; | |
3030 | 4095 int c; |
4096 char_u *p; | |
2935 | 4097 |
4098 len += *buffer_off; | |
4099 buffer[len] = NUL; | |
4100 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4101 // Check if the last character in buffer[] is |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4102 // incomplete, keep these bytes for the next |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4103 // round. |
2935 | 4104 for (p = buffer; p < buffer + len; p += l) |
4105 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9762
diff
changeset
|
4106 l = MB_CPTR2LEN(p); |
2935 | 4107 if (l == 0) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4108 l = 1; // NUL byte? |
2935 | 4109 else if (MB_BYTE2LEN(*p) != l) |
4110 break; | |
4111 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4112 if (p == buffer) // no complete character |
2935 | 4113 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4114 // avoid getting stuck at an illegal byte |
2935 | 4115 if (len >= 12) |
4116 ++p; | |
4117 else | |
4118 { | |
4119 *buffer_off = len; | |
4120 return; | |
4121 } | |
4122 } | |
4123 c = *p; | |
4124 *p = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4125 msg_puts((char *)buffer); |
2935 | 4126 if (p < buffer + len) |
4127 { | |
4128 *p = c; | |
4129 *buffer_off = (DWORD)((buffer + len) - p); | |
4130 mch_memmove(buffer, p, *buffer_off); | |
4131 return; | |
4132 } | |
4133 *buffer_off = 0; | |
4134 } | |
4135 else | |
4136 { | |
4137 buffer[len] = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4138 msg_puts((char *)buffer); |
2935 | 4139 } |
4140 | |
4141 windgoto(msg_row, msg_col); | |
4142 cursor_on(); | |
4143 out_flush(); | |
4144 } | |
4145 } | |
4146 | |
4147 /* | |
4148 * Version of system to use for windows NT > 5.0 (Win2K), use pipe | |
4149 * for communication and doesn't open any new window. | |
4150 */ | |
4151 static int | |
4152 mch_system_piped(char *cmd, int options) | |
4153 { | |
4154 STARTUPINFO si; | |
4155 PROCESS_INFORMATION pi; | |
4156 DWORD ret = 0; | |
4157 | |
4158 HANDLE g_hChildStd_IN_Rd = NULL; | |
4159 HANDLE g_hChildStd_IN_Wr = NULL; | |
4160 HANDLE g_hChildStd_OUT_Rd = NULL; | |
4161 HANDLE g_hChildStd_OUT_Wr = NULL; | |
4162 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4163 char_u buffer[BUFLEN + 1]; // reading buffer + size |
2935 | 4164 DWORD len; |
4165 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4166 // buffer used to receive keys |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4167 char_u ta_buf[BUFLEN + 1]; // TypeAHead |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4168 int ta_len = 0; // valid bytes in ta_buf[] |
2935 | 4169 |
4170 DWORD i; | |
4171 int c; | |
4172 int noread_cnt = 0; | |
4173 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
|
4174 int delay = 1; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4175 DWORD buffer_off = 0; // valid bytes in buffer[] |
3361 | 4176 char *p = NULL; |
2935 | 4177 |
4178 SECURITY_ATTRIBUTES saAttr; | |
4179 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4180 // Set the bInheritHandle flag so pipe handles are inherited. |
2935 | 4181 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
4182 saAttr.bInheritHandle = TRUE; | |
4183 saAttr.lpSecurityDescriptor = NULL; | |
4184 | |
4185 if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4186 // Ensure the read handle to the pipe for STDOUT is not inherited. |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4187 || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4188 // Create a pipe for the child process's STDIN. |
2935 | 4189 || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4190 // Ensure the write handle to the pipe for STDIN is not inherited. |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4191 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) |
2935 | 4192 { |
4193 CloseHandle(g_hChildStd_IN_Rd); | |
4194 CloseHandle(g_hChildStd_IN_Wr); | |
4195 CloseHandle(g_hChildStd_OUT_Rd); | |
4196 CloseHandle(g_hChildStd_OUT_Wr); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4197 msg_puts(_("\nCannot create pipes\n")); |
2935 | 4198 } |
4199 | |
4200 si.cb = sizeof(si); | |
4201 si.lpReserved = NULL; | |
4202 si.lpDesktop = NULL; | |
4203 si.lpTitle = NULL; | |
4204 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; | |
4205 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4206 // set-up our file redirection |
2935 | 4207 si.hStdError = g_hChildStd_OUT_Wr; |
4208 si.hStdOutput = g_hChildStd_OUT_Wr; | |
4209 si.hStdInput = g_hChildStd_IN_Rd; | |
4210 si.wShowWindow = SW_HIDE; | |
4211 si.cbReserved2 = 0; | |
4212 si.lpReserved2 = NULL; | |
4213 | |
4214 if (options & SHELL_READ) | |
4215 ga_init2(&ga, 1, BUFLEN); | |
4216 | |
3361 | 4217 if (cmd != NULL) |
4218 { | |
4219 p = (char *)vim_strsave((char_u *)cmd); | |
4220 if (p != NULL) | |
4221 unescape_shellxquote((char_u *)p, p_sxe); | |
4222 else | |
4223 p = cmd; | |
4224 } | |
4225 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4226 // Now, run the command. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4227 // About "Inherit handles" being TRUE: this command can be litigious, |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4228 // handle inheritance was deactivated for pending temp file, but, if we |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4229 // 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
|
4230 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
|
4231 &si, &pi, NULL, NULL); |
2935 | 4232 |
3361 | 4233 if (p != cmd) |
4234 vim_free(p); | |
2935 | 4235 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4236 // Close our unused side of the pipes |
2935 | 4237 CloseHandle(g_hChildStd_IN_Rd); |
4238 CloseHandle(g_hChildStd_OUT_Wr); | |
4239 | |
4240 if (options & SHELL_WRITE) | |
4241 { | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4242 HANDLE thread = (HANDLE) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4243 _beginthreadex(NULL, // security attributes |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4244 0, // default stack size |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4245 sub_process_writer, // function to be executed |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4246 g_hChildStd_IN_Wr, // parameter |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4247 0, // creation flag, start immediately |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4248 NULL); // we don't care about thread id |
2935 | 4249 CloseHandle(thread); |
4250 g_hChildStd_IN_Wr = NULL; | |
4251 } | |
4252 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4253 // Keep updating the window while waiting for the shell to finish. |
2935 | 4254 for (;;) |
4255 { | |
4256 MSG msg; | |
4257 | |
5553 | 4258 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
2935 | 4259 { |
4260 TranslateMessage(&msg); | |
5553 | 4261 pDispatchMessage(&msg); |
2935 | 4262 } |
4263 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4264 // write pipe information in the window |
2935 | 4265 if ((options & (SHELL_READ|SHELL_WRITE)) |
4266 # ifdef FEAT_GUI | |
4267 || gui.in_use | |
4268 # endif | |
4269 ) | |
4270 { | |
4271 len = 0; | |
4272 if (!(options & SHELL_EXPAND) | |
4273 && ((options & | |
4274 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4275 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
4276 # ifdef FEAT_GUI | |
4277 || gui.in_use | |
4278 # endif | |
4279 ) | |
4280 && (ta_len > 0 || noread_cnt > 4)) | |
4281 { | |
4282 if (ta_len == 0) | |
4283 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4284 // Get extra characters when we don't have any. Reset the |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4285 // counter and timer. |
2935 | 4286 noread_cnt = 0; |
4287 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4288 } | |
4289 if (ta_len > 0 || len > 0) | |
4290 { | |
4291 /* | |
4292 * For pipes: Check for CTRL-C: send interrupt signal to | |
4293 * child. Check for CTRL-D: EOF, close pipe to child. | |
4294 */ | |
4295 if (len == 1 && cmd != NULL) | |
4296 { | |
4297 if (ta_buf[ta_len] == Ctrl_C) | |
4298 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4299 // Learn what exit code is expected, for |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4300 // now put 9 as SIGKILL |
2935 | 4301 TerminateProcess(pi.hProcess, 9); |
4302 } | |
4303 if (ta_buf[ta_len] == Ctrl_D) | |
4304 { | |
4305 CloseHandle(g_hChildStd_IN_Wr); | |
4306 g_hChildStd_IN_Wr = NULL; | |
4307 } | |
4308 } | |
4309 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4310 // replace K_BS by <BS> and K_DEL by <DEL> |
2935 | 4311 for (i = ta_len; i < ta_len + len; ++i) |
4312 { | |
4313 if (ta_buf[i] == CSI && len - i > 2) | |
4314 { | |
4315 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); | |
4316 if (c == K_DEL || c == K_KDEL || c == K_BS) | |
4317 { | |
4318 mch_memmove(ta_buf + i + 1, ta_buf + i + 3, | |
4319 (size_t)(len - i - 2)); | |
4320 if (c == K_DEL || c == K_KDEL) | |
4321 ta_buf[i] = DEL; | |
4322 else | |
4323 ta_buf[i] = Ctrl_H; | |
4324 len -= 2; | |
4325 } | |
4326 } | |
4327 else if (ta_buf[i] == '\r') | |
4328 ta_buf[i] = '\n'; | |
4329 if (has_mbyte) | |
4330 i += (*mb_ptr2len_len)(ta_buf + i, | |
4331 ta_len + len - i) - 1; | |
4332 } | |
4333 | |
4334 /* | |
4335 * For pipes: echo the typed characters. For a pty this | |
4336 * does not seem to work. | |
4337 */ | |
4338 for (i = ta_len; i < ta_len + len; ++i) | |
4339 { | |
4340 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4341 msg_putchar(ta_buf[i]); | |
4342 else if (has_mbyte) | |
4343 { | |
4344 int l = (*mb_ptr2len)(ta_buf + i); | |
4345 | |
4346 msg_outtrans_len(ta_buf + i, l); | |
4347 i += l - 1; | |
4348 } | |
4349 else | |
4350 msg_outtrans_len(ta_buf + i, 1); | |
4351 } | |
4352 windgoto(msg_row, msg_col); | |
4353 out_flush(); | |
4354 | |
4355 ta_len += len; | |
4356 | |
4357 /* | |
4358 * Write the characters to the child, unless EOF has been | |
4359 * typed for pipes. Write one character at a time, to | |
4360 * avoid losing too much typeahead. When writing buffer | |
4361 * lines, drop the typed characters (only check for | |
4362 * CTRL-C). | |
4363 */ | |
4364 if (options & SHELL_WRITE) | |
4365 ta_len = 0; | |
4366 else if (g_hChildStd_IN_Wr != NULL) | |
4367 { | |
4368 WriteFile(g_hChildStd_IN_Wr, (char*)ta_buf, | |
4369 1, &len, NULL); | |
4370 // if we are typing in, we want to keep things reactive | |
4371 delay = 1; | |
4372 if (len > 0) | |
4373 { | |
4374 ta_len -= len; | |
4375 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4376 } | |
4377 } | |
4378 } | |
4379 } | |
4380 } | |
4381 | |
4382 if (ta_len) | |
4383 ui_inchar_undo(ta_buf, ta_len); | |
4384 | |
4385 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4386 { | |
3030 | 4387 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4388 break; |
4389 } | |
4390 | |
4391 ++noread_cnt; | |
3030 | 4392 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4393 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4394 // We start waiting for a very short time and then increase it, so |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4395 // that we respond quickly when the process is quick, and don't |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4396 // consume too much overhead when it's slow. |
2935 | 4397 if (delay < 50) |
4398 delay += 10; | |
4399 } | |
4400 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4401 // Close the pipe |
2935 | 4402 CloseHandle(g_hChildStd_OUT_Rd); |
4403 if (g_hChildStd_IN_Wr != NULL) | |
4404 CloseHandle(g_hChildStd_IN_Wr); | |
4405 | |
4406 WaitForSingleObject(pi.hProcess, INFINITE); | |
4407 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4408 // Get the command exit code |
2935 | 4409 GetExitCodeProcess(pi.hProcess, &ret); |
4410 | |
4411 if (options & SHELL_READ) | |
4412 { | |
4413 if (ga.ga_len > 0) | |
4414 { | |
4415 append_ga_line(&ga); | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4416 // remember that the NL was missing |
2935 | 4417 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; |
4418 } | |
4419 else | |
4420 curbuf->b_no_eol_lnum = 0; | |
4421 ga_clear(&ga); | |
4422 } | |
4423 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4424 // Close the handles to the subprocess, so that it goes away |
2935 | 4425 CloseHandle(pi.hThread); |
4426 CloseHandle(pi.hProcess); | |
4427 | |
4428 return ret; | |
4429 } | |
4430 | |
4431 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
|
4432 mch_system_g(char *cmd, int options) |
2935 | 4433 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4434 // 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
|
4435 if (!p_stmp) |
2935 | 4436 return mch_system_piped(cmd, options); |
4437 else | |
4438 return mch_system_classic(cmd, options); | |
4439 } | |
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
|
4440 #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
|
4441 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4442 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
5547 | 4443 static int |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
4444 mch_system_c(char *cmd, int options UNUSED) |
5547 | 4445 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4446 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
|
4447 WCHAR *wcmd; |
18241
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4448 char_u *buf; |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4449 size_t len; |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4450 |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4451 // If the command starts and ends with double quotes, enclose the command |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4452 // in parentheses. |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4453 len = STRLEN(cmd); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4454 if (len >= 2 && cmd[0] == '"' && cmd[len - 1] == '"') |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4455 { |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4456 len += 3; |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4457 buf = alloc(len); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4458 if (buf == NULL) |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4459 return -1; |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4460 vim_snprintf((char *)buf, len, "(%s)", cmd); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4461 wcmd = enc_to_utf16(buf, NULL); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4462 free(buf); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4463 } |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4464 else |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4465 wcmd = enc_to_utf16((char_u *)cmd, NULL); |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4466 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4467 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
|
4468 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
|
4469 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4470 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
|
4471 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
|
4472 return ret; |
5547 | 4473 } |
7 | 4474 |
4475 #endif | |
4476 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4477 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
|
4478 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
|
4479 { |
7ae2396cef62
patch 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 #ifdef VIMDLL |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4481 if (gui.in_use || gui.starting) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4482 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
|
4483 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
|
4484 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
|
4485 #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
|
4486 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
|
4487 #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
|
4488 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
|
4489 #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
|
4490 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4491 |
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
|
4492 #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
|
4493 /* |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4494 * 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
|
4495 */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4496 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
|
4497 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
|
4498 char_u *cmd, |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4499 int options UNUSED) // SHELL_*, see vim.h |
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
|
4500 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4501 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
|
4502 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
|
4503 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
|
4504 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
|
4505 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
|
4506 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
|
4507 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
|
4508 aco_save_T aco; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4509 oparg_T oa; // operator arguments |
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
|
4510 |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4511 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4512 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
|
4513 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4514 cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
4515 newcmd = alloc(cmdlen); |
13485
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4516 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
|
4517 return 255; |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4518 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4519 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4520 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
|
4521 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
|
4522 } |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4523 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4524 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4525 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
|
4526 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
|
4527 } |
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
|
4528 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4529 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
|
4530 |
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 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
|
4532 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
|
4533 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
|
4534 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
|
4535 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
|
4536 { |
884b683d12e9
patch 8.1.1028: MS-Windows: memory leak when creating terminal fails
Bram Moolenaar <Bram@vim.org>
parents:
16015
diff
changeset
|
4537 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
|
4538 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
|
4539 } |
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
|
4540 |
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
|
4541 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
|
4542 ++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
|
4543 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4544 // Find a window to make "buf" curbuf. |
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
|
4545 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
|
4546 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4547 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
|
4548 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
|
4549 { |
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 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
|
4551 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4552 // If terminal_loop() returns OK we got a key that is handled |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4553 // in Normal model. We don't do redrawing anyway. |
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
|
4554 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
|
4555 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
|
4556 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4557 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
|
4558 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
|
4559 } |
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
|
4560 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
|
4561 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
|
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_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
|
4564 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4565 // restore curwin/curbuf and a few other things |
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 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
|
4567 |
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 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
|
4569 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
|
4570 |
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 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
|
4572 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
|
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 #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
|
4575 |
7 | 4576 /* |
4577 * Either execute a command by calling the shell or start a new shell | |
4578 */ | |
4579 int | |
4580 mch_call_shell( | |
26 | 4581 char_u *cmd, |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4582 int options) // SHELL_*, see vim.h |
7 | 4583 { |
4584 int x = 0; | |
4585 int tmode = cur_tmode; | |
4586 #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
|
4587 WCHAR szShellTitle[512]; |
6293 | 4588 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4589 // 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
|
4590 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
|
4591 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
|
4592 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4593 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
|
4594 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
|
4595 else |
6290 | 4596 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4597 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
|
4598 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4599 if (wn != NULL) |
6290 | 4600 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4601 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
|
4602 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
|
4603 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
|
4604 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
|
4605 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
|
4606 vim_free(wn); |
6290 | 4607 } |
4608 } | |
4609 } | |
7 | 4610 #endif |
4611 | |
4612 out_flush(); | |
4613 | |
4614 #ifdef MCH_WRITE_DUMP | |
4615 if (fdDump) | |
4616 { | |
4617 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options); | |
4618 fflush(fdDump); | |
4619 } | |
4620 #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
|
4621 #if defined(FEAT_GUI) && defined(FEAT_TERMINAL) |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4622 // 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
|
4623 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
|
4624 # ifdef VIMDLL |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4625 gui.in_use && |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4626 # endif |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4627 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
|
4628 && (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
|
4629 { |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4630 char_u *cmdbase = cmd; |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4631 |
18133
d683b2c82c00
patch 8.1.2061: MS-Windows GUI: ":sh" crashes when trying to use a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18064
diff
changeset
|
4632 if (cmdbase != NULL) |
d683b2c82c00
patch 8.1.2061: MS-Windows GUI: ":sh" crashes when trying to use a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18064
diff
changeset
|
4633 // Skip a leading quote and (. |
d683b2c82c00
patch 8.1.2061: MS-Windows GUI: ":sh" crashes when trying to use a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18064
diff
changeset
|
4634 while (*cmdbase == '"' || *cmdbase == '(') |
d683b2c82c00
patch 8.1.2061: MS-Windows GUI: ":sh" crashes when trying to use a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18064
diff
changeset
|
4635 ++cmdbase; |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4636 |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4637 // Check the command does not begin with "start " |
18611
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4638 if (cmdbase == NULL || STRNICMP(cmdbase, "start", 5) != 0 |
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
4639 || !VIM_ISWHITE(cmdbase[5])) |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4640 { |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4641 // Use a terminal window to run the command in. |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4642 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
|
4643 # ifdef FEAT_TITLE |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4644 resettitle(); |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
4645 # endif |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4646 return x; |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4647 } |
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
|
4648 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4649 #endif |
7 | 4650 |
4651 /* | |
4652 * Catch all deadly signals while running the external command, because a | |
4653 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us. | |
4654 */ | |
4655 signal(SIGINT, SIG_IGN); | |
4656 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4657 signal(SIGKILL, SIG_IGN); | |
4658 #else | |
4659 signal(SIGBREAK, SIG_IGN); | |
4660 #endif | |
4661 signal(SIGILL, SIG_IGN); | |
4662 signal(SIGFPE, SIG_IGN); | |
4663 signal(SIGSEGV, SIG_IGN); | |
4664 signal(SIGTERM, SIG_IGN); | |
4665 signal(SIGABRT, SIG_IGN); | |
4666 | |
4667 if (options & SHELL_COOKED) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4668 settmode(TMODE_COOK); // set to normal mode |
7 | 4669 |
4670 if (cmd == NULL) | |
4671 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4672 x = mch_system((char *)p_sh, options); |
7 | 4673 } |
4674 else | |
4675 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4676 // we use "command" or "cmd" to start the shell; slow but easy |
3363 | 4677 char_u *newcmd = NULL; |
4678 char_u *cmdbase = cmd; | |
4679 long_u cmdlen; | |
3361 | 4680 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4681 // Skip a leading ", ( and "(. |
3361 | 4682 if (*cmdbase == '"' ) |
4683 ++cmdbase; | |
4684 if (*cmdbase == '(') | |
4685 ++cmdbase; | |
4686 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4687 if ((STRNICMP(cmdbase, "start", 5) == 0) && VIM_ISWHITE(cmdbase[5])) |
3361 | 4688 { |
4689 STARTUPINFO si; | |
4690 PROCESS_INFORMATION pi; | |
4691 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
|
4692 INT n_show_cmd = SW_SHOWNORMAL; |
3361 | 4693 char_u *p; |
4694 | |
5627 | 4695 ZeroMemory(&si, sizeof(si)); |
3361 | 4696 si.cb = sizeof(si); |
4697 si.lpReserved = NULL; | |
4698 si.lpDesktop = NULL; | |
4699 si.lpTitle = NULL; | |
4700 si.dwFlags = 0; | |
4701 si.cbReserved2 = 0; | |
4702 si.lpReserved2 = NULL; | |
4703 | |
4704 cmdbase = skipwhite(cmdbase + 5); | |
4705 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
|
4706 && VIM_ISWHITE(cmdbase[4])) |
3361 | 4707 { |
4708 cmdbase = skipwhite(cmdbase + 4); | |
4709 si.dwFlags = STARTF_USESHOWWINDOW; | |
4710 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
|
4711 n_show_cmd = SW_SHOWMINNOACTIVE; |
3361 | 4712 } |
4713 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
|
4714 && VIM_ISWHITE(cmdbase[2])) |
3361 | 4715 { |
4716 cmdbase = skipwhite(cmdbase + 2); | |
4717 flags = CREATE_NO_WINDOW; | |
4718 si.dwFlags = STARTF_USESTDHANDLES; | |
4719 si.hStdInput = CreateFile("\\\\.\\NUL", // File name | |
3363 | 4720 GENERIC_READ, // Access flags |
3361 | 4721 0, // Share flags |
3363 | 4722 NULL, // Security att. |
4723 OPEN_EXISTING, // Open flags | |
4724 FILE_ATTRIBUTE_NORMAL, // File att. | |
4725 NULL); // Temp file | |
3361 | 4726 si.hStdOutput = si.hStdInput; |
4727 si.hStdError = si.hStdInput; | |
4728 } | |
4729 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4730 // Remove a trailing ", ) and )" if they have a match |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4731 // at the start of the command. |
3361 | 4732 if (cmdbase > cmd) |
4733 { | |
4734 p = cmdbase + STRLEN(cmdbase); | |
4735 if (p > cmdbase && p[-1] == '"' && *cmd == '"') | |
4736 *--p = NUL; | |
4737 if (p > cmdbase && p[-1] == ')' | |
4738 && (*cmd =='(' || cmd[1] == '(')) | |
4739 *--p = NUL; | |
4740 } | |
4741 | |
3363 | 4742 newcmd = cmdbase; |
4743 unescape_shellxquote(cmdbase, p_sxe); | |
4744 | |
3361 | 4745 /* |
3363 | 4746 * If creating new console, arguments are passed to the |
4747 * 'cmd.exe' as-is. If it's not, arguments are not treated | |
4748 * correctly for current 'cmd.exe'. So unescape characters in | |
4749 * shellxescape except '|' for avoiding to be treated as | |
4750 * argument to them. Pass the arguments to sub-shell. | |
3361 | 4751 */ |
3363 | 4752 if (flags != CREATE_NEW_CONSOLE) |
4753 { | |
4754 char_u *subcmd; | |
3367 | 4755 char_u *cmd_shell = mch_getenv("COMSPEC"); |
4756 | |
4757 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
|
4758 cmd_shell = (char_u *)default_shell(); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4759 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4760 subcmd = vim_strsave_escaped_ext(cmdbase, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4761 (char_u *)"|", '^', FALSE); |
3363 | 4762 if (subcmd != NULL) |
4763 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4764 // make "cmd.exe /c arguments" |
3363 | 4765 cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5; |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
4766 newcmd = alloc(cmdlen); |
3363 | 4767 if (newcmd != NULL) |
4768 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s", | |
3367 | 4769 cmd_shell, subcmd); |
3363 | 4770 else |
4771 newcmd = cmdbase; | |
3367 | 4772 vim_free(subcmd); |
3363 | 4773 } |
4774 } | |
3361 | 4775 |
4776 /* | |
4777 * Now, start the command as a process, so that it doesn't | |
4778 * inherit our handles which causes unpleasant dangling swap | |
4779 * files if we exit before the spawned process | |
4780 */ | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4781 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
|
4782 &si, &pi, NULL, NULL)) |
3361 | 4783 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
|
4784 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
|
4785 > (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
|
4786 x = 0; |
3361 | 4787 else |
4788 { | |
4789 x = -1; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4790 #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
|
4791 # 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
|
4792 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
|
4793 # 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
|
4794 emsg(_("E371: Command not found")); |
3361 | 4795 #endif |
4796 } | |
3363 | 4797 |
4798 if (newcmd != cmdbase) | |
4799 vim_free(newcmd); | |
4800 | |
5627 | 4801 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) |
3361 | 4802 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4803 // Close the handle to \\.\NUL created above. |
3361 | 4804 CloseHandle(si.hStdInput); |
4805 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4806 // Close the handles to the subprocess, so that it goes away |
3361 | 4807 CloseHandle(pi.hThread); |
4808 CloseHandle(pi.hProcess); | |
4809 } | |
4810 else | |
4811 { | |
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
|
4812 cmdlen = |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4813 #ifdef FEAT_GUI_MSWIN |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4814 ((gui.in_use || gui.starting) ? |
16584
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4815 (!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
|
4816 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
|
4817 : 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
|
4818 #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
|
4819 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; |
1569 | 4820 |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
4821 newcmd = alloc(cmdlen); |
3361 | 4822 if (newcmd != NULL) |
7 | 4823 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4824 #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
|
4825 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
|
4826 # ifdef VIMDLL |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4827 (gui.in_use || gui.starting) && |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4828 # 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
|
4829 need_vimrun_warning) |
7 | 4830 { |
10400
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4831 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
|
4832 "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
|
4833 "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
|
4834 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
|
4835 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
|
4836 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
|
4837 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4838 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
|
4839 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
|
4840 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
|
4841 vim_free(wtitle); |
7 | 4842 need_vimrun_warning = FALSE; |
4843 } | |
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
|
4844 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
|
4845 # ifdef VIMDLL |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4846 (gui.in_use || gui.starting) && |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4847 # 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
|
4848 !s_dont_use_vimrun && p_stmp) |
16750
8050cde51945
patch 8.1.1377: MS-Windows GUI uses wrong shell command for bash
Bram Moolenaar <Bram@vim.org>
parents:
16734
diff
changeset
|
4849 // Use vimrun to execute the command. It opens a console |
8050cde51945
patch 8.1.1377: MS-Windows GUI uses wrong shell command for bash
Bram Moolenaar <Bram@vim.org>
parents:
16734
diff
changeset
|
4850 // 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
|
4851 vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s", |
7 | 4852 vimrun_path, |
4853 (msg_silent != 0 || (options & SHELL_DOOUT)) | |
4854 ? "-s " : "", | |
4855 p_sh, p_shcf, cmd); | |
16750
8050cde51945
patch 8.1.1377: MS-Windows GUI uses wrong shell command for bash
Bram Moolenaar <Bram@vim.org>
parents:
16734
diff
changeset
|
4856 else if ( |
16584
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4857 # ifdef VIMDLL |
16750
8050cde51945
patch 8.1.1377: MS-Windows GUI uses wrong shell command for bash
Bram Moolenaar <Bram@vim.org>
parents:
16734
diff
changeset
|
4858 (gui.in_use || gui.starting) && |
16584
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4859 # endif |
17569
9544335db006
patch 8.1.1782: MS-Windows: system() has temp file error with 'noshelltemp'
Bram Moolenaar <Bram@vim.org>
parents:
17393
diff
changeset
|
4860 s_dont_use_vimrun && STRCMP(p_shcf, "/c") == 0) |
16750
8050cde51945
patch 8.1.1377: MS-Windows GUI uses wrong shell command for bash
Bram Moolenaar <Bram@vim.org>
parents:
16734
diff
changeset
|
4861 // workaround for the case that "vimrun" does not exist |
16584
29a0a549c790
patch 8.1.1295: when vimrun.exe does not exist external command may fail
Bram Moolenaar <Bram@vim.org>
parents:
16455
diff
changeset
|
4862 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
|
4863 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
|
4864 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
|
4865 #endif |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4866 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", |
1569 | 4867 p_sh, p_shcf, cmd); |
7 | 4868 x = mch_system((char *)newcmd, options); |
3361 | 4869 vim_free(newcmd); |
7 | 4870 } |
4871 } | |
4872 } | |
4873 | |
4874 if (tmode == TMODE_RAW) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4875 settmode(TMODE_RAW); // set to raw mode |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4876 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4877 // Print the return value, unless "vimrun" was used. |
7 | 4878 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
|
4879 #if defined(FEAT_GUI_MSWIN) |
16734
e3feaa3e5f10
patch 8.1.1369: get E484 when using system() during GUI startup
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4880 && ((gui.in_use || gui.starting) ? |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4881 ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) : 1) |
7 | 4882 #endif |
4883 ) | |
4884 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
4885 smsg(_("shell returned %d"), x); |
7 | 4886 msg_putchar('\n'); |
4887 } | |
4888 #ifdef FEAT_TITLE | |
4889 resettitle(); | |
4890 #endif | |
4891 | |
4892 signal(SIGINT, SIG_DFL); | |
4893 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4894 signal(SIGKILL, SIG_DFL); | |
4895 #else | |
4896 signal(SIGBREAK, SIG_DFL); | |
4897 #endif | |
4898 signal(SIGILL, SIG_DFL); | |
4899 signal(SIGFPE, SIG_DFL); | |
4900 signal(SIGSEGV, SIG_DFL); | |
4901 signal(SIGTERM, SIG_DFL); | |
4902 signal(SIGABRT, SIG_DFL); | |
4903 | |
4904 return x; | |
4905 } | |
4906 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
4907 #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
|
4908 static HANDLE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4909 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
|
4910 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
|
4911 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
|
4912 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
|
4913 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
|
4914 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
|
4915 DWORD dwFlagsAndAttributes) |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4916 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4917 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
|
4918 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
|
4919 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4920 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
|
4921 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
|
4922 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
|
4923 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4924 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
|
4925 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
|
4926 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
|
4927 vim_free(wn); |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4928 return h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4929 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
4930 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4931 /* |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4932 * 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
|
4933 * 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
|
4934 */ |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12140
diff
changeset
|
4935 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
|
4936 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
|
4937 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4938 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
|
4939 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
|
4940 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
|
4941 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4942 // for last \0 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4943 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
|
4944 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4945 |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4946 if (base) |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4947 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4948 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
|
4949 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4950 // for last \0 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4951 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
|
4952 return; |
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 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
|
4955 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4956 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
|
4957 *((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
|
4958 p++; |
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 FreeEnvironmentStrings(base); |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4961 *((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
|
4962 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4963 |
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
|
4964 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
|
4965 { |
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
|
4966 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
|
4967 { |
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
|
4968 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
|
4969 { |
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
|
4970 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
|
4971 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
|
4972 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
|
4973 --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
|
4974 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
|
4975 { |
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 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
|
4977 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
|
4978 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
|
4979 |
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 (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
|
4981 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
|
4982 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
|
4983 *((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
|
4984 *((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
|
4985 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
|
4986 *((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
|
4987 *((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
|
4988 } |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
4989 vim_free(wkey); |
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
4990 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
|
4991 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4992 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4993 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4994 |
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
|
4995 # 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
|
4996 { |
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
|
4997 # 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
|
4998 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
|
4999 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
|
5000 # 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
|
5001 # 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
|
5002 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
|
5003 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
|
5004 # endif |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5005 // 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
|
5006 // 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
|
5007 // 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
|
5008 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
|
5009 # 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
|
5010 + 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
|
5011 # 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
|
5012 # 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
|
5013 + 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
|
5014 # 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
|
5015 ; |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5016 |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5017 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
|
5018 { |
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
|
5019 # 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
|
5020 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
|
5021 *((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
|
5022 (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
|
5023 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
|
5024 *((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
|
5025 (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
|
5026 *((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
|
5027 # 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
|
5028 # 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
|
5029 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
|
5030 { |
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 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
|
5032 *((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
|
5033 (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
|
5034 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
|
5035 *((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
|
5036 (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
|
5037 *((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
|
5038 } |
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 |
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
|
5040 } |
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
|
5041 } |
14067
39ec4b90e4a7
patch 8.1.0051: MS-Windows: missing #endif
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
5042 # endif |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5043 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5044 |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5045 /* |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5046 * 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
|
5047 * 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
|
5048 */ |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5049 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
|
5050 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
|
5051 { |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5052 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
|
5053 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
|
5054 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
|
5055 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5056 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
|
5057 GetCurrentProcessId(), |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5058 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
|
5059 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5060 // 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
|
5061 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
|
5062 name, |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5063 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
|
5064 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
|
5065 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
|
5066 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5067 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
|
5068 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
|
5069 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5070 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
|
5071 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
|
5072 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
|
5073 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5074 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
|
5075 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
|
5076 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
|
5077 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
|
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[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
|
5080 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5081 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
|
5082 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
|
5083 } |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5084 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5085 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
|
5086 } |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5087 |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5088 void |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11230
diff
changeset
|
5089 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
|
5090 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5091 STARTUPINFO si; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5092 PROCESS_INFORMATION pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5093 HANDLE jo; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5094 SECURITY_ATTRIBUTES saAttr; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5095 channel_T *channel = NULL; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5096 HANDLE ifd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5097 HANDLE ofd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5098 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
|
5099 garray_T ga; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5100 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5101 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
|
5102 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
|
5103 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
|
5104 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
|
5105 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
|
5106 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
|
5107 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
|
5108 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5109 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
|
5110 use_null_for_err = TRUE; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5111 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5112 ifd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5113 ifd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5114 ofd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5115 ofd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5116 efd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5117 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
|
5118 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
|
5119 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5120 jo = CreateJobObject(NULL, NULL); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5121 if (jo == NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5122 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5123 job->jv_status = JOB_FAILED; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5124 goto failed; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5125 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5126 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5127 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
|
5128 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
|
5129 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5130 ZeroMemory(&pi, sizeof(pi)); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5131 ZeroMemory(&si, sizeof(si)); |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5132 si.cb = sizeof(si); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5133 si.dwFlags |= STARTF_USESHOWWINDOW; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5134 si.wShowWindow = SW_HIDE; |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5135 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5136 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5137 saAttr.bInheritHandle = TRUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5138 saAttr.lpSecurityDescriptor = NULL; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5139 |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5140 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5141 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5142 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
|
5143 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5144 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
|
5145 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5146 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5147 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
|
5148 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5149 semsg(_(e_notopen), fname); |
8443
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5150 goto failed; |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5151 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5152 } |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5153 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
|
5154 && (!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
|
5155 || !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
|
5156 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5157 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5158 if (use_file_for_out) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5159 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5160 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
|
5161 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5162 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
|
5163 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5164 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5165 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
|
5166 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5167 semsg(_(e_notopen), fname); |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5168 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5169 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5170 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5171 else if (!use_null_for_out && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5172 (!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
|
5173 || !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
|
5174 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5175 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5176 if (use_file_for_err) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5177 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5178 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
|
5179 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5180 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
|
5181 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5182 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5183 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
|
5184 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5185 semsg(_(e_notopen), fname); |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5186 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5187 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5188 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5189 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
|
5190 (!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
|
5191 || !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
|
5192 goto failed; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5193 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5194 si.dwFlags |= STARTF_USESTDHANDLES; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5195 si.hStdInput = ifd[0]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5196 si.hStdOutput = ofd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5197 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
|
5198 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5199 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
|
5200 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5201 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5202 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5203 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5204 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5205 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5206 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5207 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5208 channel = add_channel(); |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5209 if (channel == NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5210 goto failed; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5211 } |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5212 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5213 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
|
5214 CREATE_SUSPENDED | |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5215 CREATE_DEFAULT_ERROR_MODE | |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5216 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
|
5217 CREATE_UNICODE_ENVIRONMENT | |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5218 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
|
5219 &si, &pi, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5220 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
|
5221 (char *)options->jo_cwd)) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5222 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5223 CloseHandle(jo); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5224 job->jv_status = JOB_FAILED; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5225 goto failed; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5226 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5227 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5228 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
|
5229 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5230 if (!AssignProcessToJobObject(jo, pi.hProcess)) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5231 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5232 // if failing, switch the way to terminate |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5233 // process with TerminateProcess. |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5234 CloseHandle(jo); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5235 jo = NULL; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5236 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5237 ResumeThread(pi.hThread); |
8479
9f63e4506c40
commit https://github.com/vim/vim/commit/75578a388d2aff59dc330ceccd8894c79b4bc735
Christian Brabandt <cb@256bit.org>
parents:
8471
diff
changeset
|
5238 CloseHandle(pi.hThread); |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5239 job->jv_proc_info = pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5240 job->jv_job_object = jo; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5241 job->jv_status = JOB_STARTED; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5242 |
10060
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5243 CloseHandle(ifd[0]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5244 CloseHandle(ofd[1]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5245 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
|
5246 CloseHandle(efd[1]); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5247 |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5248 job->jv_channel = channel; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5249 if (channel != NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5250 { |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5251 channel_set_pipes(channel, |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5252 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
|
5253 ? INVALID_FD : (sock_T)ifd[1], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5254 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
|
5255 ? INVALID_FD : (sock_T)ofd[0], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5256 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
|
5257 ? INVALID_FD : (sock_T)efd[0]); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5258 channel_set_job(channel, job, options); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5259 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5260 return; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5261 |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5262 failed: |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5263 CloseHandle(ifd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5264 CloseHandle(ofd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5265 CloseHandle(efd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5266 CloseHandle(ifd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5267 CloseHandle(ofd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5268 CloseHandle(efd[1]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5269 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
|
5270 ga_clear(&ga); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5271 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5272 |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5273 char * |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5274 mch_job_status(job_T *job) |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5275 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5276 DWORD dwExitCode = 0; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5277 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5278 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
|
5279 || dwExitCode != STILL_ACTIVE) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5280 { |
8176
477c1d855698
commit https://github.com/vim/vim/commit/eab089d22f172ddd2d33367a998e68c2f1c6c989
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
5281 job->jv_exitval = (int)dwExitCode; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10317
diff
changeset
|
5282 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
|
5283 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5284 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
|
5285 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5286 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5287 return "dead"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5288 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5289 return "run"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5290 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5291 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5292 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5293 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
|
5294 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5295 HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5296 job_T *jobArray[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5297 job_T *job = job_list; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5298 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5299 while (job != NULL) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5300 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5301 DWORD n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5302 DWORD result; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5303 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5304 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
|
5305 && job != NULL; job = job->jv_next) |
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 if (job->jv_status == JOB_STARTED) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5308 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5309 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
|
5310 jobArray[n] = job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5311 ++n; |
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 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5314 if (n == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5315 continue; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5316 result = WaitForMultipleObjects(n, jobHandles, FALSE, 0); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5317 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
|
5318 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5319 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
|
5320 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5321 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
|
5322 return wait_job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5323 } |
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 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5326 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5327 |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5328 static BOOL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5329 terminate_all(HANDLE process, int code) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5330 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5331 PROCESSENTRY32 pe; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5332 HANDLE h = INVALID_HANDLE_VALUE; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5333 DWORD pid = GetProcessId(process); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5334 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5335 if (pid != 0) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5336 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5337 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5338 if (h != INVALID_HANDLE_VALUE) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5339 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5340 pe.dwSize = sizeof(PROCESSENTRY32); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5341 if (!Process32First(h, &pe)) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5342 goto theend; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5343 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5344 do |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5345 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5346 if (pe.th32ParentProcessID == pid) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5347 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5348 HANDLE ph = OpenProcess( |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5349 PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5350 if (ph != NULL) |
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 terminate_all(ph, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5353 CloseHandle(ph); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5354 } |
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 } while (Process32Next(h, &pe)); |
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 CloseHandle(h); |
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 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5361 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5362 theend: |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5363 return TerminateProcess(process, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5364 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5365 |
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 * Send a (deadly) signal to "job". |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5368 * 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
|
5369 */ |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5370 int |
12037
85f0f557661e
patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
5371 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
|
5372 { |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5373 int ret; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5374 |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5375 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
|
5376 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5377 // deadly signal |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5378 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
|
5379 { |
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
|
5380 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
|
5381 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
|
5382 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
|
5383 } |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5384 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
|
5385 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5386 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5387 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
|
5388 return FAIL; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5389 ret = GenerateConsoleCtrlEvent( |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5390 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
|
5391 job->jv_proc_info.dwProcessId) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5392 ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5393 FreeConsole(); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5394 return ret; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5395 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5396 |
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 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5399 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5400 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5401 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5402 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5403 if (job->jv_status != JOB_FAILED) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5404 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5405 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5406 CloseHandle(job->jv_job_object); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5407 CloseHandle(job->jv_proc_info.hProcess); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5408 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5409 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5410 #endif |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5411 |
7 | 5412 |
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
|
5413 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 5414 |
5415 /* | |
5416 * Start termcap mode | |
5417 */ | |
5418 static void | |
5419 termcap_mode_start(void) | |
5420 { | |
5421 DWORD cmodein; | |
5422 | |
5423 if (g_fTermcapMode) | |
5424 return; | |
5425 | |
5426 SaveConsoleBuffer(&g_cbNonTermcap); | |
5427 | |
5428 if (g_cbTermcap.IsValid) | |
5429 { | |
5430 /* | |
5431 * We've been in termcap mode before. Restore certain screen | |
5432 * characteristics, including the buffer size and the window | |
5433 * size. Since we will be redrawing the screen, we don't need | |
5434 * to restore the actual contents of the buffer. | |
5435 */ | |
5436 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
|
5437 reset_console_color_rgb(); |
7 | 5438 SetConsoleWindowInfo(g_hConOut, TRUE, &g_cbTermcap.Info.srWindow); |
5439 Rows = g_cbTermcap.Info.dwSize.Y; | |
5440 Columns = g_cbTermcap.Info.dwSize.X; | |
5441 } | |
5442 else | |
5443 { | |
5444 /* | |
5445 * This is our first time entering termcap mode. Clear the console | |
5446 * screen buffer, and resize the buffer to match the current window | |
5447 * size. We will use this as the size of our editing environment. | |
5448 */ | |
5449 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
|
5450 set_console_color_rgb(); |
7 | 5451 ResizeConBufAndWindow(g_hConOut, Columns, Rows); |
5452 } | |
5453 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5454 # ifdef FEAT_TITLE |
7 | 5455 resettitle(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5456 # endif |
7 | 5457 |
5458 GetConsoleMode(g_hConIn, &cmodein); | |
5459 if (g_fMouseActive) | |
5460 cmodein |= ENABLE_MOUSE_INPUT; | |
5461 else | |
5462 cmodein &= ~ENABLE_MOUSE_INPUT; | |
5463 cmodein |= ENABLE_WINDOW_INPUT; | |
5464 SetConsoleMode(g_hConIn, cmodein); | |
5465 | |
5466 redraw_later_clear(); | |
5467 g_fTermcapMode = TRUE; | |
5468 } | |
5469 | |
5470 | |
5471 /* | |
5472 * End termcap mode | |
5473 */ | |
5474 static void | |
5475 termcap_mode_end(void) | |
5476 { | |
5477 DWORD cmodein; | |
5478 ConsoleBuffer *cb; | |
5479 COORD coord; | |
5480 DWORD dwDummy; | |
5481 | |
5482 if (!g_fTermcapMode) | |
5483 return; | |
5484 | |
5485 SaveConsoleBuffer(&g_cbTermcap); | |
5486 | |
5487 GetConsoleMode(g_hConIn, &cmodein); | |
5488 cmodein &= ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT); | |
5489 SetConsoleMode(g_hConIn, cmodein); | |
5490 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5491 # ifdef FEAT_RESTORE_ORIG_SCREEN |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5492 cb = exiting ? &g_cbOrig : &g_cbNonTermcap; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5493 # else |
7 | 5494 cb = &g_cbNonTermcap; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5495 # endif |
7 | 5496 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
|
5497 reset_console_color_rgb(); |
7 | 5498 SetConsoleCursorInfo(g_hConOut, &g_cci); |
5499 | |
5500 if (p_rs || exiting) | |
5501 { | |
5502 /* | |
5503 * Clear anything that happens to be on the current line. | |
5504 */ | |
5505 coord.X = 0; | |
5506 coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); | |
5507 FillConsoleOutputCharacter(g_hConOut, ' ', | |
5508 cb->Info.dwSize.X, coord, &dwDummy); | |
5509 /* | |
5510 * The following is just for aesthetics. If we are exiting without | |
5511 * restoring the screen, then we want to have a prompt string | |
5512 * appear at the bottom line. However, the command interpreter | |
5513 * seems to always advance the cursor one line before displaying | |
5514 * the prompt string, which causes the screen to scroll. To | |
5515 * counter this, move the cursor up one line before exiting. | |
5516 */ | |
5517 if (exiting && !p_rs) | |
5518 coord.Y--; | |
5519 /* | |
5520 * Position the cursor at the leftmost column of the desired row. | |
5521 */ | |
5522 SetConsoleCursorPosition(g_hConOut, coord); | |
5523 } | |
5524 | |
5525 g_fTermcapMode = FALSE; | |
5526 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5527 #endif // FEAT_GUI_MSWIN |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5528 |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5529 |
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
|
5530 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 5531 void |
5532 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
|
5533 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
|
5534 int len UNUSED) |
7 | 5535 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5536 // never used |
7 | 5537 } |
5538 | |
5539 #else | |
5540 | |
5541 /* | |
5542 * clear `n' chars, starting from `coord' | |
5543 */ | |
5544 static void | |
5545 clear_chars( | |
5546 COORD coord, | |
5547 DWORD n) | |
5548 { | |
5549 DWORD dwDummy; | |
5550 | |
5551 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
|
5552 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5553 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
|
5554 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
|
5555 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
|
5556 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5557 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
|
5558 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
|
5559 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
|
5560 } |
7 | 5561 } |
5562 | |
5563 | |
5564 /* | |
5565 * Clear the screen | |
5566 */ | |
5567 static void | |
5568 clear_screen(void) | |
5569 { | |
5570 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
|
5571 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5572 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
|
5573 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
|
5574 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5575 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5576 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
|
5577 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
|
5578 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
|
5579 } |
7 | 5580 } |
5581 | |
5582 | |
5583 /* | |
5584 * Clear to end of display | |
5585 */ | |
5586 static void | |
5587 clear_to_end_of_display(void) | |
5588 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5589 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
|
5590 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5591 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
|
5592 clear_chars(g_coord, (Rows - g_coord.Y - 1) |
7 | 5593 * 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
|
5594 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5595 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5596 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
|
5597 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
|
5598 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
|
5599 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5600 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
|
5601 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
|
5602 } |
7 | 5603 } |
5604 | |
5605 | |
5606 /* | |
5607 * Clear to end of line | |
5608 */ | |
5609 static void | |
5610 clear_to_end_of_line(void) | |
5611 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5612 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
|
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 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
|
5615 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
|
5616 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5617 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5618 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
|
5619 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
|
5620 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
|
5621 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5622 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
|
5623 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
|
5624 } |
7 | 5625 } |
5626 | |
5627 | |
5628 /* | |
5629 * Scroll the scroll region up by `cLines' lines | |
5630 */ | |
5631 static void | |
26 | 5632 scroll(unsigned cLines) |
7 | 5633 { |
5634 COORD oldcoord = g_coord; | |
5635 | |
5636 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); | |
5637 delete_lines(cLines); | |
5638 | |
5639 g_coord = oldcoord; | |
5640 } | |
5641 | |
5642 | |
5643 /* | |
5644 * Set the scroll region | |
5645 */ | |
5646 static void | |
5647 set_scroll_region( | |
5648 unsigned left, | |
5649 unsigned top, | |
5650 unsigned right, | |
5651 unsigned bottom) | |
5652 { | |
5653 if (left >= right | |
5654 || top >= bottom | |
5655 || right > (unsigned) Columns - 1 | |
5656 || bottom > (unsigned) Rows - 1) | |
5657 return; | |
5658 | |
5659 g_srScrollRegion.Left = left; | |
5660 g_srScrollRegion.Top = top; | |
5661 g_srScrollRegion.Right = right; | |
5662 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
|
5663 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5664 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5665 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
|
5666 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
|
5667 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
|
5668 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
|
5669 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5670 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
|
5671 return; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5672 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5673 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
|
5674 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
|
5675 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5676 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5677 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
|
5678 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
|
5679 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
|
5680 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
|
5681 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5682 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
|
5683 return; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5684 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5685 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
|
5686 g_srScrollRegion.Right = right; |
7 | 5687 } |
5688 | |
5689 | |
5690 /* | |
5691 * Insert `cLines' lines at the current cursor position | |
5692 */ | |
5693 static void | |
26 | 5694 insert_lines(unsigned cLines) |
7 | 5695 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5696 SMALL_RECT source, clip; |
7 | 5697 COORD dest; |
5698 CHAR_INFO fill; | |
5699 | |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5700 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
|
5701 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5702 dest.X = g_srScrollRegion.Left; |
7 | 5703 dest.Y = g_coord.Y + cLines; |
5704 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5705 source.Left = g_srScrollRegion.Left; |
7 | 5706 source.Top = g_coord.Y; |
5707 source.Right = g_srScrollRegion.Right; | |
5708 source.Bottom = g_srScrollRegion.Bottom - cLines; | |
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 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
|
5711 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
|
5712 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
|
5713 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
|
5714 |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5715 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
|
5716 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
|
5717 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
|
5718 else |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5719 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
|
5720 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5721 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
|
5722 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5723 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
|
5724 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5725 // 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
|
5726 // 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
|
5727 // 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
|
5728 // 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
|
5729 // 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
|
5730 // direction). |
7 | 5731 |
5732 if (source.Bottom < dest.Y) | |
5733 { | |
5734 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
|
5735 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
|
5736 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5737 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
|
5738 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
|
5739 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5740 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
|
5741 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
|
5742 } |
7 | 5743 } |
5744 } | |
5745 | |
5746 | |
5747 /* | |
5748 * Delete `cLines' lines at the current cursor position | |
5749 */ | |
5750 static void | |
26 | 5751 delete_lines(unsigned cLines) |
7 | 5752 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5753 SMALL_RECT source, clip; |
7 | 5754 COORD dest; |
5755 CHAR_INFO fill; | |
5756 int nb; | |
5757 | |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5758 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
|
5759 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5760 dest.X = g_srScrollRegion.Left; |
7 | 5761 dest.Y = g_coord.Y; |
5762 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5763 source.Left = g_srScrollRegion.Left; |
7 | 5764 source.Top = g_coord.Y + cLines; |
5765 source.Right = g_srScrollRegion.Right; | |
5766 source.Bottom = g_srScrollRegion.Bottom; | |
5767 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5768 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
|
5769 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
|
5770 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
|
5771 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
|
5772 |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5773 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
|
5774 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
|
5775 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
|
5776 else |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5777 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
|
5778 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5779 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
|
5780 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5781 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
|
5782 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5783 // 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
|
5784 // above. |
7 | 5785 |
5786 nb = dest.Y + (source.Bottom - source.Top) + 1; | |
5787 | |
5788 if (nb < source.Top) | |
5789 { | |
5790 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
|
5791 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
|
5792 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5793 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
|
5794 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
|
5795 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5796 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
|
5797 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
|
5798 } |
7 | 5799 } |
5800 } | |
5801 | |
5802 | |
5803 /* | |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5804 * Set the cursor position to (x,y) (1-based). |
7 | 5805 */ |
5806 static void | |
5807 gotoxy( | |
5808 unsigned x, | |
5809 unsigned y) | |
5810 { | |
5811 if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) | |
5812 return; | |
5813 | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5814 if (!USE_VTP) |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5815 { |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5816 // external cursor coords are 1-based; internal are 0-based |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5817 g_coord.X = x - 1; |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5818 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
|
5819 SetConsoleCursorPosition(g_hConOut, g_coord); |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5820 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5821 else |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5822 { |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5823 // Move the cursor to the left edge of the screen to prevent screen |
18275
5218e26c658f
patch 8.1.2132: MS-Windows: screen mess when not recognizing insider build
Bram Moolenaar <Bram@vim.org>
parents:
18241
diff
changeset
|
5824 // destruction. Insider build bug. Always enabled because it's cheap |
5218e26c658f
patch 8.1.2132: MS-Windows: screen mess when not recognizing insider build
Bram Moolenaar <Bram@vim.org>
parents:
18241
diff
changeset
|
5825 // and avoids mistakes with recognizing the build. |
5218e26c658f
patch 8.1.2132: MS-Windows: screen mess when not recognizing insider build
Bram Moolenaar <Bram@vim.org>
parents:
18241
diff
changeset
|
5826 vtp_printf("\033[%d;%dH", g_coord.Y + 1, 1); |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5827 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5828 vtp_printf("\033[%d;%dH", y, x); |
18180
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5829 |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5830 g_coord.X = x - 1; |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5831 g_coord.Y = y - 1; |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
5832 } |
7 | 5833 } |
5834 | |
5835 | |
5836 /* | |
5837 * 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
|
5838 * See ../runtime/doc/os_win32.txt for the numbers. |
7 | 5839 */ |
5840 static void | |
26 | 5841 textattr(WORD wAttr) |
7 | 5842 { |
6710 | 5843 g_attrCurrent = wAttr & 0xff; |
7 | 5844 |
5845 SetConsoleTextAttribute(g_hConOut, wAttr); | |
5846 } | |
5847 | |
5848 | |
5849 static void | |
26 | 5850 textcolor(WORD wAttr) |
7 | 5851 { |
6710 | 5852 g_attrCurrent = (g_attrCurrent & 0xf0) + (wAttr & 0x0f); |
7 | 5853 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5854 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
|
5855 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
|
5856 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5857 vtp_sgr_bulk(wAttr); |
7 | 5858 } |
5859 | |
5860 | |
5861 static void | |
26 | 5862 textbackground(WORD wAttr) |
7 | 5863 { |
6710 | 5864 g_attrCurrent = (g_attrCurrent & 0x0f) + ((wAttr & 0x0f) << 4); |
7 | 5865 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5866 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
|
5867 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
|
5868 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5869 vtp_sgr_bulk(wAttr); |
7 | 5870 } |
5871 | |
5872 | |
5873 /* | |
5874 * restore the default text attribute (whatever we started with) | |
5875 */ | |
5876 static void | |
26 | 5877 normvideo(void) |
7 | 5878 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5879 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
|
5880 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
|
5881 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5882 vtp_sgr_bulk(0); |
7 | 5883 } |
5884 | |
5885 | |
5886 static WORD g_attrPreStandout = 0; | |
5887 | |
5888 /* | |
5889 * Make the text standout, by brightening it | |
5890 */ | |
5891 static void | |
5892 standout(void) | |
5893 { | |
5894 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
|
5895 |
7 | 5896 textattr((WORD) (g_attrCurrent|FOREGROUND_INTENSITY|BACKGROUND_INTENSITY)); |
5897 } | |
5898 | |
5899 | |
5900 /* | |
5901 * Turn off standout mode | |
5902 */ | |
5903 static void | |
26 | 5904 standend(void) |
7 | 5905 { |
5906 if (g_attrPreStandout) | |
5907 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
|
5908 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5909 g_attrPreStandout = 0; |
7 | 5910 } |
5911 | |
5912 | |
5913 /* | |
1199 | 5914 * Set normal fg/bg color, based on T_ME. Called when t_me has been set. |
7 | 5915 */ |
5916 void | |
26 | 5917 mch_set_normal_colors(void) |
7 | 5918 { |
5919 char_u *p; | |
5920 int n; | |
5921 | |
5922 cterm_normal_fg_color = (g_attrDefault & 0xf) + 1; | |
5923 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
|
5924 if ( |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5925 # ifdef FEAT_TERMGUICOLORS |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5926 !p_tgc && |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5927 # 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
|
5928 T_ME[0] == ESC && T_ME[1] == '|') |
7 | 5929 { |
5930 p = T_ME + 2; | |
5931 n = getdigits(&p); | |
5932 if (*p == 'm' && n > 0) | |
5933 { | |
5934 cterm_normal_fg_color = (n & 0xf) + 1; | |
5935 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1; | |
5936 } | |
5937 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5938 # ifdef FEAT_TERMGUICOLORS |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5939 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
|
5940 cterm_normal_bg_gui_color = INVALCOLOR; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5941 # endif |
7 | 5942 } |
5943 | |
5944 | |
5945 /* | |
5946 * visual bell: flash the screen | |
5947 */ | |
5948 static void | |
26 | 5949 visual_bell(void) |
7 | 5950 { |
5951 COORD coordOrigin = {0, 0}; | |
5952 WORD attrFlash = ~g_attrCurrent & 0xff; | |
5953 | |
5954 DWORD dwDummy; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
5955 LPWORD oldattrs = ALLOC_MULT(WORD, Rows * Columns); |
7 | 5956 |
5957 if (oldattrs == NULL) | |
5958 return; | |
5959 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
5960 coordOrigin, &dwDummy); | |
5961 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, | |
5962 coordOrigin, &dwDummy); | |
5963 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5964 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
|
5965 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
|
5966 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, |
7 | 5967 coordOrigin, &dwDummy); |
5968 vim_free(oldattrs); | |
5969 } | |
5970 | |
5971 | |
5972 /* | |
5973 * Make the cursor visible or invisible | |
5974 */ | |
5975 static void | |
26 | 5976 cursor_visible(BOOL fVisible) |
7 | 5977 { |
5978 s_cursor_visible = fVisible; | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5979 # ifdef MCH_CURSOR_SHAPE |
7 | 5980 mch_update_cursor(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5981 # endif |
7 | 5982 } |
5983 | |
5984 | |
5985 /* | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
5986 * 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
|
5987 * Returns the number of bytes actually written (at least one). |
7 | 5988 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5989 static DWORD |
7 | 5990 write_chars( |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5991 char_u *pchBuf, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
5992 DWORD cbToWrite) |
7 | 5993 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
5994 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
|
5995 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
|
5996 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
|
5997 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
|
5998 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
|
5999 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
|
6000 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
|
6001 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6002 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
|
6003 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
|
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 vim_free(unicodebuf); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6006 unicodebuf = LALLOC_MULT(WCHAR, length); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6007 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
|
6008 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6009 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
|
6010 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
|
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 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
|
6013 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6014 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
|
6015 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6016 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
|
6017 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
|
6018 // 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
|
6019 // 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
|
6020 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
|
6021 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
|
6022 || 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
|
6023 cchwritten = 1; |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6024 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6025 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6026 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6027 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
|
6028 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
|
6029 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
|
6030 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6031 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6032 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
|
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 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
|
6035 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
|
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 else |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6038 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6039 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
|
6040 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
|
6041 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
|
6042 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
|
6043 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
|
6044 } |
7 | 6045 |
6046 while (g_coord.X > g_srScrollRegion.Right) | |
6047 { | |
6048 g_coord.X -= (SHORT) Columns; | |
6049 if (g_coord.Y < g_srScrollRegion.Bottom) | |
6050 g_coord.Y++; | |
6051 } | |
6052 | |
6053 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
6054 | |
6055 return written; | |
6056 } | |
6057 | |
6058 | |
6059 /* | |
6060 * mch_write(): write the output buffer to the screen, translating ESC | |
6061 * sequences into calls to console output routines. | |
6062 */ | |
6063 void | |
6064 mch_write( | |
6065 char_u *s, | |
6066 int len) | |
6067 { | |
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
|
6068 # 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
|
6069 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
|
6070 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
|
6071 # 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
|
6072 |
7 | 6073 s[len] = NUL; |
6074 | |
6075 if (!term_console) | |
6076 { | |
6077 write(1, s, (unsigned)len); | |
6078 return; | |
6079 } | |
6080 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6081 // translate ESC | sequences into faked bios calls |
7 | 6082 while (len--) |
6083 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6084 // optimization: use one single write_chars for runs of text, |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6085 // 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
|
6086 DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033"); |
7 | 6087 |
6088 if (p_wd) | |
6089 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6090 WaitForChar(p_wd, FALSE); |
7 | 6091 if (prefix != 0) |
6092 prefix = 1; | |
6093 } | |
6094 | |
6095 if (prefix != 0) | |
6096 { | |
6097 DWORD nWritten; | |
6098 | |
6099 nWritten = write_chars(s, prefix); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6100 # ifdef MCH_WRITE_DUMP |
7 | 6101 if (fdDump) |
6102 { | |
6103 fputc('>', fdDump); | |
6104 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6105 fputs("<\n", fdDump); | |
6106 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6107 # endif |
7 | 6108 len -= (nWritten - 1); |
6109 s += nWritten; | |
6110 } | |
6111 else if (s[0] == '\n') | |
6112 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6113 // \n, newline: go to the beginning of the next line or scroll |
7 | 6114 if (g_coord.Y == g_srScrollRegion.Bottom) |
6115 { | |
6116 scroll(1); | |
6117 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1); | |
6118 } | |
6119 else | |
6120 { | |
6121 gotoxy(g_srScrollRegion.Left + 1, g_coord.Y + 2); | |
6122 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6123 # ifdef MCH_WRITE_DUMP |
7 | 6124 if (fdDump) |
6125 fputs("\\n\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6126 # endif |
7 | 6127 s++; |
6128 } | |
6129 else if (s[0] == '\r') | |
6130 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6131 // \r, carriage return: go to beginning of line |
7 | 6132 gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6133 # ifdef MCH_WRITE_DUMP |
7 | 6134 if (fdDump) |
6135 fputs("\\r\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6136 # endif |
7 | 6137 s++; |
6138 } | |
6139 else if (s[0] == '\b') | |
6140 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6141 // \b, backspace: move cursor one position left |
7 | 6142 if (g_coord.X > g_srScrollRegion.Left) |
6143 g_coord.X--; | |
6144 else if (g_coord.Y > g_srScrollRegion.Top) | |
6145 { | |
6146 g_coord.X = g_srScrollRegion.Right; | |
6147 g_coord.Y--; | |
6148 } | |
6149 gotoxy(g_coord.X + 1, g_coord.Y + 1); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6150 # ifdef MCH_WRITE_DUMP |
7 | 6151 if (fdDump) |
6152 fputs("\\b\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6153 # endif |
7 | 6154 s++; |
6155 } | |
6156 else if (s[0] == '\a') | |
6157 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6158 // \a, bell |
7 | 6159 MessageBeep(0xFFFFFFFF); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6160 # ifdef MCH_WRITE_DUMP |
7 | 6161 if (fdDump) |
6162 fputs("\\a\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6163 # endif |
7 | 6164 s++; |
6165 } | |
6166 else if (s[0] == ESC && len >= 3-1 && s[1] == '|') | |
6167 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6168 # ifdef MCH_WRITE_DUMP |
24 | 6169 char_u *old_s = s; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6170 # endif |
24 | 6171 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
|
6172 int arg1 = 0, arg2 = 0, argc = 0, args[16]; |
7 | 6173 |
6174 switch (s[2]) | |
6175 { | |
6176 case '0': case '1': case '2': case '3': case '4': | |
6177 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
|
6178 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
|
6179 do |
7 | 6180 { |
6181 ++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
|
6182 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
|
6183 argc += (argc < 15) ? 1 : 0; |
7 | 6184 if (p > s + len) |
6185 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
|
6186 } 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
|
6187 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6188 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
|
6189 break; |
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 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
|
6192 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
|
6193 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
|
6194 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6195 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
|
6196 normvideo(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6197 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
|
6198 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6199 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
|
6200 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
|
6201 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6202 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
|
6203 } |
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 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
|
6205 vtp_sgr_bulks(argc, args); |
7 | 6206 } |
13314
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 (argc == 2 && *p == 'H') |
7 | 6208 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6209 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
|
6210 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6211 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
|
6212 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6213 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
|
6214 } |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6215 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
|
6216 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6217 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
|
6218 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6219 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
|
6220 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6221 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
|
6222 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6223 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
|
6224 { |
7 | 6225 gotoxy(g_coord.X + 1, |
6226 max(g_srScrollRegion.Top, g_coord.Y - arg1) + 1); | |
6227 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6228 else if (argc == 1 && *p == 'b') |
7 | 6229 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6230 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
|
6231 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6232 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
|
6233 { |
7 | 6234 gotoxy(min(g_srScrollRegion.Right, g_coord.X + arg1) + 1, |
6235 g_coord.Y + 1); | |
6236 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6237 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
|
6238 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6239 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
|
6240 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6241 else if (argc == 1 && *p == 'H') |
7 | 6242 { |
6243 gotoxy(1, arg1); | |
6244 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6245 else if (argc == 1 && *p == 'L') |
7 | 6246 { |
6247 insert_lines(arg1); | |
6248 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6249 else if (argc == 1 && *p == 'M') |
7 | 6250 { |
6251 delete_lines(arg1); | |
6252 } | |
6253 | |
835 | 6254 len -= (int)(p - s); |
7 | 6255 s = p + 1; |
6256 break; | |
6257 | |
6258 case 'A': | |
6259 gotoxy(g_coord.X + 1, | |
6260 max(g_srScrollRegion.Top, g_coord.Y - 1) + 1); | |
6261 goto got3; | |
6262 | |
6263 case 'B': | |
6264 visual_bell(); | |
6265 goto got3; | |
6266 | |
6267 case 'C': | |
6268 gotoxy(min(g_srScrollRegion.Right, g_coord.X + 1) + 1, | |
6269 g_coord.Y + 1); | |
6270 goto got3; | |
6271 | |
6272 case 'E': | |
6273 termcap_mode_end(); | |
6274 goto got3; | |
6275 | |
6276 case 'F': | |
6277 standout(); | |
6278 goto got3; | |
6279 | |
6280 case 'f': | |
6281 standend(); | |
6282 goto got3; | |
6283 | |
6284 case 'H': | |
6285 gotoxy(1, 1); | |
6286 goto got3; | |
6287 | |
6288 case 'j': | |
6289 clear_to_end_of_display(); | |
6290 goto got3; | |
6291 | |
6292 case 'J': | |
6293 clear_screen(); | |
6294 goto got3; | |
6295 | |
6296 case 'K': | |
6297 clear_to_end_of_line(); | |
6298 goto got3; | |
6299 | |
6300 case 'L': | |
6301 insert_lines(1); | |
6302 goto got3; | |
6303 | |
6304 case 'M': | |
6305 delete_lines(1); | |
6306 goto got3; | |
6307 | |
6308 case 'S': | |
6309 termcap_mode_start(); | |
6310 goto got3; | |
6311 | |
6312 case 'V': | |
6313 cursor_visible(TRUE); | |
6314 goto got3; | |
6315 | |
6316 case 'v': | |
6317 cursor_visible(FALSE); | |
6318 goto got3; | |
6319 | |
6320 got3: | |
6321 s += 3; | |
6322 len -= 2; | |
6323 } | |
6324 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6325 # ifdef MCH_WRITE_DUMP |
7 | 6326 if (fdDump) |
6327 { | |
6328 fputs("ESC | ", fdDump); | |
6329 fwrite(old_s + 2, sizeof(char_u), s - old_s - 2, fdDump); | |
6330 fputc('\n', fdDump); | |
6331 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6332 # endif |
7 | 6333 } |
6334 else | |
6335 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6336 // Write a single character |
7 | 6337 DWORD nWritten; |
6338 | |
6339 nWritten = write_chars(s, 1); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6340 # ifdef MCH_WRITE_DUMP |
7 | 6341 if (fdDump) |
6342 { | |
6343 fputc('>', fdDump); | |
6344 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6345 fputs("<\n", fdDump); | |
6346 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6347 # endif |
7 | 6348 |
6349 len -= (nWritten - 1); | |
6350 s += nWritten; | |
6351 } | |
6352 } | |
6353 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6354 # ifdef MCH_WRITE_DUMP |
7 | 6355 if (fdDump) |
6356 fflush(fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6357 # endif |
7 | 6358 } |
6359 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6360 #endif // FEAT_GUI_MSWIN |
7 | 6361 |
6362 | |
6363 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
6364 * Delay for "msec" milliseconds. |
7 | 6365 */ |
6366 void | |
6367 mch_delay( | |
6368 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
|
6369 int ignoreinput UNUSED) |
7 | 6370 { |
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
|
6371 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6372 Sleep((int)msec); // never wait for input |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6373 #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
|
6374 # 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
|
6375 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
|
6376 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6377 Sleep((int)msec); // never wait for input |
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
|
6378 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
|
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 # endif |
7 | 6381 if (ignoreinput) |
14 | 6382 # ifdef FEAT_MZSCHEME |
6383 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq) | |
6384 { | |
6385 int towait = p_mzq; | |
6386 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6387 // if msec is large enough, wait by portions in p_mzq |
14 | 6388 while (msec > 0) |
6389 { | |
6390 mzvim_check_threads(); | |
6391 if (msec < towait) | |
6392 towait = msec; | |
6393 Sleep(towait); | |
6394 msec -= towait; | |
6395 } | |
6396 } | |
6397 else | |
6398 # endif | |
6399 Sleep((int)msec); | |
7 | 6400 else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6401 WaitForChar(msec, FALSE); |
7 | 6402 #endif |
6403 } | |
6404 | |
6405 | |
6406 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6407 * 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
|
6408 * This can also remove a symbolic link like Unix. |
7 | 6409 * Return 0 for success, -1 for failure. |
6410 */ | |
6411 int | |
6412 mch_remove(char_u *name) | |
6413 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6414 WCHAR *wn; |
7 | 6415 int n; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6416 |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6417 /* |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6418 * 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
|
6419 * 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
|
6420 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6421 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
|
6422 return mch_rmdir(name); |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6423 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6424 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6425 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6426 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
|
6427 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
|
6428 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
|
6429 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6430 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
|
6431 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
|
6432 return n; |
7 | 6433 } |
6434 | |
6435 | |
6436 /* | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6437 * Check for an "interrupt signal": CTRL-break or CTRL-C. |
7 | 6438 */ |
6439 void | |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
6440 mch_breakcheck(int force UNUSED) |
7 | 6441 { |
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
|
6442 #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
|
6443 # 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
|
6444 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
|
6445 # 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
|
6446 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
|
6447 { |
7ae2396cef62
patch 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 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
|
6449 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
|
6450 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
|
6451 } |
7 | 6452 #endif |
6453 } | |
6454 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6455 // physical RAM to leave for the OS |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6456 #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
|
6457 |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6458 /* |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6459 * 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
|
6460 */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6461 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
|
6462 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
|
6463 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6464 MEMORYSTATUSEX ms; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6465 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6466 // Need to use GlobalMemoryStatusEx() when there is more memory than |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6467 // what fits in 32 bits. |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6468 ms.dwLength = sizeof(MEMORYSTATUSEX); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6469 GlobalMemoryStatusEx(&ms); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6470 if (ms.ullAvailVirtual < ms.ullTotalPhys) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6471 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6472 // Process address space fits in physical RAM, use all of it. |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6473 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
|
6474 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6475 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
|
6476 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6477 // Catch old NT box or perverse hardware setup. |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6478 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
|
6479 } |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6480 // Use physical RAM less reserve for OS + data. |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6481 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
|
6482 } |
7 | 6483 |
6484 /* | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6485 * mch_wrename() works around a bug in rename (aka MoveFile) in |
7 | 6486 * Windows 95: rename("foo.bar", "foo.bar~") will generate a |
6487 * file whose short file name is "FOO.BAR" (its long file name will | |
6488 * be correct: "foo.bar~"). Because a file can be accessed by | |
6489 * either its SFN or its LFN, "foo.bar" has effectively been | |
6490 * renamed to "foo.bar", which is not at all what was wanted. This | |
6491 * seems to happen only when renaming files with three-character | |
6492 * extensions by appending a suffix that does not include ".". | |
6493 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR". | |
6494 * | |
6495 * There is another problem, which isn't really a bug but isn't right either: | |
6496 * When renaming "abcdef~1.txt" to "abcdef~1.txt~", the short name can be | |
6497 * "abcdef~1.txt" again. This has been reported on Windows NT 4.0 with | |
6498 * service pack 6. Doesn't seem to happen on Windows 98. | |
6499 * | |
6500 * Like rename(), returns 0 upon success, non-zero upon failure. | |
6501 * Should probably set errno appropriately when errors occur. | |
6502 */ | |
6503 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
|
6504 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
|
6505 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6506 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
|
6507 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
|
6508 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
|
6509 WCHAR szNewPath[_MAX_PATH + 1]; |
7 | 6510 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
|
6511 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6512 // 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
|
6513 // 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
|
6514 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
|
6515 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
|
6516 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
|
6517 && 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
|
6518 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
|
6519 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
|
6520 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
|
6521 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6522 // 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
|
6523 // 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
|
6524 if (GetFullPathNameW(wnew, _MAX_PATH, szNewPath, &p) == 0 || p == NULL) |
7 | 6525 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
|
6526 *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
|
6527 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6528 // 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
|
6529 if (GetTempFileNameW(szNewPath, L"VIM", 0, szTempFile) == 0) |
7 | 6530 return -2; |
6531 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6532 // 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
|
6533 if (!DeleteFileW(szTempFile)) |
7 | 6534 return -3; |
6535 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6536 // 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
|
6537 if (!MoveFileW(wold, szTempFile)) |
7 | 6538 return -4; |
6539 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6540 // 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
|
6541 // 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
|
6542 // 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
|
6543 // 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
|
6544 // 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
|
6545 // 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
|
6546 // 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
|
6547 // 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
|
6548 // 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
|
6549 if ((hf = CreateFileW(wold, GENERIC_WRITE, 0, NULL, CREATE_NEW, |
7 | 6550 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) |
6551 return -5; | |
6552 if (!CloseHandle(hf)) | |
6553 return -6; | |
6554 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6555 // 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
|
6556 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
|
6557 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6558 // 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
|
6559 // 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
|
6560 (void)MoveFileW(szTempFile, wold); |
7 | 6561 return -7; |
6562 } | |
6563 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6564 // 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
|
6565 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
|
6566 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6567 // 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
|
6568 if (!DeleteFileW(wold)) |
7 | 6569 return -8; |
6570 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6571 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
|
6572 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6573 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6574 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6575 /* |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6576 * 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
|
6577 * 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
|
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 int |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6580 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
|
6581 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
|
6582 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
|
6583 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6584 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
|
6585 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
|
6586 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
|
6587 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6588 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
|
6589 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
|
6590 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
|
6591 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
|
6592 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
|
6593 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
|
6594 return retval; |
7 | 6595 } |
6596 | |
6597 /* | |
6598 * Get the default shell for the current hardware platform | |
6599 */ | |
6600 char * | |
26 | 6601 default_shell(void) |
7 | 6602 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6603 return "cmd.exe"; |
7 | 6604 } |
6605 | |
6606 /* | |
6607 * mch_access() extends access() to do more detailed check on network drives. | |
6608 * Returns 0 if file "n" has access rights according to "p", -1 otherwise. | |
6609 */ | |
6610 int | |
6611 mch_access(char *n, int p) | |
6612 { | |
6613 HANDLE hFile; | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6614 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
|
6615 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
|
6616 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6617 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
|
6618 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
|
6619 return -1; |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6620 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
6621 if (mch_isdir((char_u *)n)) |
7 | 6622 { |
6623 WCHAR TempNameW[_MAX_PATH + 16] = L""; | |
6624 | |
6625 if (p & R_OK) | |
6626 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6627 // Read check is performed by seeing if we can do a find file on |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6628 // 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
|
6629 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
|
6630 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
|
6631 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6632 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
|
6633 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
|
6634 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
|
6635 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
|
6636 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
|
6637 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
|
6638 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6639 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
|
6640 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
|
6641 goto getout; |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6642 else |
7 | 6643 (void)FindClose(hFile); |
6644 } | |
6645 | |
6646 if (p & W_OK) | |
6647 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6648 // Trying to create a temporary file in the directory should catch |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6649 // directories on read-only network shares. However, in |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6650 // directories whose ACL allows writes but denies deletes will end |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6651 // 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
|
6652 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
|
6653 goto getout; |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6654 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
|
6655 DeleteFileW(TempNameW); |
7 | 6656 } |
6657 } | |
6658 else | |
6659 { | |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
6660 // 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
|
6661 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
|
6662 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6663 // Trying to open the file for the required access does ACL, read-only |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6664 // 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
|
6665 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
|
6666 | ((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
|
6667 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6668 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
|
6669 NULL, OPEN_EXISTING, 0, NULL); |
7 | 6670 if (hFile == INVALID_HANDLE_VALUE) |
6671 goto getout; | |
6672 CloseHandle(hFile); | |
6673 } | |
6674 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6675 retval = 0; // success |
7 | 6676 getout: |
6677 vim_free(wn); | |
6678 return retval; | |
6679 } | |
6680 | |
6681 /* | |
1752 | 6682 * Version of open() that may use UTF-16 file name. |
7 | 6683 */ |
6684 int | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
6685 mch_open(const char *name, int flags, int mode) |
7 | 6686 { |
6687 WCHAR *wn; | |
6688 int f; | |
6689 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6690 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
|
6691 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
|
6692 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
|
6693 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6694 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
|
6695 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
|
6696 return f; |
7 | 6697 } |
6698 | |
6699 /* | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6700 * Version of fopen() that uses UTF-16 file name. |
7 | 6701 */ |
6702 FILE * | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
6703 mch_fopen(const char *name, const char *mode) |
7 | 6704 { |
6705 WCHAR *wn, *wm; | |
6706 FILE *f = NULL; | |
6707 | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6708 #if defined(DEBUG) && _MSC_VER >= 1400 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6709 // Work around an annoying assertion in the Microsoft debug CRT |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6710 // when mode's text/binary setting doesn't match _get_fmode(). |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6711 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
|
6712 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
|
6713 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6714 _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
|
6715 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
|
6716 _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
|
6717 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
|
6718 _set_fmode(_O_BINARY); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6719 #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
|
6720 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
|
6721 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
|
6722 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
|
6723 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
|
6724 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
|
6725 vim_free(wm); |
1569 | 6726 |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6727 #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
|
6728 _set_fmode(oldMode); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6729 #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
|
6730 return f; |
7 | 6731 } |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
6732 |
7 | 6733 /* |
6734 * SUB STREAM (aka info stream) handling: | |
6735 * | |
6736 * NTFS can have sub streams for each file. Normal contents of file is | |
6737 * stored in the main stream, and extra contents (author information and | |
6738 * title and so on) can be stored in sub stream. After Windows 2000, user | |
6739 * can access and store those informations in sub streams via explorer's | |
6740 * property menuitem in right click menu. Those informations in sub streams | |
6741 * were lost when copying only the main stream. So we have to copy sub | |
6742 * streams. | |
6743 * | |
6744 * Incomplete explanation: | |
6745 * http://msdn.microsoft.com/library/en-us/dnw2k/html/ntfs5.asp | |
6746 * More useful info and an example: | |
6747 * http://www.sysinternals.com/ntw2k/source/misc.shtml#streams | |
6748 */ | |
6749 | |
6750 /* | |
6751 * Copy info stream data "substream". Read from the file with BackupRead(sh) | |
6752 * and write to stream "substream" of file "to". | |
6753 * Errors are ignored. | |
6754 */ | |
6755 static void | |
6756 copy_substream(HANDLE sh, void *context, WCHAR *to, WCHAR *substream, long len) | |
6757 { | |
6758 HANDLE hTo; | |
6759 WCHAR *to_name; | |
6760 | |
6761 to_name = malloc((wcslen(to) + wcslen(substream) + 1) * sizeof(WCHAR)); | |
6762 wcscpy(to_name, to); | |
6763 wcscat(to_name, substream); | |
6764 | |
6765 hTo = CreateFileW(to_name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, | |
6766 FILE_ATTRIBUTE_NORMAL, NULL); | |
6767 if (hTo != INVALID_HANDLE_VALUE) | |
6768 { | |
6769 long done; | |
6770 DWORD todo; | |
6771 DWORD readcnt, written; | |
6772 char buf[4096]; | |
6773 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6774 // Copy block of bytes at a time. Abort when something goes wrong. |
7 | 6775 for (done = 0; done < len; done += written) |
6776 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6777 // (size_t) cast for Borland C 5.5 |
835 | 6778 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) |
6779 : (size_t)(len - done)); | |
7 | 6780 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, |
6781 FALSE, FALSE, context) | |
6782 || readcnt != todo | |
6783 || !WriteFile(hTo, buf, todo, &written, NULL) | |
6784 || written != todo) | |
6785 break; | |
6786 } | |
6787 CloseHandle(hTo); | |
6788 } | |
6789 | |
6790 free(to_name); | |
6791 } | |
6792 | |
6793 /* | |
6794 * Copy info streams from file "from" to file "to". | |
6795 */ | |
6796 static void | |
6797 copy_infostreams(char_u *from, char_u *to) | |
6798 { | |
6799 WCHAR *fromw; | |
6800 WCHAR *tow; | |
6801 HANDLE sh; | |
6802 WIN32_STREAM_ID sid; | |
6803 int headersize; | |
6804 WCHAR streamname[_MAX_PATH]; | |
6805 DWORD readcount; | |
6806 void *context = NULL; | |
6807 DWORD lo, hi; | |
6808 int len; | |
6809 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6810 // Convert the file names to wide characters. |
1752 | 6811 fromw = enc_to_utf16(from, NULL); |
6812 tow = enc_to_utf16(to, NULL); | |
7 | 6813 if (fromw != NULL && tow != NULL) |
6814 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6815 // Open the file for reading. |
7 | 6816 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, |
6817 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | |
6818 if (sh != INVALID_HANDLE_VALUE) | |
6819 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6820 // Use BackupRead() to find the info streams. Repeat until we |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6821 // have done them all. |
7 | 6822 for (;;) |
6823 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6824 // Get the header to find the length of the stream name. If |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6825 // the "readcount" is zero we have done all info streams. |
7 | 6826 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); |
835 | 6827 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); |
7 | 6828 if (!BackupRead(sh, (LPBYTE)&sid, headersize, |
6829 &readcount, FALSE, FALSE, &context) | |
6830 || readcount == 0) | |
6831 break; | |
6832 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6833 // We only deal with streams that have a name. The normal |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6834 // file data appears to be without a name, even though docs |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6835 // suggest it is called "::$DATA". |
7 | 6836 if (sid.dwStreamNameSize > 0) |
6837 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6838 // Read the stream name. |
7 | 6839 if (!BackupRead(sh, (LPBYTE)streamname, |
6840 sid.dwStreamNameSize, | |
6841 &readcount, FALSE, FALSE, &context)) | |
6842 break; | |
6843 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6844 // Copy an info stream with a name ":anything:$DATA". |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6845 // Skip "::$DATA", it has no stream name (examples suggest |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6846 // it might be used for the normal file contents). |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6847 // Note that BackupRead() counts bytes, but the name is in |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6848 // wide characters. |
7 | 6849 len = readcount / sizeof(WCHAR); |
6850 streamname[len] = 0; | |
6851 if (len > 7 && wcsicmp(streamname + len - 6, | |
6852 L":$DATA") == 0) | |
6853 { | |
6854 streamname[len - 6] = 0; | |
6855 copy_substream(sh, &context, tow, streamname, | |
10 | 6856 (long)sid.Size.u.LowPart); |
7 | 6857 } |
6858 } | |
6859 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6860 // Advance to the next stream. We might try seeking too far, |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6861 // but BackupSeek() doesn't skip over stream borders, thus |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6862 // that's OK. |
323 | 6863 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, |
7 | 6864 &lo, &hi, &context); |
6865 } | |
6866 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6867 // Clear the context. |
7 | 6868 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); |
6869 | |
6870 CloseHandle(sh); | |
6871 } | |
6872 } | |
6873 vim_free(fromw); | |
6874 vim_free(tow); | |
6875 } | |
6876 | |
6877 /* | |
6878 * Copy file attributes from file "from" to file "to". | |
6879 * For Windows NT and later we copy info streams. | |
6880 * Always returns zero, errors are ignored. | |
6881 */ | |
6882 int | |
6883 mch_copy_file_attribute(char_u *from, char_u *to) | |
6884 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6885 // 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
|
6886 copy_infostreams(from, to); |
7 | 6887 return 0; |
6888 } | |
6889 | |
6890 #if defined(MYRESETSTKOFLW) || defined(PROTO) | |
6891 /* | |
6892 * Recreate a destroyed stack guard page in win32. | |
6893 * Written by Benjamin Peterson. | |
6894 */ | |
6895 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6896 // 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
|
6897 # define MIN_STACK_WINNT 2 |
7 | 6898 |
6899 /* | |
6900 * This function does the same thing as _resetstkoflw(), which is only | |
6901 * available in DevStudio .net and later. | |
6902 * Returns 0 for failure, 1 for success. | |
6903 */ | |
6904 int | |
6905 myresetstkoflw(void) | |
6906 { | |
6907 BYTE *pStackPtr; | |
6908 BYTE *pGuardPage; | |
6909 BYTE *pStackBase; | |
6910 BYTE *pLowestPossiblePage; | |
6911 MEMORY_BASIC_INFORMATION mbi; | |
6912 SYSTEM_INFO si; | |
6913 DWORD nPageSize; | |
6914 DWORD dummy; | |
6915 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6916 // We need to know the system page size. |
7 | 6917 GetSystemInfo(&si); |
6918 nPageSize = si.dwPageSize; | |
6919 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6920 // ...and the current stack pointer |
7 | 6921 pStackPtr = (BYTE*)_alloca(1); |
6922 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6923 // ...and the base of the stack. |
7 | 6924 if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0) |
6925 return 0; | |
6926 pStackBase = (BYTE*)mbi.AllocationBase; | |
6927 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6928 // ...and the page thats min_stack_req pages away from stack base; this is |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6929 // 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
|
6930 pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6931 |
7 | 6932 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6933 // We want the first committed page in the stack Start at the stack |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6934 // base and move forward through memory until we find a committed block. |
7 | 6935 BYTE *pBlock = pStackBase; |
6936 | |
406 | 6937 for (;;) |
7 | 6938 { |
6939 if (VirtualQuery(pBlock, &mbi, sizeof mbi) == 0) | |
6940 return 0; | |
6941 | |
6942 pBlock += mbi.RegionSize; | |
6943 | |
6944 if (mbi.State & MEM_COMMIT) | |
6945 break; | |
6946 } | |
6947 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6948 // mbi now describes the first committed block in the stack. |
7 | 6949 if (mbi.Protect & PAGE_GUARD) |
6950 return 1; | |
6951 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6952 // decide where the guard page should start |
7 | 6953 if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage) |
6954 pGuardPage = pLowestPossiblePage; | |
6955 else | |
6956 pGuardPage = (BYTE*)mbi.BaseAddress; | |
6957 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6958 // allocate the guard page |
7 | 6959 if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE)) |
6960 return 0; | |
6961 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6962 // apply the guard attribute to the page |
7 | 6963 if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD, |
6964 &dummy)) | |
6965 return 0; | |
6966 } | |
6967 | |
6968 return 1; | |
6969 } | |
6970 #endif | |
26 | 6971 |
6972 | |
6973 /* | |
6974 * The command line arguments in UCS2 | |
6975 */ | |
344 | 6976 static int nArgsW = 0; |
26 | 6977 static LPWSTR *ArglistW = NULL; |
6978 static int global_argc = 0; | |
6979 static char **global_argv; | |
6980 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6981 static int used_file_argc = 0; // last argument in global_argv[] used |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6982 // for the argument list. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6983 static int *used_file_indexes = NULL; // indexes in global_argv[] for |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6984 // command line arguments added to |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6985 // the argument list |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6986 static int used_file_count = 0; // nr of entries in used_file_indexes |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6987 static int used_file_literal = FALSE; // take file names literally |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6988 static int used_file_full_path = FALSE; // file name was full path |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6989 static int used_file_diff_mode = FALSE; // file name was with diff mode |
26 | 6990 static int used_alist_count = 0; |
6991 | |
6992 | |
6993 /* | |
6994 * Get the command line arguments. Unicode version. | |
6995 * Returns argc. Zero when something fails. | |
6996 */ | |
6997 int | |
6998 get_cmd_argsW(char ***argvp) | |
6999 { | |
7000 char **argv = NULL; | |
7001 int argc = 0; | |
7002 int i; | |
7003 | |
6193 | 7004 free_cmd_argsW(); |
26 | 7005 ArglistW = CommandLineToArgvW(GetCommandLineW(), &nArgsW); |
7006 if (ArglistW != NULL) | |
7007 { | |
7008 argv = malloc((nArgsW + 1) * sizeof(char *)); | |
7009 if (argv != NULL) | |
7010 { | |
7011 argc = nArgsW; | |
7012 argv[argc] = NULL; | |
7013 for (i = 0; i < argc; ++i) | |
7014 { | |
7015 int len; | |
7016 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7017 // Convert each Unicode argument to the current codepage. |
26 | 7018 WideCharToMultiByte_alloc(GetACP(), 0, |
835 | 7019 ArglistW[i], (int)wcslen(ArglistW[i]) + 1, |
26 | 7020 (LPSTR *)&argv[i], &len, 0, 0); |
7021 if (argv[i] == NULL) | |
7022 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7023 // Out of memory, clear everything. |
26 | 7024 while (i > 0) |
7025 free(argv[--i]); | |
7026 free(argv); | |
5529 | 7027 argv = NULL; |
26 | 7028 argc = 0; |
7029 } | |
7030 } | |
7031 } | |
7032 } | |
7033 | |
7034 global_argc = argc; | |
7035 global_argv = argv; | |
7036 if (argc > 0) | |
6193 | 7037 { |
7038 if (used_file_indexes != NULL) | |
7039 free(used_file_indexes); | |
26 | 7040 used_file_indexes = malloc(argc * sizeof(int)); |
6193 | 7041 } |
26 | 7042 |
7043 if (argvp != NULL) | |
7044 *argvp = argv; | |
7045 return argc; | |
7046 } | |
7047 | |
7048 void | |
7049 free_cmd_argsW(void) | |
7050 { | |
7051 if (ArglistW != NULL) | |
7052 { | |
7053 GlobalFree(ArglistW); | |
7054 ArglistW = NULL; | |
7055 } | |
7056 } | |
7057 | |
7058 /* | |
7059 * Remember "name" is an argument that was added to the argument list. | |
7060 * This avoids that we have to re-parse the argument list when fix_arg_enc() | |
7061 * is called. | |
7062 */ | |
7063 void | |
819 | 7064 used_file_arg(char *name, int literal, int full_path, int diff_mode) |
26 | 7065 { |
7066 int i; | |
7067 | |
7068 if (used_file_indexes == NULL) | |
7069 return; | |
7070 for (i = used_file_argc + 1; i < global_argc; ++i) | |
7071 if (STRCMP(global_argv[i], name) == 0) | |
7072 { | |
7073 used_file_argc = i; | |
7074 used_file_indexes[used_file_count++] = i; | |
7075 break; | |
7076 } | |
7077 used_file_literal = literal; | |
7078 used_file_full_path = full_path; | |
819 | 7079 used_file_diff_mode = diff_mode; |
26 | 7080 } |
7081 | |
7082 /* | |
7083 * Remember the length of the argument list as it was. If it changes then we | |
7084 * leave it alone when 'encoding' is set. | |
7085 */ | |
7086 void | |
7087 set_alist_count(void) | |
7088 { | |
7089 used_alist_count = GARGCOUNT; | |
7090 } | |
7091 | |
7092 /* | |
7093 * Fix the encoding of the command line arguments. Invoked when 'encoding' | |
7094 * has been changed while starting up. Use the UCS-2 command line arguments | |
7095 * and convert them to 'encoding'. | |
7096 */ | |
7097 void | |
7098 fix_arg_enc(void) | |
7099 { | |
7100 int i; | |
7101 int idx; | |
7102 char_u *str; | |
41 | 7103 int *fnum_list; |
26 | 7104 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7105 // Safety checks: |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7106 // - if argument count differs between the wide and non-wide argument |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7107 // list, something must be wrong. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7108 // - the file name arguments must have been located. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7109 // - the length of the argument list wasn't changed by the user. |
344 | 7110 if (global_argc != nArgsW |
26 | 7111 || ArglistW == NULL |
7112 || used_file_indexes == NULL | |
7113 || used_file_count == 0 | |
7114 || used_alist_count != GARGCOUNT) | |
7115 return; | |
7116 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7117 // Remember the buffer numbers for the arguments. |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
7118 fnum_list = ALLOC_MULT(int, GARGCOUNT); |
41 | 7119 if (fnum_list == NULL) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7120 return; // out of memory |
41 | 7121 for (i = 0; i < GARGCOUNT; ++i) |
7122 fnum_list[i] = GARGLIST[i].ae_fnum; | |
7123 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7124 // Clear the argument list. Make room for the new arguments. |
26 | 7125 alist_clear(&global_alist); |
7126 if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7127 return; // out of memory |
26 | 7128 |
7129 for (i = 0; i < used_file_count; ++i) | |
7130 { | |
7131 idx = used_file_indexes[i]; | |
1752 | 7132 str = utf16_to_enc(ArglistW[idx], NULL); |
26 | 7133 if (str != NULL) |
41 | 7134 { |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7135 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
|
7136 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
7137 #ifdef FEAT_DIFF |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7138 // When using diff mode may need to concatenate file name to |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7139 // directory name. Just like it's done in main(). |
819 | 7140 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 |
7141 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
7142 { | |
7143 char_u *r; | |
7144 | |
7145 r = concat_fnames(str, gettail(alist_name(&GARGLIST[0])), TRUE); | |
7146 if (r != NULL) | |
7147 { | |
7148 vim_free(str); | |
7149 str = r; | |
7150 } | |
7151 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
7152 #endif |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7153 // Re-use the old buffer by renaming it. When not using literal |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7154 // names it's done by alist_expand() below. |
41 | 7155 if (used_file_literal) |
7156 buf_set_name(fnum_list[i], str); | |
7157 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7158 // Check backtick literal. backtick literal is already expanded in |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7159 // main.c, so this part add str as literal. |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7160 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
|
7161 { |
12015
7e704d75a882
patch 8.0.0888: compiler warnings with 64 bit build
Christian Brabandt <cb@256bit.org>
parents:
11991
diff
changeset
|
7162 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
|
7163 |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7164 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
|
7165 literal = TRUE; |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7166 } |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7167 alist_add(&global_alist, str, literal ? 2 : 0); |
41 | 7168 } |
26 | 7169 } |
7170 | |
7171 if (!used_file_literal) | |
7172 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7173 // Now expand wildcards in the arguments. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7174 // Temporarily add '(' and ')' to 'isfname'. These are valid |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7175 // filename characters but are excluded from 'isfname' to make |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7176 // "gf" work on a file name in parenthesis (e.g.: see vim.h). |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7177 // Also, unset wildignore to not be influenced by this option. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7178 // The arguments specified in command-line should be kept even if |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7179 // encoding options were changed. |
26 | 7180 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
|
7181 do_cmdline_cmd((char_u *)":let SaVe_WIG = &wig|set wig="); |
41 | 7182 alist_expand(fnum_list, used_alist_count); |
26 | 7183 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
|
7184 do_cmdline_cmd((char_u *)":let &wig = SaVe_WIG|unlet SaVe_WIG"); |
26 | 7185 } |
7186 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7187 // If wildcard expansion failed, we are editing the first file of the |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7188 // arglist and there is no file name: Edit the first argument now. |
26 | 7189 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) |
7190 { | |
7191 do_cmdline_cmd((char_u *)":rewind"); | |
7192 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
|
7193 (void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop"); |
26 | 7194 } |
41 | 7195 |
7196 set_alist_count(); | |
26 | 7197 } |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7198 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7199 int |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
7200 mch_setenv(char *var, char *value, int x UNUSED) |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7201 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7202 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
|
7203 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
|
7204 |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16750
diff
changeset
|
7205 envbuf = alloc(STRLEN(var) + STRLEN(value) + 2); |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7206 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
|
7207 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
|
7208 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7209 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
|
7210 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7211 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
|
7212 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7213 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
|
7214 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
|
7215 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
|
7216 _wputenv(p); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7217 #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
|
7218 libintl_wputenv(p); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7219 #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
|
7220 // 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
|
7221 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
|
7222 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7223 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
|
7224 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7225 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7226 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7227 * 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
|
7228 * 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
|
7229 */ |
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
|
7230 #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
|
7231 |
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
|
7232 /* |
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
|
7233 * Support for pseudo-console (ConPTY) was added in windows 10 |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7234 * version 1809 (October 2018 update). |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7235 */ |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7236 #define CONPTY_FIRST_SUPPORT_BUILD MAKE_VER(10, 0, 17763) |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7237 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7238 /* |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7239 * ConPTY differences between versions, need different logic. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7240 * version 1903 (May 2019 update). |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7241 */ |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7242 #define CONPTY_1903_BUILD MAKE_VER(10, 0, 18362) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7243 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7244 /* |
18611
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7245 * version 1909 (November 2019 update). |
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7246 */ |
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7247 #define CONPTY_1909_BUILD MAKE_VER(10, 0, 18363) |
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7248 |
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7249 /* |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7250 * Confirm until this version. Also the logic changes. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7251 * insider preview. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7252 */ |
18235
88716bc1c20b
patch 8.1.2112: build number for ConPTY is outdated
Bram Moolenaar <Bram@vim.org>
parents:
18180
diff
changeset
|
7253 #define CONPTY_INSIDER_BUILD MAKE_VER(10, 0, 18995) |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7254 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7255 /* |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7256 * Not stable now. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7257 */ |
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
|
7258 #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
|
7259 |
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
|
7260 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
|
7261 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
|
7262 { |
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
|
7263 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
|
7264 #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
|
7265 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
|
7266 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
|
7267 |
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
|
7268 # 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
|
7269 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
|
7270 # 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
|
7271 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7272 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
|
7273 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7274 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
|
7275 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
|
7276 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
|
7277 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
|
7278 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
|
7279 } |
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
|
7280 #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
|
7281 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7282 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
|
7283 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
|
7284 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
|
7285 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
|
7286 |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7287 if (ver <= CONPTY_INSIDER_BUILD) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7288 conpty_type = 3; |
18611
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7289 if (ver <= CONPTY_1909_BUILD) |
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7290 conpty_type = 2; |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7291 if (ver <= CONPTY_1903_BUILD) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7292 conpty_type = 2; |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7293 if (ver < CONPTY_FIRST_SUPPORT_BUILD) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7294 conpty_type = 1; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15621
diff
changeset
|
7295 } |
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
|
7296 |
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
|
7297 #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
|
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 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
|
7300 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
|
7301 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7302 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
|
7303 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
|
7304 # 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
|
7305 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
|
7306 # 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
|
7307 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7308 // Use functions supported from Vista |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7309 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
|
7310 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
|
7311 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7312 pGetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7313 (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
|
7314 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
|
7315 pSetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7316 (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
|
7317 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
|
7318 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
|
7319 && 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
|
7320 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
|
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 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
|
7324 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
|
7325 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
|
7326 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
|
7327 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
|
7328 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7329 # 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
|
7330 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
|
7331 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
|
7332 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
|
7333 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
|
7334 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
|
7335 default_console_color_fg = fg; |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
7336 # 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
|
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 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
|
7339 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7340 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7341 static void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7342 vtp_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
|
7343 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7344 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
|
7345 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7346 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7347 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
|
7348 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
|
7349 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
|
7350 ...) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7351 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7352 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
|
7353 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
|
7354 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
|
7355 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7356 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
|
7357 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
|
7358 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
|
7359 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
|
7360 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
|
7361 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7362 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7363 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
|
7364 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
|
7365 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
|
7366 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7367 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
|
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 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
|
7370 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
|
7371 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7372 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7373 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
|
7374 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
|
7375 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
|
7376 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
|
7377 ) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7378 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7379 // 2('\033[') + 4('255.') * 16 + NUL |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7380 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
|
7381 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
|
7382 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
|
7383 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7384 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
|
7385 *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
|
7386 *p++ = '['; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7387 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7388 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
|
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 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
|
7391 *p++ = ';'; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7392 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7393 p--; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7394 *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
|
7395 *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
|
7396 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
|
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 |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
7399 # 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
|
7400 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
|
7401 ctermtoxterm( |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7402 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
|
7403 { |
13839
ca8953d36264
patch 8.0.1791: using uint8_t does not work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13827
diff
changeset
|
7404 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
|
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 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
|
7407 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
|
7408 } |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
7409 # 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
|
7410 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7411 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
|
7412 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
|
7413 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7414 # 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
|
7415 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
18786
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7416 guicolor_T fg, bg; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7417 int ctermfg, 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
|
7418 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7419 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
|
7420 return; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7421 |
18786
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7422 get_default_console_color(&ctermfg, &ctermbg, &fg, &bg); |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7423 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7424 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
|
7425 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
|
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 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
|
7429 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
|
7430 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7431 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
|
7432 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
|
7433 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
|
7434 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
|
7435 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
|
7436 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
|
7437 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
|
7438 # endif |
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 |
18786
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7441 # if defined(FEAT_TERMGUICOLORS) || defined(PROTO) |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7442 void |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7443 get_default_console_color( |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7444 int *cterm_fg, |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7445 int *cterm_bg, |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7446 guicolor_T *gui_fg, |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7447 guicolor_T *gui_bg) |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7448 { |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7449 int id; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7450 guicolor_T guifg = INVALCOLOR; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7451 guicolor_T guibg = INVALCOLOR; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7452 int ctermfg = 0; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7453 int ctermbg = 0; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7454 |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7455 id = syn_name2id((char_u *)"Normal"); |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7456 if (id > 0 && p_tgc) |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7457 syn_id2colors(id, &guifg, &guibg); |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7458 if (guifg == INVALCOLOR) |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7459 { |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7460 ctermfg = -1; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7461 if (id > 0) |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7462 syn_id2cterm_bg(id, &ctermfg, &ctermbg); |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7463 guifg = ctermfg != -1 ? ctermtoxterm(ctermfg) |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7464 : default_console_color_fg; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7465 cterm_normal_fg_gui_color = guifg; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7466 ctermfg = ctermfg < 0 ? 0 : ctermfg; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7467 } |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7468 if (guibg == INVALCOLOR) |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7469 { |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7470 ctermbg = -1; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7471 if (id > 0) |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7472 syn_id2cterm_bg(id, &ctermfg, &ctermbg); |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7473 guibg = ctermbg != -1 ? ctermtoxterm(ctermbg) |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7474 : default_console_color_bg; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7475 cterm_normal_bg_gui_color = guibg; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7476 ctermbg = ctermbg < 0 ? 0 : ctermbg; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7477 } |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7478 |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7479 *cterm_fg = ctermfg; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7480 *cterm_bg = ctermbg; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7481 *gui_fg = guifg; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7482 *gui_bg = guibg; |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7483 } |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7484 # endif |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
7485 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7486 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
|
7487 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
|
7488 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7489 # 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
|
7490 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
|
7491 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7492 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
|
7493 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
|
7494 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
|
7495 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7496 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
|
7497 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
|
7498 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
|
7499 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
|
7500 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
|
7501 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
|
7502 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
|
7503 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7504 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7505 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7506 void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7507 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
|
7508 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7509 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
|
7510 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
|
7511 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7512 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
|
7513 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7514 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7515 int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7516 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
|
7517 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7518 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
|
7519 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7520 |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7521 int |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7522 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
|
7523 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7524 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
|
7525 } |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
7526 |
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
|
7527 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
|
7528 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
|
7529 { |
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
|
7530 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
|
7531 } |
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
|
7532 |
15848
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
7533 #endif |
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
7534 |
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
|
7535 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
|
7536 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
|
7537 { |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7538 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
|
7539 } |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7540 |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7541 int |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7542 get_conpty_type(void) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7543 { |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7544 return conpty_type; |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7545 } |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7546 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7547 int |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7548 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
|
7549 { |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7550 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
|
7551 } |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7552 |
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
|
7553 #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
|
7554 void |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7555 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
|
7556 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7557 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
|
7558 COORD coord; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7559 SMALL_RECT newsize; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7560 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7561 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
|
7562 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7563 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
|
7564 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
|
7565 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
|
7566 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7567 newsize.Left = 0; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7568 newsize.Top = 0; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7569 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
|
7570 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
|
7571 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
|
7572 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7573 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
|
7574 } |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7575 } |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
7576 #endif |