Mercurial > vim
annotate src/os_win32.c @ 27517:f00a7a2bee21 v8.2.4286
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Commit: https://github.com/vim/vim/commit/381692b6f1c2ec9b73a139500286ddc9347a1c01
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 2 20:01:27 2022 +0000
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Problem: Vim9: strict type checking after copy() and deepcopy().
Solution: Allow type to change after making a copy. (closes https://github.com/vim/vim/issues/9644)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 02 Feb 2022 21:15:03 +0100 |
parents | 6045bf58926d |
children | 3ad379c0ab28 |
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> | |
23819
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
36 # include <winternl.h> |
3927 | 37 #endif |
7 | 38 |
39 #undef chdir | |
40 #ifdef __GNUC__ | |
41 # ifndef __MINGW32__ | |
42 # include <dirent.h> | |
43 # endif | |
44 #else | |
45 # include <direct.h> | |
46 #endif | |
47 | |
3927 | 48 #ifndef PROTO |
26336
a2e6da79274d
patch 8.2.3699: the +title feature adds a lot of #ifdef but little code
Bram Moolenaar <Bram@vim.org>
parents:
26171
diff
changeset
|
49 # if !defined(FEAT_GUI_MSWIN) |
3927 | 50 # include <shellapi.h> |
51 # endif | |
7 | 52 #endif |
53 | |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
54 #ifdef FEAT_JOB_CHANNEL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
55 # include <tlhelp32.h> |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
56 #endif |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
57 |
7 | 58 #ifdef __MINGW32__ |
59 # ifndef FROM_LEFT_1ST_BUTTON_PRESSED | |
60 # define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001 | |
61 # endif | |
62 # ifndef RIGHTMOST_BUTTON_PRESSED | |
63 # define RIGHTMOST_BUTTON_PRESSED 0x0002 | |
64 # endif | |
65 # ifndef FROM_LEFT_2ND_BUTTON_PRESSED | |
66 # define FROM_LEFT_2ND_BUTTON_PRESSED 0x0004 | |
67 # endif | |
68 # ifndef FROM_LEFT_3RD_BUTTON_PRESSED | |
69 # define FROM_LEFT_3RD_BUTTON_PRESSED 0x0008 | |
70 # endif | |
71 # ifndef FROM_LEFT_4TH_BUTTON_PRESSED | |
72 # define FROM_LEFT_4TH_BUTTON_PRESSED 0x0010 | |
73 # endif | |
74 | |
75 /* | |
76 * EventFlags | |
77 */ | |
78 # ifndef MOUSE_MOVED | |
79 # define MOUSE_MOVED 0x0001 | |
80 # endif | |
81 # ifndef DOUBLE_CLICK | |
82 # define DOUBLE_CLICK 0x0002 | |
83 # endif | |
84 #endif | |
85 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
86 // 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
|
87 // #define MCH_WRITE_DUMP |
7 | 88 |
89 #ifdef MCH_WRITE_DUMP | |
90 FILE* fdDump = NULL; | |
91 #endif | |
92 | |
93 /* | |
94 * When generating prototypes for Win32 on Unix, these lines make the syntax | |
95 * errors disappear. They do not need to be correct. | |
96 */ | |
97 #ifdef PROTO | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
98 # define WINAPI |
7 | 99 typedef char * LPCSTR; |
26 | 100 typedef char * LPWSTR; |
7 | 101 typedef int ACCESS_MASK; |
102 typedef int BOOL; | |
103 typedef int COLORREF; | |
104 typedef int CONSOLE_CURSOR_INFO; | |
105 typedef int COORD; | |
106 typedef int DWORD; | |
107 typedef int HANDLE; | |
7668
21b0a39d13ed
commit https://github.com/vim/vim/commit/ef26954a35207c3f17d6ed35d9a40c918d974892
Christian Brabandt <cb@256bit.org>
parents:
7657
diff
changeset
|
108 typedef int LPHANDLE; |
7 | 109 typedef int HDC; |
110 typedef int HFONT; | |
111 typedef int HICON; | |
112 typedef int HINSTANCE; | |
113 typedef int HWND; | |
114 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
|
115 typedef int INT; |
7 | 116 typedef int KEY_EVENT_RECORD; |
117 typedef int LOGFONT; | |
118 typedef int LPBOOL; | |
119 typedef int LPCTSTR; | |
120 typedef int LPDWORD; | |
121 typedef int LPSTR; | |
122 typedef int LPTSTR; | |
123 typedef int LPVOID; | |
124 typedef int MOUSE_EVENT_RECORD; | |
125 typedef int PACL; | |
126 typedef int PDWORD; | |
127 typedef int PHANDLE; | |
128 typedef int PRINTDLG; | |
129 typedef int PSECURITY_DESCRIPTOR; | |
130 typedef int PSID; | |
131 typedef int SECURITY_INFORMATION; | |
132 typedef int SHORT; | |
133 typedef int SMALL_RECT; | |
134 typedef int TEXTMETRIC; | |
135 typedef int TOKEN_INFORMATION_CLASS; | |
136 typedef int TRUSTEE; | |
137 typedef int WORD; | |
138 typedef int WCHAR; | |
139 typedef void VOID; | |
3927 | 140 typedef int BY_HANDLE_FILE_INFORMATION; |
5112
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
141 typedef int SE_OBJECT_TYPE; |
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
142 typedef int PSNSECINFO; |
f063be86b632
updated for version 7.3.1299
Bram Moolenaar <bram@vim.org>
parents:
5049
diff
changeset
|
143 typedef int PSNSECINFOW; |
6359 | 144 typedef int STARTUPINFO; |
145 typedef int PROCESS_INFORMATION; | |
10025
068f397d0da4
commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
146 typedef int LPSECURITY_ATTRIBUTES; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
147 # define __stdcall // empty |
7 | 148 #endif |
149 | |
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
|
150 #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
|
151 // Win32 Console handles for input and output |
7 | 152 static HANDLE g_hConIn = INVALID_HANDLE_VALUE; |
153 static HANDLE g_hConOut = INVALID_HANDLE_VALUE; | |
154 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
155 // Win32 Screen buffer,coordinate,console I/O information |
7 | 156 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
|
157 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
|
158 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
159 // 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
|
160 static WORD g_attrDefault = 7; // lightgray text on black background |
7 | 161 static WORD g_attrCurrent; |
162 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
163 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
|
164 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
|
165 static int g_fForceExit = FALSE; // set when forcefully exiting |
7 | 166 |
167 static void scroll(unsigned cLines); | |
168 static void set_scroll_region(unsigned left, unsigned top, | |
169 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
|
170 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
|
171 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
|
172 static void insert_lines(unsigned cLines); |
7 | 173 static void delete_lines(unsigned cLines); |
174 static void gotoxy(unsigned x, unsigned y); | |
175 static void standout(void); | |
176 static int s_cursor_visible = TRUE; | |
177 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
|
178 #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
|
179 #ifdef FEAT_GUI_MSWIN |
7 | 180 static int s_dont_use_vimrun = TRUE; |
181 static int need_vimrun_warning = FALSE; | |
182 static char *vimrun_path = "vimrun "; | |
183 #endif | |
184 | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
185 static int win32_getattrs(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
186 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
|
187 static int win32_set_archive(char_u *name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
188 |
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
|
189 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
|
190 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
|
191 static int conpty_stable = 0; |
20201
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
192 static int conpty_fix_type = 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
|
193 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
|
194 |
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
|
195 #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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
202 static int wt_working = 0; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
203 static void wt_init(); |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
204 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
205 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
|
206 static guicolor_T save_console_fg_rgb; |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
207 static guicolor_T store_console_bg_rgb; |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
208 static guicolor_T store_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
|
209 |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
210 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
|
211 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
|
212 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
213 # 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
|
214 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
|
215 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
|
216 # endif |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
217 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
218 # 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
|
219 # define USE_VTP (vtp_working && is_term_win32() && (p_tgc || (!p_tgc && t_colors >= 256))) |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
220 # define USE_WT (wt_working) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
221 # else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
222 # define USE_VTP 0 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
223 # define USE_WT 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
|
224 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
225 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
226 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
|
227 static void reset_console_color_rgb(void); |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
228 static void restore_console_color_rgb(void); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
229 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
230 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
231 // 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
|
232 #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
|
233 # 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
|
234 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
235 |
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
|
236 #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
|
237 static int suppress_winsize = 1; // don't fiddle with console |
7 | 238 #endif |
239 | |
2612 | 240 static char_u *exe_path = NULL; |
241 | |
5633 | 242 static BOOL win8_or_later = FALSE; |
243 | |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
244 # if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
245 # define UChar UnicodeChar |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
246 # else |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
247 # define UChar uChar.UnicodeChar |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
248 # endif |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
249 |
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
|
250 #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
|
251 // 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
|
252 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
|
253 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 } 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 #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
|
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 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
272 * 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
|
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 typedef BOOL (WINAPI *PfnRtlGetVersion)(LPOSVERSIONINFOW); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
275 #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
|
276 (((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
|
277 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
278 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
|
279 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
|
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 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
|
282 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
|
283 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
|
284 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
|
285 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
286 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
|
287 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
|
288 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
289 pRtlGetVersion = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
290 (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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
296 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
|
297 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
298 |
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
|
299 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
300 static BOOL |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
301 is_ambiwidth_event( |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
302 INPUT_RECORD *ir) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
303 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
304 return ir->EventType == KEY_EVENT |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
305 && ir->Event.KeyEvent.bKeyDown |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
306 && ir->Event.KeyEvent.wRepeatCount == 1 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
307 && ir->Event.KeyEvent.wVirtualKeyCode == 0x12 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
308 && ir->Event.KeyEvent.wVirtualScanCode == 0x38 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
309 && ir->Event.KeyEvent.UChar == 0 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
310 && ir->Event.KeyEvent.dwControlKeyState == 2; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
311 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
312 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
313 static void |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
314 make_ambiwidth_event( |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
315 INPUT_RECORD *down, |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
316 INPUT_RECORD *up) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
317 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
318 down->Event.KeyEvent.wVirtualKeyCode = 0; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
319 down->Event.KeyEvent.wVirtualScanCode = 0; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
320 down->Event.KeyEvent.UChar = up->Event.KeyEvent.UChar; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
321 down->Event.KeyEvent.dwControlKeyState = 0; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
322 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
323 |
5580 | 324 /* |
325 * Version of ReadConsoleInput() that works with IME. | |
5590 | 326 * Works around problems on Windows 8. |
5580 | 327 */ |
328 static BOOL | |
329 read_console_input( | |
5590 | 330 HANDLE hInput, |
331 INPUT_RECORD *lpBuffer, | |
332 DWORD nLength, | |
333 LPDWORD lpEvents) | |
5580 | 334 { |
335 enum | |
336 { | |
5590 | 337 IRSIZE = 10 |
5580 | 338 }; |
5590 | 339 static INPUT_RECORD s_irCache[IRSIZE]; |
5580 | 340 static DWORD s_dwIndex = 0; |
341 static DWORD s_dwMax = 0; | |
5590 | 342 DWORD dwEvents; |
5635 | 343 int head; |
344 int tail; | |
345 int i; | |
20183
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
346 static INPUT_RECORD s_irPseudo; |
5580 | 347 |
6981 | 348 if (nLength == -2) |
349 return (s_dwMax > 0) ? TRUE : FALSE; | |
350 | |
5633 | 351 if (!win8_or_later) |
352 { | |
353 if (nLength == -1) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
354 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
355 return ReadConsoleInputW(hInput, lpBuffer, 1, &dwEvents); |
5633 | 356 } |
357 | |
5580 | 358 if (s_dwMax == 0) |
359 { | |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
360 if (!USE_WT && nLength == -1) |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
361 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
362 GetNumberOfConsoleInputEvents(hInput, &dwEvents); |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
363 if (dwEvents == 0 && nLength == -1) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
364 return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents); |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
365 ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents); |
5580 | 366 s_dwIndex = 0; |
5590 | 367 s_dwMax = dwEvents; |
368 if (dwEvents == 0) | |
5580 | 369 { |
5590 | 370 *lpEvents = 0; |
371 return TRUE; | |
5580 | 372 } |
5635 | 373 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
374 for (i = s_dwIndex; i < (int)s_dwMax - 1; ++i) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
375 if (is_ambiwidth_event(&s_irCache[i])) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
376 make_ambiwidth_event(&s_irCache[i], &s_irCache[i + 1]); |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
377 |
5635 | 378 if (s_dwMax > 1) |
379 { | |
380 head = 0; | |
381 tail = s_dwMax - 1; | |
382 while (head != tail) | |
383 { | |
384 if (s_irCache[head].EventType == WINDOW_BUFFER_SIZE_EVENT | |
385 && s_irCache[head + 1].EventType | |
386 == WINDOW_BUFFER_SIZE_EVENT) | |
387 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
388 // Remove duplicate event to avoid flicker. |
5635 | 389 for (i = head; i < tail; ++i) |
390 s_irCache[i] = s_irCache[i + 1]; | |
391 --tail; | |
392 continue; | |
393 } | |
394 head++; | |
395 } | |
396 s_dwMax = tail + 1; | |
397 } | |
5580 | 398 } |
5635 | 399 |
20183
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
400 if (s_irCache[s_dwIndex].EventType == KEY_EVENT) |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
401 { |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
402 if (s_irCache[s_dwIndex].Event.KeyEvent.wRepeatCount > 1) |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
403 { |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
404 s_irPseudo = s_irCache[s_dwIndex]; |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
405 s_irPseudo.Event.KeyEvent.wRepeatCount = 1; |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
406 s_irCache[s_dwIndex].Event.KeyEvent.wRepeatCount--; |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
407 *lpBuffer = s_irPseudo; |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
408 *lpEvents = 1; |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
409 return TRUE; |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
410 } |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
411 } |
5888cce49574
patch 8.2.0647: MS-Windows: repeat count for events was not used
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
412 |
5590 | 413 *lpBuffer = s_irCache[s_dwIndex]; |
6981 | 414 if (!(nLength == -1 || nLength == -2) && ++s_dwIndex >= s_dwMax) |
5580 | 415 s_dwMax = 0; |
5590 | 416 *lpEvents = 1; |
5580 | 417 return TRUE; |
418 } | |
419 | |
420 /* | |
421 * Version of PeekConsoleInput() that works with IME. | |
422 */ | |
423 static BOOL | |
424 peek_console_input( | |
5590 | 425 HANDLE hInput, |
426 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
|
427 DWORD nLength UNUSED, |
5590 | 428 LPDWORD lpEvents) |
5580 | 429 { |
27455
6045bf58926d
patch 8.2.4256: MS-Windows: compiler warnings when compiled with /W4
Bram Moolenaar <Bram@vim.org>
parents:
27370
diff
changeset
|
430 return read_console_input(hInput, lpBuffer, (DWORD)-1, lpEvents); |
5580 | 431 } |
432 | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
433 # ifdef FEAT_CLIENTSERVER |
6981 | 434 static DWORD |
435 msg_wait_for_multiple_objects( | |
436 DWORD nCount, | |
437 LPHANDLE pHandles, | |
438 BOOL fWaitAll, | |
439 DWORD dwMilliseconds, | |
440 DWORD dwWakeMask) | |
441 { | |
27455
6045bf58926d
patch 8.2.4256: MS-Windows: compiler warnings when compiled with /W4
Bram Moolenaar <Bram@vim.org>
parents:
27370
diff
changeset
|
442 if (read_console_input(NULL, NULL, (DWORD)-2, NULL)) |
6981 | 443 return WAIT_OBJECT_0; |
444 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, | |
445 dwMilliseconds, dwWakeMask); | |
446 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
447 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
448 |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
449 # ifndef FEAT_CLIENTSERVER |
6981 | 450 static DWORD |
451 wait_for_single_object( | |
452 HANDLE hHandle, | |
453 DWORD dwMilliseconds) | |
454 { | |
455 if (read_console_input(NULL, NULL, -2, NULL)) | |
456 return WAIT_OBJECT_0; | |
457 return WaitForSingleObject(hHandle, dwMilliseconds); | |
458 } | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
459 # endif |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8084
diff
changeset
|
460 #endif |
6981 | 461 |
7 | 462 static void |
463 get_exe_name(void) | |
464 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
465 // 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
|
466 // as the maximum length that works (plus a NUL byte). |
2630 | 467 #define MAX_ENV_PATH_LEN 8192 |
468 char temp[MAX_ENV_PATH_LEN]; | |
2612 | 469 char_u *p; |
7 | 470 |
471 if (exe_name == NULL) | |
472 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
473 // store the name of the executable, may be used for $VIM |
2630 | 474 GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1); |
7 | 475 if (*temp != NUL) |
476 exe_name = FullName_save((char_u *)temp, FALSE); | |
477 } | |
819 | 478 |
2612 | 479 if (exe_path == NULL && exe_name != NULL) |
819 | 480 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20593
diff
changeset
|
481 exe_path = vim_strnsave(exe_name, gettail_sep(exe_name) - exe_name); |
2612 | 482 if (exe_path != NULL) |
819 | 483 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
484 // 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
|
485 // "!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
|
486 // SearchPath() also looks there. |
2612 | 487 p = mch_getenv("PATH"); |
2630 | 488 if (p == NULL |
489 || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN) | |
2612 | 490 { |
2630 | 491 if (p == NULL || *p == NUL) |
492 temp[0] = NUL; | |
493 else | |
494 { | |
495 STRCPY(temp, p); | |
496 STRCAT(temp, ";"); | |
497 } | |
2612 | 498 STRCAT(temp, exe_path); |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
499 vim_setenv((char_u *)"PATH", (char_u *)temp); |
2612 | 500 } |
819 | 501 } |
502 } | |
7 | 503 } |
504 | |
2612 | 505 /* |
3361 | 506 * Unescape characters in "p" that appear in "escaped". |
507 */ | |
508 static void | |
509 unescape_shellxquote(char_u *p, char_u *escaped) | |
510 { | |
3386 | 511 int l = (int)STRLEN(p); |
3361 | 512 int n; |
513 | |
514 while (*p != NUL) | |
515 { | |
516 if (*p == '^' && vim_strchr(escaped, p[1]) != NULL) | |
517 mch_memmove(p, p + 1, l--); | |
518 n = (*mb_ptr2len)(p); | |
519 p += n; | |
520 l -= n; | |
521 } | |
522 } | |
523 | |
524 /* | |
2612 | 525 * Load library "name". |
526 */ | |
527 HINSTANCE | |
528 vimLoadLib(char *name) | |
529 { | |
3902 | 530 HINSTANCE dll = NULL; |
3889 | 531 |
24563
30ad18017e1c
patch 8.2.2821: MS-Windows: unnessarily loading libraries when registering OLE
Bram Moolenaar <Bram@vim.org>
parents:
24506
diff
changeset
|
532 // No need to load any library when registering OLE. |
30ad18017e1c
patch 8.2.2821: MS-Windows: unnessarily loading libraries when registering OLE
Bram Moolenaar <Bram@vim.org>
parents:
24506
diff
changeset
|
533 if (found_register_arg) |
30ad18017e1c
patch 8.2.2821: MS-Windows: unnessarily loading libraries when registering OLE
Bram Moolenaar <Bram@vim.org>
parents:
24506
diff
changeset
|
534 return dll; |
30ad18017e1c
patch 8.2.2821: MS-Windows: unnessarily loading libraries when registering OLE
Bram Moolenaar <Bram@vim.org>
parents:
24506
diff
changeset
|
535 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
536 // 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
|
537 // vimLoadLib() recursively, which causes a stack overflow. |
2612 | 538 if (exe_path == NULL) |
539 get_exe_name(); | |
3902 | 540 if (exe_path != NULL) |
2612 | 541 { |
3902 | 542 WCHAR old_dirw[MAXPATHL]; |
543 | |
544 if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) | |
545 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
546 // 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
|
547 // 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
|
548 // in the current directory. |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
549 SetCurrentDirectory((LPCSTR)exe_path); |
3902 | 550 dll = LoadLibrary(name); |
551 SetCurrentDirectoryW(old_dirw); | |
552 return dll; | |
553 } | |
2612 | 554 } |
555 return dll; | |
556 } | |
557 | |
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
|
558 #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
|
559 /* |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
560 * 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
|
561 */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
562 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
|
563 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
|
564 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
565 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
|
566 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
|
567 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
|
568 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
569 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
|
570 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
|
571 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
|
572 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
|
573 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
|
574 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
|
575 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
|
576 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
|
577 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
578 #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
|
579 |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
580 #if 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
|
581 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
582 * 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
|
583 * 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
|
584 * 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
|
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 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
|
587 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
|
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 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
|
590 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
|
591 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
|
592 PIMAGE_IMPORT_DESCRIPTOR pImpDesc; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
593 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
|
594 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
|
595 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
|
596 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 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
|
603 + 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
|
604 .VirtualAddress); |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
605 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
|
606 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
607 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
|
608 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
609 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
|
610 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
|
611 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
|
612 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
613 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
|
614 continue; |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
615 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
|
616 + (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
|
617 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
|
618 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
619 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
|
620 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
621 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
|
622 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
|
623 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
|
624 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
|
625 default: |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
626 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
|
627 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
628 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
629 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
630 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
631 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
|
632 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
633 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
634 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
635 * 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
|
636 */ |
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 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
638 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
|
639 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
640 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
|
641 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
642 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
|
643 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
|
644 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
|
645 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
|
646 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
647 |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
648 /* |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
649 * 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
|
650 */ |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
651 void * |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
652 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
|
653 { |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
654 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
|
655 } |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
656 #endif |
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
657 |
7 | 658 #if defined(DYNAMIC_GETTEXT) || defined(PROTO) |
659 # ifndef GETTEXT_DLL | |
660 # 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
|
661 # 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
|
662 # define GETTEXT_DLL_ALT2 "intl.dll" |
7 | 663 # endif |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
664 // Dummy functions |
36 | 665 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
|
666 static char *null_libintl_ngettext(const char *, const char *, unsigned long n); |
36 | 667 static char *null_libintl_textdomain(const char *); |
668 static char *null_libintl_bindtextdomain(const char *, const char *); | |
669 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
|
670 static int null_libintl_wputenv(const wchar_t *); |
7 | 671 |
2612 | 672 static HINSTANCE hLibintlDLL = NULL; |
36 | 673 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
|
674 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
|
675 = null_libintl_ngettext; |
36 | 676 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; |
677 char *(*dyn_libintl_bindtextdomain)(const char *, const char *) | |
7 | 678 = null_libintl_bindtextdomain; |
36 | 679 char *(*dyn_libintl_bind_textdomain_codeset)(const char *, const char *) |
680 = 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
|
681 int (*dyn_libintl_wputenv)(const wchar_t *) = null_libintl_wputenv; |
7 | 682 |
683 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
684 dyn_libintl_init(void) |
7 | 685 { |
686 int i; | |
687 static struct | |
688 { | |
689 char *name; | |
690 FARPROC *ptr; | |
691 } libintl_entry[] = | |
692 { | |
693 {"gettext", (FARPROC*)&dyn_libintl_gettext}, | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
694 {"ngettext", (FARPROC*)&dyn_libintl_ngettext}, |
7 | 695 {"textdomain", (FARPROC*)&dyn_libintl_textdomain}, |
696 {"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, | |
697 {NULL, NULL} | |
698 }; | |
10571
b726d3ea70bc
patch 8.0.0175: setting language on MS-Windows does not always work
Christian Brabandt <cb@256bit.org>
parents:
10418
diff
changeset
|
699 HINSTANCE hmsvcrt; |
7 | 700 |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
701 // 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
|
702 if (hLibintlDLL != NULL) |
7 | 703 return 1; |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
704 // 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
|
705 hLibintlDLL = vimLoadLib(GETTEXT_DLL); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
706 # ifdef GETTEXT_DLL_ALT1 |
7613
4456fa2d22e8
commit https://github.com/vim/vim/commit/286eacd3f6631e985089176fb1dff1bcf1a1d6b5
Christian Brabandt <cb@256bit.org>
parents:
7460
diff
changeset
|
707 if (!hLibintlDLL) |
14881
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
708 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT1); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
709 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
710 # 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
|
711 if (!hLibintlDLL) |
35aff6b8a2c7
patch 8.1.0452: MS-Windows: not finding intl.dll
Bram Moolenaar <Bram@vim.org>
parents:
14879
diff
changeset
|
712 hLibintlDLL = vimLoadLib(GETTEXT_DLL_ALT2); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
713 # endif |
7734
616769d423fc
commit https://github.com/vim/vim/commit/938ee834d345062cd94f8fdfd54fad0019432a83
Christian Brabandt <cb@256bit.org>
parents:
7668
diff
changeset
|
714 if (!hLibintlDLL) |
7 | 715 { |
2612 | 716 if (p_verbose > 0) |
7 | 717 { |
2612 | 718 verbose_enter(); |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
719 semsg(_(e_could_not_load_library_str_str), GETTEXT_DLL, GetWin32Error()); |
2612 | 720 verbose_leave(); |
7 | 721 } |
2612 | 722 return 0; |
7 | 723 } |
724 for (i = 0; libintl_entry[i].name != NULL | |
725 && libintl_entry[i].ptr != NULL; ++i) | |
726 { | |
727 if ((*libintl_entry[i].ptr = (FARPROC)GetProcAddress(hLibintlDLL, | |
728 libintl_entry[i].name)) == NULL) | |
729 { | |
730 dyn_libintl_end(); | |
731 if (p_verbose > 0) | |
292 | 732 { |
733 verbose_enter(); | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
734 semsg(_(e_could_not_load_library_function_str), libintl_entry[i].name); |
292 | 735 verbose_leave(); |
736 } | |
7 | 737 return 0; |
738 } | |
739 } | |
36 | 740 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
741 // The bind_textdomain_codeset() function is optional. |
323 | 742 dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL, |
36 | 743 "bind_textdomain_codeset"); |
744 if (dyn_libintl_bind_textdomain_codeset == NULL) | |
745 dyn_libintl_bind_textdomain_codeset = | |
746 null_libintl_bind_textdomain_codeset; | |
747 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
748 // _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
|
749 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
|
750 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
|
751 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
|
752 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
|
753 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
|
754 |
7 | 755 return 1; |
756 } | |
757 | |
758 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
759 dyn_libintl_end(void) |
7 | 760 { |
761 if (hLibintlDLL) | |
762 FreeLibrary(hLibintlDLL); | |
763 hLibintlDLL = NULL; | |
764 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
|
765 dyn_libintl_ngettext = null_libintl_ngettext; |
7 | 766 dyn_libintl_textdomain = null_libintl_textdomain; |
767 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain; | |
36 | 768 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
|
769 dyn_libintl_wputenv = null_libintl_wputenv; |
7 | 770 } |
771 | |
772 static char * | |
26 | 773 null_libintl_gettext(const char *msgid) |
7 | 774 { |
775 return (char*)msgid; | |
776 } | |
777 | |
778 static char * | |
9754
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
779 null_libintl_ngettext( |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
780 const char *msgid, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
781 const char *msgid_plural, |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
782 unsigned long n) |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
783 { |
9762
93dcc4329c74
commit https://github.com/vim/vim/commit/c90f2aedd0a5dc2cc75bc9b5f475f8a3e3fe36b1
Christian Brabandt <cb@256bit.org>
parents:
9754
diff
changeset
|
784 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
|
785 } |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
786 |
a990e7ed260b
commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5
Christian Brabandt <cb@256bit.org>
parents:
9750
diff
changeset
|
787 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
|
788 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
|
789 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
|
790 const char *dirname UNUSED) |
7 | 791 { |
792 return NULL; | |
793 } | |
794 | |
795 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
|
796 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
|
797 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
|
798 const char *codeset UNUSED) |
36 | 799 { |
800 return NULL; | |
801 } | |
802 | |
803 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
|
804 null_libintl_textdomain(const char *domainname UNUSED) |
7 | 805 { |
806 return NULL; | |
807 } | |
808 | |
11929
3457728d1a58
patch 8.0.0844: wrong function prototype because of missing static
Christian Brabandt <cb@256bit.org>
parents:
11921
diff
changeset
|
809 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
|
810 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
|
811 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
812 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
|
813 } |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
814 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
815 #endif // DYNAMIC_GETTEXT |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
816 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
817 // This symbol is not defined in older versions of the SDK or Visual C++ |
7 | 818 |
819 #ifndef VER_PLATFORM_WIN32_WINDOWS | |
820 # define VER_PLATFORM_WIN32_WINDOWS 1 | |
821 #endif | |
822 | |
823 #ifdef HAVE_ACL | |
3927 | 824 # ifndef PROTO |
825 # include <aclapi.h> | |
826 # endif | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
827 # ifndef PROTECTED_DACL_SECURITY_INFORMATION |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
828 # define PROTECTED_DACL_SECURITY_INFORMATION 0x80000000L |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
829 # endif |
7 | 830 #endif |
831 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
832 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
833 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
834 * Enables or disables the specified privilege. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
835 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
836 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
837 win32_enable_privilege(LPTSTR lpszPrivilege, BOOL bEnable) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
838 { |
5590 | 839 BOOL bResult; |
840 LUID luid; | |
841 HANDLE hToken; | |
842 TOKEN_PRIVILEGES tokenPrivileges; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
843 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
844 if (!OpenProcessToken(GetCurrentProcess(), |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
845 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
846 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
847 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
848 if (!LookupPrivilegeValue(NULL, lpszPrivilege, &luid)) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
849 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
850 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
851 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
852 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
853 |
6047 | 854 tokenPrivileges.PrivilegeCount = 1; |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
855 tokenPrivileges.Privileges[0].Luid = luid; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
856 tokenPrivileges.Privileges[0].Attributes = bEnable ? |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
857 SE_PRIVILEGE_ENABLED : 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
858 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
859 bResult = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
860 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
861 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
862 CloseHandle(hToken); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
863 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
864 return bResult && GetLastError() == ERROR_SUCCESS; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
865 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
866 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
867 |
23090
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
868 #ifdef _MSC_VER |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
869 // Suppress the deprecation warning for using GetVersionEx(). |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
870 // It is needed for implementing "windowsversion()". |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
871 # pragma warning(push) |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
872 # pragma warning(disable: 4996) |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
873 #endif |
7 | 874 /* |
20478
af8feeaf167a
patch 8.2.0793: MS-Windows: cannot build GUI with small features
Bram Moolenaar <Bram@vim.org>
parents:
20439
diff
changeset
|
875 * Set "win8_or_later" and fill in "windowsVersion" if possible. |
7 | 876 */ |
877 void | |
878 PlatformId(void) | |
879 { | |
880 static int done = FALSE; | |
881 | |
882 if (!done) | |
883 { | |
884 OSVERSIONINFO ovi; | |
885 | |
886 ovi.dwOSVersionInfoSize = sizeof(ovi); | |
887 GetVersionEx(&ovi); | |
888 | |
20478
af8feeaf167a
patch 8.2.0793: MS-Windows: cannot build GUI with small features
Bram Moolenaar <Bram@vim.org>
parents:
20439
diff
changeset
|
889 #ifdef FEAT_EVAL |
18973
bf8eb950df61
patch 8.2.0047: cannot skip tests for specific MS-Windows platform
Bram Moolenaar <Bram@vim.org>
parents:
18876
diff
changeset
|
890 vim_snprintf(windowsVersion, sizeof(windowsVersion), "%d.%d", |
bf8eb950df61
patch 8.2.0047: cannot skip tests for specific MS-Windows platform
Bram Moolenaar <Bram@vim.org>
parents:
18876
diff
changeset
|
891 (int)ovi.dwMajorVersion, (int)ovi.dwMinorVersion); |
20478
af8feeaf167a
patch 8.2.0793: MS-Windows: cannot build GUI with small features
Bram Moolenaar <Bram@vim.org>
parents:
20439
diff
changeset
|
892 #endif |
5633 | 893 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2) |
894 || ovi.dwMajorVersion > 6) | |
895 win8_or_later = TRUE; | |
896 | |
7 | 897 #ifdef HAVE_ACL |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
898 // 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
|
899 win32_enable_privilege(SE_SECURITY_NAME, TRUE); |
7 | 900 #endif |
901 done = TRUE; | |
902 } | |
903 } | |
23090
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
904 #ifdef _MSC_VER |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
905 # pragma warning(pop) |
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23060
diff
changeset
|
906 #endif |
7 | 907 |
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
|
908 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 909 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
910 # define SHIFT (SHIFT_PRESSED) |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
911 # 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
|
912 # 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
|
913 # define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) |
7 | 914 |
915 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
916 // 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
|
917 // 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
|
918 // 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
|
919 // 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
|
920 // 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
|
921 // combinations of function/arrow/etc keys. |
7 | 922 |
297 | 923 static const struct |
7 | 924 { |
925 WORD wVirtKey; | |
926 BOOL fAnsiKey; | |
927 int chAlone; | |
928 int chShift; | |
929 int chCtrl; | |
930 int chAlt; | |
931 } VirtKeyMap[] = | |
932 { | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
933 // Key ANSI alone shift ctrl alt |
7 | 934 { VK_ESCAPE,FALSE, ESC, ESC, ESC, ESC, }, |
935 | |
936 { VK_F1, TRUE, ';', 'T', '^', 'h', }, | |
937 { VK_F2, TRUE, '<', 'U', '_', 'i', }, | |
938 { VK_F3, TRUE, '=', 'V', '`', 'j', }, | |
939 { VK_F4, TRUE, '>', 'W', 'a', 'k', }, | |
940 { VK_F5, TRUE, '?', 'X', 'b', 'l', }, | |
941 { VK_F6, TRUE, '@', 'Y', 'c', 'm', }, | |
942 { VK_F7, TRUE, 'A', 'Z', 'd', 'n', }, | |
943 { VK_F8, TRUE, 'B', '[', 'e', 'o', }, | |
944 { VK_F9, TRUE, 'C', '\\', 'f', 'p', }, | |
945 { 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
|
946 { 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
|
947 { 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
|
948 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
949 { 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
|
950 { 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
|
951 { 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
|
952 { 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
|
953 { 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
|
954 { 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
|
955 { 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
|
956 { 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
|
957 { 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
|
958 { 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
|
959 { 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
|
960 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
961 { VK_SNAPSHOT,TRUE, 0, 0, 0, 'r', }, // PrtScrn |
7 | 962 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
963 # if 0 |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
964 // 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
|
965 { 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
|
966 { 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
|
967 { 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
|
968 { 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
|
969 { 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
|
970 { 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
|
971 { 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
|
972 { 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
|
973 # endif |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
974 { 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
|
975 { 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
|
976 // { 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
|
977 { 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
|
978 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
979 { 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
|
980 { 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
|
981 { 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
|
982 { 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
|
983 { 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
|
984 { 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
|
985 { 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
|
986 { 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
|
987 { 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
|
988 // 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
|
989 { VK_NUMPAD9,TRUE, '\376', '\377', '|', '}', }, |
7 | 990 }; |
991 | |
992 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
993 /* |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
994 * 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
|
995 */ |
7 | 996 static int |
997 win32_kbd_patch_key( | |
26 | 998 KEY_EVENT_RECORD *pker) |
7 | 999 { |
1000 UINT uMods = pker->dwControlKeyState; | |
1001 static int s_iIsDead = 0; | |
1002 static WORD awAnsiCode[2]; | |
1003 static BYTE abKeystate[256]; | |
1004 | |
1005 | |
1006 if (s_iIsDead == 2) | |
1007 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1008 pker->UChar = (WCHAR) awAnsiCode[1]; |
7 | 1009 s_iIsDead = 0; |
1010 return 1; | |
1011 } | |
1012 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1013 if (pker->UChar != 0) |
7 | 1014 return 1; |
1015 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19983
diff
changeset
|
1016 CLEAR_FIELD(abKeystate); |
7 | 1017 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1018 // Clear any pending dead keys |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1019 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); |
7 | 1020 |
1021 if (uMods & SHIFT_PRESSED) | |
1022 abKeystate[VK_SHIFT] = 0x80; | |
1023 if (uMods & CAPSLOCK_ON) | |
1024 abKeystate[VK_CAPITAL] = 1; | |
1025 | |
1026 if ((uMods & ALT_GR) == ALT_GR) | |
1027 { | |
1028 abKeystate[VK_CONTROL] = abKeystate[VK_LCONTROL] = | |
1029 abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80; | |
1030 } | |
1031 | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1032 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
|
1033 abKeystate, awAnsiCode, 2, 0); |
7 | 1034 |
1035 if (s_iIsDead > 0) | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1036 pker->UChar = (WCHAR) awAnsiCode[0]; |
7 | 1037 |
1038 return s_iIsDead; | |
1039 } | |
1040 | |
1041 static BOOL g_fJustGotFocus = FALSE; | |
1042 | |
1043 /* | |
1044 * Decode a KEY_EVENT into one or two keystrokes | |
1045 */ | |
1046 static BOOL | |
1047 decode_key_event( | |
1048 KEY_EVENT_RECORD *pker, | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1049 WCHAR *pch, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1050 WCHAR *pch2, |
7 | 1051 int *pmodifiers, |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
1052 BOOL fDoPost UNUSED) |
7 | 1053 { |
1054 int i; | |
1055 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL); | |
1056 | |
1057 *pch = *pch2 = NUL; | |
1058 g_fJustGotFocus = FALSE; | |
1059 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1060 // ignore key up events |
7 | 1061 if (!pker->bKeyDown) |
1062 return FALSE; | |
1063 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1064 // ignore some keystrokes |
7 | 1065 switch (pker->wVirtualKeyCode) |
1066 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1067 // modifiers |
7 | 1068 case VK_SHIFT: |
1069 case VK_CONTROL: | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1070 case VK_MENU: // Alt key |
7 | 1071 return FALSE; |
1072 | |
1073 default: | |
1074 break; | |
1075 } | |
1076 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1077 // special cases |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1078 if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL) |
7 | 1079 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1080 // Ctrl-6 is Ctrl-^ |
7 | 1081 if (pker->wVirtualKeyCode == '6') |
1082 { | |
1083 *pch = Ctrl_HAT; | |
1084 return TRUE; | |
1085 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1086 // Ctrl-2 is Ctrl-@ |
7 | 1087 else if (pker->wVirtualKeyCode == '2') |
1088 { | |
1089 *pch = NUL; | |
1090 return TRUE; | |
1091 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1092 // Ctrl-- is Ctrl-_ |
7 | 1093 else if (pker->wVirtualKeyCode == 0xBD) |
1094 { | |
1095 *pch = Ctrl__; | |
1096 return TRUE; | |
1097 } | |
1098 } | |
1099 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1100 // Shift-TAB |
7 | 1101 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) |
1102 { | |
1103 *pch = K_NUL; | |
1104 *pch2 = '\017'; | |
1105 return TRUE; | |
1106 } | |
1107 | |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24749
diff
changeset
|
1108 for (i = ARRAY_LENGTH(VirtKeyMap); --i >= 0; ) |
7 | 1109 { |
1110 if (VirtKeyMap[i].wVirtKey == pker->wVirtualKeyCode) | |
1111 { | |
1112 if (nModifs == 0) | |
1113 *pch = VirtKeyMap[i].chAlone; | |
1114 else if ((nModifs & SHIFT) != 0 && (nModifs & ~SHIFT) == 0) | |
1115 *pch = VirtKeyMap[i].chShift; | |
1116 else if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0) | |
1117 *pch = VirtKeyMap[i].chCtrl; | |
1118 else if ((nModifs & ALT) != 0 && (nModifs & ~ALT) == 0) | |
1119 *pch = VirtKeyMap[i].chAlt; | |
1120 | |
1121 if (*pch != 0) | |
1122 { | |
1123 if (VirtKeyMap[i].fAnsiKey) | |
1124 { | |
1125 *pch2 = *pch; | |
1126 *pch = K_NUL; | |
1127 } | |
1128 | |
1129 return TRUE; | |
1130 } | |
1131 } | |
1132 } | |
1133 | |
1134 i = win32_kbd_patch_key(pker); | |
1135 | |
1136 if (i < 0) | |
1137 *pch = NUL; | |
1138 else | |
1139 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1140 *pch = (i > 0) ? pker->UChar : NUL; |
7 | 1141 |
1142 if (pmodifiers != NULL) | |
1143 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1144 // 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
|
1145 // with CTRL (which is ALTGR). |
7 | 1146 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) |
1147 *pmodifiers |= MOD_MASK_ALT; | |
1148 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1149 // 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
|
1150 // it's already included with the character. |
7 | 1151 if ((nModifs & SHIFT) != 0 && *pch <= 0x20) |
1152 *pmodifiers |= MOD_MASK_SHIFT; | |
1153 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1154 // 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
|
1155 // 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
|
1156 // combined with ALT (which is ALTGR). |
7 | 1157 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 |
1158 && *pch >= 0x20 && *pch < 0x80) | |
1159 *pmodifiers |= MOD_MASK_CTRL; | |
1160 } | |
1161 } | |
1162 | |
1163 return (*pch != NUL); | |
1164 } | |
1165 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1166 #endif // FEAT_GUI_MSWIN |
7 | 1167 |
1168 | |
1169 /* | |
1170 * For the GUI the mouse handling is in gui_w32.c. | |
1171 */ | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1172 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 1173 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
|
1174 mch_setmouse(int on UNUSED) |
7 | 1175 { |
1176 } | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1177 #else |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1178 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
|
1179 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
|
1180 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
|
1181 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
|
1182 static int g_yMouse; // mouse y coordinate |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1183 static DWORD g_cmodein = 0; // Original console input mode |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1184 static DWORD g_cmodeout = 0; // Original console output mode |
7 | 1185 |
1186 /* | |
1187 * Enable or disable mouse input | |
1188 */ | |
1189 void | |
26 | 1190 mch_setmouse(int on) |
7 | 1191 { |
1192 DWORD cmodein; | |
1193 | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1194 # 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
|
1195 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
|
1196 return; |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1197 # endif |
7 | 1198 if (!g_fMouseAvail) |
1199 return; | |
1200 | |
1201 g_fMouseActive = on; | |
1202 GetConsoleMode(g_hConIn, &cmodein); | |
1203 | |
1204 if (g_fMouseActive) | |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1205 { |
7 | 1206 cmodein |= ENABLE_MOUSE_INPUT; |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1207 cmodein &= ~ENABLE_QUICK_EDIT_MODE; |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1208 } |
7 | 1209 else |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1210 { |
7 | 1211 cmodein &= ~ENABLE_MOUSE_INPUT; |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1212 cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE; |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1213 } |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1214 |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
1215 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS); |
7 | 1216 } |
1217 | |
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
|
1218 |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1219 # 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
|
1220 /* |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1221 * 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
|
1222 */ |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1223 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
|
1224 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
|
1225 { |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1226 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
|
1227 } |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1228 # 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
|
1229 |
7 | 1230 /* |
1231 * Decode a MOUSE_EVENT. If it's a valid event, return MOUSE_LEFT, | |
1232 * MOUSE_MIDDLE, or MOUSE_RIGHT for a click; MOUSE_DRAG for a mouse | |
1233 * move with a button held down; and MOUSE_RELEASE after a MOUSE_DRAG | |
1234 * or a MOUSE_LEFT, _MIDDLE, or _RIGHT. We encode the button type, | |
1235 * the number of clicks, and the Shift/Ctrl/Alt modifiers in g_nMouseClick, | |
1236 * and we return the mouse position in g_xMouse and g_yMouse. | |
1237 * | |
1238 * Every MOUSE_LEFT, _MIDDLE, or _RIGHT will be followed by zero or more | |
1239 * MOUSE_DRAGs and one MOUSE_RELEASE. MOUSE_RELEASE will be followed only | |
1240 * by MOUSE_LEFT, _MIDDLE, or _RIGHT. | |
1241 * | |
1242 * For multiple clicks, we send, say, MOUSE_LEFT/1 click, MOUSE_RELEASE, | |
1243 * MOUSE_LEFT/2 clicks, MOUSE_RELEASE, MOUSE_LEFT/3 clicks, MOUSE_RELEASE, .... | |
1244 * | |
1245 * Windows will send us MOUSE_MOVED notifications whenever the mouse | |
1246 * moves, even if it stays within the same character cell. We ignore | |
1247 * all MOUSE_MOVED messages if the position hasn't really changed, and | |
1248 * we ignore all MOUSE_MOVED messages where no button is held down (i.e., | |
1249 * we're only interested in MOUSE_DRAG). | |
1250 * | |
1251 * All of this is complicated by the code that fakes MOUSE_MIDDLE on | |
1252 * 2-button mouses by pressing the left & right buttons simultaneously. | |
1253 * In practice, it's almost impossible to click both at the same time, | |
1254 * so we need to delay a little. Also, we tend not to get MOUSE_RELEASE | |
1255 * in such cases, if the user is clicking quickly. | |
1256 */ | |
1257 static BOOL | |
1258 decode_mouse_event( | |
26 | 1259 MOUSE_EVENT_RECORD *pmer) |
7 | 1260 { |
1261 static int s_nOldButton = -1; | |
1262 static int s_nOldMouseClick = -1; | |
1263 static int s_xOldMouse = -1; | |
1264 static int s_yOldMouse = -1; | |
1265 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
|
1266 # ifdef FEAT_DIFF |
7 | 1267 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
|
1268 # endif |
7 | 1269 static int s_cClicks = 1; |
1270 static BOOL s_fReleased = TRUE; | |
1271 static DWORD s_dwLastClickTime = 0; | |
1272 static BOOL s_fNextIsMiddle = FALSE; | |
1273 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1274 static DWORD cButtons = 0; // number of buttons supported |
7 | 1275 |
1276 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; | |
1277 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; | |
1278 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED; | |
1279 const DWORD LEFT_RIGHT = LEFT | RIGHT; | |
1280 | |
1281 int nButton; | |
1282 | |
1283 if (cButtons == 0 && !GetNumberOfConsoleMouseButtons(&cButtons)) | |
1284 cButtons = 2; | |
1285 | |
1286 if (!g_fMouseAvail || !g_fMouseActive) | |
1287 { | |
1288 g_nMouseClick = -1; | |
1289 return FALSE; | |
1290 } | |
1291 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1292 // get a spurious MOUSE_EVENT immediately after receiving focus; ignore |
7 | 1293 if (g_fJustGotFocus) |
1294 { | |
1295 g_fJustGotFocus = FALSE; | |
1296 return FALSE; | |
1297 } | |
1298 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1299 // unprocessed mouse click? |
7 | 1300 if (g_nMouseClick != -1) |
1301 return TRUE; | |
1302 | |
1303 nButton = -1; | |
1304 g_xMouse = pmer->dwMousePosition.X; | |
1305 g_yMouse = pmer->dwMousePosition.Y; | |
1306 | |
1307 if (pmer->dwEventFlags == MOUSE_MOVED) | |
1308 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1309 // 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
|
1310 // events even when the mouse moves only within a char cell.) |
7 | 1311 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) |
1312 return FALSE; | |
1313 } | |
1314 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1315 // If no buttons are pressed... |
7 | 1316 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) |
1317 { | |
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
|
1318 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
|
1319 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1320 // If the last thing returned was MOUSE_RELEASE, ignore this |
7 | 1321 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
|
1322 { |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1323 # ifdef FEAT_BEVAL_TERM |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1324 // 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
|
1325 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
|
1326 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
|
1327 else |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1328 # 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
|
1329 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
|
1330 } |
e534e8b21fd7
patch 8.0.1582: in the MS-Windows console mouse movement is not used
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1331 |
7 | 1332 s_fReleased = TRUE; |
1333 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1334 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
|
1335 { |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1336 // 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
|
1337 // simultaneously to get MIDDLE. |
7 | 1338 |
1339 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) | |
1340 { | |
1341 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); | |
1342 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1343 // 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
|
1344 // next mouse event has both of them pressed |
7 | 1345 if (dwLR == LEFT || dwLR == RIGHT) |
1346 { | |
1347 for (;;) | |
1348 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1349 // wait a short time for next input event |
7 | 1350 if (WaitForSingleObject(g_hConIn, p_mouset / 3) |
1351 != WAIT_OBJECT_0) | |
1352 break; | |
1353 else | |
1354 { | |
1355 DWORD cRecords = 0; | |
1356 INPUT_RECORD ir; | |
1357 MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent; | |
1358 | |
5580 | 1359 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1360 |
1361 if (cRecords == 0 || ir.EventType != MOUSE_EVENT | |
1362 || !(pmer2->dwButtonState & LEFT_RIGHT)) | |
1363 break; | |
1364 else | |
1365 { | |
1366 if (pmer2->dwEventFlags != MOUSE_MOVED) | |
1367 { | |
5580 | 1368 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1369 |
1370 return decode_mouse_event(pmer2); | |
1371 } | |
1372 else if (s_xOldMouse == pmer2->dwMousePosition.X && | |
1373 s_yOldMouse == pmer2->dwMousePosition.Y) | |
1374 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1375 // throw away spurious mouse move |
5580 | 1376 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1377 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1378 // are there any more mouse events in queue? |
5580 | 1379 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1380 |
1381 if (cRecords==0 || ir.EventType != MOUSE_EVENT) | |
1382 break; | |
1383 } | |
1384 else | |
1385 break; | |
1386 } | |
1387 } | |
1388 } | |
1389 } | |
1390 } | |
1391 | |
1392 if (s_fNextIsMiddle) | |
1393 { | |
1394 nButton = (pmer->dwEventFlags == MOUSE_MOVED) | |
1395 ? MOUSE_DRAG : MOUSE_MIDDLE; | |
1396 s_fNextIsMiddle = FALSE; | |
1397 } | |
1398 else if (cButtons == 2 && | |
1399 ((pmer->dwButtonState & LEFT_RIGHT) == LEFT_RIGHT)) | |
1400 { | |
1401 nButton = MOUSE_MIDDLE; | |
1402 | |
1403 if (! s_fReleased && pmer->dwEventFlags != MOUSE_MOVED) | |
1404 { | |
1405 s_fNextIsMiddle = TRUE; | |
1406 nButton = MOUSE_RELEASE; | |
1407 } | |
1408 } | |
1409 else if ((pmer->dwButtonState & LEFT) == LEFT) | |
1410 nButton = MOUSE_LEFT; | |
1411 else if ((pmer->dwButtonState & MIDDLE) == MIDDLE) | |
1412 nButton = MOUSE_MIDDLE; | |
1413 else if ((pmer->dwButtonState & RIGHT) == RIGHT) | |
1414 nButton = MOUSE_RIGHT; | |
1415 | |
1416 if (! s_fReleased && ! s_fNextIsMiddle | |
1417 && nButton != s_nOldButton && s_nOldButton != MOUSE_DRAG) | |
1418 return FALSE; | |
1419 | |
1420 s_fReleased = s_fNextIsMiddle; | |
1421 } | |
1422 | |
1423 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) | |
1424 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1425 // button pressed or released, without mouse moving |
7 | 1426 if (nButton != -1 && nButton != MOUSE_RELEASE) |
1427 { | |
1428 DWORD dwCurrentTime = GetTickCount(); | |
1429 | |
1430 if (s_xOldMouse != g_xMouse | |
1431 || s_yOldMouse != g_yMouse | |
1432 || s_nOldButton != nButton | |
1433 || 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
|
1434 # ifdef FEAT_DIFF |
7 | 1435 || 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
|
1436 # endif |
7 | 1437 || (int)(dwCurrentTime - s_dwLastClickTime) > p_mouset) |
1438 { | |
1439 s_cClicks = 1; | |
1440 } | |
1441 else if (++s_cClicks > 4) | |
1442 { | |
1443 s_cClicks = 1; | |
1444 } | |
1445 | |
1446 s_dwLastClickTime = dwCurrentTime; | |
1447 } | |
1448 } | |
1449 else if (pmer->dwEventFlags == MOUSE_MOVED) | |
1450 { | |
1451 if (nButton != -1 && nButton != MOUSE_RELEASE) | |
1452 nButton = MOUSE_DRAG; | |
1453 | |
1454 s_cClicks = 1; | |
1455 } | |
1456 | |
1457 if (nButton == -1) | |
1458 return FALSE; | |
1459 | |
1460 if (nButton != MOUSE_RELEASE) | |
1461 s_nOldButton = nButton; | |
1462 | |
1463 g_nMouseClick = nButton; | |
1464 | |
1465 if (pmer->dwControlKeyState & SHIFT_PRESSED) | |
1466 g_nMouseClick |= MOUSE_SHIFT; | |
1467 if (pmer->dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) | |
1468 g_nMouseClick |= MOUSE_CTRL; | |
1469 if (pmer->dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) | |
1470 g_nMouseClick |= MOUSE_ALT; | |
1471 | |
1472 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) | |
1473 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); | |
1474 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1475 // only pass on interesting (i.e., different) mouse events |
7 | 1476 if (s_xOldMouse == g_xMouse |
1477 && s_yOldMouse == g_yMouse | |
1478 && s_nOldMouseClick == g_nMouseClick) | |
1479 { | |
1480 g_nMouseClick = -1; | |
1481 return FALSE; | |
1482 } | |
1483 | |
1484 s_xOldMouse = g_xMouse; | |
1485 s_yOldMouse = g_yMouse; | |
1486 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
|
1487 # ifdef FEAT_DIFF |
7 | 1488 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
|
1489 # endif |
7 | 1490 s_nOldMouseClick = g_nMouseClick; |
1491 | |
1492 return TRUE; | |
1493 } | |
1494 | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1495 #endif // FEAT_GUI_MSWIN |
7 | 1496 |
1497 | |
1498 #ifdef MCH_CURSOR_SHAPE | |
1499 /* | |
1500 * Set the shape of the cursor. | |
1501 * 'thickness' can be from 1 (thin) to 99 (block) | |
1502 */ | |
1503 static void | |
1504 mch_set_cursor_shape(int thickness) | |
1505 { | |
1506 CONSOLE_CURSOR_INFO ConsoleCursorInfo; | |
1507 ConsoleCursorInfo.dwSize = thickness; | |
1508 ConsoleCursorInfo.bVisible = s_cursor_visible; | |
1509 | |
1510 SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo); | |
1511 if (s_cursor_visible) | |
1512 SetConsoleCursorPosition(g_hConOut, g_coord); | |
1513 } | |
1514 | |
1515 void | |
1516 mch_update_cursor(void) | |
1517 { | |
1518 int idx; | |
1519 int thickness; | |
1520 | |
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
|
1521 # 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
|
1522 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
|
1523 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
|
1524 # 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
|
1525 |
7 | 1526 /* |
1527 * How the cursor is drawn depends on the current mode. | |
1528 */ | |
1529 idx = get_shape_idx(FALSE); | |
1530 | |
1531 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
|
1532 thickness = 99; // 100 doesn't work on W95 |
7 | 1533 else |
1534 thickness = shape_table[idx].percentage; | |
1535 mch_set_cursor_shape(thickness); | |
1536 } | |
1537 #endif | |
1538 | |
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
|
1539 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 1540 /* |
1541 * Handle FOCUS_EVENT. | |
1542 */ | |
1543 static void | |
1544 handle_focus_event(INPUT_RECORD ir) | |
1545 { | |
1546 g_fJustGotFocus = ir.Event.FocusEvent.bSetFocus; | |
1547 ui_focus_change((int)g_fJustGotFocus); | |
1548 } | |
1549 | |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1550 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
|
1551 |
7 | 1552 /* |
1553 * Wait until console input from keyboard or mouse is available, | |
1554 * 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
|
1555 * When "ignore_input" is TRUE even wait when input is available. |
7 | 1556 * Return TRUE if something is available FALSE if not. |
1557 */ | |
1558 static int | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1559 WaitForChar(long msec, int ignore_input) |
7 | 1560 { |
1561 DWORD dwNow = 0, dwEndTime = 0; | |
1562 INPUT_RECORD ir; | |
1563 DWORD cRecords; | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1564 WCHAR ch, ch2; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1565 # ifdef FEAT_TIMERS |
8947
c07caeb90a35
commit https://github.com/vim/vim/commit/40b1b5443c88fab77f1f7c6f9e801f7ffdb7e0a8
Christian Brabandt <cb@256bit.org>
parents:
8589
diff
changeset
|
1566 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
|
1567 # endif |
7 | 1568 |
1569 if (msec > 0) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1570 // Wait until the specified time has elapsed. |
7 | 1571 dwEndTime = GetTickCount() + msec; |
1572 else if (msec < 0) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1573 // Wait forever. |
7 | 1574 dwEndTime = INFINITE; |
1575 | |
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
|
1576 // 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
|
1577 // we might get multiple unusable mouse events in that time. |
7 | 1578 for (;;) |
1579 { | |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1580 // 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
|
1581 if (msec != 0) |
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1582 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1583 # 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
|
1584 parse_queued_messages(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1585 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1586 # 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
|
1587 mzvim_check_threads(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1588 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1589 # 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
|
1590 serverProcessPendingMessages(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1591 # endif |
14673
f1b7d308de2f
patch 8.1.0349: crash when wiping buffer in a callback
Christian Brabandt <cb@256bit.org>
parents:
14650
diff
changeset
|
1592 } |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1593 |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18275
diff
changeset
|
1594 if (g_nMouseClick != -1 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1595 # ifdef FEAT_CLIENTSERVER |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1596 || (!ignore_input && input_available()) |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1597 # endif |
7 | 1598 ) |
1599 return TRUE; | |
1600 | |
1601 if (msec > 0) | |
1602 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1603 // 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
|
1604 // GetTickCount() may wrap around (overflow). |
7 | 1605 dwNow = GetTickCount(); |
5292
d5d6b78cff09
updated for version 7.4b.022
Bram Moolenaar <bram@vim.org>
parents:
5229
diff
changeset
|
1606 if ((int)(dwNow - dwEndTime) >= 0) |
7 | 1607 break; |
1608 } | |
1609 if (msec != 0) | |
1610 { | |
14 | 1611 DWORD dwWaitTime = dwEndTime - dwNow; |
1612 | |
23060
ab8a9b9bd349
patch 8.2.2076: MS-Windows console: sometimes drops typed characters
Bram Moolenaar <Bram@vim.org>
parents:
22856
diff
changeset
|
1613 // Don't wait for more than 11 msec to avoid dropping characters, |
ab8a9b9bd349
patch 8.2.2076: MS-Windows console: sometimes drops typed characters
Bram Moolenaar <Bram@vim.org>
parents:
22856
diff
changeset
|
1614 // check channel while waiting for input and handle a callback from |
ab8a9b9bd349
patch 8.2.2076: MS-Windows console: sometimes drops typed characters
Bram Moolenaar <Bram@vim.org>
parents:
22856
diff
changeset
|
1615 // 'balloonexpr'. |
ab8a9b9bd349
patch 8.2.2076: MS-Windows console: sometimes drops typed characters
Bram Moolenaar <Bram@vim.org>
parents:
22856
diff
changeset
|
1616 if (dwWaitTime > 11) |
ab8a9b9bd349
patch 8.2.2076: MS-Windows console: sometimes drops typed characters
Bram Moolenaar <Bram@vim.org>
parents:
22856
diff
changeset
|
1617 dwWaitTime = 11; |
ab8a9b9bd349
patch 8.2.2076: MS-Windows console: sometimes drops typed characters
Bram Moolenaar <Bram@vim.org>
parents:
22856
diff
changeset
|
1618 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1619 # ifdef FEAT_MZSCHEME |
23060
ab8a9b9bd349
patch 8.2.2076: MS-Windows console: sometimes drops typed characters
Bram Moolenaar <Bram@vim.org>
parents:
22856
diff
changeset
|
1620 if (mzthreads_allowed() && p_mzq > 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
|
1621 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
|
1622 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1623 # ifdef FEAT_TIMERS |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1624 // 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
|
1625 if (dwWaitTime > 10) |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1626 { |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1627 long due_time; |
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1628 |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1629 // 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
|
1630 // 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
|
1631 due_time = check_due_timer(); |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1632 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
|
1633 { |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1634 // timer may have used feedkeys(). |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1635 return FALSE; |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1636 } |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1637 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
|
1638 dwWaitTime = due_time; |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1639 } |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1640 # endif |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1641 if ( |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1642 # ifdef FEAT_CLIENTSERVER |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1643 // 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
|
1644 // 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
|
1645 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
|
1646 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
|
1647 # else |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1648 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
|
1649 != WAIT_OBJECT_0 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1650 # endif |
15553
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1651 ) |
df198b298bff
patch 8.1.0784: messy indent in if statement
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1652 continue; |
7 | 1653 } |
1654 | |
1655 cRecords = 0; | |
5580 | 1656 peek_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1657 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1658 # ifdef FEAT_MBYTE_IME |
24671
703bf1d19cfe
patch 8.2.2874: MS-Windows: screen redraws too often
Bram Moolenaar <Bram@vim.org>
parents:
24604
diff
changeset
|
1659 // May have to redraw if the cursor ends up in the wrong place. |
703bf1d19cfe
patch 8.2.2874: MS-Windows: screen redraws too often
Bram Moolenaar <Bram@vim.org>
parents:
24604
diff
changeset
|
1660 // Only when not peeking. |
703bf1d19cfe
patch 8.2.2874: MS-Windows: screen redraws too often
Bram Moolenaar <Bram@vim.org>
parents:
24604
diff
changeset
|
1661 if (State & CMDLINE && msg_row == Rows - 1 && msec != 0) |
7 | 1662 { |
1663 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
1664 | |
1665 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
1666 { | |
1667 if (csbi.dwCursorPosition.Y != msg_row) | |
1668 { | |
24604
b1ba40ea418d
patch 8.2.2841: MS-Windows: cursor wrong when 'lz' and 'stl' are set
Bram Moolenaar <Bram@vim.org>
parents:
24563
diff
changeset
|
1669 // The screen is now messed up, must redraw the command |
b1ba40ea418d
patch 8.2.2841: MS-Windows: cursor wrong when 'lz' and 'stl' are set
Bram Moolenaar <Bram@vim.org>
parents:
24563
diff
changeset
|
1670 // line and later all the windows. |
7 | 1671 redraw_all_later(CLEAR); |
24604
b1ba40ea418d
patch 8.2.2841: MS-Windows: cursor wrong when 'lz' and 'stl' are set
Bram Moolenaar <Bram@vim.org>
parents:
24563
diff
changeset
|
1672 compute_cmdrow(); |
7 | 1673 redrawcmd(); |
1674 } | |
1675 } | |
1676 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1677 # endif |
7 | 1678 |
1679 if (cRecords > 0) | |
1680 { | |
1681 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) | |
1682 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1683 # ifdef FEAT_MBYTE_IME |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1684 // 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
|
1685 // wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1686 if (ir.Event.KeyEvent.UChar == 0 |
7 | 1687 && ir.Event.KeyEvent.wVirtualKeyCode == 13) |
1688 { | |
5580 | 1689 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1690 continue; |
1691 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1692 # endif |
7 | 1693 if (decode_key_event(&ir.Event.KeyEvent, &ch, &ch2, |
1694 NULL, FALSE)) | |
1695 return TRUE; | |
1696 } | |
1697 | |
5580 | 1698 read_console_input(g_hConIn, &ir, 1, &cRecords); |
7 | 1699 |
1700 if (ir.EventType == FOCUS_EVENT) | |
1701 handle_focus_event(ir); | |
1702 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
|
1703 { |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1704 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
|
1705 |
18876
44906eff69f9
patch 8.1.2424: MS-Windows: console buffer is resized unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
18810
diff
changeset
|
1706 // Only call shell_resized() when the size actually changed to |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1707 // 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
|
1708 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
|
1709 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1710 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
|
1711 GetConsoleScreenBufferInfo(g_hConOut, &csbi); |
18876
44906eff69f9
patch 8.1.2424: MS-Windows: console buffer is resized unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
18810
diff
changeset
|
1712 dwSize.X = csbi.srWindow.Right - csbi.srWindow.Left + 1; |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1713 dwSize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; |
18876
44906eff69f9
patch 8.1.2424: MS-Windows: console buffer is resized unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
18810
diff
changeset
|
1714 if (dwSize.X != Columns || dwSize.Y != Rows) |
44906eff69f9
patch 8.1.2424: MS-Windows: console buffer is resized unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
18810
diff
changeset
|
1715 { |
44906eff69f9
patch 8.1.2424: MS-Windows: console buffer is resized unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
18810
diff
changeset
|
1716 ResizeConBuf(g_hConOut, dwSize); |
44906eff69f9
patch 8.1.2424: MS-Windows: console buffer is resized unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
18810
diff
changeset
|
1717 shell_resized(); |
44906eff69f9
patch 8.1.2424: MS-Windows: console buffer is resized unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
18810
diff
changeset
|
1718 } |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
1719 } |
13260
ee1a1276a759
patch 8.0.1504: Win32: the screen may be cleared on startup
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1720 } |
7 | 1721 else if (ir.EventType == MOUSE_EVENT |
1722 && decode_mouse_event(&ir.Event.MouseEvent)) | |
1723 return TRUE; | |
1724 } | |
1725 else if (msec == 0) | |
1726 break; | |
1727 } | |
1728 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1729 # ifdef FEAT_CLIENTSERVER |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1730 // Something might have been received while we were waiting. |
7 | 1731 if (input_available()) |
1732 return TRUE; | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1733 # endif |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7784
diff
changeset
|
1734 |
7 | 1735 return FALSE; |
1736 } | |
1737 | |
1738 /* | |
1739 * return non-zero if a character is available | |
1740 */ | |
1741 int | |
26 | 1742 mch_char_avail(void) |
7 | 1743 { |
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
|
1744 # 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
|
1745 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
|
1746 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
|
1747 # endif |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1748 return WaitForChar(0L, FALSE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1749 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1750 |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1751 # 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
|
1752 /* |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1753 * 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
|
1754 */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1755 int |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1756 mch_check_messages(void) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1757 { |
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
|
1758 # 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
|
1759 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
|
1760 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
|
1761 # endif |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1762 return WaitForChar(0L, TRUE); |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1763 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1764 # endif |
7 | 1765 |
1766 /* | |
1767 * Create the console input. Used when reading stdin doesn't work. | |
1768 */ | |
1769 static void | |
1770 create_conin(void) | |
1771 { | |
1772 g_hConIn = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE, | |
1773 FILE_SHARE_READ|FILE_SHARE_WRITE, | |
1774 (LPSECURITY_ATTRIBUTES) NULL, | |
840 | 1775 OPEN_EXISTING, 0, (HANDLE)NULL); |
7 | 1776 did_create_conin = TRUE; |
1777 } | |
1778 | |
1779 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
1780 * Get a keystroke or a mouse event, use a blocking wait. |
7 | 1781 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1782 static WCHAR |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1783 tgetch(int *pmodifiers, WCHAR *pch2) |
7 | 1784 { |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1785 WCHAR ch; |
7 | 1786 |
1787 for (;;) | |
1788 { | |
1789 INPUT_RECORD ir; | |
1790 DWORD cRecords = 0; | |
1791 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1792 # ifdef FEAT_CLIENTSERVER |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1793 (void)WaitForChar(-1L, FALSE); |
7 | 1794 if (input_available()) |
1795 return 0; | |
1796 if (g_nMouseClick != -1) | |
1797 return 0; | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1798 # endif |
5580 | 1799 if (read_console_input(g_hConIn, &ir, 1, &cRecords) == 0) |
7 | 1800 { |
1801 if (did_create_conin) | |
1802 read_error_exit(); | |
1803 create_conin(); | |
1804 continue; | |
1805 } | |
1806 | |
1807 if (ir.EventType == KEY_EVENT) | |
1808 { | |
1809 if (decode_key_event(&ir.Event.KeyEvent, &ch, pch2, | |
1810 pmodifiers, TRUE)) | |
1811 return ch; | |
1812 } | |
1813 else if (ir.EventType == FOCUS_EVENT) | |
1814 handle_focus_event(ir); | |
1815 else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT) | |
1816 shell_resized(); | |
1817 else if (ir.EventType == MOUSE_EVENT) | |
1818 { | |
1819 if (decode_mouse_event(&ir.Event.MouseEvent)) | |
1820 return 0; | |
1821 } | |
1822 } | |
1823 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1824 #endif // !FEAT_GUI_MSWIN |
7 | 1825 |
1826 | |
1827 /* | |
3622 | 1828 * mch_inchar(): low-level input function. |
7 | 1829 * Get one or more characters from the keyboard or the mouse. |
1830 * If time == 0, do not wait for characters. | |
1831 * If time == n, wait a short time for characters. | |
1832 * If time == -1, wait forever for characters. | |
1833 * Returns the number of characters read into buf. | |
1834 */ | |
1835 int | |
1836 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
|
1837 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
|
1838 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
|
1839 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
|
1840 int tb_change_cnt UNUSED) |
7 | 1841 { |
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
|
1842 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 1843 |
1844 int len; | |
1845 int c; | |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1846 # ifdef VIMDLL |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1847 // Extra space for maximum three CSIs. E.g. U+1B6DB -> 0xF0 0x9B 0x9B 0x9B. |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1848 # define TYPEAHEADSPACE 6 |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1849 # else |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1850 # define TYPEAHEADSPACE 0 |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1851 # endif |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1852 # define TYPEAHEADLEN (20 + TYPEAHEADSPACE) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1853 static char_u typeahead[TYPEAHEADLEN]; // previously typed bytes. |
7 | 1854 static int typeaheadlen = 0; |
1855 | |
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
|
1856 # 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
|
1857 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
|
1858 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
|
1859 # 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
|
1860 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1861 // First use any typeahead that was kept because "buf" was too small. |
7 | 1862 if (typeaheadlen > 0) |
1863 goto theend; | |
1864 | |
1865 if (time >= 0) | |
1866 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1867 if (!WaitForChar(time, FALSE)) // no character available |
7 | 1868 return 0; |
1869 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1870 else // time == -1, wait forever |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1871 { |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1872 mch_set_winsize_now(); // Allow winsize changes from now on |
7 | 1873 |
203 | 1874 /* |
1875 * If there is no character available within 2 seconds (default) | |
1876 * write the autoscript file to disk. Or cause the CursorHold event | |
1877 * to be triggered. | |
1878 */ | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
1879 if (!WaitForChar(p_ut, FALSE)) |
7 | 1880 { |
609 | 1881 if (trigger_cursorhold() && maxlen >= 3) |
7 | 1882 { |
203 | 1883 buf[0] = K_SPECIAL; |
1884 buf[1] = KS_EXTRA; | |
1885 buf[2] = (int)KE_CURSORHOLD; | |
1886 return 3; | |
7 | 1887 } |
368 | 1888 before_blocking(); |
7 | 1889 } |
1890 } | |
1891 | |
1892 /* | |
1893 * Try to read as many characters as there are, until the buffer is full. | |
1894 */ | |
1895 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1896 // we will get at least one key. Get more if they are available. |
7 | 1897 g_fCBrkPressed = FALSE; |
1898 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1899 # ifdef MCH_WRITE_DUMP |
7 | 1900 if (fdDump) |
1901 fputc('[', fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1902 # endif |
7 | 1903 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1904 // 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
|
1905 // 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
|
1906 // 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
|
1907 while ((typeaheadlen == 0 || WaitForChar(0L, FALSE)) |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1908 && typeaheadlen + 5 + TYPEAHEADSPACE <= TYPEAHEADLEN) |
7 | 1909 { |
1910 if (typebuf_changed(tb_change_cnt)) | |
1911 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1912 // "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
|
1913 // typeahead buffer and "buf" is in the typeahead buffer. |
7 | 1914 typeaheadlen = 0; |
1915 break; | |
1916 } | |
1917 if (g_nMouseClick != -1) | |
1918 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1919 # ifdef MCH_WRITE_DUMP |
7 | 1920 if (fdDump) |
1921 fprintf(fdDump, "{%02x @ %d, %d}", | |
1922 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
|
1923 # endif |
7 | 1924 typeahead[typeaheadlen++] = ESC + 128; |
1925 typeahead[typeaheadlen++] = 'M'; | |
1926 typeahead[typeaheadlen++] = g_nMouseClick; | |
1927 typeahead[typeaheadlen++] = g_xMouse + '!'; | |
1928 typeahead[typeaheadlen++] = g_yMouse + '!'; | |
1929 g_nMouseClick = -1; | |
1930 } | |
1931 else | |
1932 { | |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1933 WCHAR ch2 = NUL; |
7 | 1934 int modifiers = 0; |
1935 | |
1936 c = tgetch(&modifiers, &ch2); | |
1937 | |
1938 if (typebuf_changed(tb_change_cnt)) | |
1939 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1940 // "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
|
1941 // typeahead buffer and "buf" is in the typeahead buffer. |
7 | 1942 typeaheadlen = 0; |
1943 break; | |
1944 } | |
1945 | |
1946 if (c == Ctrl_C && ctrl_c_interrupts) | |
1947 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1948 # if defined(FEAT_CLIENTSERVER) |
7 | 1949 trash_input_buf(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
1950 # endif |
7 | 1951 got_int = TRUE; |
1952 } | |
1953 | |
1954 if (g_nMouseClick == -1) | |
1955 { | |
1956 int n = 1; | |
6047 | 1957 |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1958 if (ch2 == NUL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1959 { |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1960 int i, j; |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1961 char_u *p; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1962 WCHAR ch[2]; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1963 |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1964 ch[0] = c; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
1965 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
|
1966 { |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1967 ch[1] = tgetch(&modifiers, &ch2); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1968 n++; |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1969 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1970 p = utf16_to_enc(ch, &n); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1971 if (p != NULL) |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1972 { |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1973 for (i = 0, j = 0; i < n; i++) |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1974 { |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1975 typeahead[typeaheadlen + j++] = p[i]; |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1976 # ifdef VIMDLL |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1977 if (p[i] == CSI) |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1978 { |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1979 typeahead[typeaheadlen + j++] = KS_EXTRA; |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1980 typeahead[typeaheadlen + j++] = KE_CSI; |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1981 } |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1982 # endif |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1983 } |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1984 n = j; |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1985 vim_free(p); |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1986 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1987 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1988 else |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1989 { |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
1990 typeahead[typeaheadlen] = c; |
19599
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1991 # ifdef VIMDLL |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1992 if (c == CSI) |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1993 { |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1994 typeahead[typeaheadlen + 1] = KS_EXTRA; |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1995 typeahead[typeaheadlen + 2] = KE_CSI; |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1996 n = 3; |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1997 } |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1998 # endif |
5eb0ead1415f
patch 8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
1999 } |
7 | 2000 if (ch2 != NUL) |
2001 { | |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2002 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
|
2003 { |
14891
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2004 switch (ch2) |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2005 { |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2006 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
|
2007 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
|
2008 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
|
2009 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
|
2010 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
|
2011 n++; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2012 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2013 |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2014 default: |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2015 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
|
2016 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
|
2017 n += 2; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2018 break; |
66176f8735aa
patch 8.1.0457: win32 console: key mappings don't work
Bram Moolenaar <Bram@vim.org>
parents:
14883
diff
changeset
|
2019 } |
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
|
2020 } |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
2021 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
|
2022 { |
ec86ba548446
patch 8.0.1371: Shift-Insert doesn't always work in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
12958
diff
changeset
|
2023 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
|
2024 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
|
2025 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
|
2026 } |
6047 | 2027 } |
2028 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2029 // 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
|
2030 // 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
|
2031 // 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
|
2032 // byte). |
7 | 2033 if ((modifiers & MOD_MASK_ALT) |
2034 && n == 1 | |
2035 && (typeahead[typeaheadlen] & 0x80) == 0 | |
2036 && !enc_dbcs | |
2037 ) | |
2038 { | |
1443 | 2039 n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80, |
2040 typeahead + typeaheadlen); | |
7 | 2041 modifiers &= ~MOD_MASK_ALT; |
2042 } | |
2043 | |
2044 if (modifiers != 0) | |
2045 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2046 // Prepend modifiers to the character. |
7 | 2047 mch_memmove(typeahead + typeaheadlen + 3, |
2048 typeahead + typeaheadlen, n); | |
2049 typeahead[typeaheadlen++] = K_SPECIAL; | |
2050 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER; | |
2051 typeahead[typeaheadlen++] = modifiers; | |
2052 } | |
2053 | |
2054 typeaheadlen += n; | |
2055 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2056 # ifdef MCH_WRITE_DUMP |
7 | 2057 if (fdDump) |
2058 fputc(c, fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2059 # endif |
7 | 2060 } |
2061 } | |
2062 } | |
2063 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2064 # ifdef MCH_WRITE_DUMP |
7 | 2065 if (fdDump) |
2066 { | |
2067 fputs("]\n", fdDump); | |
2068 fflush(fdDump); | |
2069 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2070 # endif |
7 | 2071 |
2072 theend: | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2073 // Move typeahead to "buf", as much as fits. |
7 | 2074 len = 0; |
2075 while (len < maxlen && typeaheadlen > 0) | |
2076 { | |
2077 buf[len++] = typeahead[0]; | |
2078 mch_memmove(typeahead, typeahead + 1, --typeaheadlen); | |
2079 } | |
22065
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
2080 # ifdef FEAT_JOB_CHANNEL |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
2081 if (len > 0) |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
2082 { |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
2083 buf[len] = NUL; |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
2084 ch_log(NULL, "raw key input: \"%s\"", buf); |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
2085 } |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
2086 # endif |
7 | 2087 return len; |
2088 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2089 #else // FEAT_GUI_MSWIN |
7 | 2090 return 0; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2091 #endif // FEAT_GUI_MSWIN |
7 | 2092 } |
2093 | |
3927 | 2094 #ifndef PROTO |
2095 # ifndef __MINGW32__ | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2096 # include <shellapi.h> // required for FindExecutable() |
3927 | 2097 # endif |
7 | 2098 #endif |
2099 | |
9 | 2100 /* |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2101 * Return TRUE if "name" is an executable file, FALSE if not or it doesn't exist. |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2102 * 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
|
2103 * the allocated memory. |
10 | 2104 * TODO: Should somehow check if it's really executable. |
9 | 2105 */ |
7 | 2106 static int |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2107 executable_file(char *name, char_u **path) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2108 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2109 if (mch_getperm((char_u *)name) != -1 && !mch_isdir((char_u *)name)) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2110 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2111 if (path != NULL) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2112 *path = FullName_save((char_u *)name, FALSE); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2113 return TRUE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2114 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2115 return FALSE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2116 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2117 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2118 /* |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2119 * If "use_path" is TRUE: Return TRUE if "name" is in $PATH. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2120 * If "use_path" is FALSE: Return TRUE if "name" exists. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2121 * If "use_pathext" is TRUE search "name" with extensions in $PATHEXT. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2122 * When returning TRUE and "path" is not NULL save the path and set "*path" to |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2123 * the allocated memory. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2124 */ |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2125 static int |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2126 executable_exists(char *name, char_u **path, int use_path, int use_pathext) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2127 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2128 // WinNT and later can use _MAX_PATH wide characters for a pathname, which |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2129 // means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2130 // UTF-8. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2131 char_u buf[_MAX_PATH * 3]; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2132 size_t len = STRLEN(name); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2133 size_t tmplen; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2134 char_u *p, *e, *e2; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2135 char_u *pathbuf = NULL; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2136 char_u *pathext = NULL; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2137 char_u *pathextbuf = NULL; |
25084
beff72446e2e
patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents:
25068
diff
changeset
|
2138 char_u *shname = NULL; |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2139 int noext = FALSE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2140 int retval = FALSE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2141 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2142 if (len >= sizeof(buf)) // safety check |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
2143 return FALSE; |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2144 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2145 // Using the name directly when a Unix-shell like 'shell'. |
25084
beff72446e2e
patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents:
25068
diff
changeset
|
2146 shname = gettail(p_sh); |
beff72446e2e
patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents:
25068
diff
changeset
|
2147 if (strstr((char *)shname, "sh") != NULL && |
beff72446e2e
patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents:
25068
diff
changeset
|
2148 !(strstr((char *)shname, "powershell") != NULL |
beff72446e2e
patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents:
25068
diff
changeset
|
2149 || strstr((char *)shname, "pwsh") != NULL)) |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2150 noext = TRUE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2151 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2152 if (use_pathext) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2153 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2154 pathext = mch_getenv("PATHEXT"); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2155 if (pathext == NULL) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2156 pathext = (char_u *)".com;.exe;.bat;.cmd"; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2157 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2158 if (noext == FALSE) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2159 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2160 /* |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2161 * Loop over all extensions in $PATHEXT. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2162 * Check "name" ends with extension. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2163 */ |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2164 p = pathext; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2165 while (*p) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2166 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2167 if (p[0] == ';' |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2168 || (p[0] == '.' && (p[1] == NUL || p[1] == ';'))) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2169 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2170 // Skip empty or single ".". |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2171 ++p; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2172 continue; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2173 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2174 e = vim_strchr(p, ';'); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2175 if (e == NULL) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2176 e = p + STRLEN(p); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2177 tmplen = e - p; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2178 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2179 if (_strnicoll(name + len - tmplen, (char *)p, tmplen) == 0) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2180 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2181 noext = TRUE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2182 break; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2183 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2184 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2185 p = e; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2186 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2187 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2188 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2189 |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
2190 // Prepend single "." to pathext, it means no extension added. |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2191 if (pathext == NULL) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2192 pathext = (char_u *)"."; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2193 else if (noext == TRUE) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2194 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2195 if (pathextbuf == NULL) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2196 pathextbuf = alloc(STRLEN(pathext) + 3); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2197 if (pathextbuf == NULL) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2198 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2199 retval = FALSE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2200 goto theend; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2201 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2202 STRCPY(pathextbuf, ".;"); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2203 STRCAT(pathextbuf, pathext); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2204 pathext = pathextbuf; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2205 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2206 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2207 // Use $PATH when "use_path" is TRUE and "name" is basename. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2208 if (use_path && gettail((char_u *)name) == (char_u *)name) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2209 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2210 p = mch_getenv("PATH"); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2211 if (p != NULL) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2212 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2213 pathbuf = alloc(STRLEN(p) + 3); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2214 if (pathbuf == NULL) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2215 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2216 retval = FALSE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2217 goto theend; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2218 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2219 STRCPY(pathbuf, ".;"); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2220 STRCAT(pathbuf, p); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2221 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2222 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2223 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2224 /* |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2225 * Walk through all entries in $PATH to check if "name" exists there and |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2226 * is an executable file. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2227 */ |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2228 p = (pathbuf != NULL) ? pathbuf : (char_u *)"."; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2229 while (*p) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2230 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2231 if (*p == ';') // Skip empty entry |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2232 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2233 ++p; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2234 continue; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2235 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2236 e = vim_strchr(p, ';'); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2237 if (e == NULL) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2238 e = p + STRLEN(p); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2239 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2240 if (e - p + len + 2 > sizeof(buf)) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2241 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2242 retval = FALSE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2243 goto theend; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2244 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2245 // A single "." that means current dir. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2246 if (e - p == 1 && *p == '.') |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2247 STRCPY(buf, name); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2248 else |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2249 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2250 vim_strncpy(buf, p, e - p); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2251 add_pathsep(buf); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2252 STRCAT(buf, name); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2253 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2254 tmplen = STRLEN(buf); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2255 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2256 /* |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2257 * Loop over all extensions in $PATHEXT. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2258 * Check "name" with extension added. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2259 */ |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2260 p = pathext; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2261 while (*p) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2262 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2263 if (*p == ';') |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2264 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2265 // Skip empty entry |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2266 ++p; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2267 continue; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2268 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2269 e2 = vim_strchr(p, (int)';'); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2270 if (e2 == NULL) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2271 e2 = p + STRLEN(p); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2272 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2273 if (!(p[0] == '.' && (p[1] == NUL || p[1] == ';'))) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2274 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2275 // Not a single "." that means no extension is added. |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2276 if (e2 - p + tmplen + 1 > sizeof(buf)) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2277 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2278 retval = FALSE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2279 goto theend; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2280 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2281 vim_strncpy(buf + tmplen, p, e2 - p); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2282 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2283 if (executable_file((char *)buf, path)) |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2284 { |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2285 retval = TRUE; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2286 goto theend; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2287 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2288 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2289 p = e2; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2290 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2291 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2292 p = e; |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2293 } |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2294 |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2295 theend: |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2296 free(pathextbuf); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2297 free(pathbuf); |
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2298 return retval; |
7 | 2299 } |
2300 | |
15955
907481b9260f
patch 8.1.0983: checking __CYGWIN32__ unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2301 #if (defined(__MINGW32__) && __MSVCRT_VERSION__ >= 0x800) || \ |
907481b9260f
patch 8.1.0983: checking __CYGWIN32__ unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2302 (defined(_MSC_VER) && _MSC_VER >= 1400) |
2584 | 2303 /* |
2304 * Bad parameter handler. | |
2305 * | |
2306 * Certain MS CRT functions will intentionally crash when passed invalid | |
2307 * parameters to highlight possible security holes. Setting this function as | |
2308 * the bad parameter handler will prevent the crash. | |
2309 * | |
2310 * In debug builds the parameters contain CRT information that might help track | |
2311 * down the source of a problem, but in non-debug builds the arguments are all | |
2312 * NULL/0. Debug builds will also produce assert dialogs from the CRT, it is | |
2313 * worth allowing these to make debugging of issues easier. | |
2314 */ | |
2315 static void | |
2316 bad_param_handler(const wchar_t *expression, | |
2317 const wchar_t *function, | |
2318 const wchar_t *file, | |
2319 unsigned int line, | |
2320 uintptr_t pReserved) | |
2321 { | |
2322 } | |
2323 | |
2324 # define SET_INVALID_PARAM_HANDLER \ | |
2325 ((void)_set_invalid_parameter_handler(bad_param_handler)) | |
2326 #else | |
2327 # define SET_INVALID_PARAM_HANDLER | |
2328 #endif | |
2329 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
2330 #ifdef FEAT_GUI_MSWIN |
7 | 2331 |
2332 /* | |
2333 * GUI version of mch_init(). | |
2334 */ | |
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
|
2335 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
|
2336 mch_init_g(void) |
7 | 2337 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2338 # ifndef __MINGW32__ |
7 | 2339 extern int _fmode; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2340 # endif |
7 | 2341 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2342 // Silently handle invalid parameters to CRT functions |
2584 | 2343 SET_INVALID_PARAM_HANDLER; |
2344 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2345 // 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
|
2346 // for the timestamp test to work on removed floppies. |
7 | 2347 SetErrorMode(SEM_FAILCRITICALERRORS); |
2348 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2349 _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
|
2350 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2351 // Specify window size. Is there a place to get the default from? |
7 | 2352 Rows = 25; |
2353 Columns = 80; | |
2354 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2355 // Look for 'vimrun' |
7 | 2356 { |
2357 char_u vimrun_location[_MAX_PATH + 4]; | |
2358 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2359 // First try in same directory as gvim.exe |
7 | 2360 STRCPY(vimrun_location, exe_name); |
2361 STRCPY(gettail(vimrun_location), "vimrun.exe"); | |
2362 if (mch_getperm(vimrun_location) >= 0) | |
2363 { | |
2364 if (*skiptowhite(vimrun_location) != NUL) | |
2365 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2366 // Enclose path with white space in double quotes. |
7 | 2367 mch_memmove(vimrun_location + 1, vimrun_location, |
2368 STRLEN(vimrun_location) + 1); | |
2369 *vimrun_location = '"'; | |
2370 STRCPY(gettail(vimrun_location), "vimrun\" "); | |
2371 } | |
2372 else | |
2373 STRCPY(gettail(vimrun_location), "vimrun "); | |
2374 | |
2375 vimrun_path = (char *)vim_strsave(vimrun_location); | |
2376 s_dont_use_vimrun = FALSE; | |
2377 } | |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2378 else if (executable_exists("vimrun.exe", NULL, TRUE, FALSE)) |
7 | 2379 s_dont_use_vimrun = FALSE; |
2380 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2381 // 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
|
2382 // 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
|
2383 // not need vimrun.exe. |
7 | 2384 if (s_dont_use_vimrun) |
2385 need_vimrun_warning = TRUE; | |
2386 } | |
2387 | |
2388 /* | |
2389 * If "finstr.exe" doesn't exist, use "grep -n" for 'grepprg'. | |
2390 * Otherwise the default "findstr /n" is used. | |
2391 */ | |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
2392 if (!executable_exists("findstr.exe", NULL, TRUE, FALSE)) |
7 | 2393 set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0); |
2394 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2395 # ifdef FEAT_CLIPBOARD |
4168 | 2396 win_clip_init(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2397 # 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
|
2398 |
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
|
2399 vtp_flag_init(); |
7 | 2400 } |
2401 | |
2402 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2403 #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
|
2404 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2405 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 2406 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2407 # 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
|
2408 # define SRHEIGHT(sr) ((sr).Bottom - (sr).Top + 1) |
7 | 2409 |
2410 /* | |
2411 * ClearConsoleBuffer() | |
2412 * Description: | |
2413 * Clears the entire contents of the console screen buffer, using the | |
2414 * specified attribute. | |
2415 * Returns: | |
2416 * TRUE on success | |
2417 */ | |
2418 static BOOL | |
2419 ClearConsoleBuffer(WORD wAttribute) | |
2420 { | |
2421 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2422 COORD coord; | |
2423 DWORD NumCells, dummy; | |
2424 | |
2425 if (!GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2426 return FALSE; | |
2427 | |
2428 NumCells = csbi.dwSize.X * csbi.dwSize.Y; | |
2429 coord.X = 0; | |
2430 coord.Y = 0; | |
2431 if (!FillConsoleOutputCharacter(g_hConOut, ' ', NumCells, | |
2432 coord, &dummy)) | |
2433 return FALSE; | |
2434 if (!FillConsoleOutputAttribute(g_hConOut, wAttribute, NumCells, | |
2435 coord, &dummy)) | |
2436 return FALSE; | |
2437 | |
2438 return TRUE; | |
2439 } | |
2440 | |
2441 /* | |
2442 * FitConsoleWindow() | |
2443 * Description: | |
2444 * Checks if the console window will fit within given buffer dimensions. | |
2445 * Also, if requested, will shrink the window to fit. | |
2446 * Returns: | |
2447 * TRUE on success | |
2448 */ | |
2449 static BOOL | |
2450 FitConsoleWindow( | |
2451 COORD dwBufferSize, | |
2452 BOOL WantAdjust) | |
2453 { | |
2454 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
2455 COORD dwWindowSize; | |
2456 BOOL NeedAdjust = FALSE; | |
2457 | |
2458 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
2459 { | |
2460 /* | |
2461 * A buffer resize will fail if the current console window does | |
2462 * not lie completely within that buffer. To avoid this, we might | |
2463 * have to move and possibly shrink the window. | |
2464 */ | |
2465 if (csbi.srWindow.Right >= dwBufferSize.X) | |
2466 { | |
2467 dwWindowSize.X = SRWIDTH(csbi.srWindow); | |
2468 if (dwWindowSize.X > dwBufferSize.X) | |
2469 dwWindowSize.X = dwBufferSize.X; | |
2470 csbi.srWindow.Right = dwBufferSize.X - 1; | |
2471 csbi.srWindow.Left = dwBufferSize.X - dwWindowSize.X; | |
2472 NeedAdjust = TRUE; | |
2473 } | |
2474 if (csbi.srWindow.Bottom >= dwBufferSize.Y) | |
2475 { | |
2476 dwWindowSize.Y = SRHEIGHT(csbi.srWindow); | |
2477 if (dwWindowSize.Y > dwBufferSize.Y) | |
2478 dwWindowSize.Y = dwBufferSize.Y; | |
2479 csbi.srWindow.Bottom = dwBufferSize.Y - 1; | |
2480 csbi.srWindow.Top = dwBufferSize.Y - dwWindowSize.Y; | |
2481 NeedAdjust = TRUE; | |
2482 } | |
2483 if (NeedAdjust && WantAdjust) | |
2484 { | |
2485 if (!SetConsoleWindowInfo(g_hConOut, TRUE, &csbi.srWindow)) | |
2486 return FALSE; | |
2487 } | |
2488 return TRUE; | |
2489 } | |
2490 | |
2491 return FALSE; | |
2492 } | |
2493 | |
2494 typedef struct ConsoleBufferStruct | |
2495 { | |
26 | 2496 BOOL IsValid; |
2497 CONSOLE_SCREEN_BUFFER_INFO Info; | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2498 PCHAR_INFO Buffer; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2499 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
|
2500 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
|
2501 int NumRegions; |
7 | 2502 } ConsoleBuffer; |
2503 | |
2504 /* | |
2505 * SaveConsoleBuffer() | |
2506 * Description: | |
2507 * Saves important information about the console buffer, including the | |
2508 * actual buffer contents. The saved information is suitable for later | |
2509 * restoration by RestoreConsoleBuffer(). | |
2510 * Returns: | |
2511 * TRUE if all information was saved; FALSE otherwise | |
2512 * If FALSE, still sets cb->IsValid if buffer characteristics were saved. | |
2513 */ | |
2514 static BOOL | |
2515 SaveConsoleBuffer( | |
2516 ConsoleBuffer *cb) | |
2517 { | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2518 DWORD NumCells; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2519 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2520 SMALL_RECT ReadRegion; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2521 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
|
2522 int i, numregions; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2523 |
7 | 2524 if (cb == NULL) |
2525 return FALSE; | |
2526 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2527 if (!GetConsoleScreenBufferInfo(g_hConOut, &cb->Info)) |
7 | 2528 { |
2529 cb->IsValid = FALSE; | |
2530 return FALSE; | |
2531 } | |
2532 cb->IsValid = TRUE; | |
2533 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2534 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2535 * 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
|
2536 * 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
|
2537 * 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
|
2538 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2539 if (!cb->IsValid || cb->Buffer == NULL || |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2540 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
|
2541 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
|
2542 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2543 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
|
2544 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
|
2545 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
|
2546 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
|
2547 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
|
2548 if (cb->Buffer == NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2549 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2550 } |
7 | 2551 |
2552 /* | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2553 * 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
|
2554 * 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
|
2555 * 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
|
2556 * 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
|
2557 * 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
|
2558 * 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
|
2559 * height of each chunk will be (12000 / width). |
7 | 2560 */ |
7078
383d6f39669b
commit https://github.com/vim/vim/commit/615942452eb74eee7d8386fd3d76a1534181fa06
Christian Brabandt <cb@256bit.org>
parents:
6981
diff
changeset
|
2561 BufferCoord.X = 0; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2562 ReadRegion.Left = 0; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2563 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
|
2564 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
|
2565 |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2566 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
|
2567 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
|
2568 { |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2569 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
|
2570 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
|
2571 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
|
2572 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
|
2573 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2574 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
|
2575 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
|
2576 } |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2577 } |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2578 |
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2579 for (i = 0, Y = 0; i < cb->NumRegions; i++, Y += Y_incr) |
7 | 2580 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2581 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2582 * 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
|
2583 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2584 BufferCoord.Y = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2585 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2586 * 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
|
2587 * 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
|
2588 * 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
|
2589 * 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
|
2590 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2591 ReadRegion.Top = Y; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2592 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
|
2593 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
|
2594 cb->Buffer, // our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2595 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
|
2596 BufferCoord, // offset in our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2597 &ReadRegion)) // region to save |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2598 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2599 VIM_CLEAR(cb->Buffer); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2600 VIM_CLEAR(cb->Regions); |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2601 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2602 } |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2603 cb->Regions[i] = ReadRegion; |
7 | 2604 } |
2605 | |
2606 return TRUE; | |
2607 } | |
2608 | |
2609 /* | |
2610 * RestoreConsoleBuffer() | |
2611 * Description: | |
2612 * Restores important information about the console buffer, including the | |
2613 * actual buffer contents, if desired. The information to restore is in | |
2614 * the same format used by SaveConsoleBuffer(). | |
2615 * Returns: | |
2616 * TRUE on success | |
2617 */ | |
2618 static BOOL | |
2619 RestoreConsoleBuffer( | |
26 | 2620 ConsoleBuffer *cb, |
2621 BOOL RestoreScreen) | |
7 | 2622 { |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2623 COORD BufferCoord; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2624 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
|
2625 int i; |
7 | 2626 |
2627 if (cb == NULL || !cb->IsValid) | |
2628 return FALSE; | |
2629 | |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2630 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2631 * 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
|
2632 * 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
|
2633 * 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
|
2634 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2635 if (RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2636 ClearConsoleBuffer(cb->Info.wAttributes); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2637 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2638 FitConsoleWindow(cb->Info.dwSize, TRUE); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2639 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
|
2640 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2641 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
|
2642 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2643 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2644 if (!RestoreScreen) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2645 { |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2646 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2647 * 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
|
2648 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2649 return TRUE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2650 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2651 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2652 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
|
2653 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2654 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
|
2655 return FALSE; |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2656 |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2657 /* |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2658 * Restore the screen buffer contents. |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2659 */ |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2660 if (cb->Buffer != NULL) |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2661 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2662 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
|
2663 { |
12050
779c9247cc0e
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Christian Brabandt <cb@256bit.org>
parents:
12043
diff
changeset
|
2664 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
|
2665 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
|
2666 WriteRegion = cb->Regions[i]; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2667 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
|
2668 cb->Buffer, // our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2669 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
|
2670 BufferCoord, // offset in our buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2671 &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
|
2672 return FALSE; |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2673 } |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2674 } |
7 | 2675 |
2676 return TRUE; | |
2677 } | |
2678 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2679 # define FEAT_RESTORE_ORIG_SCREEN |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2680 # ifdef FEAT_RESTORE_ORIG_SCREEN |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2681 static ConsoleBuffer g_cbOrig = { 0 }; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2682 # endif |
7 | 2683 static ConsoleBuffer g_cbNonTermcap = { 0 }; |
2684 static ConsoleBuffer g_cbTermcap = { 0 }; | |
2685 | |
2686 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
|
2687 HWND g_hWnd = NULL; // also used in os_mswin.c |
7 | 2688 static HICON g_hOrigIconSmall = NULL; |
2689 static HICON g_hOrigIcon = NULL; | |
2690 static HICON g_hVimIcon = NULL; | |
2691 static BOOL g_fCanChangeIcon = FALSE; | |
2692 | |
2693 /* | |
2694 * GetConsoleIcon() | |
2695 * Description: | |
2696 * Attempts to retrieve the small icon and/or the big icon currently in | |
2697 * use by a given window. | |
2698 * Returns: | |
2699 * TRUE on success | |
2700 */ | |
2701 static BOOL | |
2702 GetConsoleIcon( | |
26 | 2703 HWND hWnd, |
2704 HICON *phIconSmall, | |
2705 HICON *phIcon) | |
7 | 2706 { |
2707 if (hWnd == NULL) | |
2708 return FALSE; | |
2709 | |
2710 if (phIconSmall != NULL) | |
26 | 2711 *phIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, |
2712 (WPARAM)ICON_SMALL, (LPARAM)0); | |
7 | 2713 if (phIcon != NULL) |
26 | 2714 *phIcon = (HICON)SendMessage(hWnd, WM_GETICON, |
2715 (WPARAM)ICON_BIG, (LPARAM)0); | |
7 | 2716 return TRUE; |
2717 } | |
2718 | |
2719 /* | |
2720 * SetConsoleIcon() | |
2721 * Description: | |
2722 * Attempts to change the small icon and/or the big icon currently in | |
2723 * use by a given window. | |
2724 * Returns: | |
2725 * TRUE on success | |
2726 */ | |
2727 static BOOL | |
2728 SetConsoleIcon( | |
26 | 2729 HWND hWnd, |
2730 HICON hIconSmall, | |
2731 HICON hIcon) | |
7 | 2732 { |
2733 if (hWnd == NULL) | |
2734 return FALSE; | |
2735 | |
2736 if (hIconSmall != NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2737 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2738 (WPARAM)ICON_SMALL, (LPARAM)hIconSmall); |
7 | 2739 if (hIcon != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2740 SendMessage(hWnd, WM_SETICON, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
2741 (WPARAM)ICON_BIG, (LPARAM) hIcon); |
7 | 2742 return TRUE; |
2743 } | |
2744 | |
2745 /* | |
2746 * SaveConsoleTitleAndIcon() | |
2747 * Description: | |
2748 * Saves the current console window title in g_szOrigTitle, for later | |
2749 * restoration. Also, attempts to obtain a handle to the console window, | |
2750 * and use it to save the small and big icons currently in use by the | |
2751 * console window. This is not always possible on some versions of Windows; | |
2752 * nor is it possible when running Vim remotely using Telnet (since the | |
2753 * console window the user sees is owned by a remote process). | |
2754 */ | |
2755 static void | |
2756 SaveConsoleTitleAndIcon(void) | |
2757 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2758 // Save the original title. |
7 | 2759 if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle))) |
2760 return; | |
2761 | |
2762 /* | |
2763 * Obtain a handle to the console window using GetConsoleWindow() from | |
2764 * KERNEL32.DLL; we need to handle in order to change the window icon. | |
2765 * This function only exists on NT-based Windows, starting with Windows | |
2766 * 2000. On older operating systems, we can't change the window icon | |
2767 * anyway. | |
2768 */ | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
2769 g_hWnd = GetConsoleWindow(); |
7 | 2770 if (g_hWnd == NULL) |
2771 return; | |
2772 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2773 // Save the original console window icon. |
7 | 2774 GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon); |
2775 if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL) | |
2776 return; | |
2777 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2778 // Extract the first icon contained in the Vim executable. |
6249 | 2779 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
|
2780 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); |
7 | 2781 if (g_hVimIcon != NULL) |
2782 g_fCanChangeIcon = TRUE; | |
2783 } | |
2784 | |
2785 static int g_fWindInitCalled = FALSE; | |
2786 static int g_fTermcapMode = FALSE; | |
2787 static CONSOLE_CURSOR_INFO g_cci; | |
2788 | |
2789 /* | |
2790 * non-GUI version of mch_init(). | |
2791 */ | |
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
|
2792 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
|
2793 mch_init_c(void) |
7 | 2794 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2795 # ifndef FEAT_RESTORE_ORIG_SCREEN |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2796 CONSOLE_SCREEN_BUFFER_INFO csbi; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2797 # endif |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2798 # ifndef __MINGW32__ |
7 | 2799 extern int _fmode; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2800 # endif |
7 | 2801 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2802 // Silently handle invalid parameters to CRT functions |
2584 | 2803 SET_INVALID_PARAM_HANDLER; |
2804 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2805 // 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
|
2806 // for the timestamp test to work on removed floppies. |
7 | 2807 SetErrorMode(SEM_FAILCRITICALERRORS); |
2808 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2809 _fmode = O_BINARY; // we do our own CR-LF translation |
7 | 2810 out_flush(); |
2811 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2812 // Obtain handles for the standard Console I/O devices |
7 | 2813 if (read_cmd_fd == 0) |
2814 g_hConIn = GetStdHandle(STD_INPUT_HANDLE); | |
2815 else | |
2816 create_conin(); | |
2817 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
|
2818 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2819 # 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
|
2820 // 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
|
2821 SaveConsoleBuffer(&g_cbOrig); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2822 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
|
2823 # else |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2824 // Get current text attributes |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2825 GetConsoleScreenBufferInfo(g_hConOut, &csbi); |
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
2826 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
|
2827 # endif |
7 | 2828 if (cterm_normal_fg_color == 0) |
2829 cterm_normal_fg_color = (g_attrCurrent & 0xf) + 1; | |
2830 if (cterm_normal_bg_color == 0) | |
2831 cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1; | |
2832 | |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
2833 // 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
|
2834 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
|
2835 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
|
2836 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2837 // set termcap codes to current text attributes |
7 | 2838 update_tcap(g_attrCurrent); |
2839 | |
2840 GetConsoleCursorInfo(g_hConOut, &g_cci); | |
2841 GetConsoleMode(g_hConIn, &g_cmodein); | |
2842 GetConsoleMode(g_hConOut, &g_cmodeout); | |
2843 | |
2844 SaveConsoleTitleAndIcon(); | |
2845 /* | |
2846 * Set both the small and big icons of the console window to Vim's icon. | |
2847 * Note that Vim presently only has one size of icon (32x32), but it | |
2848 * automatically gets scaled down to 16x16 when setting the small icon. | |
2849 */ | |
2850 if (g_fCanChangeIcon) | |
2851 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); | |
2852 | |
2853 ui_get_shellsize(); | |
2854 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2855 # ifdef MCH_WRITE_DUMP |
7 | 2856 fdDump = fopen("dump", "wt"); |
2857 | |
2858 if (fdDump) | |
2859 { | |
2860 time_t t; | |
2861 | |
2862 time(&t); | |
2863 fputs(ctime(&t), fdDump); | |
2864 fflush(fdDump); | |
2865 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2866 # endif |
7 | 2867 |
2868 g_fWindInitCalled = TRUE; | |
2869 | |
2870 g_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); | |
2871 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2872 # ifdef FEAT_CLIPBOARD |
4168 | 2873 win_clip_init(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2874 # 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
|
2875 |
20051
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2876 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
|
2877 vtp_init(); |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
2878 wt_init(); |
7 | 2879 } |
2880 | |
2881 /* | |
2882 * non-GUI version of mch_exit(). | |
2883 * Shut down and exit with status `r' | |
2884 * Careful: mch_exit() may be called before mch_init()! | |
2885 */ | |
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
|
2886 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
|
2887 mch_exit_c(int r) |
7 | 2888 { |
10835
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
2889 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
|
2890 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
2891 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
|
2892 |
7 | 2893 stoptermcap(); |
2894 if (g_fWindInitCalled) | |
2895 settmode(TMODE_COOK); | |
2896 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2897 ml_close_all(TRUE); // remove all memfiles |
7 | 2898 |
2899 if (g_fWindInitCalled) | |
2900 { | |
14479
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14473
diff
changeset
|
2901 mch_restore_title(SAVE_RESTORE_BOTH); |
7 | 2902 /* |
2903 * Restore both the small and big icons of the console window to | |
2904 * what they were at startup. Don't do this when the window is | |
2905 * closed, Vim would hang here. | |
2906 */ | |
2907 if (g_fCanChangeIcon && !g_fForceExit) | |
2908 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
|
2909 |
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2910 # ifdef MCH_WRITE_DUMP |
7 | 2911 if (fdDump) |
2912 { | |
2913 time_t t; | |
2914 | |
2915 time(&t); | |
2916 fputs(ctime(&t), fdDump); | |
2917 fclose(fdDump); | |
2918 } | |
2919 fdDump = NULL; | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2920 # endif |
7 | 2921 } |
2922 | |
2923 SetConsoleCursorInfo(g_hConOut, &g_cci); | |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
2924 SetConsoleMode(g_hConIn, g_cmodein | ENABLE_EXTENDED_FLAGS); |
7 | 2925 SetConsoleMode(g_hConOut, g_cmodeout); |
2926 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2927 # ifdef DYNAMIC_GETTEXT |
7 | 2928 dyn_libintl_end(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
2929 # endif |
7 | 2930 |
2931 exit(r); | |
2932 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
2933 #endif // !FEAT_GUI_MSWIN |
7 | 2934 |
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
|
2935 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
|
2936 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
|
2937 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2938 #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
|
2939 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
|
2940 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
|
2941 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
|
2942 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
|
2943 #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
|
2944 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
|
2945 #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
|
2946 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
|
2947 #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
|
2948 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2949 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2950 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
|
2951 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
|
2952 { |
20087
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20073
diff
changeset
|
2953 #ifdef FEAT_NETBEANS_INTG |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20073
diff
changeset
|
2954 netbeans_send_disconnect(); |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20073
diff
changeset
|
2955 #endif |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
20073
diff
changeset
|
2956 |
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
|
2957 #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
|
2958 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
|
2959 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
|
2960 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
|
2961 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
|
2962 #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
|
2963 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
|
2964 #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
|
2965 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
|
2966 #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
|
2967 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
2968 |
7 | 2969 /* |
2970 * Do we have an interactive window? | |
2971 */ | |
2972 int | |
2973 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
|
2974 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
|
2975 char **argv UNUSED) |
7 | 2976 { |
2977 get_exe_name(); | |
2978 | |
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
|
2979 #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
|
2980 return OK; // GUI always has a tty |
7 | 2981 #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
|
2982 # 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
|
2983 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
|
2984 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
|
2985 # endif |
7 | 2986 if (isatty(1)) |
2987 return OK; | |
2988 return FAIL; | |
2989 #endif | |
2990 } | |
2991 | |
5326 | 2992 /* |
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
|
2993 * Set the case of the file name, if it already exists. |
7 | 2994 * When "len" is > 0, also expand short to long filenames. |
2995 */ | |
2996 void | |
2997 fname_case( | |
2998 char_u *name, | |
2999 int len) | |
3000 { | |
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
|
3001 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
|
3002 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
|
3003 WCHAR buf[_MAX_PATH + 1]; |
7 | 3004 |
434 | 3005 flen = (int)STRLEN(name); |
5326 | 3006 if (flen == 0) |
7 | 3007 return; |
3008 | |
3009 slash_adjust(name); | |
3010 | |
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
|
3011 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
|
3012 if (p == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3013 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
|
3014 |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
3015 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
|
3016 { |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
3017 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
|
3018 |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
3019 if (q != NULL) |
7 | 3020 { |
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
|
3021 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
|
3022 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
|
3023 vim_free(q); |
7 | 3024 } |
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
|
3025 } |
602f1888a230
patch 8.1.1083: MS-Windows: hang when opening a file on network share
Bram Moolenaar <Bram@vim.org>
parents:
16109
diff
changeset
|
3026 vim_free(p); |
7 | 3027 } |
3028 | |
3029 | |
3030 /* | |
3031 * Insert user name in s[len]. | |
3032 */ | |
3033 int | |
3034 mch_get_user_name( | |
26 | 3035 char_u *s, |
3036 int len) | |
7 | 3037 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3038 WCHAR wszUserName[256 + 1]; // UNLEN is 256 |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24749
diff
changeset
|
3039 DWORD wcch = ARRAY_LENGTH(wszUserName); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3040 |
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 (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
|
3042 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3043 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
|
3044 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3045 if (p != NULL) |
5549 | 3046 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3047 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
|
3048 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
|
3049 return OK; |
5549 | 3050 } |
3051 } | |
7 | 3052 s[0] = NUL; |
3053 return FAIL; | |
3054 } | |
3055 | |
3056 | |
3057 /* | |
3058 * Insert host name in s[len]. | |
3059 */ | |
3060 void | |
3061 mch_get_host_name( | |
3062 char_u *s, | |
3063 int len) | |
3064 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3065 WCHAR wszHostName[256 + 1]; |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24749
diff
changeset
|
3066 DWORD wcch = ARRAY_LENGTH(wszHostName); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3067 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3068 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
|
3069 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3070 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
|
3071 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3072 if (p != NULL) |
5551 | 3073 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3074 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
|
3075 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
|
3076 return; |
5551 | 3077 } |
3078 } | |
7 | 3079 } |
3080 | |
3081 | |
3082 /* | |
3083 * return process ID | |
3084 */ | |
3085 long | |
26 | 3086 mch_get_pid(void) |
7 | 3087 { |
3088 return (long)GetCurrentProcessId(); | |
3089 } | |
3090 | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3091 /* |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3092 * 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
|
3093 */ |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3094 int |
16455
1ae13586edf8
patch 8.1.1232: can't build on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
3095 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
|
3096 { |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3097 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
|
3098 DWORD status = 0; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3099 int ret = FALSE; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3100 |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3101 if (hProcess == NULL) |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3102 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
|
3103 if (GetExitCodeProcess(hProcess, &status) ) |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3104 ret = status == STILL_ACTIVE; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3105 CloseHandle(hProcess); |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3106 return ret; |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
3107 } |
7 | 3108 |
3109 /* | |
3110 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
3111 * Return OK for success, FAIL for failure. | |
3112 */ | |
3113 int | |
3114 mch_dirname( | |
3115 char_u *buf, | |
3116 int len) | |
3117 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3118 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
|
3119 |
7 | 3120 /* |
3121 * Originally this was: | |
3122 * return (getcwd(buf, len) != NULL ? OK : FAIL); | |
3123 * But the Win32s known bug list says that getcwd() doesn't work | |
3124 * so use the Win32 system call instead. <Negri> | |
3125 */ | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3126 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
|
3127 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3128 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
|
3129 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
|
3130 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3131 if (GetLongPathNameW(wbuf, wcbuf, _MAX_PATH) != 0) |
7 | 3132 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3133 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
|
3134 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
|
3135 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3136 // long path name is too long, fall back to short one |
7 | 3137 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
|
3138 p = NULL; |
7 | 3139 } |
3140 } | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3141 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
|
3142 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
|
3143 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3144 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
|
3145 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3146 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
|
3147 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
|
3148 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
|
3149 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3150 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3151 return FAIL; |
7 | 3152 } |
3153 | |
3154 /* | |
5494 | 3155 * Get file permissions for "name". |
3156 * Return mode_t or -1 for error. | |
7 | 3157 */ |
3158 long | |
26 | 3159 mch_getperm(char_u *name) |
7 | 3160 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8949
diff
changeset
|
3161 stat_T st; |
5494 | 3162 int n; |
3163 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
3164 n = mch_stat((char *)name, &st); |
5588 | 3165 return n == 0 ? (long)(unsigned short)st.st_mode : -1L; |
7 | 3166 } |
3167 | |
3168 | |
3169 /* | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3170 * Set file permission for "name" to "perm". |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3171 * |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3172 * Return FAIL for failure, OK otherwise. |
7 | 3173 */ |
3174 int | |
5229
1261caf9bc51
updated for version 7.4a.040
Bram Moolenaar <bram@vim.org>
parents:
5112
diff
changeset
|
3175 mch_setperm(char_u *name, long perm) |
7 | 3176 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3177 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
|
3178 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
|
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 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
|
3181 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
|
3182 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
|
3183 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3184 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
|
3185 vim_free(p); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3186 if (n == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3187 return FAIL; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3188 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3189 win32_set_archive(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3190 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3191 return OK; |
7 | 3192 } |
3193 | |
3194 /* | |
3195 * Set hidden flag for "name". | |
3196 */ | |
3197 void | |
3198 mch_hide(char_u *name) | |
3199 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3200 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3201 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3202 return; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3203 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3204 attrs |= FILE_ATTRIBUTE_HIDDEN; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3205 win32_setattrs(name, attrs); |
7 | 3206 } |
3207 | |
3208 /* | |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3209 * 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
|
3210 */ |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3211 int |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3212 mch_ishidden(char_u *name) |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3213 { |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3214 int f = win32_getattrs(name); |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3215 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3216 if (f == -1) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3217 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
|
3218 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3219 return (f & FILE_ATTRIBUTE_HIDDEN) != 0; |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3220 } |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3221 |
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7184
diff
changeset
|
3222 /* |
7 | 3223 * return TRUE if "name" is a directory |
3224 * return FALSE if "name" is not a directory or upon error | |
3225 */ | |
3226 int | |
3227 mch_isdir(char_u *name) | |
3228 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3229 int f = win32_getattrs(name); |
7 | 3230 |
3231 if (f == -1) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3232 return FALSE; // file does not exist at all |
7 | 3233 |
3234 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; | |
3235 } | |
3236 | |
3237 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3238 * 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
|
3239 * 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
|
3240 * return FALSE for error |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3241 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3242 int |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3243 mch_isrealdir(char_u *name) |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3244 { |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3245 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
|
3246 } |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3247 |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3248 /* |
2803 | 3249 * Create directory "name". |
3250 * Return 0 on success, -1 on error. | |
3251 */ | |
3252 int | |
3253 mch_mkdir(char_u *name) | |
3254 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3255 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
|
3256 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
|
3257 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3258 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
|
3259 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
|
3260 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
|
3261 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
|
3262 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
|
3263 return retval; |
2803 | 3264 } |
3265 | |
3266 /* | |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3267 * Delete directory "name". |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3268 * 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
|
3269 */ |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3270 int |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3271 mch_rmdir(char_u *name) |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3272 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3273 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
|
3274 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
|
3275 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3276 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
|
3277 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
|
3278 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
|
3279 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
|
3280 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
|
3281 return retval; |
7619
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3282 } |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3283 |
6fed43c541c8
commit https://github.com/vim/vim/commit/4cf7679383dca81a4a351e2b0ec333c95d6d9085
Christian Brabandt <cb@256bit.org>
parents:
7613
diff
changeset
|
3284 /* |
696 | 3285 * Return TRUE if file "fname" has more than one link. |
3286 */ | |
3287 int | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3288 mch_is_hard_link(char_u *fname) |
696 | 3289 { |
2793 | 3290 BY_HANDLE_FILE_INFORMATION info; |
3291 | |
3292 return win32_fileinfo(fname, &info) == FILEINFO_OK | |
3293 && info.nNumberOfLinks > 1; | |
3294 } | |
3295 | |
3296 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3297 * 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
|
3298 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3299 int |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3300 mch_is_symbolic_link(char_u *name) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3301 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3302 HANDLE hFind; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3303 int res = FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3304 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
|
3305 WCHAR *wn; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3306 WIN32_FIND_DATAW findDataW; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3307 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3308 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
|
3309 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
|
3310 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
|
3311 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3312 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
|
3313 vim_free(wn); |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3314 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
|
3315 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3316 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
|
3317 reparseTag = findDataW.dwReserved0; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3318 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
|
3319 } |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3320 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3321 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
|
3322 && (reparseTag == IO_REPARSE_TAG_SYMLINK |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
3323 || reparseTag == IO_REPARSE_TAG_MOUNT_POINT)) |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3324 res = TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3325 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3326 return res; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3327 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3328 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3329 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3330 * 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
|
3331 * link. |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3332 */ |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3333 int |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3334 mch_is_linked(char_u *fname) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3335 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3336 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
|
3337 return TRUE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3338 return FALSE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3339 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3340 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3341 /* |
2793 | 3342 * Get the by-handle-file-information for "fname". |
3343 * Returns FILEINFO_OK when OK. | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3344 * Returns FILEINFO_ENC_FAIL when enc_to_utf16() failed. |
2793 | 3345 * Returns FILEINFO_READ_FAIL when CreateFile() failed. |
3346 * Returns FILEINFO_INFO_FAIL when GetFileInformationByHandle() failed. | |
3347 */ | |
3348 int | |
3349 win32_fileinfo(char_u *fname, BY_HANDLE_FILE_INFORMATION *info) | |
3350 { | |
696 | 3351 HANDLE hFile; |
2793 | 3352 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
|
3353 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
|
3354 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3355 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
|
3356 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
|
3357 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
|
3358 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3359 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
|
3360 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
|
3361 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
|
3362 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
|
3363 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
|
3364 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
|
3365 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
|
3366 vim_free(wn); |
696 | 3367 |
3368 if (hFile != INVALID_HANDLE_VALUE) | |
3369 { | |
2793 | 3370 if (GetFileInformationByHandle(hFile, info) != 0) |
3371 res = FILEINFO_OK; | |
3372 else | |
3373 res = FILEINFO_INFO_FAIL; | |
696 | 3374 CloseHandle(hFile); |
3375 } | |
3376 | |
3377 return res; | |
3378 } | |
3379 | |
3380 /* | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3381 * get file attributes for `name' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3382 * -1 : error |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3383 * else FILE_ATTRIBUTE_* defined in winnt.h |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3384 */ |
5494 | 3385 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3386 win32_getattrs(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3387 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3388 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
|
3389 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
|
3390 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3391 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
|
3392 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
|
3393 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
|
3394 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3395 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
|
3396 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3397 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3398 return attr; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3399 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3400 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3401 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3402 * set file attributes for `name' to `attrs' |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3403 * |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3404 * return -1 for failure, 0 otherwise |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3405 */ |
14862
27b9a84395b5
patch 8.1.0443: unnecessary static function prototypes
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
3406 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3407 win32_setattrs(char_u *name, int attrs) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3408 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3409 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
|
3410 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
|
3411 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3412 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
|
3413 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
|
3414 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
|
3415 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3416 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
|
3417 vim_free(p); |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3418 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3419 return res ? 0 : -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3420 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3421 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3422 /* |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3423 * Set archive flag for "name". |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3424 */ |
14862
27b9a84395b5
patch 8.1.0443: unnecessary static function prototypes
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
3425 static int |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3426 win32_set_archive(char_u *name) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3427 { |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3428 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3429 if (attrs == -1) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3430 return -1; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3431 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3432 attrs |= FILE_ATTRIBUTE_ARCHIVE; |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3433 return win32_setattrs(name, attrs); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3434 } |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3435 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3436 /* |
7 | 3437 * Return TRUE if file or directory "name" is writable (not readonly). |
3438 * Strange semantics of Win32: a readonly directory is writable, but you can't | |
3439 * delete a file. Let's say this means it is writable. | |
3440 */ | |
3441 int | |
3442 mch_writable(char_u *name) | |
3443 { | |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3444 int attrs = win32_getattrs(name); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3445 |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3446 return (attrs != -1 && (!(attrs & FILE_ATTRIBUTE_READONLY) |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
3447 || (attrs & FILE_ATTRIBUTE_DIRECTORY))); |
7 | 3448 } |
3449 | |
3450 /* | |
11054
576238eda5a4
patch 8.0.0416: setting v:progpath is not quite right
Christian Brabandt <cb@256bit.org>
parents:
11014
diff
changeset
|
3451 * Return TRUE if "name" can be executed, FALSE if not. |
6700 | 3452 * 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
|
3453 * 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
|
3454 * the allocated memory. |
7 | 3455 */ |
3456 int | |
6700 | 3457 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 3458 { |
20593
89b0f161e6a6
patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe
Bram Moolenaar <Bram@vim.org>
parents:
20589
diff
changeset
|
3459 return executable_exists((char *)name, path, TRUE, TRUE); |
7 | 3460 } |
3461 | |
3462 /* | |
3463 * Check what "name" is: | |
3464 * NODE_NORMAL: file or directory (or doesn't exist) | |
3465 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
3466 * NODE_OTHER: non-writable things | |
3467 */ | |
3468 int | |
3469 mch_nodetype(char_u *name) | |
3470 { | |
3471 HANDLE hFile; | |
3472 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
|
3473 WCHAR *wn; |
7 | 3474 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3475 // 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
|
3476 // 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
|
3477 // here. |
1004 | 3478 if (STRNCMP(name, "\\\\.\\", 4) == 0) |
3479 return NODE_WRITABLE; | |
3480 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3481 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
|
3482 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
|
3483 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
|
3484 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3485 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
|
3486 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
|
3487 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
|
3488 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
|
3489 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
|
3490 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
|
3491 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
|
3492 vim_free(wn); |
7 | 3493 if (hFile == INVALID_HANDLE_VALUE) |
3494 return NODE_NORMAL; | |
3495 | |
3496 type = GetFileType(hFile); | |
3497 CloseHandle(hFile); | |
3498 if (type == FILE_TYPE_CHAR) | |
3499 return NODE_WRITABLE; | |
3500 if (type == FILE_TYPE_DISK) | |
3501 return NODE_NORMAL; | |
3502 return NODE_OTHER; | |
3503 } | |
3504 | |
3505 #ifdef HAVE_ACL | |
3506 struct my_acl | |
3507 { | |
3508 PSECURITY_DESCRIPTOR pSecurityDescriptor; | |
3509 PSID pSidOwner; | |
3510 PSID pSidGroup; | |
3511 PACL pDacl; | |
3512 PACL pSacl; | |
3513 }; | |
3514 #endif | |
3515 | |
3516 /* | |
3517 * Return a pointer to the ACL of file "fname" in allocated memory. | |
3518 * Return NULL if the ACL is not available for whatever reason. | |
3519 */ | |
3520 vim_acl_T | |
26 | 3521 mch_get_acl(char_u *fname) |
7 | 3522 { |
3523 #ifndef HAVE_ACL | |
3524 return (vim_acl_T)NULL; | |
3525 #else | |
3526 struct my_acl *p = NULL; | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3527 DWORD err; |
7 | 3528 |
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
|
3529 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
|
3530 if (p != NULL) |
7 | 3531 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3532 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
|
3533 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3534 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
|
3535 if (wn == NULL) |
22856
3b476f974406
patch 8.2.1975: Win32: memory leak when encoding conversion fails
Bram Moolenaar <Bram@vim.org>
parents:
22065
diff
changeset
|
3536 { |
3b476f974406
patch 8.2.1975: Win32: memory leak when encoding conversion fails
Bram Moolenaar <Bram@vim.org>
parents:
22065
diff
changeset
|
3537 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
|
3538 return NULL; |
22856
3b476f974406
patch 8.2.1975: Win32: memory leak when encoding conversion fails
Bram Moolenaar <Bram@vim.org>
parents:
22065
diff
changeset
|
3539 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3540 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3541 // 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
|
3542 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
|
3543 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
|
3544 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
|
3545 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
|
3546 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
|
3547 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
|
3548 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
|
3549 &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
|
3550 &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
|
3551 &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
|
3552 &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
|
3553 &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
|
3554 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
|
3555 err == ERROR_PRIVILEGE_NOT_HELD) |
7 | 3556 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3557 // 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
|
3558 (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
|
3559 wn, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3560 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
|
3561 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
|
3562 NULL, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3563 NULL, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3564 &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
|
3565 NULL, |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3566 &p->pSecurityDescriptor); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3567 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3568 if (p->pSecurityDescriptor == NULL) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
3569 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3570 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
|
3571 p = NULL; |
7 | 3572 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3573 vim_free(wn); |
7 | 3574 } |
3575 | |
3576 return (vim_acl_T)p; | |
3577 #endif | |
3578 } | |
3579 | |
5047
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3580 #ifdef HAVE_ACL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3581 /* |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3582 * Check if "acl" contains inherited ACE. |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3583 */ |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3584 static BOOL |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3585 is_acl_inherited(PACL acl) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3586 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3587 DWORD i; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3588 ACL_SIZE_INFORMATION acl_info; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3589 PACCESS_ALLOWED_ACE ace; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3590 |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3591 acl_info.AceCount = 0; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3592 GetAclInformation(acl, &acl_info, sizeof(acl_info), AclSizeInformation); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3593 for (i = 0; i < acl_info.AceCount; i++) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3594 { |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3595 GetAce(acl, i, (LPVOID *)&ace); |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3596 if (ace->Header.AceFlags & INHERITED_ACE) |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3597 return TRUE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3598 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3599 return FALSE; |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3600 } |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3601 #endif |
cabdcfe72dc3
updated for version 7.3.1267
Bram Moolenaar <bram@vim.org>
parents:
4930
diff
changeset
|
3602 |
7 | 3603 /* |
3604 * Set the ACL of file "fname" to "acl" (unless it's NULL). | |
3605 * Errors are ignored. | |
3606 * This must only be called with "acl" equal to what mch_get_acl() returned. | |
3607 */ | |
3608 void | |
26 | 3609 mch_set_acl(char_u *fname, vim_acl_T acl) |
7 | 3610 { |
3611 #ifdef HAVE_ACL | |
3612 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
|
3613 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
|
3614 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
|
3615 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3616 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
|
3617 return; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3618 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3619 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
|
3620 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
|
3621 return; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3622 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3623 // 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
|
3624 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
|
3625 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
|
3626 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
|
3627 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
|
3628 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
|
3629 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3630 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
|
3631 // 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
|
3632 // 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
|
3633 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
|
3634 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
|
3635 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3636 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
|
3637 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
|
3638 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3639 (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
|
3640 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
|
3641 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
|
3642 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
|
3643 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
|
3644 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
|
3645 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
|
3646 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
|
3647 ); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
3648 vim_free(wn); |
7 | 3649 #endif |
3650 } | |
3651 | |
3652 void | |
26 | 3653 mch_free_acl(vim_acl_T acl) |
7 | 3654 { |
3655 #ifdef HAVE_ACL | |
3656 struct my_acl *p = (struct my_acl *)acl; | |
3657 | |
3658 if (p != NULL) | |
3659 { | |
3660 LocalFree(p->pSecurityDescriptor); // Free the memory just in case | |
3661 vim_free(p); | |
3662 } | |
3663 #endif | |
3664 } | |
3665 | |
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
|
3666 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 3667 |
3668 /* | |
3669 * handler for ctrl-break, ctrl-c interrupts, and fatal events. | |
3670 */ | |
3671 static BOOL WINAPI | |
3672 handler_routine( | |
3673 DWORD dwCtrlType) | |
3674 { | |
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
|
3675 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
|
3676 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
|
3677 |
7 | 3678 switch (dwCtrlType) |
3679 { | |
3680 case CTRL_C_EVENT: | |
3681 if (ctrl_c_interrupts) | |
3682 g_fCtrlCPressed = TRUE; | |
3683 return TRUE; | |
3684 | |
3685 case CTRL_BREAK_EVENT: | |
3686 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
|
3687 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
|
3688 // 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
|
3689 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
|
3690 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
|
3691 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
|
3692 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
|
3693 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
|
3694 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
|
3695 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
|
3696 WriteConsoleInput(g_hConIn, &ir, 1, &out); |
7 | 3697 return TRUE; |
3698 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3699 // fatal events: shut down gracefully |
7 | 3700 case CTRL_CLOSE_EVENT: |
3701 case CTRL_LOGOFF_EVENT: | |
3702 case CTRL_SHUTDOWN_EVENT: | |
3703 windgoto((int)Rows - 1, 0); | |
3704 g_fForceExit = TRUE; | |
3705 | |
1569 | 3706 vim_snprintf((char *)IObuff, IOSIZE, _("Vim: Caught %s event\n"), |
7 | 3707 (dwCtrlType == CTRL_CLOSE_EVENT |
3708 ? _("close") | |
3709 : dwCtrlType == CTRL_LOGOFF_EVENT | |
3710 ? _("logoff") | |
3711 : _("shutdown"))); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3712 # ifdef DEBUG |
7 | 3713 OutputDebugString(IObuff); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3714 # endif |
7 | 3715 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3716 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
|
3717 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3718 return TRUE; // not reached |
7 | 3719 |
3720 default: | |
3721 return FALSE; | |
3722 } | |
3723 } | |
3724 | |
3725 | |
3726 /* | |
3727 * set the tty in (raw) ? "raw" : "cooked" mode | |
3728 */ | |
3729 void | |
20439
d4b2a8675b78
patch 8.2.0774: t_TI and t_TE are output when using 'visualbell'
Bram Moolenaar <Bram@vim.org>
parents:
20437
diff
changeset
|
3730 mch_settmode(tmode_T tmode) |
7 | 3731 { |
3732 DWORD cmodein; | |
3733 DWORD cmodeout; | |
3734 BOOL bEnableHandler; | |
3735 | |
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
|
3736 # 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
|
3737 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
|
3738 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
|
3739 # endif |
7 | 3740 GetConsoleMode(g_hConIn, &cmodein); |
3741 GetConsoleMode(g_hConOut, &cmodeout); | |
3742 if (tmode == TMODE_RAW) | |
3743 { | |
3744 cmodein &= ~(ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3745 ENABLE_ECHO_INPUT); | |
3746 if (g_fMouseActive) | |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3747 { |
7 | 3748 cmodein |= ENABLE_MOUSE_INPUT; |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3749 cmodein &= ~ENABLE_QUICK_EDIT_MODE; |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3750 } |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3751 else |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3752 { |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3753 cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE; |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3754 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
3755 cmodeout &= ~( |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3756 # ifdef FEAT_TERMGUICOLORS |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3757 // 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
|
3758 // 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
|
3759 ((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
|
3760 # 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
|
3761 ENABLE_PROCESSED_OUTPUT | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3762 # 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
|
3763 ENABLE_WRAP_AT_EOL_OUTPUT); |
7 | 3764 bEnableHandler = TRUE; |
3765 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3766 else // cooked |
7 | 3767 { |
3768 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | | |
3769 ENABLE_ECHO_INPUT); | |
3770 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); | |
3771 bEnableHandler = FALSE; | |
3772 } | |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
3773 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS); |
7 | 3774 SetConsoleMode(g_hConOut, cmodeout); |
3775 SetConsoleCtrlHandler(handler_routine, bEnableHandler); | |
3776 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3777 # ifdef MCH_WRITE_DUMP |
7 | 3778 if (fdDump) |
3779 { | |
3780 fprintf(fdDump, "mch_settmode(%s, in = %x, out = %x)\n", | |
3781 tmode == TMODE_RAW ? "raw" : | |
3782 tmode == TMODE_COOK ? "cooked" : "normal", | |
3783 cmodein, cmodeout); | |
3784 fflush(fdDump); | |
3785 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3786 # endif |
7 | 3787 } |
3788 | |
3789 | |
3790 /* | |
3791 * Get the size of the current window in `Rows' and `Columns' | |
3792 * Return OK when size could be determined, FAIL otherwise. | |
3793 */ | |
3794 int | |
26 | 3795 mch_get_shellsize(void) |
7 | 3796 { |
3797 CONSOLE_SCREEN_BUFFER_INFO csbi; | |
3798 | |
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
|
3799 # 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
|
3800 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
|
3801 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
|
3802 # endif |
7 | 3803 if (!g_fTermcapMode && g_cbTermcap.IsValid) |
3804 { | |
3805 /* | |
3806 * For some reason, we are trying to get the screen dimensions | |
3807 * even though we are not in termcap mode. The 'Rows' and 'Columns' | |
3808 * variables are really intended to mean the size of Vim screen | |
3809 * while in termcap mode. | |
3810 */ | |
3811 Rows = g_cbTermcap.Info.dwSize.Y; | |
3812 Columns = g_cbTermcap.Info.dwSize.X; | |
3813 } | |
3814 else if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3815 { | |
3816 Rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3817 Columns = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3818 } | |
3819 else | |
3820 { | |
3821 Rows = 25; | |
3822 Columns = 80; | |
3823 } | |
3824 return OK; | |
3825 } | |
3826 | |
3827 /* | |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3828 * 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
|
3829 */ |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3830 static void |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3831 ResizeConBuf( |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3832 HANDLE hConsole, |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3833 COORD coordScreen) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3834 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3835 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
|
3836 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3837 # 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
|
3838 if (fdDump) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3839 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3840 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
|
3841 GetLastError()); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3842 fflush(fdDump); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3843 } |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3844 # endif |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3845 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3846 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3847 |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3848 /* |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3849 * 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
|
3850 */ |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3851 static void |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3852 ResizeWindow( |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3853 HANDLE hConsole, |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3854 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
|
3855 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3856 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
|
3857 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3858 # 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
|
3859 if (fdDump) |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3860 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3861 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
|
3862 GetLastError()); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3863 fflush(fdDump); |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3864 } |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3865 # endif |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3866 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3867 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3868 |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3869 /* |
7 | 3870 * Set a console window to `xSize' * `ySize' |
3871 */ | |
3872 static void | |
3873 ResizeConBufAndWindow( | |
26 | 3874 HANDLE hConsole, |
3875 int xSize, | |
3876 int ySize) | |
7 | 3877 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3878 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
|
3879 SMALL_RECT srWindowRect; // hold the new console size |
7 | 3880 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
|
3881 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
|
3882 static int resized = FALSE; |
7 | 3883 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3884 # ifdef MCH_WRITE_DUMP |
7 | 3885 if (fdDump) |
3886 { | |
3887 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize); | |
3888 fflush(fdDump); | |
3889 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
3890 # endif |
7 | 3891 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3892 // get the largest size we can size the console window to |
7 | 3893 coordScreen = GetLargestConsoleWindowSize(hConsole); |
3894 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3895 // define the new console window size and scroll position |
7 | 3896 srWindowRect.Left = srWindowRect.Top = (SHORT) 0; |
3897 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); | |
3898 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); | |
3899 | |
3900 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) | |
3901 { | |
3902 int sx, sy; | |
3903 | |
3904 sx = csbi.srWindow.Right - csbi.srWindow.Left + 1; | |
3905 sy = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | |
3906 if (sy < ySize || sx < xSize) | |
3907 { | |
3908 /* | |
3909 * Increasing number of lines/columns, do buffer first. | |
3910 * Use the maximal size in x and y direction. | |
3911 */ | |
3912 if (sy < ySize) | |
3913 coordScreen.Y = ySize; | |
3914 else | |
3915 coordScreen.Y = sy; | |
3916 if (sx < xSize) | |
3917 coordScreen.X = xSize; | |
3918 else | |
3919 coordScreen.X = sx; | |
3920 SetConsoleScreenBufferSize(hConsole, coordScreen); | |
3921 } | |
3922 } | |
3923 | |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3924 // define the new console buffer size |
7 | 3925 coordScreen.X = xSize; |
3926 coordScreen.Y = ySize; | |
3927 | |
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
|
3928 // 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
|
3929 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
|
3930 { |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3931 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
|
3932 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
|
3933 } |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3934 else |
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3935 { |
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
|
3936 // 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
|
3937 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
|
3938 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
|
3939 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
|
3940 |
14473
2771a99db70c
patch 8.1.0250: MS-Windows using VTP: windows size change incorrect
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
3941 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
|
3942 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
|
3943 resized = TRUE; |
7 | 3944 } |
3945 } | |
3946 | |
3947 | |
3948 /* | |
3949 * Set the console window to `Rows' * `Columns' | |
3950 */ | |
3951 void | |
26 | 3952 mch_set_shellsize(void) |
7 | 3953 { |
3954 COORD coordScreen; | |
3955 | |
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
|
3956 # 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
|
3957 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
|
3958 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
|
3959 # endif |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3960 // Don't change window size while still starting up |
7 | 3961 if (suppress_winsize != 0) |
3962 { | |
3963 suppress_winsize = 2; | |
3964 return; | |
3965 } | |
3966 | |
3967 if (term_console) | |
3968 { | |
3969 coordScreen = GetLargestConsoleWindowSize(g_hConOut); | |
3970 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
3971 // Clamp Rows and Columns to reasonable values |
7 | 3972 if (Rows > coordScreen.Y) |
3973 Rows = coordScreen.Y; | |
3974 if (Columns > coordScreen.X) | |
3975 Columns = coordScreen.X; | |
3976 | |
3977 ResizeConBufAndWindow(g_hConOut, Columns, Rows); | |
3978 } | |
3979 } | |
3980 | |
3981 /* | |
3982 * Rows and/or Columns has changed. | |
3983 */ | |
3984 void | |
26 | 3985 mch_new_shellsize(void) |
7 | 3986 { |
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
|
3987 # 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
|
3988 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
|
3989 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
|
3990 # endif |
7 | 3991 set_scroll_region(0, 0, Columns - 1, Rows - 1); |
3992 } | |
3993 | |
3994 | |
3995 /* | |
3996 * Called when started up, to set the winsize that was delayed. | |
3997 */ | |
3998 void | |
26 | 3999 mch_set_winsize_now(void) |
7 | 4000 { |
4001 if (suppress_winsize == 2) | |
4002 { | |
4003 suppress_winsize = 0; | |
4004 mch_set_shellsize(); | |
4005 shell_resized(); | |
4006 } | |
4007 suppress_winsize = 0; | |
4008 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4009 #endif // FEAT_GUI_MSWIN |
7 | 4010 |
5547 | 4011 static BOOL |
4012 vim_create_process( | |
5556 | 4013 char *cmd, |
5569 | 4014 BOOL inherit_handles, |
5547 | 4015 DWORD flags, |
4016 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
|
4017 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
|
4018 LPVOID *env, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4019 char *cwd) |
5547 | 4020 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4021 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
|
4022 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
|
4023 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4024 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
|
4025 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
|
4026 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
|
4027 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
|
4028 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4029 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
|
4030 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
|
4031 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
|
4032 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4033 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4034 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
|
4035 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
|
4036 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
|
4037 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
|
4038 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
|
4039 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
|
4040 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
|
4041 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
|
4042 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
|
4043 (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
|
4044 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
|
4045 theend: |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4046 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
|
4047 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
|
4048 return ret; |
5547 | 4049 } |
7 | 4050 |
4051 | |
11230
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4052 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
|
4053 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
|
4054 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
|
4055 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
|
4056 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4057 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
|
4058 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
|
4059 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4060 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
|
4061 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
|
4062 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
|
4063 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4064 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
|
4065 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
|
4066 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
|
4067 } |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4068 |
a3ea65af63cf
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4069 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4070 #if defined(FEAT_GUI_MSWIN) || defined(PROTO) |
7 | 4071 |
4072 /* | |
4073 * Specialised version of system() for Win32 GUI mode. | |
4074 * This version proceeds as follows: | |
4075 * 1. Create a console window for use by the subprocess | |
4076 * 2. Run the subprocess (it gets the allocated console by default) | |
4077 * 3. Wait for the subprocess to terminate and get its exit code | |
4078 * 4. Prompt the user to press a key to close the console window | |
4079 */ | |
4080 static int | |
2935 | 4081 mch_system_classic(char *cmd, int options) |
7 | 4082 { |
4083 STARTUPINFO si; | |
4084 PROCESS_INFORMATION pi; | |
4085 DWORD ret = 0; | |
4086 HWND hwnd = GetFocus(); | |
4087 | |
4088 si.cb = sizeof(si); | |
4089 si.lpReserved = NULL; | |
4090 si.lpDesktop = NULL; | |
4091 si.lpTitle = NULL; | |
4092 si.dwFlags = STARTF_USESHOWWINDOW; | |
4093 /* | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4094 * It's nicer to run a filter command in a minimized window. |
2643 | 4095 * Don't activate the window to keep focus on Vim. |
7 | 4096 */ |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
4097 if (options & SHELL_DOOUT) |
2643 | 4098 si.wShowWindow = SW_SHOWMINNOACTIVE; |
7 | 4099 else |
4100 si.wShowWindow = SW_SHOWNORMAL; | |
4101 si.cbReserved2 = 0; | |
4102 si.lpReserved2 = NULL; | |
4103 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4104 // Now, run the command |
5547 | 4105 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
|
4106 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
|
4107 &si, &pi, NULL, NULL); |
7 | 4108 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4109 // Wait for the command to terminate before continuing |
7 | 4110 { |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
4111 # ifdef FEAT_GUI |
7 | 4112 int delay = 1; |
4113 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4114 // Keep updating the window while waiting for the shell to finish. |
7 | 4115 for (;;) |
4116 { | |
4117 MSG msg; | |
4118 | |
27283
b4d92a69035b
patch 8.2.4170: MS-Windows: still using old message API calls
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
4119 if (PeekMessageW(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
7 | 4120 { |
4121 TranslateMessage(&msg); | |
27283
b4d92a69035b
patch 8.2.4170: MS-Windows: still using old message API calls
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
4122 DispatchMessageW(&msg); |
3720 | 4123 delay = 1; |
4124 continue; | |
7 | 4125 } |
4126 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4127 break; | |
4128 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4129 // 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
|
4130 // 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
|
4131 // consume too much overhead when it's slow. |
7 | 4132 if (delay < 50) |
4133 delay += 10; | |
4134 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
4135 # else |
7 | 4136 WaitForSingleObject(pi.hProcess, INFINITE); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
4137 # endif |
7 | 4138 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4139 // Get the command exit code |
7 | 4140 GetExitCodeProcess(pi.hProcess, &ret); |
4141 } | |
4142 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4143 // Close the handles to the subprocess, so that it goes away |
7 | 4144 CloseHandle(pi.hThread); |
4145 CloseHandle(pi.hProcess); | |
4146 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4147 // Try to get input focus back. Doesn't always work though. |
7 | 4148 PostMessage(hwnd, WM_SETFOCUS, 0, 0); |
4149 | |
4150 return ret; | |
4151 } | |
2935 | 4152 |
4153 /* | |
4154 * Thread launched by the gui to send the current buffer data to the | |
4155 * process. This way avoid to hang up vim totally if the children | |
4156 * process take a long time to process the lines. | |
4157 */ | |
9750
0f4b76b2757a
commit https://github.com/vim/vim/commit/4c38d66d25e4ba433fe87283a4664425a3dbd529
Christian Brabandt <cb@256bit.org>
parents:
9740
diff
changeset
|
4158 static unsigned int __stdcall |
2935 | 4159 sub_process_writer(LPVOID param) |
4160 { | |
4161 HANDLE g_hChildStd_IN_Wr = param; | |
4162 linenr_T lnum = curbuf->b_op_start.lnum; | |
4163 DWORD len = 0; | |
4164 DWORD l; | |
4165 char_u *lp = ml_get(lnum); | |
4166 char_u *s; | |
4167 int written = 0; | |
4168 | |
4169 for (;;) | |
4170 { | |
4171 l = (DWORD)STRLEN(lp + written); | |
4172 if (l == 0) | |
4173 len = 0; | |
4174 else if (lp[written] == NL) | |
4175 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4176 // NL -> NUL translation |
2935 | 4177 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); |
4178 } | |
4179 else | |
4180 { | |
4181 s = vim_strchr(lp + written, NL); | |
4182 WriteFile(g_hChildStd_IN_Wr, (char *)lp + written, | |
4183 s == NULL ? l : (DWORD)(s - (lp + written)), | |
4184 &len, NULL); | |
4185 } | |
4186 if (len == (int)l) | |
4187 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4188 // 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
|
4189 // one. |
2935 | 4190 if (lnum != curbuf->b_op_end.lnum |
6933 | 4191 || (!curbuf->b_p_bin |
4192 && curbuf->b_p_fixeol) | |
2935 | 4193 || (lnum != curbuf->b_no_eol_lnum |
4194 && (lnum != curbuf->b_ml.ml_line_count | |
4195 || curbuf->b_p_eol))) | |
4196 { | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14673
diff
changeset
|
4197 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
|
4198 (LPDWORD)&vim_ignored, NULL); |
2935 | 4199 } |
4200 | |
4201 ++lnum; | |
4202 if (lnum > curbuf->b_op_end.lnum) | |
4203 break; | |
4204 | |
4205 lp = ml_get(lnum); | |
4206 written = 0; | |
4207 } | |
4208 else if (len > 0) | |
4209 written += len; | |
4210 } | |
4211 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4212 // finished all the lines, close pipe |
2935 | 4213 CloseHandle(g_hChildStd_IN_Wr); |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4214 return 0; |
2935 | 4215 } |
4216 | |
4217 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4218 # define BUFLEN 100 // length for buffer, stolen from unix version |
2935 | 4219 |
4220 /* | |
4221 * This function read from the children's stdout and write the | |
4222 * data on screen or in the buffer accordingly. | |
4223 */ | |
4224 static void | |
4225 dump_pipe(int options, | |
4226 HANDLE g_hChildStd_OUT_Rd, | |
4227 garray_T *ga, | |
4228 char_u buffer[], | |
4229 DWORD *buffer_off) | |
4230 { | |
4231 DWORD availableBytes = 0; | |
4232 DWORD i; | |
4233 int ret; | |
4234 DWORD len; | |
4235 DWORD toRead; | |
4236 int repeatCount; | |
4237 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4238 // 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
|
4239 // 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
|
4240 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
|
4241 NULL, // optional buffer |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4242 0, // buffer size |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4243 NULL, // number of read bytes |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4244 &availableBytes, // available bytes total |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4245 NULL); // byteLeft |
2935 | 4246 |
4247 repeatCount = 0; | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4248 // We got real data in the pipe, read it |
3622 | 4249 while (ret != 0 && availableBytes > 0) |
2935 | 4250 { |
4251 repeatCount++; | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
4252 toRead = (DWORD)(BUFLEN - *buffer_off); |
2935 | 4253 toRead = availableBytes < toRead ? availableBytes : toRead; |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
4254 ReadFile(g_hChildStd_OUT_Rd, buffer + *buffer_off, toRead , &len, NULL); |
2935 | 4255 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4256 // If we haven't read anything, there is a problem |
2935 | 4257 if (len == 0) |
4258 break; | |
4259 | |
4260 availableBytes -= len; | |
4261 | |
4262 if (options & SHELL_READ) | |
4263 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4264 // 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
|
4265 // lines to the current buffer. |
2935 | 4266 for (i = 0; i < len; ++i) |
4267 { | |
4268 if (buffer[i] == NL) | |
4269 append_ga_line(ga); | |
4270 else if (buffer[i] == NUL) | |
4271 ga_append(ga, NL); | |
4272 else | |
4273 ga_append(ga, buffer[i]); | |
4274 } | |
4275 } | |
4276 else if (has_mbyte) | |
4277 { | |
4278 int l; | |
3030 | 4279 int c; |
4280 char_u *p; | |
2935 | 4281 |
4282 len += *buffer_off; | |
4283 buffer[len] = NUL; | |
4284 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4285 // 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
|
4286 // 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
|
4287 // round. |
2935 | 4288 for (p = buffer; p < buffer + len; p += l) |
4289 { | |
9898
bff8a09016a5
commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents:
9762
diff
changeset
|
4290 l = MB_CPTR2LEN(p); |
2935 | 4291 if (l == 0) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4292 l = 1; // NUL byte? |
2935 | 4293 else if (MB_BYTE2LEN(*p) != l) |
4294 break; | |
4295 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4296 if (p == buffer) // no complete character |
2935 | 4297 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4298 // avoid getting stuck at an illegal byte |
2935 | 4299 if (len >= 12) |
4300 ++p; | |
4301 else | |
4302 { | |
4303 *buffer_off = len; | |
4304 return; | |
4305 } | |
4306 } | |
4307 c = *p; | |
4308 *p = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4309 msg_puts((char *)buffer); |
2935 | 4310 if (p < buffer + len) |
4311 { | |
4312 *p = c; | |
4313 *buffer_off = (DWORD)((buffer + len) - p); | |
4314 mch_memmove(buffer, p, *buffer_off); | |
4315 return; | |
4316 } | |
4317 *buffer_off = 0; | |
4318 } | |
4319 else | |
4320 { | |
4321 buffer[len] = NUL; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15539
diff
changeset
|
4322 msg_puts((char *)buffer); |
2935 | 4323 } |
4324 | |
4325 windgoto(msg_row, msg_col); | |
4326 cursor_on(); | |
4327 out_flush(); | |
4328 } | |
4329 } | |
4330 | |
4331 /* | |
4332 * Version of system to use for windows NT > 5.0 (Win2K), use pipe | |
4333 * for communication and doesn't open any new window. | |
4334 */ | |
4335 static int | |
4336 mch_system_piped(char *cmd, int options) | |
4337 { | |
4338 STARTUPINFO si; | |
4339 PROCESS_INFORMATION pi; | |
4340 DWORD ret = 0; | |
4341 | |
4342 HANDLE g_hChildStd_IN_Rd = NULL; | |
4343 HANDLE g_hChildStd_IN_Wr = NULL; | |
4344 HANDLE g_hChildStd_OUT_Rd = NULL; | |
4345 HANDLE g_hChildStd_OUT_Wr = NULL; | |
4346 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4347 char_u buffer[BUFLEN + 1]; // reading buffer + size |
2935 | 4348 DWORD len; |
4349 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4350 // buffer used to receive keys |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4351 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
|
4352 int ta_len = 0; // valid bytes in ta_buf[] |
2935 | 4353 |
4354 DWORD i; | |
4355 int noread_cnt = 0; | |
4356 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
|
4357 int delay = 1; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4358 DWORD buffer_off = 0; // valid bytes in buffer[] |
3361 | 4359 char *p = NULL; |
2935 | 4360 |
4361 SECURITY_ATTRIBUTES saAttr; | |
4362 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4363 // Set the bInheritHandle flag so pipe handles are inherited. |
2935 | 4364 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
4365 saAttr.bInheritHandle = TRUE; | |
4366 saAttr.lpSecurityDescriptor = NULL; | |
4367 | |
4368 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
|
4369 // 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
|
4370 || ! 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
|
4371 // Create a pipe for the child process's STDIN. |
2935 | 4372 || ! 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
|
4373 // 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
|
4374 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) |
2935 | 4375 { |
4376 CloseHandle(g_hChildStd_IN_Rd); | |
4377 CloseHandle(g_hChildStd_IN_Wr); | |
4378 CloseHandle(g_hChildStd_OUT_Rd); | |
4379 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
|
4380 msg_puts(_("\nCannot create pipes\n")); |
2935 | 4381 } |
4382 | |
4383 si.cb = sizeof(si); | |
4384 si.lpReserved = NULL; | |
4385 si.lpDesktop = NULL; | |
4386 si.lpTitle = NULL; | |
4387 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; | |
4388 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4389 // set-up our file redirection |
2935 | 4390 si.hStdError = g_hChildStd_OUT_Wr; |
4391 si.hStdOutput = g_hChildStd_OUT_Wr; | |
4392 si.hStdInput = g_hChildStd_IN_Rd; | |
4393 si.wShowWindow = SW_HIDE; | |
4394 si.cbReserved2 = 0; | |
4395 si.lpReserved2 = NULL; | |
4396 | |
4397 if (options & SHELL_READ) | |
4398 ga_init2(&ga, 1, BUFLEN); | |
4399 | |
3361 | 4400 if (cmd != NULL) |
4401 { | |
4402 p = (char *)vim_strsave((char_u *)cmd); | |
4403 if (p != NULL) | |
4404 unescape_shellxquote((char_u *)p, p_sxe); | |
4405 else | |
4406 p = cmd; | |
4407 } | |
4408 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4409 // Now, run the command. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4410 // 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
|
4411 // 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
|
4412 // 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
|
4413 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
|
4414 &si, &pi, NULL, NULL); |
2935 | 4415 |
3361 | 4416 if (p != cmd) |
4417 vim_free(p); | |
2935 | 4418 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4419 // Close our unused side of the pipes |
2935 | 4420 CloseHandle(g_hChildStd_IN_Rd); |
4421 CloseHandle(g_hChildStd_OUT_Wr); | |
4422 | |
4423 if (options & SHELL_WRITE) | |
4424 { | |
9740
4665d491a69e
commit https://github.com/vim/vim/commit/86f2cd5bc574c23fa276d7f57cd1300e24222913
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4425 HANDLE thread = (HANDLE) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4426 _beginthreadex(NULL, // security attributes |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4427 0, // default stack size |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4428 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
|
4429 g_hChildStd_IN_Wr, // parameter |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4430 0, // creation flag, start immediately |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4431 NULL); // we don't care about thread id |
2935 | 4432 CloseHandle(thread); |
4433 g_hChildStd_IN_Wr = NULL; | |
4434 } | |
4435 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4436 // Keep updating the window while waiting for the shell to finish. |
2935 | 4437 for (;;) |
4438 { | |
4439 MSG msg; | |
4440 | |
27283
b4d92a69035b
patch 8.2.4170: MS-Windows: still using old message API calls
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
4441 if (PeekMessageW(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) |
2935 | 4442 { |
4443 TranslateMessage(&msg); | |
27283
b4d92a69035b
patch 8.2.4170: MS-Windows: still using old message API calls
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
4444 DispatchMessageW(&msg); |
2935 | 4445 } |
4446 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4447 // write pipe information in the window |
2935 | 4448 if ((options & (SHELL_READ|SHELL_WRITE)) |
4449 # ifdef FEAT_GUI | |
4450 || gui.in_use | |
4451 # endif | |
4452 ) | |
4453 { | |
4454 len = 0; | |
4455 if (!(options & SHELL_EXPAND) | |
4456 && ((options & | |
4457 (SHELL_READ|SHELL_WRITE|SHELL_COOKED)) | |
4458 != (SHELL_READ|SHELL_WRITE|SHELL_COOKED) | |
4459 # ifdef FEAT_GUI | |
4460 || gui.in_use | |
4461 # endif | |
4462 ) | |
4463 && (ta_len > 0 || noread_cnt > 4)) | |
4464 { | |
4465 if (ta_len == 0) | |
4466 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4467 // 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
|
4468 // counter and timer. |
2935 | 4469 noread_cnt = 0; |
4470 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); | |
4471 } | |
4472 if (ta_len > 0 || len > 0) | |
4473 { | |
4474 /* | |
4475 * For pipes: Check for CTRL-C: send interrupt signal to | |
4476 * child. Check for CTRL-D: EOF, close pipe to child. | |
4477 */ | |
4478 if (len == 1 && cmd != NULL) | |
4479 { | |
4480 if (ta_buf[ta_len] == Ctrl_C) | |
4481 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4482 // 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
|
4483 // now put 9 as SIGKILL |
2935 | 4484 TerminateProcess(pi.hProcess, 9); |
4485 } | |
4486 if (ta_buf[ta_len] == Ctrl_D) | |
4487 { | |
4488 CloseHandle(g_hChildStd_IN_Wr); | |
4489 g_hChildStd_IN_Wr = NULL; | |
4490 } | |
4491 } | |
4492 | |
19405
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
19362
diff
changeset
|
4493 term_replace_bs_del_keycode(ta_buf, ta_len, len); |
2935 | 4494 |
4495 /* | |
4496 * For pipes: echo the typed characters. For a pty this | |
4497 * does not seem to work. | |
4498 */ | |
4499 for (i = ta_len; i < ta_len + len; ++i) | |
4500 { | |
4501 if (ta_buf[i] == '\n' || ta_buf[i] == '\b') | |
4502 msg_putchar(ta_buf[i]); | |
4503 else if (has_mbyte) | |
4504 { | |
4505 int l = (*mb_ptr2len)(ta_buf + i); | |
4506 | |
4507 msg_outtrans_len(ta_buf + i, l); | |
4508 i += l - 1; | |
4509 } | |
4510 else | |
4511 msg_outtrans_len(ta_buf + i, 1); | |
4512 } | |
4513 windgoto(msg_row, msg_col); | |
4514 out_flush(); | |
4515 | |
4516 ta_len += len; | |
4517 | |
4518 /* | |
4519 * Write the characters to the child, unless EOF has been | |
4520 * typed for pipes. Write one character at a time, to | |
4521 * avoid losing too much typeahead. When writing buffer | |
4522 * lines, drop the typed characters (only check for | |
4523 * CTRL-C). | |
4524 */ | |
4525 if (options & SHELL_WRITE) | |
4526 ta_len = 0; | |
4527 else if (g_hChildStd_IN_Wr != NULL) | |
4528 { | |
4529 WriteFile(g_hChildStd_IN_Wr, (char*)ta_buf, | |
4530 1, &len, NULL); | |
4531 // if we are typing in, we want to keep things reactive | |
4532 delay = 1; | |
4533 if (len > 0) | |
4534 { | |
4535 ta_len -= len; | |
4536 mch_memmove(ta_buf, ta_buf + len, ta_len); | |
4537 } | |
4538 } | |
4539 } | |
4540 } | |
4541 } | |
4542 | |
4543 if (ta_len) | |
4544 ui_inchar_undo(ta_buf, ta_len); | |
4545 | |
4546 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) | |
4547 { | |
3030 | 4548 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4549 break; |
4550 } | |
4551 | |
4552 ++noread_cnt; | |
3030 | 4553 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); |
2935 | 4554 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4555 // 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
|
4556 // 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
|
4557 // consume too much overhead when it's slow. |
2935 | 4558 if (delay < 50) |
4559 delay += 10; | |
4560 } | |
4561 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4562 // Close the pipe |
2935 | 4563 CloseHandle(g_hChildStd_OUT_Rd); |
4564 if (g_hChildStd_IN_Wr != NULL) | |
4565 CloseHandle(g_hChildStd_IN_Wr); | |
4566 | |
4567 WaitForSingleObject(pi.hProcess, INFINITE); | |
4568 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4569 // Get the command exit code |
2935 | 4570 GetExitCodeProcess(pi.hProcess, &ret); |
4571 | |
4572 if (options & SHELL_READ) | |
4573 { | |
4574 if (ga.ga_len > 0) | |
4575 { | |
4576 append_ga_line(&ga); | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4577 // remember that the NL was missing |
2935 | 4578 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; |
4579 } | |
4580 else | |
4581 curbuf->b_no_eol_lnum = 0; | |
4582 ga_clear(&ga); | |
4583 } | |
4584 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4585 // Close the handles to the subprocess, so that it goes away |
2935 | 4586 CloseHandle(pi.hThread); |
4587 CloseHandle(pi.hProcess); | |
4588 | |
4589 return ret; | |
4590 } | |
4591 | |
4592 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
|
4593 mch_system_g(char *cmd, int options) |
2935 | 4594 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4595 // 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
|
4596 if (!p_stmp) |
2935 | 4597 return mch_system_piped(cmd, options); |
4598 else | |
4599 return mch_system_classic(cmd, options); | |
4600 } | |
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
|
4601 #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
|
4602 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4603 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
5547 | 4604 static int |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
4605 mch_system_c(char *cmd, int options UNUSED) |
5547 | 4606 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4607 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
|
4608 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
|
4609 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
|
4610 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
|
4611 |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4612 // 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
|
4613 // 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
|
4614 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
|
4615 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
|
4616 { |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4617 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
|
4618 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
|
4619 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
|
4620 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
|
4621 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
|
4622 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
|
4623 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
|
4624 } |
85160a3649b9
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents:
18235
diff
changeset
|
4625 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
|
4626 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
|
4627 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4628 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
|
4629 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
|
4630 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4631 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
|
4632 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
|
4633 return ret; |
5547 | 4634 } |
7 | 4635 |
4636 #endif | |
4637 | |
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
|
4638 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
|
4639 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
|
4640 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4641 #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
|
4642 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
|
4643 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
|
4644 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
|
4645 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
|
4646 #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
|
4647 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
|
4648 #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
|
4649 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
|
4650 #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
|
4651 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
4652 |
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
|
4653 #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
|
4654 /* |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4655 * 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
|
4656 */ |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4657 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
|
4658 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
|
4659 char_u *cmd, |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4660 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
|
4661 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4662 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
|
4663 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
|
4664 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
|
4665 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
|
4666 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
|
4667 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
|
4668 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
|
4669 aco_save_T aco; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4670 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
|
4671 |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4672 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4673 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
|
4674 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4675 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
|
4676 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
|
4677 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
|
4678 return 255; |
13487
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4679 if (cmd == NULL) |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4680 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4681 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
|
4682 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
|
4683 } |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4684 else |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4685 { |
db5cc048222d
patch 8.0.1617: Win32: :shell command in the GUI crashes
Christian Brabandt <cb@256bit.org>
parents:
13485
diff
changeset
|
4686 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
|
4687 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
|
4688 } |
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
|
4689 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4690 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
|
4691 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4692 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
|
4693 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
|
4694 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
|
4695 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
|
4696 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
|
4697 { |
884b683d12e9
patch 8.1.1028: MS-Windows: memory leak when creating terminal fails
Bram Moolenaar <Bram@vim.org>
parents:
16015
diff
changeset
|
4698 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
|
4699 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
|
4700 } |
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
|
4701 |
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
|
4702 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
|
4703 ++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
|
4704 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4705 // 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
|
4706 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
|
4707 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4708 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
|
4709 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
|
4710 { |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4711 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
|
4712 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4713 // 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
|
4714 // 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
|
4715 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
|
4716 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
|
4717 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4718 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
|
4719 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
|
4720 } |
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
|
4721 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
|
4722 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
|
4723 |
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
|
4724 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
|
4725 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4726 // 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
|
4727 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
|
4728 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4729 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
|
4730 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
|
4731 |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4732 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
|
4733 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
|
4734 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4735 #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
|
4736 |
7 | 4737 /* |
4738 * Either execute a command by calling the shell or start a new shell | |
4739 */ | |
4740 int | |
4741 mch_call_shell( | |
26 | 4742 char_u *cmd, |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4743 int options) // SHELL_*, see vim.h |
7 | 4744 { |
4745 int x = 0; | |
4746 int tmode = cur_tmode; | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4747 WCHAR szShellTitle[512]; |
6293 | 4748 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4749 // Change the title to reflect that we are in a subshell. |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24749
diff
changeset
|
4750 if (GetConsoleTitleW(szShellTitle, ARRAY_LENGTH(szShellTitle) - 4) > 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
|
4751 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4752 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
|
4753 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
|
4754 else |
6290 | 4755 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4756 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
|
4757 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4758 if (wn != NULL) |
6290 | 4759 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4760 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
|
4761 if ((wcslen(szShellTitle) + wcslen(wn) < |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24749
diff
changeset
|
4762 ARRAY_LENGTH(szShellTitle))) |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4763 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
|
4764 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
|
4765 vim_free(wn); |
6290 | 4766 } |
4767 } | |
4768 } | |
7 | 4769 |
4770 out_flush(); | |
4771 | |
4772 #ifdef MCH_WRITE_DUMP | |
4773 if (fdDump) | |
4774 { | |
4775 fprintf(fdDump, "mch_call_shell(\"%s\", %d)\n", cmd, options); | |
4776 fflush(fdDump); | |
4777 } | |
4778 #endif | |
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
|
4779 #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
|
4780 // 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
|
4781 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
|
4782 # 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
|
4783 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
|
4784 # endif |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4785 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
|
4786 && (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
|
4787 { |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4788 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
|
4789 |
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
|
4790 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
|
4791 // 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
|
4792 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
|
4793 ++cmdbase; |
16984
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4794 |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4795 // 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
|
4796 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
|
4797 || !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
|
4798 { |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4799 // 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
|
4800 x = mch_call_shell_terminal(cmd, options); |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4801 resettitle(); |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4802 return x; |
d4ecdb8a4c58
patch 8.1.1492: MS-Windows: when "!" is in 'guioptions' ":!start" fails
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4803 } |
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
|
4804 } |
f717be87320c
patch 8.0.1616: Win32: shell commands in the GUI open a new console
Christian Brabandt <cb@256bit.org>
parents:
13433
diff
changeset
|
4805 #endif |
7 | 4806 |
4807 /* | |
4808 * Catch all deadly signals while running the external command, because a | |
4809 * CTRL-C, Ctrl-Break or illegal instruction might otherwise kill us. | |
4810 */ | |
4811 signal(SIGINT, SIG_IGN); | |
4812 #if defined(__GNUC__) && !defined(__MINGW32__) | |
4813 signal(SIGKILL, SIG_IGN); | |
4814 #else | |
4815 signal(SIGBREAK, SIG_IGN); | |
4816 #endif | |
4817 signal(SIGILL, SIG_IGN); | |
4818 signal(SIGFPE, SIG_IGN); | |
4819 signal(SIGSEGV, SIG_IGN); | |
4820 signal(SIGTERM, SIG_IGN); | |
4821 signal(SIGABRT, SIG_IGN); | |
4822 | |
4823 if (options & SHELL_COOKED) | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4824 settmode(TMODE_COOK); // set to normal mode |
7 | 4825 |
4826 if (cmd == NULL) | |
4827 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4828 x = mch_system((char *)p_sh, options); |
7 | 4829 } |
4830 else | |
4831 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4832 // we use "command" or "cmd" to start the shell; slow but easy |
3363 | 4833 char_u *newcmd = NULL; |
4834 char_u *cmdbase = cmd; | |
4835 long_u cmdlen; | |
3361 | 4836 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4837 // Skip a leading ", ( and "(. |
3361 | 4838 if (*cmdbase == '"' ) |
4839 ++cmdbase; | |
4840 if (*cmdbase == '(') | |
4841 ++cmdbase; | |
4842 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4843 if ((STRNICMP(cmdbase, "start", 5) == 0) && VIM_ISWHITE(cmdbase[5])) |
3361 | 4844 { |
4845 STARTUPINFO si; | |
4846 PROCESS_INFORMATION pi; | |
4847 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
|
4848 INT n_show_cmd = SW_SHOWNORMAL; |
3361 | 4849 char_u *p; |
4850 | |
5627 | 4851 ZeroMemory(&si, sizeof(si)); |
3361 | 4852 si.cb = sizeof(si); |
4853 si.lpReserved = NULL; | |
4854 si.lpDesktop = NULL; | |
4855 si.lpTitle = NULL; | |
4856 si.dwFlags = 0; | |
4857 si.cbReserved2 = 0; | |
4858 si.lpReserved2 = NULL; | |
4859 | |
4860 cmdbase = skipwhite(cmdbase + 5); | |
4861 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
|
4862 && VIM_ISWHITE(cmdbase[4])) |
3361 | 4863 { |
4864 cmdbase = skipwhite(cmdbase + 4); | |
4865 si.dwFlags = STARTF_USESHOWWINDOW; | |
4866 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
|
4867 n_show_cmd = SW_SHOWMINNOACTIVE; |
3361 | 4868 } |
4869 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
|
4870 && VIM_ISWHITE(cmdbase[2])) |
3361 | 4871 { |
4872 cmdbase = skipwhite(cmdbase + 2); | |
4873 flags = CREATE_NO_WINDOW; | |
4874 si.dwFlags = STARTF_USESTDHANDLES; | |
4875 si.hStdInput = CreateFile("\\\\.\\NUL", // File name | |
3363 | 4876 GENERIC_READ, // Access flags |
3361 | 4877 0, // Share flags |
3363 | 4878 NULL, // Security att. |
4879 OPEN_EXISTING, // Open flags | |
4880 FILE_ATTRIBUTE_NORMAL, // File att. | |
4881 NULL); // Temp file | |
3361 | 4882 si.hStdOutput = si.hStdInput; |
4883 si.hStdError = si.hStdInput; | |
4884 } | |
4885 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4886 // 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
|
4887 // at the start of the command. |
3361 | 4888 if (cmdbase > cmd) |
4889 { | |
4890 p = cmdbase + STRLEN(cmdbase); | |
4891 if (p > cmdbase && p[-1] == '"' && *cmd == '"') | |
4892 *--p = NUL; | |
4893 if (p > cmdbase && p[-1] == ')' | |
4894 && (*cmd =='(' || cmd[1] == '(')) | |
4895 *--p = NUL; | |
4896 } | |
4897 | |
3363 | 4898 newcmd = cmdbase; |
4899 unescape_shellxquote(cmdbase, p_sxe); | |
4900 | |
3361 | 4901 /* |
3363 | 4902 * If creating new console, arguments are passed to the |
4903 * 'cmd.exe' as-is. If it's not, arguments are not treated | |
4904 * correctly for current 'cmd.exe'. So unescape characters in | |
4905 * shellxescape except '|' for avoiding to be treated as | |
4906 * argument to them. Pass the arguments to sub-shell. | |
3361 | 4907 */ |
3363 | 4908 if (flags != CREATE_NEW_CONSOLE) |
4909 { | |
4910 char_u *subcmd; | |
3367 | 4911 char_u *cmd_shell = mch_getenv("COMSPEC"); |
4912 | |
4913 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
|
4914 cmd_shell = (char_u *)default_shell(); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4915 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4916 subcmd = vim_strsave_escaped_ext(cmdbase, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
4917 (char_u *)"|", '^', FALSE); |
3363 | 4918 if (subcmd != NULL) |
4919 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4920 // make "cmd.exe /c arguments" |
3363 | 4921 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
|
4922 newcmd = alloc(cmdlen); |
3363 | 4923 if (newcmd != NULL) |
4924 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s", | |
3367 | 4925 cmd_shell, subcmd); |
3363 | 4926 else |
4927 newcmd = cmdbase; | |
3367 | 4928 vim_free(subcmd); |
3363 | 4929 } |
4930 } | |
3361 | 4931 |
4932 /* | |
4933 * Now, start the command as a process, so that it doesn't | |
4934 * inherit our handles which causes unpleasant dangling swap | |
4935 * files if we exit before the spawned process | |
4936 */ | |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
4937 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
|
4938 &si, &pi, NULL, NULL)) |
3361 | 4939 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
|
4940 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
|
4941 > (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
|
4942 x = 0; |
3361 | 4943 else |
4944 { | |
4945 x = -1; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4946 #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
|
4947 # 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
|
4948 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
|
4949 # endif |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4950 emsg(_(e_command_not_found)); |
3361 | 4951 #endif |
4952 } | |
3363 | 4953 |
4954 if (newcmd != cmdbase) | |
4955 vim_free(newcmd); | |
4956 | |
5627 | 4957 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) |
3361 | 4958 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4959 // Close the handle to \\.\NUL created above. |
3361 | 4960 CloseHandle(si.hStdInput); |
4961 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
4962 // Close the handles to the subprocess, so that it goes away |
3361 | 4963 CloseHandle(pi.hThread); |
4964 CloseHandle(pi.hProcess); | |
4965 } | |
4966 else | |
4967 { | |
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
|
4968 cmdlen = |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4969 #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
|
4970 ((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
|
4971 (!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
|
4972 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
|
4973 : 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
|
4974 #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
|
4975 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; |
1569 | 4976 |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
4977 newcmd = alloc(cmdlen); |
3361 | 4978 if (newcmd != NULL) |
7 | 4979 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
4980 #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
|
4981 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
|
4982 # 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
|
4983 (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
|
4984 # 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
|
4985 need_vimrun_warning) |
7 | 4986 { |
10400
17165aabc731
commit https://github.com/vim/vim/commit/63e4344edc0cc1b4ed68a9d9c787265799602670
Christian Brabandt <cb@256bit.org>
parents:
10386
diff
changeset
|
4987 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
|
4988 "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
|
4989 "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
|
4990 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
|
4991 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
|
4992 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
|
4993 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
4994 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
|
4995 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
|
4996 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
|
4997 vim_free(wtitle); |
7 | 4998 need_vimrun_warning = FALSE; |
4999 } | |
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
|
5000 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
|
5001 # 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
|
5002 (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
|
5003 # 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
|
5004 !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
|
5005 // 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
|
5006 // 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
|
5007 vim_snprintf((char *)newcmd, cmdlen, "%s%s%s %s %s", |
7 | 5008 vimrun_path, |
5009 (msg_silent != 0 || (options & SHELL_DOOUT)) | |
5010 ? "-s " : "", | |
5011 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
|
5012 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
|
5013 # 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
|
5014 (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
|
5015 # 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
|
5016 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
|
5017 // 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
|
5018 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
|
5019 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
|
5020 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
|
5021 #endif |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5022 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", |
1569 | 5023 p_sh, p_shcf, cmd); |
7 | 5024 x = mch_system((char *)newcmd, options); |
3361 | 5025 vim_free(newcmd); |
7 | 5026 } |
5027 } | |
5028 } | |
5029 | |
5030 if (tmode == TMODE_RAW) | |
20437
3bb4dea4a164
patch 8.2.0773: switching to raw mode every time ":" is used
Bram Moolenaar <Bram@vim.org>
parents:
20227
diff
changeset
|
5031 { |
3bb4dea4a164
patch 8.2.0773: switching to raw mode every time ":" is used
Bram Moolenaar <Bram@vim.org>
parents:
20227
diff
changeset
|
5032 // The shell may have messed with the mode, always set it. |
3bb4dea4a164
patch 8.2.0773: switching to raw mode every time ":" is used
Bram Moolenaar <Bram@vim.org>
parents:
20227
diff
changeset
|
5033 cur_tmode = TMODE_UNKNOWN; |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5034 settmode(TMODE_RAW); // set to raw mode |
20437
3bb4dea4a164
patch 8.2.0773: switching to raw mode every time ":" is used
Bram Moolenaar <Bram@vim.org>
parents:
20227
diff
changeset
|
5035 } |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5036 |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5037 // Print the return value, unless "vimrun" was used. |
7 | 5038 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
|
5039 #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
|
5040 && ((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
|
5041 ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) : 1) |
7 | 5042 #endif |
5043 ) | |
5044 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5045 smsg(_("shell returned %d"), x); |
7 | 5046 msg_putchar('\n'); |
5047 } | |
5048 resettitle(); | |
5049 | |
5050 signal(SIGINT, SIG_DFL); | |
5051 #if defined(__GNUC__) && !defined(__MINGW32__) | |
5052 signal(SIGKILL, SIG_DFL); | |
5053 #else | |
5054 signal(SIGBREAK, SIG_DFL); | |
5055 #endif | |
5056 signal(SIGILL, SIG_DFL); | |
5057 signal(SIGFPE, SIG_DFL); | |
5058 signal(SIGSEGV, SIG_DFL); | |
5059 signal(SIGTERM, SIG_DFL); | |
5060 signal(SIGABRT, SIG_DFL); | |
5061 | |
5062 return x; | |
5063 } | |
5064 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8491
diff
changeset
|
5065 #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
|
5066 static HANDLE |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5067 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
|
5068 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
|
5069 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
|
5070 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
|
5071 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
|
5072 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
|
5073 DWORD dwFlagsAndAttributes) |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5074 { |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5075 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
|
5076 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
|
5077 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
5078 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
|
5079 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
|
5080 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
|
5081 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
5082 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
|
5083 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
|
5084 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
|
5085 vim_free(wn); |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5086 return h; |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5087 } |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5088 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5089 /* |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5090 * 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
|
5091 * 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
|
5092 */ |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12140
diff
changeset
|
5093 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
|
5094 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
|
5095 { |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5096 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
|
5097 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
|
5098 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
|
5099 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5100 // 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
|
5101 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
|
5102 return; |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5103 |
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
|
5104 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
|
5105 { |
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
|
5106 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
|
5107 { |
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
|
5108 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
|
5109 { |
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
|
5110 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
|
5111 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
|
5112 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
|
5113 --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
|
5114 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
|
5115 { |
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
|
5116 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
|
5117 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
|
5118 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
|
5119 |
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
|
5120 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
|
5121 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
|
5122 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
|
5123 *((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
|
5124 *((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
|
5125 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
|
5126 *((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
|
5127 *((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
|
5128 } |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
5129 vim_free(wkey); |
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15955
diff
changeset
|
5130 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
|
5131 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5132 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5133 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5134 |
19362
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5135 if (base) |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5136 { |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5137 WCHAR *p = (WCHAR*) base; |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5138 |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5139 // for last \0 |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5140 if (ga_grow(gap, 1) == FAIL) |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5141 return; |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5142 |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5143 while (*p != 0 || *(p + 1) != 0) |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5144 { |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5145 if (ga_grow(gap, 1) == OK) |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5146 *((WCHAR*)gap->ga_data + gap->ga_len++) = *p; |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5147 p++; |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5148 } |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5149 FreeEnvironmentStrings(base); |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5150 *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5151 } |
7894f20668b1
patch 8.2.0239: MS-Windows: 'env' job option does not override existing vars
Bram Moolenaar <Bram@vim.org>
parents:
19360
diff
changeset
|
5152 |
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
|
5153 # 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
|
5154 { |
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
|
5155 # 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
|
5156 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
|
5157 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
|
5158 # 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
|
5159 # 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
|
5160 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
|
5161 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
|
5162 # endif |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5163 // 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
|
5164 // 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
|
5165 // 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
|
5166 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
|
5167 # 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
|
5168 + 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
|
5169 # 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
|
5170 # 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
|
5171 + 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
|
5172 # 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
|
5173 ; |
14063
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5174 |
f39150ec146e
patch 8.1.0049: shell cannot tell running in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13853
diff
changeset
|
5175 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
|
5176 { |
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
|
5177 # 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
|
5178 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
|
5179 *((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
|
5180 (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
|
5181 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
|
5182 *((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
|
5183 (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
|
5184 *((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
|
5185 # 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
|
5186 # 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
|
5187 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
|
5188 { |
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
|
5189 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
|
5190 *((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
|
5191 (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
|
5192 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
|
5193 *((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
|
5194 (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
|
5195 *((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
|
5196 } |
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
|
5197 # 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
|
5198 } |
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
|
5199 } |
14067
39ec4b90e4a7
patch 8.1.0051: MS-Windows: missing #endif
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
5200 # endif |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5201 } |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5202 |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5203 /* |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5204 * 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
|
5205 * 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
|
5206 */ |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5207 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
|
5208 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
|
5209 { |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5210 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
|
5211 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
|
5212 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
|
5213 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5214 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
|
5215 GetCurrentProcessId(), |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5216 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
|
5217 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5218 // 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
|
5219 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
|
5220 name, |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5221 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
|
5222 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
|
5223 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
|
5224 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5225 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
|
5226 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
|
5227 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5228 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
|
5229 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
|
5230 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
|
5231 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5232 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
|
5233 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
|
5234 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
|
5235 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
|
5236 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5237 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
|
5238 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5239 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
|
5240 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
|
5241 } |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5242 |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5243 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
|
5244 } |
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5245 |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5246 void |
11723
1922710ee8fa
patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents:
11230
diff
changeset
|
5247 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
|
5248 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5249 STARTUPINFO si; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5250 PROCESS_INFORMATION pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5251 HANDLE jo; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5252 SECURITY_ATTRIBUTES saAttr; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5253 channel_T *channel = NULL; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5254 HANDLE ifd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5255 HANDLE ofd[2]; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5256 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
|
5257 garray_T ga; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5258 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5259 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
|
5260 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
|
5261 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
|
5262 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
|
5263 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
|
5264 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
|
5265 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
|
5266 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5267 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
|
5268 use_null_for_err = TRUE; |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5269 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5270 ifd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5271 ifd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5272 ofd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5273 ofd[1] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5274 efd[0] = INVALID_HANDLE_VALUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5275 efd[1] = INVALID_HANDLE_VALUE; |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26913
diff
changeset
|
5276 ga_init2(&ga, sizeof(wchar_t), 500); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5277 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5278 jo = CreateJobObject(NULL, NULL); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5279 if (jo == NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5280 { |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5281 job->jv_status = JOB_FAILED; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5282 goto failed; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5283 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5284 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5285 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
|
5286 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
|
5287 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5288 ZeroMemory(&pi, sizeof(pi)); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5289 ZeroMemory(&si, sizeof(si)); |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5290 si.cb = sizeof(si); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5291 si.dwFlags |= STARTF_USESHOWWINDOW; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5292 si.wShowWindow = SW_HIDE; |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5293 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5294 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5295 saAttr.bInheritHandle = TRUE; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5296 saAttr.lpSecurityDescriptor = NULL; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5297 |
8430
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5298 if (use_file_for_in) |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5299 { |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5300 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
|
5301 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5302 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
|
5303 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5304 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5305 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
|
5306 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
5307 semsg(_(e_cant_open_file_str), fname); |
8443
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5308 goto failed; |
6c421014a0b3
commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8
Christian Brabandt <cb@256bit.org>
parents:
8430
diff
changeset
|
5309 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5310 } |
15539
ba876ced4f1f
patch 8.1.0777: Win32: using pipes for channel does not work well
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5311 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
|
5312 && (!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
|
5313 || !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
|
5314 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5315 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5316 if (use_file_for_out) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5317 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5318 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
|
5319 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5320 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
|
5321 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5322 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5323 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
|
5324 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
5325 semsg(_(e_cant_open_file_str), fname); |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5326 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5327 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5328 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5329 else if (!use_null_for_out && |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5330 (!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
|
5331 || !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
|
5332 goto failed; |
800423dbc260
commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents:
8386
diff
changeset
|
5333 |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5334 if (use_file_for_err) |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5335 { |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5336 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
|
5337 |
8483
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5338 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
|
5339 FILE_SHARE_READ | FILE_SHARE_WRITE, |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5340 &saAttr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); |
7376d36395f0
commit https://github.com/vim/vim/commit/7bffaa9f9b477969d85cef41adeadc4506373708
Christian Brabandt <cb@256bit.org>
parents:
8479
diff
changeset
|
5341 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
|
5342 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
5343 semsg(_(e_cant_open_file_str), fname); |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5344 goto failed; |
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5345 } |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5346 } |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5347 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
|
5348 (!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
|
5349 || !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
|
5350 goto failed; |
8457
20533e3de373
commit https://github.com/vim/vim/commit/13d6fb17a2c5d2ae02429e31fc8603a9caa4395e
Christian Brabandt <cb@256bit.org>
parents:
8443
diff
changeset
|
5351 |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5352 si.dwFlags |= STARTF_USESTDHANDLES; |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5353 si.hStdInput = ifd[0]; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5354 si.hStdOutput = ofd[1]; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5355 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
|
5356 |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5357 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
|
5358 { |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5359 if (options->jo_set & JO_CHANNEL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5360 { |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5361 channel = options->jo_channel; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5362 if (channel != NULL) |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5363 ++channel->ch_refcount; |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5364 } |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5365 else |
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5366 channel = add_channel(); |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5367 if (channel == NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5368 goto failed; |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5369 } |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5370 |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5371 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
|
5372 CREATE_SUSPENDED | |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5373 CREATE_DEFAULT_ERROR_MODE | |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5374 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
|
5375 CREATE_UNICODE_ENVIRONMENT | |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5376 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
|
5377 &si, &pi, |
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5378 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
|
5379 (char *)options->jo_cwd)) |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5380 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5381 CloseHandle(jo); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5382 job->jv_status = JOB_FAILED; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5383 goto failed; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5384 } |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5385 |
12043
2796a2c9fc17
patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents:
12037
diff
changeset
|
5386 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
|
5387 |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5388 if (!AssignProcessToJobObject(jo, pi.hProcess)) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5389 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5390 // 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
|
5391 // process with TerminateProcess. |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5392 CloseHandle(jo); |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5393 jo = NULL; |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5394 } |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5395 ResumeThread(pi.hThread); |
8479
9f63e4506c40
commit https://github.com/vim/vim/commit/75578a388d2aff59dc330ceccd8894c79b4bc735
Christian Brabandt <cb@256bit.org>
parents:
8471
diff
changeset
|
5396 CloseHandle(pi.hThread); |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5397 job->jv_proc_info = pi; |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5398 job->jv_job_object = jo; |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5399 job->jv_status = JOB_STARTED; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5400 |
10060
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5401 CloseHandle(ifd[0]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5402 CloseHandle(ofd[1]); |
cf9e550f17f6
commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5403 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
|
5404 CloseHandle(efd[1]); |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5405 |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5406 job->jv_channel = channel; |
8471
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5407 if (channel != NULL) |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5408 { |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5409 channel_set_pipes(channel, |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5410 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
|
5411 ? INVALID_FD : (sock_T)ifd[1], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5412 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
|
5413 ? INVALID_FD : (sock_T)ofd[0], |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5414 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
|
5415 ? INVALID_FD : (sock_T)efd[0]); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5416 channel_set_job(channel, job, options); |
c1aae3a79279
commit https://github.com/vim/vim/commit/d5d3d307ddb824f59a2f2516c4b6a6d48762aa58
Christian Brabandt <cb@256bit.org>
parents:
8457
diff
changeset
|
5417 } |
8047
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5418 return; |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5419 |
7c74cafac0a1
commit https://github.com/vim/vim/commit/7b3ca76a451b10d238ef946f3231762e0bd988e9
Christian Brabandt <cb@256bit.org>
parents:
8023
diff
changeset
|
5420 failed: |
8059
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5421 CloseHandle(ifd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5422 CloseHandle(ofd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5423 CloseHandle(efd[0]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5424 CloseHandle(ifd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5425 CloseHandle(ofd[1]); |
19304db153bc
commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents:
8053
diff
changeset
|
5426 CloseHandle(efd[1]); |
8491
daebcbd87bd3
commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents:
8483
diff
changeset
|
5427 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
|
5428 ga_clear(&ga); |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5429 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5430 |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5431 char * |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5432 mch_job_status(job_T *job) |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5433 { |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5434 DWORD dwExitCode = 0; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5435 |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5436 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
|
5437 || dwExitCode != STILL_ACTIVE) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5438 { |
8176
477c1d855698
commit https://github.com/vim/vim/commit/eab089d22f172ddd2d33367a998e68c2f1c6c989
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
5439 job->jv_exitval = (int)dwExitCode; |
10386
d3f0946b4a80
commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents:
10317
diff
changeset
|
5440 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
|
5441 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5442 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
|
5443 job->jv_status = JOB_ENDED; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5444 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5445 return "dead"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5446 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5447 return "run"; |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5448 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5449 |
10279
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5450 job_T * |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5451 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
|
5452 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5453 HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5454 job_T *jobArray[MAXIMUM_WAIT_OBJECTS]; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5455 job_T *job = job_list; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5456 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5457 while (job != NULL) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5458 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5459 DWORD n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5460 DWORD result; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5461 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5462 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
|
5463 && job != NULL; job = job->jv_next) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5464 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5465 if (job->jv_status == JOB_STARTED) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5466 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5467 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
|
5468 jobArray[n] = job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5469 ++n; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5470 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5471 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5472 if (n == 0) |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5473 continue; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5474 result = WaitForMultipleObjects(n, jobHandles, FALSE, 0); |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5475 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
|
5476 { |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5477 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
|
5478 |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5479 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
|
5480 return wait_job; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5481 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5482 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5483 return NULL; |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5484 } |
c5c15c818bda
commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
5485 |
10317
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5486 static BOOL |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5487 terminate_all(HANDLE process, int code) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5488 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5489 PROCESSENTRY32 pe; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5490 HANDLE h = INVALID_HANDLE_VALUE; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5491 DWORD pid = GetProcessId(process); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5492 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5493 if (pid != 0) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5494 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5495 h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5496 if (h != INVALID_HANDLE_VALUE) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5497 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5498 pe.dwSize = sizeof(PROCESSENTRY32); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5499 if (!Process32First(h, &pe)) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5500 goto theend; |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5501 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5502 do |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5503 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5504 if (pe.th32ParentProcessID == pid) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5505 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5506 HANDLE ph = OpenProcess( |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5507 PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5508 if (ph != NULL) |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5509 { |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5510 terminate_all(ph, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5511 CloseHandle(ph); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5512 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5513 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5514 } while (Process32Next(h, &pe)); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5515 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5516 CloseHandle(h); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5517 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5518 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5519 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5520 theend: |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5521 return TerminateProcess(process, code); |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5522 } |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5523 |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5524 /* |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5525 * Send a (deadly) signal to "job". |
25cc0021a8d7
commit https://github.com/vim/vim/commit/fb63090b62801d718fe7e1f44407358404c08724
Christian Brabandt <cb@256bit.org>
parents:
10311
diff
changeset
|
5526 * 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
|
5527 */ |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5528 int |
12037
85f0f557661e
patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
5529 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
|
5530 { |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5531 int ret; |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5532 |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5533 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
|
5534 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5535 // deadly signal |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5536 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
|
5537 { |
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
|
5538 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
|
5539 job->jv_channel->ch_killing = TRUE; |
27455
6045bf58926d
patch 8.2.4256: MS-Windows: compiler warnings when compiled with /W4
Bram Moolenaar <Bram@vim.org>
parents:
27370
diff
changeset
|
5540 return TerminateJobObject(job->jv_job_object, (UINT)-1) ? 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
|
5541 } |
19360
16d538568dc8
patch 8.2.0238: MS-Windows: job_stop() results in exit value zero
Bram Moolenaar <Bram@vim.org>
parents:
19239
diff
changeset
|
5542 return terminate_all(job->jv_proc_info.hProcess, -1) ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5543 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5544 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5545 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
|
5546 return FAIL; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5547 ret = GenerateConsoleCtrlEvent( |
8251
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5548 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
|
5549 job->jv_proc_info.dwProcessId) |
989ac3aed1ef
commit https://github.com/vim/vim/commit/923d926d57d985ec8965da9d0cd3634e6b24bfe1
Christian Brabandt <cb@256bit.org>
parents:
8222
diff
changeset
|
5550 ? OK : FAIL; |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5551 FreeConsole(); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5552 return ret; |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5553 } |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5554 |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5555 /* |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5556 * Clear the data related to "job". |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5557 */ |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5558 void |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5559 mch_clear_job(job_T *job) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5560 { |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5561 if (job->jv_status != JOB_FAILED) |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5562 { |
10311
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5563 if (job->jv_job_object != NULL) |
931422d27b69
commit https://github.com/vim/vim/commit/14207f487c9e79a913256a41e3e9716b03b46955
Christian Brabandt <cb@256bit.org>
parents:
10304
diff
changeset
|
5564 CloseHandle(job->jv_job_object); |
8023
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5565 CloseHandle(job->jv_proc_info.hProcess); |
75e0831549f1
commit https://github.com/vim/vim/commit/76467dfcafcf295fd987f712730774c6f55317d3
Christian Brabandt <cb@256bit.org>
parents:
8015
diff
changeset
|
5566 } |
7975
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5567 } |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5568 #endif |
7224f5e9c36a
commit https://github.com/vim/vim/commit/942d6b22686858c9e72f8b8929df5c288170179c
Christian Brabandt <cb@256bit.org>
parents:
7935
diff
changeset
|
5569 |
7 | 5570 |
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
|
5571 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 5572 |
5573 /* | |
5574 * Start termcap mode | |
5575 */ | |
5576 static void | |
5577 termcap_mode_start(void) | |
5578 { | |
5579 DWORD cmodein; | |
5580 | |
5581 if (g_fTermcapMode) | |
5582 return; | |
5583 | |
20051
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5584 if (!p_rs && USE_VTP) |
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5585 vtp_printf("\033[?1049h"); |
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5586 |
7 | 5587 SaveConsoleBuffer(&g_cbNonTermcap); |
5588 | |
5589 if (g_cbTermcap.IsValid) | |
5590 { | |
5591 /* | |
5592 * We've been in termcap mode before. Restore certain screen | |
5593 * characteristics, including the buffer size and the window | |
5594 * size. Since we will be redrawing the screen, we don't need | |
5595 * to restore the actual contents of the buffer. | |
5596 */ | |
5597 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
|
5598 reset_console_color_rgb(); |
7 | 5599 SetConsoleWindowInfo(g_hConOut, TRUE, &g_cbTermcap.Info.srWindow); |
5600 Rows = g_cbTermcap.Info.dwSize.Y; | |
5601 Columns = g_cbTermcap.Info.dwSize.X; | |
5602 } | |
5603 else | |
5604 { | |
5605 /* | |
5606 * This is our first time entering termcap mode. Clear the console | |
5607 * screen buffer, and resize the buffer to match the current window | |
5608 * size. We will use this as the size of our editing environment. | |
5609 */ | |
5610 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
|
5611 set_console_color_rgb(); |
7 | 5612 ResizeConBufAndWindow(g_hConOut, Columns, Rows); |
5613 } | |
5614 | |
5615 resettitle(); | |
5616 | |
5617 GetConsoleMode(g_hConIn, &cmodein); | |
5618 if (g_fMouseActive) | |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
5619 { |
7 | 5620 cmodein |= ENABLE_MOUSE_INPUT; |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
5621 cmodein &= ~ENABLE_QUICK_EDIT_MODE; |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
5622 } |
7 | 5623 else |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
5624 { |
7 | 5625 cmodein &= ~ENABLE_MOUSE_INPUT; |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
5626 cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE; |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
5627 } |
7 | 5628 cmodein |= ENABLE_WINDOW_INPUT; |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
5629 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS); |
7 | 5630 |
5631 redraw_later_clear(); | |
5632 g_fTermcapMode = TRUE; | |
5633 } | |
5634 | |
5635 | |
5636 /* | |
5637 * End termcap mode | |
5638 */ | |
5639 static void | |
5640 termcap_mode_end(void) | |
5641 { | |
5642 DWORD cmodein; | |
5643 ConsoleBuffer *cb; | |
5644 COORD coord; | |
5645 DWORD dwDummy; | |
5646 | |
5647 if (!g_fTermcapMode) | |
5648 return; | |
5649 | |
5650 SaveConsoleBuffer(&g_cbTermcap); | |
5651 | |
5652 GetConsoleMode(g_hConIn, &cmodein); | |
5653 cmodein &= ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT); | |
24749
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
5654 cmodein |= g_cmodein & ENABLE_QUICK_EDIT_MODE; |
fb44ba319785
patch 8.2.2913: MS-Windows conpty supports using mouse events
Bram Moolenaar <Bram@vim.org>
parents:
24671
diff
changeset
|
5655 SetConsoleMode(g_hConIn, cmodein | ENABLE_EXTENDED_FLAGS); |
7 | 5656 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5657 # ifdef FEAT_RESTORE_ORIG_SCREEN |
7184
0a256475412f
commit https://github.com/vim/vim/commit/4c0aac57599092da404f6726e88701ba441a4a6d
Christian Brabandt <cb@256bit.org>
parents:
7150
diff
changeset
|
5658 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
|
5659 # else |
7 | 5660 cb = &g_cbNonTermcap; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
5661 # endif |
20051
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5662 RestoreConsoleBuffer(cb, p_rs); |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
5663 restore_console_color_rgb(); |
7 | 5664 SetConsoleCursorInfo(g_hConOut, &g_cci); |
5665 | |
5666 if (p_rs || exiting) | |
5667 { | |
5668 /* | |
5669 * Clear anything that happens to be on the current line. | |
5670 */ | |
5671 coord.X = 0; | |
5672 coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1)); | |
5673 FillConsoleOutputCharacter(g_hConOut, ' ', | |
5674 cb->Info.dwSize.X, coord, &dwDummy); | |
5675 /* | |
5676 * The following is just for aesthetics. If we are exiting without | |
5677 * restoring the screen, then we want to have a prompt string | |
5678 * appear at the bottom line. However, the command interpreter | |
5679 * seems to always advance the cursor one line before displaying | |
5680 * the prompt string, which causes the screen to scroll. To | |
5681 * counter this, move the cursor up one line before exiting. | |
5682 */ | |
5683 if (exiting && !p_rs) | |
5684 coord.Y--; | |
5685 /* | |
5686 * Position the cursor at the leftmost column of the desired row. | |
5687 */ | |
20051
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5688 SetConsoleCursorPosition(g_hConOut, coord); |
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5689 } |
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5690 |
678cdef2d690
patch 8.2.0581: Win32 console: the cursor position is always top-left
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5691 if (!p_rs && USE_VTP) |
19868
a2fa2fc0f403
patch 8.2.0490: Win32: VTP doesn't respect 'restorescreen'
Bram Moolenaar <Bram@vim.org>
parents:
19789
diff
changeset
|
5692 vtp_printf("\033[?1049l"); |
a2fa2fc0f403
patch 8.2.0490: Win32: VTP doesn't respect 'restorescreen'
Bram Moolenaar <Bram@vim.org>
parents:
19789
diff
changeset
|
5693 |
7 | 5694 g_fTermcapMode = FALSE; |
5695 } | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5696 #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
|
5697 |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5698 |
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
|
5699 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 5700 void |
5701 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
|
5702 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
|
5703 int len UNUSED) |
7 | 5704 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
5705 // never used |
7 | 5706 } |
5707 | |
5708 #else | |
5709 | |
5710 /* | |
5711 * clear `n' chars, starting from `coord' | |
5712 */ | |
5713 static void | |
5714 clear_chars( | |
5715 COORD coord, | |
5716 DWORD n) | |
5717 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5718 if (!USE_VTP) |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
5719 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
5720 DWORD dwDummy; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
5721 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
5722 FillConsoleOutputCharacter(g_hConOut, ' ', n, coord, &dwDummy); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
5723 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, n, coord, |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
5724 &dwDummy); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
5725 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5726 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
|
5727 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
5728 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
|
5729 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
|
5730 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
|
5731 } |
7 | 5732 } |
5733 | |
5734 | |
5735 /* | |
5736 * Clear the screen | |
5737 */ | |
5738 static void | |
5739 clear_screen(void) | |
5740 { | |
5741 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
|
5742 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5743 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
|
5744 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
|
5745 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5746 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5747 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
|
5748 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
|
5749 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
|
5750 } |
7 | 5751 } |
5752 | |
5753 | |
5754 /* | |
5755 * Clear to end of display | |
5756 */ | |
5757 static void | |
5758 clear_to_end_of_display(void) | |
5759 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5760 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
|
5761 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5762 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
|
5763 clear_chars(g_coord, (Rows - g_coord.Y - 1) |
7 | 5764 * 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
|
5765 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5766 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5767 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
|
5768 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
|
5769 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
|
5770 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5771 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
|
5772 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
|
5773 } |
7 | 5774 } |
5775 | |
5776 | |
5777 /* | |
5778 * Clear to end of line | |
5779 */ | |
5780 static void | |
5781 clear_to_end_of_line(void) | |
5782 { | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5783 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
|
5784 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5785 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
|
5786 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
|
5787 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5788 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5789 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
|
5790 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
|
5791 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
|
5792 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
5793 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
|
5794 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
|
5795 } |
7 | 5796 } |
5797 | |
5798 | |
5799 /* | |
5800 * Scroll the scroll region up by `cLines' lines | |
5801 */ | |
5802 static void | |
26 | 5803 scroll(unsigned cLines) |
7 | 5804 { |
5805 COORD oldcoord = g_coord; | |
5806 | |
5807 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Top + 1); | |
5808 delete_lines(cLines); | |
5809 | |
5810 g_coord = oldcoord; | |
5811 } | |
5812 | |
5813 | |
5814 /* | |
5815 * Set the scroll region | |
5816 */ | |
5817 static void | |
5818 set_scroll_region( | |
5819 unsigned left, | |
5820 unsigned top, | |
5821 unsigned right, | |
5822 unsigned bottom) | |
5823 { | |
5824 if (left >= right | |
5825 || top >= bottom | |
5826 || right > (unsigned) Columns - 1 | |
5827 || bottom > (unsigned) Rows - 1) | |
5828 return; | |
5829 | |
5830 g_srScrollRegion.Left = left; | |
5831 g_srScrollRegion.Top = top; | |
5832 g_srScrollRegion.Right = right; | |
5833 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
|
5834 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5835 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5836 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
|
5837 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
|
5838 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
|
5839 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
|
5840 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5841 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
|
5842 return; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5843 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5844 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
|
5845 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
|
5846 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5847 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5848 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
|
5849 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
|
5850 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
|
5851 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
|
5852 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5853 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
|
5854 return; |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5855 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5856 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
|
5857 g_srScrollRegion.Right = right; |
7 | 5858 } |
5859 | |
5860 | |
5861 /* | |
5862 * Insert `cLines' lines at the current cursor position | |
5863 */ | |
5864 static void | |
26 | 5865 insert_lines(unsigned cLines) |
7 | 5866 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5867 SMALL_RECT source, clip; |
7 | 5868 COORD dest; |
5869 CHAR_INFO fill; | |
5870 | |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5871 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
|
5872 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5873 dest.X = g_srScrollRegion.Left; |
7 | 5874 dest.Y = g_coord.Y + cLines; |
5875 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5876 source.Left = g_srScrollRegion.Left; |
7 | 5877 source.Top = g_coord.Y; |
5878 source.Right = g_srScrollRegion.Right; | |
5879 source.Bottom = g_srScrollRegion.Bottom - cLines; | |
5880 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5881 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
|
5882 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
|
5883 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
|
5884 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
|
5885 |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5886 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
|
5887 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
|
5888 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
|
5889 else |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5890 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
|
5891 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5892 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
|
5893 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5894 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
|
5895 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5896 // 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
|
5897 // 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
|
5898 // 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
|
5899 // 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
|
5900 // 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
|
5901 // direction). |
7 | 5902 |
5903 if (source.Bottom < dest.Y) | |
5904 { | |
5905 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
|
5906 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
|
5907 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5908 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
|
5909 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
|
5910 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5911 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
|
5912 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
|
5913 } |
7 | 5914 } |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5915 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5916 if (USE_WT) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5917 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5918 COORD coord; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5919 int i; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5920 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5921 coord.X = source.Left; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5922 for (i = source.Top; i < dest.Y; ++i) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5923 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5924 coord.Y = i; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5925 clear_chars(coord, source.Right - source.Left + 1); |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5926 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5927 } |
7 | 5928 } |
5929 | |
5930 | |
5931 /* | |
5932 * Delete `cLines' lines at the current cursor position | |
5933 */ | |
5934 static void | |
26 | 5935 delete_lines(unsigned cLines) |
7 | 5936 { |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5937 SMALL_RECT source, clip; |
7 | 5938 COORD dest; |
5939 CHAR_INFO fill; | |
5940 int nb; | |
5941 | |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5942 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
|
5943 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5944 dest.X = g_srScrollRegion.Left; |
7 | 5945 dest.Y = g_coord.Y; |
5946 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5947 source.Left = g_srScrollRegion.Left; |
7 | 5948 source.Top = g_coord.Y + cLines; |
5949 source.Right = g_srScrollRegion.Right; | |
5950 source.Bottom = g_srScrollRegion.Bottom; | |
5951 | |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5952 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
|
5953 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
|
5954 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
|
5955 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
|
5956 |
16015
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5957 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
|
5958 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
|
5959 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
|
5960 else |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5961 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
|
5962 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5963 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
|
5964 |
7e33709a3d0a
patch 8.1.1013: MS-Windows: Scrolling fails when dividing the screen
Bram Moolenaar <Bram@vim.org>
parents:
15983
diff
changeset
|
5965 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
|
5966 |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5967 // 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
|
5968 // above. |
7 | 5969 |
5970 nb = dest.Y + (source.Bottom - source.Top) + 1; | |
5971 | |
5972 if (nb < source.Top) | |
5973 { | |
5974 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
|
5975 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
|
5976 |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5977 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
|
5978 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
|
5979 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
5980 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
|
5981 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
|
5982 } |
7 | 5983 } |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5984 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5985 if (USE_WT) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5986 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5987 COORD coord; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5988 int i; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5989 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5990 coord.X = source.Left; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5991 for (i = nb; i <= source.Bottom; ++i) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5992 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5993 coord.Y = i; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5994 clear_chars(coord, source.Right - source.Left + 1); |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5995 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
5996 } |
7 | 5997 } |
5998 | |
5999 | |
6000 /* | |
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
|
6001 * Set the cursor position to (x,y) (1-based). |
7 | 6002 */ |
6003 static void | |
6004 gotoxy( | |
6005 unsigned x, | |
6006 unsigned y) | |
6007 { | |
6008 if (x < 1 || x > (unsigned)Columns || y < 1 || y > (unsigned)Rows) | |
6009 return; | |
6010 | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6011 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
|
6012 { |
19789
25836c21ccf9
patch 8.2.0451: Win32: double-width character displayed incorrectly
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
6013 // There are reports of double-width characters not displayed |
25836c21ccf9
patch 8.2.0451: Win32: double-width character displayed incorrectly
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
6014 // correctly. This workaround should fix it, similar to how it's done |
25836c21ccf9
patch 8.2.0451: Win32: double-width character displayed incorrectly
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
6015 // for VTP. |
25836c21ccf9
patch 8.2.0451: Win32: double-width character displayed incorrectly
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
6016 g_coord.X = 0; |
25836c21ccf9
patch 8.2.0451: Win32: double-width character displayed incorrectly
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
6017 SetConsoleCursorPosition(g_hConOut, g_coord); |
25836c21ccf9
patch 8.2.0451: Win32: double-width character displayed incorrectly
Bram Moolenaar <Bram@vim.org>
parents:
19599
diff
changeset
|
6018 |
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
|
6019 // 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
|
6020 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
|
6021 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
|
6022 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
|
6023 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6024 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
|
6025 { |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
6026 // 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
|
6027 // 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
|
6028 // 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
|
6029 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
|
6030 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6031 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
|
6032 |
2ededa437271
patch 8.1.2085: MS-Windows: draw error moving cursor over double-cell char
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
6033 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
|
6034 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
|
6035 } |
7 | 6036 } |
6037 | |
6038 | |
6039 /* | |
6040 * 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
|
6041 * See ../runtime/doc/os_win32.txt for the numbers. |
7 | 6042 */ |
6043 static void | |
26 | 6044 textattr(WORD wAttr) |
7 | 6045 { |
6710 | 6046 g_attrCurrent = wAttr & 0xff; |
7 | 6047 |
6048 SetConsoleTextAttribute(g_hConOut, wAttr); | |
6049 } | |
6050 | |
6051 | |
6052 static void | |
26 | 6053 textcolor(WORD wAttr) |
7 | 6054 { |
6710 | 6055 g_attrCurrent = (g_attrCurrent & 0xf0) + (wAttr & 0x0f); |
7 | 6056 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6057 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
|
6058 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
|
6059 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6060 vtp_sgr_bulk(wAttr); |
7 | 6061 } |
6062 | |
6063 | |
6064 static void | |
26 | 6065 textbackground(WORD wAttr) |
7 | 6066 { |
6710 | 6067 g_attrCurrent = (g_attrCurrent & 0x0f) + ((wAttr & 0x0f) << 4); |
7 | 6068 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6069 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
|
6070 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
|
6071 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6072 vtp_sgr_bulk(wAttr); |
7 | 6073 } |
6074 | |
6075 | |
6076 /* | |
6077 * restore the default text attribute (whatever we started with) | |
6078 */ | |
6079 static void | |
26 | 6080 normvideo(void) |
7 | 6081 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6082 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
|
6083 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
|
6084 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6085 vtp_sgr_bulk(0); |
7 | 6086 } |
6087 | |
6088 | |
6089 static WORD g_attrPreStandout = 0; | |
6090 | |
6091 /* | |
6092 * Make the text standout, by brightening it | |
6093 */ | |
6094 static void | |
6095 standout(void) | |
6096 { | |
6097 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
|
6098 |
7 | 6099 textattr((WORD) (g_attrCurrent|FOREGROUND_INTENSITY|BACKGROUND_INTENSITY)); |
6100 } | |
6101 | |
6102 | |
6103 /* | |
6104 * Turn off standout mode | |
6105 */ | |
6106 static void | |
26 | 6107 standend(void) |
7 | 6108 { |
6109 if (g_attrPreStandout) | |
6110 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
|
6111 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6112 g_attrPreStandout = 0; |
7 | 6113 } |
6114 | |
6115 | |
6116 /* | |
1199 | 6117 * Set normal fg/bg color, based on T_ME. Called when t_me has been set. |
7 | 6118 */ |
6119 void | |
26 | 6120 mch_set_normal_colors(void) |
7 | 6121 { |
6122 char_u *p; | |
6123 int n; | |
6124 | |
6125 cterm_normal_fg_color = (g_attrDefault & 0xf) + 1; | |
6126 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
|
6127 if ( |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6128 # 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
|
6129 !p_tgc && |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6130 # 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
|
6131 T_ME[0] == ESC && T_ME[1] == '|') |
7 | 6132 { |
6133 p = T_ME + 2; | |
6134 n = getdigits(&p); | |
6135 if (*p == 'm' && n > 0) | |
6136 { | |
6137 cterm_normal_fg_color = (n & 0xf) + 1; | |
6138 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1; | |
6139 } | |
6140 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6141 # 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
|
6142 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
|
6143 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
|
6144 # endif |
7 | 6145 } |
6146 | |
6147 | |
6148 /* | |
6149 * visual bell: flash the screen | |
6150 */ | |
6151 static void | |
26 | 6152 visual_bell(void) |
7 | 6153 { |
6154 COORD coordOrigin = {0, 0}; | |
6155 WORD attrFlash = ~g_attrCurrent & 0xff; | |
6156 | |
6157 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
|
6158 LPWORD oldattrs = ALLOC_MULT(WORD, Rows * Columns); |
7 | 6159 |
6160 if (oldattrs == NULL) | |
6161 return; | |
6162 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, | |
6163 coordOrigin, &dwDummy); | |
6164 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, | |
6165 coordOrigin, &dwDummy); | |
6166 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6167 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
|
6168 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
|
6169 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, |
7 | 6170 coordOrigin, &dwDummy); |
6171 vim_free(oldattrs); | |
6172 } | |
6173 | |
6174 | |
6175 /* | |
6176 * Make the cursor visible or invisible | |
6177 */ | |
6178 static void | |
26 | 6179 cursor_visible(BOOL fVisible) |
7 | 6180 { |
6181 s_cursor_visible = fVisible; | |
20073
a2124c6d5e6e
patch 8.2.0592: MS-Windows with VTP: cursor is not made invisible
Bram Moolenaar <Bram@vim.org>
parents:
20051
diff
changeset
|
6182 |
a2124c6d5e6e
patch 8.2.0592: MS-Windows with VTP: cursor is not made invisible
Bram Moolenaar <Bram@vim.org>
parents:
20051
diff
changeset
|
6183 if (USE_VTP) |
a2124c6d5e6e
patch 8.2.0592: MS-Windows with VTP: cursor is not made invisible
Bram Moolenaar <Bram@vim.org>
parents:
20051
diff
changeset
|
6184 vtp_printf("\033[?25%c", fVisible ? 'h' : 'l'); |
a2124c6d5e6e
patch 8.2.0592: MS-Windows with VTP: cursor is not made invisible
Bram Moolenaar <Bram@vim.org>
parents:
20051
diff
changeset
|
6185 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6186 # ifdef MCH_CURSOR_SHAPE |
7 | 6187 mch_update_cursor(); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6188 # endif |
7 | 6189 } |
6190 | |
6191 | |
6192 /* | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6193 * 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
|
6194 * Returns the number of bytes actually written (at least one). |
7 | 6195 */ |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6196 static DWORD |
7 | 6197 write_chars( |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6198 char_u *pchBuf, |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6199 DWORD cbToWrite) |
7 | 6200 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6201 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
|
6202 DWORD written; |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6203 DWORD n, cchwritten; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6204 static DWORD cells; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6205 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
|
6206 static int unibuflen = 0; |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6207 static int 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
|
6208 int cp = enc_utf8 ? CP_UTF8 : enc_codepage; |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6209 static WCHAR *utf8spbuf = NULL; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6210 static int utf8splength; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6211 static DWORD utf8spcells; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6212 static WCHAR **utf8usingbuf = &unicodebuf; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6213 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6214 if (cbToWrite != 1 || *pchBuf != ' ' || !enc_utf8) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6215 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6216 utf8usingbuf = &unicodebuf; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6217 do |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6218 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6219 length = MultiByteToWideChar(cp, 0, (LPCSTR)pchBuf, cbToWrite, |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6220 unicodebuf, unibuflen); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6221 if (length && length <= unibuflen) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6222 break; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6223 vim_free(unicodebuf); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6224 unicodebuf = length ? LALLOC_MULT(WCHAR, length) : NULL; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6225 unibuflen = unibuflen ? 0 : length; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6226 } while(1); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6227 cells = mb_string2cells(pchBuf, cbToWrite); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6228 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6229 else // cbToWrite == 1 && *pchBuf == ' ' && enc_utf8 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6230 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6231 if (utf8usingbuf != &utf8spbuf) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6232 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6233 if (utf8spbuf == NULL) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6234 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6235 cells = mb_string2cells((char_u *)" ", 1); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6236 length = MultiByteToWideChar(CP_UTF8, 0, " ", 1, NULL, 0); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6237 utf8spbuf = LALLOC_MULT(WCHAR, length); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6238 if (utf8spbuf != NULL) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6239 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6240 MultiByteToWideChar(CP_UTF8, 0, " ", 1, utf8spbuf, length); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6241 utf8usingbuf = &utf8spbuf; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6242 utf8splength = length; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6243 utf8spcells = cells; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6244 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6245 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6246 else |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6247 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6248 utf8usingbuf = &utf8spbuf; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6249 length = utf8splength; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6250 cells = utf8spcells; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6251 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6252 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6253 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6254 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6255 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
|
6256 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6257 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
|
6258 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
|
6259 // 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
|
6260 // character was written, otherwise we get stuck. |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6261 if (WriteConsoleOutputCharacterW(g_hConOut, *utf8usingbuf, 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
|
6262 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
|
6263 || 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
|
6264 cchwritten = 1; |
7080
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6265 } |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6266 else |
1a34f5272977
commit https://github.com/vim/vim/commit/ac360bf2ca293735fc7c6654dc2b3066f4c62488
Christian Brabandt <cb@256bit.org>
parents:
7078
diff
changeset
|
6267 { |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6268 if (WriteConsoleW(g_hConOut, *utf8usingbuf, length, &cchwritten, |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6269 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
|
6270 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
|
6271 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6272 |
27455
6045bf58926d
patch 8.2.4256: MS-Windows: compiler warnings when compiled with /W4
Bram Moolenaar <Bram@vim.org>
parents:
27370
diff
changeset
|
6273 if (cchwritten == (DWORD)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
|
6274 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6275 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
|
6276 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
|
6277 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6278 else |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6279 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6280 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
|
6281 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
|
6282 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
|
6283 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
|
6284 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
|
6285 } |
7 | 6286 |
6287 while (g_coord.X > g_srScrollRegion.Right) | |
6288 { | |
6289 g_coord.X -= (SHORT) Columns; | |
6290 if (g_coord.Y < g_srScrollRegion.Bottom) | |
6291 g_coord.Y++; | |
6292 } | |
6293 | |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6294 // Cursor under VTP is always in the correct position, no need to reset. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6295 if (!USE_VTP) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6296 gotoxy(g_coord.X + 1, g_coord.Y + 1); |
7 | 6297 |
6298 return written; | |
6299 } | |
6300 | |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6301 static char_u * |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6302 get_seq( |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6303 int *args, |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6304 int *count, |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6305 char_u *head) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6306 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6307 int argc; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6308 char_u *p; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6309 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6310 if (head == NULL || *head != '\033') |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6311 return NULL; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6312 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6313 argc = 0; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6314 p = head; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6315 ++p; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6316 do |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6317 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6318 ++p; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6319 args[argc] = getdigits(&p); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6320 argc += (argc < 15) ? 1 : 0; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6321 } while (*p == ';'); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6322 *count = argc; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6323 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6324 return p; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6325 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6326 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6327 static char_u * |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6328 get_sgr( |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6329 int *args, |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6330 int *count, |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6331 char_u *head) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6332 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6333 char_u *p = get_seq(args, count, head); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6334 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6335 return (p && *p == 'm') ? ++p : NULL; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6336 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6337 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6338 /* |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6339 * Pointer to next if SGR (^[[n;2;*;*;*m), NULL otherwise. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6340 */ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6341 static char_u * |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6342 sgrn2( |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6343 char_u *head, |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6344 int n) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6345 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6346 int argc; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6347 int args[16]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6348 char_u *p = get_sgr(args, &argc, head); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6349 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6350 return p && argc == 5 && args[0] == n && args[1] == 2 ? p : NULL; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6351 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6352 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6353 /* |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6354 * Pointer to next if SGR(^[[nm)<space>ESC, NULL otherwise. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6355 */ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6356 static char_u * |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6357 sgrnc( |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6358 char_u *head, |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6359 int n) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6360 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6361 int argc; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6362 int args[16]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6363 char_u *p = get_sgr(args, &argc, head); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6364 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6365 return p && argc == 1 && args[0] == n && (p = skipwhite(p)) && *p == '\033' |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6366 ? p : NULL; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6367 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6368 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6369 static char_u * |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6370 skipblank(char_u *q) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6371 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6372 char_u *p = q; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6373 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6374 while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6375 ++p; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6376 return p; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6377 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6378 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6379 /* |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6380 * Pointer to the next if any whitespace that may follow SGR is ESC, otherwise |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6381 * NULL. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6382 */ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6383 static char_u * |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6384 sgrn2c( |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6385 char_u *head, |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6386 int n) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6387 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6388 char_u *p = sgrn2(head, n); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6389 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6390 return p && *p != NUL && (p = skipblank(p)) && *p == '\033' ? p : NULL; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6391 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6392 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6393 /* |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6394 * If there is only a newline between the sequence immediately following it, |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6395 * a pointer to the character following the newline is returned. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6396 * Otherwise NULL. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6397 */ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6398 static char_u * |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6399 sgrn2cn( |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6400 char_u *head, |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6401 int n) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6402 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6403 char_u *p = sgrn2(head, n); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6404 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6405 return p && p[0] == 0x0a && p[1] == '\033' ? ++p : NULL; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6406 } |
7 | 6407 |
6408 /* | |
6409 * mch_write(): write the output buffer to the screen, translating ESC | |
6410 * sequences into calls to console output routines. | |
6411 */ | |
6412 void | |
6413 mch_write( | |
6414 char_u *s, | |
6415 int len) | |
6416 { | |
24506
cf773d752eb9
patch 8.2.2793: MS-Windows: string literals are writable with MSVC
Bram Moolenaar <Bram@vim.org>
parents:
24494
diff
changeset
|
6417 char_u *end = s + len; |
cf773d752eb9
patch 8.2.2793: MS-Windows: string literals are writable with MSVC
Bram Moolenaar <Bram@vim.org>
parents:
24494
diff
changeset
|
6418 |
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
|
6419 # 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
|
6420 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
|
6421 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
|
6422 # 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
|
6423 |
7 | 6424 if (!term_console) |
6425 { | |
6426 write(1, s, (unsigned)len); | |
6427 return; | |
6428 } | |
6429 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6430 // translate ESC | sequences into faked bios calls |
7 | 6431 while (len--) |
6432 { | |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6433 int prefix = -1; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6434 char_u ch; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6435 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6436 // While processing a sequence, on rare occasions it seems that another |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6437 // sequence may be inserted asynchronously. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6438 if (len < 0) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6439 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6440 redraw_all_later(CLEAR); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6441 return; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6442 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6443 |
24506
cf773d752eb9
patch 8.2.2793: MS-Windows: string literals are writable with MSVC
Bram Moolenaar <Bram@vim.org>
parents:
24494
diff
changeset
|
6444 while (s + ++prefix < end) |
cf773d752eb9
patch 8.2.2793: MS-Windows: string literals are writable with MSVC
Bram Moolenaar <Bram@vim.org>
parents:
24494
diff
changeset
|
6445 { |
cf773d752eb9
patch 8.2.2793: MS-Windows: string literals are writable with MSVC
Bram Moolenaar <Bram@vim.org>
parents:
24494
diff
changeset
|
6446 ch = s[prefix]; |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6447 if (ch <= 0x1e && !(ch != '\n' && ch != '\r' && ch != '\b' |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6448 && ch != '\a' && ch != '\033')) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6449 break; |
24506
cf773d752eb9
patch 8.2.2793: MS-Windows: string literals are writable with MSVC
Bram Moolenaar <Bram@vim.org>
parents:
24494
diff
changeset
|
6450 } |
7 | 6451 |
6452 if (p_wd) | |
6453 { | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6454 WaitForChar(p_wd, FALSE); |
7 | 6455 if (prefix != 0) |
6456 prefix = 1; | |
6457 } | |
6458 | |
6459 if (prefix != 0) | |
6460 { | |
6461 DWORD nWritten; | |
6462 | |
6463 nWritten = write_chars(s, prefix); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6464 # ifdef MCH_WRITE_DUMP |
7 | 6465 if (fdDump) |
6466 { | |
6467 fputc('>', fdDump); | |
6468 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6469 fputs("<\n", fdDump); | |
6470 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6471 # endif |
7 | 6472 len -= (nWritten - 1); |
6473 s += nWritten; | |
6474 } | |
6475 else if (s[0] == '\n') | |
6476 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6477 // \n, newline: go to the beginning of the next line or scroll |
7 | 6478 if (g_coord.Y == g_srScrollRegion.Bottom) |
6479 { | |
6480 scroll(1); | |
6481 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1); | |
6482 } | |
6483 else | |
6484 { | |
6485 gotoxy(g_srScrollRegion.Left + 1, g_coord.Y + 2); | |
6486 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6487 # ifdef MCH_WRITE_DUMP |
7 | 6488 if (fdDump) |
6489 fputs("\\n\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6490 # endif |
7 | 6491 s++; |
6492 } | |
6493 else if (s[0] == '\r') | |
6494 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6495 // \r, carriage return: go to beginning of line |
7 | 6496 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
|
6497 # ifdef MCH_WRITE_DUMP |
7 | 6498 if (fdDump) |
6499 fputs("\\r\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6500 # endif |
7 | 6501 s++; |
6502 } | |
6503 else if (s[0] == '\b') | |
6504 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6505 // \b, backspace: move cursor one position left |
7 | 6506 if (g_coord.X > g_srScrollRegion.Left) |
6507 g_coord.X--; | |
6508 else if (g_coord.Y > g_srScrollRegion.Top) | |
6509 { | |
6510 g_coord.X = g_srScrollRegion.Right; | |
6511 g_coord.Y--; | |
6512 } | |
6513 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
|
6514 # ifdef MCH_WRITE_DUMP |
7 | 6515 if (fdDump) |
6516 fputs("\\b\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6517 # endif |
7 | 6518 s++; |
6519 } | |
6520 else if (s[0] == '\a') | |
6521 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6522 // \a, bell |
7 | 6523 MessageBeep(0xFFFFFFFF); |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6524 # ifdef MCH_WRITE_DUMP |
7 | 6525 if (fdDump) |
6526 fputs("\\a\n", fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6527 # endif |
7 | 6528 s++; |
6529 } | |
6530 else if (s[0] == ESC && len >= 3-1 && s[1] == '|') | |
6531 { | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6532 # ifdef MCH_WRITE_DUMP |
24 | 6533 char_u *old_s = s; |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6534 # endif |
24 | 6535 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
|
6536 int arg1 = 0, arg2 = 0, argc = 0, args[16]; |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6537 char_u *sp; |
7 | 6538 |
6539 switch (s[2]) | |
6540 { | |
6541 case '0': case '1': case '2': case '3': case '4': | |
6542 case '5': case '6': case '7': case '8': case '9': | |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6543 if (*(p = get_seq(args, &argc, s)) != 'm') |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6544 goto notsgr; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6545 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6546 p = s; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6547 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6548 // Handling frequent optional sequences. Output to the screen |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6549 // takes too long, so do not output as much as possible. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6550 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6551 // If resetFG,FG,BG,<cr>,BG,FG are connected, the preceding |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6552 // resetFG,FG,BG are omitted. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6553 if (sgrn2(sgrn2(sgrn2cn(sgrn2(sgrnc(p, 39), 38), 48), 48), 38)) |
7 | 6554 { |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6555 p = sgrn2(sgrn2(sgrnc(p, 39), 38), 48); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6556 len = len + 1 - (int)(p - s); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6557 s = 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
|
6558 break; |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6559 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6560 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6561 // If FG,BG,BG,FG of SGR are connected, the first FG can be |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6562 // omitted. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6563 if (sgrn2(sgrn2(sgrn2c((sp = sgrn2(p, 38)), 48), 48), 38)) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6564 p = sp; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6565 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6566 // If FG,BG,FG,BG of SGR are connected, the first FG can be |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6567 // omitted. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6568 if (sgrn2(sgrn2(sgrn2c((sp = sgrn2(p, 38)), 48), 38), 48)) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6569 p = sp; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6570 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6571 // If BG,BG of SGR are connected, the first BG can be omitted. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6572 if (sgrn2((sp = sgrn2(p, 48)), 48)) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6573 p = sp; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6574 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6575 // If restoreFG and FG are connected, the restoreFG can be |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6576 // omitted. |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6577 if (sgrn2((sp = sgrnc(p, 39)), 38)) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6578 p = sp; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6579 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6580 p = get_seq(args, &argc, p); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6581 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
6582 notsgr: |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6583 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
|
6584 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
|
6585 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
|
6586 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6587 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
|
6588 normvideo(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6589 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
|
6590 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6591 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
|
6592 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
|
6593 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6594 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
|
6595 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6596 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
|
6597 vtp_sgr_bulks(argc, args); |
7 | 6598 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6599 else if (argc == 2 && *p == 'H') |
7 | 6600 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6601 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
|
6602 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6603 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
|
6604 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6605 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
|
6606 } |
15852
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6607 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
|
6608 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6609 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
|
6610 } |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6611 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
|
6612 { |
acd4fc05422b
patch 8.1.0933: When using VTP scroll region isn't used properly
Bram Moolenaar <Bram@vim.org>
parents:
15848
diff
changeset
|
6613 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
|
6614 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6615 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
|
6616 { |
7 | 6617 gotoxy(g_coord.X + 1, |
6618 max(g_srScrollRegion.Top, g_coord.Y - arg1) + 1); | |
6619 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6620 else if (argc == 1 && *p == 'b') |
7 | 6621 { |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6622 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
|
6623 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6624 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
|
6625 { |
7 | 6626 gotoxy(min(g_srScrollRegion.Right, g_coord.X + arg1) + 1, |
6627 g_coord.Y + 1); | |
6628 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6629 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
|
6630 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6631 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
|
6632 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6633 else if (argc == 1 && *p == 'H') |
7 | 6634 { |
6635 gotoxy(1, arg1); | |
6636 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6637 else if (argc == 1 && *p == 'L') |
7 | 6638 { |
6639 insert_lines(arg1); | |
6640 } | |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
6641 else if (argc == 1 && *p == 'M') |
7 | 6642 { |
6643 delete_lines(arg1); | |
6644 } | |
6645 | |
835 | 6646 len -= (int)(p - s); |
7 | 6647 s = p + 1; |
6648 break; | |
6649 | |
6650 case 'A': | |
6651 gotoxy(g_coord.X + 1, | |
6652 max(g_srScrollRegion.Top, g_coord.Y - 1) + 1); | |
6653 goto got3; | |
6654 | |
6655 case 'B': | |
6656 visual_bell(); | |
6657 goto got3; | |
6658 | |
6659 case 'C': | |
6660 gotoxy(min(g_srScrollRegion.Right, g_coord.X + 1) + 1, | |
6661 g_coord.Y + 1); | |
6662 goto got3; | |
6663 | |
6664 case 'E': | |
6665 termcap_mode_end(); | |
6666 goto got3; | |
6667 | |
6668 case 'F': | |
6669 standout(); | |
6670 goto got3; | |
6671 | |
6672 case 'f': | |
6673 standend(); | |
6674 goto got3; | |
6675 | |
6676 case 'H': | |
6677 gotoxy(1, 1); | |
6678 goto got3; | |
6679 | |
6680 case 'j': | |
6681 clear_to_end_of_display(); | |
6682 goto got3; | |
6683 | |
6684 case 'J': | |
6685 clear_screen(); | |
6686 goto got3; | |
6687 | |
6688 case 'K': | |
6689 clear_to_end_of_line(); | |
6690 goto got3; | |
6691 | |
6692 case 'L': | |
6693 insert_lines(1); | |
6694 goto got3; | |
6695 | |
6696 case 'M': | |
6697 delete_lines(1); | |
6698 goto got3; | |
6699 | |
6700 case 'S': | |
6701 termcap_mode_start(); | |
6702 goto got3; | |
6703 | |
6704 case 'V': | |
6705 cursor_visible(TRUE); | |
6706 goto got3; | |
6707 | |
6708 case 'v': | |
6709 cursor_visible(FALSE); | |
6710 goto got3; | |
6711 | |
6712 got3: | |
6713 s += 3; | |
6714 len -= 2; | |
6715 } | |
6716 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6717 # ifdef MCH_WRITE_DUMP |
7 | 6718 if (fdDump) |
6719 { | |
6720 fputs("ESC | ", fdDump); | |
6721 fwrite(old_s + 2, sizeof(char_u), s - old_s - 2, fdDump); | |
6722 fputc('\n', fdDump); | |
6723 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6724 # endif |
7 | 6725 } |
6726 else | |
6727 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6728 // Write a single character |
7 | 6729 DWORD nWritten; |
6730 | |
6731 nWritten = write_chars(s, 1); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6732 # ifdef MCH_WRITE_DUMP |
7 | 6733 if (fdDump) |
6734 { | |
6735 fputc('>', fdDump); | |
6736 fwrite(s, sizeof(char_u), nWritten, fdDump); | |
6737 fputs("<\n", fdDump); | |
6738 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6739 # endif |
7 | 6740 |
6741 len -= (nWritten - 1); | |
6742 s += nWritten; | |
6743 } | |
6744 } | |
6745 | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6746 # ifdef MCH_WRITE_DUMP |
7 | 6747 if (fdDump) |
6748 fflush(fdDump); | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
6749 # endif |
7 | 6750 } |
6751 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6752 #endif // FEAT_GUI_MSWIN |
7 | 6753 |
6754 | |
6755 /* | |
8589
e32ab146b6c9
commit https://github.com/vim/vim/commit/0e0b3dd335b863603b9a2d415ef18d983e2467ae
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
6756 * Delay for "msec" milliseconds. |
7 | 6757 */ |
6758 void | |
6759 mch_delay( | |
6760 long msec, | |
21927
88070e222e82
patch 8.2.1513: cannot interrupt shell used for filename expansion
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
6761 int flags UNUSED) |
7 | 6762 { |
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
|
6763 #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
|
6764 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
|
6765 #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
|
6766 # 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
|
6767 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
|
6768 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6769 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
|
6770 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
|
6771 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6772 # endif |
21927
88070e222e82
patch 8.2.1513: cannot interrupt shell used for filename expansion
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
6773 if (flags & MCH_DELAY_IGNOREINPUT) |
14 | 6774 # ifdef FEAT_MZSCHEME |
6775 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq) | |
6776 { | |
6777 int towait = p_mzq; | |
6778 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6779 // if msec is large enough, wait by portions in p_mzq |
14 | 6780 while (msec > 0) |
6781 { | |
6782 mzvim_check_threads(); | |
6783 if (msec < towait) | |
6784 towait = msec; | |
6785 Sleep(towait); | |
6786 msec -= towait; | |
6787 } | |
6788 } | |
6789 else | |
6790 # endif | |
6791 Sleep((int)msec); | |
7 | 6792 else |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11929
diff
changeset
|
6793 WaitForChar(msec, FALSE); |
7 | 6794 #endif |
6795 } | |
6796 | |
6797 | |
6798 /* | |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6799 * 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
|
6800 * This can also remove a symbolic link like Unix. |
7 | 6801 * Return 0 for success, -1 for failure. |
6802 */ | |
6803 int | |
6804 mch_remove(char_u *name) | |
6805 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6806 WCHAR *wn; |
7 | 6807 int n; |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6808 |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6809 /* |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6810 * 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
|
6811 * 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
|
6812 */ |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6813 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
|
6814 return mch_rmdir(name); |
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7619
diff
changeset
|
6815 |
4872
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6816 win32_setattrs(name, FILE_ATTRIBUTE_NORMAL); |
fa98c2b030ed
updated for version 7.3.1182
Bram Moolenaar <bram@vim.org>
parents:
4789
diff
changeset
|
6817 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6818 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
|
6819 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
|
6820 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
|
6821 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6822 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
|
6823 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
|
6824 return n; |
7 | 6825 } |
6826 | |
6827 | |
6828 /* | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10060
diff
changeset
|
6829 * Check for an "interrupt signal": CTRL-break or CTRL-C. |
7 | 6830 */ |
6831 void | |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
6832 mch_breakcheck(int force UNUSED) |
7 | 6833 { |
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
|
6834 #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
|
6835 # 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
|
6836 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
|
6837 # 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
|
6838 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
|
6839 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
6840 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
|
6841 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
|
6842 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
|
6843 } |
7 | 6844 #endif |
6845 } | |
6846 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6847 // 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
|
6848 #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
|
6849 |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6850 /* |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6851 * 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
|
6852 */ |
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6853 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
|
6854 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
|
6855 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6856 MEMORYSTATUSEX ms; |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6857 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6858 // 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
|
6859 // what fits in 32 bits. |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6860 ms.dwLength = sizeof(MEMORYSTATUSEX); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6861 GlobalMemoryStatusEx(&ms); |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6862 if (ms.ullAvailVirtual < ms.ullTotalPhys) |
7460
1420ccc9f610
commit https://github.com/vim/vim/commit/ee2739787f1e996739541bb60e6003b892497e03
Christian Brabandt <cb@256bit.org>
parents:
7194
diff
changeset
|
6863 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6864 // 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
|
6865 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
|
6866 } |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6867 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
|
6868 { |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6869 // 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
|
6870 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
|
6871 } |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
6872 // 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
|
6873 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
|
6874 } |
7 | 6875 |
6876 /* | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6877 * mch_wrename() works around a bug in rename (aka MoveFile) in |
7 | 6878 * Windows 95: rename("foo.bar", "foo.bar~") will generate a |
6879 * file whose short file name is "FOO.BAR" (its long file name will | |
6880 * be correct: "foo.bar~"). Because a file can be accessed by | |
6881 * either its SFN or its LFN, "foo.bar" has effectively been | |
6882 * renamed to "foo.bar", which is not at all what was wanted. This | |
6883 * seems to happen only when renaming files with three-character | |
6884 * extensions by appending a suffix that does not include ".". | |
6885 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR". | |
6886 * | |
6887 * There is another problem, which isn't really a bug but isn't right either: | |
6888 * When renaming "abcdef~1.txt" to "abcdef~1.txt~", the short name can be | |
6889 * "abcdef~1.txt" again. This has been reported on Windows NT 4.0 with | |
6890 * service pack 6. Doesn't seem to happen on Windows 98. | |
6891 * | |
6892 * Like rename(), returns 0 upon success, non-zero upon failure. | |
6893 * Should probably set errno appropriately when errors occur. | |
6894 */ | |
6895 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
|
6896 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
|
6897 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6898 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
|
6899 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
|
6900 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
|
6901 WCHAR szNewPath[_MAX_PATH + 1]; |
7 | 6902 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
|
6903 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6904 // 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
|
6905 // 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
|
6906 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
|
6907 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
|
6908 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
|
6909 && 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
|
6910 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
|
6911 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
|
6912 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
|
6913 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6914 // 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
|
6915 // 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
|
6916 if (GetFullPathNameW(wnew, _MAX_PATH, szNewPath, &p) == 0 || p == NULL) |
7 | 6917 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
|
6918 *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
|
6919 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6920 // 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
|
6921 if (GetTempFileNameW(szNewPath, L"VIM", 0, szTempFile) == 0) |
7 | 6922 return -2; |
6923 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6924 // 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
|
6925 if (!DeleteFileW(szTempFile)) |
7 | 6926 return -3; |
6927 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6928 // 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
|
6929 if (!MoveFileW(wold, szTempFile)) |
7 | 6930 return -4; |
6931 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6932 // 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
|
6933 // 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
|
6934 // 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
|
6935 // 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
|
6936 // 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
|
6937 // 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
|
6938 // 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
|
6939 // 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
|
6940 // 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
|
6941 if ((hf = CreateFileW(wold, GENERIC_WRITE, 0, NULL, CREATE_NEW, |
7 | 6942 FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) |
6943 return -5; | |
6944 if (!CloseHandle(hf)) | |
6945 return -6; | |
6946 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6947 // 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
|
6948 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
|
6949 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6950 // 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
|
6951 // 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
|
6952 (void)MoveFileW(szTempFile, wold); |
7 | 6953 return -7; |
6954 } | |
6955 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6956 // 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
|
6957 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
|
6958 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6959 // 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
|
6960 if (!DeleteFileW(wold)) |
7 | 6961 return -8; |
6962 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6963 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
|
6964 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6965 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6966 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6967 /* |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6968 * 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
|
6969 * 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
|
6970 */ |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6971 int |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6972 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
|
6973 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
|
6974 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
|
6975 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6976 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
|
6977 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
|
6978 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
|
6979 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
6980 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
|
6981 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
|
6982 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
|
6983 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
|
6984 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
|
6985 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
|
6986 return retval; |
7 | 6987 } |
6988 | |
6989 /* | |
6990 * Get the default shell for the current hardware platform | |
6991 */ | |
6992 char * | |
26 | 6993 default_shell(void) |
7 | 6994 { |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
6995 return "cmd.exe"; |
7 | 6996 } |
6997 | |
6998 /* | |
6999 * mch_access() extends access() to do more detailed check on network drives. | |
7000 * Returns 0 if file "n" has access rights according to "p", -1 otherwise. | |
7001 */ | |
7002 int | |
7003 mch_access(char *n, int p) | |
7004 { | |
7005 HANDLE hFile; | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7006 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
|
7007 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
|
7008 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7009 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
|
7010 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
|
7011 return -1; |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
7012 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8059
diff
changeset
|
7013 if (mch_isdir((char_u *)n)) |
7 | 7014 { |
7015 WCHAR TempNameW[_MAX_PATH + 16] = L""; | |
7016 | |
7017 if (p & R_OK) | |
7018 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7019 // 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
|
7020 // 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
|
7021 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
|
7022 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
|
7023 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7024 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
|
7025 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
|
7026 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
|
7027 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
|
7028 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
|
7029 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
|
7030 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7031 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
|
7032 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
|
7033 goto getout; |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7034 else |
7 | 7035 (void)FindClose(hFile); |
7036 } | |
7037 | |
7038 if (p & W_OK) | |
7039 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7040 // 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
|
7041 // 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
|
7042 // 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
|
7043 // 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
|
7044 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
|
7045 goto getout; |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
7046 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
|
7047 DeleteFileW(TempNameW); |
7 | 7048 } |
7049 } | |
7050 else | |
7051 { | |
13853
1ea18443d569
patch 8.0.1798: MS-Windows: file considered read-only too often
Christian Brabandt <cb@256bit.org>
parents:
13839
diff
changeset
|
7052 // 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
|
7053 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
|
7054 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7055 // 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
|
7056 // 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
|
7057 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
|
7058 | ((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
|
7059 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7060 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
|
7061 NULL, OPEN_EXISTING, 0, NULL); |
7 | 7062 if (hFile == INVALID_HANDLE_VALUE) |
7063 goto getout; | |
7064 CloseHandle(hFile); | |
7065 } | |
7066 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7067 retval = 0; // success |
7 | 7068 getout: |
7069 vim_free(wn); | |
7070 return retval; | |
7071 } | |
7072 | |
7073 /* | |
1752 | 7074 * Version of open() that may use UTF-16 file name. |
7 | 7075 */ |
7076 int | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
7077 mch_open(const char *name, int flags, int mode) |
7 | 7078 { |
7079 WCHAR *wn; | |
7080 int f; | |
7081 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7082 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
|
7083 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
|
7084 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
|
7085 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7086 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
|
7087 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
|
7088 return f; |
7 | 7089 } |
7090 | |
7091 /* | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7092 * Version of fopen() that uses UTF-16 file name. |
7 | 7093 */ |
7094 FILE * | |
11921
bafbdbc64bbe
patch 8.0.0840: MS-Windows: fopen() and open() prototypes are wrong
Christian Brabandt <cb@256bit.org>
parents:
11723
diff
changeset
|
7095 mch_fopen(const char *name, const char *mode) |
7 | 7096 { |
7097 WCHAR *wn, *wm; | |
7098 FILE *f = NULL; | |
7099 | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7100 #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
|
7101 // 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
|
7102 // 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
|
7103 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
|
7104 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
|
7105 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7106 _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
|
7107 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
|
7108 _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
|
7109 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
|
7110 _set_fmode(_O_BINARY); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7111 #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
|
7112 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
|
7113 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
|
7114 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
|
7115 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
|
7116 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
|
7117 vim_free(wm); |
1569 | 7118 |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7119 #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
|
7120 _set_fmode(oldMode); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7121 #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
|
7122 return f; |
7 | 7123 } |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7124 |
7 | 7125 /* |
7126 * SUB STREAM (aka info stream) handling: | |
7127 * | |
23229
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
7128 * NTFS can have sub streams for each file. The normal contents of a file is |
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
7129 * stored in the main stream, and extra contents (author information, title and |
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
7130 * so on) can be stored in a sub stream. After Windows 2000, the user can |
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
7131 * access and store this information in sub streams via an explorer's property |
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
7132 * menu item in the right click menu. This information in sub streams was lost |
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
7133 * when copying only the main stream. Therefore we have to copy sub streams. |
7 | 7134 * |
7135 * Incomplete explanation: | |
7136 * http://msdn.microsoft.com/library/en-us/dnw2k/html/ntfs5.asp | |
7137 * More useful info and an example: | |
7138 * http://www.sysinternals.com/ntw2k/source/misc.shtml#streams | |
7139 */ | |
7140 | |
7141 /* | |
7142 * Copy info stream data "substream". Read from the file with BackupRead(sh) | |
7143 * and write to stream "substream" of file "to". | |
7144 * Errors are ignored. | |
7145 */ | |
7146 static void | |
7147 copy_substream(HANDLE sh, void *context, WCHAR *to, WCHAR *substream, long len) | |
7148 { | |
7149 HANDLE hTo; | |
7150 WCHAR *to_name; | |
7151 | |
7152 to_name = malloc((wcslen(to) + wcslen(substream) + 1) * sizeof(WCHAR)); | |
7153 wcscpy(to_name, to); | |
7154 wcscat(to_name, substream); | |
7155 | |
7156 hTo = CreateFileW(to_name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, | |
7157 FILE_ATTRIBUTE_NORMAL, NULL); | |
7158 if (hTo != INVALID_HANDLE_VALUE) | |
7159 { | |
7160 long done; | |
7161 DWORD todo; | |
7162 DWORD readcnt, written; | |
7163 char buf[4096]; | |
7164 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7165 // Copy block of bytes at a time. Abort when something goes wrong. |
7 | 7166 for (done = 0; done < len; done += written) |
7167 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7168 // (size_t) cast for Borland C 5.5 |
835 | 7169 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) |
7170 : (size_t)(len - done)); | |
7 | 7171 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, |
7172 FALSE, FALSE, context) | |
7173 || readcnt != todo | |
7174 || !WriteFile(hTo, buf, todo, &written, NULL) | |
7175 || written != todo) | |
7176 break; | |
7177 } | |
7178 CloseHandle(hTo); | |
7179 } | |
7180 | |
7181 free(to_name); | |
7182 } | |
7183 | |
7184 /* | |
7185 * Copy info streams from file "from" to file "to". | |
7186 */ | |
7187 static void | |
7188 copy_infostreams(char_u *from, char_u *to) | |
7189 { | |
7190 WCHAR *fromw; | |
7191 WCHAR *tow; | |
7192 HANDLE sh; | |
7193 WIN32_STREAM_ID sid; | |
7194 int headersize; | |
7195 WCHAR streamname[_MAX_PATH]; | |
7196 DWORD readcount; | |
7197 void *context = NULL; | |
7198 DWORD lo, hi; | |
7199 int len; | |
7200 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7201 // Convert the file names to wide characters. |
1752 | 7202 fromw = enc_to_utf16(from, NULL); |
7203 tow = enc_to_utf16(to, NULL); | |
7 | 7204 if (fromw != NULL && tow != NULL) |
7205 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7206 // Open the file for reading. |
7 | 7207 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, |
7208 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | |
7209 if (sh != INVALID_HANDLE_VALUE) | |
7210 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7211 // 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
|
7212 // have done them all. |
7 | 7213 for (;;) |
7214 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7215 // 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
|
7216 // the "readcount" is zero we have done all info streams. |
7 | 7217 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); |
835 | 7218 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); |
7 | 7219 if (!BackupRead(sh, (LPBYTE)&sid, headersize, |
7220 &readcount, FALSE, FALSE, &context) | |
7221 || readcount == 0) | |
7222 break; | |
7223 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7224 // 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
|
7225 // 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
|
7226 // suggest it is called "::$DATA". |
7 | 7227 if (sid.dwStreamNameSize > 0) |
7228 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7229 // Read the stream name. |
7 | 7230 if (!BackupRead(sh, (LPBYTE)streamname, |
7231 sid.dwStreamNameSize, | |
7232 &readcount, FALSE, FALSE, &context)) | |
7233 break; | |
7234 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7235 // 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
|
7236 // 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
|
7237 // 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
|
7238 // 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
|
7239 // wide characters. |
7 | 7240 len = readcount / sizeof(WCHAR); |
7241 streamname[len] = 0; | |
7242 if (len > 7 && wcsicmp(streamname + len - 6, | |
7243 L":$DATA") == 0) | |
7244 { | |
7245 streamname[len - 6] = 0; | |
7246 copy_substream(sh, &context, tow, streamname, | |
10 | 7247 (long)sid.Size.u.LowPart); |
7 | 7248 } |
7249 } | |
7250 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7251 // 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
|
7252 // 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
|
7253 // that's OK. |
323 | 7254 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, |
7 | 7255 &lo, &hi, &context); |
7256 } | |
7257 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7258 // Clear the context. |
7 | 7259 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); |
7260 | |
7261 CloseHandle(sh); | |
7262 } | |
7263 } | |
7264 vim_free(fromw); | |
7265 vim_free(tow); | |
7266 } | |
7267 | |
7268 /* | |
23819
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7269 * ntdll.dll definitions |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7270 */ |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7271 #define FileEaInformation 7 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7272 #ifndef STATUS_SUCCESS |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7273 # define STATUS_SUCCESS ((NTSTATUS) 0x00000000L) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7274 #endif |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7275 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7276 typedef struct _FILE_FULL_EA_INFORMATION_ { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7277 ULONG NextEntryOffset; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7278 UCHAR Flags; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7279 UCHAR EaNameLength; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7280 USHORT EaValueLength; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7281 CHAR EaName[1]; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7282 } FILE_FULL_EA_INFORMATION_, *PFILE_FULL_EA_INFORMATION_; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7283 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7284 typedef struct _FILE_EA_INFORMATION_ { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7285 ULONG EaSize; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7286 } FILE_EA_INFORMATION_, *PFILE_EA_INFORMATION_; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7287 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7288 typedef NTSTATUS (NTAPI *PfnNtOpenFile)( |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7289 PHANDLE FileHandle, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7290 ACCESS_MASK DesiredAccess, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7291 POBJECT_ATTRIBUTES ObjectAttributes, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7292 PIO_STATUS_BLOCK IoStatusBlock, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7293 ULONG ShareAccess, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7294 ULONG OpenOptions); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7295 typedef NTSTATUS (NTAPI *PfnNtClose)( |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7296 HANDLE Handle); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7297 typedef NTSTATUS (NTAPI *PfnNtSetEaFile)( |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7298 HANDLE FileHandle, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7299 PIO_STATUS_BLOCK IoStatusBlock, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7300 PVOID Buffer, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7301 ULONG Length); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7302 typedef NTSTATUS (NTAPI *PfnNtQueryEaFile)( |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7303 HANDLE FileHandle, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7304 PIO_STATUS_BLOCK IoStatusBlock, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7305 PVOID Buffer, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7306 ULONG Length, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7307 BOOLEAN ReturnSingleEntry, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7308 PVOID EaList, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7309 ULONG EaListLength, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7310 PULONG EaIndex, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7311 BOOLEAN RestartScan); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7312 typedef NTSTATUS (NTAPI *PfnNtQueryInformationFile)( |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7313 HANDLE FileHandle, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7314 PIO_STATUS_BLOCK IoStatusBlock, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7315 PVOID FileInformation, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7316 ULONG Length, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7317 FILE_INFORMATION_CLASS FileInformationClass); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7318 typedef VOID (NTAPI *PfnRtlInitUnicodeString)( |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7319 PUNICODE_STRING DestinationString, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7320 PCWSTR SourceString); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7321 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7322 PfnNtOpenFile pNtOpenFile = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7323 PfnNtClose pNtClose = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7324 PfnNtSetEaFile pNtSetEaFile = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7325 PfnNtQueryEaFile pNtQueryEaFile = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7326 PfnNtQueryInformationFile pNtQueryInformationFile = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7327 PfnRtlInitUnicodeString pRtlInitUnicodeString = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7328 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7329 /* |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7330 * Load ntdll.dll functions. |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7331 */ |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7332 static BOOL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7333 load_ntdll(void) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7334 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7335 static int loaded = -1; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7336 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7337 if (loaded == -1) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7338 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7339 HMODULE hNtdll = GetModuleHandle("ntdll.dll"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7340 if (hNtdll != NULL) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7341 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7342 pNtOpenFile = (PfnNtOpenFile) GetProcAddress(hNtdll, "NtOpenFile"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7343 pNtClose = (PfnNtClose) GetProcAddress(hNtdll, "NtClose"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7344 pNtSetEaFile = (PfnNtSetEaFile) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7345 GetProcAddress(hNtdll, "NtSetEaFile"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7346 pNtQueryEaFile = (PfnNtQueryEaFile) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7347 GetProcAddress(hNtdll, "NtQueryEaFile"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7348 pNtQueryInformationFile = (PfnNtQueryInformationFile) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7349 GetProcAddress(hNtdll, "NtQueryInformationFile"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7350 pRtlInitUnicodeString = (PfnRtlInitUnicodeString) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7351 GetProcAddress(hNtdll, "RtlInitUnicodeString"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7352 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7353 if (pNtOpenFile == NULL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7354 || pNtClose == NULL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7355 || pNtSetEaFile == NULL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7356 || pNtQueryEaFile == NULL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7357 || pNtQueryInformationFile == NULL |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7358 || pRtlInitUnicodeString == NULL) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7359 loaded = FALSE; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7360 else |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7361 loaded = TRUE; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7362 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7363 return (BOOL) loaded; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7364 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7365 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7366 /* |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7367 * Copy extended attributes (EA) from file "from" to file "to". |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7368 */ |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7369 static void |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7370 copy_extattr(char_u *from, char_u *to) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7371 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7372 char_u *fromf = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7373 char_u *tof = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7374 WCHAR *fromw = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7375 WCHAR *tow = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7376 UNICODE_STRING u; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7377 HANDLE h; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7378 OBJECT_ATTRIBUTES oa; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7379 IO_STATUS_BLOCK iosb; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7380 FILE_EA_INFORMATION_ eainfo = {0}; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7381 void *ea = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7382 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7383 if (!load_ntdll()) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7384 return; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7385 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7386 // Convert the file names to the fully qualified object names. |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7387 fromf = alloc(STRLEN(from) + 5); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7388 tof = alloc(STRLEN(to) + 5); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7389 if (fromf == NULL || tof == NULL) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7390 goto theend; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7391 STRCPY(fromf, "\\??\\"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7392 STRCAT(fromf, from); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7393 STRCPY(tof, "\\??\\"); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7394 STRCAT(tof, to); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7395 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7396 // Convert the names to wide characters. |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7397 fromw = enc_to_utf16(fromf, NULL); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7398 tow = enc_to_utf16(tof, NULL); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7399 if (fromw == NULL || tow == NULL) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7400 goto theend; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7401 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7402 // Get the EA. |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7403 pRtlInitUnicodeString(&u, fromw); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7404 InitializeObjectAttributes(&oa, &u, 0, NULL, NULL); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7405 if (pNtOpenFile(&h, FILE_READ_EA, &oa, &iosb, 0, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7406 FILE_NON_DIRECTORY_FILE) != STATUS_SUCCESS) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7407 goto theend; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7408 pNtQueryInformationFile(h, &iosb, &eainfo, sizeof(eainfo), |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7409 FileEaInformation); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7410 if (eainfo.EaSize != 0) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7411 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7412 ea = alloc(eainfo.EaSize); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7413 if (ea != NULL) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7414 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7415 if (pNtQueryEaFile(h, &iosb, ea, eainfo.EaSize, FALSE, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7416 NULL, 0, NULL, TRUE) != STATUS_SUCCESS) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7417 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7418 vim_free(ea); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7419 ea = NULL; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7420 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7421 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7422 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7423 pNtClose(h); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7424 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7425 // Set the EA. |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7426 if (ea != NULL) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7427 { |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7428 pRtlInitUnicodeString(&u, tow); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7429 InitializeObjectAttributes(&oa, &u, 0, NULL, NULL); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7430 if (pNtOpenFile(&h, FILE_WRITE_EA, &oa, &iosb, 0, |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7431 FILE_NON_DIRECTORY_FILE) != STATUS_SUCCESS) |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7432 goto theend; |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7433 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7434 pNtSetEaFile(h, &iosb, ea, eainfo.EaSize); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7435 pNtClose(h); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7436 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7437 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7438 theend: |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7439 vim_free(fromf); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7440 vim_free(tof); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7441 vim_free(fromw); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7442 vim_free(tow); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7443 vim_free(ea); |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7444 } |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7445 |
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7446 /* |
7 | 7447 * Copy file attributes from file "from" to file "to". |
7448 * For Windows NT and later we copy info streams. | |
7449 * Always returns zero, errors are ignored. | |
7450 */ | |
7451 int | |
7452 mch_copy_file_attribute(char_u *from, char_u *to) | |
7453 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7454 // 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
|
7455 copy_infostreams(from, to); |
23819
7237ed5f89bd
patch 8.2.2451: MS-Windows: Extended Attributes not preserved
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
7456 copy_extattr(from, to); |
7 | 7457 return 0; |
7458 } | |
7459 | |
26 | 7460 |
7461 /* | |
24848
c91b3e5b7896
patch 8.2.2962: MS-Windows command line arguments have wrong encoding
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
7462 * The command line arguments in UTF-16 |
26 | 7463 */ |
344 | 7464 static int nArgsW = 0; |
26 | 7465 static LPWSTR *ArglistW = NULL; |
7466 static int global_argc = 0; | |
7467 static char **global_argv; | |
7468 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7469 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
|
7470 // for the argument list. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7471 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
|
7472 // command line arguments added to |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7473 // the argument list |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7474 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
|
7475 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
|
7476 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
|
7477 static int used_file_diff_mode = FALSE; // file name was with diff mode |
26 | 7478 static int used_alist_count = 0; |
7479 | |
7480 | |
7481 /* | |
7482 * Get the command line arguments. Unicode version. | |
7483 * Returns argc. Zero when something fails. | |
7484 */ | |
7485 int | |
7486 get_cmd_argsW(char ***argvp) | |
7487 { | |
7488 char **argv = NULL; | |
7489 int argc = 0; | |
7490 int i; | |
7491 | |
6193 | 7492 free_cmd_argsW(); |
26 | 7493 ArglistW = CommandLineToArgvW(GetCommandLineW(), &nArgsW); |
7494 if (ArglistW != NULL) | |
7495 { | |
7496 argv = malloc((nArgsW + 1) * sizeof(char *)); | |
7497 if (argv != NULL) | |
7498 { | |
7499 argc = nArgsW; | |
7500 argv[argc] = NULL; | |
7501 for (i = 0; i < argc; ++i) | |
7502 { | |
7503 int len; | |
7504 | |
24848
c91b3e5b7896
patch 8.2.2962: MS-Windows command line arguments have wrong encoding
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
7505 // Convert each Unicode argument to UTF-8. |
c91b3e5b7896
patch 8.2.2962: MS-Windows command line arguments have wrong encoding
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
7506 WideCharToMultiByte_alloc(CP_UTF8, 0, |
835 | 7507 ArglistW[i], (int)wcslen(ArglistW[i]) + 1, |
26 | 7508 (LPSTR *)&argv[i], &len, 0, 0); |
7509 if (argv[i] == NULL) | |
7510 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7511 // Out of memory, clear everything. |
26 | 7512 while (i > 0) |
7513 free(argv[--i]); | |
7514 free(argv); | |
5529 | 7515 argv = NULL; |
26 | 7516 argc = 0; |
7517 } | |
7518 } | |
7519 } | |
7520 } | |
7521 | |
7522 global_argc = argc; | |
7523 global_argv = argv; | |
7524 if (argc > 0) | |
6193 | 7525 { |
7526 if (used_file_indexes != NULL) | |
7527 free(used_file_indexes); | |
26 | 7528 used_file_indexes = malloc(argc * sizeof(int)); |
6193 | 7529 } |
26 | 7530 |
7531 if (argvp != NULL) | |
7532 *argvp = argv; | |
7533 return argc; | |
7534 } | |
7535 | |
7536 void | |
7537 free_cmd_argsW(void) | |
7538 { | |
7539 if (ArglistW != NULL) | |
7540 { | |
7541 GlobalFree(ArglistW); | |
7542 ArglistW = NULL; | |
7543 } | |
7544 } | |
7545 | |
7546 /* | |
7547 * Remember "name" is an argument that was added to the argument list. | |
7548 * This avoids that we have to re-parse the argument list when fix_arg_enc() | |
7549 * is called. | |
7550 */ | |
7551 void | |
819 | 7552 used_file_arg(char *name, int literal, int full_path, int diff_mode) |
26 | 7553 { |
7554 int i; | |
7555 | |
7556 if (used_file_indexes == NULL) | |
7557 return; | |
7558 for (i = used_file_argc + 1; i < global_argc; ++i) | |
7559 if (STRCMP(global_argv[i], name) == 0) | |
7560 { | |
7561 used_file_argc = i; | |
7562 used_file_indexes[used_file_count++] = i; | |
7563 break; | |
7564 } | |
7565 used_file_literal = literal; | |
7566 used_file_full_path = full_path; | |
819 | 7567 used_file_diff_mode = diff_mode; |
26 | 7568 } |
7569 | |
7570 /* | |
7571 * Remember the length of the argument list as it was. If it changes then we | |
7572 * leave it alone when 'encoding' is set. | |
7573 */ | |
7574 void | |
7575 set_alist_count(void) | |
7576 { | |
7577 used_alist_count = GARGCOUNT; | |
7578 } | |
7579 | |
7580 /* | |
7581 * Fix the encoding of the command line arguments. Invoked when 'encoding' | |
24848
c91b3e5b7896
patch 8.2.2962: MS-Windows command line arguments have wrong encoding
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
7582 * has been changed while starting up. Use the UTF-16 command line arguments |
26 | 7583 * and convert them to 'encoding'. |
7584 */ | |
7585 void | |
7586 fix_arg_enc(void) | |
7587 { | |
7588 int i; | |
7589 int idx; | |
7590 char_u *str; | |
41 | 7591 int *fnum_list; |
26 | 7592 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7593 // Safety checks: |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7594 // - 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
|
7595 // list, something must be wrong. |
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7596 // - 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
|
7597 // - the length of the argument list wasn't changed by the user. |
344 | 7598 if (global_argc != nArgsW |
26 | 7599 || ArglistW == NULL |
7600 || used_file_indexes == NULL | |
7601 || used_file_count == 0 | |
7602 || used_alist_count != GARGCOUNT) | |
7603 return; | |
7604 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7605 // 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
|
7606 fnum_list = ALLOC_MULT(int, GARGCOUNT); |
41 | 7607 if (fnum_list == NULL) |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7608 return; // out of memory |
41 | 7609 for (i = 0; i < GARGCOUNT; ++i) |
7610 fnum_list[i] = GARGLIST[i].ae_fnum; | |
7611 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7612 // Clear the argument list. Make room for the new arguments. |
26 | 7613 alist_clear(&global_alist); |
7614 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
|
7615 return; // out of memory |
26 | 7616 |
7617 for (i = 0; i < used_file_count; ++i) | |
7618 { | |
7619 idx = used_file_indexes[i]; | |
1752 | 7620 str = utf16_to_enc(ArglistW[idx], NULL); |
26 | 7621 if (str != NULL) |
41 | 7622 { |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7623 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
|
7624 |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
7625 #ifdef FEAT_DIFF |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7626 // 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
|
7627 // directory name. Just like it's done in main(). |
819 | 7628 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 |
7629 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
7630 { | |
7631 char_u *r; | |
7632 | |
7633 r = concat_fnames(str, gettail(alist_name(&GARGLIST[0])), TRUE); | |
7634 if (r != NULL) | |
7635 { | |
7636 vim_free(str); | |
7637 str = r; | |
7638 } | |
7639 } | |
18773
38a3bef525e6
patch 8.1.2376: preprocessor indents are incorrect
Bram Moolenaar <Bram@vim.org>
parents:
18662
diff
changeset
|
7640 #endif |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7641 // 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
|
7642 // names it's done by alist_expand() below. |
41 | 7643 if (used_file_literal) |
7644 buf_set_name(fnum_list[i], str); | |
7645 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7646 // 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
|
7647 // 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
|
7648 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
|
7649 { |
12015
7e704d75a882
patch 8.0.0888: compiler warnings with 64 bit build
Christian Brabandt <cb@256bit.org>
parents:
11991
diff
changeset
|
7650 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
|
7651 |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7652 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
|
7653 literal = TRUE; |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7654 } |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
7655 alist_add(&global_alist, str, literal ? 2 : 0); |
41 | 7656 } |
26 | 7657 } |
7658 | |
7659 if (!used_file_literal) | |
7660 { | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7661 // 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
|
7662 // 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
|
7663 // filename characters but are excluded from 'isfname' to make |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
7664 // "gf" work on a file name in parentheses (e.g.: see vim.h). |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7665 // 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
|
7666 // 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
|
7667 // encoding options were changed. |
26071
0bb9004c993b
patch 8.2.3569: error for :let when vimrc is Vim 9 script
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
7668 // Use :legacy so that it also works when in Vim9 script. |
0bb9004c993b
patch 8.2.3569: error for :let when vimrc is Vim 9 script
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
7669 do_cmdline_cmd((char_u *)":legacy let g:SaVe_ISF = &isf|set isf+=(,)"); |
0bb9004c993b
patch 8.2.3569: error for :let when vimrc is Vim 9 script
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
7670 do_cmdline_cmd((char_u *)":legacy let g:SaVe_WIG = &wig|set wig="); |
41 | 7671 alist_expand(fnum_list, used_alist_count); |
26071
0bb9004c993b
patch 8.2.3569: error for :let when vimrc is Vim 9 script
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
7672 do_cmdline_cmd( |
0bb9004c993b
patch 8.2.3569: error for :let when vimrc is Vim 9 script
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
7673 (char_u *)":legacy let &isf = g:SaVe_ISF|unlet g:SaVe_ISF"); |
0bb9004c993b
patch 8.2.3569: error for :let when vimrc is Vim 9 script
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
7674 do_cmdline_cmd( |
0bb9004c993b
patch 8.2.3569: error for :let when vimrc is Vim 9 script
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
7675 (char_u *)":legacy let &wig = g:SaVe_WIG|unlet g:SaVe_WIG"); |
26 | 7676 } |
7677 | |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7678 // 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
|
7679 // arglist and there is no file name: Edit the first argument now. |
26 | 7680 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) |
7681 { | |
7682 do_cmdline_cmd((char_u *)":rewind"); | |
26171
fa8161b003f6
patch 8.2.3617: ":verbose pwd" does not mention 'autochdir' was applied
Bram Moolenaar <Bram@vim.org>
parents:
26071
diff
changeset
|
7683 if (GARGCOUNT == 1 && used_file_full_path |
fa8161b003f6
patch 8.2.3617: ":verbose pwd" does not mention 'autochdir' was applied
Bram Moolenaar <Bram@vim.org>
parents:
26071
diff
changeset
|
7684 && vim_chdirfile(alist_name(&GARGLIST[0]), "drop") == OK) |
fa8161b003f6
patch 8.2.3617: ":verbose pwd" does not mention 'autochdir' was applied
Bram Moolenaar <Bram@vim.org>
parents:
26071
diff
changeset
|
7685 last_chdir_reason = "drop"; |
26 | 7686 } |
41 | 7687 |
7688 set_alist_count(); | |
26 | 7689 } |
10781
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7690 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7691 int |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18133
diff
changeset
|
7692 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
|
7693 { |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7694 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
|
7695 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
|
7696 |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16750
diff
changeset
|
7697 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
|
7698 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
|
7699 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
|
7700 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7701 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
|
7702 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7703 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
|
7704 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16182
diff
changeset
|
7705 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
|
7706 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
|
7707 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
|
7708 _wputenv(p); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7709 #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
|
7710 libintl_wputenv(p); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15553
diff
changeset
|
7711 #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
|
7712 // 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
|
7713 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
|
7714 |
c96534dd2b2f
patch 8.0.0280: problem setting multi-byte environment var on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
10571
diff
changeset
|
7715 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
|
7716 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7717 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7718 /* |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7719 * 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
|
7720 * 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
|
7721 */ |
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
|
7722 #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
|
7723 |
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
|
7724 /* |
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
|
7725 * 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
|
7726 * 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
|
7727 */ |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7728 #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
|
7729 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7730 /* |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7731 * 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
|
7732 * 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
|
7733 */ |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7734 #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
|
7735 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7736 /* |
18611
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7737 * 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
|
7738 */ |
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7739 #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
|
7740 |
6a7ebc2ee528
patch 8.1.2299: ConPTY in MS-Windows 1909 is still wrong
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
7741 /* |
20201
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7742 * Stay ahead of the next update, and when it's done, fix this. |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7743 * version ? (2020 update, temporarily use the build number of insider preview) |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7744 */ |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7745 #define CONPTY_NEXT_UPDATE_BUILD MAKE_VER(10, 0, 19587) |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7746 |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7747 /* |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7748 * 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
|
7749 * insider preview. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7750 */ |
18235
88716bc1c20b
patch 8.1.2112: build number for ConPTY is outdated
Bram Moolenaar <Bram@vim.org>
parents:
18180
diff
changeset
|
7751 #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
|
7752 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7753 /* |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7754 * Not stable now. |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7755 */ |
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
|
7756 #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
|
7757 |
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
|
7758 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
|
7759 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
|
7760 { |
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
|
7761 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
|
7762 #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
|
7763 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
|
7764 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
|
7765 |
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
|
7766 # 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
|
7767 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
|
7768 # 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
|
7769 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7770 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
|
7771 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
7772 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
|
7773 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
|
7774 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
|
7775 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
|
7776 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
|
7777 } |
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
|
7778 #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
|
7779 |
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
|
7780 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
|
7781 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
|
7782 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
|
7783 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
|
7784 |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7785 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
|
7786 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
|
7787 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
|
7788 conpty_type = 2; |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7789 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
|
7790 conpty_type = 2; |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
7791 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
|
7792 conpty_type = 1; |
20201
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7793 |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7794 if (ver >= CONPTY_NEXT_UPDATE_BUILD) |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
7795 conpty_fix_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
|
7796 } |
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
|
7797 |
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
|
7798 #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
|
7799 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7800 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
|
7801 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
|
7802 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7803 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
|
7804 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
|
7805 # 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
|
7806 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
|
7807 # 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
|
7808 |
18810
44b855153d8e
patch 8.1.2393: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18786
diff
changeset
|
7809 // 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
|
7810 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
|
7811 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
|
7812 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7813 pGetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7814 (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
|
7815 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
|
7816 pSetConsoleScreenBufferInfoEx = |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7817 (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
|
7818 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
|
7819 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
|
7820 && 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
|
7821 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
|
7822 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7823 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7824 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
|
7825 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
|
7826 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
|
7827 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
|
7828 save_console_fg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_fg]; |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
7829 store_console_bg_rgb = save_console_bg_rgb; |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
7830 store_console_fg_rgb = save_console_fg_rgb; |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7831 |
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
7832 # 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
|
7833 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
|
7834 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
|
7835 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
|
7836 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
|
7837 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
|
7838 default_console_color_fg = fg; |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14891
diff
changeset
|
7839 # 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
|
7840 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7841 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
|
7842 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7843 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7844 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
|
7845 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
|
7846 { |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
7847 restore_console_color_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
|
7848 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7849 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
7850 int |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7851 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
|
7852 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
|
7853 ...) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7854 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7855 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
|
7856 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
|
7857 DWORD result; |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7858 int len; |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7859 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7860 va_start(list, format); |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7861 len = vim_vsnprintf((char *)buf, 100, (char *)format, list); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7862 va_end(list); |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7863 WriteConsoleA(g_hConOut, buf, (DWORD)len, &result, NULL); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7864 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
|
7865 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7866 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7867 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
|
7868 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
|
7869 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
|
7870 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7871 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
|
7872 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7873 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
|
7874 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
|
7875 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7876 |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7877 #define FAST256(x) \ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7878 if ((*p-- = "0123456789"[(n = x % 10)]) \ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7879 && x >= 10 && (*p-- = "0123456789"[((m = x % 100) - n) / 10]) \ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7880 && x >= 100 && (*p-- = "012"[((x & 0xff) - m) / 100])); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7881 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7882 #define FAST256CASE(x) \ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7883 case x: \ |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7884 FAST256(newargs[x - 1]); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7885 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
7886 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
|
7887 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
|
7888 int argc, |
20227
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7889 int *args) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7890 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7891 #define MAXSGR 16 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7892 #define SGRBUFSIZE 2 + 4 * MAXSGR + 1 // '\033[' + SGR + 'm' |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7893 char_u buf[SGRBUFSIZE]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7894 char_u *p; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7895 int in, out; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7896 int newargs[16]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7897 static int sgrfgr = -1, sgrfgg, sgrfgb; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7898 static int sgrbgr = -1, sgrbgg, sgrbgb; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7899 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7900 if (argc == 0) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7901 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7902 sgrfgr = sgrbgr = -1; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7903 vtp_printf("033[m"); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7904 return; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7905 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7906 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7907 in = out = 0; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7908 while (in < argc) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7909 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7910 int s = args[in]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7911 int copylen = 1; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7912 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7913 if (s == 38) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7914 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7915 if (argc - in >= 5 && args[in + 1] == 2) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7916 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7917 if (sgrfgr == args[in + 2] && sgrfgg == args[in + 3] |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7918 && sgrfgb == args[in + 4]) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7919 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7920 in += 5; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7921 copylen = 0; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7922 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7923 else |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7924 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7925 sgrfgr = args[in + 2]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7926 sgrfgg = args[in + 3]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7927 sgrfgb = args[in + 4]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7928 copylen = 5; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7929 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7930 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7931 else if (argc - in >= 3 && args[in + 1] == 5) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7932 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7933 sgrfgr = -1; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7934 copylen = 3; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7935 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7936 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7937 else if (s == 48) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7938 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7939 if (argc - in >= 5 && args[in + 1] == 2) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7940 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7941 if (sgrbgr == args[in + 2] && sgrbgg == args[in + 3] |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7942 && sgrbgb == args[in + 4]) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7943 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7944 in += 5; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7945 copylen = 0; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7946 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7947 else |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7948 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7949 sgrbgr = args[in + 2]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7950 sgrbgg = args[in + 3]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7951 sgrbgb = args[in + 4]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7952 copylen = 5; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7953 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7954 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7955 else if (argc - in >= 3 && args[in + 1] == 5) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7956 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7957 sgrbgr = -1; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7958 copylen = 3; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7959 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7960 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7961 else if (30 <= s && s <= 39) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7962 sgrfgr = -1; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7963 else if (90 <= s && s <= 97) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7964 sgrfgr = -1; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7965 else if (40 <= s && s <= 49) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7966 sgrbgr = -1; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7967 else if (100 <= s && s <= 107) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7968 sgrbgr = -1; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7969 else if (s == 0) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7970 sgrfgr = sgrbgr = -1; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7971 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7972 while (copylen--) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7973 newargs[out++] = args[in++]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7974 } |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7975 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7976 p = &buf[sizeof(buf) - 1]; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7977 *p-- = 'm'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7978 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7979 switch (out) |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7980 { |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7981 int n, m; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7982 DWORD r; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7983 |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7984 FAST256CASE(16); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7985 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7986 FAST256CASE(15); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7987 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7988 FAST256CASE(14); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7989 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7990 FAST256CASE(13); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7991 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7992 FAST256CASE(12); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7993 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7994 FAST256CASE(11); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7995 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7996 FAST256CASE(10); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7997 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7998 FAST256CASE(9); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
7999 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8000 FAST256CASE(8); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8001 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8002 FAST256CASE(7); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8003 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8004 FAST256CASE(6); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8005 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8006 FAST256CASE(5); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8007 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8008 FAST256CASE(4); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8009 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8010 FAST256CASE(3); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8011 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8012 FAST256CASE(2); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8013 *p-- = ';'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8014 FAST256CASE(1); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8015 *p-- = '['; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8016 *p = '\033'; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8017 WriteConsoleA(g_hConOut, p, (DWORD)(&buf[SGRBUFSIZE] - p), &r, NULL); |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8018 default: |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8019 break; |
f2e4c12b24b3
patch 8.2.0669: MS-Windows: display in VTP is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
20201
diff
changeset
|
8020 } |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8021 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8022 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8023 static void |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8024 wt_init(void) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8025 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8026 wt_working = (mch_getenv("WT_SESSION") != NULL); |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8027 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8028 |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8029 int |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8030 use_wt(void) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8031 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8032 return USE_WT; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8033 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8034 |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
8035 # 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
|
8036 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
|
8037 ctermtoxterm( |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8038 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
|
8039 { |
13839
ca8953d36264
patch 8.0.1791: using uint8_t does not work everywhere
Christian Brabandt <cb@256bit.org>
parents:
13827
diff
changeset
|
8040 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
|
8041 |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8042 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
|
8043 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
|
8044 } |
13827
27e09f1a8e5c
patch 8.0.1785: missing symbol in Win32 small build
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
8045 # 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
|
8046 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8047 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
|
8048 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
|
8049 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8050 # 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
|
8051 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
|
8052 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
|
8053 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
|
8054 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8055 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
|
8056 return; |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8057 |
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
|
8058 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
|
8059 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8060 if (USE_WT) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8061 { |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8062 term_fg_rgb_color(fg); |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8063 term_bg_rgb_color(bg); |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8064 return; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8065 } |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8066 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8067 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
|
8068 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
|
8069 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8070 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
|
8071 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
|
8072 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
|
8073 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8074 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
|
8075 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
|
8076 csbi.srWindow.Bottom += 1; |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8077 store_console_bg_rgb = csbi.ColorTable[g_color_index_bg]; |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8078 store_console_fg_rgb = csbi.ColorTable[g_color_index_fg]; |
14650
99e45fab9d17
patch 8.1.0338: MS-Windows: VTP doesn't work properly with Powershell
Christian Brabandt <cb@256bit.org>
parents:
14619
diff
changeset
|
8079 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
|
8080 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
|
8081 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
|
8082 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
|
8083 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8084 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8085 |
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
|
8086 # 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
|
8087 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
|
8088 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
|
8089 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
|
8090 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
|
8091 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
|
8092 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
|
8093 { |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8094 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
|
8095 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
|
8096 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
|
8097 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
|
8098 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
|
8099 |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8100 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
|
8101 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
|
8102 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
|
8103 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
|
8104 { |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8105 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
|
8106 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
|
8107 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
|
8108 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
|
8109 : 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
|
8110 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
|
8111 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
|
8112 } |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8113 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
|
8114 { |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8115 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
|
8116 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
|
8117 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
|
8118 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
|
8119 : 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
|
8120 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
|
8121 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
|
8122 } |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8123 |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8124 *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
|
8125 *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
|
8126 *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
|
8127 *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
|
8128 } |
1756fe125914
patch 8.1.2382: MS-Windows: When using VTP bold+inverse doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
18773
diff
changeset
|
8129 # 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
|
8130 |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8131 /* |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8132 * Set the console colors to the original colors or the last set colors. |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8133 */ |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8134 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
|
8135 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
|
8136 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8137 # 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
|
8138 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
|
8139 |
20589
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8140 if (USE_WT) |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8141 return; |
ecaceb5c5644
patch 8.2.0848: MS-Windows: the Windows terminal code has some flaws
Bram Moolenaar <Bram@vim.org>
parents:
20478
diff
changeset
|
8142 |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8143 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
|
8144 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
|
8145 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
|
8146 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8147 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
|
8148 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
|
8149 csbi.srWindow.Bottom += 1; |
19239
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8150 csbi.ColorTable[g_color_index_bg] = (COLORREF)store_console_bg_rgb; |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8151 csbi.ColorTable[g_color_index_fg] = (COLORREF)store_console_fg_rgb; |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8152 if (has_csbiex) |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8153 pSetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8154 # endif |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8155 } |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8156 |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8157 /* |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8158 * Set the console colors to the original colors. |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8159 */ |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8160 static void |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8161 restore_console_color_rgb(void) |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8162 { |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8163 # ifdef FEAT_TERMGUICOLORS |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8164 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi; |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8165 |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8166 csbi.cbSize = sizeof(csbi); |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8167 if (has_csbiex) |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8168 pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi); |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8169 |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8170 csbi.cbSize = sizeof(csbi); |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8171 csbi.srWindow.Right += 1; |
c189e3826ec3
patch 8.2.0178: with VTP the screen may not be restored properly
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
8172 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
|
8173 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
|
8174 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
|
8175 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
|
8176 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
|
8177 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8178 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8179 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8180 void |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8181 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
|
8182 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8183 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
|
8184 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
|
8185 else |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8186 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
|
8187 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8188 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8189 int |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8190 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
|
8191 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8192 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
|
8193 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13260
diff
changeset
|
8194 |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8195 int |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8196 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
|
8197 { |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8198 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
|
8199 } |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13491
diff
changeset
|
8200 |
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
|
8201 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
|
8202 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
|
8203 { |
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
|
8204 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
|
8205 } |
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
|
8206 |
15848
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
8207 #endif |
cea7a0fde805
patch 8.1.0931: vtp_working included in GUI build but unused
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
8208 |
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
|
8209 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
|
8210 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
|
8211 { |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
8212 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
|
8213 } |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
8214 |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
8215 int |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8216 get_conpty_type(void) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8217 { |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8218 return conpty_type; |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8219 } |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8220 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17569
diff
changeset
|
8221 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
|
8222 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
|
8223 { |
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
8224 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
|
8225 } |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8226 |
20201
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
8227 int |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
8228 get_conpty_fix_type(void) |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
8229 { |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
8230 return conpty_fix_type; |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
8231 } |
304015471ae9
patch 8.2.0656: MS-Windows: redrawing right screen edge may not be needed
Bram Moolenaar <Bram@vim.org>
parents:
20183
diff
changeset
|
8232 |
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
|
8233 #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
|
8234 void |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8235 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
|
8236 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8237 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
|
8238 COORD coord; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8239 SMALL_RECT newsize; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8240 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8241 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
|
8242 { |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8243 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
|
8244 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
|
8245 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
|
8246 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8247 newsize.Left = 0; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8248 newsize.Top = 0; |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8249 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
|
8250 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
|
8251 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
|
8252 |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8253 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
|
8254 } |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8255 } |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15862
diff
changeset
|
8256 #endif |
25342
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8257 |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8258 char * |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8259 GetWin32Error(void) |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8260 { |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8261 char *msg = NULL; |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8262 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8263 NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL); |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8264 if (msg != NULL) |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8265 { |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8266 // remove trailing \r\n |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8267 char *pcrlf = strstr(msg, "\r\n"); |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8268 if (pcrlf != NULL) |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8269 *pcrlf = '\0'; |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8270 } |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8271 return msg; |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25084
diff
changeset
|
8272 } |